primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTraceMemoryDump.h" |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/GrTexture.h" |
| 13 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/gl/GrGLBuffer.h" |
| 16 | #include "src/gpu/gl/GrGLDefines.h" |
| 17 | #include "src/gpu/gl/GrGLGpu.h" |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 18 | |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 19 | /* |
| 20 | * Build test for SkTraceMemoryDump. |
| 21 | */ |
| 22 | class TestSkTraceMemoryDump : public SkTraceMemoryDump { |
| 23 | public: |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 24 | TestSkTraceMemoryDump(bool shouldDumpWrappedObjects) |
| 25 | : fShouldDumpWrappedObjects(shouldDumpWrappedObjects) {} |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 26 | ~TestSkTraceMemoryDump() override { } |
| 27 | |
| 28 | void dumpNumericValue(const char* dumpName, const char* valueName, const char* units, |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 29 | uint64_t value) override { |
| 30 | // Only count "size" dumps, others are just providing metadata. |
| 31 | if (SkString("size") == SkString(valueName)) { |
| 32 | ++fNumDumpedObjects; |
| 33 | fDumpedObjectsSize += value; |
| 34 | } |
| 35 | } |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 36 | void setMemoryBacking(const char* dumpName, const char* backingType, |
| 37 | const char* backingObjectId) override { } |
| 38 | void setDiscardableMemoryBacking( |
| 39 | const char* dumpName, |
| 40 | const SkDiscardableMemory& discardableMemoryObject) override { } |
ssid | f0c9865 | 2015-09-30 04:31:23 -0700 | [diff] [blame] | 41 | LevelOfDetail getRequestedDetails() const override { |
| 42 | return SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail; |
| 43 | } |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 44 | bool shouldDumpWrappedObjects() const override { return fShouldDumpWrappedObjects; } |
| 45 | |
| 46 | size_t numDumpedObjects() const { return fNumDumpedObjects; } |
| 47 | size_t dumpedObjectsSize() const { return fDumpedObjectsSize; } |
| 48 | |
| 49 | private: |
| 50 | bool fShouldDumpWrappedObjects; |
| 51 | size_t fNumDumpedObjects = 0; |
| 52 | size_t fDumpedObjectsSize = 0; |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 55 | void ValidateMemoryDumps(skiatest::Reporter* reporter, GrContext* context, size_t size, |
| 56 | bool isOwned) { |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 57 | // Note than one entry in the dumped objects is expected for the text blob cache. |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 58 | TestSkTraceMemoryDump dump_with_wrapped(true /* shouldDumpWrappedObjects */); |
| 59 | context->dumpMemoryStatistics(&dump_with_wrapped); |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 60 | REPORTER_ASSERT(reporter, 2 == dump_with_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, size == dump_with_wrapped.dumpedObjectsSize()); |
| 62 | |
| 63 | TestSkTraceMemoryDump dump_no_wrapped(false /* shouldDumpWrappedObjects */); |
| 64 | context->dumpMemoryStatistics(&dump_no_wrapped); |
| 65 | if (isOwned) { |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 66 | REPORTER_ASSERT(reporter, 2 == dump_no_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, size == dump_no_wrapped.dumpedObjectsSize()); |
| 68 | } else { |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 69 | REPORTER_ASSERT(reporter, 1 == dump_no_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 70 | REPORTER_ASSERT(reporter, 0 == dump_no_wrapped.dumpedObjectsSize()); |
ssid | f0c9865 | 2015-09-30 04:31:23 -0700 | [diff] [blame] | 71 | } |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 72 | } |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 73 | |
| 74 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLBuffer, reporter, ctxInfo) { |
| 75 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 76 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 77 | const size_t kMemorySize = 1024; |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 78 | sk_sp<GrGLBuffer> buffer = |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 79 | GrGLBuffer::Make(gpu, kMemorySize, GrGpuBufferType::kVertex, kDynamic_GrAccessPattern); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 80 | |
| 81 | ValidateMemoryDumps(reporter, context, kMemorySize, true /* isOwned */); |
| 82 | } |
| 83 | |
| 84 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTexture, reporter, ctxInfo) { |
| 85 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 86 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 87 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 88 | GrGLTexture::Desc desc; |
| 89 | desc.fTarget = GR_GL_TEXTURE_2D; |
| 90 | desc.fID = 7; // Arbitrary, we don't actually use the texture. |
| 91 | desc.fFormat = GrGLFormat::kRGBA8; |
| 92 | desc.fOwnership = GrBackendObjectOwnership::kOwned; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 93 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 94 | desc.fSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 95 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 96 | auto texture = |
| 97 | sk_make_sp<GrGLTexture>(gpu, SkBudgeted::kNo, desc, GrMipMapsStatus::kNotAllocated); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 98 | |
| 99 | ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), true /* isOwned */); |
| 100 | } |
| 101 | |
| 102 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLTexture, reporter, ctxInfo) { |
| 103 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 104 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 105 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 106 | GrGLTexture::Desc desc; |
| 107 | desc.fTarget = GR_GL_TEXTURE_2D; |
| 108 | desc.fID = 7; // Arbitrary, we don't actually use the texture. |
| 109 | desc.fFormat = GrGLFormat::kRGBA8; |
| 110 | desc.fOwnership = GrBackendObjectOwnership::kBorrowed; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 111 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 112 | desc.fSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 113 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 114 | auto params = sk_make_sp<GrGLTextureParameters>(); |
| 115 | |
| 116 | auto texture = |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 117 | GrGLTexture::MakeWrapped(gpu, GrMipMapsStatus::kNotAllocated, desc, std::move(params), |
| 118 | GrWrapCacheable::kNo, kRead_GrIOType); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 119 | |
| 120 | ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), false /* isOwned */); |
| 121 | } |
| 122 | |
| 123 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLRenderTarget, reporter, ctxInfo) { |
| 124 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 125 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 126 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 127 | static constexpr auto kSize = SkISize::Make(64, 64); |
| 128 | static constexpr auto kConfig = kRGBA_8888_GrPixelConfig; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 129 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 130 | GrGLRenderTarget::IDs rtIDs; |
| 131 | rtIDs.fRTFBOID = 20; |
| 132 | rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kOwned; |
| 133 | rtIDs.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 134 | rtIDs.fMSColorRenderbufferID = 22; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 135 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 136 | sk_sp<GrGLRenderTarget> rt = |
| 137 | GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, kConfig, 1, rtIDs, 0); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 138 | |
| 139 | ValidateMemoryDumps(reporter, context, rt->gpuMemorySize(), true /* isOwned */); |
| 140 | } |
| 141 | |
| 142 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLRenderTarget, reporter, ctxInfo) { |
| 143 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 144 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 145 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 146 | static constexpr auto kSize = SkISize::Make(64, 64); |
| 147 | static constexpr auto kConfig = kRGBA_8888_GrPixelConfig; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 148 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 149 | GrGLRenderTarget::IDs rtIDs; |
| 150 | rtIDs.fRTFBOID = 20; |
| 151 | rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed; |
| 152 | rtIDs.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 153 | rtIDs.fMSColorRenderbufferID = 22; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 154 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 155 | sk_sp<GrGLRenderTarget> rt = |
| 156 | GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, kConfig, 1, rtIDs, 0); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 157 | |
| 158 | ValidateMemoryDumps(reporter, context, rt->gpuMemorySize(), false /* isOwned */); |
| 159 | } |