skia2/tools/DDLPromiseImageHelper.cpp

447 lines
18 KiB
C++
Raw Normal View History

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/DDLPromiseImageHelper.h"
#include "include/core/SkDeferredDisplayListRecorder.h"
#include "include/core/SkPicture.h"
#include "include/core/SkSerialProcs.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrYUVABackendTextures.h"
#include "src/codec/SkCodecImageGenerator.h"
#include "src/core/SkCachedData.h"
#include "src/core/SkMipmap.h"
#include "src/core/SkTaskGroup.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/image/SkImage_Base.h"
#include "src/image/SkImage_GpuYUVA.h"
DDLPromiseImageHelper::PromiseImageInfo::PromiseImageInfo(int index,
uint32_t originalUniqueID,
const SkImageInfo& ii)
: fIndex(index)
, fOriginalUniqueID(originalUniqueID)
, fImageInfo(ii) {
}
DDLPromiseImageHelper::PromiseImageInfo::PromiseImageInfo(PromiseImageInfo&& other)
: fIndex(other.fIndex)
, fOriginalUniqueID(other.fOriginalUniqueID)
, fImageInfo(other.fImageInfo)
, fBaseLevel(other.fBaseLevel)
, fMipLevels(std::move(other.fMipLevels))
, fYUVAPixmaps(std::move(other.fYUVAPixmaps)) {
for (int i = 0; i < SkYUVAInfo::kMaxPlanes; ++i) {
fCallbackContexts[i] = std::move(other.fCallbackContexts[i]);
}
}
DDLPromiseImageHelper::PromiseImageInfo::~PromiseImageInfo() {}
std::unique_ptr<SkPixmap[]> DDLPromiseImageHelper::PromiseImageInfo::normalMipLevels() const {
SkASSERT(!this->isYUV());
std::unique_ptr<SkPixmap[]> pixmaps(new SkPixmap[this->numMipLevels()]);
pixmaps[0] = fBaseLevel.pixmap();
if (fMipLevels) {
for (int i = 0; i < fMipLevels->countLevels(); ++i) {
SkMipmap::Level mipLevel;
fMipLevels->getLevel(i, &mipLevel);
pixmaps[i+1] = mipLevel.fPixmap;
}
}
return pixmaps;
}
int DDLPromiseImageHelper::PromiseImageInfo::numMipLevels() const {
SkASSERT(!this->isYUV());
return fMipLevels ? fMipLevels->countLevels()+1 : 1;
}
void DDLPromiseImageHelper::PromiseImageInfo::setMipLevels(const SkBitmap& baseLevel,
std::unique_ptr<SkMipmap> mipLevels) {
fBaseLevel = baseLevel;
fMipLevels = std::move(mipLevels);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
PromiseImageCallbackContext::~PromiseImageCallbackContext() {
Reland "Test all YUVA image factories with different encoded origins." This reverts commit f1650efc557e75520f810d21f5f574f1ece005fe. Reason for revert: fix for cpu/ddl configs Original change's description: > Revert "Test all YUVA image factories with different encoded origins." > > This reverts commit 2ba80af000b7efa1c54616bd12edc627e5cb45af. > > Reason for revert: new test fails ddl and cpu configs on imggen > > Original change's description: > > Test all YUVA image factories with different encoded origins. > > > > Now that SkImage_GpuYUVA stores a GrYUVATextureProxies it supports > > encoded origins. > > > > Modify wacky_yuv_format GMs to use different origins and remove > > restriction in SkImage::MakeFromYUVAPixmaps. > > > > Bug: skia:10632 > > Change-Id: I02477d592b7baba164944d629eeac48223698c10 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353623 > > Reviewed-by: Jim Van Verth <jvanverth@google.com> > > Commit-Queue: Brian Salomon <bsalomon@google.com> > > TBR=jvanverth@google.com,bsalomon@google.com > > Change-Id: If909ee4769cc1c74e1682a5e2870ec85a83f65c5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10632 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354661 > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Brian Salomon <bsalomon@google.com> TBR=jvanverth@google.com,bsalomon@google.com # Not skipping CQ checks because this is a reland. Bug: skia:10632 Change-Id: Iafe79ab5b3ce0ff9e3a4007e5d8fbc44edded196 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/355630 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
2021-01-19 17:11:07 +00:00
SkASSERT(fDoneCnt == fNumImages);
SkASSERT(!fTotalFulfills || fDoneCnt);
if (fPromiseImageTexture) {
fContext->deleteBackendTexture(fPromiseImageTexture->backendTexture());
}
}
void PromiseImageCallbackContext::setBackendTexture(const GrBackendTexture& backendTexture) {
SkASSERT(!fPromiseImageTexture);
SkASSERT(fBackendFormat == backendTexture.getBackendFormat());
fPromiseImageTexture = SkPromiseImageTexture::Make(backendTexture);
}
void PromiseImageCallbackContext::destroyBackendTexture() {
SkASSERT(!fPromiseImageTexture || fPromiseImageTexture->unique());
if (fPromiseImageTexture) {
fContext->deleteBackendTexture(fPromiseImageTexture->backendTexture());
}
fPromiseImageTexture = nullptr;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkPicture> DDLPromiseImageHelper::recreateSKP(GrDirectContext* dContext,
SkPicture* inputPicture) {
SkSerialProcs procs;
procs.fImageCtx = this;
procs.fImageProc = [](SkImage* image, void* ctx) -> sk_sp<SkData> {
auto helper = static_cast<DDLPromiseImageHelper*>(ctx);
int id = helper->findOrDefineImage(image);
// Even if 'id' is invalid (i.e., -1) write it to the SKP
return SkData::MakeWithCopy(&id, sizeof(id));
};
sk_sp<SkData> compressedPictureData = inputPicture->serialize(&procs);
if (!compressedPictureData) {
return nullptr;
}
this->createCallbackContexts(dContext);
return this->reinflateSKP(dContext->threadSafeProxy(), compressedPictureData.get());
}
static GrBackendTexture create_yuva_texture(GrDirectContext* direct,
const SkPixmap& pm,
int texIndex) {
SkASSERT(texIndex >= 0 && texIndex <= 3);
bool finishedBECreate = false;
auto markFinished = [](void* context) {
*(bool*)context = true;
};
auto beTex = direct->createBackendTexture(pm,
kTopLeft_GrSurfaceOrigin,
GrRenderable::kNo,
GrProtected::kNo,
markFinished,
&finishedBECreate);
if (beTex.isValid()) {
direct->submit();
while (!finishedBECreate) {
direct->checkAsyncWorkCompletion();
}
}
return beTex;
}
/*
* Create backend textures and upload data to them for all the textures required to satisfy
* a single promise image.
* For YUV textures this will result in up to 4 actual textures.
*/
void DDLPromiseImageHelper::CreateBETexturesForPromiseImage(GrDirectContext* direct,
PromiseImageInfo* info) {
if (info->isYUV()) {
int numPixmaps = info->yuvaInfo().numPlanes();
for (int j = 0; j < numPixmaps; ++j) {
const SkPixmap& yuvPixmap = info->yuvPixmap(j);
PromiseImageCallbackContext* callbackContext = info->callbackContext(j);
SkASSERT(callbackContext);
// DDL TODO: what should we do with mipmapped YUV images
callbackContext->setBackendTexture(create_yuva_texture(direct, yuvPixmap, j));
SkASSERT(callbackContext->promiseImageTexture());
}
} else {
PromiseImageCallbackContext* callbackContext = info->callbackContext(0);
if (!callbackContext) {
// This texture would've been too large to fit on the GPU
return;
}
std::unique_ptr<SkPixmap[]> mipLevels = info->normalMipLevels();
bool finishedBECreate = false;
auto markFinished = [](void* context) {
*(bool*)context = true;
};
auto backendTex = direct->createBackendTexture(mipLevels.get(),
info->numMipLevels(),
kTopLeft_GrSurfaceOrigin,
GrRenderable::kNo,
GrProtected::kNo,
markFinished,
&finishedBECreate);
SkASSERT(backendTex.isValid());
direct->submit();
while (!finishedBECreate) {
direct->checkAsyncWorkCompletion();
}
callbackContext->setBackendTexture(backendTex);
}
}
void DDLPromiseImageHelper::DeleteBETexturesForPromiseImage(PromiseImageInfo* info) {
if (info->isYUV()) {
int numPixmaps = info->yuvaInfo().numPlanes();
for (int j = 0; j < numPixmaps; ++j) {
PromiseImageCallbackContext* callbackContext = info->callbackContext(j);
SkASSERT(callbackContext);
callbackContext->destroyBackendTexture();
SkASSERT(!callbackContext->promiseImageTexture());
}
} else {
PromiseImageCallbackContext* callbackContext = info->callbackContext(0);
if (!callbackContext) {
// This texture would've been too large to fit on the GPU
return;
}
callbackContext->destroyBackendTexture();
SkASSERT(!callbackContext->promiseImageTexture());
}
}
void DDLPromiseImageHelper::createCallbackContexts(GrDirectContext* direct) {
const GrCaps* caps = direct->priv().caps();
const int maxDimension = caps->maxTextureSize();
for (int i = 0; i < fImageInfo.count(); ++i) {
PromiseImageInfo& info = fImageInfo[i];
if (info.isYUV()) {
int numPixmaps = info.yuvaInfo().numPlanes();
for (int j = 0; j < numPixmaps; ++j) {
const SkPixmap& yuvPixmap = info.yuvPixmap(j);
GrBackendFormat backendFormat = direct->defaultBackendFormat(yuvPixmap.colorType(),
GrRenderable::kNo);
sk_sp<PromiseImageCallbackContext> callbackContext(
new PromiseImageCallbackContext(direct, backendFormat));
info.setCallbackContext(j, std::move(callbackContext));
}
} else {
const SkBitmap& baseLevel = info.baseLevel();
// TODO: explicitly mark the PromiseImageInfo as too big and check in uploadAllToGPU
if (maxDimension < std::max(baseLevel.width(), baseLevel.height())) {
// This won't fit on the GPU. Fallback to a raster-backed image per tile.
continue;
}
GrBackendFormat backendFormat = direct->defaultBackendFormat(baseLevel.colorType(),
GrRenderable::kNo);
Reland "Remove GrBackendFormat's textureType use from isFormatTexturable call." This reverts commit d90777ada391dffa9a19101fe7917d0c13a606b3. Reason for revert: relanding with fix to GrBackendTexture Original change's description: > Revert "Remove GrBackendFormat's textureType use from isFormatTexturable call." > > This reverts commit 832c817bc8a9567aa379181e71e7c602d2480de8. > > Reason for revert: uninitialized value in GrBackendTexture > > Original change's description: > > Remove GrBackendFormat's textureType use from isFormatTexturable call. > > > > The goal of this change was to remove the use of GrBackendFormat::textureType() > > from GrCaps::isFormatTexturable call. Instead we will always pass in a > > GrTextureType into this call. > > > > To do this a lot of plumbing of GrTextureType was added to various call > > sites. However, this CL halts the plubming up at the proxy level where we > > get it from the GrBackendFormat still. Future CLs will continue removing > > these call sites and others that use GrBackendFormat::textureType(). > > > > Bug: skia:12342 > > Change-Id: Ic0f02b9c7f7402405623b8aa31aa32a9a7c22297 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439277 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com > > Change-Id: I354bbbf00be7a86c480009f3e7b36a8777a6bf3a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:12342 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439338 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:12342 Change-Id: I151196f149f9e191d2975b8fe81334f4f8720744 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439339 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-08-13 20:20:18 +00:00
if (!caps->isFormatTexturable(backendFormat, GrTextureType::k2D)) {
continue;
}
sk_sp<PromiseImageCallbackContext> callbackContext(
new PromiseImageCallbackContext(direct, backendFormat));
info.setCallbackContext(0, std::move(callbackContext));
}
}
}
void DDLPromiseImageHelper::uploadAllToGPU(SkTaskGroup* taskGroup, GrDirectContext* direct) {
if (taskGroup) {
for (int i = 0; i < fImageInfo.count(); ++i) {
PromiseImageInfo* info = &fImageInfo[i];
taskGroup->add([direct, info]() { CreateBETexturesForPromiseImage(direct, info); });
}
} else {
for (int i = 0; i < fImageInfo.count(); ++i) {
CreateBETexturesForPromiseImage(direct, &fImageInfo[i]);
}
}
}
void DDLPromiseImageHelper::deleteAllFromGPU(SkTaskGroup* taskGroup, GrDirectContext* direct) {
if (taskGroup) {
for (int i = 0; i < fImageInfo.count(); ++i) {
PromiseImageInfo* info = &fImageInfo[i];
taskGroup->add([info]() { DeleteBETexturesForPromiseImage(info); });
}
} else {
for (int i = 0; i < fImageInfo.count(); ++i) {
DeleteBETexturesForPromiseImage(&fImageInfo[i]);
}
}
}
sk_sp<SkPicture> DDLPromiseImageHelper::reinflateSKP(
Reland "Support sharing promise images between DDLs" This reverts commit 38b9a4bc3e3c11e0f17545d15e714a74c10211e3. Reason for revert: Fixed ASAN, TSAN, and other bugs via other CLs. Original change's description: > Revert "Support sharing promise images between DDLs" > > This reverts commit 07e11d48cb02ba9a3845e653c1772c25021e65a3. > > Reason for revert: Broke DDL3_ASAN and DDL3_TSAN > > Original change's description: > > Support sharing promise images between DDLs > > > > - Migrate our code to SkImage::MakePromiseTexture > > - Have DDLTileHelper share one SKP and one set of promise images across all tiles. > > - Disallow on-the-fly allocation of mips for promise textures. > > > > Bug: skia:10286 > > Change-Id: Ie35976958454fc520f3c9d860e6285441260c9f7 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291938 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I939b14875d1a20e4a92eab94680adcfe9596ad81 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10286 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375738 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10286 Change-Id: Ibfd7dfcd72f10a4e29a87fa8c610f2dfd018e0db Cq-Include-Trybots: luci.skia.skia.primary:Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Debug-All-DDL3_ASAN,Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-DDL3_TSAN Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375739 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2021-03-03 23:12:56 +00:00
sk_sp<GrContextThreadSafeProxy> threadSafeProxy,
SkData* compressedPictureData) {
DeserialImageProcContext procContext { std::move(threadSafeProxy), this };
SkDeserialProcs procs;
Reland "Support sharing promise images between DDLs" This reverts commit 38b9a4bc3e3c11e0f17545d15e714a74c10211e3. Reason for revert: Fixed ASAN, TSAN, and other bugs via other CLs. Original change's description: > Revert "Support sharing promise images between DDLs" > > This reverts commit 07e11d48cb02ba9a3845e653c1772c25021e65a3. > > Reason for revert: Broke DDL3_ASAN and DDL3_TSAN > > Original change's description: > > Support sharing promise images between DDLs > > > > - Migrate our code to SkImage::MakePromiseTexture > > - Have DDLTileHelper share one SKP and one set of promise images across all tiles. > > - Disallow on-the-fly allocation of mips for promise textures. > > > > Bug: skia:10286 > > Change-Id: Ie35976958454fc520f3c9d860e6285441260c9f7 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291938 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I939b14875d1a20e4a92eab94680adcfe9596ad81 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10286 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375738 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10286 Change-Id: Ibfd7dfcd72f10a4e29a87fa8c610f2dfd018e0db Cq-Include-Trybots: luci.skia.skia.primary:Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Debug-All-DDL3_ASAN,Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-DDL3_TSAN Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375739 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2021-03-03 23:12:56 +00:00
procs.fImageCtx = (void*) &procContext;
procs.fImageProc = CreatePromiseImages;
return SkPicture::MakeFromData(compressedPictureData, &procs);
}
// This generates promise images to replace the indices in the compressed picture.
sk_sp<SkImage> DDLPromiseImageHelper::CreatePromiseImages(const void* rawData,
size_t length,
void* ctxIn) {
Reland "Support sharing promise images between DDLs" This reverts commit 38b9a4bc3e3c11e0f17545d15e714a74c10211e3. Reason for revert: Fixed ASAN, TSAN, and other bugs via other CLs. Original change's description: > Revert "Support sharing promise images between DDLs" > > This reverts commit 07e11d48cb02ba9a3845e653c1772c25021e65a3. > > Reason for revert: Broke DDL3_ASAN and DDL3_TSAN > > Original change's description: > > Support sharing promise images between DDLs > > > > - Migrate our code to SkImage::MakePromiseTexture > > - Have DDLTileHelper share one SKP and one set of promise images across all tiles. > > - Disallow on-the-fly allocation of mips for promise textures. > > > > Bug: skia:10286 > > Change-Id: Ie35976958454fc520f3c9d860e6285441260c9f7 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291938 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I939b14875d1a20e4a92eab94680adcfe9596ad81 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10286 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375738 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10286 Change-Id: Ibfd7dfcd72f10a4e29a87fa8c610f2dfd018e0db Cq-Include-Trybots: luci.skia.skia.primary:Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Debug-All-DDL3_ASAN,Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-DDL3_TSAN Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375739 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2021-03-03 23:12:56 +00:00
DeserialImageProcContext* procContext = static_cast<DeserialImageProcContext*>(ctxIn);
DDLPromiseImageHelper* helper = procContext->fHelper;
SkASSERT(length == sizeof(int));
const int* indexPtr = static_cast<const int*>(rawData);
if (!helper->isValidID(*indexPtr)) {
return nullptr;
}
const DDLPromiseImageHelper::PromiseImageInfo& curImage = helper->getInfo(*indexPtr);
// If there is no callback context that means 'createCallbackContexts' determined the
// texture wouldn't fit on the GPU. Create a bitmap-backed image.
if (!curImage.isYUV() && !curImage.callbackContext(0)) {
SkASSERT(curImage.baseLevel().isImmutable());
return curImage.baseLevel().asImage();
}
SkASSERT(curImage.index() == *indexPtr);
sk_sp<SkImage> image;
if (curImage.isYUV()) {
GrBackendFormat backendFormats[SkYUVAInfo::kMaxPlanes];
const SkYUVAInfo& yuvaInfo = curImage.yuvaInfo();
void* contexts[SkYUVAInfo::kMaxPlanes] = {nullptr, nullptr, nullptr, nullptr};
int textureCount = yuvaInfo.numPlanes();
for (int i = 0; i < textureCount; ++i) {
backendFormats[i] = curImage.backendFormat(i);
contexts[i] = curImage.refCallbackContext(i).release();
}
GrYUVABackendTextureInfo yuvaBackendTextures(yuvaInfo,
backendFormats,
GrMipmapped::kNo,
kTopLeft_GrSurfaceOrigin);
Reland "Support sharing promise images between DDLs" This reverts commit 38b9a4bc3e3c11e0f17545d15e714a74c10211e3. Reason for revert: Fixed ASAN, TSAN, and other bugs via other CLs. Original change's description: > Revert "Support sharing promise images between DDLs" > > This reverts commit 07e11d48cb02ba9a3845e653c1772c25021e65a3. > > Reason for revert: Broke DDL3_ASAN and DDL3_TSAN > > Original change's description: > > Support sharing promise images between DDLs > > > > - Migrate our code to SkImage::MakePromiseTexture > > - Have DDLTileHelper share one SKP and one set of promise images across all tiles. > > - Disallow on-the-fly allocation of mips for promise textures. > > > > Bug: skia:10286 > > Change-Id: Ie35976958454fc520f3c9d860e6285441260c9f7 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291938 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I939b14875d1a20e4a92eab94680adcfe9596ad81 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10286 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375738 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10286 Change-Id: Ibfd7dfcd72f10a4e29a87fa8c610f2dfd018e0db Cq-Include-Trybots: luci.skia.skia.primary:Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Debug-All-DDL3_ASAN,Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-DDL3_TSAN Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375739 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2021-03-03 23:12:56 +00:00
image = SkImage::MakePromiseYUVATexture(
procContext->fThreadSafeProxy,
yuvaBackendTextures,
curImage.refOverallColorSpace(),
PromiseImageCallbackContext::PromiseImageFulfillProc,
PromiseImageCallbackContext::PromiseImageReleaseProc,
contexts);
if (!image) {
return nullptr;
}
for (int i = 0; i < textureCount; ++i) {
curImage.callbackContext(i)->wasAddedToImage();
}
} else {
const GrBackendFormat& backendFormat = curImage.backendFormat(0);
SkASSERT(backendFormat.isValid());
Reland "Support sharing promise images between DDLs" This reverts commit 38b9a4bc3e3c11e0f17545d15e714a74c10211e3. Reason for revert: Fixed ASAN, TSAN, and other bugs via other CLs. Original change's description: > Revert "Support sharing promise images between DDLs" > > This reverts commit 07e11d48cb02ba9a3845e653c1772c25021e65a3. > > Reason for revert: Broke DDL3_ASAN and DDL3_TSAN > > Original change's description: > > Support sharing promise images between DDLs > > > > - Migrate our code to SkImage::MakePromiseTexture > > - Have DDLTileHelper share one SKP and one set of promise images across all tiles. > > - Disallow on-the-fly allocation of mips for promise textures. > > > > Bug: skia:10286 > > Change-Id: Ie35976958454fc520f3c9d860e6285441260c9f7 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291938 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I939b14875d1a20e4a92eab94680adcfe9596ad81 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10286 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375738 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10286 Change-Id: Ibfd7dfcd72f10a4e29a87fa8c610f2dfd018e0db Cq-Include-Trybots: luci.skia.skia.primary:Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Debug-All-DDL3_ASAN,Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-DDL3_TSAN Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375739 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2021-03-03 23:12:56 +00:00
image = SkImage::MakePromiseTexture(procContext->fThreadSafeProxy,
backendFormat,
curImage.overallDimensions(),
curImage.mipmapped(0),
Reland "Support sharing promise images between DDLs" This reverts commit 38b9a4bc3e3c11e0f17545d15e714a74c10211e3. Reason for revert: Fixed ASAN, TSAN, and other bugs via other CLs. Original change's description: > Revert "Support sharing promise images between DDLs" > > This reverts commit 07e11d48cb02ba9a3845e653c1772c25021e65a3. > > Reason for revert: Broke DDL3_ASAN and DDL3_TSAN > > Original change's description: > > Support sharing promise images between DDLs > > > > - Migrate our code to SkImage::MakePromiseTexture > > - Have DDLTileHelper share one SKP and one set of promise images across all tiles. > > - Disallow on-the-fly allocation of mips for promise textures. > > > > Bug: skia:10286 > > Change-Id: Ie35976958454fc520f3c9d860e6285441260c9f7 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291938 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I939b14875d1a20e4a92eab94680adcfe9596ad81 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10286 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375738 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10286 Change-Id: Ibfd7dfcd72f10a4e29a87fa8c610f2dfd018e0db Cq-Include-Trybots: luci.skia.skia.primary:Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Debug-All-DDL3_ASAN,Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-DDL3_TSAN Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375739 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2021-03-03 23:12:56 +00:00
GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
curImage.overallColorType(),
curImage.overallAlphaType(),
curImage.refOverallColorSpace(),
PromiseImageCallbackContext::PromiseImageFulfillProc,
PromiseImageCallbackContext::PromiseImageReleaseProc,
(void*)curImage.refCallbackContext(0).release());
curImage.callbackContext(0)->wasAddedToImage();
}
helper->fPromiseImages.push_back(image);
SkASSERT(image);
return image;
}
int DDLPromiseImageHelper::findImage(SkImage* image) const {
for (int i = 0; i < fImageInfo.count(); ++i) {
if (fImageInfo[i].originalUniqueID() == image->uniqueID()) { // trying to dedup here
SkASSERT(fImageInfo[i].index() == i);
SkASSERT(this->isValidID(i) && this->isValidID(fImageInfo[i].index()));
return i;
}
}
return -1;
}
int DDLPromiseImageHelper::addImage(SkImage* image) {
SkImage_Base* ib = as_IB(image);
SkImageInfo overallII = SkImageInfo::Make(image->width(), image->height(),
image->colorType() == kBGRA_8888_SkColorType
? kRGBA_8888_SkColorType
: image->colorType(),
image->alphaType(),
image->refColorSpace());
PromiseImageInfo& newImageInfo = fImageInfo.emplace_back(fImageInfo.count(),
image->uniqueID(),
overallII);
auto codec = SkCodecImageGenerator::MakeFromEncodedCodec(ib->refEncodedData());
SkYUVAPixmapInfo yuvaInfo;
2020-09-01 19:01:15 +00:00
if (codec && codec->queryYUVAInfo(fSupportedYUVADataTypes, &yuvaInfo)) {
auto yuvaPixmaps = SkYUVAPixmaps::Allocate(yuvaInfo);
if (!codec->getYUVAPlanes(yuvaPixmaps)) {
return -1;
}
SkASSERT(yuvaPixmaps.isValid());
newImageInfo.setYUVPlanes(std::move(yuvaPixmaps));
} else {
sk_sp<SkImage> rasterImage = image->makeRasterImage(); // force decoding of lazy images
if (!rasterImage) {
return -1;
}
SkBitmap tmp;
tmp.allocPixels(overallII);
if (!rasterImage->readPixels(nullptr, tmp.pixmap(), 0, 0)) {
return -1;
}
tmp.setImmutable();
// Given how the DDL testing harness works (i.e., only modifying the SkImages w/in an
// SKP) we don't know if a given SkImage will require mipmapping. To work around this
// we just try to create all the backend textures as mipmapped but, failing that, fall
// back to un-mipped.
std::unique_ptr<SkMipmap> mipmaps(SkMipmap::Build(tmp.pixmap(), nullptr));
newImageInfo.setMipLevels(tmp, std::move(mipmaps));
}
// In either case newImageInfo's PromiseImageCallbackContext is filled in by uploadAllToGPU
return fImageInfo.count()-1;
}
int DDLPromiseImageHelper::findOrDefineImage(SkImage* image) {
int preExistingID = this->findImage(image);
if (preExistingID >= 0) {
SkASSERT(this->isValidID(preExistingID));
return preExistingID;
}
int newID = this->addImage(image);
return newID;
}