Debian Codegraph @

src/text/gpu/VertexFiller.h

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 #ifndef sktext_gpu_VertexFiller_DEFINED
8 #define sktext_gpu_VertexFiller_DEFINED
9
10 #include "include/core/SkMatrix.h"
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkScalar.h"
14 #include "include/core/SkSpan.h"
15 #include "include/core/SkTypes.h"
16 #include "include/private/base/SkTLogic.h"
17 #include "src/base/SkVx.h"
18 #include "src/core/SkColorData.h"
19
20 #include <cstddef>
21 #include <optional>
22 #include <tuple>
23
24 class SkReadBuffer;
25 class SkWriteBuffer;
26
27 namespace skgpu {
28 enum class MaskFormat : int;
29
30 namespace graphite {
31 class DrawWriter;
32 class Rect;
33 class Transform;
34 }
35 }
36
37 namespace sktext::gpu {
38 class Glyph;
39 class SubRunAllocator;
40
41 enum FillerType {
42 kIsDirect,
43 kIsTransformed
44 };
45
46 // -- VertexFiller ---------------------------------------------------------------------------------
47 // The VertexFiller assumes that all points, glyph atlas entries, and bounds are created with
48 // respect to the CreationMatrix. This assumes that mapping any point, mask or bounds through the
49 // CreationMatrix will result in the proper device position. In order to draw using an arbitrary
50 // PositionMatrix, calculate a
51 //
52 // viewDifference = [PositionMatrix] * [CreationMatrix] ^ -1.
53 //
54 // The viewDifference is used to map all points, masks and bounds to position to the device
55 // respecting the PositionMatrix.
56 class VertexFiller {
57 public:
58 VertexFiller(skgpu::MaskFormat maskFormat,
59 const SkMatrix &creationMatrix,
60 SkRect creationBounds,
61 SkSpan<const SkPoint> leftTop,
62 bool canDrawDirect);
63
64 static VertexFiller Make(skgpu::MaskFormat maskType,
65 const SkMatrix &creationMatrix,
66 SkRect creationBounds,
67 SkSpan<const SkPoint> positions,
68 SubRunAllocator *alloc,
69 FillerType fillerType);
70
71 static std::optional<VertexFiller> MakeFromBuffer(SkReadBuffer &buffer,
72 SubRunAllocator *alloc);
73
74 int unflattenSize() const { return fLeftTop.size_bytes(); }
75
76 void flatten(SkWriteBuffer &buffer) const;
77
78 // These are only available if the Ganesh backend is compiled in (see GaneshVertexFiller.cpp)
79 size_t vertexStride(const SkMatrix &matrix) const;
80 void fillVertexData(int offset, int count,
81 SkSpan<const Glyph*> glyphs,
82 const SkPMColor4f& color,
83 const SkMatrix& positionMatrix,
84 SkIRect clip,
85 void* vertexBuffer) const;
86
87 // This is only available if the Graphite backend is compiled in (see GraphiteVertexFiller.cpp)
88 void fillInstanceData(skgpu::graphite::DrawWriter* dw,
89 int offset, int count,
90 unsigned short flags,
91 uint32_t ssboIndex,
92 SkSpan<const Glyph*> glyphs,
93 SkScalar depth) const;
94
95 std::tuple<skgpu::graphite::Rect, skgpu::graphite::Transform> boundsAndDeviceMatrix(
96 const skgpu::graphite::Transform& localToDevice, SkPoint drawOrigin) const;
97
98 // Return true if the positionMatrix represents an integer translation. Return the device
99 // bounding box of all the glyphs. If the bounding box is empty, then something went singular
100 // and this operation should be dropped.
101 std::tuple<bool, SkRect> deviceRectAndCheckTransform(const SkMatrix &positionMatrix) const;
102
103 skgpu::MaskFormat grMaskType() const { return fMaskType; }
104 bool isLCD() const;
105
106 int count() const { return SkCount(fLeftTop); }
107
108 private:
109 static std::tuple<bool, SkVector> CanUseDirect(const SkMatrix& creationMatrix,
110 const SkMatrix& positionMatrix);
111
112 SkMatrix viewDifference(const SkMatrix &positionMatrix) const;
113
114 const skgpu::MaskFormat fMaskType;
115 const bool fCanDrawDirect;
116 const SkMatrix fCreationMatrix;
117 const SkRect fCreationBounds;
118 const SkSpan<const SkPoint> fLeftTop;
119 };
120
121 } // namespace sktext::gpu
122
123 #endif