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

Side by Side Diff: tests/WritePixelsTest.cpp

Issue 211293002: Revert "Revert of implement readPixels and writePixels natively, w/o using the (deprecated) (https:… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 6 years, 9 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 | « tests/DeferredCanvasTest.cpp ('k') | tools/sk_tool_utils.h » ('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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 case 3: 49 case 3:
50 a = 0x00; 50 a = 0x00;
51 break; 51 break;
52 case 4: 52 case 4:
53 a = 0x01; 53 a = 0x01;
54 break; 54 break;
55 } 55 }
56 return SkPremultiplyARGBInline(a, r, g, b); 56 return SkPremultiplyARGBInline(a, r, g, b);
57 } 57 }
58 58
59 static bool config8888IsPremul(SkCanvas::Config8888 config8888) {
60 switch (config8888) {
61 case SkCanvas::kNative_Premul_Config8888:
62 case SkCanvas::kBGRA_Premul_Config8888:
63 case SkCanvas::kRGBA_Premul_Config8888:
64 return true;
65 case SkCanvas::kNative_Unpremul_Config8888:
66 case SkCanvas::kBGRA_Unpremul_Config8888:
67 case SkCanvas::kRGBA_Unpremul_Config8888:
68 return false;
69 default:
70 SkASSERT(0);
71 return false;
72 }
73 }
74
75 // assumes any premu/.unpremul has been applied 59 // assumes any premu/.unpremul has been applied
76 static uint32_t packConfig8888(SkCanvas::Config8888 config8888, 60 static uint32_t packColorType(SkColorType ct, U8CPU a, U8CPU r, U8CPU g, U8CPU b ) {
77 U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
78 uint32_t r32; 61 uint32_t r32;
79 uint8_t* result = reinterpret_cast<uint8_t*>(&r32); 62 uint8_t* result = reinterpret_cast<uint8_t*>(&r32);
80 switch (config8888) { 63 switch (ct) {
81 case SkCanvas::kNative_Premul_Config8888: 64 case kBGRA_8888_SkColorType:
82 case SkCanvas::kNative_Unpremul_Config8888:
83 r32 = SkPackARGB32NoCheck(a, r, g, b);
84 break;
85 case SkCanvas::kBGRA_Premul_Config8888:
86 case SkCanvas::kBGRA_Unpremul_Config8888:
87 result[0] = b; 65 result[0] = b;
88 result[1] = g; 66 result[1] = g;
89 result[2] = r; 67 result[2] = r;
90 result[3] = a; 68 result[3] = a;
91 break; 69 break;
92 case SkCanvas::kRGBA_Premul_Config8888: 70 case kRGBA_8888_SkColorType:
93 case SkCanvas::kRGBA_Unpremul_Config8888:
94 result[0] = r; 71 result[0] = r;
95 result[1] = g; 72 result[1] = g;
96 result[2] = b; 73 result[2] = b;
97 result[3] = a; 74 result[3] = a;
98 break; 75 break;
99 default: 76 default:
100 SkASSERT(0); 77 SkASSERT(0);
101 return 0; 78 return 0;
102 } 79 }
103 return r32; 80 return r32;
104 } 81 }
105 82
106 static uint32_t getBitmapColor(int x, int y, int w, SkCanvas::Config8888 config8 888) { 83 static uint32_t getBitmapColor(int x, int y, int w, SkColorType ct, SkAlphaType at) {
107 int n = y * w + x; 84 int n = y * w + x;
108 U8CPU b = n & 0xff; 85 U8CPU b = n & 0xff;
109 U8CPU g = (n >> 8) & 0xff; 86 U8CPU g = (n >> 8) & 0xff;
110 U8CPU r = (n >> 16) & 0xff; 87 U8CPU r = (n >> 16) & 0xff;
111 U8CPU a = 0; 88 U8CPU a = 0;
112 switch ((x+y) % 5) { 89 switch ((x+y) % 5) {
113 case 4: 90 case 4:
114 a = 0xff; 91 a = 0xff;
115 break; 92 break;
116 case 3: 93 case 3:
117 a = 0x80; 94 a = 0x80;
118 break; 95 break;
119 case 2: 96 case 2:
120 a = 0xCC; 97 a = 0xCC;
121 break; 98 break;
122 case 1: 99 case 1:
123 a = 0x01; 100 a = 0x01;
124 break; 101 break;
125 case 0: 102 case 0:
126 a = 0x00; 103 a = 0x00;
127 break; 104 break;
128 } 105 }
129 if (config8888IsPremul(config8888)) { 106 if (kPremul_SkAlphaType == at) {
130 r = SkMulDiv255Ceiling(r, a); 107 r = SkMulDiv255Ceiling(r, a);
131 g = SkMulDiv255Ceiling(g, a); 108 g = SkMulDiv255Ceiling(g, a);
132 b = SkMulDiv255Ceiling(b, a); 109 b = SkMulDiv255Ceiling(b, a);
133 } 110 }
134 return packConfig8888(config8888, a, r, g , b); 111 return packColorType(ct, a, r, g , b);
135 } 112 }
136 113
137 static void fillCanvas(SkCanvas* canvas) { 114 static void fillCanvas(SkCanvas* canvas) {
138 SkBitmap bmp; 115 SkBitmap bmp;
139 if (bmp.isNull()) { 116 if (bmp.isNull()) {
140 SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H); 117 SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H);
141 SkASSERT(alloc); 118 SkASSERT(alloc);
142 for (int y = 0; y < DEV_H; ++y) { 119 for (int y = 0; y < DEV_H; ++y) {
143 for (int x = 0; x < DEV_W; ++x) { 120 for (int x = 0; x < DEV_W; ++x) {
144 *bmp.getAddr32(x, y) = getCanvasColor(x, y); 121 *bmp.getAddr32(x, y) = getCanvasColor(x, y);
145 } 122 }
146 } 123 }
147 } 124 }
148 canvas->save(); 125 canvas->save();
149 canvas->setMatrix(SkMatrix::I()); 126 canvas->setMatrix(SkMatrix::I());
150 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op); 127 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op);
151 SkPaint paint; 128 SkPaint paint;
152 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 129 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
153 canvas->drawBitmap(bmp, 0, 0, &paint); 130 canvas->drawBitmap(bmp, 0, 0, &paint);
154 canvas->restore(); 131 canvas->restore();
155 } 132 }
156 133
157 static SkPMColor convertConfig8888ToPMColor(SkCanvas::Config8888 config8888, 134 /**
158 uint32_t color, 135 * Lucky for us, alpha is always in the same spot (SK_A32_SHIFT), for both RGBA and BGRA.
159 bool* premul) { 136 * Thus this routine doesn't need to know the exact colortype
160 const uint8_t* c = reinterpret_cast<uint8_t*>(&color); 137 */
161 U8CPU a,r,g,b; 138 static uint32_t premul(uint32_t color) {
162 *premul = false; 139 unsigned a = SkGetPackedA32(color);
163 switch (config8888) { 140 // these next three are not necessarily r,g,b in that order, but they are r, g,b in some order.
164 case SkCanvas::kNative_Premul_Config8888: 141 unsigned c0 = SkGetPackedR32(color);
165 return color; 142 unsigned c1 = SkGetPackedG32(color);
166 case SkCanvas::kNative_Unpremul_Config8888: 143 unsigned c2 = SkGetPackedB32(color);
167 *premul = true; 144 c0 = SkMulDiv255Ceiling(c0, a);
168 a = SkGetPackedA32(color); 145 c1 = SkMulDiv255Ceiling(c1, a);
169 r = SkGetPackedR32(color); 146 c2 = SkMulDiv255Ceiling(c2, a);
170 g = SkGetPackedG32(color); 147 return SkPackARGB32NoCheck(a, c0, c1, c2);
171 b = SkGetPackedB32(color); 148 }
149
150 static SkPMColor convert_to_PMColor(SkColorType ct, SkAlphaType at, uint32_t col or) {
151 if (kUnpremul_SkAlphaType == at) {
152 color = premul(color);
153 }
154 switch (ct) {
155 case kRGBA_8888_SkColorType:
156 color = SkSwizzle_RGBA_to_PMColor(color);
172 break; 157 break;
173 case SkCanvas::kBGRA_Unpremul_Config8888: 158 case kBGRA_8888_SkColorType:
174 *premul = true; // fallthru 159 color = SkSwizzle_BGRA_to_PMColor(color);
175 case SkCanvas::kBGRA_Premul_Config8888:
176 a = static_cast<U8CPU>(c[3]);
177 r = static_cast<U8CPU>(c[2]);
178 g = static_cast<U8CPU>(c[1]);
179 b = static_cast<U8CPU>(c[0]);
180 break;
181 case SkCanvas::kRGBA_Unpremul_Config8888:
182 *premul = true; // fallthru
183 case SkCanvas::kRGBA_Premul_Config8888:
184 a = static_cast<U8CPU>(c[3]);
185 r = static_cast<U8CPU>(c[0]);
186 g = static_cast<U8CPU>(c[1]);
187 b = static_cast<U8CPU>(c[2]);
188 break; 160 break;
189 default: 161 default:
190 SkDEBUGFAIL("Unexpected Config8888"); 162 SkASSERT(0);
191 return 0; 163 break;
192 } 164 }
193 if (*premul) { 165 return color;
194 r = SkMulDiv255Ceiling(r, a);
195 g = SkMulDiv255Ceiling(g, a);
196 b = SkMulDiv255Ceiling(b, a);
197 }
198 return SkPackARGB32(a, r, g, b);
199 } 166 }
200 167
201 static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) { 168 static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) {
202 if (!didPremulConversion) { 169 if (!didPremulConversion) {
203 return a == b; 170 return a == b;
204 } 171 }
205 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a)); 172 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a));
206 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a)); 173 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a));
207 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a)); 174 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a));
208 int32_t aB = SkGetPackedB32(a); 175 int32_t aB = SkGetPackedB32(a);
209 176
210 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b)); 177 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b));
211 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b)); 178 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b));
212 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b)); 179 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b));
213 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b)); 180 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b));
214 181
215 return aA == bA && 182 return aA == bA &&
216 SkAbs32(aR - bR) <= 1 && 183 SkAbs32(aR - bR) <= 1 &&
217 SkAbs32(aG - bG) <= 1 && 184 SkAbs32(aG - bG) <= 1 &&
218 SkAbs32(aB - bB) <= 1; 185 SkAbs32(aB - bB) <= 1;
219 } 186 }
220 187
221 static bool checkWrite(skiatest::Reporter* reporter, 188 static bool checkWrite(skiatest::Reporter* reporter, SkCanvas* canvas, const SkB itmap& bitmap,
222 SkCanvas* canvas, 189 int writeX, int writeY) {
223 const SkBitmap& bitmap, 190 SkImageInfo canvasInfo;
224 int writeX, int writeY, 191 size_t canvasRowBytes;
225 SkCanvas::Config8888 config8888) { 192 const uint32_t* canvasPixels;
226 SkBaseDevice* dev = canvas->getDevice(); 193
227 if (!dev) { 194 // Can't use canvas->peekPixels(), as we are trying to look at GPU pixels so metimes as well.
195 // At some point this will be unsupported, as we won't allow accessBitmap() to magically call
196 // readPixels for the client.
197 SkBitmap secretDevBitmap;
198 {
199 SkBaseDevice* dev = canvas->getDevice();
200 if (!dev) {
201 return false;
202 }
203 secretDevBitmap = dev->accessBitmap(false);
204 }
205 SkAutoLockPixels alp(secretDevBitmap);
206 canvasInfo = secretDevBitmap.info();
207 canvasRowBytes = secretDevBitmap.rowBytes();
208 canvasPixels = static_cast<const uint32_t*>(secretDevBitmap.getPixels());
209
210 if (NULL == canvasPixels) {
228 return false; 211 return false;
229 } 212 }
230 SkBitmap devBmp = dev->accessBitmap(false); 213
231 if (devBmp.width() != DEV_W || 214 if (canvasInfo.width() != DEV_W ||
232 devBmp.height() != DEV_H || 215 canvasInfo.height() != DEV_H ||
233 devBmp.config() != SkBitmap::kARGB_8888_Config || 216 canvasInfo.colorType() != kPMColor_SkColorType) {
234 devBmp.isNull()) {
235 return false; 217 return false;
236 } 218 }
237 SkAutoLockPixels alp(devBmp);
238 219
239 intptr_t canvasPixels = reinterpret_cast<intptr_t>(devBmp.getPixels()); 220 const SkImageInfo bmInfo = bitmap.info();
240 size_t canvasRowBytes = devBmp.rowBytes(); 221
241 SkIRect writeRect = SkIRect::MakeXYWH(writeX, writeY, bitmap.width(), bitmap .height()); 222 SkIRect writeRect = SkIRect::MakeXYWH(writeX, writeY, bitmap.width(), bitmap .height());
242 for (int cy = 0; cy < DEV_H; ++cy) { 223 for (int cy = 0; cy < DEV_H; ++cy) {
243 const SkPMColor* canvasRow = reinterpret_cast<const SkPMColor*>(canvasPi xels);
244 for (int cx = 0; cx < DEV_W; ++cx) { 224 for (int cx = 0; cx < DEV_W; ++cx) {
245 SkPMColor canvasPixel = canvasRow[cx]; 225 SkPMColor canvasPixel = canvasPixels[cx];
246 if (writeRect.contains(cx, cy)) { 226 if (writeRect.contains(cx, cy)) {
247 int bx = cx - writeX; 227 int bx = cx - writeX;
248 int by = cy - writeY; 228 int by = cy - writeY;
249 uint32_t bmpColor8888 = getBitmapColor(bx, by, bitmap.width(), c onfig8888); 229 uint32_t bmpColor8888 = getBitmapColor(bx, by, bitmap.width(),
250 bool mul; 230 bmInfo.colorType(), bmInf o.alphaType());
251 SkPMColor bmpPMColor = convertConfig8888ToPMColor(config8888, bm pColor8888, &mul); 231 bool mul = (kUnpremul_SkAlphaType == bmInfo.alphaType());
252 bool check; 232 SkPMColor bmpPMColor = convert_to_PMColor(bmInfo.colorType(), bm Info.alphaType(),
253 REPORTER_ASSERT(reporter, check = checkPixel(bmpPMColor, canvasP ixel, mul)); 233 bmpColor8888);
234 bool check = checkPixel(bmpPMColor, canvasPixel, mul);
235 REPORTER_ASSERT(reporter, check);
254 if (!check) { 236 if (!check) {
255 return false; 237 return false;
256 } 238 }
257 } else { 239 } else {
258 bool check; 240 bool check;
259 SkPMColor testColor = getCanvasColor(cx, cy); 241 SkPMColor testColor = getCanvasColor(cx, cy);
260 REPORTER_ASSERT(reporter, check = (canvasPixel == testColor)); 242 REPORTER_ASSERT(reporter, check = (canvasPixel == testColor));
261 if (!check) { 243 if (!check) {
262 return false; 244 return false;
263 } 245 }
264 } 246 }
265 } 247 }
266 if (cy != DEV_H -1) { 248 if (cy != DEV_H -1) {
267 const char* pad = reinterpret_cast<const char*>(canvasPixels + 4 * D EV_W); 249 const char* pad = reinterpret_cast<const char*>(canvasPixels + DEV_W );
268 for (size_t px = 0; px < canvasRowBytes - 4 * DEV_W; ++px) { 250 for (size_t px = 0; px < canvasRowBytes - 4 * DEV_W; ++px) {
269 bool check; 251 bool check;
270 REPORTER_ASSERT(reporter, check = (pad[px] == static_cast<char>( DEV_PAD))); 252 REPORTER_ASSERT(reporter, check = (pad[px] == static_cast<char>( DEV_PAD)));
271 if (!check) { 253 if (!check) {
272 return false; 254 return false;
273 } 255 }
274 } 256 }
275 } 257 }
276 canvasPixels += canvasRowBytes; 258 canvasPixels += canvasRowBytes/4;
277 } 259 }
278 260
279 return true; 261 return true;
280 } 262 }
281 263
282 enum DevType { 264 enum DevType {
283 kRaster_DevType, 265 kRaster_DevType,
284 #if SK_SUPPORT_GPU 266 #if SK_SUPPORT_GPU
285 kGpu_BottomLeft_DevType, 267 kGpu_BottomLeft_DevType,
286 kGpu_TopLeft_DevType, 268 kGpu_TopLeft_DevType,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 desc.fOrigin = kGpu_TopLeft_DevType == c.fDevType ? 329 desc.fOrigin = kGpu_TopLeft_DevType == c.fDevType ?
348 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; 330 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
349 GrAutoScratchTexture ast(grCtx, desc, GrContext::kExact_ScratchTexMa tch); 331 GrAutoScratchTexture ast(grCtx, desc, GrContext::kExact_ScratchTexMa tch);
350 SkAutoTUnref<GrTexture> tex(ast.detach()); 332 SkAutoTUnref<GrTexture> tex(ast.detach());
351 return new SkGpuDevice(grCtx, tex); 333 return new SkGpuDevice(grCtx, tex);
352 #endif 334 #endif
353 } 335 }
354 return NULL; 336 return NULL;
355 } 337 }
356 338
357 static bool setupBitmap(SkBitmap* bitmap, 339 static bool setupBitmap(SkBitmap* bm, SkColorType ct, SkAlphaType at, int w, int h, int tightRB) {
358 SkCanvas::Config8888 config8888, 340 size_t rowBytes = tightRB ? 0 : 4 * w + 60;
359 int w, int h, 341 SkImageInfo info = SkImageInfo::Make(w, h, ct, at);
360 bool tightRowBytes) { 342 if (!allocRowBytes(bm, info, rowBytes)) {
361 size_t rowBytes = tightRowBytes ? 0 : 4 * w + 60;
362 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
363 if (!allocRowBytes(bitmap, info, rowBytes)) {
364 return false; 343 return false;
365 } 344 }
366 SkAutoLockPixels alp(*bitmap); 345 SkAutoLockPixels alp(*bm);
367 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels());
368 for (int y = 0; y < h; ++y) { 346 for (int y = 0; y < h; ++y) {
369 for (int x = 0; x < w; ++x) { 347 for (int x = 0; x < w; ++x) {
370 uint32_t* pixel = reinterpret_cast<uint32_t*>(pixels + y * bitmap->r owBytes() + x * 4); 348 *bm->getAddr32(x, y) = getBitmapColor(x, y, w, ct, at);
371 *pixel = getBitmapColor(x, y, w, config8888);
372 } 349 }
373 } 350 }
374 return true; 351 return true;
375 } 352 }
376 353
377 DEF_GPUTEST(WritePixels, reporter, factory) { 354 DEF_GPUTEST(WritePixels, reporter, factory) {
378 SkCanvas canvas; 355 SkCanvas canvas;
379 356
380 const SkIRect testRects[] = { 357 const SkIRect testRects[] = {
381 // entire thing 358 // entire thing
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 context = factory->get(type); 422 context = factory->get(type);
446 if (NULL == context) { 423 if (NULL == context) {
447 continue; 424 continue;
448 } 425 }
449 } 426 }
450 #endif 427 #endif
451 428
452 SkAutoTUnref<SkBaseDevice> device(createDevice(gCanvasConfigs[i], co ntext)); 429 SkAutoTUnref<SkBaseDevice> device(createDevice(gCanvasConfigs[i], co ntext));
453 SkCanvas canvas(device); 430 SkCanvas canvas(device);
454 431
455 static const SkCanvas::Config8888 gSrcConfigs[] = { 432 static const struct {
456 SkCanvas::kNative_Premul_Config8888, 433 SkColorType fColorType;
457 SkCanvas::kNative_Unpremul_Config8888, 434 SkAlphaType fAlphaType;
458 SkCanvas::kBGRA_Premul_Config8888, 435 } gSrcConfigs[] = {
459 SkCanvas::kBGRA_Unpremul_Config8888, 436 { kRGBA_8888_SkColorType, kPremul_SkAlphaType },
460 SkCanvas::kRGBA_Premul_Config8888, 437 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
461 SkCanvas::kRGBA_Unpremul_Config8888, 438 { kBGRA_8888_SkColorType, kPremul_SkAlphaType },
439 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
462 }; 440 };
463 for (size_t r = 0; r < SK_ARRAY_COUNT(testRects); ++r) { 441 for (size_t r = 0; r < SK_ARRAY_COUNT(testRects); ++r) {
464 const SkIRect& rect = testRects[r]; 442 const SkIRect& rect = testRects[r];
465 for (int tightBmp = 0; tightBmp < 2; ++tightBmp) { 443 for (int tightBmp = 0; tightBmp < 2; ++tightBmp) {
466 for (size_t c = 0; c < SK_ARRAY_COUNT(gSrcConfigs); ++c) { 444 for (size_t c = 0; c < SK_ARRAY_COUNT(gSrcConfigs); ++c) {
445 const SkColorType ct = gSrcConfigs[c].fColorType;
446 const SkAlphaType at = gSrcConfigs[c].fAlphaType;
447
467 fillCanvas(&canvas); 448 fillCanvas(&canvas);
468 SkCanvas::Config8888 config8888 = gSrcConfigs[c];
469 SkBitmap bmp; 449 SkBitmap bmp;
470 REPORTER_ASSERT(reporter, setupBitmap(&bmp, config8888, rect.width(), rect.height(), SkToBool(tightBmp))); 450 REPORTER_ASSERT(reporter, setupBitmap(&bmp, ct, at, rect .width(),
451 rect.height(), SkT oBool(tightBmp)));
471 uint32_t idBefore = canvas.getDevice()->accessBitmap(fal se).getGenerationID(); 452 uint32_t idBefore = canvas.getDevice()->accessBitmap(fal se).getGenerationID();
472 453
473 SkColorType ct; 454 // sk_tool_utils::write_pixels(&canvas, bmp, rect.fLeft, rect.fTop, ct, at);
474 SkAlphaType at; 455 canvas.writePixels(bmp, rect.fLeft, rect.fTop);
475 sk_tool_utils::config8888_to_imagetypes(config8888, &ct, &at);
476 sk_tool_utils::write_pixels(&canvas, bmp, rect.fLeft, re ct.fTop, ct, at);
477 456
478 uint32_t idAfter = canvas.getDevice()->accessBitmap(fals e).getGenerationID(); 457 uint32_t idAfter = canvas.getDevice()->accessBitmap(fals e).getGenerationID();
479 REPORTER_ASSERT(reporter, checkWrite(reporter, &canvas, bmp, rect.fLeft, rect.fTop, config8888)); 458 REPORTER_ASSERT(reporter, checkWrite(reporter, &canvas, bmp, rect.fLeft, rect.fTop));
480 459
481 // we should change the genID iff pixels were actually w ritten. 460 // we should change the genID iff pixels were actually w ritten.
482 SkIRect canvasRect = SkIRect::MakeSize(canvas.getDeviceS ize()); 461 SkIRect canvasRect = SkIRect::MakeSize(canvas.getDeviceS ize());
483 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f Top, 462 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f Top,
484 bmp.width(), bmp.h eight()); 463 bmp.width(), bmp.h eight());
485 bool intersects = SkIRect::Intersects(canvasRect, writeR ect) ; 464 bool intersects = SkIRect::Intersects(canvasRect, writeR ect) ;
486 REPORTER_ASSERT(reporter, intersects == (idBefore != idA fter)); 465 REPORTER_ASSERT(reporter, intersects == (idBefore != idA fter));
487 } 466 }
488 } 467 }
489 } 468 }
490 } 469 }
491 } 470 }
492 } 471 }
OLDNEW
« no previous file with comments | « tests/DeferredCanvasTest.cpp ('k') | tools/sk_tool_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698