Skip to content

Commit c22a44d

Browse files
authored
Merge branch 'master' into impeller-render-conics-directly-from-flutter
2 parents 59e7f7a + 8b0cf61 commit c22a44d

File tree

10 files changed

+131
-108
lines changed

10 files changed

+131
-108
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ vars = {
5656
# Dart is: https://github.com/dart-lang/sdk/blob/main/DEPS
5757
# You can use //tools/dart/create_updated_flutter_deps.py to produce
5858
# updated revision list of existing dependencies.
59-
'dart_revision': '509faa921c95dc72651fe803f7c93a29cefe6339',
59+
'dart_revision': '6b07a09cbd2dfb32058a11655c4a9f79e2d5183e',
6060

6161
# WARNING: DO NOT EDIT MANUALLY
6262
# The lines between blank lines above and below are generated by a script. See create_updated_flutter_deps.py

engine/src/flutter/ci/licenses_golden/excluded_files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@
14981498
../../../flutter/third_party/dart/runtime/tools/heapsnapshot/README.md
14991499
../../../flutter/third_party/dart/runtime/tools/heapsnapshot/pubspec.yaml
15001500
../../../flutter/third_party/dart/runtime/tools/heapsnapshot/test
1501+
../../../flutter/third_party/dart/runtime/tools/profiling/.dart_tool
15011502
../../../flutter/third_party/dart/runtime/tools/profiling/.gitignore
15021503
../../../flutter/third_party/dart/runtime/tools/profiling/CHANGELOG.md
15031504
../../../flutter/third_party/dart/runtime/tools/profiling/README.md

engine/src/flutter/impeller/entity/contents/text_contents.cc

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ void TextContents::ComputeVertexData(
108108
// interpolated vertex information is also used in the fragment shader to
109109
// sample from the glyph atlas.
110110

111-
constexpr std::array<Point, 6> unit_points = {Point{0, 0}, Point{1, 0},
112-
Point{0, 1}, Point{1, 0},
111+
constexpr std::array<Point, 4> unit_points = {Point{0, 0}, Point{1, 0},
113112
Point{0, 1}, Point{1, 1}};
114113

115114
ISize atlas_size = atlas->GetTexture()->GetSize();
@@ -119,9 +118,19 @@ void TextContents::ComputeVertexData(
119118
VS::PerVertexData vtx;
120119
size_t i = 0u;
121120
size_t bounds_offset = 0u;
121+
Rational rounded_scale = frame->GetScale();
122+
Scalar inverted_rounded_scale = static_cast<Scalar>(rounded_scale.Invert());
123+
Matrix unscaled_basis =
124+
basis_transform *
125+
Matrix::MakeScale({inverted_rounded_scale, inverted_rounded_scale, 1});
126+
127+
// In typical scales < 48x these values should be -1 or 1. We round to
128+
// those to avoid inaccuracies.
129+
unscaled_basis.m[0] = AttractToOne(unscaled_basis.m[0]);
130+
unscaled_basis.m[5] = AttractToOne(unscaled_basis.m[5]);
131+
122132
for (const TextRun& run : frame->GetRuns()) {
123133
const Font& font = run.GetFont();
124-
Rational rounded_scale = frame->GetScale();
125134
const Matrix transform = frame->GetOffsetTransform();
126135
FontGlyphAtlas* font_atlas = nullptr;
127136

@@ -181,26 +190,15 @@ void TextContents::ComputeVertexData(
181190
atlas_glyph_bounds = maybe_atlas_glyph_bounds.value().atlas_bounds;
182191
}
183192

184-
Scalar inverted_rounded_scale =
185-
static_cast<Scalar>(rounded_scale.Invert());
186193
Rect scaled_bounds = glyph_bounds.Scale(inverted_rounded_scale);
187194
// For each glyph, we compute two rectangles. One for the vertex
188195
// positions and one for the texture coordinates (UVs). The atlas
189196
// glyph bounds are used to compute UVs in cases where the
190197
// destination and source sizes may differ due to clamping the sizes
191198
// of large glyphs.
192-
Point uv_origin = (atlas_glyph_bounds.GetLeftTop()) / atlas_size;
199+
Point uv_origin = atlas_glyph_bounds.GetLeftTop() / atlas_size;
193200
Point uv_size = SizeToPoint(atlas_glyph_bounds.GetSize()) / atlas_size;
194201

195-
Matrix unscaled_basis =
196-
basis_transform * Matrix::MakeScale({inverted_rounded_scale,
197-
inverted_rounded_scale, 1});
198-
199-
// In typical scales < 48x these values should be -1 or 1. We round to
200-
// those to avoid inaccuracies.
201-
unscaled_basis.m[0] = AttractToOne(unscaled_basis.m[0]);
202-
unscaled_basis.m[5] = AttractToOne(unscaled_basis.m[5]);
203-
204202
Point unrounded_glyph_position =
205203
// This is for RTL text.
206204
unscaled_basis * glyph_bounds.GetLeftTop() +
@@ -231,12 +229,12 @@ void TextContents::ComputeVertexData(
231229
bool TextContents::Render(const ContentContext& renderer,
232230
const Entity& entity,
233231
RenderPass& pass) const {
234-
auto color = GetColor();
232+
Color color = GetColor();
235233
if (color.IsTransparent()) {
236234
return true;
237235
}
238236

239-
auto type = frame_->GetAtlasType();
237+
GlyphAtlas::Type type = frame_->GetAtlasType();
240238
const std::shared_ptr<GlyphAtlas>& atlas =
241239
renderer.GetLazyGlyphAtlas()->CreateOrGetGlyphAtlas(
242240
*renderer.GetContext(), renderer.GetTransientsBuffer(), type);
@@ -298,26 +296,45 @@ bool TextContents::Render(const ContentContext& renderer,
298296
sampler_desc) // sampler
299297
);
300298

301-
auto& host_buffer = renderer.GetTransientsBuffer();
302-
size_t vertex_count = 0;
299+
HostBuffer& host_buffer = renderer.GetTransientsBuffer();
300+
size_t glyph_count = 0;
303301
for (const auto& run : frame_->GetRuns()) {
304-
vertex_count += run.GetGlyphPositions().size();
302+
glyph_count += run.GetGlyphPositions().size();
305303
}
306-
vertex_count *= 6;
304+
size_t vertex_count = glyph_count * 4;
305+
size_t index_count = glyph_count * 6;
307306

308307
BufferView buffer_view = host_buffer.Emplace(
309308
vertex_count * sizeof(VS::PerVertexData), alignof(VS::PerVertexData),
310-
[&](uint8_t* contents) {
309+
[&](uint8_t* data) {
311310
VS::PerVertexData* vtx_contents =
312-
reinterpret_cast<VS::PerVertexData*>(contents);
313-
ComputeVertexData(vtx_contents, frame_, scale_,
314-
/*entity_transform=*/entity_transform, offset_,
315-
GetGlyphProperties(), atlas);
311+
reinterpret_cast<VS::PerVertexData*>(data);
312+
ComputeVertexData(/*vtx_contents=*/vtx_contents,
313+
/*frame=*/frame_,
314+
/*scale=*/scale_,
315+
/*entity_transform=*/entity_transform,
316+
/*offset=*/offset_,
317+
/*glyph_properties=*/GetGlyphProperties(),
318+
/*atlas=*/atlas);
319+
});
320+
BufferView index_buffer_view = host_buffer.Emplace(
321+
index_count * sizeof(uint16_t), alignof(uint16_t), [&](uint8_t* data) {
322+
uint16_t* indices = reinterpret_cast<uint16_t*>(data);
323+
size_t j = 0;
324+
for (auto i = 0u; i < glyph_count; i++) {
325+
size_t base = i * 4;
326+
indices[j++] = base + 0;
327+
indices[j++] = base + 1;
328+
indices[j++] = base + 2;
329+
indices[j++] = base + 1;
330+
indices[j++] = base + 2;
331+
indices[j++] = base + 3;
332+
}
316333
});
317334

318335
pass.SetVertexBuffer(std::move(buffer_view));
319-
pass.SetIndexBuffer({}, IndexType::kNone);
320-
pass.SetElementCount(vertex_count);
336+
pass.SetIndexBuffer(index_buffer_view, IndexType::k16bit);
337+
pass.SetElementCount(index_count);
321338

322339
return pass.Draw().ok();
323340
}

engine/src/flutter/impeller/entity/contents/text_contents_unittests.cc

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ std::shared_ptr<GlyphAtlas> CreateGlyphAtlas(
6969
}
7070

7171
Rect PerVertexDataPositionToRect(
72-
GlyphAtlasPipeline::VertexShader::PerVertexData data[6]) {
72+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData>::iterator
73+
data) {
7374
Scalar right = FLT_MIN;
7475
Scalar left = FLT_MAX;
7576
Scalar top = FLT_MAX;
7677
Scalar bottom = FLT_MIN;
77-
for (int i = 0; i < 6; ++i) {
78+
for (int i = 0; i < 4; ++i) {
7879
right = std::max(right, data[i].position.x);
7980
left = std::min(left, data[i].position.x);
8081
top = std::min(top, data[i].position.y);
@@ -85,13 +86,13 @@ Rect PerVertexDataPositionToRect(
8586
}
8687

8788
Rect PerVertexDataUVToRect(
88-
GlyphAtlasPipeline::VertexShader::PerVertexData data[6],
89+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData>::iterator data,
8990
ISize texture_size) {
9091
Scalar right = FLT_MIN;
9192
Scalar left = FLT_MAX;
9293
Scalar top = FLT_MAX;
9394
Scalar bottom = FLT_MIN;
94-
for (int i = 0; i < 6; ++i) {
95+
for (int i = 0; i < 4; ++i) {
9596
right = std::max(right, data[i].uv.x * texture_size.width);
9697
left = std::min(left, data[i].uv.x * texture_size.width);
9798
top = std::min(top, data[i].uv.y * texture_size.height);
@@ -111,7 +112,7 @@ TEST_P(TextContentsTest, SimpleComputeVertexData) {
111112
GTEST_SKIP() << "Results aren't stable across linux and macos.";
112113
#endif
113114

114-
GlyphAtlasPipeline::VertexShader::PerVertexData data[6];
115+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
115116

116117
std::shared_ptr<TextFrame> text_frame =
117118
MakeTextFrame("1", "ahem.ttf", TextOptions{.font_size = 50});
@@ -128,13 +129,13 @@ TEST_P(TextContentsTest, SimpleComputeVertexData) {
128129
atlas_context, text_frame, /*offset=*/{0, 0});
129130

130131
ISize texture_size = atlas->GetTexture()->GetSize();
131-
TextContents::ComputeVertexData(data, text_frame, /*scale=*/1.0,
132+
TextContents::ComputeVertexData(data.data(), text_frame, /*scale=*/1.0,
132133
/*entity_transform=*/Matrix(),
133134
/*offset=*/Vector2(0, 0),
134135
/*glyph_properties=*/std::nullopt, atlas);
135136

136-
Rect position_rect = PerVertexDataPositionToRect(data);
137-
Rect uv_rect = PerVertexDataUVToRect(data, texture_size);
137+
Rect position_rect = PerVertexDataPositionToRect(data.begin());
138+
Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
138139
// The -1 offset comes from Skia in `ComputeGlyphSize`. So since the font size
139140
// is 50, the math appears to be to get back a 50x50 rect and apply 1 pixel
140141
// of padding.
@@ -147,8 +148,7 @@ TEST_P(TextContentsTest, SimpleComputeVertexData2x) {
147148
GTEST_SKIP() << "Results aren't stable across linux and macos.";
148149
#endif
149150

150-
GlyphAtlasPipeline::VertexShader::PerVertexData data[6];
151-
151+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
152152
std::shared_ptr<TextFrame> text_frame =
153153
MakeTextFrame("1", "ahem.ttf", TextOptions{.font_size = 50});
154154

@@ -166,15 +166,15 @@ TEST_P(TextContentsTest, SimpleComputeVertexData2x) {
166166

167167
ISize texture_size = atlas->GetTexture()->GetSize();
168168
TextContents::ComputeVertexData(
169-
data, text_frame, static_cast<Scalar>(font_scale),
169+
data.data(), text_frame, static_cast<Scalar>(font_scale),
170170
/*entity_transform=*/
171171
Matrix::MakeScale({static_cast<Scalar>(font_scale),
172172
static_cast<Scalar>(font_scale), 1}),
173173
/*offset=*/Vector2(0, 0),
174174
/*glyph_properties=*/std::nullopt, atlas);
175175

176-
Rect position_rect = PerVertexDataPositionToRect(data);
177-
Rect uv_rect = PerVertexDataUVToRect(data, texture_size);
176+
Rect position_rect = PerVertexDataPositionToRect(data.begin());
177+
Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
178178
EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -81, 102, 102));
179179
EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 102, 102));
180180
}
@@ -196,24 +196,25 @@ TEST_P(TextContentsTest, MaintainsShape) {
196196
Rect uv_rect[2];
197197

198198
{
199-
GlyphAtlasPipeline::VertexShader::PerVertexData data[12];
199+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(12);
200+
200201
std::shared_ptr<GlyphAtlas> atlas =
201202
CreateGlyphAtlas(*GetContext(), context.get(), *host_buffer,
202203
GlyphAtlas::Type::kAlphaBitmap, font_scale,
203204
atlas_context, text_frame, /*offset=*/{0, 0});
204205
ISize texture_size = atlas->GetTexture()->GetSize();
205206

206207
TextContents::ComputeVertexData(
207-
data, text_frame, static_cast<Scalar>(font_scale),
208+
data.data(), text_frame, static_cast<Scalar>(font_scale),
208209
/*entity_transform=*/
209210
Matrix::MakeScale({static_cast<Scalar>(font_scale),
210211
static_cast<Scalar>(font_scale), 1}),
211212
/*offset=*/Vector2(0, 0),
212213
/*glyph_properties=*/std::nullopt, atlas);
213-
position_rect[0] = PerVertexDataPositionToRect(data);
214-
uv_rect[0] = PerVertexDataUVToRect(data, texture_size);
215-
position_rect[1] = PerVertexDataPositionToRect(data + 6);
216-
uv_rect[1] = PerVertexDataUVToRect(data + 6, texture_size);
214+
position_rect[0] = PerVertexDataPositionToRect(data.begin());
215+
uv_rect[0] = PerVertexDataUVToRect(data.begin(), texture_size);
216+
position_rect[1] = PerVertexDataPositionToRect(data.begin() + 4);
217+
uv_rect[1] = PerVertexDataUVToRect(data.begin() + 4, texture_size);
217218
}
218219
EXPECT_NEAR(GetAspectRatio(position_rect[1]), GetAspectRatio(uv_rect[1]),
219220
0.001)
@@ -226,7 +227,7 @@ TEST_P(TextContentsTest, SimpleSubpixel) {
226227
GTEST_SKIP() << "Results aren't stable across linux and macos.";
227228
#endif
228229

229-
GlyphAtlasPipeline::VertexShader::PerVertexData data[6];
230+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
230231

231232
std::shared_ptr<TextFrame> text_frame = MakeTextFrame(
232233
"1", "ahem.ttf", TextOptions{.font_size = 50, .is_subpixel = true});
@@ -245,12 +246,12 @@ TEST_P(TextContentsTest, SimpleSubpixel) {
245246

246247
ISize texture_size = atlas->GetTexture()->GetSize();
247248
TextContents::ComputeVertexData(
248-
data, text_frame, /*scale=*/1.0,
249+
data.data(), text_frame, /*scale=*/1.0,
249250
/*entity_transform=*/Matrix::MakeTranslation(offset), offset,
250251
/*glyph_properties=*/std::nullopt, atlas);
251252

252-
Rect position_rect = PerVertexDataPositionToRect(data);
253-
Rect uv_rect = PerVertexDataUVToRect(data, texture_size);
253+
Rect position_rect = PerVertexDataPositionToRect(data.begin());
254+
Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
254255
// The values at Point(0, 0).
255256
// EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
256257
// EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
@@ -263,7 +264,7 @@ TEST_P(TextContentsTest, SimpleSubpixel3x) {
263264
GTEST_SKIP() << "Results aren't stable across linux and macos.";
264265
#endif
265266

266-
GlyphAtlasPipeline::VertexShader::PerVertexData data[6];
267+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
267268

268269
std::shared_ptr<TextFrame> text_frame = MakeTextFrame(
269270
"1", "ahem.ttf", TextOptions{.font_size = 50, .is_subpixel = true});
@@ -283,16 +284,16 @@ TEST_P(TextContentsTest, SimpleSubpixel3x) {
283284

284285
ISize texture_size = atlas->GetTexture()->GetSize();
285286
TextContents::ComputeVertexData(
286-
data, text_frame, static_cast<Scalar>(font_scale),
287+
data.data(), text_frame, static_cast<Scalar>(font_scale),
287288
/*entity_transform=*/
288289
Matrix::MakeTranslation(offset) *
289290
Matrix::MakeScale({static_cast<Scalar>(font_scale),
290291
static_cast<Scalar>(font_scale), 1}),
291292
offset,
292293
/*glyph_properties=*/std::nullopt, atlas);
293294

294-
Rect position_rect = PerVertexDataPositionToRect(data);
295-
Rect uv_rect = PerVertexDataUVToRect(data, texture_size);
295+
Rect position_rect = PerVertexDataPositionToRect(data.begin());
296+
Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
296297
// Values at Point(0, 0)
297298
// EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -121, 152, 152));
298299
// EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 152, 152));
@@ -307,7 +308,7 @@ TEST_P(TextContentsTest, SimpleSubpixel26) {
307308
GTEST_SKIP() << "Results aren't stable across linux and macos.";
308309
#endif
309310

310-
GlyphAtlasPipeline::VertexShader::PerVertexData data[6];
311+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
311312

312313
std::shared_ptr<TextFrame> text_frame = MakeTextFrame(
313314
"1", "ahem.ttf", TextOptions{.font_size = 50, .is_subpixel = true});
@@ -326,12 +327,12 @@ TEST_P(TextContentsTest, SimpleSubpixel26) {
326327

327328
ISize texture_size = atlas->GetTexture()->GetSize();
328329
TextContents::ComputeVertexData(
329-
data, text_frame, /*scale=*/1.0,
330+
data.data(), text_frame, /*scale=*/1.0,
330331
/*entity_transform=*/Matrix::MakeTranslation(offset), offset,
331332
/*glyph_properties=*/std::nullopt, atlas);
332333

333-
Rect position_rect = PerVertexDataPositionToRect(data);
334-
Rect uv_rect = PerVertexDataUVToRect(data, texture_size);
334+
Rect position_rect = PerVertexDataPositionToRect(data.begin());
335+
Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
335336
// The values without subpixel.
336337
// EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
337338
// EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
@@ -344,7 +345,7 @@ TEST_P(TextContentsTest, SimpleSubpixel80) {
344345
GTEST_SKIP() << "Results aren't stable across linux and macos.";
345346
#endif
346347

347-
GlyphAtlasPipeline::VertexShader::PerVertexData data[6];
348+
std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
348349

349350
std::shared_ptr<TextFrame> text_frame = MakeTextFrame(
350351
"1", "ahem.ttf", TextOptions{.font_size = 50, .is_subpixel = true});
@@ -363,12 +364,12 @@ TEST_P(TextContentsTest, SimpleSubpixel80) {
363364

364365
ISize texture_size = atlas->GetTexture()->GetSize();
365366
TextContents::ComputeVertexData(
366-
data, text_frame, /*scale=*/1.0,
367+
data.data(), text_frame, /*scale=*/1.0,
367368
/*entity_transform=*/Matrix::MakeTranslation(offset), offset,
368369
/*glyph_properties=*/std::nullopt, atlas);
369370

370-
Rect position_rect = PerVertexDataPositionToRect(data);
371-
Rect uv_rect = PerVertexDataUVToRect(data, texture_size);
371+
Rect position_rect = PerVertexDataPositionToRect(data.begin());
372+
Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
372373
// The values without subpixel.
373374
// EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
374375
// EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));

engine/src/flutter/lib/web_ui/analysis_options.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66

77
include: ../../analysis_options.yaml
88

9+
analyzer:
10+
errors:
11+
avoid_print: ignore
12+
avoid_setters_without_getters: ignore
13+
library_private_types_in_public_api: ignore
14+
no_default_cases: ignore
15+
prefer_relative_imports: ignore
16+
public_member_api_docs: ignore
17+
use_setters_to_change_properties: ignore
18+
919
linter:
1020
rules:
11-
avoid_print: false
12-
avoid_setters_without_getters: false
13-
library_private_types_in_public_api: false
14-
no_default_cases: false
15-
prefer_relative_imports: false
16-
public_member_api_docs: false
17-
unawaited_futures: true
18-
use_setters_to_change_properties: false
21+
- directives_ordering
22+
- unawaited_futures

0 commit comments

Comments
 (0)