2015-08-20 15:00:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTraceMemoryDump.h"
|
2015-08-20 15:00:32 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2015-08-20 15:00:32 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrRenderTarget.h"
|
|
|
|
#include "include/gpu/GrTexture.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/gl/GrGLBuffer.h"
|
|
|
|
#include "src/gpu/gl/GrGLDefines.h"
|
|
|
|
#include "src/gpu/gl/GrGLGpu.h"
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2015-08-20 15:00:32 +00:00
|
|
|
/*
|
|
|
|
* Build test for SkTraceMemoryDump.
|
|
|
|
*/
|
|
|
|
class TestSkTraceMemoryDump : public SkTraceMemoryDump {
|
|
|
|
public:
|
2018-03-19 20:04:03 +00:00
|
|
|
TestSkTraceMemoryDump(bool shouldDumpWrappedObjects)
|
|
|
|
: fShouldDumpWrappedObjects(shouldDumpWrappedObjects) {}
|
2015-08-20 15:00:32 +00:00
|
|
|
~TestSkTraceMemoryDump() override { }
|
|
|
|
|
|
|
|
void dumpNumericValue(const char* dumpName, const char* valueName, const char* units,
|
2018-03-19 20:04:03 +00:00
|
|
|
uint64_t value) override {
|
|
|
|
// Only count "size" dumps, others are just providing metadata.
|
|
|
|
if (SkString("size") == SkString(valueName)) {
|
|
|
|
++fNumDumpedObjects;
|
|
|
|
fDumpedObjectsSize += value;
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 15:00:32 +00:00
|
|
|
void setMemoryBacking(const char* dumpName, const char* backingType,
|
|
|
|
const char* backingObjectId) override { }
|
|
|
|
void setDiscardableMemoryBacking(
|
|
|
|
const char* dumpName,
|
|
|
|
const SkDiscardableMemory& discardableMemoryObject) override { }
|
2015-09-30 11:31:23 +00:00
|
|
|
LevelOfDetail getRequestedDetails() const override {
|
|
|
|
return SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail;
|
|
|
|
}
|
2018-03-19 20:04:03 +00:00
|
|
|
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;
|
2015-08-20 15:00:32 +00:00
|
|
|
};
|
|
|
|
|
2018-03-19 20:04:03 +00:00
|
|
|
void ValidateMemoryDumps(skiatest::Reporter* reporter, GrContext* context, size_t size,
|
|
|
|
bool isOwned) {
|
2018-10-29 20:05:36 +00:00
|
|
|
// Note than one entry in the dumped objects is expected for the text blob cache.
|
2018-03-19 20:04:03 +00:00
|
|
|
TestSkTraceMemoryDump dump_with_wrapped(true /* shouldDumpWrappedObjects */);
|
|
|
|
context->dumpMemoryStatistics(&dump_with_wrapped);
|
2018-10-29 20:05:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == dump_with_wrapped.numDumpedObjects());
|
2018-03-19 20:04:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, size == dump_with_wrapped.dumpedObjectsSize());
|
|
|
|
|
|
|
|
TestSkTraceMemoryDump dump_no_wrapped(false /* shouldDumpWrappedObjects */);
|
|
|
|
context->dumpMemoryStatistics(&dump_no_wrapped);
|
|
|
|
if (isOwned) {
|
2018-10-29 20:05:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == dump_no_wrapped.numDumpedObjects());
|
2018-03-19 20:04:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, size == dump_no_wrapped.dumpedObjectsSize());
|
|
|
|
} else {
|
2018-10-29 20:05:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == dump_no_wrapped.numDumpedObjects());
|
2018-03-19 20:04:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == dump_no_wrapped.dumpedObjectsSize());
|
2015-09-30 11:31:23 +00:00
|
|
|
}
|
2015-08-20 15:00:32 +00:00
|
|
|
}
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLBuffer, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
const size_t kMemorySize = 1024;
|
2019-01-29 19:38:50 +00:00
|
|
|
sk_sp<GrGLBuffer> buffer =
|
2019-02-05 14:41:37 +00:00
|
|
|
GrGLBuffer::Make(gpu, kMemorySize, GrGpuBufferType::kVertex, kDynamic_GrAccessPattern);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
ValidateMemoryDumps(reporter, context, kMemorySize, true /* isOwned */);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTexture, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
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();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
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;
|
|
|
|
|
2019-06-04 19:58:31 +00:00
|
|
|
auto params = sk_make_sp<GrGLTextureParameters>();
|
|
|
|
|
|
|
|
auto texture =
|
|
|
|
GrGLTexture::MakeWrapped(gpu, desc, GrMipMapsStatus::kNotAllocated, idDesc,
|
|
|
|
std::move(params), GrWrapCacheable::kNo, kRead_GrIOType);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), false /* isOwned */);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLRenderTarget, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc sd;
|
|
|
|
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;
|
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
sk_sp<GrGLRenderTarget> rt = GrGLRenderTarget::MakeWrapped(gpu, sd, GR_GL_RGBA8, iddesc, 0);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
ValidateMemoryDumps(reporter, context, rt->gpuMemorySize(), true /* isOwned */);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLRenderTarget, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc sd;
|
|
|
|
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;
|
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
sk_sp<GrGLRenderTarget> rt = GrGLRenderTarget::MakeWrapped(gpu, sd, GR_GL_RGBA8, iddesc, 0);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
|
|
|
ValidateMemoryDumps(reporter, context, rt->gpuMemorySize(), false /* isOwned */);
|
|
|
|
}
|