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"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.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 "src/gpu/GrContextPriv.h"
|
2019-08-14 21:00:30 +00:00
|
|
|
#include "src/gpu/GrRenderTarget.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-11-08 21:18:15 +00:00
|
|
|
#ifdef SK_GL
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/gl/GrGLBuffer.h"
|
|
|
|
#include "src/gpu/gl/GrGLDefines.h"
|
|
|
|
#include "src/gpu/gl/GrGLGpu.h"
|
2019-11-08 21:18:15 +00:00
|
|
|
#endif
|
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
|
|
|
};
|
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
void ValidateMemoryDumps(skiatest::Reporter* reporter, GrDirectContext* dContext, size_t size,
|
2018-03-19 20:04:03 +00:00
|
|
|
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 */);
|
2020-07-23 13:41:57 +00:00
|
|
|
dContext->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 */);
|
2020-07-23 13:41:57 +00:00
|
|
|
dContext->dumpMemoryStatistics(&dump_no_wrapped);
|
2018-03-19 20:04:03 +00:00
|
|
|
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
|
|
|
|
2019-11-08 21:18:15 +00:00
|
|
|
#ifdef SK_GL
|
2018-03-19 20:04:03 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLBuffer, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->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
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, kMemorySize, true /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTexture, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
GrGLTexture::Desc desc;
|
|
|
|
desc.fTarget = GR_GL_TEXTURE_2D;
|
|
|
|
desc.fID = 7; // Arbitrary, we don't actually use the texture.
|
|
|
|
desc.fFormat = GrGLFormat::kRGBA8;
|
|
|
|
desc.fOwnership = GrBackendObjectOwnership::kOwned;
|
|
|
|
desc.fSize = SkISize::Make(64, 64);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
auto texture =
|
2020-07-21 13:56:23 +00:00
|
|
|
sk_make_sp<GrGLTexture>(gpu, SkBudgeted::kNo, desc, GrMipmapStatus::kNotAllocated);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, texture->gpuMemorySize(), true /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLTexture, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
GrGLTexture::Desc desc;
|
|
|
|
desc.fTarget = GR_GL_TEXTURE_2D;
|
|
|
|
desc.fID = 7; // Arbitrary, we don't actually use the texture.
|
|
|
|
desc.fFormat = GrGLFormat::kRGBA8;
|
|
|
|
desc.fOwnership = GrBackendObjectOwnership::kBorrowed;
|
|
|
|
desc.fSize = SkISize::Make(64, 64);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-06-04 19:58:31 +00:00
|
|
|
auto params = sk_make_sp<GrGLTextureParameters>();
|
|
|
|
|
|
|
|
auto texture =
|
2020-07-21 13:56:23 +00:00
|
|
|
GrGLTexture::MakeWrapped(gpu, GrMipmapStatus::kNotAllocated, desc, std::move(params),
|
2019-08-07 17:04:55 +00:00
|
|
|
GrWrapCacheable::kNo, kRead_GrIOType);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, texture->gpuMemorySize(), false /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLRenderTarget, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
static constexpr auto kSize = SkISize::Make(64, 64);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
GrGLRenderTarget::IDs rtIDs;
|
|
|
|
rtIDs.fRTFBOID = 20;
|
|
|
|
rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kOwned;
|
|
|
|
rtIDs.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
|
|
|
|
rtIDs.fMSColorRenderbufferID = 22;
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
sk_sp<GrGLRenderTarget> rt =
|
2020-01-22 21:53:38 +00:00
|
|
|
GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, 1, rtIDs, 0);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, rt->gpuMemorySize(), true /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLRenderTarget, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
static constexpr auto kSize = SkISize::Make(64, 64);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
GrGLRenderTarget::IDs rtIDs;
|
|
|
|
rtIDs.fRTFBOID = 20;
|
|
|
|
rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed;
|
|
|
|
rtIDs.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
|
|
|
|
rtIDs.fMSColorRenderbufferID = 22;
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
sk_sp<GrGLRenderTarget> rt =
|
2020-01-22 21:53:38 +00:00
|
|
|
GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, 1, rtIDs, 0);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, rt->gpuMemorySize(), false /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
2019-11-08 21:18:15 +00:00
|
|
|
#endif // SK_GL
|