xref: /aosp_15_r20/external/skia/src/gpu/graphite/Texture.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2021 Google LLC
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 
8 #include "src/gpu/graphite/Texture.h"
9 
10 #include "include/core/SkTraceMemoryDump.h"
11 #include "include/gpu/MutableTextureState.h"
12 #include "src/gpu/RefCntedCallback.h"
13 #include "src/gpu/graphite/Caps.h"
14 #include "src/gpu/graphite/SharedContext.h"
15 #include "src/gpu/graphite/TextureUtils.h"
16 
17 namespace skgpu::graphite {
18 
Texture(const SharedContext * sharedContext,SkISize dimensions,const TextureInfo & info,sk_sp<MutableTextureState> mutableState,Ownership ownership,skgpu::Budgeted budgeted)19 Texture::Texture(const SharedContext* sharedContext,
20                  SkISize dimensions,
21                  const TextureInfo& info,
22                  sk_sp<MutableTextureState> mutableState,
23                  Ownership ownership,
24                  skgpu::Budgeted budgeted)
25         : Resource(sharedContext, ownership, budgeted, ComputeSize(dimensions, info))
26         , fDimensions(dimensions)
27         , fInfo(info)
28         , fMutableState(std::move(mutableState)) {}
29 
30 Texture::~Texture() = default;
31 
setReleaseCallback(sk_sp<RefCntedCallback> releaseCallback)32 void Texture::setReleaseCallback(sk_sp<RefCntedCallback> releaseCallback) {
33     fReleaseCallback = std::move(releaseCallback);
34 }
35 
invokeReleaseProc()36 void Texture::invokeReleaseProc() {
37     if (fReleaseCallback) {
38         // Depending on the ref count of fReleaseCallback this may or may not actually trigger
39         // the ReleaseProc to be called.
40         fReleaseCallback.reset();
41     }
42 }
43 
mutableState() const44 MutableTextureState* Texture::mutableState() const { return fMutableState.get(); }
45 
onDumpMemoryStatistics(SkTraceMemoryDump * traceMemoryDump,const char * dumpName) const46 void Texture::onDumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump,
47                                      const char* dumpName) const {
48     SkString dimensionsStr;
49     dimensionsStr.printf("(%dx%d)", fDimensions.width(), fDimensions.height());
50     traceMemoryDump->dumpStringValue(dumpName, "dimensions", dimensionsStr.c_str());
51     traceMemoryDump->dumpStringValue(dumpName, "textureInfo", fInfo.toString().c_str());
52 }
53 
54 } // namespace skgpu::graphite
55