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

Side by Side Diff: gm/image.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/hairmodes.cpp ('k') | gm/imageblur2.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 2011 Google Inc. 2 * Copyright 2011 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 <functional> 8 #include <functional>
9 #include "gm.h" 9 #include "gm.h"
10 #include "SkAutoPixmapStorage.h" 10 #include "SkAutoPixmapStorage.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 SkISize onISize() override { 126 SkISize onISize() override {
127 return SkISize::Make(960, 1200); 127 return SkISize::Make(960, 1200);
128 } 128 }
129 129
130 void onDraw(SkCanvas* canvas) override { 130 void onDraw(SkCanvas* canvas) override {
131 drawJpeg(canvas, this->getISize()); 131 drawJpeg(canvas, this->getISize());
132 132
133 canvas->scale(2, 2); 133 canvas->scale(2, 2);
134 134
135 static const char* kLabel1 = "Original Img"; 135 const char* kLabel1 = "Original Img";
136 static const char* kLabel2 = "Modified Img"; 136 const char* kLabel2 = "Modified Img";
137 static const char* kLabel3 = "Cur Surface"; 137 const char* kLabel3 = "Cur Surface";
138 static const char* kLabel4 = "Full Crop"; 138 const char* kLabel4 = "Full Crop";
139 static const char* kLabel5 = "Over-crop"; 139 const char* kLabel5 = "Over-crop";
140 static const char* kLabel6 = "Upper-left"; 140 const char* kLabel6 = "Upper-left";
141 static const char* kLabel7 = "No Crop"; 141 const char* kLabel7 = "No Crop";
142 142
143 static const char* kLabel8 = "Pre-Alloc Img"; 143 const char* kLabel8 = "Pre-Alloc Img";
144 static const char* kLabel9 = "New Alloc Img"; 144 const char* kLabel9 = "New Alloc Img";
145 static const char* kLabel10 = "GPU"; 145 const char* kLabel10 = "GPU";
146 146
147 SkPaint textPaint; 147 SkPaint textPaint;
148 textPaint.setAntiAlias(true); 148 textPaint.setAntiAlias(true);
149 sk_tool_utils::set_portable_typeface(&textPaint); 149 sk_tool_utils::set_portable_typeface(&textPaint);
150 textPaint.setTextSize(8); 150 textPaint.setTextSize(8);
151 151
152 canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint); 152 canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint);
153 canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint); 153 canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint);
154 canvas->drawText(kLabel3, strlen(kLabel3), 10, 220, textPaint); 154 canvas->drawText(kLabel3, strlen(kLabel3), 10, 220, textPaint);
155 canvas->drawText(kLabel4, strlen(kLabel4), 10, 300, textPaint); 155 canvas->drawText(kLabel4, strlen(kLabel4), 10, 300, textPaint);
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 paint.setColor(SK_ColorRED); 446 paint.setColor(SK_ColorRED);
447 canvas->drawRect(SkRect::MakeXYWH(10.f,10.f,10.f,10.f), paint); 447 canvas->drawRect(SkRect::MakeXYWH(10.f,10.f,10.f,10.f), paint);
448 paint.setColor(SK_ColorGREEN); 448 paint.setColor(SK_ColorGREEN);
449 canvas->drawRect(SkRect::MakeXYWH(30.f,10.f,10.f,10.f), paint); 449 canvas->drawRect(SkRect::MakeXYWH(30.f,10.f,10.f,10.f), paint);
450 paint.setColor(SK_ColorYELLOW); 450 paint.setColor(SK_ColorYELLOW);
451 canvas->drawRect(SkRect::MakeXYWH(10.f,30.f,10.f,10.f), paint); 451 canvas->drawRect(SkRect::MakeXYWH(10.f,30.f,10.f,10.f), paint);
452 paint.setColor(SK_ColorCYAN); 452 paint.setColor(SK_ColorCYAN);
453 canvas->drawRect(SkRect::MakeXYWH(30.f,30.f,10.f,10.f), paint); 453 canvas->drawRect(SkRect::MakeXYWH(30.f,30.f,10.f,10.f), paint);
454 }; 454 };
455 455
456 static const int kSize = 50; 456 static constexpr int kSize = 50;
457 SkBitmap bmp; 457 SkBitmap bmp;
458 bmp.allocN32Pixels(kSize, kSize); 458 bmp.allocN32Pixels(kSize, kSize);
459 SkCanvas bmpCanvas(bmp); 459 SkCanvas bmpCanvas(bmp);
460 render_image(&bmpCanvas); 460 render_image(&bmpCanvas);
461 461
462 std::function<sk_sp<SkImage>()> imageFactories[] = { 462 std::function<sk_sp<SkImage>()> imageFactories[] = {
463 // Create sw raster image. 463 // Create sw raster image.
464 [bmp] { 464 [bmp] {
465 return SkImage::MakeFromBitmap(bmp); 465 return SkImage::MakeFromBitmap(bmp);
466 }, 466 },
(...skipping 17 matching lines...) Expand all
484 SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, 484 SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
485 SkImageInfo::MakeN32Premul(kSize, kS ize))); 485 SkImageInfo::MakeN32Premul(kSize, kS ize)));
486 if (!surface) { 486 if (!surface) {
487 return nullptr; 487 return nullptr;
488 } 488 }
489 render_image(surface->getCanvas()); 489 render_image(surface->getCanvas());
490 return surface->makeImageSnapshot(); 490 return surface->makeImageSnapshot();
491 } 491 }
492 }; 492 };
493 493
494 static const SkScalar kPad = 5.f; 494 constexpr SkScalar kPad = 5.f;
495 canvas->translate(kPad, kPad); 495 canvas->translate(kPad, kPad);
496 for (auto factory : imageFactories) { 496 for (auto factory : imageFactories) {
497 auto image(factory()); 497 auto image(factory());
498 if (!image) { 498 if (!image) {
499 continue; 499 continue;
500 } 500 }
501 if (context) { 501 if (context) {
502 sk_sp<SkImage> texImage(image->makeTextureImage(context)); 502 sk_sp<SkImage> texImage(image->makeTextureImage(context));
503 if (texImage) { 503 if (texImage) {
504 canvas->drawImage(texImage, 0, 0); 504 canvas->drawImage(texImage, 0, 0);
505 } 505 }
506 } 506 }
507 canvas->translate(image->width() + kPad, 0); 507 canvas->translate(image->width() + kPad, 0);
508 } 508 }
509 } 509 }
OLDNEW
« no previous file with comments | « gm/hairmodes.cpp ('k') | gm/imageblur2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698