Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: src/gpu/gl/GrGLGpu.cpp

Issue 1810323002: Cache render targets that render to wrapped textures Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: moved the refactoring to another patch Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | tools/gpu/GrTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLGpu.cpp
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index b94991b6915f241918dd4baf541946da967b5d8a..1d53b49e092d06a57f62333718fbc1304348ef45 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -698,21 +698,19 @@ GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencilBits);
}
-GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) {
+static bool backend_texture_to_tex_info(const GrBackendTextureDesc& desc,
+ GrGLTextureInfo* outInfo) {
#ifdef SK_IGNORE_GL_TEXTURE_TARGET
if (!desc.fTextureHandle) {
- return nullptr;
+ return false;
}
#else
const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle);
if (!info || !info->fID) {
- return nullptr;
+ return false;
}
#endif
-
GrGLTextureInfo texInfo;
- GrSurfaceDesc surfDesc;
-
#ifdef SK_IGNORE_GL_TEXTURE_TARGET
texInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle);
// We only support GL_TEXTURE_2D at the moment.
@@ -726,9 +724,63 @@ GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu
// Only texture rectangle and texture 2d are supported. We do not check whether texture
// rectangle is supported by Skia - if the caller provided us with a texture rectangle,
// we assume the necessary support exists.
+ return false;
+ }
+ *outInfo = texInfo;
+ return true;
+}
+
+static void compute_backend_texture_key_for_wrap_as_render_target(const GrBackendTextureDesc& desc,
+ GrUniqueKey* key) {
+ GrGLTextureInfo texInfo;
+ if (!backend_texture_to_tex_info(desc, &texInfo)) {
+ return;
+ }
+ static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
+ GrUniqueKey::Builder builder(key, kDomain, 3);
+ builder[0] = desc.fWidth;
+ builder[1] = desc.fHeight;
+ builder[2] = desc.fConfig | (desc.fFlags << 5) | (desc.fSampleCnt << 6) | (desc.fOrigin << 14)
+ | ((texInfo.fTarget == GR_GL_TEXTURE_2D) << 16);
+ builder.finish();
+}
+
+void GrGLGpu::onComputeBackendTextureKeyForWrapAsRenderTarget(const GrBackendTextureDesc& desc,
+ GrUniqueKey* key) {
+ compute_backend_texture_key_for_wrap_as_render_target(desc, key);
+}
+
+bool GrGLGpu::onRewrapRenderTargetWithBackendTexture(const GrBackendTextureDesc& desc,
+ GrRenderTarget* rt) {
+ GrGLTextureInfo texInfo;
+ SkAssertResult(backend_texture_to_tex_info(desc, &texInfo));
+
+
+ GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(rt);
+ SkASSERT(glRT);
+ fStats.incRenderTargetBinds();
+ GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->textureFBOID()));
+ if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) {
+ GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER,
+ GR_GL_COLOR_ATTACHMENT0,
+ texInfo.fTarget,
+ texInfo.fID, 0, desc.fSampleCnt));
+ } else {
+ GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
+ GR_GL_COLOR_ATTACHMENT0,
+ texInfo.fTarget,
+ texInfo.fID, 0));
+ }
+ return true;
+}
+
+GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) {
+ GrGLTextureInfo texInfo;
+ if (!backend_texture_to_tex_info(desc, &texInfo)) {
return nullptr;
}
+ GrSurfaceDesc surfDesc;
surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags;
surfDesc.fWidth = desc.fWidth;
surfDesc.fHeight = desc.fHeight;
@@ -748,7 +800,11 @@ GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu
if (!this->createRenderTargetObjects(surfDesc, texInfo, &rtIDDesc)) {
return nullptr;
}
- return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0);
+ GrGLRenderTarget* rt = GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0);
+ GrUniqueKey key;
+ compute_backend_texture_key_for_wrap_as_render_target(desc, &key);
+ rt->resourcePriv().setUniqueKey(key);
+ return rt;
}
////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | tools/gpu/GrTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698