diff options
author | Eric Karl <ericrk@chromium.org> | 2018-03-19 13:04:03 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-19 20:37:25 +0000 |
commit | af7700265b74123d8ad3de6dde0c21545453140b (patch) | |
tree | e642696535d8ad9fa814bb9b3dde6c2f4e37a18a /src/gpu | |
parent | 72040d9d709a27b53bbce5f11ede02bfcf72dfdf (diff) |
Allow SkTraceMemoryDump to exclude wrapped objects
Allow SkTraceMemoryDump to exclude wrapped objects from dumps. This
helps avoid duplicate dumping when Skia is wrapping an external object
which is already dumped externally.
Bug: 795358
Change-Id: Icbda96b564c81b958d40f74693280ac7d5ba7332
Reviewed-on: https://skia-review.googlesource.com/114681
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Eric Karl <ericrk@chromium.org>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrGpuResource.cpp | 4 | ||||
-rw-r--r-- | src/gpu/gl/GrGLRenderTarget.cpp | 18 | ||||
-rw-r--r-- | src/gpu/gl/GrGLTexture.cpp | 40 | ||||
-rw-r--r-- | src/gpu/gl/GrGLTexture.h | 4 | ||||
-rw-r--r-- | src/gpu/gl/GrGLTextureRenderTarget.cpp | 28 |
5 files changed, 55 insertions, 39 deletions
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp index 3d3c88bbe2..d90498d6f4 100644 --- a/src/gpu/GrGpuResource.cpp +++ b/src/gpu/GrGpuResource.cpp @@ -69,6 +69,10 @@ void GrGpuResource::abandon() { } void GrGpuResource::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { + if (this->fRefsWrappedObjects && !traceMemoryDump->shouldDumpWrappedObjects()) { + return; + } + // Dump resource as "skia/gpu_resources/resource_#". SkString dumpName("skia/gpu_resources/resource_"); dumpName.appendU32(this->uniqueID().asUInt()); diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp index e1a4eb0bae..9500e7d6fe 100644 --- a/src/gpu/gl/GrGLRenderTarget.cpp +++ b/src/gpu/gl/GrGLRenderTarget.cpp @@ -195,11 +195,21 @@ bool GrGLRenderTarget::canAttemptStencilAttachment() const { } 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. + // Don't check this->fRefsWrappedObjects, as we might be the base of a GrGLTextureRenderTarget + // which is multiply inherited from both ourselves and a texture. In these cases, one part + // (texture, rt) may be wrapped, while the other is owned by Skia. + bool refsWrappedRenderTargetObjects = + this->fRTFBOOwnership == GrBackendObjectOwnership::kBorrowed; + if (refsWrappedRenderTargetObjects && !traceMemoryDump->shouldDumpWrappedObjects()) { + return; + } + + // Don't log the framebuffer, as the framebuffer itself doesn't contribute to meaningful + // memory usage. It is always a wrapper around either: + // - a texture, which is owned elsewhere, and will be dumped there + // - a renderbuffer, which will be dumped below. - // Log any renderbuffer's contribution to memory. We only do this if we own the renderbuffer - // (have a fMSColorRenderbufferID). + // Log any renderbuffer's contribution to memory. if (fMSColorRenderbufferID) { size_t size = GrSurface::ComputeSize(this->config(), this->width(), this->height(), this->msaaSamples(), GrMipMapped::kNo); diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp index 0f36dd0f32..5175ea88e7 100644 --- a/src/gpu/gl/GrGLTexture.cpp +++ b/src/gpu/gl/GrGLTexture.cpp @@ -101,14 +101,6 @@ GrBackendTexture GrGLTexture::getBackendTexture() const { return GrBackendTexture(this->width(), this->height(), this->texturePriv().mipMapped(), fInfo); } -void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, - const SkString& dumpName) const { - SkString texture_id; - texture_id.appendU32(this->textureID()); - traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", - texture_id.c_str()); -} - sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc) { return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, mipMapsStatus, idDesc)); @@ -126,3 +118,35 @@ bool GrGLTexture::onStealBackendTexture(GrBackendTexture* backendTexture, this->GrGLTexture::onAbandon(); return true; } + +void GrGLTexture::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { + // Don't check this->fRefsWrappedObjects, as we might be the base of a GrGLTextureRenderTarget + // which is multiply inherited from both ourselves and a texture. In these cases, one part + // (texture, rt) may be wrapped, while the other is owned by Skia. + bool refsWrappedTextureObjects = + this->fTextureIDOwnership == GrBackendObjectOwnership::kBorrowed; + if (refsWrappedTextureObjects && !traceMemoryDump->shouldDumpWrappedObjects()) { + return; + } + + // Dump as skia/gpu_resources/resource_#/texture, to avoid conflicts in the + // GrGLTextureRenderTarget case, where multiple things may dump to the same resource. This + // has no downside in the normal case. + SkString dumpName("skia/gpu_resources/resource_"); + dumpName.appendU32(this->uniqueID().asUInt()); + dumpName.append("/texture"); + + // As we are only dumping our texture memory (not any additional memory tracked by classes + // which may inherit from us), specifically call GrGLTexture::gpuMemorySize to avoid + // hitting an override. + size_t size = GrGLTexture::gpuMemorySize(); + traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size); + + if (this->isPurgeable()) { + traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size", "bytes", size); + } + + SkString texture_id; + texture_id.appendU32(this->textureID()); + traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", texture_id.c_str()); +} diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h index 2b10be8689..7da2bb4428 100644 --- a/src/gpu/gl/GrGLTexture.h +++ b/src/gpu/gl/GrGLTexture.h @@ -70,6 +70,8 @@ public: static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&); + void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; + protected: // Constructor for subclasses. GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus); @@ -82,8 +84,6 @@ protected: void onAbandon() override; void onRelease() override; - void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, - const SkString& dumpName) const override; bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override; diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp index 3e7b89f089..e9f224b71b 100644 --- a/src/gpu/gl/GrGLTextureRenderTarget.cpp +++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp @@ -35,33 +35,11 @@ GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu, this->registerWithCacheWrapped(); } -// GrGLTextureRenderTarget must dump both of its superclasses. void GrGLTextureRenderTarget::dumpMemoryStatistics( SkTraceMemoryDump* traceMemoryDump) const { - GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump); - - // Also dump the GrGLTexture's memory. Due to this resource having both a - // texture and a - // renderbuffer component, dump as skia/gpu_resources/resource_#/texture - SkString dumpName("skia/gpu_resources/resource_"); - dumpName.appendU32(this->uniqueID().asUInt()); - dumpName.append("/texture"); - - // Use the texture's gpuMemorySize, not our own, which includes the - // renderbuffer as well. - size_t size = GrGLTexture::gpuMemorySize(); - - traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size); - - if (this->isPurgeable()) { - traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size", - "bytes", size); - } - - SkString texture_id; - texture_id.appendU32(this->textureID()); - traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", - texture_id.c_str()); + // Delegate to the base classes + GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump); + GrGLTexture::dumpMemoryStatistics(traceMemoryDump); } bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const { |