Flutter Engine
The Flutter Engine
Enumerations | Functions | Variables
ReadPixelsTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkClipOp.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkAlign.h"
#include "include/private/base/SkCPUTypes.h"
#include "include/private/base/SkSafe32.h"
#include "src/base/SkHalf.h"
#include "src/base/SkMathPriv.h"
#include "src/core/SkImageInfoPriv.h"
#include "tests/Test.h"
#include <cstdint>
#include <cstring>
#include <initializer_list>
#include <memory>
#include <string>

Go to the source code of this file.

Enumerations

enum class  TightRowBytes : bool { kNo , kYes }
 

Functions

static SkPMColor get_src_color (int x, int y)
 
static SkPMColor get_dst_bmp_init_color (int x, int y, int w)
 
static SkPMColor convert_to_pmcolor (SkColorType ct, SkAlphaType at, const uint32_t *addr, bool *doUnpremul)
 
static sk_sp< SkImagemake_src_image ()
 
static void fill_src_canvas (SkCanvas *canvas)
 
static void fill_dst_bmp_with_init_data (SkBitmap *bitmap)
 
static bool check_read_pixel (SkPMColor a, SkPMColor b, bool didPremulConversion)
 
static bool check_read (skiatest::Reporter *reporter, const SkBitmap &bitmap, int x, int y, bool checkSurfacePixels, bool checkBitmapPixels, const SkImageInfo &surfaceInfo)
 
static void init_bitmap (SkBitmap *bitmap, const SkIRect &rect, TightRowBytes tightRB, SkColorType ct, SkAlphaType at)
 
bool read_should_succeed (const SkIRect &srcRect, const SkImageInfo &dstInfo, const SkImageInfo &srcInfo)
 
static void test_readpixels (skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, const SkImageInfo &surfaceInfo)
 
 DEF_TEST (ReadPixels, reporter)
 
static const void * five_reference_pixels (SkColorType colorType)
 
static void test_conversion (skiatest::Reporter *r, const SkImageInfo &dstInfo, const SkImageInfo &srcInfo)
 
 DEF_TEST (ReadPixels_ValidConversion, reporter)
 
 DEF_TEST (ReadPixels_InvalidRowBytes, reporter)
 

Variables

static const int DEV_W = 100
 
static const int DEV_H = 100
 
static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H)
 
static const SkRect DEV_RECT_S
 
struct {
   SkColorType   fColorType
 
