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

Side by Side Diff: gm/imagefromyuvtextures.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/imageblur2.cpp ('k') | gm/imagemagnifier.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 2015 Google Inc. 2 * Copyright 2015 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 20 matching lines...) Expand all
31 } 31 }
32 32
33 SkISize onISize() override { 33 SkISize onISize() override {
34 return SkISize::Make(50, 175); 34 return SkISize::Make(50, 175);
35 } 35 }
36 36
37 void onOnceBeforeDraw() override { 37 void onOnceBeforeDraw() override {
38 // We create an RGB bitmap and then extract YUV bmps where the U and V b itmaps are 38 // We create an RGB bitmap and then extract YUV bmps where the U and V b itmaps are
39 // subsampled by 2 in both dimensions. 39 // subsampled by 2 in both dimensions.
40 SkPaint paint; 40 SkPaint paint;
41 static const SkColor kColors[] = 41 constexpr SkColor kColors[] =
42 { SK_ColorBLUE, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorWHITE }; 42 { SK_ColorBLUE, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorWHITE };
43 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(0,0), kBmpSiz e / 2.f, kColors, 43 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(0,0), kBmpSiz e / 2.f, kColors,
44 nullptr, SK_ARRAY_COUNT(kCo lors), 44 nullptr, SK_ARRAY_COUNT(kCo lors),
45 SkShader::kMirror_TileMode) ); 45 SkShader::kMirror_TileMode) );
46 SkBitmap rgbBmp; 46 SkBitmap rgbBmp;
47 rgbBmp.allocN32Pixels(kBmpSize, kBmpSize, true); 47 rgbBmp.allocN32Pixels(kBmpSize, kBmpSize, true);
48 SkCanvas canvas(rgbBmp); 48 SkCanvas canvas(rgbBmp);
49 canvas.drawPaint(paint); 49 canvas.drawPaint(paint);
50 SkPMColor* rgbColors = static_cast<SkPMColor*>(rgbBmp.getPixels()); 50 SkPMColor* rgbColors = static_cast<SkPMColor*>(rgbBmp.getPixels());
51 51
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 void onDraw(SkCanvas* canvas) override { 126 void onDraw(SkCanvas* canvas) override {
127 GrContext* context = canvas->getGrContext(); 127 GrContext* context = canvas->getGrContext();
128 if (!context) { 128 if (!context) {
129 skiagm::GM::DrawGpuOnlyMessage(canvas); 129 skiagm::GM::DrawGpuOnlyMessage(canvas);
130 return; 130 return;
131 } 131 }
132 132
133 133
134 static const SkScalar kPad = 10.f; 134 constexpr SkScalar kPad = 10.f;
135 135
136 SkISize sizes[] = { 136 SkISize sizes[] = {
137 { fYUVBmps[0].width(), fYUVBmps[0].height()}, 137 { fYUVBmps[0].width(), fYUVBmps[0].height()},
138 { fYUVBmps[1].width(), fYUVBmps[1].height()}, 138 { fYUVBmps[1].width(), fYUVBmps[1].height()},
139 { fYUVBmps[2].width(), fYUVBmps[2].height()}, 139 { fYUVBmps[2].width(), fYUVBmps[2].height()},
140 }; 140 };
141 SkTArray<sk_sp<SkImage>> images; 141 SkTArray<sk_sp<SkImage>> images;
142 images.push_back(fRGBImage); 142 images.push_back(fRGBImage);
143 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa ce; ++space) { 143 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa ce; ++space) {
144 GrBackendObject yuvHandles[3]; 144 GrBackendObject yuvHandles[3];
145 this->createYUVTextures(context, yuvHandles); 145 this->createYUVTextures(context, yuvHandles);
146 images.push_back(SkImage::MakeFromYUVTexturesCopy(context, 146 images.push_back(SkImage::MakeFromYUVTexturesCopy(context,
147 static_cast<SkYUVC olorSpace>(space), 147 static_cast<SkYUVC olorSpace>(space),
148 yuvHandles, sizes, 148 yuvHandles, sizes,
149 kTopLeft_GrSurface Origin)); 149 kTopLeft_GrSurface Origin));
150 this->deleteYUVTextures(context, yuvHandles); 150 this->deleteYUVTextures(context, yuvHandles);
151 } 151 }
152 for (int i = 0; i < images.count(); ++ i) { 152 for (int i = 0; i < images.count(); ++ i) {
153 SkScalar y = (i + 1) * kPad + i * fYUVBmps[0].height(); 153 SkScalar y = (i + 1) * kPad + i * fYUVBmps[0].height();
154 SkScalar x = kPad; 154 SkScalar x = kPad;
155 155
156 canvas->drawImage(images[i].get(), x, y); 156 canvas->drawImage(images[i].get(), x, y);
157 } 157 }
158 } 158 }
159 159
160 private: 160 private:
161 sk_sp<SkImage> fRGBImage; 161 sk_sp<SkImage> fRGBImage;
162 SkBitmap fYUVBmps[3]; 162 SkBitmap fYUVBmps[3];
163 163
164 static const int kBmpSize = 32; 164 static constexpr int kBmpSize = 32;
165 165
166 typedef GM INHERITED; 166 typedef GM INHERITED;
167 }; 167 };
168 168
169 DEF_GM(return new ImageFromYUVTextures;) 169 DEF_GM(return new ImageFromYUVTextures;)
170 } 170 }
171 171
172 #endif 172 #endif
OLDNEW
« no previous file with comments | « gm/imageblur2.cpp ('k') | gm/imagemagnifier.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698