27#if defined(SK_GRAPHITE)
38enum class ReadSource {
50template <ReadSource>
struct SourceS;
58template <ReadSource RS>
64std::variant<sk_sp<SkImage>,
skiagm::DrawResult> convert_image_to_source<ReadSource::kImage>(
68#if defined(SK_GRAPHITE)
69 if (
auto recorder = canvas->
recorder()) {
74 *errorMsg =
"Could not create Graphite image";
80 *errorMsg =
"Not supported in DDL mode";
89 if (dContext && dContext->abandoned()) {
92 *errorMsg =
"Could not create Ganesh image";
99std::variant<sk_sp<SkSurface>,
skiagm::DrawResult> convert_image_to_source<ReadSource::kSurface>(
111 *errorMsg =
"Could not create surface for image.";
133 template <ReadSource ReadSource>
141 auto* asyncContext =
new AsyncContext();
143#if defined(SK_GRAPHITE)
145 if (!graphiteContext) {
149 std::unique_ptr<skgpu::graphite::Recording> recording = recorder->
snap();
166 graphiteContext->
submit();
167 while (!asyncContext->fCalled) {
175 src->asyncRescaleAndReadPixels(ii,
184 while (!asyncContext->fCalled) {
190 if (!asyncContext->fResult) {
193 SkPixmap pixmap(ii, asyncContext->fResult->data(0), asyncContext->fResult->rowBytes(0));
194 auto releasePixels = [](
const void*,
void* c) {
delete static_cast<AsyncContext*
>(c); };
200 template <ReadSource ReadSource>
217 AsyncContext asyncContext;
219#if defined(SK_GRAPHITE)
221 if (!graphiteContext) {
225 std::unique_ptr<skgpu::graphite::Recording> recording = recorder->
snap();
256 graphiteContext->
submit();
257 while (!asyncContext.fCalled) {
266 src->asyncRescaleAndReadPixelsYUVA420(yuvCS,
275 src->asyncRescaleAndReadPixelsYUV420(yuvCS,
287 while (!asyncContext.fCalled) {
293 if (!asyncContext.fResult) {
303 {yaII, asyncContext.fResult->data(0), asyncContext.fResult->rowBytes(0)},
304 {uvII, asyncContext.fResult->data(1), asyncContext.fResult->rowBytes(1)},
305 {uvII, asyncContext.fResult->data(2), asyncContext.fResult->rowBytes(2)},
309 yuvPMs[3] = {yaII, asyncContext.fResult->data(3), asyncContext.fResult->rowBytes(3)};
315#if defined(SK_GRAPHITE)
327 template <ReadSource ReadSource>
329 Source<ReadSource>*
src,
353 result = readAndScaleRGBA<ReadSource>(
src,
361 errorMsg->
printf(
"async read call failed.");
368 result = readAndScaleYUVA<ReadSource>(
src,
379 errorMsg->
printf(
"YUV[A]420 async call failed. Allowed for now.");
382 int nextCS =
static_cast<int>(yuvColorSpace + 1) %
398 struct AsyncContext {
399 bool fCalled =
false;
400 std::unique_ptr<const SkImage::AsyncReadResult>
fResult;
406 static void AsyncCallback(
void* c, std::unique_ptr<const SkImage::AsyncReadResult>
result) {
407 auto context =
static_cast<AsyncContext*
>(c);
408 context->fResult = std::move(
result);
409 context->fCalled =
true;
415template <ReadSource ReadSource, Type Type>
416class AsyncRescaleAndReadGridGM :
public AsyncReadGMBase {
418 AsyncRescaleAndReadGridGM(
const char*
name,
419 const char* imageFile,
422 : AsyncReadGMBase(
name)
423 , fImageFile(imageFile)
425 , fReadSize(readSize) {}
431 errorMsg->
printf(
"Could not load image file %s.", fImageFile.c_str());
435 *errorMsg =
"Not supported on recording/vector backends.";
439 auto sourceOrResult = convert_image_to_source<ReadSource>(canvas,
image, errorMsg);
440 if (
auto dr = std::get_if<skiagm::DrawResult>(&sourceOrResult)) {
445 return drawRescaleGrid<ReadSource>(canvas,
446 std::get<Src>(sourceOrResult).
get(),
453 SkISize getISize()
override {
return {3 * fReadSize.
width(), 2 * fReadSize.height()}; }
462#define DEF_RESCALE_AND_READ_GRID_GM(IMAGE_FILE, TAG, SRC_RECT, W, H, SOURCE, TYPE) \
463 DEF_GM(return new (AsyncRescaleAndReadGridGM<SOURCE, TYPE>)( \
464 "async_rescale_and_read_" #TAG, #IMAGE_FILE, SRC_RECT, SkISize{W, H});)
471 ReadSource::kSurface,
484 SkIRect::MakeXYWH(100, 20, 100, 100),
487 ReadSource::kSurface,
492 SkIRect::MakeXYWH(0, 10, 180, 150),
495 ReadSource::kSurface,
519 ReadSource::kSurface,
537 *errorMsg =
"Not supported on recording/vector backends.";
542 if (!dContext &&
surface->recordingContext()) {
543 *errorMsg =
"Not supported in DDL mode";
556 auto yuvImage = readAndScaleYUVA<ReadSource::kSurface>(
surface,
576DEF_GM(
return new AyncYUVNoScaleGM();)
579class AsyncRescaleAndReadNoBleedGM :
public AsyncReadGMBase {
581 AsyncRescaleAndReadNoBleedGM() : AsyncReadGMBase(
"async_rescale_and_read_no_bleed") {}
583 SkISize getISize()
override {
return {60, 60}; }
587 *errorMsg =
"Not supported on recording/vector backends.";
593 *errorMsg =
"Not supported in DDL mode";
597 static constexpr int kBorder = 5;
598 static constexpr int kInner = 5;
601 kInner + 2 * kBorder,
607 *errorMsg =
"Could not create surface for image.";
618 surface->getCanvas()->restore();
619 static constexpr int kPad = 2;
622 SkISize downSize = {
static_cast<int>(
kInner / 2),
static_cast<int>(kInner / 2)};
623 result = drawRescaleGrid<ReadSource::kSurface>(canvas,
634 SkISize upSize = {
static_cast<int>(
kInner * 3.5),
static_cast<int>(kInner * 4.6)};
635 result = drawRescaleGrid<ReadSource::kSurface>(canvas,
650DEF_GM(
return new AsyncRescaleAndReadNoBleedGM();)
653class AsyncRescaleAndReadAlphaTypeGM :
public AsyncReadGMBase {
655 AsyncRescaleAndReadAlphaTypeGM() : AsyncReadGMBase(
"async_rescale_and_read_alpha_type") {}
657 SkISize getISize()
override {
return {512, 512}; }
662 *errorMsg =
"Not supported in DDL mode";
667 *errorMsg =
"Reading to unpremul not supported in Graphite.";
679 {.3f, .3f, .3f, .3f},
680 {1.f, .2f, .6f, .9f},
681 {0.f, .1f, 1.f, .1f},
682 {.7f, .8f, .2f, .7f},
692 paint.setShader(std::move(shader));
694 upmSurf->getCanvas()->drawPaint(
paint);
695 pmSurf ->getCanvas()->drawPaint(
paint);
697 auto pmImg = pmSurf->makeImageSnapshot();
698 auto upmImg = upmSurf->makeImageSnapshot();
700 auto imageOrResult = convert_image_to_source<ReadSource::kImage>(canvas,
703 if (
const auto*
dr = std::get_if<skiagm::DrawResult>(&imageOrResult)) {
708 imageOrResult = convert_image_to_source<ReadSource::kImage>(canvas,
711 if (
const auto*
dr = std::get_if<skiagm::DrawResult>(&imageOrResult)) {
720 for (
const auto& img : {pmImg, upmImg}) {
723 auto readInfo = img->imageInfo().makeAlphaType(readAT).makeWH(
size,
size);
725 readAndScaleRGBA<ReadSource::kImage>(img.get(),
733 *errorMsg =
"async readback failed";
747DEF_GM(
return new AsyncRescaleAndReadAlphaTypeGM();)
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kUnknown_SkColorType
uninitialized
constexpr SkColor SK_ColorLTGRAY
constexpr SkColor SK_ColorBLUE
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
constexpr SkColor SK_ColorDKGRAY
@ kLastEnum_SkYUVColorSpace
last valid value
@ kRec601_SkYUVColorSpace
LoopControlFlowInfo fResult
#define DEF_RESCALE_AND_READ_GRID_GM(IMAGE_FILE, TAG, SRC_RECT, W, H, SOURCE, TYPE)
Type::kYUV Type::kRGBA text_down
Type::kYUV Type::kRGBA()() Type::kRGBA text_up_large
void checkAsyncWorkCompletion()
bool submit(GrSyncCpu sync=GrSyncCpu::kNo)
bool abandoned() override
SkSurface * getSurface() const
void translate(SkScalar dx, SkScalar dy)
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
virtual GrRecordingContext * recordingContext() const
virtual skgpu::graphite::Recorder * recorder() const
void clear(SkColor color)
SkImageInfo imageInfo() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
static sk_sp< SkColorSpace > MakeSRGB()
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)
const SkImageInfo & imageInfo() const
SkISize dimensions() const
void printf(const char format[],...) SK_PRINTF_LIKE(2
@ kY_U_V_A
Plane 0: Y, Plane 1: U, Plane 2: V, Plane 3: A.
@ kY_U_V
Plane 0: Y, Plane 1: U, Plane 2: V.
@ k420
1 set of UV values for each 2x2 block of Y values.
static SkYUVAPixmaps FromExternalPixmaps(const SkYUVAInfo &, const SkPixmap[kMaxPlanes])
DrawResult onDraw(SkCanvas *canvas, SkString *errorMsg) override
SkISize getISize() override
static std::unique_ptr< LazyYUVImage > Make(sk_sp< SkData > data, skgpu::Mipmapped=skgpu::Mipmapped::kNo, sk_sp< SkColorSpace >=nullptr)
void asyncRescaleAndReadPixelsYUV420(const SkImage *, SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
void asyncRescaleAndReadPixelsYUVA420(const SkImage *, SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
bool submit(SyncToCpu=SyncToCpu::kNo)
bool insertRecording(const InsertRecordingInfo &)
void checkAsyncWorkCompletion()
void asyncRescaleAndReadPixels(const SkImage *image, const SkImageInfo &dstImageInfo, const SkIRect &srcRect, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
std::unique_ptr< Recording > snap()
GraphiteTestContext * graphiteTestContext() const
virtual SkString getName() const =0
std::array< MockImage, 3 > images
SK_API sk_sp< SkImage > RasterFromPixmap(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
sk_sp< const SkImage > image
PODArray< SkColor > colors
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
DEF_SWITCHES_START aot vmservice shared library name
@ kInner
fuzzy inside, nothing outside
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 mode
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
const myers::Point & get(const myers::Segment &)
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkIRect MakeSize(const SkISize &size)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const
SkImageInfo makeDimensions(SkISize newSize) const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkColorType colorType() const
static SkRect Make(const SkISize &size)