Flutter Engine
The Flutter Engine
TextureProxy.h
Go to the documentation of this file.
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#ifndef skgpu_graphite_TextureProxy_DEFINED
9#define skgpu_graphite_TextureProxy_DEFINED
10
12#include "include/core/SkSize.h"
15
16#include <functional>
17
18enum SkColorType : int;
19
20namespace skgpu::graphite {
21
22class Caps;
23class Recorder;
25class ScratchResourceManager;
26class Texture;
27
28class TextureProxy : public SkRefCnt {
29public:
30 TextureProxy() = delete;
31
32 ~TextureProxy() override;
33
34 int numSamples() const { return fInfo.numSamples(); }
35 Mipmapped mipmapped() const { return fInfo.mipmapped(); }
36
37 SkISize dimensions() const;
38 const TextureInfo& textureInfo() const { return fInfo; }
39
40 const char* label() const { return fLabel.c_str(); }
41
42 bool isLazy() const;
43 bool isFullyLazy() const;
44 bool isVolatile() const;
45 bool isProtected() const;
46
47 size_t uninstantiatedGpuMemorySize() const;
48
50 /*
51 * We currently only instantiate lazy proxies at insertion-time. Snap-time 'instantiate'
52 * calls should be wrapped in 'InstantiateIfNotLazy'.
53 *
54 * Unlike Ganesh, in Graphite we do not update the proxy's dimensions with the instantiating
55 * texture's dimensions. This means that when a fully-lazy proxy is instantiated and
56 * deinstantiated, it goes back to being fully-lazy and without dimensions, and can be
57 * re-instantiated with a new texture with different dimensions than the first.
58 */
60 /*
61 * For Lazy proxies this will return true. Otherwise, it will return the result of
62 * calling instantiate on the texture proxy.
63 *
64 * DEPRECATED: Eventually all un-instantiated non-lazy proxies should use the
65 * ScratchResourceManager function instead of the ResourceProvider directly.
66 */
68
69 /*
70 * Instantiate any scratch proxy (not already instantiated and not lazy) by using a texture
71 * from the ScratchResourceManager. When possible, this will be a texture that has been returned
72 * for reuse by a prior task. Lazy proxies and already instantiated proxies will return true.
73 *
74 * False is returned if instantiation fails.
75 */
77
78 bool isInstantiated() const { return SkToBool(fTexture); }
79 void deinstantiate();
81 const Texture* texture() const;
82 Texture* texture() { return fTexture.get(); }
83
84 // Make() will immediately instantiate non-budgeted proxies.
85 static sk_sp<TextureProxy> Make(const Caps*,
88 const TextureInfo&,
89 std::string_view label,
91
92 using LazyInstantiateCallback = std::function<sk_sp<Texture> (ResourceProvider*)>;
93
94 static sk_sp<TextureProxy> MakeLazy(const Caps*,
96 const TextureInfo&,
102 Volatile,
104
106
107private:
109 const TextureInfo& info,
110 std::string_view label,
111 skgpu::Budgeted budgeted);
113 const TextureInfo&,
115 Volatile,
118
119#ifdef SK_DEBUG
120 void validateTexture(const Texture*);
121#endif
122
123 // In the following, 'fVolatile' and 'fLazyInstantiateCallback' can be accessed from
124 // multiple threads so need to remain immutable.
125 SkISize fDimensions;
126 const TextureInfo fInfo;
127
128 // String used to describe the current use of this TextureProxy. It will be set on its
129 // Texture object when the proxy gets instantiated.
130 std::string fLabel;
131
132 skgpu::Budgeted fBudgeted;
133 const Volatile fVolatile;
134
135 sk_sp<Texture> fTexture;
136
137 const LazyInstantiateCallback fLazyInstantiateCallback;
138};
139
140// Volatile texture proxy that deinstantiates itself on destruction.
142public:
143 AutoDeinstantiateTextureProxy(TextureProxy* textureProxy) : fTextureProxy(textureProxy) {}
144
146 if (fTextureProxy) {
147 fTextureProxy->deinstantiate();
148 }
149 }
150
151private:
152 TextureProxy* const fTextureProxy;
153};
154
155} // namespace skgpu::graphite
156
157#endif // skgpu_graphite_TextureProxy_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkColorType
Definition: SkColorType.h:19
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
AutoDeinstantiateTextureProxy(TextureProxy *textureProxy)
Definition: TextureProxy.h:143
Mipmapped mipmapped() const
Definition: TextureInfo.h:79
uint32_t numSamples() const
Definition: TextureInfo.h:78
bool lazyInstantiate(ResourceProvider *)
bool instantiate(ResourceProvider *)
static bool InstantiateIfNotLazy(ResourceProvider *, TextureProxy *)
std::function< sk_sp< Texture >(ResourceProvider *)> LazyInstantiateCallback
Definition: TextureProxy.h:92
static sk_sp< TextureProxy > Wrap(sk_sp< Texture >)
static sk_sp< TextureProxy > Make(const Caps *, ResourceProvider *, SkISize dimensions, const TextureInfo &, std::string_view label, skgpu::Budgeted)
const char * label() const
Definition: TextureProxy.h:40
Mipmapped mipmapped() const
Definition: TextureProxy.h:35
const TextureInfo & textureInfo() const
Definition: TextureProxy.h:38
sk_sp< Texture > refTexture() const
static sk_sp< TextureProxy > MakeFullyLazy(const TextureInfo &, skgpu::Budgeted, Volatile, LazyInstantiateCallback &&)
const Texture * texture() const
static sk_sp< TextureProxy > MakeLazy(const Caps *, SkISize dimensions, const TextureInfo &, skgpu::Budgeted, Volatile, LazyInstantiateCallback &&)
size_t uninstantiatedGpuMemorySize() const
Budgeted
Definition: GpuTypes.h:35
Mipmapped
Definition: GpuTypes.h:53
Definition: SkSize.h:16