blob: d0bf9031f0f6fe09a36bd7933f85cd2137cf8bab [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()) {
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +000099 SkDEBUGCODE(bool alloc =) bmp.allocN32Pixels(DEV_W, DEV_H);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000100 SkASSERT(alloc);
101 SkAutoLockPixels alp(bmp);
102 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
103 for (int y = 0; y < DEV_H; ++y) {
104 for (int x = 0; x < DEV_W; ++x) {
105 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp.rowBytes() + x * bmp.bytesPerPixel());
106 *pixel = getCanvasColor(x, y);
107 }
108 }
109 }
110 canvas->save();
111 canvas->setMatrix(SkMatrix::I());
112 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op);
113 SkPaint paint;
114 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
115 canvas->drawBitmap(bmp, 0, 0, &paint);
116 canvas->restore();
117}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000118
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000119static void fillBitmap(SkBitmap* bitmap) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000120 SkASSERT(bitmap->lockPixelsAreWritable());
121 SkAutoLockPixels alp(*bitmap);
122 int w = bitmap->width();
123 int h = bitmap->height();
124 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels());
125 for (int y = 0; y < h; ++y) {
126 for (int x = 0; x < w; ++x) {
127 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap->rowBytes() + x * bitmap->bytesPerPixel());
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000128 *pixel = getBitmapColor(x, y, w);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000129 }
130 }
131}
132
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000133static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) {
bsalomon@google.comc4364992011-11-07 15:54:49 +0000134 if (!didPremulConversion) {
135 return a == b;
136 }
137 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a));
138 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a));
139 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a));
140 int32_t aB = SkGetPackedB32(a);
141
142 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b));
143 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b));
144 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b));
145 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b));
146
147 return aA == bA &&
148 SkAbs32(aR - bR) <= 1 &&
149 SkAbs32(aG - bG) <= 1 &&
150 SkAbs32(aB - bB) <= 1;
151}
152
bsalomon@google.comc6980972011-11-02 19:57:21 +0000153// checks the bitmap contains correct pixels after the readPixels
154// if the bitmap was prefilled with pixels it checks that these weren't
155// overwritten in the area outside the readPixels.
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000156static bool checkRead(skiatest::Reporter* reporter,
157 const SkBitmap& bitmap,
158 int x, int y,
159 bool checkCanvasPixels,
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000160 bool checkBitmapPixels) {
161 SkASSERT(4 == bitmap.bytesPerPixel());
bsalomon@google.comc6980972011-11-02 19:57:21 +0000162 SkASSERT(!bitmap.isNull());
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000163 SkASSERT(checkCanvasPixels || checkBitmapPixels);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000164
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000165 const SkColorType ct = bitmap.colorType();
166 const SkAlphaType at = bitmap.alphaType();
167
bsalomon@google.comc6980972011-11-02 19:57:21 +0000168 int bw = bitmap.width();
169 int bh = bitmap.height();
170
171 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh);
172 SkIRect clippedSrcRect = DEV_RECT;
173 if (!clippedSrcRect.intersect(srcRect)) {
174 clippedSrcRect.setEmpty();
175 }
bsalomon@google.comc6980972011-11-02 19:57:21 +0000176 SkAutoLockPixels alp(bitmap);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000177 for (int by = 0; by < bh; ++by) {
178 for (int bx = 0; bx < bw; ++bx) {
179 int devx = bx + srcRect.fLeft;
180 int devy = by + srcRect.fTop;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000181
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000182 const uint32_t* pixel = bitmap.getAddr32(bx, by);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000183
184 if (clippedSrcRect.contains(devx, devy)) {
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000185 if (checkCanvasPixels) {
186 SkPMColor canvasPixel = getCanvasColor(devx, devy);
bsalomon@google.comc4364992011-11-07 15:54:49 +0000187 bool didPremul;
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000188 SkPMColor pmPixel = convertToPMColor(ct, at, pixel, &didPremul);
bsalomon@google.comc4364992011-11-07 15:54:49 +0000189 bool check;
190 REPORTER_ASSERT(reporter, check = checkPixel(pmPixel, canvasPixel, didPremul));
191 if (!check) {
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000192 return false;
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000193 }
bsalomon@google.comc6980972011-11-02 19:57:21 +0000194 }
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000195 } else if (checkBitmapPixels) {
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000196 REPORTER_ASSERT(reporter, getBitmapColor(bx, by, bw) == *pixel);
197 if (getBitmapColor(bx, by, bw) != *pixel) {
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000198 return false;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000199 }
200 }
201 }
202 }
bsalomon@google.com72f3dca2012-08-17 13:32:06 +0000203 return true;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000204}
205
206enum BitmapInit {
207 kFirstBitmapInit = 0,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000208
bsalomon@google.comc6980972011-11-02 19:57:21 +0000209 kNoPixels_BitmapInit = kFirstBitmapInit,
210 kTight_BitmapInit,
211 kRowBytes_BitmapInit,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000212
bsalomon@google.comc6980972011-11-02 19:57:21 +0000213 kBitmapInitCnt
214};
215
commit-bot@chromium.orgddf94cf2013-10-12 17:25:17 +0000216static BitmapInit nextBMI(BitmapInit bmi) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000217 int x = bmi;
218 return static_cast<BitmapInit>(++x);
219}
220
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000221static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init, SkColorType ct,
222 SkAlphaType at) {
223 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), ct, at);
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000224 size_t rowBytes = 0;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000225 bool alloc = true;
226 switch (init) {
227 case kNoPixels_BitmapInit:
228 alloc = false;
229 case kTight_BitmapInit:
230 break;
231 case kRowBytes_BitmapInit:
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000232 rowBytes = (info.width() + 16) * sizeof(SkPMColor);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000233 break;
234 default:
235 SkASSERT(0);
236 break;
237 }
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000238
bsalomon@google.comc6980972011-11-02 19:57:21 +0000239 if (alloc) {
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +0000240 bitmap->allocPixels(info);
241 } else {
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +0000242 bitmap->setInfo(info, rowBytes);
bsalomon@google.comc6980972011-11-02 19:57:21 +0000243 }
244}
245
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000246DEF_GPUTEST(ReadPixels, reporter, factory) {
bsalomon@google.comc6980972011-11-02 19:57:21 +0000247 const SkIRect testRects[] = {
248 // entire thing
249 DEV_RECT,
250 // larger on all sides
251 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10),
252 // fully contained
253 SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4),
254 // outside top left
255 SkIRect::MakeLTRB(-10, -10, -1, -1),
256 // touching top left corner
257 SkIRect::MakeLTRB(-10, -10, 0, 0),
258 // overlapping top left corner
259 SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H / 4),
260 // overlapping top left and top right corners
261 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H / 4),
262 // touching entire top edge
263 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, 0),
264 // overlapping top right corner
265 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H / 4),
266 // contained in x, overlapping top edge
267 SkIRect::MakeLTRB(DEV_W / 4, -10, 3 * DEV_W / 4, DEV_H / 4),
268 // outside top right corner
269 SkIRect::MakeLTRB(DEV_W + 1, -10, DEV_W + 10, -1),
270 // touching top right corner
271 SkIRect::MakeLTRB(DEV_W, -10, DEV_W + 10, 0),
272 // overlapping top left and bottom left corners
273 SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H + 10),
274 // touching entire left edge
275 SkIRect::MakeLTRB(-10, -10, 0, DEV_H + 10),
276 // overlapping bottom left corner
277 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W / 4, DEV_H + 10),
278 // contained in y, overlapping left edge
279 SkIRect::MakeLTRB(-10, DEV_H / 4, DEV_W / 4, 3 * DEV_H / 4),
280 // outside bottom left corner
281 SkIRect::MakeLTRB(-10, DEV_H + 1, -1, DEV_H + 10),
282 // touching bottom left corner
283 SkIRect::MakeLTRB(-10, DEV_H, 0, DEV_H + 10),
284 // overlapping bottom left and bottom right corners
285 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
286 // touching entire left edge
287 SkIRect::MakeLTRB(0, DEV_H, DEV_W, DEV_H + 10),
288 // overlapping bottom right corner
289 SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
290 // overlapping top right and bottom right corners
291 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
292 };
293
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000294 for (int dtype = 0; dtype < 3; ++dtype) {
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000295 int glCtxTypeCnt = 1;
296#if SK_SUPPORT_GPU
297 if (0 != dtype) {
298 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000299 }
djsollen@google.com8688e5b2012-01-09 13:02:20 +0000300#endif
reed52d9ac62014-06-30 09:05:34 -0700301 const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000302 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
reed52d9ac62014-06-30 09:05:34 -0700303 SkAutoTUnref<SkSurface> surface;
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000304 if (0 == dtype) {
reed52d9ac62014-06-30 09:05:34 -0700305 surface.reset(SkSurface::NewRaster(info));
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000306 } else {
307#if SK_SUPPORT_GPU
308 GrContextFactory::GLContextType type =
309 static_cast<GrContextFactory::GLContextType>(glCtxType);
310 if (!GrContextFactory::IsRenderingGLContext(type)) {
311 continue;
bsalomon@google.comc6980972011-11-02 19:57:21 +0000312 }
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000313 GrContext* context = factory->get(type);
314 if (NULL == context) {
315 continue;
316 }
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000317 GrTextureDesc desc;
318 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
319 desc.fWidth = DEV_W;
320 desc.fHeight = DEV_H;
bsalomon@google.comfec0bc32013-02-07 14:43:04 +0000321 desc.fConfig = kSkia8888_GrPixelConfig;
reed52d9ac62014-06-30 09:05:34 -0700322 desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000323 GrAutoScratchTexture ast(context, desc, GrContext::kExact_ScratchTexMatch);
324 SkAutoTUnref<GrTexture> tex(ast.detach());
reed52d9ac62014-06-30 09:05:34 -0700325 surface.reset(SkSurface::NewRenderTargetDirect(tex->asRenderTarget()));
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000326#else
327 continue;
328#endif
329 }
reed52d9ac62014-06-30 09:05:34 -0700330 SkCanvas& canvas = *surface->getCanvas();
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000331 fillCanvas(&canvas);
332
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000333 static const struct {
334 SkColorType fColorType;
335 SkAlphaType fAlphaType;
336 } gReadConfigs[] = {
337 { kRGBA_8888_SkColorType, kPremul_SkAlphaType },
338 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
339 { kBGRA_8888_SkColorType, kPremul_SkAlphaType },
340 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000341 };
342 for (size_t rect = 0; rect < SK_ARRAY_COUNT(testRects); ++rect) {
343 const SkIRect& srcRect = testRects[rect];
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000344 for (BitmapInit bmi = kFirstBitmapInit; bmi < kBitmapInitCnt; bmi = nextBMI(bmi)) {
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000345 for (size_t c = 0; c < SK_ARRAY_COUNT(gReadConfigs); ++c) {
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000346 SkBitmap bmp;
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000347 init_bitmap(&bmp, srcRect, bmi,
348 gReadConfigs[c].fColorType, gReadConfigs[c].fAlphaType);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000349
350 // if the bitmap has pixels allocated before the readPixels,
351 // note that and fill them with pattern
352 bool startsWithPixels = !bmp.isNull();
353 if (startsWithPixels) {
354 fillBitmap(&bmp);
355 }
reed52d9ac62014-06-30 09:05:34 -0700356 uint32_t idBefore = surface->generationID();
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000357 bool success = canvas.readPixels(&bmp, srcRect.fLeft, srcRect.fTop);
reed52d9ac62014-06-30 09:05:34 -0700358 uint32_t idAfter = surface->generationID();
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000359
360 // we expect to succeed when the read isn't fully clipped
361 // out.
362 bool expectSuccess = SkIRect::Intersects(srcRect, DEV_RECT);
363 // determine whether we expected the read to succeed.
364 REPORTER_ASSERT(reporter, success == expectSuccess);
365 // read pixels should never change the gen id
366 REPORTER_ASSERT(reporter, idBefore == idAfter);
367
368 if (success || startsWithPixels) {
369 checkRead(reporter, bmp, srcRect.fLeft, srcRect.fTop,
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000370 success, startsWithPixels);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000371 } else {
372 // if we had no pixels beforehand and the readPixels
373 // failed then our bitmap should still not have pixels
374 REPORTER_ASSERT(reporter, bmp.isNull());
375 }
376 }
377 // check the old webkit version of readPixels that clips the
378 // bitmap size
379 SkBitmap wkbmp;
380 bool success = canvas.readPixels(srcRect, &wkbmp);
381 SkIRect clippedRect = DEV_RECT;
382 if (clippedRect.intersect(srcRect)) {
383 REPORTER_ASSERT(reporter, success);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000384 REPORTER_ASSERT(reporter, kN32_SkColorType == wkbmp.colorType());
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000385 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == wkbmp.alphaType());
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000386 checkRead(reporter, wkbmp, clippedRect.fLeft,
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000387 clippedRect.fTop, true, false);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000388 } else {
389 REPORTER_ASSERT(reporter, !success);
390 }
bsalomon@google.comc6980972011-11-02 19:57:21 +0000391 }
392 }
393 }
394 }
395}