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

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

Issue 1810323002: Cache render targets that render to wrapped textures Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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
Index: src/gpu/gl/GrGLRenderTarget.cpp
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index d4585f6402f926441d3893b632c1c1ebcaafe005..cc4abac5017f0ef486fc9ae209f1c86b92768348 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -17,28 +17,26 @@
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu,
+ SkBudgeted budgeted,
const GrSurfaceDesc& desc,
const IDDesc& idDesc,
GrGLStencilAttachment* stencil)
- : GrSurface(gpu, idDesc.fLifeCycle, desc)
- , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig, stencil) {
- this->init(desc, idDesc);
+ : GrSurface(gpu, budgeted, desc)
+ , INHERITED(gpu, budgeted, desc, idDesc.fSampleConfig, stencil)
+ , fIDDesc(idDesc) {
+ this->init(desc);
this->registerWithCache();
}
-GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
- Derived)
- : GrSurface(gpu, idDesc.fLifeCycle, desc)
- , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) {
- this->init(desc, idDesc);
+GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
+ const IDDesc& idDesc, Derived)
+ : GrSurface(gpu, budgeted, desc)
+ , INHERITED(gpu, budgeted, desc, idDesc.fSampleConfig)
+ , fIDDesc(idDesc) {
+ this->init(desc);
}
-void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
- fRTFBOID = idDesc.fRTFBOID;
- fTexFBOID = idDesc.fTexFBOID;
- fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID;
- fRTLifecycle = idDesc.fLifeCycle;
-
+void GrGLRenderTarget::init(const GrSurfaceDesc& desc) {
fViewport.fLeft = 0;
fViewport.fBottom = 0;
fViewport.fWidth = desc.fWidth;
@@ -47,9 +45,12 @@ void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
fGpuMemorySize = this->totalSamples() * this->totalBytesPerSample();
SkASSERT(fGpuMemorySize <= WorseCaseSize(desc));
+ SkASSERT(GrBackendObjectLifeCycle::kBorrowed == fIDDesc.fTexLifeCycle ||
+ GrBackendObjectLifeCycle::kAdopted == fIDDesc.fTexLifeCycle);
}
GrGLRenderTarget* GrGLRenderTarget::CreateWrapped(GrGLGpu* gpu,
+ SkBudgeted budgeted,
const GrSurfaceDesc& desc,
const IDDesc& idDesc,
int stencilBits) {
@@ -65,7 +66,7 @@ GrGLRenderTarget* GrGLRenderTarget::CreateWrapped(GrGLGpu* gpu,
sb = new GrGLStencilAttachment(gpu, sbDesc, desc.fWidth, desc.fHeight,
desc.fSampleCnt, format);
}
- return (new GrGLRenderTarget(gpu, desc, idDesc, sb));
+ return (new GrGLRenderTarget(gpu, budgeted, desc, idDesc, sb));
}
size_t GrGLRenderTarget::onGpuMemorySize() const {
@@ -119,60 +120,97 @@ bool GrGLRenderTarget::completeStencilAttachment() {
}
void GrGLRenderTarget::onRelease() {
- if (kBorrowed_LifeCycle != fRTLifecycle) {
- if (fTexFBOID) {
- GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
+ if (GrBackendObjectLifeCycle::kBorrowed != fIDDesc.fRTFBOLifeCycle) {
+ GrGLuint fbos[2] = {0,};
+ GrGLint i = 0;
+ if (fIDDesc.fTexFBOID) {
+ fbos[i] = fIDDesc.fTexFBOID;
+ i++;
+ }
+ if (fIDDesc.fRTFBOID && fIDDesc.fRTFBOID != fIDDesc.fTexFBOID) {
+ fbos[i] = fIDDesc.fRTFBOID;
+ i++;
+ }
+ if (i > 0) {
+ GL_CALL(DeleteFramebuffers(i, fbos));
}
- if (fRTFBOID && fRTFBOID != fTexFBOID) {
- GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
+ if (fIDDesc.fMSColorRenderbufferID) {
+ GL_CALL(DeleteRenderbuffers(1, &fIDDesc.fMSColorRenderbufferID));
}
- if (fMSColorRenderbufferID) {
- GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
+ if (GrBackendObjectLifeCycle::kBorrowed != fIDDesc.fTexLifeCycle && fIDDesc.fTexID) {
+ GL_CALL(DeleteTextures(1, &fIDDesc.fTexID));
}
+ } else {
+ SkASSERT(fIDDesc.fTexID == 0);
+ SkASSERT(fIDDesc.fTexFBOID == 0);
+ SkASSERT(fIDDesc.fMSColorRenderbufferID == 0);
}
- fRTFBOID = 0;
- fTexFBOID = 0;
- fMSColorRenderbufferID = 0;
+
+ fIDDesc.fRTFBOID = 0;
+ fIDDesc.fTexFBOID = 0;
+ fIDDesc.fTexID = 0;
+ fIDDesc.fMSColorRenderbufferID = 0;
INHERITED::onRelease();
}
void GrGLRenderTarget::onAbandon() {
- fRTFBOID = 0;
- fTexFBOID = 0;
- fMSColorRenderbufferID = 0;
+ fIDDesc.fRTFBOID = 0;
+ fIDDesc.fTexFBOID = 0;
+ fIDDesc.fTexID = 0;
+ fIDDesc.fMSColorRenderbufferID = 0;
INHERITED::onAbandon();
}
+bool GrGLRenderTarget::refsWrappedResources() const {
+ // Instances of GrGLRenderTarget wrap external resources.
+ // Internal render targets override this.
+ return true;
+}
+
GrGLGpu* GrGLRenderTarget::getGLGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrGLGpu*>(this->getGpu());
}
void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
- // Don't log the backing texture's contribution to the memory size. This will be handled by the
- // texture object.
-
- // Log any renderbuffer's contribution to memory. We only do this if we own the renderbuffer
- // (have a fMSColorRenderbufferID).
- if (fMSColorRenderbufferID) {
- size_t size = this->msaaSamples() * this->totalBytesPerSample();
-
- // Due to this resource having both a texture and a renderbuffer component, dump as
- // skia/gpu_resources/resource_#/renderbuffer
- SkString dumpName("skia/gpu_resources/resource_");
- dumpName.appendS32(this->getUniqueID());
- dumpName.append("/renderbuffer");
-
- traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size);
-
- if (this->isPurgeable()) {
- traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size", "bytes", size);
+ // Due to this resource having both a texture and a renderbuffer component, dump as
+ // skia/gpu_resources/resource_#/renderbuffer
+ // skia/gpu_resources/resource_#/texture
+ if (GrBackendObjectLifeCycle::kBorrowed != fIDDesc.fRTFBOLifeCycle) {
+ if (fIDDesc.fRTFBOID && fIDDesc.fTexFBOID != fIDDesc.fRTFBOID) {
+ size_t size = fDesc.fSampleCnt * this->totalBytesPerSample();
+
+ SkString dumpName("skia/gpu_resources/resource_");
+ dumpName.appendS32(this->getUniqueID());
+ dumpName.append("/renderbuffer");
+
+ traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size);
+
+ if (this->isPurgeable()) {
+ traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size", "bytes", size);
+ }
+
+ SkString renderbuffer_id;
+ renderbuffer_id.appendU32(fIDDesc.fMSColorRenderbufferID);
+ traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_renderbuffer",
+ renderbuffer_id.c_str());
+ }
+ }
+ if (GrBackendObjectLifeCycle::kBorrowed != fIDDesc.fTexLifeCycle) {
+ if (fIDDesc.fTexID) {
+ size_t size = this->totalBytesPerSample();
+ SkString dumpName("skia/gpu_resources/resource_");
+ dumpName.appendS32(this->getUniqueID());
+ dumpName.append("/texture");
+ traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size);
+ if (this->isPurgeable()) {
+ traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size", "bytes", size);
+ }
+ SkString texID;
+ texID.appendU32(fIDDesc.fTexID);
+ traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
+ texID.c_str());
}
-
- SkString renderbuffer_id;
- renderbuffer_id.appendU32(fMSColorRenderbufferID);
- traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_renderbuffer",
- renderbuffer_id.c_str());
}
}
@@ -185,25 +223,18 @@ size_t GrGLRenderTarget::totalBytesPerSample() const {
return fDesc.fWidth * fDesc.fHeight * colorBytes;
}
-int GrGLRenderTarget::msaaSamples() const {
- if (fTexFBOID == kUnresolvableFBOID || fTexFBOID != fRTFBOID) {
- // If the render target's FBO is external (fTexFBOID == kUnresolvableFBOID), or if we own
- // the render target's FBO (fTexFBOID == fRTFBOID) then we use the provided sample count.
- return SkTMax(1, fDesc.fSampleCnt);
- }
-
- // When fTexFBOID == fRTFBOID, we either are not using MSAA, or MSAA is auto resolving, so use
- // 0 for the sample count.
- return 0;
-}
-
int GrGLRenderTarget::totalSamples() const {
- int total_samples = this->msaaSamples();
-
- if (fTexFBOID != kUnresolvableFBOID) {
- // If we own the resolve buffer then that is one more sample per pixel.
- total_samples += 1;
- }
-
- return total_samples;
+ int total_samples = 0;
+ if (GrBackendObjectLifeCycle::kBorrowed != fIDDesc.fRTFBOLifeCycle) {
+ if (fIDDesc.fRTFBOID && fIDDesc.fTexFBOID != fIDDesc.fRTFBOID) {
+ SkASSERT(this->isUnifiedMultisampled());
+ total_samples += fDesc.fSampleCnt;
+ }
+ }
+ if (GrBackendObjectLifeCycle::kBorrowed != fIDDesc.fTexLifeCycle) {
+ if (fIDDesc.fTexFBOID) {
+ total_samples += 1;
+ }
+ }
+ return total_samples;
}

Powered by Google App Engine
This is Rietveld 408576698