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