OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrFragmentProcessor.h" | 10 #include "GrFragmentProcessor.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 struct Rect : public Prim { | 125 struct Rect : public Prim { |
126 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { | 126 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
127 SkRect rect = SkRect::MakeXYWH(0, 0, 50, 50); | 127 SkRect rect = SkRect::MakeXYWH(0, 0, 50, 50); |
128 canvas->drawRect(rect, paint); | 128 canvas->drawRect(rect, paint); |
129 return rect; | 129 return rect; |
130 } | 130 } |
131 }; | 131 }; |
132 | 132 |
133 struct Circle : public Prim { | 133 struct Circle : public Prim { |
134 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { | 134 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
135 static const SkScalar radius = 25; | 135 constexpr SkScalar radius = 25; |
136 canvas->drawCircle(radius, radius, radius, paint); | 136 canvas->drawCircle(radius, radius, radius, paint); |
137 return SkRect::MakeXYWH(0, 0, 2 * radius, 2 * radius); | 137 return SkRect::MakeXYWH(0, 0, 2 * radius, 2 * radius); |
138 } | 138 } |
139 }; | 139 }; |
140 | 140 |
141 struct RRect : public Prim { | 141 struct RRect : public Prim { |
142 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { | 142 SkRect draw(SkCanvas* canvas, const SkPaint& paint) override { |
143 SkRRect rrect; | 143 SkRRect rrect; |
144 rrect.setRectXY(SkRect::MakeXYWH(0, 0, 50, 50), 10, 10); | 144 rrect.setRectXY(SkRect::MakeXYWH(0, 0, 50, 50), 10, 10); |
145 canvas->drawRRect(rrect, paint); | 145 canvas->drawRRect(rrect, paint); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 188 } |
189 SkCanvas::PointMode fMode; | 189 SkCanvas::PointMode fMode; |
190 }; | 190 }; |
191 | 191 |
192 struct Text : public Prim { | 192 struct Text : public Prim { |
193 SkRect draw(SkCanvas* canvas, const SkPaint& origPaint) override { | 193 SkRect draw(SkCanvas* canvas, const SkPaint& origPaint) override { |
194 SkPaint paint = origPaint; | 194 SkPaint paint = origPaint; |
195 paint.setTextSize(30.f); | 195 paint.setTextSize(30.f); |
196 this->setFont(&paint); | 196 this->setFont(&paint); |
197 const char* text = this->text(); | 197 const char* text = this->text(); |
198 static const SkVector offset = SkVector::Make(10, 10); | 198 const SkVector offset = SkVector::Make(10, 10); |
199 canvas->drawText(text, strlen(text), offset.fX, offset.fY, paint
); | 199 canvas->drawText(text, strlen(text), offset.fX, offset.fY, paint
); |
200 SkRect bounds; | 200 SkRect bounds; |
201 paint.measureText(text, strlen(text), &bounds); | 201 paint.measureText(text, strlen(text), &bounds); |
202 bounds.offset(offset); | 202 bounds.offset(offset); |
203 return bounds; | 203 return bounds; |
204 } | 204 } |
205 | 205 |
206 virtual void setFont(SkPaint* paint) { | 206 virtual void setFont(SkPaint* paint) { |
207 sk_tool_utils::set_portable_typeface(paint); | 207 sk_tool_utils::set_portable_typeface(paint); |
208 } | 208 } |
(...skipping 29 matching lines...) Expand all Loading... |
238 | 238 |
239 | 239 |
240 SkTArray<SkMatrix> viewMats; | 240 SkTArray<SkMatrix> viewMats; |
241 viewMats.push_back().setScale(0.75f, 0.75f); | 241 viewMats.push_back().setScale(0.75f, 0.75f); |
242 viewMats.push_back().setRotate(45, 50, 50); | 242 viewMats.push_back().setRotate(45, 50, 50); |
243 viewMats.back().postScale(0.5f, 1.1f); | 243 viewMats.back().postScale(0.5f, 1.1f); |
244 | 244 |
245 canvas->translate(10, 20); | 245 canvas->translate(10, 20); |
246 canvas->save(); | 246 canvas->save(); |
247 SkScalar tx = 0, maxTy = 0; | 247 SkScalar tx = 0, maxTy = 0; |
248 static const SkScalar kW = 900; | 248 constexpr SkScalar kW = 900; |
249 | 249 |
250 for (int aa = 0; aa < 2; ++aa) { | 250 for (int aa = 0; aa < 2; ++aa) { |
251 for (int i = 0; i < fPrims.count(); ++i) { | 251 for (int i = 0; i < fPrims.count(); ++i) { |
252 for (int j = 0; j < devMats.count(); ++j) { | 252 for (int j = 0; j < devMats.count(); ++j) { |
253 for (int k = 0; k < viewMats.count(); ++k) { | 253 for (int k = 0; k < viewMats.count(); ++k) { |
254 paint.setShader(sk_make_sp<DCShader>(devMats[j])); | 254 paint.setShader(sk_make_sp<DCShader>(devMats[j])); |
255 paint.setAntiAlias(SkToBool(aa)); | 255 paint.setAntiAlias(SkToBool(aa)); |
256 canvas->save(); | 256 canvas->save(); |
257 canvas->concat(viewMats[k]); | 257 canvas->concat(viewMats[k]); |
258 SkRect bounds = fPrims[i]->draw(canvas, paint); | 258 SkRect bounds = fPrims[i]->draw(canvas, paint); |
(...skipping 26 matching lines...) Expand all Loading... |
285 }; | 285 }; |
286 | 286 |
287 SkTArray<Prim*> fPrims; | 287 SkTArray<Prim*> fPrims; |
288 | 288 |
289 typedef GM INHERITED; | 289 typedef GM INHERITED; |
290 }; | 290 }; |
291 | 291 |
292 DEF_GM(return new DCShaderGM;) | 292 DEF_GM(return new DCShaderGM;) |
293 } | 293 } |
294 #endif | 294 #endif |
OLD | NEW |