Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
sktext::gpu::VertexFiller Class Reference

#include <VertexFiller.h>

Public Member Functions

 VertexFiller (skgpu::MaskFormat maskFormat, const SkMatrix &creationMatrix, SkRect creationBounds, SkSpan< const SkPoint > leftTop, bool canDrawDirect)
 
int unflattenSize () const
 
void flatten (SkWriteBuffer &buffer) const
 
void fillInstanceData (skgpu::graphite::DrawWriter *dw, int offset, int count, unsigned short flags, skvx::ushort2 ssboIndex, SkSpan< const Glyph * > glyphs, SkScalar depth) const
 
std::tuple< skgpu::graphite::Rect, skgpu::graphite::TransformboundsAndDeviceMatrix (const skgpu::graphite::Transform &localToDevice, SkPoint drawOrigin) const
 
std::tuple< bool, SkRectdeviceRectAndCheckTransform (const SkMatrix &positionMatrix) const
 
skgpu::MaskFormat grMaskType () const
 
bool isLCD () const
 
int count () const
 

Static Public Member Functions

static VertexFiller Make (skgpu::MaskFormat maskType, const SkMatrix &creationMatrix, SkRect creationBounds, SkSpan< const SkPoint > positions, SubRunAllocator *alloc, FillerType fillerType)
 
static std::optional< VertexFillerMakeFromBuffer (SkReadBuffer &buffer, SubRunAllocator *alloc)
 

Detailed Description

Definition at line 60 of file VertexFiller.h.

Constructor & Destructor Documentation

◆ VertexFiller()

sktext::gpu::VertexFiller::VertexFiller ( skgpu::MaskFormat  maskFormat,
const SkMatrix creationMatrix,
SkRect  creationBounds,
SkSpan< const SkPoint leftTop,
bool  canDrawDirect 
)

Definition at line 37 of file VertexFiller.cpp.

42 : fMaskType{maskFormat}, fCanDrawDirect{canDrawDirect},
43 fCreationMatrix{creationMatrix}, fCreationBounds{creationBounds},
44 fLeftTop{leftTop} {}

Member Function Documentation

◆ boundsAndDeviceMatrix()

std::tuple< Rect, Transform > sktext::gpu::VertexFiller::boundsAndDeviceMatrix ( const skgpu::graphite::Transform localToDevice,
SkPoint  drawOrigin 
) const

Definition at line 54 of file GraphiteVertexFiller.cpp.

55 {
56 // The baked-in matrix differs from the current localToDevice by a translation if the
57 // upper 2x2 remains the same, and there's no perspective. Since there's no projection,
58 // Z is irrelevant, so it's okay that fCreationMatrix is an SkMatrix and has
59 // discarded the 3rd row/col, and can ignore those values in localToDevice.
60 const SkM44& positionMatrix = localToDevice.matrix();
61 const bool compatibleMatrix = positionMatrix.rc(0,0) == fCreationMatrix.rc(0, 0) &&
62 positionMatrix.rc(0,1) == fCreationMatrix.rc(0, 1) &&
63 positionMatrix.rc(1,0) == fCreationMatrix.rc(1, 0) &&
64 positionMatrix.rc(1,1) == fCreationMatrix.rc(1, 1) &&
65 localToDevice.type() != Transform::Type::kPerspective &&
66 !fCreationMatrix.hasPerspective();
67
68 if (compatibleMatrix) {
69 const SkV4 mappedOrigin = positionMatrix.map(drawOrigin.x(), drawOrigin.y(), 0.f, 1.f);
70 const SkV2 offset = {mappedOrigin.x - fCreationMatrix.getTranslateX(),
71 mappedOrigin.y - fCreationMatrix.getTranslateY()};
73 // The offset is an integer (but make sure), which means the generated mask can be
74 // accessed without changing how texels would be sampled.
75 return {Rect(fCreationBounds),
78 }
79 }
80
81 // Otherwise compute the relative transformation from fCreationMatrix to
82 // localToDevice, with the drawOrigin applied. If fCreationMatrix or the
83 // concatenation is not invertible the returned Transform is marked invalid and the draw
84 // will be automatically dropped.
85 const SkMatrix viewDifference = this->viewDifference(
86 localToDevice.preTranslate(drawOrigin.x(), drawOrigin.y()));
87 return {Rect(fCreationBounds), Transform(SkM44(viewDifference))};
88}
#define SkScalarRoundToInt(x)
Definition SkScalar.h:37
static bool SkScalarIsInt(SkScalar x)
Definition SkScalar.h:80
Definition SkM44.h:150
SkV4 map(float x, float y, float z, float w) const
Definition SkM44.cpp:129
SkScalar rc(int r, int c) const
Definition SkM44.h:261
static SkM44 Translate(SkScalar x, SkScalar y, SkScalar z=0)
Definition SkM44.h:225
SkScalar getTranslateY() const
Definition SkMatrix.h:452
SkScalar rc(int r, int c) const
Definition SkMatrix.h:404
bool hasPerspective() const
Definition SkMatrix.h:312
SkScalar getTranslateX() const
Definition SkMatrix.h:445
Transform preTranslate(float x, float y) const
const SkM44 & matrix() const
skgpu::graphite::Rect Rect
skgpu::graphite::Transform Transform
Point offset
constexpr float y() const
constexpr float x() const
Definition SkM44.h:19
Definition SkM44.h:98
float y
Definition SkM44.h:99
float x
Definition SkM44.h:99

