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 | 14 |
15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
16 #include "GrContextFactory.h" | 16 #include "GrContextFactory.h" |
17 #include "SkGpuDevice.h" | 17 #include "SkGpuDevice.h" |
| 18 #include "SkGr.h" |
18 #endif | 19 #endif |
19 | 20 |
20 static const int DEV_W = 100, DEV_H = 100; | 21 static const int DEV_W = 100, DEV_H = 100; |
21 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); | 22 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); |
22 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1, | 23 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1, |
23 DEV_H * SK_Scalar1); | 24 DEV_H * SK_Scalar1); |
24 | 25 |
25 static SkPMColor getCanvasColor(int x, int y) { | 26 static SkPMColor get_src_color(int x, int y) { |
26 SkASSERT(x >= 0 && x < DEV_W); | 27 SkASSERT(x >= 0 && x < DEV_W); |
27 SkASSERT(y >= 0 && y < DEV_H); | 28 SkASSERT(y >= 0 && y < DEV_H); |
28 | 29 |
29 U8CPU r = x; | 30 U8CPU r = x; |
30 U8CPU g = y; | 31 U8CPU g = y; |
31 U8CPU b = 0xc; | 32 U8CPU b = 0xc; |
32 | 33 |
33 U8CPU a = 0xff; | 34 U8CPU a = 0xff; |
34 switch ((x+y) % 5) { | 35 switch ((x+y) % 5) { |
35 case 0: | 36 case 0: |
36 a = 0xff; | 37 a = 0xff; |
37 break; | 38 break; |
38 case 1: | 39 case 1: |
39 a = 0x80; | 40 a = 0x80; |
40 break; | 41 break; |
41 case 2: | 42 case 2: |
42 a = 0xCC; | 43 a = 0xCC; |
43 break; | 44 break; |
44 case 4: | 45 case 4: |
45 a = 0x01; | 46 a = 0x01; |
46 break; | 47 break; |
47 case 3: | 48 case 3: |
48 a = 0x00; | 49 a = 0x00; |
49 break; | 50 break; |
50 } | 51 } |
51 return SkPremultiplyARGBInline(a, r, g, b); | 52 return SkPremultiplyARGBInline(a, r, g, b); |
52 } | 53 } |
53 | 54 |
54 static SkPMColor getBitmapColor(int x, int y, int w) { | 55 static SkPMColor get_dst_bmp_init_color(int x, int y, int w) { |
55 int n = y * w + x; | 56 int n = y * w + x; |
56 | 57 |
57 U8CPU b = n & 0xff; | 58 U8CPU b = n & 0xff; |
58 U8CPU g = (n >> 8) & 0xff; | 59 U8CPU g = (n >> 8) & 0xff; |
59 U8CPU r = (n >> 16) & 0xff; | 60 U8CPU r = (n >> 16) & 0xff; |
60 return SkPackARGB32(0xff, r, g , b); | 61 return SkPackARGB32(0xff, r, g , b); |
61 } | 62 } |
62 | 63 |
63 static SkPMColor convertToPMColor(SkColorType ct, SkAlphaType at, const uint32_t
* addr, | 64 static SkPMColor convert_to_pmcolor(SkColorType ct, SkAlphaType at, const uint32
_t* addr, |
64 bool* doUnpremul) { | 65 bool* doUnpremul) { |
65 *doUnpremul = (kUnpremul_SkAlphaType == at); | 66 *doUnpremul = (kUnpremul_SkAlphaType == at); |
66 | 67 |
67 const uint8_t* c = reinterpret_cast<const uint8_t*>(addr); | 68 const uint8_t* c = reinterpret_cast<const uint8_t*>(addr); |
68 U8CPU a,r,g,b; | 69 U8CPU a,r,g,b; |
69 switch (ct) { | 70 switch (ct) { |
70 case kBGRA_8888_SkColorType: | 71 case kBGRA_8888_SkColorType: |
71 b = static_cast<U8CPU>(c[0]); | 72 b = static_cast<U8CPU>(c[0]); |
72 g = static_cast<U8CPU>(c[1]); | 73 g = static_cast<U8CPU>(c[1]); |
73 r = static_cast<U8CPU>(c[2]); | 74 r = static_cast<U8CPU>(c[2]); |
74 a = static_cast<U8CPU>(c[3]); | 75 a = static_cast<U8CPU>(c[3]); |
(...skipping 10 matching lines...) Expand all Loading... |
85 } | 86 } |
86 | 87 |
87 if (*doUnpremul) { | 88 if (*doUnpremul) { |
88 r = SkMulDiv255Ceiling(r, a); | 89 r = SkMulDiv255Ceiling(r, a); |
89 g = SkMulDiv255Ceiling(g, a); | 90 g = SkMulDiv255Ceiling(g, a); |
90 b = SkMulDiv255Ceiling(b, a); | 91 b = SkMulDiv255Ceiling(b, a); |
91 } | 92 } |
92 return SkPackARGB32(a, r, g, b); | 93 return SkPackARGB32(a, r, g, b); |
93 } | 94 } |
94 | 95 |
95 static void fillCanvas(SkCanvas* canvas) { | 96 static SkBitmap make_src_bitmap() { |
96 static SkBitmap bmp; | 97 static SkBitmap bmp; |
97 if (bmp.isNull()) { | 98 if (bmp.isNull()) { |
98 bmp.allocN32Pixels(DEV_W, DEV_H); | 99 bmp.allocN32Pixels(DEV_W, DEV_H); |
99 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels()); | 100 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels()); |
100 for (int y = 0; y < DEV_H; ++y) { | 101 for (int y = 0; y < DEV_H; ++y) { |
101 for (int x = 0; x < DEV_W; ++x) { | 102 for (int x = 0; x < DEV_W; ++x) { |
102 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp
.rowBytes() + x * bmp.bytesPerPixel()); | 103 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp
.rowBytes() + x * bmp.bytesPerPixel()); |
103 *pixel = getCanvasColor(x, y); | 104 *pixel = get_src_color(x, y); |
104 } | 105 } |
105 } | 106 } |
106 } | 107 } |
| 108 return bmp; |
| 109 } |
| 110 |
| 111 static void fill_src_canvas(SkCanvas* canvas) { |
107 canvas->save(); | 112 canvas->save(); |
108 canvas->setMatrix(SkMatrix::I()); | 113 canvas->setMatrix(SkMatrix::I()); |
109 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op); | 114 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op); |
110 SkPaint paint; | 115 SkPaint paint; |
111 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 116 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
112 canvas->drawBitmap(bmp, 0, 0, &paint); | 117 canvas->drawBitmap(make_src_bitmap(), 0, 0, &paint); |
113 canvas->restore(); | 118 canvas->restore(); |
114 } | 119 } |
115 | 120 |
116 static void fillBitmap(SkBitmap* bitmap) { | 121 #if SK_SUPPORT_GPU |
| 122 static void fill_src_texture(GrTexture* texture) { |
| 123 SkBitmap bmp = make_src_bitmap(); |
| 124 bmp.lockPixels(); |
| 125 texture->writePixels(0, 0, DEV_W, DEV_H, kSkia8888_GrPixelConfig, bmp.getPix
els(), |
| 126 bmp.rowBytes()); |
| 127 bmp.unlockPixels(); |
| 128 } |
| 129 #endif |
| 130 |
| 131 static void fill_dst_bmp_with_init_data(SkBitmap* bitmap) { |
117 SkASSERT(bitmap->lockPixelsAreWritable()); | 132 SkASSERT(bitmap->lockPixelsAreWritable()); |
118 SkAutoLockPixels alp(*bitmap); | 133 SkAutoLockPixels alp(*bitmap); |
119 int w = bitmap->width(); | 134 int w = bitmap->width(); |
120 int h = bitmap->height(); | 135 int h = bitmap->height(); |
121 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels()); | 136 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels()); |
122 for (int y = 0; y < h; ++y) { | 137 for (int y = 0; y < h; ++y) { |
123 for (int x = 0; x < w; ++x) { | 138 for (int x = 0; x < w; ++x) { |
124 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap-
>rowBytes() + x * bitmap->bytesPerPixel()); | 139 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap-
>rowBytes() + x * bitmap->bytesPerPixel()); |
125 *pixel = getBitmapColor(x, y, w); | 140 *pixel = get_dst_bmp_init_color(x, y, w); |
126 } | 141 } |
127 } | 142 } |
128 } | 143 } |
129 | 144 |
130 static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) { | 145 static bool check_read_pixel(SkPMColor a, SkPMColor b, bool didPremulConversion)
{ |
131 if (!didPremulConversion) { | 146 if (!didPremulConversion) { |
132 return a == b; | 147 return a == b; |
133 } | 148 } |
134 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a)); | 149 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a)); |
135 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a)); | 150 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a)); |
136 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a)); | 151 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a)); |
137 int32_t aB = SkGetPackedB32(a); | 152 int32_t aB = SkGetPackedB32(a); |
138 | 153 |
139 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b)); | 154 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b)); |
140 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b)); | 155 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b)); |
141 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b)); | 156 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b)); |
142 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b)); | 157 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b)); |
143 | 158 |
144 return aA == bA && | 159 return aA == bA && |
145 SkAbs32(aR - bR) <= 1 && | 160 SkAbs32(aR - bR) <= 1 && |
146 SkAbs32(aG - bG) <= 1 && | 161 SkAbs32(aG - bG) <= 1 && |
147 SkAbs32(aB - bB) <= 1; | 162 SkAbs32(aB - bB) <= 1; |
148 } | 163 } |
149 | 164 |
150 // checks the bitmap contains correct pixels after the readPixels | 165 // checks the bitmap contains correct pixels after the readPixels |
151 // if the bitmap was prefilled with pixels it checks that these weren't | 166 // if the bitmap was prefilled with pixels it checks that these weren't |
152 // overwritten in the area outside the readPixels. | 167 // overwritten in the area outside the readPixels. |
153 static bool checkRead(skiatest::Reporter* reporter, | 168 static bool check_read(skiatest::Reporter* reporter, |
154 const SkBitmap& bitmap, | 169 const SkBitmap& bitmap, |
155 int x, int y, | 170 int x, int y, |
156 bool checkCanvasPixels, | 171 bool checkCanvasPixels, |
157 bool checkBitmapPixels) { | 172 bool checkBitmapPixels) { |
158 SkASSERT(4 == bitmap.bytesPerPixel()); | 173 SkASSERT(4 == bitmap.bytesPerPixel()); |
159 SkASSERT(!bitmap.isNull()); | 174 SkASSERT(!bitmap.isNull()); |
160 SkASSERT(checkCanvasPixels || checkBitmapPixels); | 175 SkASSERT(checkCanvasPixels || checkBitmapPixels); |
161 | 176 |
162 const SkColorType ct = bitmap.colorType(); | 177 const SkColorType ct = bitmap.colorType(); |
163 const SkAlphaType at = bitmap.alphaType(); | 178 const SkAlphaType at = bitmap.alphaType(); |
164 | 179 |
165 int bw = bitmap.width(); | 180 int bw = bitmap.width(); |
166 int bh = bitmap.height(); | 181 int bh = bitmap.height(); |
167 | 182 |
168 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh); | 183 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh); |
169 SkIRect clippedSrcRect = DEV_RECT; | 184 SkIRect clippedSrcRect = DEV_RECT; |
170 if (!clippedSrcRect.intersect(srcRect)) { | 185 if (!clippedSrcRect.intersect(srcRect)) { |
171 clippedSrcRect.setEmpty(); | 186 clippedSrcRect.setEmpty(); |
172 } | 187 } |
173 SkAutoLockPixels alp(bitmap); | 188 SkAutoLockPixels alp(bitmap); |
174 for (int by = 0; by < bh; ++by) { | 189 for (int by = 0; by < bh; ++by) { |
175 for (int bx = 0; bx < bw; ++bx) { | 190 for (int bx = 0; bx < bw; ++bx) { |
176 int devx = bx + srcRect.fLeft; | 191 int devx = bx + srcRect.fLeft; |
177 int devy = by + srcRect.fTop; | 192 int devy = by + srcRect.fTop; |
178 | 193 |
179 const uint32_t* pixel = bitmap.getAddr32(bx, by); | 194 const uint32_t* pixel = bitmap.getAddr32(bx, by); |
180 | 195 |
181 if (clippedSrcRect.contains(devx, devy)) { | 196 if (clippedSrcRect.contains(devx, devy)) { |
182 if (checkCanvasPixels) { | 197 if (checkCanvasPixels) { |
183 SkPMColor canvasPixel = getCanvasColor(devx, devy); | 198 SkPMColor canvasPixel = get_src_color(devx, devy); |
184 bool didPremul; | 199 bool didPremul; |
185 SkPMColor pmPixel = convertToPMColor(ct, at, pixel, &didPrem
ul); | 200 SkPMColor pmPixel = convert_to_pmcolor(ct, at, pixel, &didPr
emul); |
186 bool check; | 201 bool check = check_read_pixel(pmPixel, canvasPixel, didPremu
l); |
187 REPORTER_ASSERT(reporter, check = checkPixel(pmPixel, canvas
Pixel, didPremul)); | 202 REPORTER_ASSERT(reporter, check); |
188 if (!check) { | 203 if (!check) { |
189 return false; | 204 return false; |
190 } | 205 } |
191 } | 206 } |
192 } else if (checkBitmapPixels) { | 207 } else if (checkBitmapPixels) { |
193 REPORTER_ASSERT(reporter, getBitmapColor(bx, by, bw) == *pixel); | 208 REPORTER_ASSERT(reporter, get_dst_bmp_init_color(bx, by, bw) ==
*pixel); |
194 if (getBitmapColor(bx, by, bw) != *pixel) { | 209 if (get_dst_bmp_init_color(bx, by, bw) != *pixel) { |
195 return false; | 210 return false; |
196 } | 211 } |
197 } | 212 } |
198 } | 213 } |
199 } | 214 } |
200 return true; | 215 return true; |
201 } | 216 } |
202 | 217 |
203 enum BitmapInit { | 218 enum BitmapInit { |
204 kFirstBitmapInit = 0, | 219 kFirstBitmapInit = 0, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 SkIRect::MakeLTRB(0, DEV_H, DEV_W, DEV_H + 10), | 299 SkIRect::MakeLTRB(0, DEV_H, DEV_W, DEV_H + 10), |
285 // overlapping bottom right corner | 300 // overlapping bottom right corner |
286 SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10), | 301 SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10), |
287 // overlapping top right and bottom right corners | 302 // overlapping top right and bottom right corners |
288 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10), | 303 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10), |
289 }; | 304 }; |
290 | 305 |
291 for (int dtype = 0; dtype < 3; ++dtype) { | 306 for (int dtype = 0; dtype < 3; ++dtype) { |
292 int glCtxTypeCnt = 1; | 307 int glCtxTypeCnt = 1; |
293 #if SK_SUPPORT_GPU | 308 #if SK_SUPPORT_GPU |
| 309 // On the GPU we will also try reading back from a non-renderable textur
e. |
| 310 SkAutoTUnref<GrTexture> texture; |
| 311 |
294 if (0 != dtype) { | 312 if (0 != dtype) { |
295 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; | 313 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; |
296 } | 314 } |
297 #endif | 315 #endif |
298 const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H); | 316 const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H); |
299 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { | 317 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { |
300 SkAutoTUnref<SkSurface> surface; | 318 SkAutoTUnref<SkSurface> surface; |
301 if (0 == dtype) { | 319 if (0 == dtype) { |
302 surface.reset(SkSurface::NewRaster(info)); | 320 surface.reset(SkSurface::NewRaster(info)); |
303 } else { | 321 } else { |
304 #if SK_SUPPORT_GPU | 322 #if SK_SUPPORT_GPU |
305 GrContextFactory::GLContextType type = | 323 GrContextFactory::GLContextType type = |
306 static_cast<GrContextFactory::GLContextType>(glCtxType); | 324 static_cast<GrContextFactory::GLContextType>(glCtxType); |
307 if (!GrContextFactory::IsRenderingGLContext(type)) { | 325 if (!GrContextFactory::IsRenderingGLContext(type)) { |
308 continue; | 326 continue; |
309 } | 327 } |
310 GrContext* context = factory->get(type); | 328 GrContext* context = factory->get(type); |
311 if (NULL == context) { | 329 if (NULL == context) { |
312 continue; | 330 continue; |
313 } | 331 } |
314 GrSurfaceDesc desc; | 332 GrSurfaceDesc desc; |
315 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 333 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
316 desc.fWidth = DEV_W; | 334 desc.fWidth = DEV_W; |
317 desc.fHeight = DEV_H; | 335 desc.fHeight = DEV_H; |
318 desc.fConfig = kSkia8888_GrPixelConfig; | 336 desc.fConfig = kSkia8888_GrPixelConfig; |
319 desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLe
ft_GrSurfaceOrigin; | 337 desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLe
ft_GrSurfaceOrigin; |
320 SkAutoTUnref<GrTexture> texture( | 338 SkAutoTUnref<GrTexture> surfaceTexture( |
321 context->textureProvider()->createTexture(desc, false)); | 339 context->textureProvider()->createTexture(desc, false)); |
322 surface.reset(SkSurface::NewRenderTargetDirect(texture->asRender
Target())); | 340 surface.reset(SkSurface::NewRenderTargetDirect(surfaceTexture->a
sRenderTarget())); |
| 341 desc.fFlags = kNone_GrSurfaceFlags; |
| 342 |
| 343 texture.reset(context->textureProvider()->createTexture(desc, fa
lse)); |
323 #else | 344 #else |
324 continue; | 345 continue; |
325 #endif | 346 #endif |
326 } | 347 } |
327 SkCanvas& canvas = *surface->getCanvas(); | 348 SkCanvas& canvas = *surface->getCanvas(); |
328 fillCanvas(&canvas); | 349 fill_src_canvas(&canvas); |
| 350 |
| 351 #if SK_SUPPORT_GPU |
| 352 if (texture) { |
| 353 fill_src_texture(texture); |
| 354 } |
| 355 #endif |
329 | 356 |
330 static const struct { | 357 static const struct { |
331 SkColorType fColorType; | 358 SkColorType fColorType; |
332 SkAlphaType fAlphaType; | 359 SkAlphaType fAlphaType; |
333 } gReadConfigs[] = { | 360 } gReadConfigs[] = { |
334 { kRGBA_8888_SkColorType, kPremul_SkAlphaType }, | 361 { kRGBA_8888_SkColorType, kPremul_SkAlphaType }, |
335 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType }, | 362 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType }, |
336 { kBGRA_8888_SkColorType, kPremul_SkAlphaType }, | 363 { kBGRA_8888_SkColorType, kPremul_SkAlphaType }, |
337 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType }, | 364 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType }, |
338 }; | 365 }; |
339 for (size_t rect = 0; rect < SK_ARRAY_COUNT(testRects); ++rect) { | 366 for (size_t rect = 0; rect < SK_ARRAY_COUNT(testRects); ++rect) { |
340 const SkIRect& srcRect = testRects[rect]; | 367 const SkIRect& srcRect = testRects[rect]; |
341 for (BitmapInit bmi = kFirstBitmapInit; bmi < kBitmapInitCnt; bm
i = nextBMI(bmi)) { | 368 for (BitmapInit bmi = kFirstBitmapInit; bmi < kBitmapInitCnt; bm
i = nextBMI(bmi)) { |
342 for (size_t c = 0; c < SK_ARRAY_COUNT(gReadConfigs); ++c) { | 369 for (size_t c = 0; c < SK_ARRAY_COUNT(gReadConfigs); ++c) { |
343 SkBitmap bmp; | 370 SkBitmap bmp; |
344 init_bitmap(&bmp, srcRect, bmi, | 371 init_bitmap(&bmp, srcRect, bmi, |
345 gReadConfigs[c].fColorType, gReadConfigs[c].
fAlphaType); | 372 gReadConfigs[c].fColorType, gReadConfigs[c].
fAlphaType); |
346 | 373 |
347 // if the bitmap has pixels allocated before the readPix
els, | 374 // if the bitmap has pixels allocated before the readPix
els, |
348 // note that and fill them with pattern | 375 // note that and fill them with pattern |
349 bool startsWithPixels = !bmp.isNull(); | 376 bool startsWithPixels = !bmp.isNull(); |
350 if (startsWithPixels) { | 377 if (startsWithPixels) { |
351 fillBitmap(&bmp); | 378 fill_dst_bmp_with_init_data(&bmp); |
352 } | 379 } |
353 uint32_t idBefore = surface->generationID(); | 380 uint32_t idBefore = surface->generationID(); |
354 bool success = canvas.readPixels(&bmp, srcRect.fLeft, sr
cRect.fTop); | 381 bool success = canvas.readPixels(&bmp, srcRect.fLeft, sr
cRect.fTop); |
355 uint32_t idAfter = surface->generationID(); | 382 uint32_t idAfter = surface->generationID(); |
356 | 383 |
357 // we expect to succeed when the read isn't fully clippe
d | 384 // we expect to succeed when the read isn't fully clippe
d |
358 // out. | 385 // out. |
359 bool expectSuccess = SkIRect::Intersects(srcRect, DEV_RE
CT); | 386 bool expectSuccess = SkIRect::Intersects(srcRect, DEV_RE
CT); |
360 // determine whether we expected the read to succeed. | 387 // determine whether we expected the read to succeed. |
361 REPORTER_ASSERT(reporter, success == expectSuccess); | 388 REPORTER_ASSERT(reporter, success == expectSuccess); |
362 // read pixels should never change the gen id | 389 // read pixels should never change the gen id |
363 REPORTER_ASSERT(reporter, idBefore == idAfter); | 390 REPORTER_ASSERT(reporter, idBefore == idAfter); |
364 | 391 |
365 if (success || startsWithPixels) { | 392 if (success || startsWithPixels) { |
366 checkRead(reporter, bmp, srcRect.fLeft, srcRect.fTop
, | 393 check_read(reporter, bmp, srcRect.fLeft, srcRect.fTo
p, |
367 success, startsWithPixels); | 394 success, startsWithPixels); |
368 } else { | 395 } else { |
369 // if we had no pixels beforehand and the readPixels | 396 // if we had no pixels beforehand and the readPixels |
370 // failed then our bitmap should still not have pixe
ls | 397 // failed then our bitmap should still not have pixe
ls |
371 REPORTER_ASSERT(reporter, bmp.isNull()); | 398 REPORTER_ASSERT(reporter, bmp.isNull()); |
372 } | 399 } |
| 400 #if SK_SUPPORT_GPU |
| 401 // Try doing the read directly from a non-renderable tex
ture |
| 402 if (texture && startsWithPixels) { |
| 403 fill_dst_bmp_with_init_data(&bmp); |
| 404 GrPixelConfig dstConfig = |
| 405 SkImageInfo2GrPixelConfig(gReadConfigs[c].fColor
Type, |
| 406 gReadConfigs[c].fAlpha
Type, |
| 407 kLinear_SkColorProfile
Type); |
| 408 uint32_t flags = 0; |
| 409 if (gReadConfigs[c].fAlphaType == kUnpremul_SkAlphaT
ype) { |
| 410 flags = GrContext::kUnpremul_PixelOpsFlag; |
| 411 } |
| 412 bmp.lockPixels(); |
| 413 success = texture->readPixels(srcRect.fLeft, srcRect
.fTop, bmp.width(), |
| 414 bmp.height(), dstConfig, bmp.get
Pixels(), |
| 415 bmp.rowBytes(), flags); |
| 416 bmp.unlockPixels(); |
| 417 check_read(reporter, bmp, srcRect.fLeft, srcRect.fTo
p, |
| 418 success, true); |
| 419 } |
| 420 #endif |
373 } | 421 } |
374 // check the old webkit version of readPixels that clips the | 422 // check the old webkit version of readPixels that clips the |
375 // bitmap size | 423 // bitmap size |
376 SkBitmap wkbmp; | 424 SkBitmap wkbmp; |
377 bool success = canvas.readPixels(srcRect, &wkbmp); | 425 bool success = canvas.readPixels(srcRect, &wkbmp); |
378 SkIRect clippedRect = DEV_RECT; | 426 SkIRect clippedRect = DEV_RECT; |
379 if (clippedRect.intersect(srcRect)) { | 427 if (clippedRect.intersect(srcRect)) { |
380 REPORTER_ASSERT(reporter, success); | 428 REPORTER_ASSERT(reporter, success); |
381 REPORTER_ASSERT(reporter, kN32_SkColorType == wkbmp.colo
rType()); | 429 REPORTER_ASSERT(reporter, kN32_SkColorType == wkbmp.colo
rType()); |
382 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == wkbmp.a
lphaType()); | 430 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == wkbmp.a
lphaType()); |
383 checkRead(reporter, wkbmp, clippedRect.fLeft, | 431 check_read(reporter, wkbmp, clippedRect.fLeft, |
384 clippedRect.fTop, true, false); | 432 clippedRect.fTop, true, false); |
385 } else { | 433 } else { |
386 REPORTER_ASSERT(reporter, !success); | 434 REPORTER_ASSERT(reporter, !success); |
387 } | 435 } |
388 } | 436 } |
389 } | 437 } |
390 } | 438 } |
391 } | 439 } |
392 } | 440 } |
OLD | NEW |