   SkAlphaType   fAlphaType
 
gReadPixelsConfigs []
 
const SkIRect gReadPixelsTestRects []
 
static const uint32_t kNumPixels = 5
 
static const uint32_t rgba [kNumPixels]
 
static const uint32_t bgra [kNumPixels]
 
static const uint16_t rgb565 [kNumPixels]
 
static const uint16_t rgba4444 [kNumPixels] = { 0xF00F, 0x0F0F, 0x00FF, 0xFFFF, 0x000F }
 
static const uint64_t kRed = (uint64_t) SK_Half1 << 0
 
static const uint64_t kGreen = (uint64_t) SK_Half1 << 16
 
static const uint64_t kBlue = (uint64_t) SK_Half1 << 32
 
static const uint64_t kAlpha = (uint64_t) SK_Half1 << 48
 
static const uint64_t f16 [kNumPixels]
 
static const uint8_t alpha8 [kNumPixels] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
 
static const uint8_t gray8 [kNumPixels] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
 

Enumeration Type Documentation

◆ TightRowBytes

enum class TightRowBytes : bool
strong
Enumerator
kNo 
kYes 

Definition at line 274 of file ReadPixelsTest.cpp.

274: bool { kNo, kYes };
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.

Function Documentation

◆ check_read()

static bool check_read ( skiatest::Reporter reporter,
const SkBitmap bitmap,
int  x,
int  y,
bool  checkSurfacePixels,
bool  checkBitmapPixels,
const SkImageInfo surfaceInfo 
)
static

Definition at line 188 of file ReadPixelsTest.cpp.

190 {
191 SkAlphaType bmpAT = bitmap.alphaType();
192 SkColorType bmpCT = bitmap.colorType();
193 SkASSERT(!bitmap.isNull());
194 SkASSERT(checkSurfacePixels || checkBitmapPixels);
195
196 int bw = bitmap.width();
197 int bh = bitmap.height();
198
199 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh);
200 SkIRect clippedSrcRect = DEV_RECT;
201 if (!clippedSrcRect.intersect(srcRect)) {
202 clippedSrcRect.setEmpty();
203 }
204 if (kAlpha_8_SkColorType == bmpCT) {
205 for (int by = 0; by < bh; ++by) {
206 for (int bx = 0; bx < bw; ++bx) {
207 int devx = bx + srcRect.fLeft;
208 int devy = by + srcRect.fTop;
209 const uint8_t* alpha = bitmap.getAddr8(bx, by);
210
211 if (clippedSrcRect.contains(devx, devy)) {
212 if (checkSurfacePixels) {
213 uint8_t surfaceAlpha = (surfaceInfo.alphaType() == kOpaque_SkAlphaType)
214 ? 0xFF
215 : SkGetPackedA32(get_src_color(devx, devy));
216 if (surfaceAlpha != *alpha) {
218 "Expected readback alpha (%d, %d) value 0x%02x, got 0x%02x. ",
219 bx, by, surfaceAlpha, *alpha);
220 return false;
221 }
222 }
223 } else if (checkBitmapPixels) {
224 uint32_t origDstAlpha = SkGetPackedA32(get_dst_bmp_init_color(bx, by, bw));
225 if (origDstAlpha != *alpha) {
226 ERRORF(reporter, "Expected clipped out area of readback to be unchanged. "
227 "Expected 0x%02x, got 0x%02x", origDstAlpha, *alpha);
228 return false;
229 }
230 }
231 }
232 }
233 return true;
234 }
235 for (int by = 0; by < bh; ++by) {
236 for (int bx = 0; bx < bw; ++bx) {
237 int devx = bx + srcRect.fLeft;
238 int devy = by + srcRect.fTop;
239
240 const uint32_t* pixel = bitmap.getAddr32(bx, by);
241
242 if (clippedSrcRect.contains(devx, devy)) {
243 if (checkSurfacePixels) {
244 SkPMColor surfacePMColor = get_src_color(devx, devy);
245 if (SkColorTypeIsAlphaOnly(surfaceInfo.colorType())) {
246 surfacePMColor &= 0xFF000000;
247 }
248 if (kOpaque_SkAlphaType == surfaceInfo.alphaType() || kOpaque_SkAlphaType == bmpAT) {
249 surfacePMColor |= 0xFF000000;
250 }
251 bool didPremul;
252 SkPMColor pmPixel = convert_to_pmcolor(bmpCT, bmpAT, pixel, &didPremul);
253 if (!check_read_pixel(pmPixel, surfacePMColor, didPremul)) {
255 "Expected readback pixel (%d, %d) value 0x%08x, got 0x%08x. "
256 "Readback was unpremul: %d",
257 bx, by, surfacePMColor, pmPixel, didPremul);
258 return false;
259 }
260 }
261 } else if (checkBitmapPixels) {
262 uint32_t origDstPixel = get_dst_bmp_init_color(bx, by, bw);
263 if (origDstPixel != *pixel) {
264 ERRORF(reporter, "Expected clipped out area of readback to be unchanged. "
265 "Expected 0x%08x, got 0x%08x", origDstPixel, *pixel);
266 return false;
267 }
268 }
269 }
270 }
271 return true;
272}
reporter
Definition: FontMgrTest.cpp:39
static bool check_read_pixel(SkPMColor a, SkPMColor b, bool didPremulConversion)
static SkPMColor get_src_color(int x, int y)
static SkPMColor convert_to_pmcolor(SkColorType ct, SkAlphaType at, const uint32_t *addr, bool *doUnpremul)
static SkPMColor get_dst_bmp_init_color(int x, int y, int w)
static const SkIRect DEV_RECT
SkAlphaType
Definition: SkAlphaType.h:26
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkGetPackedA32(packed)
Definition: SkColorPriv.h:92
SkColorType
Definition: SkColorType.h:19
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
uint32_t SkPMColor
Definition: SkColor.h:205
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
#define ERRORF(r,...)
Definition: Test.h:293
double y
double x
Definition: bitmap.py:1
Definition: SkRect.h:32
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
void setEmpty()
Definition: SkRect.h:242
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463
SkAlphaType alphaType() const
Definition: SkImageInfo.h:375
SkColorType colorType() const
Definition: SkImageInfo.h:373

