• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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_geom_SubRunData_DEFINED
9 #define skgpu_graphite_geom_SubRunData_DEFINED
10 
11 #include "include/core/SkM44.h"
12 #include "include/core/SkSurfaceProps.h"
13 #include "src/gpu/graphite/geom/Rect.h"
14 #include "src/text/gpu/SubRunContainer.h"
15 
16 namespace sktext::gpu { class AtlasSubRun; }
17 
18 namespace skgpu::graphite {
19 
20 class Recorder;
21 
22 /**
23  * SubRunData represents an AtlasSubRun subspan for which per-pixel coverage data comes from a
24  * persistent glyph atlas texture.
25  *
26  * The bounds() represent the bounds of the entire AtlasSubRun and does not directly map to the
27  * local coordinates of this particular subspan. Rather, the dimensions and offset coordinates of a
28  * subspan are defined in a coordinate space that is partially transformed by a decomposition of
29  * the local-to-device matrix computed by the AtlasSubRun per instance. The transform of the draw is
30  * the rest of the decomposed transform (often only a translation) that maps this intermediate space
31  * to the device-space coordinates of the draw.
32  *
33  * The local coordinates used in shading are derived by transforming the final device coordinates
34  * using the inverse of the local-to-device matrix.
35  */
36 class SubRunData {
37 public:
38     SubRunData() = delete;
39     SubRunData(const SubRunData& subRun) = default;
40     SubRunData(SubRunData&&) = delete;
41 
SubRunData(const sktext::gpu::AtlasSubRun * subRun,sk_sp<SkRefCnt> supportDataKeepAlive,Rect deviceBounds,const SkM44 & deviceToLocal,int startGlyphIndex,int glyphCount,SkColor luminanceColor,bool useGammaCorrectDistanceTable,SkPixelGeometry pixelGeometry,Recorder * recorder,sktext::gpu::RendererData rendererData)42     SubRunData(const sktext::gpu::AtlasSubRun* subRun,
43                sk_sp<SkRefCnt> supportDataKeepAlive,
44                Rect deviceBounds,
45                const SkM44& deviceToLocal,
46                int startGlyphIndex,
47                int glyphCount,
48                SkColor luminanceColor,
49                bool useGammaCorrectDistanceTable,
50                SkPixelGeometry pixelGeometry,
51                Recorder* recorder,
52                sktext::gpu::RendererData rendererData)
53         : fSubRun(subRun)
54         , fSupportDataKeepAlive(std::move(supportDataKeepAlive))
55         , fBounds(deviceBounds)
56         , fDeviceToLocal(deviceToLocal)
57         , fStartGlyphIndex(startGlyphIndex)
58         , fGlyphCount(glyphCount)
59         , fLuminanceColor(luminanceColor)
60         , fUseGammaCorrectDistanceTable(useGammaCorrectDistanceTable)
61         , fPixelGeometry(pixelGeometry)
62         , fRecorder(recorder)
63         , fRendererData(rendererData) {}
64 
65     ~SubRunData() = default;
66 
67     // NOTE: None of the geometry types benefit from move semantics, so we don't bother
68     // defining a move assignment operator for SubRunData.
69     SubRunData& operator=(SubRunData&&) = delete;
70     SubRunData& operator=(const SubRunData& that) = default;
71 
72     // The bounding box of the originating AtlasSubRun.
bounds()73     Rect bounds() const { return fBounds; }
74 
75     // The inverse local-to-device matrix.
deviceToLocal()76     const SkM44& deviceToLocal() const { return fDeviceToLocal; }
77 
78     // Access the individual elements of the subrun data.
subRun()79     const sktext::gpu::AtlasSubRun* subRun() const { return fSubRun; }
startGlyphIndex()80     int startGlyphIndex() const { return fStartGlyphIndex; }
glyphCount()81     int glyphCount() const { return fGlyphCount; }
luminanceColor()82     SkColor luminanceColor() const { return fLuminanceColor; }
useGammaCorrectDistanceTable()83     bool useGammaCorrectDistanceTable() const { return fUseGammaCorrectDistanceTable; }
pixelGeometry()84     SkPixelGeometry pixelGeometry() const { return fPixelGeometry; }
recorder()85     Recorder* recorder() const { return fRecorder; }
rendererData()86     const sktext::gpu::RendererData& rendererData() const { return fRendererData; }
87 
88 private:
89     const sktext::gpu::AtlasSubRun* fSubRun;
90     // Keep the TextBlob or Slug alive until we're done with the Geometry.
91     sk_sp<SkRefCnt> fSupportDataKeepAlive;
92 
93     Rect fBounds;  // bounds of the data stored in the SubRun
94     SkM44 fDeviceToLocal;
95     int fStartGlyphIndex;
96     int fGlyphCount;
97     SkColor fLuminanceColor;            // only used by SDFTextRenderStep
98     bool fUseGammaCorrectDistanceTable; // only used by SDFTextRenderStep
99     SkPixelGeometry fPixelGeometry;     // only used by SDFTextLCDRenderStep
100     Recorder* fRecorder; // this SubRun can only be associated with this Recorder's atlas
101     sktext::gpu::RendererData fRendererData;
102 };
103 
104 } // namespace skgpu::graphite
105 
106 #endif // skgpu_graphite_geom_SubRunData_DEFINED
107