OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "gm.h" | 9 #include "gm.h" |
10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace skiagm { | 22 namespace skiagm { |
23 | 23 |
24 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
25 | 25 |
26 class DCShader : public SkShader { | 26 class DCShader : public SkShader { |
27 public: | 27 public: |
28 DCShader(const SkMatrix& matrix) : fDeviceMatrix(matrix) {} | 28 DCShader(const SkMatrix& matrix) : fDeviceMatrix(matrix) {} |
29 | 29 |
30 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DCShader); | 30 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DCShader); |
31 | 31 |
32 void flatten(SkWriteBuffer& buf) const SK_OVERRIDE { | 32 void flatten(SkWriteBuffer& buf) const override { |
33 buf.writeMatrix(fDeviceMatrix); | 33 buf.writeMatrix(fDeviceMatrix); |
34 } | 34 } |
35 | 35 |
36 bool asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& v
iewM, | 36 bool asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& v
iewM, |
37 const SkMatrix* localMatrix, GrColor* color, | 37 const SkMatrix* localMatrix, GrColor* color, |
38 GrFragmentProcessor** fp) const SK_OVERRIDE; | 38 GrFragmentProcessor** fp) const override; |
39 | 39 |
40 #ifndef SK_IGNORE_TO_STRING | 40 #ifndef SK_IGNORE_TO_STRING |
41 void toString(SkString* str) const SK_OVERRIDE { | 41 void toString(SkString* str) const override { |
42 str->appendf("DCShader: ()"); | 42 str->appendf("DCShader: ()"); |
43 } | 43 } |
44 #endif | 44 #endif |
45 | 45 |
46 private: | 46 private: |
47 const SkMatrix fDeviceMatrix; | 47 const SkMatrix fDeviceMatrix; |
48 }; | 48 }; |
49 | 49 |
50 SkFlattenable* DCShader::CreateProc(SkReadBuffer& buf) { | 50 SkFlattenable* DCShader::CreateProc(SkReadBuffer& buf) { |
51 SkMatrix matrix; | 51 SkMatrix matrix; |
52 buf.readMatrix(&matrix); | 52 buf.readMatrix(&matrix); |
53 return SkNEW_ARGS(DCShader, (matrix)); | 53 return SkNEW_ARGS(DCShader, (matrix)); |
54 } | 54 } |
55 | 55 |
56 class DCFP : public GrFragmentProcessor { | 56 class DCFP : public GrFragmentProcessor { |
57 public: | 57 public: |
58 DCFP(const SkMatrix& m) : fDeviceTransform(kDevice_GrCoordSet, m) { | 58 DCFP(const SkMatrix& m) : fDeviceTransform(kDevice_GrCoordSet, m) { |
59 this->addCoordTransform(&fDeviceTransform); | 59 this->addCoordTransform(&fDeviceTransform); |
60 this->initClassID<DCFP>(); | 60 this->initClassID<DCFP>(); |
61 } | 61 } |
62 | 62 |
63 void getGLProcessorKey(const GrGLCaps& caps, | 63 void getGLProcessorKey(const GrGLCaps& caps, |
64 GrProcessorKeyBuilder* b) const SK_OVERRIDE {} | 64 GrProcessorKeyBuilder* b) const override {} |
65 | 65 |
66 GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE { | 66 GrGLFragmentProcessor* createGLInstance() const override { |
67 class DCGLFP : public GrGLFragmentProcessor { | 67 class DCGLFP : public GrGLFragmentProcessor { |
68 void emitCode(GrGLFPBuilder* builder, | 68 void emitCode(GrGLFPBuilder* builder, |
69 const GrFragmentProcessor& fp, | 69 const GrFragmentProcessor& fp, |
70 const char* outputColor, | 70 const char* outputColor, |
71 const char* inputColor, | 71 const char* inputColor, |
72 const TransformedCoordsArray& coords, | 72 const TransformedCoordsArray& coords, |
73 const TextureSamplerArray& samplers) { | 73 const TextureSamplerArray& samplers) { |
74 GrGLFPFragmentBuilder* fpb = builder->getFragmentShaderBuilder()
; | 74 GrGLFPFragmentBuilder* fpb = builder->getFragmentShaderBuilder()
; |
75 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(coords, 0
).c_str()); | 75 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(coords, 0
).c_str()); |
76 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); | 76 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); |
77 fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5," | 77 fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5," |
78 "0.5*cos((c.x + c.y) / 15.0)
+ 0.5," | 78 "0.5*cos((c.x + c.y) / 15.0)
+ 0.5," |
79 "(r.x + r.y) / 20.0," | 79 "(r.x + r.y) / 20.0," |
80 "distance(r, vec2(15.0)) / 2
0.0 + 0.2);"); | 80 "distance(r, vec2(15.0)) / 2
0.0 + 0.2);"); |
81 fpb->codeAppendf("color.rgb *= color.a;" | 81 fpb->codeAppendf("color.rgb *= color.a;" |
82 "%s = color * %s;", | 82 "%s = color * %s;", |
83 outputColor, GrGLSLExpr4(inputColor).c_str()
); | 83 outputColor, GrGLSLExpr4(inputColor).c_str()
); |
84 } | 84 } |
85 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE {} | 85 void setData(const GrGLProgramDataManager&, const GrProcessor&) over
ride {} |
86 }; | 86 }; |
87 return SkNEW(DCGLFP); | 87 return SkNEW(DCGLFP); |
88 } | 88 } |
89 | 89 |
90 const char* name() const SK_OVERRIDE { return "DCFP"; } | 90 const char* name() const override { return "DCFP"; } |
91 | 91 |
92 void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { | 92 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
93 inout->mulByUnknownFourComponents(); | 93 inout->mulByUnknownFourComponents(); |
94 } | 94 } |
95 | 95 |
96 private: | 96 private: |
97 bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE { return true;
} | 97 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
98 | 98 |
99 GrCoordTransform fDeviceTransform; | 99 GrCoordTransform fDeviceTransform; |
100 }; | 100 }; |
101 | 101 |
102 bool DCShader::asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMat
rix& viewM, | 102 bool DCShader::asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMat
rix& viewM, |
103 const SkMatrix* localMatrix, GrColor* color, | 103 const SkMatrix* localMatrix, GrColor* color, |
104 GrFragmentProcessor** fp) const { | 104 GrFragmentProcessor** fp) const { |
105 *fp = SkNEW_ARGS(DCFP, (fDeviceMatrix)); | 105 *fp = SkNEW_ARGS(DCFP, (fDeviceMatrix)); |
106 *color = GrColorPackA4(paint.getAlpha()); | 106 *color = GrColorPackA4(paint.getAlpha()); |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 class DCShaderGM : public GM { | 110 class DCShaderGM : public GM { |
111 public: | 111 public: |
112 DCShaderGM() { | 112 DCShaderGM() { |
113 this->setBGColor(0xFFAABBCC); | 113 this->setBGColor(0xFFAABBCC); |
114 } | 114 } |
115 | 115 |
116 ~DCShaderGM() SK_OVERRIDE { | 116 ~DCShaderGM() override { |
117 for (int i = 0; i < fPrims.count(); ++i) { | 117 for (int i = 0; i < fPrims.count(); ++i) { |
118 SkDELETE(fPrims[i]); | 118 SkDELETE(fPrims[i]); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 protected: | 122 protected: |
123 | 123 |
124 SkString onShortName() SK_OVERRIDE { | 124 SkString onShortName() override { |
125 return SkString("dcshader"); | 125 return SkString("dcshader"); |
126 } | 126 } |
127 | 127 |
128 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1000, 900); } | 128 SkISize onISize() override { return SkISize::Make(1000, 900); } |
129 | 129 |
130 void onOnceBeforeDraw() SK_OVERRIDE { | 130 void onOnceBeforeDraw() override { |
131 struct Rect : public Prim { | 131 struct Rect : public Prim { |
132 SkRect draw(SkCanvas* canvas, const SkPaint& paint) SK_OVERRIDE { | 132 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
133 SkRect rect = SkRect::MakeXYWH(0, 0, 50, 50); | 133 SkRect rect = SkRect::MakeXYWH(0, 0, 50, 50); |
134 canvas->drawRect(rect, paint); | 134 canvas->drawRect(rect, paint); |
135 return rect; | 135 return rect; |
136 } | 136 } |
137 }; | 137 }; |
138 | 138 |
139 struct Circle : public Prim { | 139 struct Circle : public Prim { |
140 SkRect draw(SkCanvas* canvas, const SkPaint& paint) SK_OVERRIDE { | 140 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
141 static const SkScalar radius = 25; | 141 static const SkScalar radius = 25; |
142 canvas->drawCircle(radius, radius, radius, paint); | 142 canvas->drawCircle(radius, radius, radius, paint); |
143 return SkRect::MakeXYWH(0, 0, 2 * radius, 2 * radius); | 143 return SkRect::MakeXYWH(0, 0, 2 * radius, 2 * radius); |
144 } | 144 } |
145 }; | 145 }; |
146 | 146 |
147 struct RRect : public Prim { | 147 struct RRect : public Prim { |
148 SkRect draw(SkCanvas* canvas, const SkPaint& paint) SK_OVERRIDE { | 148 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
149 SkRRect rrect; | 149 SkRRect rrect; |
150 rrect.setRectXY(SkRect::MakeXYWH(0, 0, 50, 50), 10, 10); | 150 rrect.setRectXY(SkRect::MakeXYWH(0, 0, 50, 50), 10, 10); |
151 canvas->drawRRect(rrect, paint); | 151 canvas->drawRRect(rrect, paint); |
152 return rrect.getBounds(); | 152 return rrect.getBounds(); |
153 } | 153 } |
154 }; | 154 }; |
155 | 155 |
156 struct DRRect : public Prim { | 156 struct DRRect : public Prim { |
157 SkRect draw(SkCanvas* canvas, const SkPaint& paint) SK_OVERRIDE { | 157 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
158 SkRRect outerRRect; | 158 SkRRect outerRRect; |
159 outerRRect.setRectXY(SkRect::MakeXYWH(0, 0, 50, 50), 5, 5); | 159 outerRRect.setRectXY(SkRect::MakeXYWH(0, 0, 50, 50), 5, 5); |
160 SkRRect innerRRect; | 160 SkRRect innerRRect; |
161 innerRRect.setRectXY(SkRect::MakeXYWH(5, 8, 35, 30), 8, 3); | 161 innerRRect.setRectXY(SkRect::MakeXYWH(5, 8, 35, 30), 8, 3); |
162 canvas->drawDRRect(outerRRect, innerRRect, paint); | 162 canvas->drawDRRect(outerRRect, innerRRect, paint); |
163 return outerRRect.getBounds(); | 163 return outerRRect.getBounds(); |
164 } | 164 } |
165 }; | 165 }; |
166 struct Path : public Prim { | 166 struct Path : public Prim { |
167 SkRect draw(SkCanvas* canvas, const SkPaint& paint) SK_OVERRIDE { | 167 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
168 SkPath path; | 168 SkPath path; |
169 path.addCircle(15, 15, 10); | 169 path.addCircle(15, 15, 10); |
170 path.addOval(SkRect::MakeXYWH(2, 2, 22, 37)); | 170 path.addOval(SkRect::MakeXYWH(2, 2, 22, 37)); |
171 path.setFillType(SkPath::kEvenOdd_FillType); | 171 path.setFillType(SkPath::kEvenOdd_FillType); |
172 canvas->drawPath(path, paint); | 172 canvas->drawPath(path, paint); |
173 return path.getBounds(); | 173 return path.getBounds(); |
174 } | 174 } |
175 }; | 175 }; |
176 | 176 |
177 struct Points : public Prim { | 177 struct Points : public Prim { |
178 Points(SkCanvas::PointMode mode) : fMode(mode) {} | 178 Points(SkCanvas::PointMode mode) : fMode(mode) {} |
179 | 179 |
180 SkRect draw(SkCanvas* canvas, const SkPaint& paint) SK_OVERRIDE { | 180 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
181 SkRandom random; | 181 SkRandom random; |
182 SkPoint points[500]; | 182 SkPoint points[500]; |
183 SkRect bounds = SkRect::MakeWH(50, 50); | 183 SkRect bounds = SkRect::MakeWH(50, 50); |
184 int count = SkToInt(SK_ARRAY_COUNT(points)); | 184 int count = SkToInt(SK_ARRAY_COUNT(points)); |
185 if (SkCanvas::kPoints_PointMode != fMode) { | 185 if (SkCanvas::kPoints_PointMode != fMode) { |
186 count = SkTMin(count, 10); | 186 count = SkTMin(count, 10); |
187 } | 187 } |
188 for (int p = 0; p < count; ++p) { | 188 for (int p = 0; p < count; ++p) { |
189 points[p].fX = random.nextUScalar1() * bounds.width(); | 189 points[p].fX = random.nextUScalar1() * bounds.width(); |
190 points[p].fY = random.nextUScalar1() * bounds.width(); | 190 points[p].fY = random.nextUScalar1() * bounds.width(); |
191 } | 191 } |
192 canvas->drawPoints(fMode, count, points, paint); | 192 canvas->drawPoints(fMode, count, points, paint); |
193 return bounds; | 193 return bounds; |
194 } | 194 } |
195 SkCanvas::PointMode fMode; | 195 SkCanvas::PointMode fMode; |
196 }; | 196 }; |
197 | 197 |
198 struct Text : public Prim { | 198 struct Text : public Prim { |
199 SkRect draw(SkCanvas* canvas, const SkPaint& origPaint) SK_OVERRIDE
{ | 199 SkRect draw(SkCanvas* canvas, const SkPaint& origPaint) override { |
200 SkPaint paint = origPaint; | 200 SkPaint paint = origPaint; |
201 paint.setTextSize(30.f); | 201 paint.setTextSize(30.f); |
202 this->setFont(&paint); | 202 this->setFont(&paint); |
203 const char* text = this->text(); | 203 const char* text = this->text(); |
204 static const SkVector offset = SkVector::Make(10, 10); | 204 static const SkVector offset = SkVector::Make(10, 10); |
205 canvas->drawText(text, strlen(text), offset.fX, offset.fY, paint
); | 205 canvas->drawText(text, strlen(text), offset.fX, offset.fY, paint
); |
206 SkRect bounds; | 206 SkRect bounds; |
207 paint.measureText(text, strlen(text), &bounds); | 207 paint.measureText(text, strlen(text), &bounds); |
208 bounds.offset(offset); | 208 bounds.offset(offset); |
209 return bounds; | 209 return bounds; |
210 } | 210 } |
211 | 211 |
212 virtual void setFont(SkPaint* paint) { | 212 virtual void setFont(SkPaint* paint) { |
213 sk_tool_utils::set_portable_typeface(paint); | 213 sk_tool_utils::set_portable_typeface(paint); |
214 } | 214 } |
215 | 215 |
216 virtual const char* text() const { return "Hello, Skia!"; } | 216 virtual const char* text() const { return "Hello, Skia!"; } |
217 }; | 217 }; |
218 | 218 |
219 struct BmpText : public Text { | 219 struct BmpText : public Text { |
220 void setFont(SkPaint* paint) SK_OVERRIDE { | 220 void setFont(SkPaint* paint) override { |
221 if (!fTypeface) { | 221 if (!fTypeface) { |
222 SkString filename = GetResourcePath("/Funkster.ttf"); | 222 SkString filename = GetResourcePath("/Funkster.ttf"); |
223 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename
.c_str())); | 223 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename
.c_str())); |
224 if (!stream->isValid()) { | 224 if (!stream->isValid()) { |
225 SkDebugf("Could not find Funkster.ttf, please set --reso
urcePath " | 225 SkDebugf("Could not find Funkster.ttf, please set --reso
urcePath " |
226 "correctly.\n"); | 226 "correctly.\n"); |
227 return; | 227 return; |
228 } | 228 } |
229 fTypeface.reset(SkTypeface::CreateFromStream(stream.detach()
)); | 229 fTypeface.reset(SkTypeface::CreateFromStream(stream.detach()
)); |
230 } | 230 } |
231 paint->setTypeface(fTypeface); | 231 paint->setTypeface(fTypeface); |
232 } | 232 } |
233 | 233 |
234 const char* text() const SK_OVERRIDE { return "Hi, Skia!"; } | 234 const char* text() const override { return "Hi, Skia!"; } |
235 | 235 |
236 SkAutoTUnref<SkTypeface> fTypeface; | 236 SkAutoTUnref<SkTypeface> fTypeface; |
237 }; | 237 }; |
238 fPrims.push_back(SkNEW(Rect)); | 238 fPrims.push_back(SkNEW(Rect)); |
239 fPrims.push_back(SkNEW(Circle)); | 239 fPrims.push_back(SkNEW(Circle)); |
240 fPrims.push_back(SkNEW(RRect)); | 240 fPrims.push_back(SkNEW(RRect)); |
241 fPrims.push_back(SkNEW(DRRect)); | 241 fPrims.push_back(SkNEW(DRRect)); |
242 fPrims.push_back(SkNEW(Path)); | 242 fPrims.push_back(SkNEW(Path)); |
243 fPrims.push_back(SkNEW(Points(SkCanvas::kPoints_PointMode))); | 243 fPrims.push_back(SkNEW(Points(SkCanvas::kPoints_PointMode))); |
244 fPrims.push_back(SkNEW(Points(SkCanvas::kLines_PointMode))); | 244 fPrims.push_back(SkNEW(Points(SkCanvas::kLines_PointMode))); |
245 fPrims.push_back(SkNEW(Points(SkCanvas::kPolygon_PointMode))); | 245 fPrims.push_back(SkNEW(Points(SkCanvas::kPolygon_PointMode))); |
246 fPrims.push_back(SkNEW(Text)); | 246 fPrims.push_back(SkNEW(Text)); |
247 fPrims.push_back(SkNEW(BmpText)); | 247 fPrims.push_back(SkNEW(BmpText)); |
248 } | 248 } |
249 | 249 |
250 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 250 void onDraw(SkCanvas* canvas) override { |
251 // This GM exists to test a specific feature of the GPU backend. It does
not work with the | 251 // This GM exists to test a specific feature of the GPU backend. It does
not work with the |
252 // sw rasterizer, tile modes, etc. | 252 // sw rasterizer, tile modes, etc. |
253 if (NULL == canvas->getGrContext()) { | 253 if (NULL == canvas->getGrContext()) { |
254 this->drawGpuOnlyMessage(canvas); | 254 this->drawGpuOnlyMessage(canvas); |
255 return; | 255 return; |
256 } | 256 } |
257 SkPaint paint; | 257 SkPaint paint; |
258 SkTArray<SkMatrix> devMats; | 258 SkTArray<SkMatrix> devMats; |
259 devMats.push_back().reset(); | 259 devMats.push_back().reset(); |
260 devMats.push_back().setRotate(45, 500, 500); | 260 devMats.push_back().setRotate(45, 500, 500); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 }; | 311 }; |
312 | 312 |
313 SkTArray<Prim*> fPrims; | 313 SkTArray<Prim*> fPrims; |
314 | 314 |
315 typedef GM INHERITED; | 315 typedef GM INHERITED; |
316 }; | 316 }; |
317 | 317 |
318 DEF_GM( return SkNEW(DCShaderGM); ) | 318 DEF_GM( return SkNEW(DCShaderGM); ) |
319 } | 319 } |
320 #endif | 320 #endif |
OLD | NEW |