◆ check_read_pixel()

static bool check_read_pixel ( SkPMColor  a,
SkPMColor  b,
bool  didPremulConversion 
)
static

Definition at line 165 of file ReadPixelsTest.cpp.

165 {
166 if (!didPremulConversion) {
167 return a == b;
168 }
169 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a));
170 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a));
171 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a));
172 int32_t aB = SkGetPackedB32(a);
173
174 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b));
175 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b));
176 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b));
177 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b));
178
179 return aA == bA &&
180 SkAbs32(aR - bR) <= 1 &&
181 SkAbs32(aG - bG) <= 1 &&
182 SkAbs32(aB - bB) <= 1;
183}
#define SkGetPackedB32(packed)
Definition: SkColorPriv.h:95
#define SkGetPackedR32(packed)
Definition: SkColorPriv.h:93
#define SkGetPackedG32(packed)
Definition: SkColorPriv.h:94
static int32_t SkAbs32(int32_t value)
Definition: SkSafe32.h:41
static bool b
struct MyStruct a[10]

◆ convert_to_pmcolor()

static SkPMColor convert_to_pmcolor ( SkColorType  ct,
SkAlphaType  at,
const uint32_t *  addr,
bool *  doUnpremul 
)
static

Definition at line 87 of file ReadPixelsTest.cpp.

88 {
89 *doUnpremul = (kUnpremul_SkAlphaType == at);
90
91 const uint8_t* c = reinterpret_cast<const uint8_t*>(addr);
92 U8CPU a,r,g,b;
93 switch (ct) {
95 b = static_cast<U8CPU>(c[0]);
96 g = static_cast<U8CPU>(c[1]);
97 r = static_cast<U8CPU>(c[2]);
98 a = static_cast<U8CPU>(c[3]);
99 break;
100 case kRGB_888x_SkColorType: // fallthrough
102 r = static_cast<U8CPU>(c[0]);
103 g = static_cast<U8CPU>(c[1]);
104 b = static_cast<U8CPU>(c[2]);
105 // We set this even for kRGB_888x because our caller will validate that it is 0xff.
106 a = static_cast<U8CPU>(c[3]);
107 break;
108 default:
109 SkDEBUGFAIL("Unexpected colortype");
110 return 0;
111 }
112
113 if (*doUnpremul) {
114 r = SkMulDiv255Ceiling(r, a);
115 g = SkMulDiv255Ceiling(g, a);
117 }
118 return SkPackARGB32(a, r, g, b);
119}
kUnpremul_SkAlphaType
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
unsigned U8CPU
Definition: SkCPUTypes.h:18
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:106
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition: SkColorType.h:25
static U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b)
Definition: SkMathPriv.h:102

◆ DEF_TEST() [1/3]

DEF_TEST ( ReadPixels  ,
reporter   
)

Definition at line 395 of file ReadPixelsTest.cpp.

395 {
399}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static const int DEV_H
static void test_readpixels(skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, const SkImageInfo &surfaceInfo)
static const int DEV_W
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_TEST() [2/3]

DEF_TEST ( ReadPixels_InvalidRowBytes  ,
reporter   
)

Definition at line 539 of file ReadPixelsTest.cpp.

539 {
541 auto surf = SkSurfaces::Raster(srcII);
542 for (int ct = 0; ct < kLastEnum_SkColorType + 1; ++ct) {
543 auto colorType = static_cast<SkColorType>(ct);
545 if (bpp <= 1) {
546 continue;
547 }
548 auto dstII = srcII.makeColorType(colorType);
549 size_t badRowBytes = (surf->width() + 1)*bpp - 1;
550 auto storage = std::make_unique<char[]>(badRowBytes*surf->height());
551 REPORTER_ASSERT(reporter, !surf->readPixels(dstII, storage.get(), badRowBytes, 0, 0));
552 }
553}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kLastEnum_SkColorType
last valid value
Definition: SkColorType.h:56
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
Definition: SkImageInfo.cpp:16
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_TEST() [3/3]

