xref: /aosp_15_r20/external/skia/src/gpu/graphite/RasterPathAtlas.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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_RasterPathAtlas_DEFINED
9 #define skgpu_graphite_RasterPathAtlas_DEFINED
10 
11 #include "src/gpu/graphite/PathAtlas.h"
12 
13 namespace skgpu::graphite {
14 
15 /**
16  * PathAtlas class that rasterizes coverage masks on the CPU.
17  *
18  * When a new shape gets added, its path is rasterized in preparation for upload. These
19  * uploads are recorded by `recordUploads()` and subsequently added to an UploadTask.
20  *
21  * Shapes are cached for future frames to avoid the cost of raster pipeline rendering. Multiple
22  * textures (or Pages) are used to cache masks, so if the atlas is full we can reset a Page and
23  * start adding new shapes for a future atlas render.
24  */
25 class RasterPathAtlas : public PathAtlas {
26 public:
27     explicit RasterPathAtlas(Recorder* recorder);
~RasterPathAtlas()28     ~RasterPathAtlas() override {}
29     void recordUploads(DrawContext*);
30 
compact(bool forceCompact)31     void compact(bool forceCompact) {
32         fCachedAtlasMgr.compact(fRecorder, forceCompact);
33         fSmallPathAtlasMgr.compact(fRecorder, forceCompact);
34         fUncachedAtlasMgr.compact(fRecorder, forceCompact);
35     }
36 
evictAtlases()37     void evictAtlases() {
38         fCachedAtlasMgr.evictAll();
39         fSmallPathAtlasMgr.evictAll();
40         fUncachedAtlasMgr.evictAll();
41     }
42 
43 protected:
44     const TextureProxy* onAddShape(const Shape&,
45                                    const Transform& transform,
46                                    const SkStrokeRec&,
47                                    skvx::half2 maskSize,
48                                    skvx::half2* outPos) override;
49 private:
50     class RasterAtlasMgr : public PathAtlas::DrawAtlasMgr {
51     public:
RasterAtlasMgr(size_t width,size_t height,size_t plotWidth,size_t plotHeight,const Caps * caps)52         RasterAtlasMgr(size_t width, size_t height,
53                        size_t plotWidth, size_t plotHeight,
54                        const Caps* caps)
55             : PathAtlas::DrawAtlasMgr(width, height, plotWidth, plotHeight,
56                                       DrawAtlas::UseStorageTextures::kNo,
57                                       /*label=*/"RasterPathAtlas", caps) {}
58 
59     protected:
60         bool onAddToAtlas(const Shape&,
61                           const Transform& transform,
62                           const SkStrokeRec&,
63                           SkIRect shapeBounds,
64                           const AtlasLocator&) override;
65     };
66 
67     RasterAtlasMgr fCachedAtlasMgr;
68     RasterAtlasMgr fSmallPathAtlasMgr;
69     RasterAtlasMgr fUncachedAtlasMgr;
70 };
71 
72 }  // namespace skgpu::graphite
73 
74 #endif  // skgpu_graphite_RasterPathAtlas_DEFINED
75