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