| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 desc.fOrigin = kGpu_TopLeft_DevType == c.fDevType ? | 344 desc.fOrigin = kGpu_TopLeft_DevType == c.fDevType ? |
| 327 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; | 345 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; |
| 328 GrAutoScratchTexture ast(grCtx, desc, GrContext::kExact_ScratchTexMa
tch); | 346 GrAutoScratchTexture ast(grCtx, desc, GrContext::kExact_ScratchTexMa
tch); |
| 329 SkAutoTUnref<GrTexture> tex(ast.detach()); | 347 SkAutoTUnref<GrTexture> tex(ast.detach()); |
| 330 return new SkGpuDevice(grCtx, tex); | 348 return new SkGpuDevice(grCtx, tex); |
| 331 #endif | 349 #endif |
| 332 } | 350 } |
| 333 return NULL; | 351 return NULL; |
| 334 } | 352 } |
| 335 | 353 |
| 336 static bool setupBitmap(SkBitmap* bm, SkColorType ct, SkAlphaType at, int w, int
h, int tightRB) { | 354 static bool setupBitmap(SkBitmap* bitmap, |
| 337 size_t rowBytes = tightRB ? 0 : 4 * w + 60; | 355 SkCanvas::Config8888 config8888, |
| 338 SkImageInfo info = SkImageInfo::Make(w, h, ct, at); | 356 int w, int h, |
| 339 if (!allocRowBytes(bm, info, rowBytes)) { | 357 bool tightRowBytes) { |
| 358 size_t rowBytes = tightRowBytes ? 0 : 4 * w + 60; |
| 359 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); |
| 360 if (!allocRowBytes(bitmap, info, rowBytes)) { |
| 340 return false; | 361 return false; |
| 341 } | 362 } |
| 342 SkAutoLockPixels alp(*bm); | 363 SkAutoLockPixels alp(*bitmap); |
| 364 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels()); |
| 343 for (int y = 0; y < h; ++y) { | 365 for (int y = 0; y < h; ++y) { |
| 344 for (int x = 0; x < w; ++x) { | 366 for (int x = 0; x < w; ++x) { |
| 345 *bm->getAddr32(x, y) = getBitmapColor(x, y, w, ct, at); | 367 uint32_t* pixel = reinterpret_cast<uint32_t*>(pixels + y * bitmap->r
owBytes() + x * 4); |
| 368 *pixel = getBitmapColor(x, y, w, config8888); |
| 346 } | 369 } |
| 347 } | 370 } |
| 348 return true; | 371 return true; |
| 349 } | 372 } |
| 350 | 373 |
| 351 DEF_GPUTEST(WritePixels, reporter, factory) { | 374 DEF_GPUTEST(WritePixels, reporter, factory) { |
| 352 SkCanvas canvas; | 375 SkCanvas canvas; |
| 353 | 376 |
| 354 const SkIRect testRects[] = { | 377 const SkIRect testRects[] = { |
| 355 // entire thing | 378 // entire thing |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 context = factory->get(type); | 442 context = factory->get(type); |
| 420 if (NULL == context) { | 443 if (NULL == context) { |
| 421 continue; | 444 continue; |
| 422 } | 445 } |
| 423 } | 446 } |
| 424 #endif | 447 #endif |
| 425 | 448 |
| 426 SkAutoTUnref<SkBaseDevice> device(createDevice(gCanvasConfigs[i], co
ntext)); | 449 SkAutoTUnref<SkBaseDevice> device(createDevice(gCanvasConfigs[i], co
ntext)); |
| 427 SkCanvas canvas(device); | 450 SkCanvas canvas(device); |
| 428 | 451 |
| 429 static const struct { | 452 static const SkCanvas::Config8888 gSrcConfigs[] = { |
| 430 SkColorType fColorType; | 453 SkCanvas::kNative_Premul_Config8888, |
| 431 SkAlphaType fAlphaType; | 454 SkCanvas::kNative_Unpremul_Config8888, |
| 432 } gSrcConfigs[] = { | 455 SkCanvas::kBGRA_Premul_Config8888, |
| 433 { kRGBA_8888_SkColorType, kPremul_SkAlphaType }, | 456 SkCanvas::kBGRA_Unpremul_Config8888, |
| 434 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType }, | 457 SkCanvas::kRGBA_Premul_Config8888, |
| 435 { kBGRA_8888_SkColorType, kPremul_SkAlphaType }, | 458 SkCanvas::kRGBA_Unpremul_Config8888, |
| 436 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType }, | |
| 437 }; | 459 }; |
| 438 for (size_t r = 0; r < SK_ARRAY_COUNT(testRects); ++r) { | 460 for (size_t r = 0; r < SK_ARRAY_COUNT(testRects); ++r) { |
| 439 const SkIRect& rect = testRects[r]; | 461 const SkIRect& rect = testRects[r]; |
| 440 for (int tightBmp = 0; tightBmp < 2; ++tightBmp) { | 462 for (int tightBmp = 0; tightBmp < 2; ++tightBmp) { |
| 441 for (size_t c = 0; c < SK_ARRAY_COUNT(gSrcConfigs); ++c) { | 463 for (size_t c = 0; c < SK_ARRAY_COUNT(gSrcConfigs); ++c) { |
| 442 const SkColorType ct = gSrcConfigs[c].fColorType; | |
| 443 const SkAlphaType at = gSrcConfigs[c].fAlphaType; | |
| 444 | |
| 445 fillCanvas(&canvas); | 464 fillCanvas(&canvas); |
| 465 SkCanvas::Config8888 config8888 = gSrcConfigs[c]; |
| 446 SkBitmap bmp; | 466 SkBitmap bmp; |
| 447 REPORTER_ASSERT(reporter, setupBitmap(&bmp, ct, at, rect
.width(), | 467 REPORTER_ASSERT(reporter, setupBitmap(&bmp, config8888,
rect.width(), rect.height(), SkToBool(tightBmp))); |
| 448 rect.height(), SkT
oBool(tightBmp))); | |
| 449 uint32_t idBefore = canvas.getDevice()->accessBitmap(fal
se).getGenerationID(); | 468 uint32_t idBefore = canvas.getDevice()->accessBitmap(fal
se).getGenerationID(); |
| 450 | 469 |
| 451 // sk_tool_utils::write_pixels(&canvas, bmp, rect.fLeft,
rect.fTop, ct, at); | 470 SkColorType ct; |
| 452 canvas.writePixels(bmp, rect.fLeft, rect.fTop); | 471 SkAlphaType at; |
| 472 sk_tool_utils::config8888_to_imagetypes(config8888, &ct,
&at); |
| 473 sk_tool_utils::write_pixels(&canvas, bmp, rect.fLeft, re
ct.fTop, ct, at); |
| 453 | 474 |
| 454 uint32_t idAfter = canvas.getDevice()->accessBitmap(fals
e).getGenerationID(); | 475 uint32_t idAfter = canvas.getDevice()->accessBitmap(fals
e).getGenerationID(); |
| 455 REPORTER_ASSERT(reporter, checkWrite(reporter, &canvas,
bmp, rect.fLeft, rect.fTop)); | 476 REPORTER_ASSERT(reporter, checkWrite(reporter, &canvas,
bmp, rect.fLeft, rect.fTop, config8888)); |
| 456 | 477 |
| 457 // we should change the genID iff pixels were actually w
ritten. | 478 // we should change the genID iff pixels were actually w
ritten. |
| 458 SkIRect canvasRect = SkIRect::MakeSize(canvas.getDeviceS
ize()); | 479 SkIRect canvasRect = SkIRect::MakeSize(canvas.getDeviceS
ize()); |
| 459 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f
Top, | 480 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f
Top, |
| 460 bmp.width(), bmp.h
eight()); | 481 bmp.width(), bmp.h
eight()); |
| 461 bool intersects = SkIRect::Intersects(canvasRect, writeR
ect) ; | 482 bool intersects = SkIRect::Intersects(canvasRect, writeR
ect) ; |
| 462 REPORTER_ASSERT(reporter, intersects == (idBefore != idA
fter)); | 483 REPORTER_ASSERT(reporter, intersects == (idBefore != idA
fter)); |
| 463 } | 484 } |
| 464 } | 485 } |
| 465 } | 486 } |
| 466 } | 487 } |
| 467 } | 488 } |
| 468 } | 489 } |
| OLD | NEW |