From 56f970c87856f77c50a091486b28f5c4ed4b625b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BB=B7=E4=BD=B3java?= Date: Mon, 8 Sep 2025 10:55:00 +0800 Subject: [PATCH] cache small Texture on UnUni devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杜廷佳java --- m133/include/gpu/ganesh/GrContextOptions.h | 12 +++++++++++ m133/src/gpu/ganesh/GrTextureProxy.cpp | 24 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/m133/include/gpu/ganesh/GrContextOptions.h b/m133/include/gpu/ganesh/GrContextOptions.h index a83f71b4d5..d31b20542c 100644 --- a/m133/include/gpu/ganesh/GrContextOptions.h +++ b/m133/include/gpu/ganesh/GrContextOptions.h @@ -214,6 +214,18 @@ struct SK_API GrContextOptions { GrDriverBugWorkarounds fDriverBugWorkarounds; +#ifdef SKIA_OHOS + /** + * At the end of the frame, cleaning up each small-sized texture can help avoid frequent memory + * overruns and the issue of excessive time consumption during cleanup at the end of animations. + * However, enabling this feature will cause small textures to be redrawn every frame. If the te + * xture rendering on the current device is time-consuming, it is not recommended to enable this + * feature, as it may lead to performance issues. + */ + //OH ISSUE :cache small Texture on UnUni devices + bool clearSmallTexture = true; +#endif + /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap level control (ie desktop or ES3). */ diff --git a/m133/src/gpu/ganesh/GrTextureProxy.cpp b/m133/src/gpu/ganesh/GrTextureProxy.cpp index ba7f5bb31f..e7068a84c0 100644 --- a/m133/src/gpu/ganesh/GrTextureProxy.cpp +++ b/m133/src/gpu/ganesh/GrTextureProxy.cpp @@ -115,6 +115,29 @@ GrTextureProxy::~GrTextureProxy() { // message to (Note: in this case we don't want to remove its cached resource). if (fUniqueKey.isValid() && fProxyProvider) { sk_sp invalidGpuResource; +#ifdef SKIA_OHOS + //OH ISSUE :cache small Texture on UnUni devices + auto context = fProxyProvider->getfImageContext(); + bool clearSmallTexture = true; + if (context) { + clearSmallTexture = context->priv().options().clearSmallTexture; + auto direct = context->asDirectContext(); + if (direct) { + GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); + if (resourceProvider) { + invalidGpuResource = resourceProvider->findByUniqueKey(fUniqueKey); + } + } + } + // less than 1024 Bytes resources will be delated + if (invalidGpuResource && clearSmallTexture && invalidGpuResource->gpuMemorySize() < 1024) { + fProxyProvider->processInvalidUniqueKey( + fUniqueKey, this, GrProxyProvider::InvalidateGPUResource::kYes); + } else { + fProxyProvider->processInvalidUniqueKey( + fUniqueKey, this, GrProxyProvider::InvalidateGPUResource::kNo); + } +#else auto direct = fProxyProvider->getfImageContext()->asDirectContext(); if (direct) { GrResourceProvider* resourceProvider = direct->priv().resourceProvider(); @@ -130,6 +153,7 @@ GrTextureProxy::~GrTextureProxy() { fProxyProvider->processInvalidUniqueKey( fUniqueKey, this, GrProxyProvider::InvalidateGPUResource::kNo); } +#endif } else { SkASSERT(!fProxyProvider); } -- Gitee