Flutter Engine
The Flutter Engine
ProxyCache.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 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_ProxyCache_DEFINED
9#define skgpu_graphite_ProxyCache_DEFINED
10
13#include "src/core/SkTHash.h"
15#include "src/gpu/ResourceKey.h"
16
17class SkBitmap;
18
19namespace skgpu {
20 enum class Mipmapped : bool;
21 class UniqueKey;
22}
23
24namespace skgpu::graphite {
25
26class Recorder;
27class TextureProxy;
28
29// This class encapsulates the _internal_ Recorder-local caching of utility proxies.
30// For simplicity it does not support generating mipmapped cached proxies. Internal utility data
31// does not typically require mipmapping, and unlike Ganesh, the internal proxy cache is not used
32// for uploaded client-provided bitmaps (which may require generating mipmaps).
34public:
35 ProxyCache(uint32_t recorderID);
37
39 const SkBitmap&,
40 std::string_view label);
41
42 // Find or create a cached TextureProxy that's associated with an externally managed UniqueKey.
43 // If there is not a cached proxy available, the bitmap generator function will be called with
44 // the provided context argument. The successfully generated bitmap is then uploaded to a
45 // a new texture proxy on the Recorder and cached. If the bitmap generation fails, null is
46 // returned.
47 //
48 // The texture proxy's label defaults to the tag of the unique key if not otherwise provided.
49 using BitmapGeneratorContext = const void*;
52 const UniqueKey& key,
55 std::string_view label = {});
56
57 void purgeAll();
58
59#if defined(GRAPHITE_TEST_UTILS)
60 int numCached() const;
62 void forceProcessInvalidKeyMsgs();
63 void forceFreeUniquelyHeld();
64 void forcePurgeProxiesNotUsedSince(skgpu::StdSteadyClock::time_point purgeTime);
65#endif
66
67private:
68 friend class ResourceCache; // for freeUniquelyHeld
69
70 void processInvalidKeyMsgs();
71 void freeUniquelyHeld();
72 void purgeProxiesNotUsedSince(const skgpu::StdSteadyClock::time_point* purgeTime);
73 struct UniqueKeyHash {
74 uint32_t operator()(const UniqueKey& key) const;
75 };
76
79};
80
81} // namespace skgpu::graphite
82
83#endif // skgpu_graphite_ProxyCache_DEFINED
int find(T *array, int N, T item)
SkBitmap(*)(BitmapGeneratorContext) BitmapGeneratorFn
Definition: ProxyCache.h:50
sk_sp< TextureProxy > findOrCreateCachedProxy(Recorder *, const SkBitmap &, std::string_view label)
Definition: ProxyCache.cpp:74
ProxyCache(uint32_t recorderID)
Definition: ProxyCache.cpp:64
const void * BitmapGeneratorContext
Definition: ProxyCache.h:49
Definition: GpuTools.h:21
Mipmapped
Definition: GpuTypes.h:53