Flutter Engine
The Flutter Engine
AtlasProvider.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_AtlasProvider_DEFINED
9#define skgpu_graphite_AtlasProvider_DEFINED
10
15
16#include <memory>
17#include <unordered_map>
18
19namespace skgpu::graphite {
20
21class Caps;
22class ComputePathAtlas;
23class DrawContext;
24class PathAtlas;
25class RasterPathAtlas;
26class Recorder;
27class TextAtlasManager;
28class TextureProxy;
29
30/**
31 * AtlasProvider groups various texture atlas management algorithms together.
32 */
33class AtlasProvider final {
34public:
35 enum class PathAtlasFlags : unsigned {
36 kNone = 0b000,
37 // ComputePathAtlas is supported
38 kCompute = 0b001,
39 // RasterPathAtlas is supported
40 kRaster = 0b010,
41 };
44
45 // Query the supported path atlas algorithms based on device capabilities.
47
48 explicit AtlasProvider(Recorder*);
50
51 // Returns the TextAtlasManager that provides access to persistent DrawAtlas instances used in
52 // glyph rendering. This TextAtlasManager is always available.
53 TextAtlasManager* textAtlasManager() const { return fTextAtlasManager.get(); }
54
55 // Returns whether a particular atlas type is available. Currently PathAtlasFlags::kRaster is
56 // always supported.
57 bool isAvailable(PathAtlasFlags atlasType) const {
58 return SkToBool(fPathAtlasFlags & atlasType);
59 }
60
61 // Creates a new transient atlas handler that uses compute shaders to rasterize coverage masks
62 // for path rendering. This method returns nullptr if compute shaders are not supported by the
63 // owning Recorder's context.
64 std::unique_ptr<ComputePathAtlas> createComputePathAtlas(Recorder* recorder) const;
65
66 // Gets the atlas handler that uses the CPU raster pipeline to create coverage masks
67 // for path rendering.
69
70 // Return a TextureProxy with the given dimensions and color type.
72 Recorder*, uint16_t width, uint16_t height, SkColorType, uint16_t identifier,
73 bool requireStorageUsage);
74
75 void clearTexturePool();
76
77 // Push any pending uploads to atlases onto the draw context
79
80 // Handle any post-flush work (garbage collection, e.g.)
81 void postFlush();
82
83private:
84 std::unique_ptr<TextAtlasManager> fTextAtlasManager;
85
86 // Accumulates atlas coverage masks generated by software rendering that are required by one or
87 // more entries in `fPendingDraws`. During the snapUploadTask step, prior to pending draws
88 // being snapped into a new DrawPass, any necessary uploads into an atlas texture are recorded
89 // for the accumulated masks. The accumulated masks are then cleared which frees up the atlas
90 // for future draws.
91 //
92 // TODO: We should not clear all accumulated masks but cache masks over more than one frame.
93 //
94 // TODO: We may need a method to generate raster-generated masks in separate threads prior to
95 // upload.
96 std::unique_ptr<RasterPathAtlas> fRasterPathAtlas;
97
98 // Allocated and cached texture proxies shared by all PathAtlas instances. It is possible for
99 // the same texture to be bound to multiple DispatchGroups and DrawPasses across flushes. The
100 // owning Recorder must guarantee that any uploads or compute dispatches are scheduled to remain
101 // coherent across flushes.
102 // TODO: This requirement might change with a more sophisticated reuse scheme for texture
103 // allocations. For now our model is simple: all PathAtlases target the same texture and only
104 // one of them will render to the texture during a given command submission.
105 std::unordered_map<uint64_t, sk_sp<TextureProxy>> fTexturePool;
106
108};
109
111
112} // namespace skgpu::graphite
113
114#endif // skgpu_graphite_AtlasProvider_DEFINED
SkColorType
Definition: SkColorType.h:19
#define SK_DECL_BITMASK_OPS_FRIENDS(E)
Definition: SkEnumBitMask.h:82
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
bool isAvailable(PathAtlasFlags atlasType) const
Definition: AtlasProvider.h:57
static PathAtlasFlagsBitMask QueryPathAtlasSupport(const Caps *)
sk_sp< TextureProxy > getAtlasTexture(Recorder *, uint16_t width, uint16_t height, SkColorType, uint16_t identifier, bool requireStorageUsage)
TextAtlasManager * textAtlasManager() const
Definition: AtlasProvider.h:53
void recordUploads(DrawContext *)
std::unique_ptr< ComputePathAtlas > createComputePathAtlas(Recorder *recorder) const
SkEnumBitMask< PathAtlasFlags > PathAtlasFlagsBitMask
Definition: AtlasProvider.h:43
RasterPathAtlas * getRasterPathAtlas() const
static SkString identifier(const FontFamilyDesc &family, const FontDesc &font)
@ kRaster
Suitable for thread which raster data.
Definition: embedder.h:266
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By default
Definition: switches.h:183
SK_MAKE_BITMASK_OPS(DawnErrorType)
int32_t height
int32_t width