Flutter Engine
The Flutter Engine
subsetshader.cpp
Go to the documentation of this file.
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"
14#include "include/core/SkRect.h"
18#include "tools/DecodeUtils.h"
19#include "tools/Resources.h"
20
21DEF_SIMPLE_GM_CAN_FAIL(bitmap_subset_shader, canvas, errorMsg, 256, 256) {
22 canvas->clear(SK_ColorWHITE);
23
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?";
29 }
32 source.width()/2, source.height());
33 SkBitmap leftBitmap, rightBitmap;
34 source.extractSubset(&leftBitmap, left);
35 source.extractSubset(&rightBitmap, right);
36
38 matrix.setScale(0.75f, 0.75f);
39 matrix.preRotate(30.0f);
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);
47}
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
SkTileMode
Definition: SkTileMode.h:13
bool extractSubset(SkBitmap *dst, const SkIRect &subset) const
Definition: SkBitmap.cpp:453
int width() const
Definition: SkBitmap.h:149
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
int height() const
Definition: SkBitmap.h:158
const Paint & paint
Definition: color_source.cc:38
SkBitmap source
Definition: examples.cpp:28
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
bool GetResourceAsBitmap(const char *resource, SkBitmap *dst)
Definition: DecodeUtils.h:21
Definition: SkRect.h:32
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
DEF_SIMPLE_GM_CAN_FAIL(bitmap_subset_shader, canvas, errorMsg, 256, 256)