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

Side by Side Diff: gm/aaclip.cpp

Issue 159723006: add peekPixels to canvas (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | « no previous file | gm/bitmapcopy.cpp » ('j') | include/core/SkCanvas.h » ('J')
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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
11 #include "SkSurface.h"
11 12
12 static void test_quadstroke(SkCanvas* canvas) { 13 static void test_quadstroke(SkCanvas* canvas) {
13 SkPath path; 14 SkPath path;
14 path.moveTo(6, 0); 15 path.moveTo(6, 0);
15 path.quadTo(150, 150, 0, 6); 16 path.quadTo(150, 150, 0, 6);
16 17
17 SkPaint paint; 18 SkPaint paint;
18 19
19 paint.setAntiAlias(true); 20 paint.setAntiAlias(true);
20 paint.setStyle(SkPaint::kStroke_Style); 21 paint.setStyle(SkPaint::kStroke_Style);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 { 602.455933f, 625.204102f }, 116 { 602.455933f, 625.204102f },
116 }; 117 };
117 SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, SK_ColorRED, SK_ColorRED }; 118 SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, SK_ColorRED, SK_ColorRED };
118 SkScalar pos[] = { 0, 0.3f, 0.3f, 1.0f }; 119 SkScalar pos[] = { 0, 0.3f, 0.3f, 1.0f };
119 SkShader* s = SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader:: kClamp_TileMode); 120 SkShader* s = SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader:: kClamp_TileMode);
120 SkPaint p; 121 SkPaint p;
121 p.setShader(s)->unref(); 122 p.setShader(s)->unref();
122 canvas->drawPaint(p); 123 canvas->drawPaint(p);
123 } 124 }
124 125
125 static SkCanvas* MakeCanvas(const SkIRect& bounds) { 126 static SkSurface* MakeSurface(const SkIRect& bounds) {
126 SkBitmap bm; 127 SkImageInfo info = SkImageInfo::MakeN32Premul(bounds.width(),
127 bm.allocN32Pixels(bounds.width(), bounds.height()); 128 bounds.height());
128 bm.eraseColor(SK_ColorTRANSPARENT); 129 SkSurface* surface = SkSurface::NewRaster(info);
129 130 surface->getCanvas()->clear(0);
130 SkCanvas* canvas = new SkCanvas(bm); 131 surface->getCanvas()->translate(-SkIntToScalar(bounds.fLeft),
131 canvas->translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop)) ; 132 -SkIntToScalar(bounds.fTop));
132 return canvas; 133 return surface;
133 } 134 }
134 135
136 static void compare(SkSurface* a, SkSurface* b) {
135 #ifdef SK_DEBUG 137 #ifdef SK_DEBUG
136 static void GetBitmap(const SkCanvas* canvas, SkBitmap* bm) { 138 SkImageInfo infoa, infob;
137 *bm = canvas->getDevice()->accessBitmap(false); 139 size_t rowBytesa, rowBytesb;
138 }
139 #endif
140 140
141 static void compare_canvas(const SkCanvas* a, const SkCanvas* b) { 141 const void* pa = a->peekPixels(&infoa, &rowBytesa);
142 #ifdef SK_DEBUG 142 const void* pb = b->peekPixels(&infob, &rowBytesb);
143 SkASSERT(pa && pb);
144
143 SkBitmap bma, bmb; 145 SkBitmap bma, bmb;
144 GetBitmap(a, &bma); 146 bma.installPixels(infoa, const_cast<void*>(pa), rowBytesa, NULL, NULL);
145 GetBitmap(b, &bmb); 147 bmb.installPixels(infob, const_cast<void*>(pb), rowBytesb, NULL, NULL);
146 148
147 SkASSERT(bma.width() == bmb.width()); 149 SkASSERT(bma.width() == bmb.width());
148 SkASSERT(bma.height() == bmb.height()); 150 SkASSERT(bma.height() == bmb.height());
149 151
150 bma.lockPixels(); 152 bma.lockPixels();
151 bmb.lockPixels(); 153 bmb.lockPixels();
152 for (int y = 0; y < bma.height(); ++y) { 154 for (int y = 0; y < bma.height(); ++y) {
153 const SkPMColor* rowa = bma.getAddr32(0, y); 155 const SkPMColor* rowa = bma.getAddr32(0, y);
154 const SkPMColor* rowb = bmb.getAddr32(0, y); 156 const SkPMColor* rowb = bmb.getAddr32(0, y);
155 SkASSERT(!memcmp(rowa, rowb, bma.width() << 2)); 157 SkASSERT(!memcmp(rowa, rowb, bma.width() << 2));
(...skipping 12 matching lines...) Expand all
168 canvas->drawPath(path, p); 170 canvas->drawPath(path, p);
169 } 171 }
170 172
171 static void test_maskFromPath(const SkPath& path) { 173 static void test_maskFromPath(const SkPath& path) {
172 SkIRect bounds; 174 SkIRect bounds;
173 path.getBounds().roundOut(&bounds); 175 path.getBounds().roundOut(&bounds);
174 176
175 SkPaint paint; 177 SkPaint paint;
176 paint.setAntiAlias(true); 178 paint.setAntiAlias(true);
177 179
178 SkAutoTUnref<SkCanvas> path_canvas(MakeCanvas(bounds)); 180 SkAutoTUnref<SkSurface> path_surface(MakeSurface(bounds));
179 path_canvas->drawPath(path, paint); 181 path_surface->getCanvas()->drawPath(path, paint);
180 182
181 SkAutoTUnref<SkCanvas> rect_canvas(MakeCanvas(bounds)); 183 SkAutoTUnref<SkSurface> rect_surface(MakeSurface(bounds));
182 drawRectAsPath(rect_canvas, path.getBounds(), paint); 184 drawRectAsPath(rect_surface->getCanvas(), path.getBounds(), paint);
183 185
184 compare_canvas(path_canvas, rect_canvas); 186 compare(path_surface, rect_surface);
185 } 187 }
186 188
187 static void test_mask() { 189 static void test_mask() {
188 for (int i = 1; i <= 20; ++i) { 190 for (int i = 1; i <= 20; ++i) {
189 const SkScalar dx = SK_Scalar1 / i; 191 const SkScalar dx = SK_Scalar1 / i;
190 const SkRect constr = SkRect::MakeWH(dx, SkIntToScalar(2)); 192 const SkRect constr = SkRect::MakeWH(dx, SkIntToScalar(2));
191 for (int n = 2; n < 20; ++n) { 193 for (int n = 2; n < 20; ++n) {
192 SkPath path; 194 SkPath path;
193 path.setFillType(SkPath::kEvenOdd_FillType); 195 path.setFillType(SkPath::kEvenOdd_FillType);
194 SkRect r = constr; 196 SkRect r = constr;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 SkRect bounds; 280 SkRect bounds;
279 canvas->getClipBounds(&bounds); 281 canvas->getClipBounds(&bounds);
280 test_shallow_gradient(canvas, bounds.width(), bounds.height()); retu rn; 282 test_shallow_gradient(canvas, bounds.width(), bounds.height()); retu rn;
281 } 283 }
282 if (false) { 284 if (false) {
283 test_giant_dash(canvas); return; 285 test_giant_dash(canvas); return;
284 } 286 }
285 if (false) { 287 if (false) {
286 test_grad(canvas); return; 288 test_grad(canvas); return;
287 } 289 }
288 if (false) { // avoid bit rot, suppress warning 290 if (true) { // avoid bit rot, suppress warning
289 test_mask(); 291 test_mask();
290 } 292 }
291 293
292 // Initial pixel-boundary-aligned draw 294 // Initial pixel-boundary-aligned draw
293 draw_rect_tests(canvas); 295 draw_rect_tests(canvas);
294 296
295 // Repeat 4x with .2, .4, .6, .8 px offsets 297 // Repeat 4x with .2, .4, .6, .8 px offsets
296 canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); 298 canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
297 canvas->translate(SkIntToScalar(50), 0); 299 canvas->translate(SkIntToScalar(50), 0);
298 draw_rect_tests(canvas); 300 draw_rect_tests(canvas);
(...skipping 11 matching lines...) Expand all
310 draw_rect_tests(canvas); 312 draw_rect_tests(canvas);
311 } 313 }
312 314
313 virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } 315 virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; }
314 316
315 private: 317 private:
316 typedef skiagm::GM INHERITED; 318 typedef skiagm::GM INHERITED;
317 }; 319 };
318 320
319 DEF_GM( return SkNEW(AAClipGM); ) 321 DEF_GM( return SkNEW(AAClipGM); )
OLDNEW
« no previous file with comments | « no previous file | gm/bitmapcopy.cpp » ('j') | include/core/SkCanvas.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698