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 "gm.h" 11 12 DEF_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 } 36