Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: gm/beziereffects.cpp

Issue 1930623003: Clean up test drawContext usage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix typo Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gm/bigrrectaaeffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 // This test only works with the GPU backend. 8 // This test only works with the GPU backend.
9 9
10 #include "gm.h" 10 #include "gm.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 protected: 92 protected:
93 SkString onShortName() override { 93 SkString onShortName() override {
94 return SkString("bezier_cubic_effects"); 94 return SkString("bezier_cubic_effects");
95 } 95 }
96 96
97 SkISize onISize() override { 97 SkISize onISize() override {
98 return SkISize::Make(800, 800); 98 return SkISize::Make(800, 800);
99 } 99 }
100 100
101 void onDraw(SkCanvas* canvas) override { 101 void onDraw(SkCanvas* canvas) override {
102 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 102 GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDraw Context();
103 if (nullptr == rt) { 103 if (!drawContext) {
104 skiagm::GM::DrawGpuOnlyMessage(canvas); 104 skiagm::GM::DrawGpuOnlyMessage(canvas);
105 return; 105 return;
106 } 106 }
107 GrContext* context = rt->getContext(); 107
108 if (nullptr == context) { 108 GrContext* context = canvas->getGrContext();
109 if (!context) {
109 return; 110 return;
110 } 111 }
111 112
112 sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
113 if (!drawContext) {
114 return;
115 }
116
117 struct Vertex { 113 struct Vertex {
118 SkPoint fPosition; 114 SkPoint fPosition;
119 float fKLM[4]; // The last value is ignored. The effect expects a vec4f. 115 float fKLM[4]; // The last value is ignored. The effect expects a vec4f.
120 }; 116 };
121 117
122 static const int kNumCubics = 15; 118 static const int kNumCubics = 15;
123 SkRandom rand; 119 SkRandom rand;
124 120
125 // Mult by 3 for each edge effect type 121 // Mult by 3 for each edge effect type
126 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3) )); 122 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3) ));
127 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols); 123 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols);
128 SkScalar w = SkIntToScalar(rt->width()) / numCols; 124 SkScalar w = SkIntToScalar(drawContext->width()) / numCols;
129 SkScalar h = SkIntToScalar(rt->height()) / numRows; 125 SkScalar h = SkIntToScalar(drawContext->height()) / numRows;
130 int row = 0; 126 int row = 0;
131 int col = 0; 127 int col = 0;
132 static const GrColor color = 0xff000000; 128 static const GrColor color = 0xff000000;
133 129
134 for (int i = 0; i < kNumCubics; ++i) { 130 for (int i = 0; i < kNumCubics; ++i) {
135 SkPoint baseControlPts[] = { 131 SkPoint baseControlPts[] = {
136 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 132 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
137 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 133 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
138 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 134 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
139 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} 135 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 185
190 SkPaint boundsPaint; 186 SkPaint boundsPaint;
191 boundsPaint.setColor(0xff808080); 187 boundsPaint.setColor(0xff808080);
192 boundsPaint.setStrokeWidth(0); 188 boundsPaint.setStrokeWidth(0);
193 boundsPaint.setStyle(SkPaint::kStroke_Style); 189 boundsPaint.setStyle(SkPaint::kStroke_Style);
194 canvas->drawRect(bounds, boundsPaint); 190 canvas->drawRect(bounds, boundsPaint);
195 191
196 GrPipelineBuilder pipelineBuilder; 192 GrPipelineBuilder pipelineBuilder;
197 pipelineBuilder.setXPFactory( 193 pipelineBuilder.setXPFactory(
198 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref(); 194 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref();
199 pipelineBuilder.setRenderTarget(rt); 195 pipelineBuilder.setRenderTarget(drawContext->accessRenderTar get());
200 196
201 SkAutoTUnref<GrDrawBatch> batch( 197 SkAutoTUnref<GrDrawBatch> batch(
202 new BezierCubicOrConicTestBatch(gp, bounds, color, klmEq s, klmSigns[c])); 198 new BezierCubicOrConicTestBatch(gp, bounds, color, klmEq s, klmSigns[c]));
203 199
204 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch); 200 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch);
205 } 201 }
206 ++col; 202 ++col;
207 if (numCols == col) { 203 if (numCols == col) {
208 col = 0; 204 col = 0;
209 ++row; 205 ++row;
(...skipping 21 matching lines...) Expand all
231 SkString onShortName() override { 227 SkString onShortName() override {
232 return SkString("bezier_conic_effects"); 228 return SkString("bezier_conic_effects");
233 } 229 }
234 230
235 SkISize onISize() override { 231 SkISize onISize() override {
236 return SkISize::Make(800, 800); 232 return SkISize::Make(800, 800);
237 } 233 }
238 234
239 235
240 void onDraw(SkCanvas* canvas) override { 236 void onDraw(SkCanvas* canvas) override {
241 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 237 GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDraw Context();
242 if (nullptr == rt) { 238 if (!drawContext) {
243 skiagm::GM::DrawGpuOnlyMessage(canvas); 239 skiagm::GM::DrawGpuOnlyMessage(canvas);
244 return; 240 return;
245 } 241 }
246 GrContext* context = rt->getContext(); 242
247 if (nullptr == context) { 243 GrContext* context = canvas->getGrContext();
244 if (!context) {
248 return; 245 return;
249 } 246 }
250 247
251 sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
252 if (!drawContext) {
253 return;
254 }
255
256 struct Vertex { 248 struct Vertex {
257 SkPoint fPosition; 249 SkPoint fPosition;
258 float fKLM[4]; // The last value is ignored. The effect expects a vec4f. 250 float fKLM[4]; // The last value is ignored. The effect expects a vec4f.
259 }; 251 };
260 252
261 static const int kNumConics = 10; 253 static const int kNumConics = 10;
262 SkRandom rand; 254 SkRandom rand;
263 255
264 // Mult by 3 for each edge effect type 256 // Mult by 3 for each edge effect type
265 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3) )); 257 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3) ));
266 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols); 258 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols);
267 SkScalar w = SkIntToScalar(rt->width()) / numCols; 259 SkScalar w = SkIntToScalar(drawContext->width()) / numCols;
268 SkScalar h = SkIntToScalar(rt->height()) / numRows; 260 SkScalar h = SkIntToScalar(drawContext->height()) / numRows;
269 int row = 0; 261 int row = 0;
270 int col = 0; 262 int col = 0;
271 static const GrColor color = 0xff000000; 263 static const GrColor color = 0xff000000;
272 264
273 for (int i = 0; i < kNumConics; ++i) { 265 for (int i = 0; i < kNumConics; ++i) {
274 SkPoint baseControlPts[] = { 266 SkPoint baseControlPts[] = {
275 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 267 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
276 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 268 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
277 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} 269 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}
278 }; 270 };
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 318
327 SkPaint boundsPaint; 319 SkPaint boundsPaint;
328 boundsPaint.setColor(0xff808080); 320 boundsPaint.setColor(0xff808080);
329 boundsPaint.setStrokeWidth(0); 321 boundsPaint.setStrokeWidth(0);
330 boundsPaint.setStyle(SkPaint::kStroke_Style); 322 boundsPaint.setStyle(SkPaint::kStroke_Style);
331 canvas->drawRect(bounds, boundsPaint); 323 canvas->drawRect(bounds, boundsPaint);
332 324
333 GrPipelineBuilder pipelineBuilder; 325 GrPipelineBuilder pipelineBuilder;
334 pipelineBuilder.setXPFactory( 326 pipelineBuilder.setXPFactory(
335 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref(); 327 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref();
336 pipelineBuilder.setRenderTarget(rt); 328 pipelineBuilder.setRenderTarget(drawContext->accessRenderTar get());
337 329
338 SkAutoTUnref<GrDrawBatch> batch( 330 SkAutoTUnref<GrDrawBatch> batch(
339 new BezierCubicOrConicTestBatch(gp, bounds, color, klmEq s, 1.f)); 331 new BezierCubicOrConicTestBatch(gp, bounds, color, klmEq s, 1.f));
340 332
341 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch); 333 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch);
342 } 334 }
343 ++col; 335 ++col;
344 if (numCols == col) { 336 if (numCols == col) {
345 col = 0; 337 col = 0;
346 ++row; 338 ++row;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 SkString onShortName() override { 440 SkString onShortName() override {
449 return SkString("bezier_quad_effects"); 441 return SkString("bezier_quad_effects");
450 } 442 }
451 443
452 SkISize onISize() override { 444 SkISize onISize() override {
453 return SkISize::Make(800, 800); 445 return SkISize::Make(800, 800);
454 } 446 }
455 447
456 448
457 void onDraw(SkCanvas* canvas) override { 449 void onDraw(SkCanvas* canvas) override {
458 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 450 GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDraw Context();
459 if (nullptr == rt) { 451 if (!drawContext) {
460 skiagm::GM::DrawGpuOnlyMessage(canvas); 452 skiagm::GM::DrawGpuOnlyMessage(canvas);
461 return; 453 return;
462 } 454 }
463 GrContext* context = rt->getContext(); 455
464 if (nullptr == context) { 456 GrContext* context = canvas->getGrContext();
457 if (!context) {
465 return; 458 return;
466 } 459 }
467 460
468 sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
469 if (!drawContext) {
470 return;
471 }
472
473 struct Vertex { 461 struct Vertex {
474 SkPoint fPosition; 462 SkPoint fPosition;
475 float fUV[4]; // The last two values are ignored. The effect expec ts a vec4f. 463 float fUV[4]; // The last two values are ignored. The effect expec ts a vec4f.
476 }; 464 };
477 465
478 static const int kNumQuads = 5; 466 static const int kNumQuads = 5;
479 SkRandom rand; 467 SkRandom rand;
480 468
481 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3)) ); 469 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3)) );
482 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols); 470 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols);
483 SkScalar w = SkIntToScalar(rt->width()) / numCols; 471 SkScalar w = SkIntToScalar(drawContext->width()) / numCols;
484 SkScalar h = SkIntToScalar(rt->height()) / numRows; 472 SkScalar h = SkIntToScalar(drawContext->height()) / numRows;
485 int row = 0; 473 int row = 0;
486 int col = 0; 474 int col = 0;
487 static const GrColor color = 0xff000000; 475 static const GrColor color = 0xff000000;
488 476
489 for (int i = 0; i < kNumQuads; ++i) { 477 for (int i = 0; i < kNumQuads; ++i) {
490 SkPoint baseControlPts[] = { 478 SkPoint baseControlPts[] = {
491 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 479 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
492 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 480 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
493 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} 481 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}
494 }; 482 };
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 526
539 SkPaint boundsPaint; 527 SkPaint boundsPaint;
540 boundsPaint.setColor(0xff808080); 528 boundsPaint.setColor(0xff808080);
541 boundsPaint.setStrokeWidth(0); 529 boundsPaint.setStrokeWidth(0);
542 boundsPaint.setStyle(SkPaint::kStroke_Style); 530 boundsPaint.setStyle(SkPaint::kStroke_Style);
543 canvas->drawRect(bounds, boundsPaint); 531 canvas->drawRect(bounds, boundsPaint);
544 532
545 GrPipelineBuilder pipelineBuilder; 533 GrPipelineBuilder pipelineBuilder;
546 pipelineBuilder.setXPFactory( 534 pipelineBuilder.setXPFactory(
547 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref(); 535 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u nref();
548 pipelineBuilder.setRenderTarget(rt); 536 pipelineBuilder.setRenderTarget(drawContext->accessRenderTar get());
549 537
550 GrPathUtils::QuadUVMatrix DevToUV(pts); 538 GrPathUtils::QuadUVMatrix DevToUV(pts);
551 539
552 SkAutoTUnref<GrDrawBatch> batch( 540 SkAutoTUnref<GrDrawBatch> batch(
553 new BezierQuadTestBatch(gp, bounds, color, DevToUV)); 541 new BezierQuadTestBatch(gp, bounds, color, DevToUV));
554 542
555 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch); 543 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch);
556 } 544 }
557 ++col; 545 ++col;
558 if (numCols == col) { 546 if (numCols == col) {
559 col = 0; 547 col = 0;
560 ++row; 548 ++row;
561 } 549 }
562 } 550 }
563 } 551 }
564 } 552 }
565 553
566 private: 554 private:
567 typedef GM INHERITED; 555 typedef GM INHERITED;
568 }; 556 };
569 557
570 DEF_GM(return new BezierCubicEffects;) 558 DEF_GM(return new BezierCubicEffects;)
571 DEF_GM(return new BezierConicEffects;) 559 DEF_GM(return new BezierConicEffects;)
572 DEF_GM(return new BezierQuadEffects;) 560 DEF_GM(return new BezierQuadEffects;)
573 } 561 }
574 562
575 #endif 563 #endif
OLDNEW
« no previous file with comments | « no previous file | gm/bigrrectaaeffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698