aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorBrian Salomon <bsalomon@google.com>2019-01-11 16:03:19 -0500
committerSkia Commit-Bot <skia-commit-bot@chromium.org>2019-01-14 16:19:01 +0000
commit3f4cd774e6c6b2c71efc78f3e551d828f20b85e8 (patch)
tree3203661f4a3ee90faf6c1c9e32581536c9238d8a /tools
parente0e41efcfb3afa1ed1faef7d93014508391c2f44 (diff)
downloadskqp-3f4cd774e6c6b2c71efc78f3e551d828f20b85e8.tar.gz
Make SkPromiseImageTexture ref counted.
This makes the API easier to use in Chrome. It is no longer required to pass the SkPromiseImageTexture to the release proc. Bug: skia: Change-Id: I6636401f6a7915d3ad15e890718638bc91a58cc4 Reviewed-on: https://skia-review.googlesource.com/c/183383 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/DDLPromiseImageHelper.cpp25
-rw-r--r--tools/DDLPromiseImageHelper.h25
2 files changed, 23 insertions, 27 deletions
diff --git a/tools/DDLPromiseImageHelper.cpp b/tools/DDLPromiseImageHelper.cpp
index fa722651bc..05ef601d47 100644
--- a/tools/DDLPromiseImageHelper.cpp
+++ b/tools/DDLPromiseImageHelper.cpp
@@ -21,24 +21,21 @@ DDLPromiseImageHelper::PromiseImageCallbackContext::~PromiseImageCallbackContext
SkASSERT(!fUnreleasedFulfills);
SkASSERT(fTotalReleases == fTotalFulfills);
SkASSERT(!fTotalFulfills || fDoneCnt);
- GrGpu* gpu = fContext->contextPriv().getGpu();
- if (fPromiseImageTexture.isValid()) {
- gpu->deleteTestingOnlyBackendTexture(fPromiseImageTexture.backendTexture());
+ if (fPromiseImageTexture) {
+ GrGpu* gpu = fContext->contextPriv().getGpu();
+ gpu->deleteTestingOnlyBackendTexture(fPromiseImageTexture->backendTexture());
}
}
void DDLPromiseImageHelper::PromiseImageCallbackContext::setBackendTexture(
const GrBackendTexture& backendTexture) {
SkASSERT(!fUnreleasedFulfills);
- if (fPromiseImageTexture.isValid()) {
+ if (fPromiseImageTexture) {
GrGpu* gpu = fContext->contextPriv().getGpu();
-
- if (fPromiseImageTexture.isValid()) {
- gpu->deleteTestingOnlyBackendTexture(fPromiseImageTexture.backendTexture());
- }
+ gpu->deleteTestingOnlyBackendTexture(fPromiseImageTexture->backendTexture());
}
- fPromiseImageTexture = SkPromiseImageTexture{backendTexture};
+ fPromiseImageTexture = SkPromiseImageTexture::Make(backendTexture);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -128,7 +125,7 @@ void DDLPromiseImageHelper::uploadAllToGPU(GrContext* context) {
callbackContext->setBackendTexture(create_yuva_texture(gpu, yuvPixmap,
info.yuvaIndices(), j));
- SkASSERT(callbackContext->promiseImageTexture()->isValid());
+ SkASSERT(callbackContext->promiseImageTexture());
fImageInfo[i].setCallbackContext(j, std::move(callbackContext));
}
@@ -168,7 +165,7 @@ void DDLPromiseImageHelper::replaceEveryOtherPromiseTexture(GrContext* context)
const SkPixmap& yuvPixmap = info.yuvPixmap(j);
info.callbackContext(j)->setBackendTexture(
create_yuva_texture(gpu, yuvPixmap, info.yuvaIndices(), j));
- SkASSERT(info.callbackContext(j)->promiseImageTexture()->isValid());
+ SkASSERT(info.callbackContext(j)->promiseImageTexture());
}
} else {
const SkBitmap& bm = info.normalBitmap();
@@ -210,7 +207,7 @@ sk_sp<SkImage> DDLPromiseImageHelper::PromiseImageCreator(const void* rawData,
const DDLPromiseImageHelper::PromiseImageInfo& curImage = helper->getInfo(*indexPtr);
- if (!curImage.backendTexture(0).isValid()) {
+ if (!curImage.promiseTexture(0)) {
SkASSERT(!curImage.isYUV());
// We weren't able to make a backend texture for this SkImage. In this case we create
// a separate bitmap-backed image for each thread.
@@ -228,7 +225,7 @@ sk_sp<SkImage> DDLPromiseImageHelper::PromiseImageCreator(const void* rawData,
int textureCount;
SkAssertResult(SkYUVAIndex::AreValidIndices(curImage.yuvaIndices(), &textureCount));
for (int i = 0; i < textureCount; ++i) {
- const GrBackendTexture& backendTex = curImage.backendTexture(i);
+ const GrBackendTexture& backendTex = curImage.promiseTexture(i)->backendTexture();
backendFormats[i] = backendTex.getBackendFormat();
SkASSERT(backendFormats[i].isValid());
contexts[i] = curImage.refCallbackContext(i).release();
@@ -254,7 +251,7 @@ sk_sp<SkImage> DDLPromiseImageHelper::PromiseImageCreator(const void* rawData,
curImage.callbackContext(i)->wasAddedToImage();
}
} else {
- const GrBackendTexture& backendTex = curImage.backendTexture(0);
+ const GrBackendTexture& backendTex = curImage.promiseTexture(0)->backendTexture();
GrBackendFormat backendFormat = backendTex.getBackendFormat();
SkASSERT(backendFormat.isValid());
diff --git a/tools/DDLPromiseImageHelper.h b/tools/DDLPromiseImageHelper.h
index f8627aab36..890d108fcc 100644
--- a/tools/DDLPromiseImageHelper.h
+++ b/tools/DDLPromiseImageHelper.h
@@ -83,10 +83,12 @@ private:
void setBackendTexture(const GrBackendTexture& backendTexture);
- void fulfill() {
+ sk_sp<SkPromiseImageTexture> fulfill() {
+ SkASSERT(fPromiseImageTexture);
SkASSERT(fUnreleasedFulfills >= 0);
++fUnreleasedFulfills;
++fTotalFulfills;
+ return fPromiseImageTexture;
}
void release() {
@@ -102,11 +104,13 @@ private:
void wasAddedToImage() { fNumImages++; }
- SkPromiseImageTexture* promiseImageTexture() { return &fPromiseImageTexture; }
+ const SkPromiseImageTexture* promiseImageTexture() const {
+ return fPromiseImageTexture.get();
+ }
private:
GrContext* fContext;
- SkPromiseImageTexture fPromiseImageTexture;
+ sk_sp<SkPromiseImageTexture> fPromiseImageTexture;
int fNumImages = 0;
int fTotalFulfills = 0;
int fTotalReleases = 0;
@@ -169,9 +173,9 @@ private:
return fCallbackContexts[index];
}
- const GrBackendTexture& backendTexture(int index) const {
+ const SkPromiseImageTexture* promiseTexture(int index) const {
SkASSERT(index >= 0 && index < (this->isYUV() ? SkYUVASizeInfo::kMaxCount : 1));
- return fCallbackContexts[index]->promiseImageTexture()->backendTexture();
+ return fCallbackContexts[index]->promiseImageTexture();
}
void setNormalBitmap(const SkBitmap& bm) { fBitmap = bm; }
@@ -216,19 +220,14 @@ private:
SkTArray<sk_sp<SkImage>>* fPromiseImages;
};
- static SkPromiseImageTexture* PromiseImageFulfillProc(void* textureContext) {
+ static sk_sp<SkPromiseImageTexture> PromiseImageFulfillProc(void* textureContext) {
auto callbackContext = static_cast<PromiseImageCallbackContext*>(textureContext);
- SkASSERT(callbackContext->promiseImageTexture()->isValid());
- callbackContext->fulfill();
- return callbackContext->promiseImageTexture();
+ return callbackContext->fulfill();
}
- static void PromiseImageReleaseProc(void* textureContext,
- const SkPromiseImageTexture* texture) {
+ static void PromiseImageReleaseProc(void* textureContext) {
auto callbackContext = static_cast<PromiseImageCallbackContext*>(textureContext);
callbackContext->release();
- SkASSERT(texture == callbackContext->promiseImageTexture());
- SkASSERT(callbackContext->promiseImageTexture()->isValid());
}
static void PromiseImageDoneProc(void* textureContext) {