From 3390e1526975e4250402e6642cd6875401abfc9e Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Tue, 31 Jan 2017 17:53:34 -0500 Subject: [PATCH] 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 Reviewed-by: Brian Salomon Commit-Queue: Robert Phillips --- include/core/SkImage.h | 5 ++++- src/image/SkImage.cpp | 14 ++++++++------ tests/ImageFilterCacheTest.cpp | 24 ++++++++++++++++++++++-- tests/ImageTest.cpp | 20 +++++++++++++++++++- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 076da331a2..2e421c90d1 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -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 diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 5eb69372bf..40586fd06d 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -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 diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp index 650d4cb3e8..393269adf6 100644 --- a/tests/ImageFilterCacheTest.cpp +++ b/tests/ImageFilterCacheTest.cpp @@ -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 srcImage(SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlphaType)); + sk_sp 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); } diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 66f19fa7ea..76ddd9600f 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -740,8 +740,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c const int kHeight = 10; std::unique_ptr 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