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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkMathPriv.h" | 10 #include "SkMathPriv.h" |
11 #include "SkRegion.h" | 11 #include "SkRegion.h" |
12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
13 #include "Test.h" | 13 #include "Test.h" |
14 #include "sk_tool_utils.h" | 14 #include "sk_tool_utils.h" |
15 | 15 |
16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
17 #include "GrContextFactory.h" | 17 #include "GrContextFactory.h" |
18 #include "SkGpuDevice.h" | 18 #include "SkGpuDevice.h" |
19 #else | 19 #else |
20 class GrContext; | 20 class GrContext; |
21 class GrContextFactory; | 21 class GrContextFactory; |
22 #endif | 22 #endif |
23 | 23 |
24 static const int DEV_W = 100, DEV_H = 100; | 24 static const int DEV_W = 100, DEV_H = 100; |
25 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); | 25 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); |
26 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1, | 26 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1, |
27 DEV_H * SK_Scalar1); | 27 DEV_H * SK_Scalar1); |
28 static const U8CPU DEV_PAD = 0xee; | 28 static const U8CPU DEV_PAD = 0xee; |
29 | 29 |
robertphillips
2015/07/28 13:15:23
get_canvas_color ?
bsalomon
2015/07/28 14:58:17
Done.
| |
30 static SkPMColor getCanvasColor(int x, int y) { | 30 static SkPMColor getCanvasColor(int x, int y) { |
31 SkASSERT(x >= 0 && x < DEV_W); | 31 SkASSERT(x >= 0 && x < DEV_W); |
32 SkASSERT(y >= 0 && y < DEV_H); | 32 SkASSERT(y >= 0 && y < DEV_H); |
33 | 33 |
34 U8CPU r = x; | 34 U8CPU r = x; |
35 U8CPU g = y; | 35 U8CPU g = y; |
36 U8CPU b = 0xc; | 36 U8CPU b = 0xc; |
37 | 37 |
38 U8CPU a = 0x0; | 38 U8CPU a = 0x0; |
39 switch ((x+y) % 5) { | 39 switch ((x+y) % 5) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 break; | 156 break; |
157 case kBGRA_8888_SkColorType: | 157 case kBGRA_8888_SkColorType: |
158 color = SkSwizzle_BGRA_to_PMColor(color); | 158 color = SkSwizzle_BGRA_to_PMColor(color); |
159 break; | 159 break; |
160 default: | 160 default: |
161 SkASSERT(0); | 161 SkASSERT(0); |
162 break; | 162 break; |
163 } | 163 } |
164 return color; | 164 return color; |
165 } | 165 } |
166 | 166 |
robertphillips
2015/07/28 13:15:23
check_pixel ?
bsalomon
2015/07/28 14:58:18
Done.
| |
167 static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) { | 167 static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) { |
168 if (!didPremulConversion) { | 168 if (!didPremulConversion) { |
169 return a == b; | 169 return a == b; |
170 } | 170 } |
171 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a)); | 171 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a)); |
172 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a)); | 172 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a)); |
173 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a)); | 173 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a)); |
174 int32_t aB = SkGetPackedB32(a); | 174 int32_t aB = SkGetPackedB32(a); |
175 | 175 |
176 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b)); | 176 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 for (int cx = 0; cx < DEV_W; ++cx) { | 217 for (int cx = 0; cx < DEV_W; ++cx) { |
218 SkPMColor canvasPixel = canvasPixels[cx]; | 218 SkPMColor canvasPixel = canvasPixels[cx]; |
219 if (writeRect.contains(cx, cy)) { | 219 if (writeRect.contains(cx, cy)) { |
220 int bx = cx - writeX; | 220 int bx = cx - writeX; |
221 int by = cy - writeY; | 221 int by = cy - writeY; |
222 uint32_t bmpColor8888 = getBitmapColor(bx, by, bitmap.width(), | 222 uint32_t bmpColor8888 = getBitmapColor(bx, by, bitmap.width(), |
223 bmInfo.colorType(), bmInf o.alphaType()); | 223 bmInfo.colorType(), bmInf o.alphaType()); |
224 bool mul = (kUnpremul_SkAlphaType == bmInfo.alphaType()); | 224 bool mul = (kUnpremul_SkAlphaType == bmInfo.alphaType()); |
225 SkPMColor bmpPMColor = convert_to_PMColor(bmInfo.colorType(), bm Info.alphaType(), | 225 SkPMColor bmpPMColor = convert_to_PMColor(bmInfo.colorType(), bm Info.alphaType(), |
226 bmpColor8888); | 226 bmpColor8888); |
227 bool check = checkPixel(bmpPMColor, canvasPixel, mul); | 227 if (!checkPixel(bmpPMColor, canvasPixel, mul)) { |
228 REPORTER_ASSERT(reporter, check); | 228 ERRORF(reporter, "Expected canvas pixel at %d, %d to be 0x%0 8x, got 0x%08x. " |
229 if (!check) { | 229 "Write performed premul: %d", cx, cy, bmpPMColor, can vasPixel, mul); |
230 return false; | 230 return false; |
231 } | 231 } |
232 } else { | 232 } else { |
233 bool check; | |
234 SkPMColor testColor = getCanvasColor(cx, cy); | 233 SkPMColor testColor = getCanvasColor(cx, cy); |
235 REPORTER_ASSERT(reporter, check = (canvasPixel == testColor)); | 234 if (canvasPixel != testColor) { |
236 if (!check) { | 235 ERRORF(reporter, "Canvas pixel outside write rect at %d, %d changed." |
236 " Should be 0x%08x, got 0x%08x. ", cx, cy, testColor, canvasPixel); | |
237 return false; | 237 return false; |
238 } | 238 } |
239 } | 239 } |
240 } | 240 } |
241 if (cy != DEV_H -1) { | 241 if (cy != DEV_H -1) { |
242 const char* pad = reinterpret_cast<const char*>(canvasPixels + DEV_W ); | 242 const char* pad = reinterpret_cast<const char*>(canvasPixels + DEV_W ); |
243 for (size_t px = 0; px < canvasRowBytes - 4 * DEV_W; ++px) { | 243 for (size_t px = 0; px < canvasRowBytes - 4 * DEV_W; ++px) { |
244 bool check; | 244 bool check; |
245 REPORTER_ASSERT(reporter, check = (pad[px] == static_cast<char>( DEV_PAD))); | 245 REPORTER_ASSERT(reporter, check = (pad[px] == static_cast<char>( DEV_PAD))); |
246 if (!check) { | 246 if (!check) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f Top, | 469 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f Top, |
470 bmp.width(), bmp.h eight()); | 470 bmp.width(), bmp.h eight()); |
471 bool intersects = SkIRect::Intersects(canvasRect, writeR ect) ; | 471 bool intersects = SkIRect::Intersects(canvasRect, writeR ect) ; |
472 REPORTER_ASSERT(reporter, intersects == (idBefore != idA fter)); | 472 REPORTER_ASSERT(reporter, intersects == (idBefore != idA fter)); |
473 } | 473 } |
474 } | 474 } |
475 } | 475 } |
476 } | 476 } |
477 } | 477 } |
478 } | 478 } |
OLD | NEW |