Debian Codegraph @

src/text/gpu/VertexFiller.h

raw ◀ ▶
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 class AtlasSubRun;
41
42 enum FillerType {
43 kIsDirect,
44 kIsTransformed
45 };
46
47 // -- VertexFiller ---------------------------------------------------------------------------------
48 // The VertexFiller assumes that all points, glyph atlas entries, and bounds are created with
49 // respect to the CreationMatrix. This assumes that mapping any point, mask or bounds through the
50 // CreationMatrix will result in the proper device position. In order to draw using an arbitrary
51 // PositionMatrix, calculate a
52 //
53 // viewDifference = [PositionMatrix] * [CreationMatrix] ^ -1.
54 //
55 // The viewDifference is used to map all points, masks and bounds to position to the device
56 // respecting the PositionMatrix.
57 class VertexFiller {
58 public:
59 VertexFiller(skgpu::MaskFormat maskFormat,
60 const SkMatrix &creationMatrix,
61 SkRect creationBounds,
62 SkSpan<const SkPoint> leftTop,
63 bool canDrawDirect);
64
65 static VertexFiller Make(skgpu::MaskFormat maskType,
66 const SkMatrix &creationMatrix,
67 SkRect creationBounds,
68 SkSpan<const SkPoint> positions,
69 SubRunAllocator *alloc,
70 FillerType fillerType);
71
72 int unflattenSize() const { return fLeftTop.size_bytes(); }
73
74 // These are only available if the Ganesh backend is compiled in (see GaneshVertexFiller.cpp)
75 size_t vertexStride(const SkMatrix &matrix) const;
76 void fillVertexData(int offset, int count,
77 SkSpan<const Glyph*> glyphs,
78 const SkPMColor4f& color,
79 const SkMatrix& positionMatrix,
80 SkIRect clip,
81 void* vertexBuffer) const;
82
83 // This is only available if the Graphite backend is compiled in (see GraphiteVertexFiller.cpp)
84 void fillInstanceData(skgpu::graphite::DrawWriter* dw,
85 int offset, int count,
86 unsigned short flags,
87 uint32_t ssboIndex,
88 SkSpan<const Glyph*> glyphs,
89 SkScalar depth) const;
90
91 std::tuple<skgpu::graphite::Rect, skgpu::graphite::Transform> boundsAndDeviceMatrix(
92 const skgpu::graphite::Transform& localToDevice, SkPoint drawOrigin) const;
93
94 // Return true if the positionMatrix represents an integer translation. Return the device
95 // bounding box of all the glyphs. If the bounding box is empty, then something went singular
96 // and this operation should be dropped.
97 std::tuple<bool, SkRect> deviceRectAndCheckTransform(const SkMatrix &positionMatrix) const;
98
99 skgpu::MaskFormat grMaskType() const { return fMaskType; }
100 bool isLCD() const;
101
102 int count() const { return SkCount(fLeftTop); }
103
•104 skgpu::MaskFormat maskFormat() const { return fMaskType; }
105 bool canDrawDirect() const { return fCanDrawDirect; }
106 const SkMatrix& creationMatrix() const { return fCreationMatrix; }
107 SkSpan<const SkPoint> topLefts() const { return fLeftTop; }
108
109 private:
•110 friend class AtlasSubRun;
111
112 static std::tuple<bool, SkVector> CanUseDirect(const SkMatrix& creationMatrix,
113 const SkMatrix& positionMatrix);
114
115 SkMatrix viewDifference(const SkMatrix &positionMatrix) const;
116
117 const skgpu::MaskFormat fMaskType;
118 const bool fCanDrawDirect;
119 const SkMatrix fCreationMatrix;
120 const SkRect fCreationBounds;
121 const SkSpan<const SkPoint> fLeftTop;
122 };
123
124 } // namespace sktext::gpu
125
126 #endif