26DDLPromiseImageHelper::PromiseImageInfo::PromiseImageInfo(
int index,
27 uint32_t originalUniqueID,
30 , fOriginalUniqueID(originalUniqueID)
34DDLPromiseImageHelper::PromiseImageInfo::PromiseImageInfo(
PromiseImageInfo&& other)
35 : fIndex(other.fIndex)
36 , fOriginalUniqueID(other.fOriginalUniqueID)
37 , fImageInfo(other.fImageInfo)
38 , fBaseLevel(other.fBaseLevel)
39 , fMipLevels(
std::move(other.fMipLevels))
40 , fYUVAPixmaps(
std::move(other.fYUVAPixmaps)) {
42 fCallbackContexts[
i] = std::move(other.fCallbackContexts[
i]);
46DDLPromiseImageHelper::PromiseImageInfo::~PromiseImageInfo() {}
48std::unique_ptr<SkPixmap[]> DDLPromiseImageHelper::PromiseImageInfo::normalMipLevels()
const {
50 std::unique_ptr<SkPixmap[]> pixmaps(
new SkPixmap[this->numMipLevels()]);
51 pixmaps[0] = fBaseLevel.pixmap();
53 for (
int i = 0;
i < fMipLevels->countLevels(); ++
i) {
55 fMipLevels->getLevel(
i, &mipLevel);
62int DDLPromiseImageHelper::PromiseImageInfo::numMipLevels()
const {
64 return fMipLevels ? fMipLevels->countLevels()+1 : 1;
67void DDLPromiseImageHelper::PromiseImageInfo::setMipLevels(
const SkBitmap& baseLevel,
68 std::unique_ptr<SkMipmap> mipLevels) {
69 fBaseLevel = baseLevel;
70 fMipLevels = std::move(mipLevels);
76 SkASSERT(!fTotalFulfills || fDoneCnt);
78 if (fPromiseImageTexture) {
92 if (fPromiseImageTexture) {
95 fPromiseImageTexture =
nullptr;
108 int id = helper->findOrDefineImage(
image);
115 if (!compressedPictureData) {
119 this->createCallbackContexts(dContext);
127 SkASSERT(texIndex >= 0 && texIndex <= 3);
129 bool finishedBECreate =
false;
130 auto markFinished = [](
void* context) {
131 *(
bool*)context =
true;
139 "CreateYuvaTexture");
140 if (beTex.isValid()) {
142 while (!finishedBECreate) {
154void DDLPromiseImageHelper::CreateBETexturesForPromiseImage(
GrDirectContext* direct,
157 int numPixmaps =
info->yuvaInfo().numPlanes();
158 for (
int j = 0; j < numPixmaps; ++j) {
170 if (!callbackContext) {
175 std::unique_ptr<SkPixmap[]> mipLevels =
info->normalMipLevels();
177 bool finishedBECreate =
false;
178 auto markFinished = [](
void* context) {
179 *(
bool*)context =
true;
182 info->numMipLevels(),
188 "CreateBETexturesForPromiseImage");
191 while (!finishedBECreate) {
201 int numPixmaps =
info->yuvaInfo().numPlanes();
202 for (
int j = 0; j < numPixmaps; ++j) {
211 if (!callbackContext) {
221void DDLPromiseImageHelper::createCallbackContexts(
GrDirectContext* direct) {
225 for (
int i = 0;
i < fImageInfo.
size(); ++
i) {
229 int numPixmaps =
info.yuvaInfo().numPlanes();
231 for (
int j = 0; j < numPixmaps; ++j) {
240 info.setCallbackContext(j, std::move(callbackContext));
260 info.setCallbackContext(0, std::move(callbackContext));
267 for (
int i = 0;
i < fImageInfo.
size(); ++
i) {
268 PromiseImageInfo*
info = &fImageInfo[
i];
270 taskGroup->
add([direct,
info]() { CreateBETexturesForPromiseImage(direct,
info); });
273 for (
int i = 0;
i < fImageInfo.
size(); ++
i) {
274 CreateBETexturesForPromiseImage(direct, &fImageInfo[
i]);
281 for (
int i = 0;
i < fImageInfo.
size(); ++
i) {
282 PromiseImageInfo*
info = &fImageInfo[
i];
284 taskGroup->
add([
info]() { DeleteBETexturesForPromiseImage(
info); });
287 for (
int i = 0;
i < fImageInfo.
size(); ++
i) {
288 DeleteBETexturesForPromiseImage(&fImageInfo[
i]);
295 SkData* compressedPictureData) {
296 DeserialImageProcContext procContext { std::move(threadSafeProxy),
this };
306sk_sp<SkImage> DDLPromiseImageHelper::CreatePromiseImages(
const void* rawData,
309 DeserialImageProcContext* procContext =
static_cast<DeserialImageProcContext*
>(ctxIn);
314 const int* indexPtr =
static_cast<const int*
>(rawData);
315 if (!helper->isValidID(*indexPtr)) {
319 const DDLPromiseImageHelper::PromiseImageInfo& curImage = helper->getInfo(*indexPtr);
323 if (!curImage.isYUV() && !curImage.callbackContext(0)) {
324 SkASSERT(curImage.baseLevel().isImmutable());
325 return curImage.baseLevel().asImage();
328 SkASSERT(curImage.index() == *indexPtr);
331 if (curImage.isYUV()) {
333 const SkYUVAInfo& yuvaInfo = curImage.yuvaInfo();
336 for (
int i = 0;
i < textureCount; ++
i) {
337 backendFormats[
i] = curImage.backendFormat(
i);
338 contexts[
i] = curImage.refCallbackContext(
i).release();
343 procContext->fThreadSafeProxy,
345 curImage.refOverallColorSpace(),
352 for (
int i = 0;
i < textureCount; ++
i) {
353 curImage.callbackContext(
i)->wasAddedToImage();
362 curImage.overallDimensions(),
363 curImage.mipmapped(0),
365 curImage.overallColorType(),
366 curImage.overallAlphaType(),
367 curImage.refOverallColorSpace(),
370 (
void*)curImage.refCallbackContext(0).release());
371 curImage.callbackContext(0)->wasAddedToImage();
378int DDLPromiseImageHelper::findImage(
SkImage*
image)
const {
379 for (
int i = 0;
i < fImageInfo.
size(); ++
i) {
382 SkASSERT(this->isValidID(
i) && this->isValidID(fImageInfo[
i].index()));
405 if (codec && codec->queryYUVAInfo(fSupportedYUVADataTypes, &yuvaInfo)) {
407 if (!codec->getYUVAPlanes(yuvaPixmaps)) {
411 newImageInfo.setYUVPlanes(std::move(yuvaPixmaps));
433 newImageInfo.setMipLevels(tmp, std::move(mipmaps));
437 return fImageInfo.
size()-1;
440int DDLPromiseImageHelper::findOrDefineImage(
SkImage*
image) {
441 int preExistingID = this->findImage(
image);
442 if (preExistingID >= 0) {
443 SkASSERT(this->isValidID(preExistingID));
444 return preExistingID;
447 int newID = this->addImage(
image);
static GrBackendTexture create_yuva_texture(GrDirectContext *direct, const SkPixmap &pm, int texIndex)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kTopLeft_GrSurfaceOrigin
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
static SkImage_Base * as_IB(SkImage *image)
sk_sp< SkPicture > recreateSKP(GrDirectContext *, SkPicture *)
void deleteAllFromGPU(SkTaskGroup *, GrDirectContext *)
void uploadAllToGPU(SkTaskGroup *, GrDirectContext *)
GrBackendFormat getBackendFormat() const
const GrCaps * caps() const
virtual bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const =0
int maxTextureSize() const
SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const
void checkAsyncWorkCompletion()
bool submit(GrSyncCpu sync=GrSyncCpu::kNo)
void deleteBackendTexture(const GrBackendTexture &)
GrBackendTexture createBackendTexture(int width, int height, const GrBackendFormat &, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, std::string_view label={})
sk_sp< GrContextThreadSafeProxy > threadSafeProxy()
GrDirectContextPriv priv()
GrBackendTexture backendTexture() const
static sk_sp< GrPromiseImageTexture > Make(const GrBackendTexture &backendTexture)
~PromiseImageCallbackContext() override
static sk_sp< GrPromiseImageTexture > PromiseImageFulfillProc(void *textureContext)
void destroyBackendTexture()
void setBackendTexture(const GrBackendTexture &backendTexture)
static void PromiseImageReleaseProc(void *textureContext)
const GrPromiseImageTexture * promiseImageTexture() const
void allocPixels(const SkImageInfo &info, size_t rowBytes)
const SkPixmap & pixmap() const
SkColorType colorType() const
static std::unique_ptr< SkImageGenerator > MakeFromEncodedCodec(sk_sp< SkData >, std::optional< SkAlphaType >=std::nullopt)
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
bool readPixels(GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
uint32_t uniqueID() const
SkAlphaType alphaType() const
SkColorType colorType() const
sk_sp< SkData > refEncodedData() const
sk_sp< SkColorSpace > refColorSpace() const
static SkMipmap * Build(const SkPixmap &src, SkDiscardableFactoryProc, bool computeContents=true)
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const
static sk_sp< SkPicture > MakeFromData(const SkData *data, const SkDeserialProcs *procs=nullptr)
SkColorType colorType() const
void add(std::function< void(void)> fn)
static constexpr int kMaxPlanes
static SkYUVAPixmaps Allocate(const SkYUVAPixmapInfo &yuvaPixmapInfo)
T & emplace_back(Args &&... args)
static float max(float r, float g, float b)
SK_API sk_sp< SkImage > PromiseTextureFrom(skgpu::graphite::Recorder *, SkISize dimensions, const skgpu::graphite::TextureInfo &, const SkColorInfo &, skgpu::Origin origin, skgpu::graphite::Volatile, GraphitePromiseTextureFulfillProc, GraphitePromiseImageReleaseProc, GraphitePromiseTextureReleaseProc, GraphitePromiseImageContext, std::string_view label={})
SK_API sk_sp< SkImage > PromiseTextureFromYUVA(skgpu::graphite::Recorder *, const skgpu::graphite::YUVABackendTextureInfo &, sk_sp< SkColorSpace > imageColorSpace, skgpu::graphite::Volatile, GraphitePromiseTextureFulfillProc, GraphitePromiseImageReleaseProc, GraphitePromiseTextureReleaseProc, GraphitePromiseImageContext imageContext, GraphitePromiseTextureFulfillContext planeContexts[], std::string_view label={})
sk_sp< const SkImage > image
SkDeserialImageProc fImageProc
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkSerialImageProc fImageProc