Debian Codegraph @

src/gpu/graphite/RasterPathAtlas.h

raw
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);
28 ~RasterPathAtlas() override {}
29 void recordUploads(DrawContext*);
30
31 void compact() {
32 fCachedAtlasMgr.compact(fRecorder);
33 fSmallPathAtlasMgr.compact(fRecorder);
34 fUncachedAtlasMgr.compact(fRecorder);
35 }
36
37 void freeGpuResources() {
38 fCachedAtlasMgr.freeGpuResources(fRecorder);
39 fSmallPathAtlasMgr.freeGpuResources(fRecorder);
40 fUncachedAtlasMgr.freeGpuResources(fRecorder);
41 }
42
43 void evictAtlases() {
44 fCachedAtlasMgr.evictAll();
45 fSmallPathAtlasMgr.evictAll();
46 fUncachedAtlasMgr.evictAll();
47 }
48
49 protected:
50 sk_sp<TextureProxy> onAddShape(const Shape&,
51 const Transform& localToDevice,
52 const SkStrokeRec&,
53 skvx::half2 maskOrigin,
54 skvx::half2 maskSize,
55 SkIVector transformedMaskOffset,
56 skvx::half2* outPos) override;
57 private:
58 class RasterAtlasMgr : public PathAtlas::DrawAtlasMgr {
59 public:
60 RasterAtlasMgr(size_t width, size_t height,
61 size_t plotWidth, size_t plotHeight,
62 const Caps* caps)
63 : PathAtlas::DrawAtlasMgr(width, height, plotWidth, plotHeight,
64 DrawAtlas::UseStorageTextures::kNo,
65 /*label=*/"RasterPathAtlas", caps) {}
66
67 protected:
68 bool onAddToAtlas(const Shape&,
69 const Transform& localToDevice,
70 const SkStrokeRec&,
71 SkIRect shapeBounds,
72 SkIVector transformedMaskOffset,
73 const AtlasLocator&) override;
74 };
75
76 RasterAtlasMgr fCachedAtlasMgr;
77 RasterAtlasMgr fSmallPathAtlasMgr;
78 RasterAtlasMgr fUncachedAtlasMgr;
79 };
80
81 } // namespace skgpu::graphite
82
83 #endif // skgpu_graphite_RasterPathAtlas_DEFINED