2015-02-18 19:29:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/Resources.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2015-02-18 19:29:56 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
static skiagm::DrawResult draw_rotated_image(SkCanvas* canvas, const SkImage* image,
|
|
|
|
SkString* errorMsg) {
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156), SK_ColorWHITE, 12);
|
2015-10-01 14:28:13 +00:00
|
|
|
if (!image) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "No image. Did you forget to set the resourcePath?";
|
|
|
|
return skiagm::DrawResult::kFail;
|
2015-10-01 14:28:13 +00:00
|
|
|
}
|
|
|
|
SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
|
2015-02-18 19:29:56 +00:00
|
|
|
SkPaint paint;
|
2015-10-01 14:28:13 +00:00
|
|
|
paint.setColor(SkColorSetRGB(49, 48, 49));
|
|
|
|
SkScalar scale = SkTMin(128.0f / image->width(),
|
|
|
|
128.0f / image->height());
|
|
|
|
SkScalar point[2] = {-0.5f * image->width(), -0.5f * image->height()};
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SkAutoCanvasRestore autoCanvasRestore(canvas, true);
|
|
|
|
canvas->translate(96.0f + 192.0f * i, 96.0f + 192.0f * j);
|
|
|
|
canvas->rotate(18.0f * (i + 4 * j));
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->drawImage(image, point[0], point[1]);
|
2015-02-18 19:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 23:20:09 +00:00
|
|
|
return skiagm::DrawResult::kOk;
|
2015-02-18 19:29:56 +00:00
|
|
|
}
|
2015-04-17 20:27:24 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap, canvas, errorMsg, 576, 576) {
|
|
|
|
return draw_rotated_image(canvas, GetResourceAsImage("images/randPixels.png").get(), errorMsg);
|
2015-10-01 14:28:13 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap_jpg, canvas, errorMsg, 576, 576) {
|
|
|
|
return draw_rotated_image(canvas, GetResourceAsImage("images/color_wheel.jpg").get(), errorMsg);
|
2015-04-17 20:27:24 +00:00
|
|
|
}
|