DEF_TEST ( ReadPixels_ValidConversion  ,
reporter   
)

Definition at line 498 of file ReadPixelsTest.cpp.

498 {
499 const SkColorType kColorTypes[] = {
508 };
509
510 const SkAlphaType kAlphaTypes[] = {
515 };
516
517 const sk_sp<SkColorSpace> kColorSpaces[] = {
518 nullptr,
520 };
521
522 for (SkColorType dstCT : kColorTypes) {
523 for (SkAlphaType dstAT : kAlphaTypes) {
524 for (const sk_sp<SkColorSpace>& dstCS : kColorSpaces) {
525 for (SkColorType srcCT : kColorTypes) {
526 for (SkAlphaType srcAT : kAlphaTypes) {
527 for (const sk_sp<SkColorSpace>& srcCS : kColorSpaces) {
529 SkImageInfo::Make(kNumPixels, 1, dstCT, dstAT, dstCS),
530 SkImageInfo::Make(kNumPixels, 1, srcCT, srcAT, srcCS));
531 }
532 }
533 }
534 }
535 }
536 }
537}
static const uint32_t kNumPixels
static void test_conversion(skiatest::Reporter *r, const SkImageInfo &dstInfo, const SkImageInfo &srcInfo)
@ kUnknown_SkAlphaType
uninitialized
Definition: SkAlphaType.h:27
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition: SkColorType.h:23
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
static sk_sp< SkColorSpace > MakeSRGB()

◆ fill_dst_bmp_with_init_data()

static void fill_dst_bmp_with_init_data ( SkBitmap bitmap)
static

Definition at line 147 of file ReadPixelsTest.cpp.

147 {
148 int w = bitmap->width();
149 int h = bitmap->height();
150 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels());
151 for (int y = 0; y < h; ++y) {
152 for (int x = 0; x < w; ++x) {
153 SkPMColor initColor = get_dst_bmp_init_color(x, y, w);
154 if (kAlpha_8_SkColorType == bitmap->colorType()) {
155 uint8_t* alpha = reinterpret_cast<uint8_t*>(pixels + y * bitmap->rowBytes() + x);
156 *alpha = SkGetPackedA32(initColor);
157 } else {
158 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap->rowBytes() + x * bitmap->bytesPerPixel());
159 *pixel = initColor;
160 }
161 }
162 }
163}
SkScalar w
SkScalar h

◆ fill_src_canvas()

static void fill_src_canvas ( SkCanvas canvas)
static

Definition at line 137 of file ReadPixelsTest.cpp.

137 {
138 canvas->save();
139 canvas->setMatrix(SkMatrix::I());
142 paint.setBlendMode(SkBlendMode::kSrc);
143 canvas->drawImage(make_src_image(), 0, 0, SkSamplingOptions(), &paint);
144 canvas->restore();
145}
static const SkRect DEV_RECT_S
static sk_sp< SkImage > make_src_image()
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
int save()
Definition: SkCanvas.cpp:447
void setMatrix(const SkM44 &matrix)
Definition: SkCanvas.cpp:1349
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
const Paint & paint
Definition: color_source.cc:38
SkSamplingOptions(SkFilterMode::kLinear))

◆ five_reference_pixels()

static const void * five_reference_pixels ( SkColorType  colorType)
static

Definition at line 431 of file ReadPixelsTest.cpp.

431 {
432 switch (colorType) {
434 return nullptr;
436 return alpha8;
438 return rgb565;
440 return rgba4444;
442 return rgba;
444 return bgra;
446 return gray8;
448 return f16;
449 default:
450 return nullptr;
451 }
452
453 SkASSERT(false);
454 return nullptr;
455}
static const uint16_t rgba4444[kNumPixels]
static const uint32_t bgra[kNumPixels]
static const uint8_t alpha8[kNumPixels]
static const uint16_t rgb565[kNumPixels]
static const uint32_t rgba[kNumPixels]
static const uint64_t f16[kNumPixels]
static const uint8_t gray8[kNumPixels]

