repeated_bitmap.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2015 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/SkCanvas.h"
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkImage.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkRect.h"
  13. #include "include/core/SkRefCnt.h"
  14. #include "include/core/SkScalar.h"
  15. #include "include/core/SkString.h"
  16. #include "include/core/SkTypes.h"
  17. #include "tools/Resources.h"
  18. #include "tools/ToolUtils.h"
  19. static skiagm::DrawResult draw_rotated_image(SkCanvas* canvas, const SkImage* image,
  20. SkString* errorMsg) {
  21. ToolUtils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156), SK_ColorWHITE, 12);
  22. if (!image) {
  23. *errorMsg = "No image. Did you forget to set the resourcePath?";
  24. return skiagm::DrawResult::kFail;
  25. }
  26. SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
  27. SkPaint paint;
  28. paint.setColor(SkColorSetRGB(49, 48, 49));
  29. SkScalar scale = SkTMin(128.0f / image->width(),
  30. 128.0f / image->height());
  31. SkScalar point[2] = {-0.5f * image->width(), -0.5f * image->height()};
  32. for (int j = 0; j < 4; ++j) {
  33. for (int i = 0; i < 4; ++i) {
  34. SkAutoCanvasRestore autoCanvasRestore(canvas, true);
  35. canvas->translate(96.0f + 192.0f * i, 96.0f + 192.0f * j);
  36. canvas->rotate(18.0f * (i + 4 * j));
  37. canvas->drawRect(rect, paint);
  38. canvas->scale(scale, scale);
  39. canvas->drawImage(image, point[0], point[1]);
  40. }
  41. }
  42. return skiagm::DrawResult::kOk;
  43. }
  44. DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap, canvas, errorMsg, 576, 576) {
  45. return draw_rotated_image(canvas, GetResourceAsImage("images/randPixels.png").get(), errorMsg);
  46. }
  47. DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap_jpg, canvas, errorMsg, 576, 576) {
  48. return draw_rotated_image(canvas, GetResourceAsImage("images/color_wheel.jpg").get(), errorMsg);
  49. }