◆ count()

int sktext::gpu::VertexFiller::count ( ) const
inline

Definition at line 114 of file VertexFiller.h.

114{ return SkCount(fLeftTop); }
constexpr int SkCount(const Container &c)
Definition SkTLogic.h:54

◆ deviceRectAndCheckTransform()

std::tuple< bool, SkRect > sktext::gpu::VertexFiller::deviceRectAndCheckTransform ( const SkMatrix positionMatrix) const

Definition at line 355 of file VertexFiller.cpp.

356 {
357 if (fCanDrawDirect) {
358 const auto [directDrawCompatible, offset] =
359 can_use_direct(fCreationMatrix, positionMatrix);
360
361 if (directDrawCompatible) {
362 return {true, fCreationBounds.makeOffset(offset)};
363 }
364 }
365
366 if (SkMatrix inverse; fCreationMatrix.invert(&inverse)) {
367 SkMatrix viewDifference = SkMatrix::Concat(positionMatrix, inverse);
368 return {false, viewDifference.mapRect(fCreationBounds)};
369 }
370
371 // initialPositionMatrix is singular. Do nothing.
372 return {false, SkRect::MakeEmpty()};
373}
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition SkMatrix.h:1775
bool invert(SkMatrix *inverse) const
Definition SkMatrix.h:1206
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
static std::tuple< bool, SkVector > can_use_direct(const SkMatrix &creationMatrix, const SkMatrix &positionMatrix)
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595
constexpr SkRect makeOffset(float dx, float dy) const
Definition SkRect.h:965

◆ fillInstanceData()

void sktext::gpu::VertexFiller::fillInstanceData ( skgpu::graphite::DrawWriter dw,
int  offset,
int  count,
unsigned short  flags,
skvx::ushort2  ssboIndex,
SkSpan< const Glyph * >  glyphs,
SkScalar  depth 
) const

Definition at line 25 of file GraphiteVertexFiller.cpp.

