tiledscaledbitmap.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2014 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "gm/gm.h"
  8. #include "include/core/SkBitmap.h"
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkColor.h"
  11. #include "include/core/SkFilterQuality.h"
  12. #include "include/core/SkMatrix.h"
  13. #include "include/core/SkPaint.h"
  14. #include "include/core/SkShader.h"
  15. #include "include/core/SkSize.h"
  16. #include "include/core/SkString.h"
  17. #include "include/core/SkTileMode.h"
  18. /***
  19. *
  20. * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
  21. * when fractional image scaling was ignored by the high quality bitmap scaler.
  22. *
  23. ***/
  24. namespace skiagm {
  25. class TiledScaledBitmapGM : public GM {
  26. public:
  27. TiledScaledBitmapGM() {
  28. }
  29. protected:
  30. SkString onShortName() override {
  31. return SkString("tiledscaledbitmap");
  32. }
  33. SkISize onISize() override {
  34. return SkISize::Make(1016, 616);
  35. }
  36. static SkBitmap make_bm(int width, int height) {
  37. SkBitmap bm;
  38. bm.allocN32Pixels(width, height);
  39. bm.eraseColor(SK_ColorTRANSPARENT);
  40. SkCanvas canvas(bm);
  41. SkPaint paint;
  42. paint.setAntiAlias(true);
  43. canvas.drawCircle(width/2.f, height/2.f, width/4.f, paint);
  44. return bm;
  45. }
  46. void onOnceBeforeDraw() override {
  47. fBitmap = make_bm(360, 288);
  48. }
  49. void onDraw(SkCanvas* canvas) override {
  50. SkPaint paint;
  51. paint.setAntiAlias(true);
  52. paint.setFilterQuality(kHigh_SkFilterQuality);
  53. SkMatrix mat;
  54. mat.setScale(121.f/360.f, 93.f/288.f);
  55. mat.postTranslate(-72, -72);
  56. paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &mat));
  57. canvas->drawRect({ 8, 8, 1008, 608 }, paint);
  58. }
  59. private:
  60. SkBitmap fBitmap;
  61. typedef GM INHERITED;
  62. };
  63. //////////////////////////////////////////////////////////////////////////////
  64. DEF_GM(return new TiledScaledBitmapGM;)
  65. }