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