Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TraceMemoryDumpTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9#if defined(SK_GL)
11#include "include/core/SkSize.h"
27#include "tests/Test.h"
28
29#include <cstddef>
30#include <cstdint>
31#include <utility>
32
34struct GrContextOptions;
35
36/*
37 * Build test for SkTraceMemoryDump.
38 */
39class TestSkTraceMemoryDump : public SkTraceMemoryDump {
40public:
41 TestSkTraceMemoryDump(bool shouldDumpWrappedObjects)
42 : fShouldDumpWrappedObjects(shouldDumpWrappedObjects) {}
43 ~TestSkTraceMemoryDump() override { }
44
45 void dumpNumericValue(const char* dumpName, const char* valueName, const char* units,
46 uint64_t value) override {
47 // Only count "size" dumps, others are just providing metadata.
48 if (SkString("size") == SkString(valueName)) {
49 ++fNumDumpedObjects;
50 fDumpedObjectsSize += value;
51 }
52 }
53 void setMemoryBacking(const char* dumpName, const char* backingType,
54 const char* backingObjectId) override { }
56 const char* dumpName,
57 const SkDiscardableMemory& discardableMemoryObject) override { }
58 LevelOfDetail getRequestedDetails() const override {
60 }
61 bool shouldDumpWrappedObjects() const override { return fShouldDumpWrappedObjects; }
62
63 size_t numDumpedObjects() const { return fNumDumpedObjects; }
64 size_t dumpedObjectsSize() const { return fDumpedObjectsSize; }
65
66private:
67 bool fShouldDumpWrappedObjects;
68 size_t fNumDumpedObjects = 0;
69 size_t fDumpedObjectsSize = 0;
70};
71
72void ValidateMemoryDumps(skiatest::Reporter* reporter, GrDirectContext* dContext,
73 size_t numDumpedObjects, size_t size, bool isOwned) {
74 // Note than one entry in the dumped objects is expected for the text blob cache.
75 TestSkTraceMemoryDump dump_with_wrapped(true /* shouldDumpWrappedObjects */);
76 dContext->dumpMemoryStatistics(&dump_with_wrapped);
77 REPORTER_ASSERT(reporter, numDumpedObjects == dump_with_wrapped.numDumpedObjects());
78 REPORTER_ASSERT(reporter, size == dump_with_wrapped.dumpedObjectsSize());
79
80 TestSkTraceMemoryDump dump_no_wrapped(false /* shouldDumpWrappedObjects */);
81 dContext->dumpMemoryStatistics(&dump_no_wrapped);
82 if (isOwned) {
83 REPORTER_ASSERT(reporter, numDumpedObjects == dump_no_wrapped.numDumpedObjects());
84 REPORTER_ASSERT(reporter, size == dump_no_wrapped.dumpedObjectsSize());
85 } else {
86 REPORTER_ASSERT(reporter, 1 == dump_no_wrapped.numDumpedObjects());
87 REPORTER_ASSERT(reporter, 0 == dump_no_wrapped.dumpedObjectsSize());
88 }
89}
90
91DEF_GANESH_TEST_FOR_GL_CONTEXT(SkTraceMemoryDump_ownedGLBuffer,
93 ctxInfo,
95 auto dContext = ctxInfo.directContext();
96 GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
97 const size_t kMemorySize = 1024;
100
101 ValidateMemoryDumps(reporter, dContext, 2, kMemorySize, true /* isOwned */);
102}
103
104DEF_GANESH_TEST_FOR_GL_CONTEXT(SkTraceMemoryDump_ownedGLTexture,
105 reporter,
106 ctxInfo,
108 auto dContext = ctxInfo.directContext();
109 GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
110
112 desc.fTarget = GR_GL_TEXTURE_2D;
113 desc.fID = 7; // Arbitrary, we don't actually use the texture.
114 desc.fFormat = GrGLFormat::kRGBA8;
116 desc.fIsProtected = skgpu::Protected::kNo;
117 desc.fSize = SkISize::Make(64, 64);
118
119 auto texture = sk_make_sp<GrGLTexture>(gpu,
121 desc,
123 /*label=*/"SkTraceMemoryDump_ownedGLTexture");
124
125 ValidateMemoryDumps(reporter, dContext, 2, texture->gpuMemorySize(), true /* isOwned */);
126}
127
128DEF_GANESH_TEST_FOR_GL_CONTEXT(SkTraceMemoryDump_unownedGLTexture,
129 reporter,
130 ctxInfo,
132 auto dContext = ctxInfo.directContext();
133 GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
134
136 desc.fTarget = GR_GL_TEXTURE_2D;
137 desc.fID = 7; // Arbitrary, we don't actually use the texture.
138 desc.fFormat = GrGLFormat::kRGBA8;
140 desc.fSize = SkISize::Make(64, 64);
141 desc.fIsProtected = skgpu::Protected::kNo;
142
143 auto params = sk_make_sp<GrGLTextureParameters>();
144
147 desc,
148 std::move(params),
151 /*label=*/{});
152
153 ValidateMemoryDumps(reporter, dContext, 2, texture->gpuMemorySize(), false /* isOwned */);
154}
155
156DEF_GANESH_TEST_FOR_GL_CONTEXT(SkTraceMemoryDump_ownedGLRenderTarget,
157 reporter,
158 ctxInfo,
160 auto dContext = ctxInfo.directContext();
161 GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
162
163 static constexpr auto kSize = SkISize::Make(64, 64);
164
166 rtIDs.fMultisampleFBOID = 0;
168 rtIDs.fSingleSampleFBOID = 20;
169 rtIDs.fMSColorRenderbufferID = 0;
171
173 kSize,
175 1,
176 rtIDs,
177 0,
178 skgpu::Protected::kNo,
179 /*label=*/{});
180
181 ValidateMemoryDumps(reporter, dContext, 2, rt->gpuMemorySize(), true /* isOwned */);
182}
183
184DEF_GANESH_TEST_FOR_GL_CONTEXT(SkTraceMemoryDump_unownedGLRenderTarget,
185 reporter,
186 ctxInfo,
188 auto dContext = ctxInfo.directContext();
189 GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
190
191 static constexpr auto kSize = SkISize::Make(64, 64);
192
194 rtIDs.fMultisampleFBOID = 12;
196 rtIDs.fSingleSampleFBOID = 0;
197 rtIDs.fMSColorRenderbufferID = 0;
199
201 kSize,
203 4,
204 rtIDs,
205 0,
206 skgpu::Protected::kNo,
207 /*label=*/{});
208
209 ValidateMemoryDumps(reporter, dContext, 2, rt->gpuMemorySize(), false /* isOwned */);
210}
211
212DEF_GANESH_TEST_FOR_GL_CONTEXT(SkTraceMemoryDump_ownedGLTextureRenderTarget,
213 reporter,
214 ctxInfo,
216 auto dContext = ctxInfo.directContext();
217 GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
218
219 static constexpr auto kSize = SkISize::Make(64, 64);
220
221 GrGLTexture::Desc texDesc;
222 texDesc.fSize = kSize;
223 texDesc.fTarget = GR_GL_TEXTURE_2D;
224 texDesc.fID = 17;
225 texDesc.fFormat = GrGLFormat::kRGBA8;
227 texDesc.fIsProtected = skgpu::Protected::kNo;
228
230 rtIDs.fMultisampleFBOID = 12;
232 rtIDs.fSingleSampleFBOID = 20;
233 rtIDs.fMSColorRenderbufferID = 22;
235
236 auto texRT = sk_make_sp<GrGLTextureRenderTarget>(
237 gpu,
239 8,
240 texDesc,
241 rtIDs,
243 /*label=*/"SkTraceMemoryDump_ownedGLTextureRenderTarget");
244
245 ValidateMemoryDumps(reporter, dContext, 3, texRT->gpuMemorySize(), true /* isOwned */);
246}
247
248#endif // defined(SK_GL)
reporter
#define GR_GL_TEXTURE_2D
@ kRead_GrIOType
@ kDynamic_GrAccessPattern
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GANESH_TEST_FOR_GL_CONTEXT(name, reporter, context_info, ctsEnforcement)
Definition Test.h:442
void dumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump) const
GrDirectContextPriv priv()
static sk_sp< GrGLBuffer > Make(GrGLGpu *, size_t size, GrGpuBufferType intendedType, GrAccessPattern)
static sk_sp< GrGLRenderTarget > MakeWrapped(GrGLGpu *, const SkISize &, GrGLFormat, int sampleCount, const IDs &, int stencilBits, skgpu::Protected, std::string_view label)
static sk_sp< GrGLTexture > MakeWrapped(GrGLGpu *, GrMipmapStatus, const Desc &, sk_sp< GrGLTextureParameters >, GrWrapCacheable, GrIOType, std::string_view label)
virtual void setMemoryBacking(const char *dumpName, const char *backingType, const char *backingObjectId)=0
virtual void setDiscardableMemoryBacking(const char *dumpName, const SkDiscardableMemory &discardableMemoryObject)=0
virtual LevelOfDetail getRequestedDetails() const =0
virtual bool shouldDumpWrappedObjects() const
virtual void dumpNumericValue(const char *dumpName, const char *valueName, const char *units, uint64_t value)=0
static constexpr int kSize
const EmbeddedViewParams * params
static const uint8_t buffer[]
uint8_t value
FlTexture * texture
GrBackendObjectOwnership fRTFBOOwnership
skgpu::Protected fIsProtected
Definition GrGLTexture.h:28
GrBackendObjectOwnership fOwnership
Definition GrGLTexture.h:27
GrGLFormat fFormat
Definition GrGLTexture.h:26
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20