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

Side by Side Diff: gm/multipicturedraw.cpp

Issue 2300623005: Replace a lot of 'static const' with 'constexpr' or 'const'. (Closed)
Patch Set: small msvc concession Created 4 years, 3 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 | « gm/modecolorfilters.cpp ('k') | gm/nested.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 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 9
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
11 #include "SkMultiPictureDraw.h" 11 #include "SkMultiPictureDraw.h"
12 #include "SkPictureRecorder.h" 12 #include "SkPictureRecorder.h"
13 #include "SkSurface.h" 13 #include "SkSurface.h"
14 14
15 static const SkScalar kRoot3Over2 = 0.86602545f; // sin(60) 15 constexpr SkScalar kRoot3Over2 = 0.86602545f; // sin(60)
16 static const SkScalar kRoot3 = 1.73205081f; 16 constexpr SkScalar kRoot3 = 1.73205081f;
17 17
18 static const int kHexSide = 30; 18 constexpr int kHexSide = 30;
19 static const int kNumHexX = 6; 19 constexpr int kNumHexX = 6;
20 static const int kNumHexY = 6; 20 constexpr int kNumHexY = 6;
21 static const int kPicWidth = kNumHexX * kHexSide; 21 constexpr int kPicWidth = kNumHexX * kHexSide;
22 static const int kPicHeight = SkScalarCeilToInt((kNumHexY - 0.5f) * 2 * kHexSide * kRoot3Over2); 22 constexpr int kPicHeight = (int)((kNumHexY - 0.5f) * 2 * kHexSide * kRoot3Over2 + 0.5f);
23 static const SkScalar kInset = 20.0f; 23 constexpr SkScalar kInset = 20.0f;
24 static const int kNumPictures = 4; 24 constexpr int kNumPictures = 4;
25 25
26 static const int kTriSide = 40; 26 constexpr int kTriSide = 40;
27 27
28 // Create a hexagon centered at (originX, originY) 28 // Create a hexagon centered at (originX, originY)
29 static SkPath make_hex_path(SkScalar originX, SkScalar originY) { 29 static SkPath make_hex_path(SkScalar originX, SkScalar originY) {
30 SkPath hex; 30 SkPath hex;
31 hex.moveTo(originX-kHexSide, originY); 31 hex.moveTo(originX-kHexSide, originY);
32 hex.rLineTo(SkScalarHalf(kHexSide), kRoot3Over2 * kHexSide); 32 hex.rLineTo(SkScalarHalf(kHexSide), kRoot3Over2 * kHexSide);
33 hex.rLineTo(SkIntToScalar(kHexSide), 0); 33 hex.rLineTo(SkIntToScalar(kHexSide), 0);
34 hex.rLineTo(SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2); 34 hex.rLineTo(SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2);
35 hex.rLineTo(-SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2); 35 hex.rLineTo(-SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2);
36 hex.rLineTo(-SkIntToScalar(kHexSide), 0); 36 hex.rLineTo(-SkIntToScalar(kHexSide), 0);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 greyFill.setStyle(SkPaint::kFill_Style); 99 greyFill.setStyle(SkPaint::kFill_Style);
100 greyFill.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY)); 100 greyFill.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY));
101 101
102 SkPaint stroke; 102 SkPaint stroke;
103 stroke.setStyle(SkPaint::kStroke_Style); 103 stroke.setStyle(SkPaint::kStroke_Style);
104 stroke.setStrokeWidth(3); 104 stroke.setStrokeWidth(3);
105 105
106 SkPictureRecorder recorder; 106 SkPictureRecorder recorder;
107 SkRTreeFactory bbhFactory; 107 SkRTreeFactory bbhFactory;
108 108
109 static const SkScalar kBig = 10000.0f; 109 constexpr SkScalar kBig = 10000.0f;
110 SkCanvas* canvas = recorder.beginRecording(kBig, kBig, &bbhFactory); 110 SkCanvas* canvas = recorder.beginRecording(kBig, kBig, &bbhFactory);
111 111
112 canvas->saveLayer(nullptr, nullptr); 112 canvas->saveLayer(nullptr, nullptr);
113 113
114 SkScalar xPos = 0.0f, yPos = 0.0f; 114 SkScalar xPos = 0.0f, yPos = 0.0f;
115 115
116 for (int y = 0; yPos < kBig; ++y) { 116 for (int y = 0; yPos < kBig; ++y) {
117 xPos = 0; 117 xPos = 0;
118 118
119 for (int x = 0; xPos < kBig; ++x) { 119 for (int x = 0; xPos < kBig; ++x) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 static sk_sp<SkPicture> make_sierpinski_picture() { 211 static sk_sp<SkPicture> make_sierpinski_picture() {
212 sk_sp<SkPicture> pic(make_tri_picture()); 212 sk_sp<SkPicture> pic(make_tri_picture());
213 213
214 SkPictureRecorder recorder; 214 SkPictureRecorder recorder;
215 SkRTreeFactory bbhFactory; 215 SkRTreeFactory bbhFactory;
216 216
217 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), 217 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
218 SkIntToScalar(kPicHeight), 218 SkIntToScalar(kPicHeight),
219 &bbhFactory); 219 &bbhFactory);
220 220
221 static const int kNumLevels = 4; 221 constexpr int kNumLevels = 4;
222 for (int i = 0; i < kNumLevels; ++i) { 222 for (int i = 0; i < kNumLevels; ++i) {
223 canvas->save(); 223 canvas->save();
224 canvas->translate(kPicWidth/2 - (i+1) * (kTriSide/2.0f), 0.0f); 224 canvas->translate(kPicWidth/2 - (i+1) * (kTriSide/2.0f), 0.0f);
225 for (int j = 0; j < i+1; ++j) { 225 for (int j = 0; j < i+1; ++j) {
226 canvas->drawPicture(pic); 226 canvas->drawPicture(pic);
227 canvas->translate(SkIntToScalar(kTriSide), 0); 227 canvas->translate(SkIntToScalar(kTriSide), 0);
228 } 228 }
229 canvas->restore(); 229 canvas->restore();
230 230
231 pic = make_sub_picture(pic.get()); 231 pic = make_sub_picture(pic.get());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 canvas->rotate(180.0f); 329 canvas->rotate(180.0f);
330 canvas->translate(-SkIntToScalar(kPicWidth), -SkIntToScalar(kPicHeight)) ; 330 canvas->translate(-SkIntToScalar(kPicWidth), -SkIntToScalar(kPicHeight)) ;
331 canvas->drawPicture(pictures[2]); 331 canvas->drawPicture(pictures[2]);
332 canvas->restore(); 332 canvas->restore();
333 } 333 }
334 334
335 static void big_layer(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) { 335 static void big_layer(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) {
336 canvas->drawPicture(pictures[3]); 336 canvas->drawPicture(pictures[3]);
337 } 337 }
338 338
339 static const PFContentMtd gContentMthds[] = { 339 constexpr PFContentMtd gContentMthds[] = {
340 no_clip, 340 no_clip,
341 rect_clip, 341 rect_clip,
342 rrect_clip, 342 rrect_clip,
343 path_clip, 343 path_clip,
344 invpath_clip, 344 invpath_clip,
345 sierpinski, 345 sierpinski,
346 big_layer, 346 big_layer,
347 }; 347 };
348 348
349 static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen, 349 static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 SkCanvas* subCanvas = step.fSurf->getCanvas(); 384 SkCanvas* subCanvas = step.fSurf->getCanvas();
385 385
386 create_content(mpd, pfGen, pictures, subCanvas, SkMatrix::I()); 386 create_content(mpd, pfGen, pictures, subCanvas, SkMatrix::I());
387 } 387 }
388 388
389 // Draw the content into multiple canvases/tiles 389 // Draw the content into multiple canvases/tiles
390 static void tiled(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, 390 static void tiled(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
391 PFContentMtd pfGen, 391 PFContentMtd pfGen,
392 const SkPicture* pictures[kNumPictures], 392 const SkPicture* pictures[kNumPictures],
393 SkTArray<ComposeStep> *composeSteps) { 393 SkTArray<ComposeStep> *composeSteps) {
394 static const int kNumTilesX = 2; 394 const int kNumTilesX = 2;
395 static const int kNumTilesY = 2; 395 const int kNumTilesY = 2;
396 static const int kTileWidth = kPicWidth / kNumTilesX; 396 const int kTileWidth = kPicWidth / kNumTilesX;
397 static const int kTileHeight = kPicHeight / kNumTilesY; 397 const int kTileHeight = kPicHeight / kNumTilesY;
398 398
399 SkASSERT(kPicWidth == kNumTilesX * kTileWidth); 399 SkASSERT(kPicWidth == kNumTilesX * kTileWidth);
400 SkASSERT(kPicHeight == kNumTilesY * kTileHeight); 400 SkASSERT(kPicHeight == kNumTilesY * kTileHeight);
401 401
402 static const SkColor colors[kNumTilesX][kNumTilesY] = { 402 const SkColor colors[kNumTilesX][kNumTilesY] = {
403 { SK_ColorCYAN, SK_ColorMAGENTA }, 403 { SK_ColorCYAN, SK_ColorMAGENTA },
404 { SK_ColorYELLOW, SK_ColorGREEN } 404 { SK_ColorYELLOW, SK_ColorGREEN }
405 }; 405 };
406 406
407 for (int y = 0; y < kNumTilesY; ++y) { 407 for (int y = 0; y < kNumTilesY; ++y) {
408 for (int x = 0; x < kNumTilesX; ++x) { 408 for (int x = 0; x < kNumTilesX; ++x) {
409 ComposeStep& step = composeSteps->push_back(); 409 ComposeStep& step = composeSteps->push_back();
410 410
411 step.fX = SkIntToScalar(x*kTileWidth); 411 step.fX = SkIntToScalar(x*kTileWidth);
412 step.fY = SkIntToScalar(y*kTileHeight); 412 step.fY = SkIntToScalar(y*kTileHeight);
413 step.fPaint = new SkPaint; 413 step.fPaint = new SkPaint;
414 step.fPaint->setColorFilter( 414 step.fPaint->setColorFilter(
415 SkColorFilter::MakeModeFilter(colors[x][y], SkXfermode::kModulat e_Mode)); 415 SkColorFilter::MakeModeFilter(colors[x][y], SkXfermode::kModulat e_Mode));
416 416
417 step.fSurf = create_compat_surface(finalCanvas, kTileWidth, kTileHei ght); 417 step.fSurf = create_compat_surface(finalCanvas, kTileWidth, kTileHei ght);
418 418
419 SkCanvas* subCanvas = step.fSurf->getCanvas(); 419 SkCanvas* subCanvas = step.fSurf->getCanvas();
420 420
421 const SkMatrix trans = SkMatrix::MakeTrans(-SkIntToScalar(x*kTileWid th), 421 const SkMatrix trans = SkMatrix::MakeTrans(-SkIntToScalar(x*kTileWid th),
422 -SkIntToScalar(y*kTileHei ght)); 422 -SkIntToScalar(y*kTileHei ght));
423 423
424 create_content(mpd, pfGen, pictures, subCanvas, trans); 424 create_content(mpd, pfGen, pictures, subCanvas, trans);
425 } 425 }
426 } 426 }
427 } 427 }
428 428
429 static const PFLayoutMtd gLayoutMthds[] = { simple, tiled }; 429 constexpr PFLayoutMtd gLayoutMthds[] = { simple, tiled };
430 430
431 namespace skiagm { 431 namespace skiagm {
432 /** 432 /**
433 * This GM exercises the SkMultiPictureDraw object. It tests the 433 * This GM exercises the SkMultiPictureDraw object. It tests the
434 * cross product of: 434 * cross product of:
435 * tiled vs. all-at-once rendering (e.g., into many or just 1 canvas) 435 * tiled vs. all-at-once rendering (e.g., into many or just 1 canvas)
436 * different clips (e.g., none, rect, rrect) 436 * different clips (e.g., none, rect, rrect)
437 * single vs. multiple pictures (e.g., normal vs. picture-pile-style co ntent) 437 * single vs. multiple pictures (e.g., normal vs. picture-pile-style co ntent)
438 */ 438 */
439 class MultiPictureDraw : public GM { 439 class MultiPictureDraw : public GM {
440 public: 440 public:
441 enum Content { 441 enum Content {
442 kNoClipSingle_Content, 442 kNoClipSingle_Content,
443 kRectClipMulti_Content, 443 kRectClipMulti_Content,
444 kRRectClipMulti_Content, 444 kRRectClipMulti_Content,
445 kPathClipMulti_Content, 445 kPathClipMulti_Content,
446 kInvPathClipMulti_Content, 446 kInvPathClipMulti_Content,
447 kSierpinski_Content, 447 kSierpinski_Content,
448 kBigLayer_Content, 448 kBigLayer_Content,
449 449
450 kLast_Content = kBigLayer_Content 450 kLast_Content = kBigLayer_Content
451 }; 451 };
452 452
453 static const int kContentCnt = kLast_Content + 1; 453 const int kContentCnt = kLast_Content + 1;
454 454
455 enum Layout { 455 enum Layout {
456 kSimple_Layout, 456 kSimple_Layout,
457 kTiled_Layout, 457 kTiled_Layout,
458 458
459 kLast_Layout = kTiled_Layout 459 kLast_Layout = kTiled_Layout
460 }; 460 };
461 461
462 static const int kLayoutCnt = kLast_Layout + 1; 462 const int kLayoutCnt = kLast_Layout + 1;
463 463
464 MultiPictureDraw(Content content, Layout layout) : fContent(content), fL ayout(layout) { 464 MultiPictureDraw(Content content, Layout layout) : fContent(content), fL ayout(layout) {
465 SkASSERT(SK_ARRAY_COUNT(gLayoutMthds) == kLayoutCnt); 465 SkASSERT(SK_ARRAY_COUNT(gLayoutMthds) == kLayoutCnt);
466 SkASSERT(SK_ARRAY_COUNT(gContentMthds) == kContentCnt); 466 SkASSERT(SK_ARRAY_COUNT(gContentMthds) == kContentCnt);
467 467
468 for (int i = 0; i < kNumPictures; ++i) { 468 for (int i = 0; i < kNumPictures; ++i) {
469 fPictures[i] = nullptr; 469 fPictures[i] = nullptr;
470 } 470 }
471 } 471 }
472 472
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 const ComposeStep& step = composeSteps[i]; 504 const ComposeStep& step = composeSteps[i];
505 505
506 canvas->drawImage(step.fSurf->makeImageSnapshot().get(), 506 canvas->drawImage(step.fSurf->makeImageSnapshot().get(),
507 step.fX, step.fY, step.fPaint); 507 step.fX, step.fY, step.fPaint);
508 } 508 }
509 } 509 }
510 510
511 SkISize onISize() override { return SkISize::Make(kPicWidth, kPicHeight) ; } 511 SkISize onISize() override { return SkISize::Make(kPicWidth, kPicHeight) ; }
512 512
513 SkString onShortName() override { 513 SkString onShortName() override {
514 static const char* gContentNames[] = { 514 const char* gContentNames[] = {
515 "noclip", "rectclip", "rrectclip", "pathclip", 515 "noclip", "rectclip", "rrectclip", "pathclip",
516 "invpathclip", "sierpinski", "biglayer" 516 "invpathclip", "sierpinski", "biglayer"
517 }; 517 };
518 static const char* gLayoutNames[] = { "simple", "tiled" }; 518 const char* gLayoutNames[] = { "simple", "tiled" };
519 519
520 SkASSERT(SK_ARRAY_COUNT(gLayoutNames) == kLayoutCnt); 520 SkASSERT(SK_ARRAY_COUNT(gLayoutNames) == kLayoutCnt);
521 SkASSERT(SK_ARRAY_COUNT(gContentNames) == kContentCnt); 521 SkASSERT(SK_ARRAY_COUNT(gContentNames) == kContentCnt);
522 522
523 SkString name("multipicturedraw_"); 523 SkString name("multipicturedraw_");
524 524
525 name.append(gContentNames[fContent]); 525 name.append(gContentNames[fContent]);
526 name.append("_"); 526 name.append("_");
527 name.append(gLayoutNames[fLayout]); 527 name.append(gLayoutNames[fLayout]);
528 return name; 528 return name;
(...skipping 28 matching lines...) Expand all
557 MultiPictureDraw::kTiled_Layout);) 557 MultiPictureDraw::kTiled_Layout);)
558 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kPathClipMulti_Content, 558 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kPathClipMulti_Content,
559 MultiPictureDraw::kTiled_Layout);) 559 MultiPictureDraw::kTiled_Layout);)
560 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kInvPathClipMulti_Conte nt, 560 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kInvPathClipMulti_Conte nt,
561 MultiPictureDraw::kTiled_Layout);) 561 MultiPictureDraw::kTiled_Layout);)
562 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kSierpinski_Content, 562 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kSierpinski_Content,
563 MultiPictureDraw::kTiled_Layout);) 563 MultiPictureDraw::kTiled_Layout);)
564 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kBigLayer_Content, 564 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kBigLayer_Content,
565 MultiPictureDraw::kTiled_Layout);) 565 MultiPictureDraw::kTiled_Layout);)
566 } 566 }
OLDNEW
« no previous file with comments | « gm/modecolorfilters.cpp ('k') | gm/nested.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698