Flutter Engine
The Flutter Engine
GraphiteVertexFiller.cpp
Go to the documentation of 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*/
10#include "src/base/SkZip.h"
14#include "src/text/gpu/Glyph.h"
17
18namespace sktext::gpu {
19
20struct AtlasPt {
21 uint16_t u;
22 uint16_t v;
23};
24
26 int offset, int count,
27 unsigned short flags,
28 skvx::ushort2 ssboIndex,
30 SkScalar depth) const {
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}
50
53
54std::tuple<Rect, Transform> VertexFiller::boundsAndDeviceMatrix(const Transform& localToDevice,
55 SkPoint drawOrigin) const {
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}
89
90} // namespace sktext::gpu
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
static bool SkScalarIsInt(SkScalar x)
Definition: SkScalar.h:80
constexpr auto SkMakeZip(Ts &&... ts)
Definition: SkZip.h:212
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
std::tuple< skgpu::graphite::Rect, skgpu::graphite::Transform > boundsAndDeviceMatrix(const skgpu::graphite::Transform &localToDevice, SkPoint drawOrigin) const
void fillInstanceData(skgpu::graphite::DrawWriter *dw, int offset, int count, unsigned short flags, skvx::ushort2 ssboIndex, SkSpan< const Glyph * > glyphs, SkScalar depth) const
float SkScalar
Definition: extension.cpp:12
FlutterSemanticsFlag flags
Definition: ab.py:1
const CatchEntryMove ab[]
skgpu::graphite::Rect Rect
skgpu::graphite::Transform Transform
SeparatedVector2 offset
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181
Definition: SkM44.h:19
Definition: SkM44.h:98
float y
Definition: SkM44.h:99
float x
Definition: SkM44.h:99
Definition: SkVx.h:83