Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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*);
49 ~AtlasProvider() = default;
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
56 bool isAvailable(PathAtlasFlags atlasType) const {
57 return SkToBool(fPathAtlasFlags & atlasType);
58 }
59
60 // Creates a new transient atlas handler that uses compute shaders to rasterize coverage masks
61 // for path rendering. This method returns nullptr if compute shaders are not supported by the
62 // owning Recorder's context.
63 std::unique_ptr<ComputePathAtlas> createComputePathAtlas(Recorder* recorder) const;
64
65 // Gets the atlas handler that uses the CPU raster pipeline to create coverage masks
66 // for path rendering.
68
69 // Return a TextureProxy with the given dimensions and color type.
71 Recorder*, uint16_t width, uint16_t height, SkColorType, uint16_t identifier,
72 bool requireStorageUsage);
73
74 void clearTexturePool();
75
76 // Push any pending uploads to atlases onto the draw context
78
79 // Handle any post-flush work (garbage collection, e.g.)
80 void postFlush();
81
82private:
83 std::unique_ptr<TextAtlasManager> fTextAtlasManager;
84
85 // Accumulates atlas coverage masks generated by software rendering that are required by one or
86 // more entries in `fPendingDraws`. During the snapUploadTask step, prior to pending draws
87 // being snapped into a new DrawPass, any necessary uploads into an atlas texture are recorded
88 // for the accumulated masks. The accumulated masks are then cleared which frees up the atlas
89 // for future draws.
90 //
91 // TODO: We should not clear all accumulated masks but cache masks over more than one frame.
92 //
93 // TODO: We may need a method to generate raster-generated masks in separate threads prior to
94 // upload.
95 std::unique_ptr<RasterPathAtlas> fRasterPathAtlas;
96
97 // Allocated and cached texture proxies shared by all PathAtlas instances. It is possible for
98 // the same texture to be bound to multiple DispatchGroups and DrawPasses across flushes. The
99 // owning Recorder must guarantee that any uploads or compute dispatches are scheduled to remain
100 // coherent across flushes.
101 // TODO: This requirement might change with a more sophisticated reuse scheme for texture
102 // allocations. For now our model is simple: all PathAtlases target the same texture and only
103 // one of them will render to the texture during a given command submission.
104 std::unordered_map<uint64_t, sk_sp<TextureProxy>> fTexturePool;
105
107};
108
110
111} // namespace skgpu::graphite
112
113#endif // skgpu_graphite_AtlasProvider_DEFINED
SkColorType
Definition SkColorType.h:19
#define SK_DECL_BITMASK_OPS_FRIENDS(E)
#define SK_MAKE_BITMASK_OPS(E)
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
bool isAvailable(PathAtlasFlags atlasType) const
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
void recordUploads(DrawContext *)
std::unique_ptr< ComputePathAtlas > createComputePathAtlas(Recorder *recorder) const
SkEnumBitMask< PathAtlasFlags > PathAtlasFlagsBitMask
RasterPathAtlas * getRasterPathAtlas() const
static SkString identifier(const FontFamilyDesc &family, const FontDesc &font)
int32_t height
int32_t width