Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 Texture;
26
27class TextureProxy : public SkRefCnt {
28public:
29 TextureProxy() = delete;
30
31 ~TextureProxy() override;
32
33 int numSamples() const { return fInfo.numSamples(); }
34 Mipmapped mipmapped() const { return fInfo.mipmapped(); }
35
36 SkISize dimensions() const;
37 const TextureInfo& textureInfo() const { return fInfo; }
38
39 bool isLazy() const;
40 bool isFullyLazy() const;
41 bool isVolatile() const;
42 bool isProtected() const;
43
44 size_t uninstantiatedGpuMemorySize() const;
45
47 /*
48 * We currently only instantiate lazy proxies at insertion-time. Snap-time 'instantiate'
49 * calls should be wrapped in 'InstantiateIfNotLazy'.
50 *
51 * Unlike Ganesh, in Graphite we do not update the proxy's dimensions with the instantiating
52 * texture's dimensions. This means that when a fully-lazy proxy is instantiated and
53 * deinstantiated, it goes back to being fully-lazy and without dimensions, and can be
54 * re-instantiated with a new texture with different dimensions than the first.
55 */
57 /*
58 * For Lazy proxies this will return true. Otherwise, it will return the result of
59 * calling instantiate on the texture proxy.
60 */
62 bool isInstantiated() const { return SkToBool(fTexture); }
63 void deinstantiate();
65 const Texture* texture() const;
66 Texture* texture() { return fTexture.get(); }
67
68 // Make() will immediately instantiate non-budgeted proxies.
69 static sk_sp<TextureProxy> Make(const Caps*,
72 const TextureInfo&,
74
75 using LazyInstantiateCallback = std::function<sk_sp<Texture> (ResourceProvider*)>;
76
77 static sk_sp<TextureProxy> MakeLazy(const Caps*,
79 const TextureInfo&,
87
89
90private:
93 const TextureInfo&,
98
99#ifdef SK_DEBUG
100 void validateTexture(const Texture*);
101#endif
102
103 // In the following, 'fVolatile' and 'fLazyInstantiateCallback' can be accessed from
104 // multiple threads so need to remain immutable.
105 SkISize fDimensions;
106 const TextureInfo fInfo;
107
108 skgpu::Budgeted fBudgeted;
109 const Volatile fVolatile;
110
111 sk_sp<Texture> fTexture;
112
113 const LazyInstantiateCallback fLazyInstantiateCallback;
114};
115
116// Volatile texture proxy that deinstantiates itself on destruction.
118public:
119 AutoDeinstantiateTextureProxy(TextureProxy* textureProxy) : fTextureProxy(textureProxy) {}
120
122 if (fTextureProxy) {
123 fTextureProxy->deinstantiate();
124 }
125 }
126
127private:
128 TextureProxy* const fTextureProxy;
129};
130
131} // namespace skgpu::graphite
132
133#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
Type::kYUV Type::kRGBA() int(0.7 *637)
AutoDeinstantiateTextureProxy(TextureProxy *textureProxy)
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
static sk_sp< TextureProxy > Make(const Caps *, ResourceProvider *, SkISize dimensions, const TextureInfo &, skgpu::Budgeted)
Mipmapped mipmapped() const
const TextureInfo & textureInfo() const
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
GrSamplerState::WrapMode Wrap