bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1 | /* |
| 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.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 8 | #include "SkCanvas.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 9 | #include "SkColorPriv.h" |
reed@google.com | 4b163ed | 2012-08-07 21:35:13 +0000 | [diff] [blame] | 10 | #include "SkMathPriv.h" |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 11 | #include "SkRegion.h" |
reed | 52d9ac6 | 2014-06-30 09:05:34 -0700 | [diff] [blame] | 12 | #include "SkSurface.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 13 | #include "Test.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 14 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 15 | #if SK_SUPPORT_GPU |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 16 | #include "GrContext.h" |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 17 | #include "SkGr.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 18 | #endif |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 19 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 20 | #include <initializer_list> |
| 21 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 22 | static const int DEV_W = 100, DEV_H = 100; |
| 23 | static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 24 | static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 25 | DEV_H * SK_Scalar1); |
| 26 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 27 | static SkPMColor get_src_color(int x, int y) { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 28 | SkASSERT(x >= 0 && x < DEV_W); |
| 29 | SkASSERT(y >= 0 && y < DEV_H); |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 30 | |
| 31 | U8CPU r = x; |
| 32 | U8CPU g = y; |
| 33 | U8CPU b = 0xc; |
| 34 | |
| 35 | U8CPU a = 0xff; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 36 | switch ((x+y) % 5) { |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 37 | case 0: |
| 38 | a = 0xff; |
| 39 | break; |
| 40 | case 1: |
| 41 | a = 0x80; |
| 42 | break; |
| 43 | case 2: |
| 44 | a = 0xCC; |
| 45 | break; |
| 46 | case 4: |
| 47 | a = 0x01; |
| 48 | break; |
| 49 | case 3: |
| 50 | a = 0x00; |
| 51 | break; |
| 52 | } |
| 53 | return SkPremultiplyARGBInline(a, r, g, b); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 54 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame^] | 55 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 56 | static SkPMColor get_dst_bmp_init_color(int x, int y, int w) { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 57 | int n = y * w + x; |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 58 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 59 | U8CPU b = n & 0xff; |
| 60 | U8CPU g = (n >> 8) & 0xff; |
| 61 | U8CPU r = (n >> 16) & 0xff; |
| 62 | return SkPackARGB32(0xff, r, g , b); |
| 63 | } |
| 64 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 65 | static SkPMColor convert_to_pmcolor(SkColorType ct, SkAlphaType at, const uint32_t* addr, |
| 66 | bool* doUnpremul) { |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 67 | *doUnpremul = (kUnpremul_SkAlphaType == at); |
| 68 | |
| 69 | const uint8_t* c = reinterpret_cast<const uint8_t*>(addr); |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 70 | U8CPU a,r,g,b; |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 71 | switch (ct) { |
| 72 | case kBGRA_8888_SkColorType: |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 73 | b = static_cast<U8CPU>(c[0]); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 74 | g = static_cast<U8CPU>(c[1]); |
| 75 | r = static_cast<U8CPU>(c[2]); |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 76 | a = static_cast<U8CPU>(c[3]); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 77 | break; |
| 78 | case kRGBA_8888_SkColorType: |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 79 | r = static_cast<U8CPU>(c[0]); |
| 80 | g = static_cast<U8CPU>(c[1]); |
| 81 | b = static_cast<U8CPU>(c[2]); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 82 | a = static_cast<U8CPU>(c[3]); |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 83 | break; |
bsalomon@google.com | ccaa002 | 2012-09-25 19:55:07 +0000 | [diff] [blame] | 84 | default: |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 85 | SkDEBUGFAIL("Unexpected colortype"); |
bsalomon@google.com | ccaa002 | 2012-09-25 19:55:07 +0000 | [diff] [blame] | 86 | return 0; |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 87 | } |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 88 | |
| 89 | if (*doUnpremul) { |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 90 | r = SkMulDiv255Ceiling(r, a); |
| 91 | g = SkMulDiv255Ceiling(g, a); |
| 92 | b = SkMulDiv255Ceiling(b, a); |
| 93 | } |
| 94 | return SkPackARGB32(a, r, g, b); |
| 95 | } |
| 96 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 97 | static SkBitmap make_src_bitmap() { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 98 | static SkBitmap bmp; |
| 99 | if (bmp.isNull()) { |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 100 | bmp.allocN32Pixels(DEV_W, DEV_H); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 101 | intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels()); |
| 102 | for (int y = 0; y < DEV_H; ++y) { |
| 103 | for (int x = 0; x < DEV_W; ++x) { |
| 104 | SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp.rowBytes() + x * bmp.bytesPerPixel()); |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 105 | *pixel = get_src_color(x, y); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | } |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 109 | return bmp; |
| 110 | } |
| 111 | |
| 112 | static void fill_src_canvas(SkCanvas* canvas) { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 113 | canvas->save(); |
| 114 | canvas->setMatrix(SkMatrix::I()); |
| 115 | canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op); |
| 116 | SkPaint paint; |
| 117 | paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 118 | canvas->drawBitmap(make_src_bitmap(), 0, 0, &paint); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 119 | canvas->restore(); |
| 120 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 121 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 122 | #if SK_SUPPORT_GPU |
| 123 | static void fill_src_texture(GrTexture* texture) { |
| 124 | SkBitmap bmp = make_src_bitmap(); |
| 125 | bmp.lockPixels(); |
| 126 | texture->writePixels(0, 0, DEV_W, DEV_H, kSkia8888_GrPixelConfig, bmp.getPixels(), |
| 127 | bmp.rowBytes()); |
| 128 | bmp.unlockPixels(); |
| 129 | } |
| 130 | #endif |
| 131 | |
| 132 | static void fill_dst_bmp_with_init_data(SkBitmap* bitmap) { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 133 | SkASSERT(bitmap->lockPixelsAreWritable()); |
| 134 | SkAutoLockPixels alp(*bitmap); |
| 135 | int w = bitmap->width(); |
| 136 | int h = bitmap->height(); |
| 137 | intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels()); |
| 138 | for (int y = 0; y < h; ++y) { |
| 139 | for (int x = 0; x < w; ++x) { |
| 140 | SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap->rowBytes() + x * bitmap->bytesPerPixel()); |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 141 | *pixel = get_dst_bmp_init_color(x, y, w); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 146 | static bool check_read_pixel(SkPMColor a, SkPMColor b, bool didPremulConversion) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 147 | if (!didPremulConversion) { |
| 148 | return a == b; |
| 149 | } |
| 150 | int32_t aA = static_cast<int32_t>(SkGetPackedA32(a)); |
| 151 | int32_t aR = static_cast<int32_t>(SkGetPackedR32(a)); |
| 152 | int32_t aG = static_cast<int32_t>(SkGetPackedG32(a)); |
| 153 | int32_t aB = SkGetPackedB32(a); |
| 154 | |
| 155 | int32_t bA = static_cast<int32_t>(SkGetPackedA32(b)); |
| 156 | int32_t bR = static_cast<int32_t>(SkGetPackedR32(b)); |
| 157 | int32_t bG = static_cast<int32_t>(SkGetPackedG32(b)); |
| 158 | int32_t bB = static_cast<int32_t>(SkGetPackedB32(b)); |
| 159 | |
| 160 | return aA == bA && |
| 161 | SkAbs32(aR - bR) <= 1 && |
| 162 | SkAbs32(aG - bG) <= 1 && |
| 163 | SkAbs32(aB - bB) <= 1; |
| 164 | } |
| 165 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 166 | // checks the bitmap contains correct pixels after the readPixels |
| 167 | // if the bitmap was prefilled with pixels it checks that these weren't |
| 168 | // overwritten in the area outside the readPixels. |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 169 | static bool check_read(skiatest::Reporter* reporter, |
| 170 | const SkBitmap& bitmap, |
| 171 | int x, int y, |
| 172 | bool checkCanvasPixels, |
| 173 | bool checkBitmapPixels) { |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 174 | SkASSERT(4 == bitmap.bytesPerPixel()); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 175 | SkASSERT(!bitmap.isNull()); |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 176 | SkASSERT(checkCanvasPixels || checkBitmapPixels); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 177 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 178 | const SkColorType ct = bitmap.colorType(); |
| 179 | const SkAlphaType at = bitmap.alphaType(); |
| 180 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 181 | int bw = bitmap.width(); |
| 182 | int bh = bitmap.height(); |
| 183 | |
| 184 | SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh); |
| 185 | SkIRect clippedSrcRect = DEV_RECT; |
| 186 | if (!clippedSrcRect.intersect(srcRect)) { |
| 187 | clippedSrcRect.setEmpty(); |
| 188 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 189 | SkAutoLockPixels alp(bitmap); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 190 | for (int by = 0; by < bh; ++by) { |
| 191 | for (int bx = 0; bx < bw; ++bx) { |
| 192 | int devx = bx + srcRect.fLeft; |
| 193 | int devy = by + srcRect.fTop; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 194 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 195 | const uint32_t* pixel = bitmap.getAddr32(bx, by); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 196 | |
| 197 | if (clippedSrcRect.contains(devx, devy)) { |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 198 | if (checkCanvasPixels) { |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 199 | SkPMColor canvasPixel = get_src_color(devx, devy); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 200 | bool didPremul; |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 201 | SkPMColor pmPixel = convert_to_pmcolor(ct, at, pixel, &didPremul); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 202 | if (!check_read_pixel(pmPixel, canvasPixel, didPremul)) { |
| 203 | ERRORF(reporter, "Expected readback pixel value 0x%08x, got 0x%08x. " |
| 204 | "Readback was unpremul: %d", canvasPixel, pmPixel, didPremul); |
bsalomon@google.com | 72f3dca | 2012-08-17 13:32:06 +0000 | [diff] [blame] | 205 | return false; |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 206 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 207 | } |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 208 | } else if (checkBitmapPixels) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 209 | uint32_t origDstPixel = get_dst_bmp_init_color(bx, by, bw); |
| 210 | if (origDstPixel != *pixel) { |
| 211 | ERRORF(reporter, "Expected clipped out area of readback to be unchanged. " |
| 212 | "Expected 0x%08x, got 0x%08x", origDstPixel, *pixel); |
bsalomon@google.com | 72f3dca | 2012-08-17 13:32:06 +0000 | [diff] [blame] | 213 | return false; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
bsalomon@google.com | 72f3dca | 2012-08-17 13:32:06 +0000 | [diff] [blame] | 218 | return true; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | enum BitmapInit { |
| 222 | kFirstBitmapInit = 0, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 223 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 224 | kNoPixels_BitmapInit = kFirstBitmapInit, |
| 225 | kTight_BitmapInit, |
| 226 | kRowBytes_BitmapInit, |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 227 | kRowBytesOdd_BitmapInit, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 228 | |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 229 | kLastAligned_BitmapInit = kRowBytes_BitmapInit, |
Brian Salomon | a64afd6 | 2016-02-01 16:44:22 -0500 | [diff] [blame] | 230 | |
| 231 | #if 0 // THIS CAUSES ERRORS ON WINDOWS AND SOME ANDROID DEVICES |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 232 | kLast_BitmapInit = kRowBytesOdd_BitmapInit |
Brian Salomon | a64afd6 | 2016-02-01 16:44:22 -0500 | [diff] [blame] | 233 | #else |
| 234 | kLast_BitmapInit = kLastAligned_BitmapInit |
| 235 | #endif |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 236 | }; |
| 237 | |
commit-bot@chromium.org | ddf94cf | 2013-10-12 17:25:17 +0000 | [diff] [blame] | 238 | static BitmapInit nextBMI(BitmapInit bmi) { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 239 | int x = bmi; |
| 240 | return static_cast<BitmapInit>(++x); |
| 241 | } |
| 242 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 243 | static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init, SkColorType ct, |
| 244 | SkAlphaType at) { |
| 245 | SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), ct, at); |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 246 | size_t rowBytes = 0; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 247 | bool alloc = true; |
| 248 | switch (init) { |
| 249 | case kNoPixels_BitmapInit: |
| 250 | alloc = false; |
| 251 | case kTight_BitmapInit: |
| 252 | break; |
| 253 | case kRowBytes_BitmapInit: |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 254 | rowBytes = (info.width() + 16) * sizeof(SkPMColor); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 255 | break; |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 256 | case kRowBytesOdd_BitmapInit: |
| 257 | rowBytes = (info.width() * sizeof(SkPMColor)) + 3; |
| 258 | break; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 259 | default: |
| 260 | SkASSERT(0); |
| 261 | break; |
| 262 | } |
skia.committer@gmail.com | 02d6f54 | 2014-02-14 03:02:05 +0000 | [diff] [blame] | 263 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 264 | if (alloc) { |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 265 | bitmap->allocPixels(info, rowBytes); |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 266 | } else { |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 267 | bitmap->setInfo(info, rowBytes); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 271 | static const struct { |
| 272 | SkColorType fColorType; |
| 273 | SkAlphaType fAlphaType; |
| 274 | } gReadPixelsConfigs[] = { |
| 275 | { kRGBA_8888_SkColorType, kPremul_SkAlphaType }, |
| 276 | { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType }, |
| 277 | { kBGRA_8888_SkColorType, kPremul_SkAlphaType }, |
| 278 | { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType }, |
| 279 | }; |
| 280 | const SkIRect gReadPixelsTestRects[] = { |
| 281 | // entire thing |
| 282 | DEV_RECT, |
| 283 | // larger on all sides |
| 284 | SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10), |
| 285 | // fully contained |
| 286 | SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4), |
| 287 | // outside top left |
| 288 | SkIRect::MakeLTRB(-10, -10, -1, -1), |
| 289 | // touching top left corner |
| 290 | SkIRect::MakeLTRB(-10, -10, 0, 0), |
| 291 | // overlapping top left corner |
| 292 | SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H / 4), |
| 293 | // overlapping top left and top right corners |
| 294 | SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H / 4), |
| 295 | // touching entire top edge |
| 296 | SkIRect::MakeLTRB(-10, -10, DEV_W + 10, 0), |
| 297 | // overlapping top right corner |
| 298 | SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H / 4), |
| 299 | // contained in x, overlapping top edge |
| 300 | SkIRect::MakeLTRB(DEV_W / 4, -10, 3 * DEV_W / 4, DEV_H / 4), |
| 301 | // outside top right corner |
| 302 | SkIRect::MakeLTRB(DEV_W + 1, -10, DEV_W + 10, -1), |
| 303 | // touching top right corner |
| 304 | SkIRect::MakeLTRB(DEV_W, -10, DEV_W + 10, 0), |
| 305 | // overlapping top left and bottom left corners |
| 306 | SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H + 10), |
| 307 | // touching entire left edge |
| 308 | SkIRect::MakeLTRB(-10, -10, 0, DEV_H + 10), |
| 309 | // overlapping bottom left corner |
| 310 | SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W / 4, DEV_H + 10), |
| 311 | // contained in y, overlapping left edge |
| 312 | SkIRect::MakeLTRB(-10, DEV_H / 4, DEV_W / 4, 3 * DEV_H / 4), |
| 313 | // outside bottom left corner |
| 314 | SkIRect::MakeLTRB(-10, DEV_H + 1, -1, DEV_H + 10), |
| 315 | // touching bottom left corner |
| 316 | SkIRect::MakeLTRB(-10, DEV_H, 0, DEV_H + 10), |
| 317 | // overlapping bottom left and bottom right corners |
| 318 | SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10), |
| 319 | // touching entire left edge |
| 320 | SkIRect::MakeLTRB(0, DEV_H, DEV_W, DEV_H + 10), |
| 321 | // overlapping bottom right corner |
| 322 | SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10), |
| 323 | // overlapping top right and bottom right corners |
| 324 | SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10), |
| 325 | }; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 326 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 327 | static void test_readpixels(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface, |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 328 | BitmapInit lastBitmapInit) { |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 329 | SkCanvas* canvas = surface->getCanvas(); |
| 330 | fill_src_canvas(canvas); |
| 331 | for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) { |
| 332 | const SkIRect& srcRect = gReadPixelsTestRects[rect]; |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 333 | for (BitmapInit bmi = kFirstBitmapInit; bmi <= lastBitmapInit; bmi = nextBMI(bmi)) { |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 334 | for (size_t c = 0; c < SK_ARRAY_COUNT(gReadPixelsConfigs); ++c) { |
| 335 | SkBitmap bmp; |
| 336 | init_bitmap(&bmp, srcRect, bmi, |
| 337 | gReadPixelsConfigs[c].fColorType, gReadPixelsConfigs[c].fAlphaType); |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 338 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 339 | // if the bitmap has pixels allocated before the readPixels, |
| 340 | // note that and fill them with pattern |
| 341 | bool startsWithPixels = !bmp.isNull(); |
| 342 | if (startsWithPixels) { |
| 343 | fill_dst_bmp_with_init_data(&bmp); |
| 344 | } |
| 345 | uint32_t idBefore = surface->generationID(); |
| 346 | bool success = canvas->readPixels(&bmp, srcRect.fLeft, srcRect.fTop); |
| 347 | uint32_t idAfter = surface->generationID(); |
| 348 | |
| 349 | // we expect to succeed when the read isn't fully clipped |
| 350 | // out. |
| 351 | bool expectSuccess = SkIRect::Intersects(srcRect, DEV_RECT); |
| 352 | // determine whether we expected the read to succeed. |
| 353 | REPORTER_ASSERT(reporter, success == expectSuccess); |
| 354 | // read pixels should never change the gen id |
| 355 | REPORTER_ASSERT(reporter, idBefore == idAfter); |
| 356 | |
| 357 | if (success || startsWithPixels) { |
| 358 | check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop, |
| 359 | success, startsWithPixels); |
| 360 | } else { |
| 361 | // if we had no pixels beforehand and the readPixels |
| 362 | // failed then our bitmap should still not have pixels |
| 363 | REPORTER_ASSERT(reporter, bmp.isNull()); |
| 364 | } |
| 365 | } |
| 366 | // check the old webkit version of readPixels that clips the |
| 367 | // bitmap size |
| 368 | SkBitmap wkbmp; |
| 369 | bool success = canvas->readPixels(srcRect, &wkbmp); |
| 370 | SkIRect clippedRect = DEV_RECT; |
| 371 | if (clippedRect.intersect(srcRect)) { |
| 372 | REPORTER_ASSERT(reporter, success); |
| 373 | REPORTER_ASSERT(reporter, kN32_SkColorType == wkbmp.colorType()); |
| 374 | REPORTER_ASSERT(reporter, kPremul_SkAlphaType == wkbmp.alphaType()); |
| 375 | check_read(reporter, wkbmp, clippedRect.fLeft, |
| 376 | clippedRect.fTop, true, false); |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 377 | } else { |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 378 | REPORTER_ASSERT(reporter, !success); |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 379 | } |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | } |
| 383 | DEF_TEST(ReadPixels, reporter) { |
| 384 | const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 385 | auto surface(SkSurface::MakeRaster(info)); |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 386 | // SW readback fails a premul check when reading back to an unaligned rowbytes. |
| 387 | test_readpixels(reporter, surface, kLastAligned_BitmapInit); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 388 | } |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 389 | #if SK_SUPPORT_GPU |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 390 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, context) { |
| 391 | for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { |
| 392 | GrSurfaceDesc desc; |
| 393 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 394 | desc.fWidth = DEV_W; |
| 395 | desc.fHeight = DEV_H; |
| 396 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 397 | desc.fOrigin = origin; |
| 398 | SkAutoTUnref<GrTexture> surfaceTexture( |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 399 | context->textureProvider()->createTexture(desc, SkBudgeted::kNo)); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 400 | auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderTarget())); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 401 | desc.fFlags = kNone_GrSurfaceFlags; |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 402 | test_readpixels(reporter, surface, kLast_BitmapInit); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 403 | } |
| 404 | } |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 405 | #endif |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 406 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 407 | #if SK_SUPPORT_GPU |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 408 | static void test_readpixels_texture(skiatest::Reporter* reporter, GrTexture* texture) { |
| 409 | fill_src_texture(texture); |
| 410 | for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) { |
| 411 | const SkIRect& srcRect = gReadPixelsTestRects[rect]; |
bsalomon | 9d02b26 | 2016-02-01 12:49:30 -0800 | [diff] [blame] | 412 | for (BitmapInit bmi = kFirstBitmapInit; bmi <= kLast_BitmapInit; bmi = nextBMI(bmi)) { |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 413 | for (size_t c = 0; c < SK_ARRAY_COUNT(gReadPixelsConfigs); ++c) { |
| 414 | SkBitmap bmp; |
| 415 | init_bitmap(&bmp, srcRect, bmi, |
| 416 | gReadPixelsConfigs[c].fColorType, gReadPixelsConfigs[c].fAlphaType); |
| 417 | |
| 418 | // if the bitmap has pixels allocated before the readPixels, |
| 419 | // note that and fill them with pattern |
| 420 | bool startsWithPixels = !bmp.isNull(); |
| 421 | // Try doing the read directly from a non-renderable texture |
| 422 | if (startsWithPixels) { |
| 423 | fill_dst_bmp_with_init_data(&bmp); |
| 424 | GrPixelConfig dstConfig = |
| 425 | SkImageInfo2GrPixelConfig(gReadPixelsConfigs[c].fColorType, |
| 426 | gReadPixelsConfigs[c].fAlphaType, |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 427 | kLinear_SkColorProfileType, |
| 428 | *texture->getContext()->caps()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 429 | uint32_t flags = 0; |
| 430 | if (gReadPixelsConfigs[c].fAlphaType == kUnpremul_SkAlphaType) { |
| 431 | flags = GrContext::kUnpremul_PixelOpsFlag; |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 432 | } |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 433 | bmp.lockPixels(); |
| 434 | bool success = texture->readPixels(srcRect.fLeft, srcRect.fTop, bmp.width(), |
| 435 | bmp.height(), dstConfig, bmp.getPixels(), |
| 436 | bmp.rowBytes(), flags); |
| 437 | bmp.unlockPixels(); |
| 438 | check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop, |
| 439 | success, true); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | } |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 445 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, context) { |
| 446 | // On the GPU we will also try reading back from a non-renderable texture. |
| 447 | for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { |
| 448 | SkAutoTUnref<GrTexture> texture; |
| 449 | GrSurfaceDesc desc; |
| 450 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 451 | desc.fWidth = DEV_W; |
| 452 | desc.fHeight = DEV_H; |
| 453 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 454 | desc.fOrigin = origin; |
| 455 | desc.fFlags = kNone_GrSurfaceFlags; |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 456 | texture.reset(context->textureProvider()->createTexture(desc, SkBudgeted::kNo)); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 457 | test_readpixels_texture(reporter, texture); |
| 458 | } |
| 459 | } |
| 460 | #endif |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 461 | ///////////////////// |
| 462 | #if SK_SUPPORT_GPU |
| 463 | |
| 464 | // make_ringed_bitmap was lifted from gm/bleed.cpp, as that GM was what showed the following |
| 465 | // bug when a change was made to SkImage_Raster.cpp. It is possible that other test bitmaps |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 466 | // would also tickle https://bug.skia.org/4351 but this one is know to do it, so I've pasted the code |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 467 | // here so we have a dependable repro case. |
| 468 | |
| 469 | // Create a black&white checked texture with 2 1-pixel rings |
| 470 | // around the outside edge. The inner ring is red and the outer ring is blue. |
| 471 | static void make_ringed_bitmap(SkBitmap* result, int width, int height) { |
| 472 | SkASSERT(0 == width % 2 && 0 == height % 2); |
| 473 | |
| 474 | static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED); |
| 475 | static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE); |
| 476 | static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK); |
| 477 | static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE); |
| 478 | |
| 479 | result->allocN32Pixels(width, height, true); |
| 480 | |
| 481 | SkPMColor* scanline = result->getAddr32(0, 0); |
| 482 | for (int x = 0; x < width; ++x) { |
| 483 | scanline[x] = kBlue; |
| 484 | } |
| 485 | scanline = result->getAddr32(0, 1); |
| 486 | scanline[0] = kBlue; |
| 487 | for (int x = 1; x < width - 1; ++x) { |
| 488 | scanline[x] = kRed; |
| 489 | } |
| 490 | scanline[width-1] = kBlue; |
| 491 | |
| 492 | for (int y = 2; y < height/2; ++y) { |
| 493 | scanline = result->getAddr32(0, y); |
| 494 | scanline[0] = kBlue; |
| 495 | scanline[1] = kRed; |
| 496 | for (int x = 2; x < width/2; ++x) { |
| 497 | scanline[x] = kBlack; |
| 498 | } |
| 499 | for (int x = width/2; x < width-2; ++x) { |
| 500 | scanline[x] = kWhite; |
| 501 | } |
| 502 | scanline[width-2] = kRed; |
| 503 | scanline[width-1] = kBlue; |
| 504 | } |
| 505 | |
| 506 | for (int y = height/2; y < height-2; ++y) { |
| 507 | scanline = result->getAddr32(0, y); |
| 508 | scanline[0] = kBlue; |
| 509 | scanline[1] = kRed; |
| 510 | for (int x = 2; x < width/2; ++x) { |
| 511 | scanline[x] = kWhite; |
| 512 | } |
| 513 | for (int x = width/2; x < width-2; ++x) { |
| 514 | scanline[x] = kBlack; |
| 515 | } |
| 516 | scanline[width-2] = kRed; |
| 517 | scanline[width-1] = kBlue; |
| 518 | } |
| 519 | |
| 520 | scanline = result->getAddr32(0, height-2); |
| 521 | scanline[0] = kBlue; |
| 522 | for (int x = 1; x < width - 1; ++x) { |
| 523 | scanline[x] = kRed; |
| 524 | } |
| 525 | scanline[width-1] = kBlue; |
| 526 | |
| 527 | scanline = result->getAddr32(0, height-1); |
| 528 | for (int x = 0; x < width; ++x) { |
| 529 | scanline[x] = kBlue; |
| 530 | } |
| 531 | result->setImmutable(); |
| 532 | } |
| 533 | |
| 534 | static void compare_textures(skiatest::Reporter* reporter, GrTexture* txa, GrTexture* txb) { |
| 535 | REPORTER_ASSERT(reporter, txa->width() == 2); |
| 536 | REPORTER_ASSERT(reporter, txa->height() == 2); |
| 537 | REPORTER_ASSERT(reporter, txb->width() == 2); |
| 538 | REPORTER_ASSERT(reporter, txb->height() == 2); |
| 539 | REPORTER_ASSERT(reporter, txa->config() == txb->config()); |
| 540 | |
| 541 | SkPMColor pixelsA[4], pixelsB[4]; |
| 542 | REPORTER_ASSERT(reporter, txa->readPixels(0, 0, 2, 2, txa->config(), pixelsA)); |
| 543 | REPORTER_ASSERT(reporter, txb->readPixels(0, 0, 2, 2, txa->config(), pixelsB)); |
| 544 | REPORTER_ASSERT(reporter, 0 == memcmp(pixelsA, pixelsB, sizeof(pixelsA))); |
| 545 | } |
| 546 | |
| 547 | static SkData* draw_into_surface(SkSurface* surf, const SkBitmap& bm, SkFilterQuality quality) { |
| 548 | SkCanvas* canvas = surf->getCanvas(); |
| 549 | canvas->clear(SK_ColorBLUE); |
| 550 | |
| 551 | SkPaint paint; |
| 552 | paint.setFilterQuality(quality); |
| 553 | |
| 554 | canvas->translate(40, 100); |
| 555 | canvas->rotate(30); |
| 556 | canvas->scale(20, 30); |
| 557 | canvas->translate(-SkScalarHalf(bm.width()), -SkScalarHalf(bm.height())); |
| 558 | canvas->drawBitmap(bm, 0, 0, &paint); |
| 559 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 560 | return surf->makeImageSnapshot()->encode(); |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | #include "SkStream.h" |
| 564 | static void dump_to_file(const char name[], SkData* data) { |
| 565 | SkFILEWStream file(name); |
| 566 | file.write(data->data(), data->size()); |
| 567 | } |
| 568 | |
| 569 | /* |
| 570 | * Test two different ways to turn a subset of a bitmap into a texture |
| 571 | * - subset and then upload to a texture |
| 572 | * - upload to a texture and then subset |
| 573 | * |
| 574 | * These two techniques result in the same pixels (ala readPixels) |
| 575 | * but when we draw them (rotated+scaled) we don't always get the same results. |
| 576 | * |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 577 | * https://bug.skia.org/4351 |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 578 | */ |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 579 | DEF_GPUTEST_FOR_NATIVE_CONTEXT(ReadPixels_Subset_Gpu, reporter, context) { |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 580 | SkBitmap bitmap; |
| 581 | make_ringed_bitmap(&bitmap, 6, 6); |
| 582 | const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4); |
| 583 | |
| 584 | // make two textures... |
| 585 | SkBitmap bm_subset, tx_subset; |
| 586 | |
| 587 | // ... one from a texture-subset |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 588 | SkAutoTUnref<GrTexture> fullTx(GrRefCachedBitmapTexture(context, bitmap, |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 589 | GrTextureParams::ClampNoFilter())); |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 590 | SkBitmap tx_full; |
| 591 | GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_full); |
| 592 | tx_full.extractSubset(&tx_subset, subset); |
| 593 | |
| 594 | // ... one from a bitmap-subset |
| 595 | SkBitmap tmp_subset; |
| 596 | bitmap.extractSubset(&tmp_subset, subset); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 597 | SkAutoTUnref<GrTexture> subsetTx(GrRefCachedBitmapTexture(context, tmp_subset, |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 598 | GrTextureParams::ClampNoFilter())); |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 599 | GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), true, &bm_subset); |
| 600 | |
| 601 | // did we get the same subset? |
| 602 | compare_textures(reporter, bm_subset.getTexture(), tx_subset.getTexture()); |
| 603 | |
| 604 | // do they draw the same? |
| 605 | const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 606 | auto surfA(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); |
| 607 | auto surfB(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 608 | |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 609 | if (false) { |
reed | 2fd18f2 | 2015-09-16 13:18:41 -0700 | [diff] [blame] | 610 | // |
| 611 | // BUG: depending on the driver, if we calls this with various quality settings, it |
| 612 | // may fail. |
| 613 | // |
| 614 | SkFilterQuality quality = kLow_SkFilterQuality; |
| 615 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 616 | SkAutoTUnref<SkData> dataA(draw_into_surface(surfA.get(), bm_subset, quality)); |
| 617 | SkAutoTUnref<SkData> dataB(draw_into_surface(surfB.get(), tx_subset, quality)); |
reed | 2fd18f2 | 2015-09-16 13:18:41 -0700 | [diff] [blame] | 618 | |
| 619 | REPORTER_ASSERT(reporter, dataA->equals(dataB)); |
| 620 | if (false) { |
| 621 | dump_to_file("test_image_A.png", dataA); |
| 622 | dump_to_file("test_image_B.png", dataB); |
| 623 | } |
reed | 34482bb | 2015-09-16 12:50:27 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | #endif |