◆ get_dst_bmp_init_color()

static SkPMColor get_dst_bmp_init_color ( int  x,
int  y,
int  w 
)
static

Definition at line 77 of file ReadPixelsTest.cpp.

77 {
78 int n = y * w + x;
79
80 U8CPU b = n & 0xff;
81 U8CPU g = (n >> 8) & 0xff;
82 U8CPU r = (n >> 16) & 0xff;
83 return SkPackARGB32(0xff, r, g , b);
84}

◆ get_src_color()

static SkPMColor get_src_color ( int  x,
int  y 
)
static

Definition at line 48 of file ReadPixelsTest.cpp.

48 {
49 SkASSERT(x >= 0 && x < DEV_W);
50 SkASSERT(y >= 0 && y < DEV_H);
51
52 U8CPU r = x;
53 U8CPU g = y;
54 U8CPU b = 0xc;
55
56 U8CPU a = 0xff;
57 switch ((x+y) % 5) {
58 case 0:
59 a = 0xff;
60 break;
61 case 1:
62 a = 0x80;
63 break;
64 case 2:
65 a = 0xCC;
66 break;
67 case 4:
68 a = 0x01;
69 break;
70 case 3:
71 a = 0x00;
72 break;
73 }
74 return SkPremultiplyARGBInline(a, r, g, b);
75}
static SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:126

◆ init_bitmap()

static void init_bitmap ( SkBitmap bitmap,
const SkIRect rect,
TightRowBytes  tightRB,
SkColorType  ct,
SkAlphaType  at 
)
static

Definition at line 276 of file ReadPixelsTest.cpp.

277 {
278 SkImageInfo info = SkImageInfo::Make(rect.size(), ct, at);
279 size_t rowBytes = 0;
280 if (tightRB == TightRowBytes::kNo) {
281 rowBytes = SkAlign4((info.width() + 16) * info.bytesPerPixel());
282 }
283 bitmap->allocPixels(info, rowBytes);
284}
static constexpr T SkAlign4(T x)
Definition: SkAlign.h:16
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ make_src_image()

static sk_sp< SkImage > make_src_image ( )
static

Definition at line 121 of file ReadPixelsTest.cpp.

121 {
122 static SkBitmap bmp;
123 if (bmp.isNull()) {
125 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
126 for (int y = 0; y < DEV_H; ++y) {
127 for (int x = 0; x < DEV_W; ++x) {
128 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp.rowBytes() + x * bmp.bytesPerPixel());
129 *pixel = get_src_color(x, y);
130 }
131 }
132 bmp.setImmutable();
133 }
134 return bmp.asImage();
135}
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void setImmutable()
Definition: SkBitmap.cpp:400
size_t rowBytes() const
Definition: SkBitmap.h:238
bool isNull() const
Definition: SkBitmap.h:219
void * getPixels() const
Definition: SkBitmap.h:283
int bytesPerPixel() const
Definition: SkBitmap.h:187
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232

◆ read_should_succeed()

bool read_should_succeed ( const SkIRect srcRect,
const SkImageInfo dstInfo,
const SkImageInfo srcInfo 
)

Definition at line 344 of file ReadPixelsTest.cpp.

345 {
346 return SkIRect::Intersects(srcRect, DEV_RECT) && SkImageInfoValidConversion(dstInfo, srcInfo);
347}
static bool SkImageInfoValidConversion(const SkImageInfo &dst, const SkImageInfo &src)
static bool Intersects(const SkIRect &a, const SkIRect &b)
Definition: SkRect.h:535

◆ test_conversion()

static void test_conversion ( skiatest::Reporter r,
const SkImageInfo dstInfo,
const SkImageInfo srcInfo 
)
static

Definition at line 457 of file ReadPixelsTest.cpp.