30 {
31 auto quadData = [&]() {
32 return SkMakeZip(glyphs.subspan(offset, count),
33 fLeftTop.subspan(offset, count));
34 };
35
36 skgpu::graphite::DrawWriter::Instances instances{*dw, {}, {}, 4};
37 instances.reserve(count);
38 // Need to send width, height, uvPos, xyPos, and strikeToSourceScale
39 // pre-transform coords = (s*w*b_x + t_x, s*h*b_y + t_y)
40 // where (b_x, b_y) are the vertexID coords
41 for (auto [glyph, leftTop]: quadData()) {
42 auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs();
43 instances.append(1) << AtlasPt{uint16_t(ar-al), uint16_t(ab-at)}
44 << AtlasPt{uint16_t(al & 0x1fff), at}
45 << leftTop << /*index=*/uint16_t(al >> 13) << flags
46 << 1.0f
47 << depth << ssboIndex;
48 }
49}
uint16_t glyphs[5]
constexpr auto SkMakeZip(Ts &&... ts)
Definition SkZip.h:212
FlutterSemanticsFlag flags
Definition ab.py:1

◆ flatten()

void sktext::gpu::VertexFiller::flatten ( SkWriteBuffer buffer) const

Definition at line 80 of file VertexFiller.cpp.

80 {
81 buffer.writeInt(static_cast<int>(fMaskType));
82 buffer.writeBool(fCanDrawDirect);
83 buffer.writeMatrix(fCreationMatrix);
84 buffer.writeRect(fCreationBounds);
85 buffer.writePointArray(fLeftTop.data(), SkCount(fLeftTop));
86}
static const uint8_t buffer[]

◆ grMaskType()

skgpu::MaskFormat sktext::gpu::VertexFiller::grMaskType ( ) const
inline

Definition at line 111 of file VertexFiller.h.

111{ return fMaskType; }

◆ isLCD()

bool sktext::gpu::VertexFiller::isLCD ( ) const

Definition at line 350 of file VertexFiller.cpp.

350{ return fMaskType == MaskFormat::kA565; }

◆ Make()

VertexFiller sktext::gpu::VertexFiller::Make ( skgpu::MaskFormat  maskType,
const SkMatrix creationMatrix,
SkRect  creationBounds,
SkSpan< const SkPoint positions,
SubRunAllocator alloc,
FillerType  fillerType 
)
static

Definition at line 46 of file VertexFiller.cpp.

51 {
52 SkSpan<SkPoint> leftTop = alloc->makePODSpan<SkPoint>(positions);
53 return VertexFiller{
54 maskType, creationMatrix, creationBounds, leftTop, fillerType == kIsDirect};
55}
SkSpan< T > makePODSpan(SkSpan< const T > s)
VertexFiller(skgpu::MaskFormat maskFormat, const SkMatrix &creationMatrix, SkRect creationBounds, SkSpan< const SkPoint > leftTop, bool canDrawDirect)

◆ MakeFromBuffer()

std::optional< VertexFiller > sktext::gpu::VertexFiller::MakeFromBuffer ( SkReadBuffer buffer,
SubRunAllocator alloc 
)
static

Definition at line 57 of file VertexFiller.cpp.

58 {
59 int checkingMaskType = buffer.readInt();
60 if (!buffer.validate(
61 0 <= checkingMaskType && checkingMaskType < skgpu::kMaskFormatCount)) {
62 return std::nullopt;
63 }
64 MaskFormat maskType = (MaskFormat) checkingMaskType;
65
66 const bool canDrawDirect = buffer.readBool();
67
68 SkMatrix creationMatrix;
69 buffer.readMatrix(&creationMatrix);
70
71 SkRect creationBounds = buffer.readRect();
72
73 SkSpan<SkPoint> leftTop = MakePointsFromBuffer(buffer, alloc);
74 if (leftTop.empty()) { return std::nullopt; }
75
76 SkASSERT(buffer.isValid());
77 return VertexFiller{maskType, creationMatrix, creationBounds, leftTop, canDrawDirect};
78}
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr bool empty() const
Definition SkSpan_impl.h:96
skgpu::MaskFormat MaskFormat
Definition fontcache.cpp:30
static const int kMaskFormatCount
Definition AtlasTypes.h:105

◆ unflattenSize()

int sktext::gpu::VertexFiller::unflattenSize ( ) const
inline

Definition at line 78 of file VertexFiller.h.

78{ return fLeftTop.size_bytes(); }

The documentation for this class was generated from the following files: