diff options
author | Robert Phillips <robertphillips@google.com> | 2017-12-04 13:48:14 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-04 18:54:09 +0000 |
commit | 8d1e67ed6b75909ac20211ae3aec130587920cec (patch) | |
tree | 7132b299b0492ae8088f0160faccf06d2bf9878d | |
parent | 7d0cd9c3c6262db1a21d22b6ed82241f2463b5ec (diff) |
Add resource cache limits to SkSurfaceCharacterization
Change-Id: I4c3b2f1c6ecc39b2364cefae07d5dee5e3d20d60
Reviewed-on: https://skia-review.googlesource.com/79600
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
-rw-r--r-- | include/private/SkSurfaceCharacterization.h | 15 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 14 | ||||
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 15 | ||||
-rw-r--r-- | tests/DeferredDisplayListTest.cpp | 35 |
4 files changed, 70 insertions, 9 deletions
diff --git a/include/private/SkSurfaceCharacterization.h b/include/private/SkSurfaceCharacterization.h index f450b704d9..282043a879 100644 --- a/include/private/SkSurfaceCharacterization.h +++ b/include/private/SkSurfaceCharacterization.h @@ -27,7 +27,9 @@ class SkColorSpace; class SkSurfaceCharacterization { public: SkSurfaceCharacterization() - : fOrigin(kBottomLeft_GrSurfaceOrigin) + : fCacheMaxResourceCount(0) + , fCacheMaxResourceBytes(0) + , fOrigin(kBottomLeft_GrSurfaceOrigin) , fWidth(0) , fHeight(0) , fConfig(kUnknown_GrPixelConfig) @@ -43,6 +45,9 @@ public: SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default; GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); } + int cacheMaxResourceCount() const { return fCacheMaxResourceCount; } + size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; } + GrSurfaceOrigin origin() const { return fOrigin; } int width() const { return fWidth; } int height() const { return fHeight; } @@ -57,6 +62,8 @@ private: friend class SkSurface_Gpu; // for 'set' void set(sk_sp<GrContextThreadSafeProxy> contextInfo, + int cacheMaxResourceCount, + size_t cacheMaxResourceBytes, GrSurfaceOrigin origin, int width, int height, GrPixelConfig config, @@ -65,6 +72,9 @@ private: sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps& surfaceProps) { fContextInfo = contextInfo; + fCacheMaxResourceCount = cacheMaxResourceCount; + fCacheMaxResourceBytes = cacheMaxResourceBytes; + fOrigin = origin; fWidth = width; fHeight = height; @@ -76,6 +86,9 @@ private: } sk_sp<GrContextThreadSafeProxy> fContextInfo; + int fCacheMaxResourceCount; + size_t fCacheMaxResourceBytes; + GrSurfaceOrigin fOrigin; int fWidth; int fHeight; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 68cf42ef2a..2b185c4ebc 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -1022,19 +1022,19 @@ bool GrContext::validPMUPMConversionExists() { ////////////////////////////////////////////////////////////////////////////// -void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { +void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const { ASSERT_SINGLE_OWNER - if (maxTextures) { - *maxTextures = fResourceCache->getMaxResourceCount(); + if (maxResources) { + *maxResources = fResourceCache->getMaxResourceCount(); } - if (maxTextureBytes) { - *maxTextureBytes = fResourceCache->getMaxResourceBytes(); + if (maxResourceBytes) { + *maxResourceBytes = fResourceCache->getMaxResourceBytes(); } } -void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { +void GrContext::setResourceCacheLimits(int maxResources, size_t maxResourceBytes) { ASSERT_SINGLE_OWNER - fResourceCache->setLimits(maxTextures, maxTextureBytes); + fResourceCache->setLimits(maxResources, maxResourceBytes); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index dc1f308512..fc66e43e6c 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -164,7 +164,12 @@ bool SkSurface_Gpu::onCharacterize(SkSurfaceCharacterization* data) const { GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); GrContext* ctx = fDevice->context(); - data->set(ctx->threadSafeProxy(), rtc->origin(), rtc->width(), rtc->height(), + int maxResourceCount; + size_t maxResourceBytes; + ctx->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); + + data->set(ctx->threadSafeProxy(), maxResourceCount, maxResourceBytes, + rtc->origin(), rtc->width(), rtc->height(), rtc->colorSpaceInfo().config(), rtc->fsaaType(), rtc->numStencilSamples(), rtc->colorSpaceInfo().refColorSpace(), this->props()); @@ -175,7 +180,15 @@ bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& data) const { GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); GrContext* ctx = fDevice->context(); + // As long as the current state if the context allows for greater or equal resources, + // we allow the DDL to be replayed. + int maxResourceCount; + size_t maxResourceBytes; + ctx->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); + return data.contextInfo() && data.contextInfo()->matches(ctx) && + data.cacheMaxResourceCount() <= maxResourceCount && + data.cacheMaxResourceBytes() <= maxResourceBytes && data.origin() == rtc->origin() && data.width() == rtc->width() && data.height() == rtc->height() && data.config() == rtc->colorSpaceInfo().config() && data.fsaaType() == rtc->fsaaType() && data.stencilCount() == rtc->numStencilSamples() && diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp index b6839afa1a..fc9fbfed25 100644 --- a/tests/DeferredDisplayListTest.cpp +++ b/tests/DeferredDisplayListTest.cpp @@ -137,6 +137,41 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(SkSurfaceCharacterization, reporter, ctxInfo) { REPORTER_ASSERT(reporter, !s->draw(ddl.get())); } + + // Next test the compatibility of resource cache parameters + { + const SurfaceParameters params; + sk_sp<SkSurface> s = params.make(context); + + int maxResourceCount; + size_t maxResourceBytes; + context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); + + context->setResourceCacheLimits(maxResourceCount/2, maxResourceBytes); + REPORTER_ASSERT(reporter, !s->draw(ddl.get())); + + context->setResourceCacheLimits(maxResourceCount, maxResourceBytes/2); + REPORTER_ASSERT(reporter, !s->draw(ddl.get())); + + // resource limits >= those at characterization time are accepted + context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes); + REPORTER_ASSERT(reporter, s->draw(ddl.get())); + + context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes); + REPORTER_ASSERT(reporter, s->draw(ddl.get())); + + context->setResourceCacheLimits(maxResourceCount, maxResourceBytes); + REPORTER_ASSERT(reporter, s->draw(ddl.get())); + } + + // Make sure non-GPU-backed surfaces fail characterization + { + SkImageInfo ii = SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType); + + sk_sp<SkSurface> rasterSurface = SkSurface::MakeRaster(ii); + SkSurfaceCharacterization c; + REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c)); + } } #endif |