blob: cead36f0d99f57208d61fce45e6b0cb386a31dd5 [file] [log] [blame]
bsalomon@google.comc6980972011-11-02 19:57:21 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
robertphillips@google.com73672252013-08-29 12:40:26 +00008#include "SkBitmapDevice.h"
bsalomon@google.comc6980972011-11-02 19:57:21 +00009#include "SkCanvas.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000010#include "SkColorPriv.h"
reed@google.com4b163ed2012-08-07 21:35:13 +000011#include "SkMathPriv.h"
bsalomon@google.comc6980972011-11-02 19:57:21 +000012#include "SkRegion.h"
reed52d9ac62014-06-30 09:05:34 -070013#include "SkSurface.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000014#include "Test.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000015
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000016#if SK_SUPPORT_GPU
bsalomon@google.com67b915d2013-02-04 16:13:32 +000017#include "GrContextFactory.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000018#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000019#endif
bsalomon@google.comc6980972011-11-02 19:57:21 +000020
bsalomon@google.comc6980972011-11-02 19:57:21 +000021static const int DEV_W = 100, DEV_H = 100;
22static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
rmistry@google.comd6176b02012-08-23 18:14:13 +000023static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1,
bsalomon@google.comc6980972011-11-02 19:57:21 +000024 DEV_H * SK_Scalar1);
25
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +000026static SkPMColor getCanvasColor(int x, int y) {
bsalomon@google.comc6980972011-11-02 19:57:21 +000027 SkASSERT(x >= 0 && x < DEV_W);
28 SkASSERT(y >= 0 && y < DEV_H);
bsalomon@google.com6850eab2011-11-03 20:29:47 +000029
30 U8CPU r = x;
31 U8CPU g = y;
32 U8CPU b = 0xc;
33
34 U8CPU a = 0xff;
bsalomon@google.comc4364992011-11-07 15:54:49 +000035 switch ((x+y) % 5) {
bsalomon@google.com6850eab2011-11-03 20:29:47 +000036 case 0:
37 a = 0xff;
38 break;
39 case 1:
40 a = 0x80;
41 break;
42 case 2:
43 a = 0xCC;
44 break;
45 case 4:
46 a = 0x01;
47 break;
48 case 3:
49 a = 0x00;
50 break;
51 }
52 return SkPremultiplyARGBInline(a, r, g, b);
bsalomon@google.comc6980972011-11-02 19:57:21 +000053}
rmistry@google.comd6176b02012-08-23 18:14:13 +000054
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +000055static SkPMColor getBitmapColor(int x, int y, int w) {
bsalomon@google.comc6980972011-11-02 19:57:21 +000056 int n = y * w + x;
bsalomon@google.com6850eab2011-11-03 20:29:47 +000057
bsalomon@google.comc6980972011-11-02 19:57:21 +000058 U8CPU b = n & 0xff;
59 U8CPU g = (n >> 8) & 0xff;
60 U8CPU r = (n >> 16) & 0xff;
61 return SkPackARGB32(0xff, r, g , b);
62}
63
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000064static SkPMColor convertToPMColor(SkColorType ct, SkAlphaType at, const uint32_t* addr,
65 bool* doUnpremul) {
66 *doUnpremul = (kUnpremul_SkAlphaType == at);
67
68 const uint8_t* c = reinterpret_cast<const uint8_t*>(addr);
bsalomon@google.com6850eab2011-11-03 20:29:47 +000069 U8CPU a,r,g,b;
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000070 switch (ct) {
71 case kBGRA_8888_SkColorType:
bsalomon@google.com6850eab2011-11-03 20:29:47 +000072 b = static_cast<U8CPU>(c[0]);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000073 g = static_cast<U8CPU>(c[1]);
74 r = static_cast<U8CPU>(c[2]);
bsalomon@google.com6850eab2011-11-03 20:29:47 +000075 a = static_cast<U8CPU>(c[3]);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000076 break;
77 case kRGBA_8888_SkColorType:
bsalomon@google.com6850eab2011-11-03 20:29:47 +000078 r = static_cast<U8CPU>(c[0]);
79 g = static_cast<U8CPU>(c[1]);
80 b = static_cast<U8CPU>(c[2]);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000081 a = static_cast<U8CPU>(c[3]);
bsalomon@google.com6850eab2011-11-03 20:29:47 +000082 break;
bsalomon@google.comccaa0022012-09-25 19:55:07 +000083 default:
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000084 SkDEBUGFAIL("Unexpected colortype");
bsalomon@google.comccaa0022012-09-25 19:55:07 +000085 return 0;
bsalomon@google.com6850eab2011-11-03 20:29:47 +000086 }
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000087
88 if (*doUnpremul) {
bsalomon@google.com6850eab2011-11-03 20:29:47 +000089 r = SkMulDiv255Ceiling(r, a);
90 g = SkMulDiv255Ceiling(g, a);
91 b = SkMulDiv255Ceiling(b, a);
92 }
93 return SkPackARGB32(a, r, g, b);
94}
95
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +000096static void fillCanvas(SkCanvas* canvas) {
bsalomon@google.comc6980972011-11-02 19:57:21 +000097 static SkBitmap bmp;
98 if (bmp.isNull()) {
reed84825042014-09-02 12:50:45 -070099 bmp.allocN32Pixels(DEV_W, DEV_H);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000100 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
101 for (int y = 0; y < DEV_H; ++y) {
102 for (int x = 0; x < DEV_W; ++x) {
103 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp.rowBytes() + x * bmp.bytesPerPixel());
104 *pixel = getCanvasColor(x, y);
105 }
106 }
107 }
108 canvas->save();
109 canvas->setMatrix(SkMatrix::I());
110 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op);
111 SkPaint paint;
112 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
113 canvas->drawBitmap(bmp, 0, 0, &paint);
114 canvas->restore();
115}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000116
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000117static void fillBitmap(SkBitmap* bitmap) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000118 SkASSERT(bitmap->lockPixelsAreWritable());
119 SkAutoLockPixels alp(*bitmap);
120 int w = bitmap->width();
121 int h = bitmap->height();
122 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels());
123 for (int y = 0; y < h; ++y) {
124 for (int x = 0; x < w; ++x) {
125 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap->rowBytes() + x * bitmap->bytesPerPixel());
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000126 *pixel = getBitmapColor(x, y, w);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000127 }
128 }
129}
130
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000131static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) {
bsalomon@google.comc4364992011-11-07 15:54:49 +0000132 if (!didPremulConversion) {
133 return a == b;
134 }
135 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a));
136 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a));
137 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a));
138 int32_t aB = SkGetPackedB32(a);
139
140 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b));
141 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b));
142 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b));
143 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b));
144
145 return aA == bA &&
146 SkAbs32(aR - bR) <= 1 &&
147 SkAbs32(aG - bG) <= 1 &&
148 SkAbs32(aB - bB) <= 1;
149}
150
bsalomon@google.comc6980972011-11-02 19:57:21 +0000151// checks the bitmap contains correct pixels after the readPixels
152// if the bitmap was prefilled with pixels it checks that these weren't
153// overwritten in the area outside the readPixels.
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000154static bool checkRead(skiatest::Reporter* reporter,
155 const SkBitmap& bitmap,
156 int x, int y,
157 bool checkCanvasPixels,
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000158 bool checkBitmapPixels) {
159 SkASSERT(4 == bitmap.bytesPerPixel());
bsalomon@google.comc6980972011-11-02 19:57:21 +0000160 SkASSERT(!bitmap.isNull());
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000161 SkASSERT(checkCanvasPixels || checkBitmapPixels);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000162
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000163 const SkColorType ct = bitmap.colorType();
164 const SkAlphaType at = bitmap.alphaType();
165
bsalomon@google.comc6980972011-11-02 19:57:21 +0000166 int bw = bitmap.width();
167 int bh = bitmap.height();
168
169 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh);
170 SkIRect clippedSrcRect = DEV_RECT;
171 if (!clippedSrcRect.intersect(srcRect)) {
172 clippedSrcRect.setEmpty();
173 }
bsalomon@google.comc6980972011-11-02 19:57:21 +0000174 SkAutoLockPixels alp(bitmap);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000175 for (int by = 0; by < bh; ++by) {
176 for (int bx = 0; bx < bw; ++bx) {
177 int devx = bx + srcRect.fLeft;
178 int devy = by + srcRect.fTop;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000179
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000180 const uint32_t* pixel = bitmap.getAddr32(bx, by);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000181
182 if (clippedSrcRect.contains(devx, devy)) {
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000183 if (checkCanvasPixels) {
184 SkPMColor canvasPixel = getCanvasColor(devx, devy);
bsalomon@google.comc4364992011-11-07 15:54:49 +0000185 bool didPremul;
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000186 SkPMColor pmPixel = convertToPMColor(ct, at, pixel, &didPremul);
bsalomon@google.comc4364992011-11-07 15:54:49 +0000187 bool check;
188 REPORTER_ASSERT(reporter, check = checkPixel(pmPixel, canvasPixel, didPremul));
189 if (!check) {
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000190 return false;
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000191 }
bsalomon@google.comc6980972011-11-02 19:57:21 +0000192 }
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000193 } else if (checkBitmapPixels) {
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000194 REPORTER_ASSERT(reporter, getBitmapColor(bx, by, bw) == *pixel);
195 if (getBitmapColor(bx, by, bw) != *pixel) {
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000196 return false;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000197 }
198 }
199 }
200 }
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000201 return true;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000202}
203
204enum BitmapInit {
205 kFirstBitmapInit = 0,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000206
bsalomon@google.comc6980972011-11-02 19:57:21 +0000207 kNoPixels_BitmapInit = kFirstBitmapInit,
208 kTight_BitmapInit,
209 kRowBytes_BitmapInit,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000210
bsalomon@google.comc6980972011-11-02 19:57:21 +0000211 kBitmapInitCnt
212};
213
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000214static BitmapInit nextBMI(BitmapInit bmi) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000215 int x = bmi;
216 return static_cast<BitmapInit>(++x);
217}
218
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000219static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init, SkColorType ct,
220 SkAlphaType at) {
221 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), ct, at);
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000222 size_t rowBytes = 0;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000223 bool alloc = true;
224 switch (init) {
225 case kNoPixels_BitmapInit:
226 alloc = false;
227 case kTight_BitmapInit:
228 break;
229 case kRowBytes_BitmapInit:
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000230 rowBytes = (info.width() + 16) * sizeof(SkPMColor);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000231 break;
232 default:
233 SkASSERT(0);
234 break;
235 }
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000236
bsalomon@google.comc6980972011-11-02 19:57:21 +0000237 if (alloc) {
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000238 bitmap->allocPixels(info);
239 } else {
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +0000240 bitmap->setInfo(info, rowBytes);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000241 }
242}
243
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000244DEF_GPUTEST(ReadPixels, reporter, factory) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000245 const SkIRect testRects[] = {
246 // entire thing
247 DEV_RECT,
248 // larger on all sides
249 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10),
250 // fully contained
251 SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4),
252 // outside top left
253 SkIRect::MakeLTRB(-10, -10, -1, -1),
254 // touching top left corner
255 SkIRect::MakeLTRB(-10, -10, 0, 0),
256 // overlapping top left corner
257 SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H / 4),
258 // overlapping top left and top right corners
259 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H / 4),
260 // touching entire top edge
261 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, 0),
262 // overlapping top right corner
263 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H / 4),
264 // contained in x, overlapping top edge
265 SkIRect::MakeLTRB(DEV_W / 4, -10, 3 * DEV_W / 4, DEV_H / 4),
266 // outside top right corner
267 SkIRect::MakeLTRB(DEV_W + 1, -10, DEV_W + 10, -1),
268 // touching top right corner
269 SkIRect::MakeLTRB(DEV_W, -10, DEV_W + 10, 0),
270 // overlapping top left and bottom left corners
271 SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H + 10),
272 // touching entire left edge
273 SkIRect::MakeLTRB(-10, -10, 0, DEV_H + 10),
274 // overlapping bottom left corner
275 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W / 4, DEV_H + 10),
276 // contained in y, overlapping left edge
277 SkIRect::MakeLTRB(-10, DEV_H / 4, DEV_W / 4, 3 * DEV_H / 4),
278 // outside bottom left corner
279 SkIRect::MakeLTRB(-10, DEV_H + 1, -1, DEV_H + 10),
280 // touching bottom left corner
281 SkIRect::MakeLTRB(-10, DEV_H, 0, DEV_H + 10),
282 // overlapping bottom left and bottom right corners
283 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
284 // touching entire left edge
285 SkIRect::MakeLTRB(0, DEV_H, DEV_W, DEV_H + 10),
286 // overlapping bottom right corner
287 SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
288 // overlapping top right and bottom right corners
289 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
290 };
291
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000292 for (int dtype = 0; dtype < 3; ++dtype) {
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000293 int glCtxTypeCnt = 1;
294#if SK_SUPPORT_GPU
295 if (0 != dtype) {
296 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000297 }
djsollen@google.com8688e5b2012-01-09 13:02:20 +0000298#endif
reed52d9ac62014-06-30 09:05:34 -0700299 const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000300 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
reed52d9ac62014-06-30 09:05:34 -0700301 SkAutoTUnref<SkSurface> surface;
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000302 if (0 == dtype) {
reed52d9ac62014-06-30 09:05:34 -0700303 surface.reset(SkSurface::NewRaster(info));
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000304 } else {
305#if SK_SUPPORT_GPU
306 GrContextFactory::GLContextType type =
307 static_cast<GrContextFactory::GLContextType>(glCtxType);
308 if (!GrContextFactory::IsRenderingGLContext(type)) {
309 continue;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000310 }
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000311 GrContext* context = factory->get(type);
312 if (NULL == context) {
313 continue;
314 }
bsalomonf2703d82014-10-28 14:33:06 -0700315 GrSurfaceDesc desc;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800316 desc.fFlags = kRenderTarget_GrSurfaceFlag;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000317 desc.fWidth = DEV_W;
318 desc.fHeight = DEV_H;
bsalomon@google.comfec0bc32013-02-07 14:43:04 +0000319 desc.fConfig = kSkia8888_GrPixelConfig;
reed52d9ac62014-06-30 09:05:34 -0700320 desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
bsalomond0423582015-02-06 08:49:24 -0800321 SkAutoTUnref<GrTexture> texture(context->createTexture(desc, false));
bsalomone3059732014-10-14 11:47:22 -0700322 surface.reset(SkSurface::NewRenderTargetDirect(texture->asRenderTarget()));
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000323#else
324 continue;
325#endif
326 }
reed52d9ac62014-06-30 09:05:34 -0700327 SkCanvas& canvas = *surface->getCanvas();
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000328 fillCanvas(&canvas);
329
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000330 static const struct {
331 SkColorType fColorType;
332 SkAlphaType fAlphaType;
333 } gReadConfigs[] = {
334 { kRGBA_8888_SkColorType, kPremul_SkAlphaType },
335 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
336 { kBGRA_8888_SkColorType, kPremul_SkAlphaType },
337 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000338 };
339 for (size_t rect = 0; rect < SK_ARRAY_COUNT(testRects); ++rect) {
340 const SkIRect& srcRect = testRects[rect];
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000341 for (BitmapInit bmi = kFirstBitmapInit; bmi < kBitmapInitCnt; bmi = nextBMI(bmi)) {
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000342 for (size_t c = 0; c < SK_ARRAY_COUNT(gReadConfigs); ++c) {
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000343 SkBitmap bmp;
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000344 init_bitmap(&bmp, srcRect, bmi,
345 gReadConfigs[c].fColorType, gReadConfigs[c].fAlphaType);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000346
347 // if the bitmap has pixels allocated before the readPixels,
348 // note that and fill them with pattern
349 bool startsWithPixels = !bmp.isNull();
350 if (startsWithPixels) {
351 fillBitmap(&bmp);
352 }
reed52d9ac62014-06-30 09:05:34 -0700353 uint32_t idBefore = surface->generationID();
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000354 bool success = canvas.readPixels(&bmp, srcRect.fLeft, srcRect.fTop);
reed52d9ac62014-06-30 09:05:34 -0700355 uint32_t idAfter = surface->generationID();
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000356
357 // we expect to succeed when the read isn't fully clipped
358 // out.
359 bool expectSuccess = SkIRect::Intersects(srcRect, DEV_RECT);
360 // determine whether we expected the read to succeed.
361 REPORTER_ASSERT(reporter, success == expectSuccess);
362 // read pixels should never change the gen id
363 REPORTER_ASSERT(reporter, idBefore == idAfter);
364
365 if (success || startsWithPixels) {
366 checkRead(reporter, bmp, srcRect.fLeft, srcRect.fTop,
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000367 success, startsWithPixels);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000368 } else {
369 // if we had no pixels beforehand and the readPixels
370 // failed then our bitmap should still not have pixels
371 REPORTER_ASSERT(reporter, bmp.isNull());
372 }
373 }
374 // check the old webkit version of readPixels that clips the
375 // bitmap size
376 SkBitmap wkbmp;
377 bool success = canvas.readPixels(srcRect, &wkbmp);
378 SkIRect clippedRect = DEV_RECT;
379 if (clippedRect.intersect(srcRect)) {
380 REPORTER_ASSERT(reporter, success);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000381 REPORTER_ASSERT(reporter, kN32_SkColorType == wkbmp.colorType());
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000382 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == wkbmp.alphaType());
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000383 checkRead(reporter, wkbmp, clippedRect.fLeft,
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000384 clippedRect.fTop, true, false);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000385 } else {
386 REPORTER_ASSERT(reporter, !success);
387 }
bsalomon@google.comc6980972011-11-02 19:57:21 +0000388 }
389 }
390 }
391 }
392}