Expand SkImage::getTextureHandle call

AFAICT cc/output/gl_renderer.cc only calls SkImage:getTexture to determine the origin of the backing GrTexture. What do y'all think of this CL as a means of removing that call to getTexture?

One alternative would be to add a new entry point like:

bool SkImage::getBackendTextureDesc(GrBackendTextureDesc* desc) const;

which fills in the entire desc and returns whether the image is texture backed.

Change-Id: Idd302c0a11d69ad08e0100bcf546b3bbaa7cf27e
Reviewed-on: https://skia-review.googlesource.com/7788
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2017-01-31 17:53:34 -05:00 committed by Skia Commit-Bot
parent 77b3f32936
commit 3390e15269
4 changed files with 53 additions and 10 deletions

View File

@ -223,8 +223,11 @@ public:
* Retrieves the backend API handle of the texture. If flushPendingGrContextIO then the
* GrContext will issue to the backend API any deferred IO operations on the texture before
* returning.
* If 'origin' is supplied it will be filled in with the origin of the content drawn
* into the image.
*/
GrBackendObject getTextureHandle(bool flushPendingGrContextIO) const;
GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
GrSurfaceOrigin* origin = nullptr) const;
/**
* Hints to image calls where the system might cache computed intermediates (e.g. the results

View File

@ -164,14 +164,16 @@ GrTexture* SkImage::getTexture() const {
bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekTexture()); }
GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO) const {
GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO,
GrSurfaceOrigin* origin) const {
GrTexture* texture = as_IB(this)->peekTexture();
if (texture) {
GrContext* context = texture->getContext();
if (context) {
if (flushPendingGrContextIO) {
context->prepareSurfaceForExternalIO(texture);
}
if (context && flushPendingGrContextIO) {
context->prepareSurfaceForExternalIO(texture);
}
if (origin) {
*origin = texture->origin();
}
return texture->getTextureHandle();
}
@ -184,7 +186,7 @@ GrTexture* SkImage::getTexture() const { return nullptr; }
bool SkImage::isTextureBacked() const { return false; }
GrBackendObject SkImage::getTextureHandle(bool) const { return 0; }
GrBackendObject SkImage::getTextureHandle(bool, GrSurfaceOrigin*) const { return 0; }
#endif

View File

@ -199,17 +199,37 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct
}
GrBackendTextureDesc backendDesc;
backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
backendDesc.fFlags = kNone_GrBackendTextureFlag;
backendDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
backendDesc.fWidth = kFullSize;
backendDesc.fHeight = kFullSize;
backendDesc.fSampleCnt = 0;
backendDesc.fTextureHandle = srcTexture->getTextureHandle();
sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlphaType));
sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(ctxInfo.grContext(),
backendDesc,
kPremul_SkAlphaType));
if (!srcImage) {
return;
}
GrSurfaceOrigin readBackOrigin;
GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin);
// TODO: Make it so we can check this (see skbug.com/5019)
#if 0
if (readBackHandle != backendDesc.fTextureHandle) {
ERRORF(reporter, "backend mismatch %d %d\n",
(int)readBackHandle, (int)backendDesc.fTextureHandle);
}
REPORTER_ASSERT(reporter, readBackHandle == backendDesc.fTextureHandle);
#else
REPORTER_ASSERT(reporter, SkToBool(readBackHandle));
#endif
if (readBackOrigin != backendDesc.fOrigin) {
ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, backendDesc.fOrigin);
}
REPORTER_ASSERT(reporter, readBackOrigin == backendDesc.fOrigin);
test_image_backed(reporter, srcImage);
}

View File

@ -740,8 +740,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
const int kHeight = 10;
std::unique_ptr<uint32_t[]> pixels(new uint32_t[kWidth * kHeight]);
GrBackendTextureDesc backendDesc;
backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
backendDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
backendDesc.fWidth = kWidth;
backendDesc.fHeight = kHeight;
backendDesc.fSampleCnt = 0;
@ -753,6 +754,23 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlphaType,
TextureReleaseChecker::Release, &releaseChecker));
GrSurfaceOrigin readBackOrigin;
GrBackendObject readBackHandle = refImg->getTextureHandle(false, &readBackOrigin);
// TODO: Make it so we can check this (see skbug.com/5019)
#if 0
if (*readBackHandle != *(backendDesc.fTextureHandle)) {
ERRORF(reporter, "backend mismatch %d %d\n",
(int)readBackHandle, (int)backendDesc.fTextureHandle);
}
REPORTER_ASSERT(reporter, readBackHandle == backendDesc.fTextureHandle);
#else
REPORTER_ASSERT(reporter, SkToBool(readBackHandle));
#endif
if (readBackOrigin != backendDesc.fOrigin) {
ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, backendDesc.fOrigin);
}
REPORTER_ASSERT(reporter, readBackOrigin == backendDesc.fOrigin);
// Now exercise the release proc
REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
refImg.reset(nullptr); // force a release of the image