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.
11 #include "SkBlurMaskFilter.h"
16 * Stress test the GPU samplers by rendering a textured glyph with a mask and
19 class SamplerStressGM : public GM {
22 : fTextureCreated(false)
27 virtual ~SamplerStressGM() {
32 SkString onShortName() override {
33 return SkString("gpusamplerstress");
36 SkISize onISize() override {
37 return SkISize::Make(640, 480);
41 * Create a red & green stripes on black texture
43 void createTexture() {
44 if (fTextureCreated) {
48 static const int xSize = 16;
49 static const int ySize = 16;
51 fTexture.allocN32Pixels(xSize, ySize);
52 SkPMColor* addr = fTexture.getAddr32(0, 0);
54 for (int y = 0; y < ySize; ++y) {
55 for (int x = 0; x < xSize; ++x) {
56 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorBLACK);
59 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorRED);
62 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorGREEN);
67 fTextureCreated = true;
77 fShader.reset(SkShader::CreateBitmapShader(fTexture,
78 SkShader::kRepeat_TileMode,
79 SkShader::kRepeat_TileMode));
82 void createMaskFilter() {
83 if (fMaskFilter.get()) {
87 const SkScalar sigma = 1;
88 fMaskFilter.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, sigma));
91 void onDraw(SkCanvas* canvas) override {
97 // draw a letter "M" with a green & red striped texture and a
98 // stipple mask with a round rect soft clip
100 paint.setAntiAlias(true);
101 paint.setTextSize(72);
102 paint.setShader(fShader.get());
103 paint.setMaskFilter(fMaskFilter.get());
106 temp.set(SkIntToScalar(115),
112 path.addRoundRect(temp, SkIntToScalar(5), SkIntToScalar(5));
114 canvas->clipPath(path, SkRegion::kReplace_Op, true); // AA is on
116 canvas->drawText("M", 1,
117 SkIntToScalar(100), SkIntToScalar(100),
122 // Now draw stroked versions of the "M" and the round rect so we can
123 // see what is going on
125 paint2.setColor(SK_ColorBLACK);
126 paint2.setAntiAlias(true);
127 paint2.setTextSize(72);
128 paint2.setStyle(SkPaint::kStroke_Style);
129 paint2.setStrokeWidth(1);
130 canvas->drawText("M", 1,
131 SkIntToScalar(100), SkIntToScalar(100),
134 paint2.setColor(SK_ColorGRAY);
136 canvas->drawPath(path, paint2);
141 bool fTextureCreated;
142 SkAutoTUnref<SkShader> fShader;
143 SkAutoTUnref<SkMaskFilter> fMaskFilter;
145 typedef GM INHERITED;
148 //////////////////////////////////////////////////////////////////////////////
150 static GM* MyFactory(void*) { return new SamplerStressGM; }
151 static GMRegistry reg(MyFactory);