1 /*
2  * Copyright 2016 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 "Resources.h"
9 #include "SkBitmap.h"
10 #include "SkShader.h"
11 #include "gm.h"
12 
13 DEF_SIMPLE_GM_CAN_FAIL(bitmap_subset_shader, canvas, errorMsg, 256, 256) {
14     canvas->clear(SK_ColorWHITE);
15 
16     SkBitmap source;
17     if (!GetResourceAsBitmap("images/color_wheel.png", &source)) {
18         *errorMsg = "Could not load images/color_wheel.png. "
19                     "Did you forget to set the resourcePath?";
20         return skiagm::DrawResult::kFail;
21     }
22     SkIRect left = SkIRect::MakeWH(source.width()/2, source.height());
23     SkIRect right = SkIRect::MakeXYWH(source.width()/2, 0,
24                                       source.width()/2, source.height());
25     SkBitmap leftBitmap, rightBitmap;
26     source.extractSubset(&leftBitmap, left);
27     source.extractSubset(&rightBitmap, right);
28 
29     SkMatrix matrix;
30     matrix.setScale(0.75f, 0.75f);
31     matrix.preRotate(30.0f);
32     SkShader::TileMode tm = SkShader::kRepeat_TileMode;
33     SkPaint paint;
34     paint.setShader(SkShader::MakeBitmapShader(leftBitmap, tm, tm, &matrix));
35     canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint);
36     paint.setShader(SkShader::MakeBitmapShader(rightBitmap, tm, tm, &matrix));
37     canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint);
38     return skiagm::DrawResult::kOk;
39 }
40