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

Side by Side Diff: gm/colormatrix.cpp

Issue 140593005: add legacy/helper allocN32Pixels, and convert gm to use it (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « gm/clippedbitmapshaders.cpp ('k') | gm/deviceproperties.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 "gm.h" 8 #include "gm.h"
9 #include "SkColorMatrixFilter.h" 9 #include "SkColorMatrixFilter.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 virtual SkString onShortName() { 56 virtual SkString onShortName() {
57 return SkString("colormatrix"); 57 return SkString("colormatrix");
58 } 58 }
59 59
60 virtual SkISize onISize() { 60 virtual SkISize onISize() {
61 return make_isize(WIDTH, HEIGHT); 61 return make_isize(WIDTH, HEIGHT);
62 } 62 }
63 63
64 SkBitmap createSolidBitmap(int width, int height) { 64 SkBitmap createSolidBitmap(int width, int height) {
65 SkBitmap bm; 65 SkBitmap bm;
66 bm.setConfig(SkBitmap::kARGB_8888_Config, width, height); 66 bm.allocN32Pixels(width, height);
67 bm.allocPixels();
68 SkCanvas canvas(bm); 67 SkCanvas canvas(bm);
69 canvas.clear(0x0); 68 canvas.clear(0x0);
70 for (int y = 0; y < height; ++y) { 69 for (int y = 0; y < height; ++y) {
71 for (int x = 0; x < width; ++x) { 70 for (int x = 0; x < width; ++x) {
72 SkPaint paint; 71 SkPaint paint;
73 paint.setColor(SkColorSetARGB(255, x * 255 / width, y * 255 / he ight, 0)); 72 paint.setColor(SkColorSetARGB(255, x * 255 / width, y * 255 / he ight, 0));
74 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(x), 73 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(x),
75 SkIntToScalar(y), SK_Scalar1, SK_Scalar1), paint); 74 SkIntToScalar(y), SK_Scalar1, SK_Scalar1), paint);
76 } 75 }
77 } 76 }
78 return bm; 77 return bm;
79 } 78 }
80 79
81 // creates a bitmap with shades of transparent gray. 80 // creates a bitmap with shades of transparent gray.
82 SkBitmap createTransparentBitmap(int width, int height) { 81 SkBitmap createTransparentBitmap(int width, int height) {
83 SkBitmap bm; 82 SkBitmap bm;
84 bm.setConfig(SkBitmap::kARGB_8888_Config, width, height); 83 bm.allocN32Pixels(width, height);
85 bm.allocPixels();
86 SkCanvas canvas(bm); 84 SkCanvas canvas(bm);
87 canvas.clear(0x0); 85 canvas.clear(0x0);
88 86
89 SkPoint pts[] = {{0, 0}, {SkIntToScalar(width), SkIntToScalar(height)}}; 87 SkPoint pts[] = {{0, 0}, {SkIntToScalar(width), SkIntToScalar(height)}};
90 SkColor colors[] = {0x00000000, 0xFFFFFFFF}; 88 SkColor colors[] = {0x00000000, 0xFFFFFFFF};
91 SkPaint paint; 89 SkPaint paint;
92 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2, 90 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2,
93 SkShader::kClamp_TileMode ))->unref(); 91 SkShader::kClamp_TileMode ))->unref();
94 canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh t)), paint); 92 canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh t)), paint);
95 return bm; 93 return bm;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 SkBitmap fTransparentBitmap; 166 SkBitmap fTransparentBitmap;
169 typedef GM INHERITED; 167 typedef GM INHERITED;
170 }; 168 };
171 169
172 ////////////////////////////////////////////////////////////////////////////// 170 //////////////////////////////////////////////////////////////////////////////
173 171
174 static GM* MyFactory(void*) { return new ColorMatrixGM; } 172 static GM* MyFactory(void*) { return new ColorMatrixGM; }
175 static GMRegistry reg(MyFactory); 173 static GMRegistry reg(MyFactory);
176 174
177 } 175 }
OLDNEW
« no previous file with comments | « gm/clippedbitmapshaders.cpp ('k') | gm/deviceproperties.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698