blob: 59c826fbf096ae05305b6980f18a850d8166a03c [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
bsalomon@google.comc6980972011-11-02 19:57:21 +00008#include "SkCanvas.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00009#include "SkColorPriv.h"
reed@google.com4b163ed2012-08-07 21:35:13 +000010#include "SkMathPriv.h"
bsalomon@google.comc6980972011-11-02 19:57:21 +000011#include "SkRegion.h"
reed52d9ac62014-06-30 09:05:34 -070012#include "SkSurface.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000013#include "Test.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000014
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000015#if SK_SUPPORT_GPU
bsalomon@google.com67b915d2013-02-04 16:13:32 +000016#include "GrContextFactory.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000017#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000018#endif
bsalomon@google.comc6980972011-11-02 19:57:21 +000019
bsalomon@google.comc6980972011-11-02 19:57:21 +000020static const int DEV_W = 100, DEV_H = 100;
21static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
rmistry@google.comd6176b02012-08-23 18:14:13 +000022static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1,
bsalomon@google.comc6980972011-11-02 19:57:21 +000023 DEV_H * SK_Scalar1);
24
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +000025static SkPMColor getCanvasColor(int x, int y) {
bsalomon@google.comc6980972011-11-02 19:57:21 +000026 SkASSERT(x >= 0 && x < DEV_W);
27 SkASSERT(y >= 0 && y < DEV_H);
bsalomon@google.com6850eab2011-11-03 20:29:47 +000028
29 U8CPU r = x;
30 U8CPU g = y;
31 U8CPU b = 0xc;
32
33 U8CPU a = 0xff;
bsalomon@google.comc4364992011-11-07 15:54:49 +000034 switch ((x+y) % 5) {
bsalomon@google.com6850eab2011-11-03 20:29:47 +000035 case 0:
36 a = 0xff;
37 break;
38 case 1:
39 a = 0x80;
40 break;
41 case 2:
42 a = 0xCC;
43 break;
44 case 4:
45 a = 0x01;
46 break;
47 case 3:
48 a = 0x00;
49 break;
50 }
51 return SkPremultiplyARGBInline(a, r, g, b);
bsalomon@google.comc6980972011-11-02 19:57:21 +000052}
rmistry@google.comd6176b02012-08-23 18:14:13 +000053
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +000054static SkPMColor getBitmapColor(int x, int y, int w) {
bsalomon@google.comc6980972011-11-02 19:57:21 +000055 int n = y * w + x;
bsalomon@google.com6850eab2011-11-03 20:29:47 +000056
bsalomon@google.comc6980972011-11-02 19:57:21 +000057 U8CPU b = n & 0xff;
58 U8CPU g = (n >> 8) & 0xff;
59 U8CPU r = (n >> 16) & 0xff;
60 return SkPackARGB32(0xff, r, g , b);
61}
62
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000063static SkPMColor convertToPMColor(SkColorType ct, SkAlphaType at, const uint32_t* addr,
64 bool* doUnpremul) {
65 *doUnpremul = (kUnpremul_SkAlphaType == at);
66
67 const uint8_t* c = reinterpret_cast<const uint8_t*>(addr);
bsalomon@google.com6850eab2011-11-03 20:29:47 +000068 U8CPU a,r,g,b;
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000069 switch (ct) {
70 case kBGRA_8888_SkColorType:
bsalomon@google.com6850eab2011-11-03 20:29:47 +000071 b = static_cast<U8CPU>(c[0]);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000072 g = static_cast<U8CPU>(c[1]);
73 r = static_cast<U8CPU>(c[2]);
bsalomon@google.com6850eab2011-11-03 20:29:47 +000074 a = static_cast<U8CPU>(c[3]);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000075 break;
76 case kRGBA_8888_SkColorType:
bsalomon@google.com6850eab2011-11-03 20:29:47 +000077 r = static_cast<U8CPU>(c[0]);
78 g = static_cast<U8CPU>(c[1]);
79 b = static_cast<U8CPU>(c[2]);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000080 a = static_cast<U8CPU>(c[3]);
bsalomon@google.com6850eab2011-11-03 20:29:47 +000081 break;
bsalomon@google.comccaa0022012-09-25 19:55:07 +000082 default:
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000083 SkDEBUGFAIL("Unexpected colortype");
bsalomon@google.comccaa0022012-09-25 19:55:07 +000084 return 0;
bsalomon@google.com6850eab2011-11-03 20:29:47 +000085 }
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000086
87 if (*doUnpremul) {
bsalomon@google.com6850eab2011-11-03 20:29:47 +000088 r = SkMulDiv255Ceiling(r, a);
89 g = SkMulDiv255Ceiling(g, a);
90 b = SkMulDiv255Ceiling(b, a);
91 }
92 return SkPackARGB32(a, r, g, b);
93}
94
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +000095static void fillCanvas(SkCanvas* canvas) {
bsalomon@google.comc6980972011-11-02 19:57:21 +000096 static SkBitmap bmp;
97 if (bmp.isNull()) {
reed84825042014-09-02 12:50:45 -070098 bmp.allocN32Pixels(DEV_W, DEV_H);
bsalomon@google.comc6980972011-11-02 19:57:21 +000099 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
100 for (int y = 0; y < DEV_H; ++y) {
101 for (int x = 0; x < DEV_W; ++x) {
102 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp.rowBytes() + x * bmp.bytesPerPixel());
103 *pixel = getCanvasColor(x, y);
104 }
105 }
106 }
107 canvas->save();
108 canvas->setMatrix(SkMatrix::I());
109 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op);
110 SkPaint paint;
111 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
112 canvas->drawBitmap(bmp, 0, 0, &paint);
113 canvas->restore();
114}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000115
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000116static void fillBitmap(SkBitmap* bitmap) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000117 SkASSERT(bitmap->lockPixelsAreWritable());
118 SkAutoLockPixels alp(*bitmap);
119 int w = bitmap->width();
120 int h = bitmap->height();
121 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels());
122 for (int y = 0; y < h; ++y) {
123 for (int x = 0; x < w; ++x) {
124 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap->rowBytes() + x * bitmap->bytesPerPixel());
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000125 *pixel = getBitmapColor(x, y, w);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000126 }
127 }
128}
129
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000130static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) {
bsalomon@google.comc4364992011-11-07 15:54:49 +0000131 if (!didPremulConversion) {
132 return a == b;
133 }
134 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a));
135 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a));
136 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a));
137 int32_t aB = SkGetPackedB32(a);
138
139 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b));
140 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b));
141 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b));
142 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b));
143
144 return aA == bA &&
145 SkAbs32(aR - bR) <= 1 &&
146 SkAbs32(aG - bG) <= 1 &&
147 SkAbs32(aB - bB) <= 1;
148}
149
bsalomon@google.comc6980972011-11-02 19:57:21 +0000150// checks the bitmap contains correct pixels after the readPixels
151// if the bitmap was prefilled with pixels it checks that these weren't
152// overwritten in the area outside the readPixels.
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000153static bool checkRead(skiatest::Reporter* reporter,
154 const SkBitmap& bitmap,
155 int x, int y,
156 bool checkCanvasPixels,
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000157 bool checkBitmapPixels) {
158 SkASSERT(4 == bitmap.bytesPerPixel());
bsalomon@google.comc6980972011-11-02 19:57:21 +0000159 SkASSERT(!bitmap.isNull());
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000160 SkASSERT(checkCanvasPixels || checkBitmapPixels);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000161
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000162 const SkColorType ct = bitmap.colorType();
163 const SkAlphaType at = bitmap.alphaType();
164
bsalomon@google.comc6980972011-11-02 19:57:21 +0000165 int bw = bitmap.width();
166 int bh = bitmap.height();
167
168 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh);
169 SkIRect clippedSrcRect = DEV_RECT;
170 if (!clippedSrcRect.intersect(srcRect)) {
171 clippedSrcRect.setEmpty();
172 }
bsalomon@google.comc6980972011-11-02 19:57:21 +0000173 SkAutoLockPixels alp(bitmap);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000174 for (int by = 0; by < bh; ++by) {
175 for (int bx = 0; bx < bw; ++bx) {
176 int devx = bx + srcRect.fLeft;
177 int devy = by + srcRect.fTop;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000178
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000179 const uint32_t* pixel = bitmap.getAddr32(bx, by);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000180
181 if (clippedSrcRect.contains(devx, devy)) {
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000182 if (checkCanvasPixels) {
183 SkPMColor canvasPixel = getCanvasColor(devx, devy);
bsalomon@google.comc4364992011-11-07 15:54:49 +0000184 bool didPremul;
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000185 SkPMColor pmPixel = convertToPMColor(ct, at, pixel, &didPremul);
bsalomon@google.comc4364992011-11-07 15:54:49 +0000186 bool check;
187 REPORTER_ASSERT(reporter, check = checkPixel(pmPixel, canvasPixel, didPremul));
188 if (!check) {
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000189 return false;
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000190 }
bsalomon@google.comc6980972011-11-02 19:57:21 +0000191 }
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000192 } else if (checkBitmapPixels) {
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000193 REPORTER_ASSERT(reporter, getBitmapColor(bx, by, bw) == *pixel);
194 if (getBitmapColor(bx, by, bw) != *pixel) {
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000195 return false;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000196 }
197 }
198 }
199 }
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000200 return true;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000201}
202
203enum BitmapInit {
204 kFirstBitmapInit = 0,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000205
bsalomon@google.comc6980972011-11-02 19:57:21 +0000206 kNoPixels_BitmapInit = kFirstBitmapInit,
207 kTight_BitmapInit,
208 kRowBytes_BitmapInit,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000209
bsalomon@google.comc6980972011-11-02 19:57:21 +0000210 kBitmapInitCnt
211};
212
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000213static BitmapInit nextBMI(BitmapInit bmi) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000214 int x = bmi;
215 return static_cast<BitmapInit>(++x);
216}
217
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000218static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init, SkColorType ct,
219 SkAlphaType at) {
220 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), ct, at);
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000221 size_t rowBytes = 0;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000222 bool alloc = true;
223 switch (init) {
224 case kNoPixels_BitmapInit:
225 alloc = false;
226 case kTight_BitmapInit:
227 break;
228 case kRowBytes_BitmapInit:
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000229 rowBytes = (info.width() + 16) * sizeof(SkPMColor);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000230 break;
231 default:
232 SkASSERT(0);
233 break;
234 }
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000235
bsalomon@google.comc6980972011-11-02 19:57:21 +0000236 if (alloc) {
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000237 bitmap->allocPixels(info);
238 } else {
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +0000239 bitmap->setInfo(info, rowBytes);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000240 }
241}
242
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000243DEF_GPUTEST(ReadPixels, reporter, factory) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000244 const SkIRect testRects[] = {
245 // entire thing
246 DEV_RECT,
247 // larger on all sides
248 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10),
249 // fully contained
250 SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4),
251 // outside top left
252 SkIRect::MakeLTRB(-10, -10, -1, -1),
253 // touching top left corner
254 SkIRect::MakeLTRB(-10, -10, 0, 0),
255 // overlapping top left corner
256 SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H / 4),
257 // overlapping top left and top right corners
258 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H / 4),
259 // touching entire top edge
260 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, 0),
261 // overlapping top right corner
262 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H / 4),
263 // contained in x, overlapping top edge
264 SkIRect::MakeLTRB(DEV_W / 4, -10, 3 * DEV_W / 4, DEV_H / 4),
265 // outside top right corner
266 SkIRect::MakeLTRB(DEV_W + 1, -10, DEV_W + 10, -1),
267 // touching top right corner
268 SkIRect::MakeLTRB(DEV_W, -10, DEV_W + 10, 0),
269 // overlapping top left and bottom left corners
270 SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H + 10),
271 // touching entire left edge
272 SkIRect::MakeLTRB(-10, -10, 0, DEV_H + 10),
273 // overlapping bottom left corner
274 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W / 4, DEV_H + 10),
275 // contained in y, overlapping left edge
276 SkIRect::MakeLTRB(-10, DEV_H / 4, DEV_W / 4, 3 * DEV_H / 4),
277 // outside bottom left corner
278 SkIRect::MakeLTRB(-10, DEV_H + 1, -1, DEV_H + 10),
279 // touching bottom left corner
280 SkIRect::MakeLTRB(-10, DEV_H, 0, DEV_H + 10),
281 // overlapping bottom left and bottom right corners
282 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
283 // touching entire left edge
284 SkIRect::MakeLTRB(0, DEV_H, DEV_W, DEV_H + 10),
285 // overlapping bottom right corner
286 SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
287 // overlapping top right and bottom right corners
288 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
289 };
290
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000291 for (int dtype = 0; dtype < 3; ++dtype) {
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000292 int glCtxTypeCnt = 1;
293#if SK_SUPPORT_GPU
294 if (0 != dtype) {
295 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000296 }
djsollen@google.com8688e5b2012-01-09 13:02:20 +0000297#endif
reed52d9ac62014-06-30 09:05:34 -0700298 const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000299 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
reed52d9ac62014-06-30 09:05:34 -0700300 SkAutoTUnref<SkSurface> surface;
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000301 if (0 == dtype) {
reed52d9ac62014-06-30 09:05:34 -0700302 surface.reset(SkSurface::NewRaster(info));
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000303 } else {
304#if SK_SUPPORT_GPU
305 GrContextFactory::GLContextType type =
306 static_cast<GrContextFactory::GLContextType>(glCtxType);
307 if (!GrContextFactory::IsRenderingGLContext(type)) {
308 continue;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000309 }
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000310 GrContext* context = factory->get(type);
311 if (NULL == context) {
312 continue;
313 }
bsalomonf2703d82014-10-28 14:33:06 -0700314 GrSurfaceDesc desc;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800315 desc.fFlags = kRenderTarget_GrSurfaceFlag;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000316 desc.fWidth = DEV_W;
317 desc.fHeight = DEV_H;
bsalomon@google.comfec0bc32013-02-07 14:43:04 +0000318 desc.fConfig = kSkia8888_GrPixelConfig;
reed52d9ac62014-06-30 09:05:34 -0700319 desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
bsalomond309e7a2015-04-30 14:18:54 -0700320 SkAutoTUnref<GrTexture> texture(
321 context->textureProvider()->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}