Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ComputePathAtlas.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 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_ComputePathAtlas_DEFINED
9#define skgpu_graphite_ComputePathAtlas_DEFINED
10
12
14
15#ifdef SK_ENABLE_VELLO_SHADERS
17#endif
18
19#include <memory>
20
21namespace skgpu::graphite {
22
23class DispatchGroup;
24
25/**
26 * Base class for PathAtlas implementations that rasterize coverage masks on the GPU using compute
27 * shaders.
28 *
29 * When a new shape gets added, it gets tracked as input to a series of GPU compute passes. This
30 * data is recorded by `recordDispatches()` into a DispatchGroup which can be added to a
31 * ComputeTask.
32 *
33 * After a successful call to `recordDispatches()`, the client is free to call `reset()` and start
34 * adding new shapes for a future atlas render.
35 */
37public:
38 // Returns the currently preferred ComputePathAtlas implementation.
39 static std::unique_ptr<ComputePathAtlas> CreateDefault(Recorder*);
40
41 virtual std::unique_ptr<DispatchGroup> recordDispatches(Recorder*) const = 0;
42
43 // Clear all scheduled atlas draws and free up atlas allocations, if necessary. After this call
44 // the atlas can be considered cleared and available for new shape insertions. However this
45 // method does not have any bearing on the contents of any atlas textures themselves, which may
46 // be in use by GPU commands that are in-flight or yet to be submitted.
47 void reset();
48
49protected:
50 explicit ComputePathAtlas(Recorder*);
51
52 const TextureProxy* texture() const { return fTexture.get(); }
53 const TextureProxy* addRect(skvx::half2 maskSize,
54 SkIPoint16* outPos);
55 bool isSuitableForAtlasing(const Rect& transformedShapeBounds) const override;
56
57 virtual void onReset() = 0;
58
59private:
60 bool initializeTextureIfNeeded();
61
62 skgpu::RectanizerSkyline fRectanizer;
63
64 // ComputePathAtlas lazily requests a texture from the AtlasProvider when the first shape gets
65 // added to it and references the same texture for the duration of its lifetime. A reference to
66 // this texture is stored here, which is used by AtlasShapeRenderStep when encoding the render
67 // pass.
68 sk_sp<TextureProxy> fTexture;
69};
70
71} // namespace skgpu::graphite
72
73#endif // skgpu_graphite_ComputePathAtlas_DEFINED
bool isSuitableForAtlasing(const Rect &transformedShapeBounds) const override
const TextureProxy * texture() const
static std::unique_ptr< ComputePathAtlas > CreateDefault(Recorder *)
const TextureProxy * addRect(skvx::half2 maskSize, SkIPoint16 *outPos)
virtual std::unique_ptr< DispatchGroup > recordDispatches(Recorder *) const =0