Flutter Engine
The Flutter Engine
samplerstress.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 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"
13#include "include/core/SkFont.h"
16#include "include/core/SkPath.h"
17#include "include/core/SkRect.h"
21#include "include/core/SkSize.h"
25#include "tools/ToolUtils.h"
27
28namespace skiagm {
29
30/**
31 * Stress test the GPU samplers by rendering a textured glyph with a mask and
32 * an AA clip
33 */
34class SamplerStressGM : public GM {
35public:
37 : fTextureCreated(false)
38 , fMaskFilter(nullptr) {
39 }
40
41protected:
42 SkString getName() const override { return SkString("gpusamplerstress"); }
43
44 SkISize getISize() override { return SkISize::Make(640, 480); }
45
46 /**
47 * Create a red & green stripes on black texture
48 */
50 if (fTextureCreated) {
51 return;
52 }
53
54 constexpr int xSize = 16;
55 constexpr int ySize = 16;
56
57 fTexture.allocN32Pixels(xSize, ySize);
58 SkPMColor* addr = fTexture.getAddr32(0, 0);
59
60 for (int y = 0; y < ySize; ++y) {
61 for (int x = 0; x < xSize; ++x) {
63
64 if ((y % 5) == 0) {
66 }
67 if ((x % 7) == 0) {
69 }
70 }
71 }
72
73 fTextureCreated = true;
74 }
75
76 void createShader() {
77 if (fShader) {
78 return;
79 }
80
82
85 }
86
88 if (fMaskFilter) {
89 return;
90 }
91
92 const SkScalar sigma = 1;
93 fMaskFilter = SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma);
94 }
95
96 void onDraw(SkCanvas* canvas) override {
99
100 canvas->save();
101
102 // draw a letter "M" with a green & red striped texture and a
103 // stipple mask with a round rect soft clip
105 paint.setAntiAlias(true);
106 paint.setShader(fShader);
107 paint.setMaskFilter(fMaskFilter);
109
110 SkRect temp;
111 temp.setLTRB(115, 75, 144, 110);
112
113 SkPath path;
114 path.addRoundRect(temp, SkIntToScalar(5), SkIntToScalar(5));
115
116 canvas->clipPath(path, true); // AA is on
117
118 canvas->drawString("M", 100.0f, 100.0f, font, paint);
119
120 canvas->restore();
121
122 // Now draw stroked versions of the "M" and the round rect so we can
123 // see what is going on
124 SkPaint paint2;
125 paint2.setColor(SK_ColorBLACK);
126 paint2.setAntiAlias(true);
128 paint2.setStrokeWidth(1);
129 canvas->drawString("M", 100.0f, 100.0f, font, paint2);
130
131 paint2.setColor(SK_ColorGRAY);
132
133 canvas->drawPath(path, paint2);
134 }
135
136private:
137 SkBitmap fTexture;
138 bool fTextureCreated;
139 sk_sp<SkShader> fShader;
140 sk_sp<SkMaskFilter> fMaskFilter;
141
142 using INHERITED = GM;
143};
144
145//////////////////////////////////////////////////////////////////////////////
146
147DEF_GM( return new SamplerStressGM; )
148
149} // namespace skiagm
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition: SkColor.cpp:21
uint32_t SkPMColor
Definition: SkColor.h:205
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SkIntToScalar(x)
Definition: SkScalar.h:57
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
void restore()
Definition: SkCanvas.cpp:461
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
SkISize getISize() override
SkString getName() const override
void onDraw(SkCanvas *canvas) override
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
sk_sp< SkTypeface > DefaultPortableTypeface()
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
font
Font Metadata and Metrics.
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
SkSamplingOptions(SkFilterMode::kLinear))
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
void setLTRB(float left, float top, float right, float bottom)
Definition: SkRect.h:865