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