Flutter Engine
The Flutter Engine
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,
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,
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;
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
Definition: FontMgrTest.cpp:39
#define GR_GL_TEXTURE_2D
Definition: GrGLDefines.h:152
@ kRead_GrIOType
Definition: GrTypesPriv.h:403
@ kDynamic_GrAccessPattern
Definition: GrTypesPriv.h:426
#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)
Definition: GrGLBuffer.cpp:31
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
const EmbeddedViewParams * params
uint8_t value
constexpr int kSize
FlTexture * texture
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
GrBackendObjectOwnership fRTFBOOwnership
skgpu::Protected fIsProtected
Definition: GrGLTexture.h:28
GrBackendObjectOwnership fOwnership
Definition: GrGLTexture.h:27
GrGLenum fTarget
Definition: GrGLTexture.h:24
GrGLFormat fFormat
Definition: GrGLTexture.h:26
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20