164struct GraphiteReadPixelTestRules {
167 bool fAllowUnpremulSrc =
true;
169 bool fUncontainedRectSucceeds =
true;
217 static constexpr SkScalar kPos3[] = {0.f, 0.15f, 0.5f, 0.85f, 1.f};
219 (
info.width() +
info.height())/10.f,
231 const GraphiteReadPixelTestRules& rules,
242 auto runTest = [&](
const T&
src,
246 const bool csConversion =
248 const auto readCT = readInfo.colorType();
249 const auto readAT = readInfo.alphaType();
250 const auto srcCT = srcPixels.info().colorType();
251 const auto srcAT = srcPixels.info().alphaType();
253 const auto surfBounds =
SkIRect::MakeWH(srcPixels.width(), srcPixels.height());
257 const size_t dstRB = readBpp * readInfo.width() + 10 * readBpp;
259 const size_t dstSize = readInfo.computeByteSize(dstRB);
260 std::unique_ptr<char[]> dstData(
new char[dstSize]);
261 SkPixmap dstPixels(readInfo, dstData.get(), dstRB);
264 static constexpr auto kInitialByte =
static_cast<char>(0x1B);
277 }
else if (!rules.fUncontainedRectSucceeds && !surfBounds.contains(
rect)) {
282 "Read failed. %sSrc CT: %s, Src AT: %s Read CT: %s, Read AT: %s, "
283 "Rect [%d, %d, %d, %d], CS conversion: %d\n",
292 auto guardCheck = [](
char x) {
return x == kInitialByte; };
300 const bool lumConversion =
308 float numer = (lumConversion || csConversion) ? 3.f : 2.f;
314 float tol = numer / (1 << rgbBits);
322 alphaTol = 2.f / (1 << alphaBits);
325 const float tols[4] = {tol, tol, tol, alphaTol};
326 auto error = std::function<ComparePixmapsErrorReporter>([&](
int x,
int y,
327 const float diffs[4]) {
330 "%sSrc CT: %s, Src AT: %s, Read CT: %s, Read AT: %s, Rect [%d, %d, %d, %d]"
331 ", CS conversion: %d\n"
332 "Error at %d, %d. Diff in floats: (%f, %f, %f, %f)",
337 diffs[0], diffs[1], diffs[2], diffs[3]);
350 srcPixels.rowBytes());
352 unpremulSrc.
readPixels(unpremulRef, srcReadRect.
x(), srcReadRect.
y());
354 srcPixels.readPixels(ref, srcReadRect.
x(), srcReadRect.
y());
361 const auto* v = dstData.get();
362 const auto*
end = dstData.get() + dstSize;
363 guardOk = std::all_of(v, v + dstWriteRect.
top() * dstPixels.
rowBytes(), guardCheck);
365 for (
int y = dstWriteRect.
top();
y < dstWriteRect.
bottom(); ++
y) {
366 guardOk |= std::all_of(v, v + dstWriteRect.
left() * readBpp, guardCheck);
367 auto pad = v + dstWriteRect.
right() * readBpp;
370 guardOk |= std::all_of(pad, rowEnd, guardCheck);
373 guardOk |= std::all_of(v,
end, guardCheck);
375 guardOk = std::all_of(dstData.get(), dstData.get() + dstSize, guardCheck);
379 "Result pixels modified result outside read rect [%d, %d, %d, %d]. "
380 "%sSrc CT: %s, Read CT: %s, CS conversion: %d",
388 static constexpr int kW = 16;
389 static constexpr int kH = 16;
402 std::array<bool, kLastEnum_SkColorType + 1> srcCTTestedThoroughly = {},
403 readCTTestedThoroughly = {};
428 srcPixels.
alloc(srcInfo);
438 refPixels.readPixels(readPixmap, 0, 0);
441 std::unique_ptr<skgpu::graphite::Recorder> recorder = context->
makeRecorder();
443 auto src = srcFactory(recorder.get(), srcPixels);
486 srcCTTestedThoroughly[sct] && readCTTestedThoroughly[rct]
489 for (
const auto&
rect : rects) {
491 readCT, readAT, readCS);
493 Result r = runTest(
src, srcPixels, readInfo,
offset);
495 srcCTTestedThoroughly[sct] =
true;
496 readCTTestedThoroughly[rct] =
true;
508 bool fCalled =
false;
509 std::unique_ptr<const SkImage::AsyncReadResult>
fResult;
517 auto context =
static_cast<AsyncContext*
>(c);
518 context->fResult = std::move(
result);
519 context->fCalled =
true;
532 auto reader = std::function<GraphiteReadSrcFn<Image>>([context, testContext](
536 AsyncContext asyncContext;
540 TextureInfo texInfo = context->priv().caps()->getDefaultSampledTextureInfo(
545 if (!context->priv().caps()->isRenderable(texInfo)) {
546 return Result::kExcusedFailure;
549 context->asyncRescaleAndReadPixels(
image.
get(),
556 if (!asyncContext.fCalled) {
559 while (!asyncContext.fCalled) {
561 context->checkAsyncWorkCompletion();
563 if (!asyncContext.fResult) {
566 SkRectMemcpy(pixels.writable_addr(), pixels.rowBytes(), asyncContext.fResult->data(0),
567 asyncContext.fResult->rowBytes(0), pixels.info().minRowBytes(),
572 GraphiteReadPixelTestRules rules;
573 rules.fAllowUnpremulSrc =
true;
574 rules.fUncontainedRectSucceeds =
false;
577 auto factory = std::function<GraphiteSrcFactory<Image>>([&](
580 Image image = sk_gpu_test::MakeBackendTextureImage(recorder,
587 std::unique_ptr<skgpu::graphite::Recording> recording = recorder->snap();
590 context->insertRecording(recordingInfo);
611 auto reader = std::function<GraphiteReadSrcFn<Surface>>([context, testContext](
615 AsyncContext asyncContext;
618 context->asyncRescaleAndReadPixels(
surface.get(),
625 if (!asyncContext.fCalled) {
628 while (!asyncContext.fCalled) {
630 context->checkAsyncWorkCompletion();
632 if (!asyncContext.fResult) {
635 SkRectMemcpy(pixels.writable_addr(), pixels.rowBytes(), asyncContext.fResult->data(0),
636 asyncContext.fResult->rowBytes(0), pixels.info().minRowBytes(),
641 GraphiteReadPixelTestRules rules;
642 rules.fAllowUnpremulSrc =
true;
643 rules.fUncontainedRectSucceeds =
false;
645 auto factory = std::function<GraphiteSrcFactory<Surface>>(
654 std::unique_ptr<skgpu::graphite::Recording> recording = recorder->snap();
657 context->insertRecording(recordingInfo);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
std::vector< SkIRect > make_short_rect_array(int w, int h)
std::vector< SkIRect > make_long_rect_array(int w, int h)
static SkAutoPixmapStorage make_ref_data(const SkImageInfo &info, bool forceOpaque)
static constexpr int alpha_channel_bits(SkColorType ct)
static void async_callback(void *c, std::unique_ptr< const SkImage::AsyncReadResult > result)
static constexpr int min_rgb_channel_bits(SkColorType ct)
DEF_CONDITIONAL_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS(ImageAsyncReadPixelsGraphite, reporter, context, testContext, true, CtsEnforcement::kNextRelease)
static void graphite_read_pixels_test_driver(skiatest::Reporter *reporter, skgpu::graphite::Context *context, const GraphiteReadPixelTestRules &rules, const std::function< GraphiteSrcFactory< T > > &srcFactory, const std::function< GraphiteReadSrcFn< T > > &read, SkString label)
@ kUnknown_SkAlphaType
uninitialized
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kLastEnum_SkAlphaType
last valid value
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
@ kRGBA_10x6_SkColorType
pixel with 10 used bits (most significant) followed by 6 unused
@ kBGR_101010x_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
@ kLastEnum_SkColorType
last valid value
@ kSRGBA_8888_SkColorType
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
@ kA16_float_SkColorType
pixel with a half float for alpha
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
@ kUnknown_SkColorType
uninitialized
@ kR16G16_float_SkColorType
pixel with a half float for red and green
constexpr SkColor SK_ColorBLUE
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorGREEN
@ kGray_SkColorChannelFlag
constexpr SkColor SK_ColorWHITE
static bool read(SkStream *stream, void *buffer, size_t amount)
static uint32_t SkColorTypeChannelFlags(SkColorType ct)
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
SK_API bool SkColorTypeIsAlwaysOpaque(SkColorType ct)
static void SkRectMemcpy(void *dst, size_t dstRB, const void *src, size_t srcRB, size_t trimRowBytes, int rowCount)
LoopControlFlowInfo fResult
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
bool ComparePixels(const GrCPixmap &a, const GrCPixmap &b, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
#define REPORTER_ASSERT(r, cond,...)
void alloc(const SkImageInfo &)
static bool Equals(const SkColorSpace *, const SkColorSpace *)
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkColorSpace > MakeSRGBLinear()
static sk_sp< SkShader > MakeRadial(const SkPoint ¢er, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
SkColorType colorType() const
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes) const
const SkImageInfo & info() const
size_t computeByteSize() const
void * writable_addr() const
const void * addr() const
bool extractSubset(SkPixmap *subset, const SkIRect &area) const
void append(const char text[])
const char * c_str() const
std::unique_ptr< Recorder > makeRecorder(const RecorderOptions &={})
const uint8_t uint32_t uint32_t GError ** error
Dart_NativeFunction function
static float sat(float r, float g, float b)
static float min(float r, float g, float b)
sk_sp< const SkImage > image
sk_sp< SkBlender > blender SkRect rect
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
constexpr int32_t x() const
constexpr int32_t y() const
bool intersect(const SkIRect &r)
static bool Intersects(const SkIRect &a, const SkIRect &b)
constexpr int32_t top() const
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
constexpr SkISize size() const
constexpr int32_t bottom() const
constexpr int32_t right() const
static constexpr SkIRect MakeSize(const SkISize &size)
constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
constexpr int32_t left() const
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
SkImageInfo makeDimensions(SkISize newSize) const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)