blob: c4ef5f7a774f7b1a5476ec9d23c1d00e83987d19 [file] [log] [blame]
halcanary895f3f02016-04-01 11:51:00 -07001/*
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 "gm.h"
11
12DEF_SIMPLE_GM(bitmap_subset_shader, canvas, 256, 256) {
13 canvas->clear(SK_ColorWHITE);
14
15 SkBitmap source;
16 if (!GetResourceAsBitmap("color_wheel.png", &source)) {
17 return;
18 }
19 SkIRect left = SkIRect::MakeWH(source.width()/2, source.height());
20 SkIRect right = SkIRect::MakeXYWH(source.width()/2, 0,
21 source.width()/2, source.height());
22 SkBitmap leftBitmap, rightBitmap;
23 source.extractSubset(&leftBitmap, left);
24 source.extractSubset(&rightBitmap, right);
25
26 SkMatrix matrix;
27 matrix.setScale(0.75f, 0.75f);
28 matrix.preRotate(30.0f);
29 SkShader::TileMode tm = SkShader::kRepeat_TileMode;
30 SkPaint paint;
31 paint.setShader(SkShader::MakeBitmapShader(leftBitmap, tm, tm, &matrix));
32 canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint);
33 paint.setShader(SkShader::MakeBitmapShader(rightBitmap, tm, tm, &matrix));
34 canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint);
35}