blob: aa27c79073c15170ace1ee54ecb27325e96cd649 [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"
Florin Malitaab244f02017-05-03 19:16:58 +000010#include "SkShader.h"
halcanary895f3f02016-04-01 11:51:00 -070011#include "gm.h"
12
Chris Dalton50e24d72019-02-07 16:20:09 -070013DEF_SIMPLE_GM_CAN_FAIL(bitmap_subset_shader, canvas, errorMsg, 256, 256) {
halcanary895f3f02016-04-01 11:51:00 -070014 canvas->clear(SK_ColorWHITE);
15
16 SkBitmap source;
Hal Canaryc465d132017-12-08 10:21:31 -050017 if (!GetResourceAsBitmap("images/color_wheel.png", &source)) {
Chris Dalton50e24d72019-02-07 16:20:09 -070018 *errorMsg = "Could not load images/color_wheel.png. "
19 "Did you forget to set the resourcePath?";
20 return skiagm::DrawResult::kFail;
halcanary895f3f02016-04-01 11:51:00 -070021 }
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);
Mike Reedfae8fce2019-04-03 10:27:45 -040032 SkTileMode tm = SkTileMode::kRepeat;
halcanary895f3f02016-04-01 11:51:00 -070033 SkPaint paint;
Mike Reed50acf8f2019-04-08 13:20:23 -040034 paint.setShader(leftBitmap.makeShader(tm, tm, &matrix));
halcanary895f3f02016-04-01 11:51:00 -070035 canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint);
Mike Reed50acf8f2019-04-08 13:20:23 -040036 paint.setShader(rightBitmap.makeShader(tm, tm, &matrix));
halcanary895f3f02016-04-01 11:51:00 -070037 canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint);
Chris Dalton50e24d72019-02-07 16:20:09 -070038 return skiagm::DrawResult::kOk;
halcanary895f3f02016-04-01 11:51:00 -070039}