Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ResourceProvider.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_ResourceProvider_DEFINED
9#define skgpu_graphite_ResourceProvider_DEFINED
10
11#include "include/core/SkSize.h"
13#include "src/core/SkLRUCache.h"
14#include "src/gpu/ResourceKey.h"
18
19struct AHardwareBuffer;
22
23namespace skgpu {
24class SingleOwner;
25}
26
27namespace SkSL {
28 class Compiler;
29}
30
31namespace skgpu::graphite {
32
33class BackendTexture;
34class Buffer;
35class Caps;
36class ComputePipeline;
37class ComputePipelineDesc;
38class GlobalCache;
39class GraphicsPipeline;
40class GraphicsPipelineDesc;
41class GraphiteResourceKey;
42class ResourceCache;
43class RuntimeEffectDictionary;
44class ShaderCodeDictionary;
45class Sampler;
46class SharedContext;
47class Texture;
48class TextureInfo;
49
51public:
52 virtual ~ResourceProvider();
53
54 // The runtime effect dictionary provides a link between SkCodeSnippetIds referenced in the
55 // paint key and the current SkRuntimeEffect that provides the SkSL for that id.
58 const RenderPassDesc&);
59
61
63 const TextureInfo&,
64 std::string_view label,
66
67 sk_sp<Texture> createWrappedTexture(const BackendTexture&, std::string_view label);
68
70 const TextureInfo&);
71
73 const TextureInfo&);
74
78 std::string_view label);
79
81
84
85 ProxyCache* proxyCache() { return fResourceCache->proxyCache(); }
86
87 size_t getResourceCacheLimit() const { return fResourceCache->getMaxBudget(); }
89 return fResourceCache->currentBudgetedBytes();
90 }
91
92 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
93 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
94 }
95
96 void freeGpuResources();
97 void purgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime);
98
99#if defined(GRAPHITE_TEST_UTILS)
100 ResourceCache* resourceCache() { return fResourceCache.get(); }
101 const SharedContext* sharedContext() { return fSharedContext; }
102#endif
103
104#ifdef SK_BUILD_FOR_ANDROID
105 virtual BackendTexture createBackendTexture(AHardwareBuffer*,
106 bool isRenderable,
107 bool isProtectedContent,
108 SkISize dimensions,
109 bool fromAndroidWindow) const;
110#endif
111
112protected:
113 ResourceProvider(SharedContext* sharedContext,
114 SingleOwner* singleOwner,
115 uint32_t recorderID,
116 size_t resourceBudget);
117
119 // Each ResourceProvider owns one local cache; for some resources it also refers out to the
120 // global cache of the SharedContext, which is assumed to outlive the ResourceProvider.
122
123private:
126 const RenderPassDesc&) = 0;
129 const TextureInfo&,
130 skgpu::Budgeted) = 0;
133
134 sk_sp<Texture> findOrCreateTextureWithKey(SkISize dimensions,
135 const TextureInfo& info,
137 std::string_view label,
139
141
143#ifdef SK_BUILD_FOR_ANDROID
145 bool isRenderable,
146 bool isProtectedContent,
147 SkISize dimensions,
148 bool fromAndroidWindow) const;
149#endif
150 virtual void onDeleteBackendTexture(const BackendTexture&) = 0;
151};
152
153} // namespace skgpu::graphite
154
155#endif // skgpu_graphite_ResourceProvider_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
struct AHardwareBuffer AHardwareBuffer
GLenum type
sk_sp< GraphicsPipeline > findOrCreateGraphicsPipeline(const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &)
sk_sp< Texture > findOrCreateDiscardableMSAAAttachment(SkISize dimensions, const TextureInfo &)
sk_sp< ComputePipeline > findOrCreateComputePipeline(const ComputePipelineDesc &)
virtual sk_sp< Sampler > createSampler(const SamplerDesc &)=0
void purgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime)
virtual sk_sp< Buffer > createBuffer(size_t size, BufferType type, AccessPattern)=0
sk_sp< Texture > createWrappedTexture(const BackendTexture &, std::string_view label)
virtual sk_sp< Texture > onCreateWrappedTexture(const BackendTexture &)=0
sk_sp< Texture > findOrCreateScratchTexture(SkISize, const TextureInfo &, std::string_view label, skgpu::Budgeted)
virtual BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo &)=0
ResourceProvider(SharedContext *sharedContext, SingleOwner *singleOwner, uint32_t recorderID, size_t resourceBudget)
sk_sp< Sampler > findOrCreateCompatibleSampler(const SamplerDesc &)
BackendTexture createBackendTexture(SkISize dimensions, const TextureInfo &)
sk_sp< Texture > findOrCreateDepthStencilAttachment(SkISize dimensions, const TextureInfo &)
void deleteBackendTexture(const BackendTexture &)
virtual sk_sp< GraphicsPipeline > createGraphicsPipeline(const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &)=0
virtual void onDeleteBackendTexture(const BackendTexture &)=0
virtual sk_sp< Texture > createTexture(SkISize, const TextureInfo &, skgpu::Budgeted)=0
sk_sp< Buffer > findOrCreateBuffer(size_t size, BufferType type, AccessPattern, std::string_view label)
sk_sp< ResourceCache > fResourceCache
size_t getResourceCacheCurrentBudgetedBytes() const
void dumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump) const
virtual sk_sp< ComputePipeline > createComputePipeline(const ComputePipelineDesc &)=0
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...
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
Definition: GpuTools.h:21
Budgeted
Definition: GpuTypes.h:35
Definition: SkSize.h:16