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

Side by Side Diff: gm/composeshader.cpp

Issue 1562093002: Remove work from constructors to facilitate debugging. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use valid width and height. Created 4 years, 11 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/blurroundrect.cpp ('k') | gm/rrects.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 2012 Google Inc. 2 * Copyright 2012 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 "SkBitmapProcShader.h" 10 #include "SkBitmapProcShader.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 pts[0].set(0, 0); 155 pts[0].set(0, 0);
156 pts[1].set(SkIntToScalar(length), 0); 156 pts[1].set(SkIntToScalar(length), 0);
157 colors[0] = SK_ColorBLUE; 157 colors[0] = SK_ColorBLUE;
158 colors[1] = SkColorSetARGB(0, 0, 0, 0xFF); 158 colors[1] = SkColorSetARGB(0, 0, 0, 0xFF);
159 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl amp_TileMode); 159 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl amp_TileMode);
160 } 160 }
161 161
162 162
163 class ComposeShaderBitmapGM : public skiagm::GM { 163 class ComposeShaderBitmapGM : public skiagm::GM {
164 public: 164 public:
165 ComposeShaderBitmapGM() 165 ComposeShaderBitmapGM() {}
166 : fColorBitmapShader(nullptr) 166 ~ComposeShaderBitmapGM() {
167 , fAlpha8BitmapShader(nullptr) 167 SkSafeUnref(fColorBitmapShader);
168 , fLinearGradientShader(nullptr) 168 SkSafeUnref(fAlpha8BitmapShader);
169 { 169 SkSafeUnref(fLinearGradientShader);
170 } 170 }
171 171
172 protected:
172 void onOnceBeforeDraw() override { 173 void onOnceBeforeDraw() override {
173 draw_color_bm(&fColorBitmap, squareLength); 174 draw_color_bm(&fColorBitmap, squareLength);
174 draw_alpha8_bm(&fAlpha8Bitmap, squareLength); 175 draw_alpha8_bm(&fAlpha8Bitmap, squareLength);
175 SkMatrix s; 176 SkMatrix s;
176 s.reset(); 177 s.reset();
177 fColorBitmapShader = new SkBitmapProcShader(fColorBitmap, SkShader::kRep eat_TileMode, 178 fColorBitmapShader = new SkBitmapProcShader(fColorBitmap, SkShader::kRep eat_TileMode,
178 SkShader::kRepeat_TileMode, &s); 179 SkShader::kRepeat_TileMode, &s);
179 fAlpha8BitmapShader = new SkBitmapProcShader(fAlpha8Bitmap, SkShader::kR epeat_TileMode, 180 fAlpha8BitmapShader = new SkBitmapProcShader(fAlpha8Bitmap, SkShader::kR epeat_TileMode,
180 SkShader::kRepeat_TileMode, &s); 181 SkShader::kRepeat_TileMode, &s);
181 fLinearGradientShader = make_linear_gradient_shader(squareLength); 182 fLinearGradientShader = make_linear_gradient_shader(squareLength);
182 } 183 }
183 184
184 ~ComposeShaderBitmapGM() {
185 SkSafeUnref(fColorBitmapShader);
186 SkSafeUnref(fAlpha8BitmapShader);
187 SkSafeUnref(fLinearGradientShader);
188 }
189
190 protected:
191 SkString onShortName() override { 185 SkString onShortName() override {
192 return SkString("composeshader_bitmap"); 186 return SkString("composeshader_bitmap");
193 } 187 }
194 188
195 SkISize onISize() override { 189 SkISize onISize() override {
196 return SkISize::Make(7 * (squareLength + 5), 2 * (squareLength + 5)); 190 return SkISize::Make(7 * (squareLength + 5), 2 * (squareLength + 5));
197 } 191 }
198 192
199 void onDraw(SkCanvas* canvas) override { 193 void onDraw(SkCanvas* canvas) override {
200 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mo de)); 194 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mo de));
(...skipping 22 matching lines...) Expand all
223 paint.setAlpha(alpha); 217 paint.setAlpha(alpha);
224 paint.setShader(shader); 218 paint.setShader(shader);
225 canvas->drawRect(r, paint); 219 canvas->drawRect(r, paint);
226 220
227 canvas->translate(r.width() + 5, 0); 221 canvas->translate(r.width() + 5, 0);
228 } 222 }
229 canvas->restore(); 223 canvas->restore();
230 canvas->translate(0, r.height() + 5); 224 canvas->translate(0, r.height() + 5);
231 } 225 }
232 } 226 }
227
233 private: 228 private:
234 /** This determines the length and width of the bitmaps used in the SkCompos eShaders. Values 229 /** This determines the length and width of the bitmaps used in the SkCompos eShaders. Values
235 * above 20 may cause an SkASSERT to fail in SkSmallAllocator. However, lar ger values will 230 * above 20 may cause an SkASSERT to fail in SkSmallAllocator. However, lar ger values will
236 * work in a release build. You can change this parameter and then compile a release build 231 * work in a release build. You can change this parameter and then compile a release build
237 * to have this GM draw larger bitmaps for easier visual inspection. 232 * to have this GM draw larger bitmaps for easier visual inspection.
238 */ 233 */
239 static const int squareLength = 20; 234 static const int squareLength = 20;
240 235
241 SkBitmap fColorBitmap; 236 SkBitmap fColorBitmap;
242 SkBitmap fAlpha8Bitmap; 237 SkBitmap fAlpha8Bitmap;
243 SkShader* fColorBitmapShader; 238 SkShader* fColorBitmapShader{nullptr};
244 SkShader* fAlpha8BitmapShader; 239 SkShader* fAlpha8BitmapShader{nullptr};
245 SkShader* fLinearGradientShader; 240 SkShader* fLinearGradientShader{nullptr};
246 241
247 typedef GM INHERITED; 242 typedef GM INHERITED;
248 }; 243 };
249 244
250 ////////////////////////////////////////////////////////////////////////////// 245 //////////////////////////////////////////////////////////////////////////////
251 246
252 DEF_GM( return new ComposeShaderGM; ) 247 DEF_GM( return new ComposeShaderGM; )
253 DEF_GM( return new ComposeShaderAlphaGM; ) 248 DEF_GM( return new ComposeShaderAlphaGM; )
254 DEF_GM( return new ComposeShaderBitmapGM; ) 249 DEF_GM( return new ComposeShaderBitmapGM; )
OLDNEW
« no previous file with comments | « gm/blurroundrect.cpp ('k') | gm/rrects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698