skia2/tests/TraceMemoryDumpTest.cpp

179 lines
6.5 KiB
C++
Raw Normal View History

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTraceMemoryDump.h"
#include "Test.h"
#include "GrContextPriv.h"
#include "GrRenderTarget.h"
#include "GrTexture.h"
#include "gl/GrGLBuffer.h"
#include "gl/GrGLDefines.h"
#include "gl/GrGLGpu.h"
/*
* Build test for SkTraceMemoryDump.
*/
class TestSkTraceMemoryDump : public SkTraceMemoryDump {
public:
TestSkTraceMemoryDump(bool shouldDumpWrappedObjects)
: fShouldDumpWrappedObjects(shouldDumpWrappedObjects) {}
~TestSkTraceMemoryDump() override { }
void dumpNumericValue(const char* dumpName, const char* valueName, const char* units,
uint64_t value) override {
// Only count "size" dumps, others are just providing metadata.
if (SkString("size") == SkString(valueName)) {
++fNumDumpedObjects;
fDumpedObjectsSize += value;
}
}
void setMemoryBacking(const char* dumpName, const char* backingType,
const char* backingObjectId) override { }
void setDiscardableMemoryBacking(
const char* dumpName,
const SkDiscardableMemory& discardableMemoryObject) override { }
LevelOfDetail getRequestedDetails() const override {
return SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail;
}
bool shouldDumpWrappedObjects() const override { return fShouldDumpWrappedObjects; }
size_t numDumpedObjects() const { return fNumDumpedObjects; }
size_t dumpedObjectsSize() const { return fDumpedObjectsSize; }
private:
bool fShouldDumpWrappedObjects;
size_t fNumDumpedObjects = 0;
size_t fDumpedObjectsSize = 0;
};
void ValidateMemoryDumps(skiatest::Reporter* reporter, GrContext* context, size_t size,
bool isOwned) {
// Note than one entry in the dumped objects is expected for the text blob cache.
TestSkTraceMemoryDump dump_with_wrapped(true /* shouldDumpWrappedObjects */);
context->dumpMemoryStatistics(&dump_with_wrapped);
REPORTER_ASSERT(reporter, 2 == dump_with_wrapped.numDumpedObjects());
REPORTER_ASSERT(reporter, size == dump_with_wrapped.dumpedObjectsSize());
TestSkTraceMemoryDump dump_no_wrapped(false /* shouldDumpWrappedObjects */);
context->dumpMemoryStatistics(&dump_no_wrapped);
if (isOwned) {
REPORTER_ASSERT(reporter, 2 == dump_no_wrapped.numDumpedObjects());
REPORTER_ASSERT(reporter, size == dump_no_wrapped.dumpedObjectsSize());
} else {
REPORTER_ASSERT(reporter, 1 == dump_no_wrapped.numDumpedObjects());
REPORTER_ASSERT(reporter, 0 == dump_no_wrapped.dumpedObjectsSize());
}
}
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLBuffer, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->contextPriv().getGpu());
const size_t kMemorySize = 1024;
sk_sp<GrGLBuffer> buffer(
GrGLBuffer::Create(gpu, kMemorySize, kVertex_GrBufferType, kDynamic_GrAccessPattern));
ValidateMemoryDumps(reporter, context, kMemorySize, true /* isOwned */);
}
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTexture, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->contextPriv().getGpu());
GrSurfaceDesc desc;
desc.fFlags = kNone_GrSurfaceFlags;
desc.fWidth = 64;
desc.fHeight = 64;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fSampleCnt = 1;
GrGLTextureInfo glInfo;
glInfo.fTarget = GR_GL_TEXTURE_2D;
glInfo.fID = 7; // Arbitrary, we don't actually use the texture.
glInfo.fFormat = GR_GL_RGBA8;
GrGLTexture::IDDesc idDesc;
idDesc.fInfo = glInfo;
idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
auto texture = sk_make_sp<GrGLTexture>(gpu, SkBudgeted::kNo, desc, idDesc,
GrMipMapsStatus::kNotAllocated);
ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), true /* isOwned */);
}
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLTexture, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->contextPriv().getGpu());
GrSurfaceDesc desc;
desc.fFlags = kNone_GrSurfaceFlags;
desc.fWidth = 64;
desc.fHeight = 64;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fSampleCnt = 1;
GrGLTextureInfo glInfo;
glInfo.fTarget = GR_GL_TEXTURE_2D;
glInfo.fID = 7; // Arbitrary, we don't actually use the texture.
glInfo.fFormat = GR_GL_RGBA8;
GrGLTexture::IDDesc idDesc;
idDesc.fInfo = glInfo;
idDesc.fOwnership = GrBackendObjectOwnership::kBorrowed;
auto texture = GrGLTexture::MakeWrapped(gpu, desc, GrMipMapsStatus::kNotAllocated, idDesc,
false);
ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), false /* isOwned */);
}
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLRenderTarget, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->contextPriv().getGpu());
GrSurfaceDesc sd;
sd.fFlags = kRenderTarget_GrSurfaceFlag;
sd.fWidth = 64;
sd.fHeight = 64;
sd.fConfig = kRGBA_8888_GrPixelConfig;
GrGLRenderTarget::IDDesc iddesc;
iddesc.fRTFBOID = 20;
iddesc.fRTFBOOwnership = GrBackendObjectOwnership::kOwned;
iddesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
iddesc.fMSColorRenderbufferID = 22;
iddesc.fIsMixedSampled = false;
Revert "Reland "Have a GrBackendFormat be stored on gpu proxies."" This reverts commit 2f9a5ea639925f38785f4d3a0af237822007cfd6. Reason for revert: breaking fuchsia Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com Change-Id: Ia0556355e5775b2100901b7bfa37f97bb6ccd90f No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: chromium:903701 chromium:903756 Reviewed-on: https://skia-review.googlesource.com/c/171002 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-14 15:28:10 +00:00
sk_sp<GrGLRenderTarget> rt = GrGLRenderTarget::MakeWrapped(gpu, sd, iddesc, 0);
ValidateMemoryDumps(reporter, context, rt->gpuMemorySize(), true /* isOwned */);
}
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLRenderTarget, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->contextPriv().getGpu());
GrSurfaceDesc sd;
sd.fFlags = kRenderTarget_GrSurfaceFlag;
sd.fWidth = 64;
sd.fHeight = 64;
sd.fConfig = kRGBA_8888_GrPixelConfig;
GrGLRenderTarget::IDDesc iddesc;
iddesc.fRTFBOID = 20;
iddesc.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed;
iddesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
iddesc.fMSColorRenderbufferID = 22;
iddesc.fIsMixedSampled = false;
Revert "Reland "Have a GrBackendFormat be stored on gpu proxies."" This reverts commit 2f9a5ea639925f38785f4d3a0af237822007cfd6. Reason for revert: breaking fuchsia Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com Change-Id: Ia0556355e5775b2100901b7bfa37f97bb6ccd90f No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: chromium:903701 chromium:903756 Reviewed-on: https://skia-review.googlesource.com/c/171002 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-14 15:28:10 +00:00
sk_sp<GrGLRenderTarget> rt = GrGLRenderTarget::MakeWrapped(gpu, sd, iddesc, 0);
ValidateMemoryDumps(reporter, context, rt->gpuMemorySize(), false /* isOwned */);
}