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() {
31 virtual uint32_t onGetFlags() const SK_OVERRIDE {
32 return kSkipTiled_Flag;
35 virtual SkString onShortName() {
36 return SkString("gpusamplerstress");
39 virtual SkISize onISize() {
40 return SkISize::Make(640, 480);
44 * Create a red & green stripes on black texture
46 void createTexture() {
47 if (fTextureCreated) {
51 static const int xSize = 16;
52 static const int ySize = 16;
54 fTexture.allocN32Pixels(xSize, ySize);
55 SkPMColor* addr = fTexture.getAddr32(0, 0);
57 for (int y = 0; y < ySize; ++y) {
58 for (int x = 0; x < xSize; ++x) {
59 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorBLACK);
62 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorRED);
65 addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorGREEN);
70 fTextureCreated = true;
74 if (NULL != fShader.get()) {
80 fShader.reset(SkShader::CreateBitmapShader(fTexture,
81 SkShader::kRepeat_TileMode,
82 SkShader::kRepeat_TileMode));
85 void createMaskFilter() {
86 if (NULL != fMaskFilter.get()) {
90 const SkScalar sigma = 1;
91 fMaskFilter.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, sigma));
94 virtual void onDraw(SkCanvas* canvas) {
101 // draw a letter "M" with a green & red striped texture and a
102 // stipple mask with a round rect soft clip
104 paint.setAntiAlias(true);
105 paint.setTextSize(72);
106 paint.setShader(fShader.get());
107 paint.setMaskFilter(fMaskFilter.get());
110 temp.set(SkIntToScalar(115),
116 path.addRoundRect(temp, SkIntToScalar(5), SkIntToScalar(5));
118 canvas->clipPath(path, SkRegion::kReplace_Op, true); // AA is on
120 canvas->drawText("M", 1,
121 SkIntToScalar(100), SkIntToScalar(100),
126 // Now draw stroked versions of the "M" and the round rect so we can
127 // see what is going on
129 paint2.setColor(SK_ColorBLACK);
130 paint2.setAntiAlias(true);
131 paint2.setTextSize(72);
132 paint2.setStyle(SkPaint::kStroke_Style);
133 paint2.setStrokeWidth(1);
134 canvas->drawText("M", 1,
135 SkIntToScalar(100), SkIntToScalar(100),
138 paint2.setColor(SK_ColorGRAY);
140 canvas->drawPath(path, paint2);
145 bool fTextureCreated;
146 SkAutoTUnref<SkShader> fShader;
147 SkAutoTUnref<SkMaskFilter> fMaskFilter;
149 typedef GM INHERITED;
152 //////////////////////////////////////////////////////////////////////////////
154 static GM* MyFactory(void*) { return new SamplerStressGM; }
155 static GMRegistry reg(MyFactory);