blob: 0d5d48411f60ddfdcf8b737b30cca8ffaa63b1e8 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkBitmap.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "include/core/SkShader.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040016#include "include/core/SkString.h"
17#include "include/core/SkTileMode.h"
Kevin Lubick8b741882023-10-06 11:41:38 -040018#include "tools/DecodeUtils.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "tools/Resources.h"
halcanary895f3f02016-04-01 11:51:00 -070020
Chris Dalton50e24d72019-02-07 16:20:09 -070021DEF_SIMPLE_GM_CAN_FAIL(bitmap_subset_shader, canvas, errorMsg, 256, 256) {
halcanary895f3f02016-04-01 11:51:00 -070022 canvas->clear(SK_ColorWHITE);
23
24 SkBitmap source;
Kevin Lubick8b741882023-10-06 11:41:38 -040025 if (!ToolUtils::GetResourceAsBitmap("images/color_wheel.png", &source)) {
Chris Dalton50e24d72019-02-07 16:20:09 -070026 *errorMsg = "Could not load images/color_wheel.png. "
27 "Did you forget to set the resourcePath?";
28 return skiagm::DrawResult::kFail;
halcanary895f3f02016-04-01 11:51:00 -070029 }
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);
Mike Reedfae8fce2019-04-03 10:27:45 -040040 SkTileMode tm = SkTileMode::kRepeat;
halcanary895f3f02016-04-01 11:51:00 -070041 SkPaint paint;
Mike Reedb41bd152020-12-12 11:18:31 -050042 paint.setShader(leftBitmap.makeShader(tm, tm, SkSamplingOptions(), matrix));
halcanary895f3f02016-04-01 11:51:00 -070043 canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint);
Mike Reedb41bd152020-12-12 11:18:31 -050044 paint.setShader(rightBitmap.makeShader(tm, tm, SkSamplingOptions(), matrix));
halcanary895f3f02016-04-01 11:51:00 -070045 canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint);
Chris Dalton50e24d72019-02-07 16:20:09 -070046 return skiagm::DrawResult::kOk;
halcanary895f3f02016-04-01 11:51:00 -070047}