458 {
459 if (!SkImageInfoIsValid(srcInfo)) {
460 return;
461 }
462
463 const void* srcPixels = five_reference_pixels(srcInfo.colorType());
464 SkPixmap srcPixmap(srcInfo, srcPixels, srcInfo.minRowBytes());
465 sk_sp<SkImage> src = SkImages::RasterFromPixmap(srcPixmap, nullptr, nullptr);
467
468 // Enough space for 5 pixels when color type is F16, more than enough space in other cases.
469 uint64_t dstPixels[kNumPixels];
470 SkPixmap dstPixmap(dstInfo, dstPixels, dstInfo.minRowBytes());
471 bool success = src->readPixels(nullptr, dstPixmap, 0, 0);
472 REPORTER_ASSERT(r, success == SkImageInfoValidConversion(dstInfo, srcInfo));
473
474 if (success) {
475 if (kGray_8_SkColorType == srcInfo.colorType() &&
476 kGray_8_SkColorType != dstInfo.colorType()) {
477 // TODO: test (r,g,b) == (gray,gray,gray)?
478 return;
479 }
480
481 if (kGray_8_SkColorType == dstInfo.colorType() &&
482 kGray_8_SkColorType != srcInfo.colorType()) {
483 // TODO: test gray = luminance?
484 return;
485 }
486
487 if (kAlpha_8_SkColorType == srcInfo.colorType() &&
488 kAlpha_8_SkColorType != dstInfo.colorType()) {
489 // TODO: test output = black with this alpha?
490 return;
491 }
492
493 REPORTER_ASSERT(r, 0 == memcmp(dstPixels, five_reference_pixels(dstInfo.colorType()),
495 }
496}
static const void * five_reference_pixels(SkColorType colorType)
static bool SkImageInfoIsValid(const SkImageInfo &info)
SK_API sk_sp< SkImage > RasterFromPixmap(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
size_t minRowBytes() const
Definition: SkImageInfo.h:517

◆ test_readpixels()

static void test_readpixels ( skiatest::Reporter reporter,
const sk_sp< SkSurface > &  surface,
const SkImageInfo surfaceInfo 
)
static

Definition at line 349 of file ReadPixelsTest.cpp.

350 {
351 SkCanvas* canvas = surface->getCanvas();
352 fill_src_canvas(canvas);
353 for (size_t rect = 0; rect < std::size(gReadPixelsTestRects); ++rect) {
354 const SkIRect& srcRect = gReadPixelsTestRects[rect];
355 for (auto tightRB : {TightRowBytes::kYes, TightRowBytes::kNo}) {
356 for (size_t c = 0; c < std::size(gReadPixelsConfigs); ++c) {
357 SkBitmap bmp;
358 init_bitmap(&bmp, srcRect, tightRB, gReadPixelsConfigs[c].fColorType,
360
361 // if the bitmap has pixels allocated before the readPixels,
362 // note that and fill them with pattern
363 bool startsWithPixels = !bmp.isNull();
364 if (startsWithPixels) {
366 }
367 uint32_t idBefore = surface->generationID();
368 bool success = surface->readPixels(bmp, srcRect.fLeft, srcRect.fTop);
369 uint32_t idAfter = surface->generationID();
370
371 // we expect to succeed when the read isn't fully clipped out and the infos are
372 // compatible.
373 bool expectSuccess = read_should_succeed(srcRect, bmp.info(), surfaceInfo);
374 // determine whether we expected the read to succeed.
375 REPORTER_ASSERT(reporter, expectSuccess == success,
376 "Read succeed=%d unexpectedly, src ct/at: %d/%d, dst ct/at: %d/%d",
377 success, surfaceInfo.colorType(), surfaceInfo.alphaType(),
378 bmp.info().colorType(), bmp.info().alphaType());
379 // read pixels should never change the gen id
380 REPORTER_ASSERT(reporter, idBefore == idAfter);
381
382 if (success || startsWithPixels) {
383 check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop, success,
384 startsWithPixels, surfaceInfo);
385 } else {
386 // if we had no pixels beforehand and the readPixels
387 // failed then our bitmap should still not have pixels
389 }
390 }
391 }
392 }
393}
static void fill_src_canvas(SkCanvas *canvas)
static void fill_dst_bmp_with_init_data(SkBitmap *bitmap)
SkColorType fColorType
static const struct @437 gReadPixelsConfigs[]
bool read_should_succeed(const SkIRect &srcRect, const SkImageInfo &dstInfo, const SkImageInfo &srcInfo)
SkAlphaType fAlphaType
const SkIRect gReadPixelsTestRects[]
static void init_bitmap(SkBitmap *bitmap, const SkIRect &rect, TightRowBytes tightRB, SkColorType ct, SkAlphaType at)
static bool check_read(skiatest::Reporter *reporter, const SkBitmap &bitmap, int x, int y, bool checkSurfacePixels, bool checkBitmapPixels, const SkImageInfo &surfaceInfo)
const SkImageInfo & info() const
Definition: SkBitmap.h:139
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

Variable Documentation

◆ alpha8

const uint8_t alpha8[kNumPixels] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
static

Definition at line 428 of file ReadPixelsTest.cpp.

◆ bgra

const uint32_t bgra[kNumPixels]
static
Initial value:
= {
0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFFFF, 0xFF000000
}

Definition at line 411 of file ReadPixelsTest.cpp.

◆ DEV_H

const int DEV_H = 100
static

Definition at line 43 of file ReadPixelsTest.cpp.

◆ DEV_RECT

const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H)
static

Definition at line 44 of file ReadPixelsTest.cpp.

◆ DEV_RECT_S

const SkRect DEV_RECT_S
static
Initial value:
#define SK_Scalar1
Definition: SkScalar.h:18
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

Definition at line 45 of file ReadPixelsTest.cpp.

◆ DEV_W

const int DEV_W = 100
static

Definition at line 43 of file ReadPixelsTest.cpp.

◆ f16

const uint64_t f16[kNumPixels]
static
Initial value:
= {
}
static const uint64_t kGreen
static const uint64_t kAlpha
static const uint64_t kBlue
static const uint64_t kRed

Definition at line 424 of file ReadPixelsTest.cpp.

◆ fAlphaType

SkAlphaType fAlphaType

Definition at line 288 of file ReadPixelsTest.cpp.

◆ fColorType

SkColorType fColorType

Definition at line 287 of file ReadPixelsTest.cpp.

◆ gray8

const uint8_t gray8[kNumPixels] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
static

Definition at line 429 of file ReadPixelsTest.cpp.

◆ 

const struct { ... } gReadPixelsConfigs[]

◆ gReadPixelsTestRects

const SkIRect gReadPixelsTestRects[]

Definition at line 297 of file ReadPixelsTest.cpp.

◆ kAlpha

const uint64_t kAlpha = (uint64_t) SK_Half1 << 48
static

Definition at line 423 of file ReadPixelsTest.cpp.

◆ kBlue

const uint64_t kBlue = (uint64_t) SK_Half1 << 32
static

Definition at line 422 of file ReadPixelsTest.cpp.

◆ kGreen

const uint64_t kGreen = (uint64_t) SK_Half1 << 16
static

Definition at line 421 of file ReadPixelsTest.cpp.

◆ kNumPixels

const uint32_t kNumPixels = 5
static

Definition at line 403 of file ReadPixelsTest.cpp.

◆ kRed

const uint64_t kRed = (uint64_t) SK_Half1 << 0
static

Definition at line 420 of file ReadPixelsTest.cpp.

◆ rgb565

const uint16_t rgb565[kNumPixels]
static
Initial value:
= {
}
#define SK_R16_MASK_IN_PLACE
Definition: SkColorData.h:149
#define SK_G16_MASK_IN_PLACE
Definition: SkColorData.h:150
#define SK_B16_MASK_IN_PLACE
Definition: SkColorData.h:151

Definition at line 414 of file ReadPixelsTest.cpp.

◆ rgba

const uint32_t rgba[kNumPixels]
static
Initial value:
= {
0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFFFFFF, 0xFF000000
}

Definition at line 408 of file ReadPixelsTest.cpp.

◆ rgba4444

const uint16_t rgba4444[kNumPixels] = { 0xF00F, 0x0F0F, 0x00FF, 0xFFFF, 0x000F }
static

Definition at line 418 of file ReadPixelsTest.cpp.