2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkBlurMaskFilter.h"
17 * Stress test the GPU samplers by rendering a textured glyph with a mask and
20 class SamplerStressGM : public GM {
23 : fTextureCreated(false)
24 , fMaskFilter(nullptr) {
29 SkString onShortName() override {
30 return SkString("gpusamplerstress");
33 SkISize onISize() override {
34 return SkISize::Make(640, 480);
38 * Create a red & green stripes on black texture
40 void createTexture() {
41 if (fTextureCreated) {
45 static const int xSize = 16;
46 static const int ySize = 16;
48 fTexture.allocN32Pixels(xSize, ySize);
49 SkPMColor* addr = fTexture.getAddr32(0, 0);
51 for (int y = 0; y < ySize; ++y) {
52 for (int x = 0; x < xSize; ++x) {
53 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorBLACK);
56 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorRED);
59 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorGREEN);
64 fTextureCreated = true;
74 fShader = SkShader::MakeBitmapShader(fTexture, SkShader::kRepeat_TileMode,
75 SkShader::kRepeat_TileMode);
78 void createMaskFilter() {
79 if (fMaskFilter.get()) {
83 const SkScalar sigma = 1;
84 fMaskFilter.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, sigma));
87 void onDraw(SkCanvas* canvas) override {
93 // draw a letter "M" with a green & red striped texture and a
94 // stipple mask with a round rect soft clip
96 paint.setAntiAlias(true);
97 paint.setTextSize(72);
98 paint.setShader(fShader.get());
99 paint.setMaskFilter(fMaskFilter.get());
100 sk_tool_utils::set_portable_typeface(&paint);
103 temp.set(SkIntToScalar(115),
109 path.addRoundRect(temp, SkIntToScalar(5), SkIntToScalar(5));
111 canvas->clipPath(path, SkRegion::kReplace_Op, true); // AA is on
113 canvas->drawText("M", 1,
114 SkIntToScalar(100), SkIntToScalar(100),
119 // Now draw stroked versions of the "M" and the round rect so we can
120 // see what is going on
122 paint2.setColor(SK_ColorBLACK);
123 paint2.setAntiAlias(true);
124 paint2.setTextSize(72);
125 paint2.setStyle(SkPaint::kStroke_Style);
126 paint2.setStrokeWidth(1);
127 sk_tool_utils::set_portable_typeface(&paint2);
128 canvas->drawText("M", 1,
129 SkIntToScalar(100), SkIntToScalar(100),
132 paint2.setColor(sk_tool_utils::color_to_565(SK_ColorGRAY));
134 canvas->drawPath(path, paint2);
139 bool fTextureCreated;
140 sk_sp<SkShader> fShader;
141 SkAutoTUnref<SkMaskFilter> fMaskFilter;
143 typedef GM INHERITED;
146 //////////////////////////////////////////////////////////////////////////////
148 static GM* MyFactory(void*) { return new SamplerStressGM; }
149 static GMRegistry reg(MyFactory);