Skip to content

Commit 70c9202

Browse files
authored
Revert "[Impeller] SDF text rendering " (flutter#36330)
1 parent d5a0510 commit 70c9202

26 files changed

+150
-470
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,6 @@ FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur.frag
658658
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur.vert
659659
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
660660
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
661-
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_sdf.frag
662-
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_sdf.vert
663661
FILE: ../../../flutter/impeller/entity/shaders/gradient_fill.vert
664662
FILE: ../../../flutter/impeller/entity/shaders/linear_gradient_fill.frag
665663
FILE: ../../../flutter/impeller/entity/shaders/linear_to_srgb_filter.frag

impeller/compiler/shader_lib/impeller/transform.glsl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,4 @@ vec2 IPVec2TransformPosition(mat4 matrix, vec2 point) {
1111
return transformed.xy / transformed.w;
1212
}
1313

14-
// Returns the transformed gl_Position for a given glyph position in a glyph
15-
// atlas.
16-
vec4 IPPositionForGlyphPosition(mat4 mvp, vec2 unit_vertex, vec2 glyph_position, vec2 glyph_size) {
17-
vec4 translate = mvp[0] * glyph_position.x
18-
+ mvp[1] * glyph_position.y
19-
+ mvp[3];
20-
mat4 translated_mvp = mat4(
21-
mvp[0],
22-
mvp[1],
23-
mvp[2],
24-
vec4(
25-
translate.xyz,
26-
mvp[3].w
27-
)
28-
);
29-
return translated_mvp *
30-
vec4(unit_vertex.x * glyph_size.x,
31-
unit_vertex.y * glyph_size.y, 0.0, 1.0);
32-
}
33-
3414
#endif

impeller/entity/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ impeller_shaders("entity_shaders") {
3636
"shaders/gaussian_blur.vert",
3737
"shaders/glyph_atlas.frag",
3838
"shaders/glyph_atlas.vert",
39-
"shaders/glyph_atlas_sdf.frag",
40-
"shaders/glyph_atlas_sdf.vert",
4139
"shaders/gradient_fill.vert",
4240
"shaders/linear_to_srgb_filter.frag",
4341
"shaders/linear_to_srgb_filter.vert",

impeller/entity/contents/content_context.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
207207
CreateDefaultPipeline<SolidStrokePipeline>(*context_);
208208
glyph_atlas_pipelines_[{}] =
209209
CreateDefaultPipeline<GlyphAtlasPipeline>(*context_);
210-
glyph_atlas_sdf_pipelines_[{}] =
211-
CreateDefaultPipeline<GlyphAtlasSdfPipeline>(*context_);
212210
vertices_pipelines_[{}] = CreateDefaultPipeline<VerticesPipeline>(*context_);
213211
atlas_pipelines_[{}] = CreateDefaultPipeline<AtlasPipeline>(*context_);
214212

impeller/entity/contents/content_context.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
#include "impeller/entity/gaussian_blur.vert.h"
4141
#include "impeller/entity/glyph_atlas.frag.h"
4242
#include "impeller/entity/glyph_atlas.vert.h"
43-
#include "impeller/entity/glyph_atlas_sdf.frag.h"
44-
#include "impeller/entity/glyph_atlas_sdf.vert.h"
4543
#include "impeller/entity/gradient_fill.vert.h"
4644
#include "impeller/entity/linear_gradient_fill.frag.h"
4745
#include "impeller/entity/linear_to_srgb_filter.frag.h"
@@ -146,8 +144,6 @@ using SolidStrokePipeline =
146144
RenderPipelineT<SolidStrokeVertexShader, SolidStrokeFragmentShader>;
147145
using GlyphAtlasPipeline =
148146
RenderPipelineT<GlyphAtlasVertexShader, GlyphAtlasFragmentShader>;
149-
using GlyphAtlasSdfPipeline =
150-
RenderPipelineT<GlyphAtlasSdfVertexShader, GlyphAtlasSdfFragmentShader>;
151147
using VerticesPipeline =
152148
RenderPipelineT<VerticesVertexShader, VerticesFragmentShader>;
153149
using AtlasPipeline =
@@ -276,11 +272,6 @@ class ContentContext {
276272
return GetPipeline(glyph_atlas_pipelines_, opts);
277273
}
278274

279-
std::shared_ptr<Pipeline<PipelineDescriptor>> GetGlyphAtlasSdfPipeline(
280-
ContentContextOptions opts) const {
281-
return GetPipeline(glyph_atlas_sdf_pipelines_, opts);
282-
}
283-
284275
std::shared_ptr<Pipeline<PipelineDescriptor>> GetVerticesPipeline(
285276
ContentContextOptions opts) const {
286277
return GetPipeline(vertices_pipelines_, opts);
@@ -408,7 +399,6 @@ class ContentContext {
408399
mutable Variants<SolidStrokePipeline> solid_stroke_pipelines_;
409400
mutable Variants<ClipPipeline> clip_pipelines_;
410401
mutable Variants<GlyphAtlasPipeline> glyph_atlas_pipelines_;
411-
mutable Variants<GlyphAtlasSdfPipeline> glyph_atlas_sdf_pipelines_;
412402
mutable Variants<VerticesPipeline> vertices_pipelines_;
413403
mutable Variants<AtlasPipeline> atlas_pipelines_;
414404
// Advanced blends.

impeller/entity/contents/text_contents.cc

Lines changed: 45 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include "impeller/entity/contents/text_contents.h"
66

7+
#include <iostream>
78
#include <optional>
8-
#include <type_traits>
99

1010
#include "impeller/entity/contents/content_context.h"
1111
#include "impeller/entity/entity.h"
@@ -28,16 +28,22 @@ void TextContents::SetTextFrame(TextFrame frame) {
2828
frame_ = std::move(frame);
2929
}
3030

31+
void TextContents::SetGlyphAtlas(std::shared_ptr<GlyphAtlas> atlas) {
32+
atlas_ = std::move(atlas);
33+
}
34+
3135
void TextContents::SetGlyphAtlas(std::shared_ptr<LazyGlyphAtlas> atlas) {
32-
lazy_atlas_ = std::move(atlas);
36+
atlas_ = std::move(atlas);
3337
}
3438

3539
std::shared_ptr<GlyphAtlas> TextContents::ResolveAtlas(
36-
GlyphAtlas::Type type,
3740
std::shared_ptr<Context> context) const {
38-
FML_DCHECK(lazy_atlas_);
39-
if (lazy_atlas_) {
40-
return lazy_atlas_->CreateOrGetGlyphAtlas(type, context);
41+
if (auto lazy_atlas = std::get_if<std::shared_ptr<LazyGlyphAtlas>>(&atlas_)) {
42+
return lazy_atlas->get()->CreateOrGetGlyphAtlas(context);
43+
}
44+
45+
if (auto atlas = std::get_if<std::shared_ptr<GlyphAtlas>>(&atlas_)) {
46+
return *atlas;
4147
}
4248

4349
return nullptr;
@@ -55,19 +61,33 @@ std::optional<Rect> TextContents::GetCoverage(const Entity& entity) const {
5561
return bounds->TransformBounds(entity.GetTransformation());
5662
}
5763

58-
template <class TPipeline>
59-
static bool CommonRender(const ContentContext& renderer,
60-
const Entity& entity,
61-
RenderPass& pass,
62-
const Color& color,
63-
const TextFrame& frame,
64-
std::shared_ptr<GlyphAtlas> atlas,
65-
Command& cmd) {
66-
using VS = typename TPipeline::VertexShader;
67-
using FS = typename TPipeline::FragmentShader;
64+
bool TextContents::Render(const ContentContext& renderer,
65+
const Entity& entity,
66+
RenderPass& pass) const {
67+
if (color_.IsTransparent()) {
68+
return true;
69+
}
70+
71+
auto atlas = ResolveAtlas(renderer.GetContext());
72+
73+
if (!atlas || !atlas->IsValid()) {
74+
VALIDATION_LOG << "Cannot render glyphs without prepared atlas.";
75+
return false;
76+
}
77+
78+
using VS = GlyphAtlasPipeline::VertexShader;
79+
using FS = GlyphAtlasPipeline::FragmentShader;
80+
81+
// Information shared by all glyph draw calls.
82+
Command cmd;
83+
cmd.label = "TextFrame";
84+
cmd.primitive_type = PrimitiveType::kTriangle;
85+
cmd.pipeline =
86+
renderer.GetGlyphAtlasPipeline(OptionsFromPassAndEntity(pass, entity));
87+
cmd.stencil_reference = entity.GetStencilDepth();
6888

6989
// Common vertex uniforms for all glyphs.
70-
typename VS::FrameInfo frame_info;
90+
VS::FrameInfo frame_info;
7191
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
7292
entity.GetTransformation();
7393
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
@@ -76,8 +96,8 @@ static bool CommonRender(const ContentContext& renderer,
7696
sampler_desc.min_filter = MinMagFilter::kLinear;
7797
sampler_desc.mag_filter = MinMagFilter::kLinear;
7898

79-
typename FS::FragInfo frag_info;
80-
frag_info.text_color = ToVector(color.Premultiply());
99+
FS::FragInfo frag_info;
100+
frag_info.text_color = ToVector(color_.Premultiply());
81101
frag_info.atlas_size =
82102
Point{static_cast<Scalar>(atlas->GetTexture()->GetSize().width),
83103
static_cast<Scalar>(atlas->GetTexture()->GetSize().height)};
@@ -102,15 +122,16 @@ static bool CommonRender(const ContentContext& renderer,
102122
{0, 0}, {1, 0}, {0, 1}, {1, 0}, {0, 1}, {1, 1},
103123
};
104124

105-
VertexBufferBuilder<typename VS::PerVertexData> vertex_builder;
106-
for (const auto& run : frame.GetRuns()) {
125+
VertexBufferBuilder<VS::PerVertexData> vertex_builder;
126+
for (const auto& run : frame_.GetRuns()) {
107127
auto font = run.GetFont();
108128
auto glyph_size = ISize::Ceil(font.GetMetrics().GetBoundingBox().size);
109129
for (const auto& glyph_position : run.GetGlyphPositions()) {
110130
FontGlyphPair font_glyph_pair{font, glyph_position.glyph};
111-
131+
auto color_glyph =
132+
atlas->IsColorFontGlyphPair(font_glyph_pair) ? 1.0 : 0.0;
112133
for (const auto& point : unit_vertex_points) {
113-
typename VS::PerVertexData vtx;
134+
VS::PerVertexData vtx;
114135
vtx.unit_vertex = point;
115136

116137
auto atlas_glyph_pos = atlas->FindFontGlyphPosition(font_glyph_pair);
@@ -128,10 +149,7 @@ static bool CommonRender(const ContentContext& renderer,
128149
1 / atlas_glyph_pos->size.height};
129150
vtx.atlas_glyph_size =
130151
Point{atlas_glyph_pos->size.width, atlas_glyph_pos->size.height};
131-
if constexpr (std::is_same_v<TPipeline, GlyphAtlasPipeline>) {
132-
vtx.color_glyph =
133-
glyph_position.glyph.type == Glyph::Type::kBitmap ? 1.0 : 0.0;
134-
}
152+
vtx.color_glyph = color_glyph;
135153
vertex_builder.AppendVertex(std::move(vtx));
136154
}
137155
}
@@ -147,55 +165,4 @@ static bool CommonRender(const ContentContext& renderer,
147165
return true;
148166
}
149167

150-
bool TextContents::RenderSdf(const ContentContext& renderer,
151-
const Entity& entity,
152-
RenderPass& pass) const {
153-
auto atlas = ResolveAtlas(GlyphAtlas::Type::kSignedDistanceField,
154-
renderer.GetContext());
155-
156-
if (!atlas || !atlas->IsValid()) {
157-
VALIDATION_LOG << "Cannot render glyphs without prepared atlas.";
158-
return false;
159-
}
160-
161-
// Information shared by all glyph draw calls.
162-
Command cmd;
163-
cmd.label = "TextFrameSDF";
164-
cmd.primitive_type = PrimitiveType::kTriangle;
165-
cmd.pipeline =
166-
renderer.GetGlyphAtlasSdfPipeline(OptionsFromPassAndEntity(pass, entity));
167-
cmd.stencil_reference = entity.GetStencilDepth();
168-
169-
return CommonRender<GlyphAtlasSdfPipeline>(renderer, entity, pass, color_,
170-
frame_, atlas, cmd);
171-
}
172-
173-
bool TextContents::Render(const ContentContext& renderer,
174-
const Entity& entity,
175-
RenderPass& pass) const {
176-
if (color_.IsTransparent()) {
177-
return true;
178-
}
179-
180-
auto atlas = ResolveAtlas(frame_.HasColor() ? GlyphAtlas::Type::kColorBitmap
181-
: GlyphAtlas::Type::kAlphaBitmap,
182-
renderer.GetContext());
183-
184-
if (!atlas || !atlas->IsValid()) {
185-
VALIDATION_LOG << "Cannot render glyphs without prepared atlas.";
186-
return false;
187-
}
188-
189-
// Information shared by all glyph draw calls.
190-
Command cmd;
191-
cmd.label = "TextFrame";
192-
cmd.primitive_type = PrimitiveType::kTriangle;
193-
cmd.pipeline =
194-
renderer.GetGlyphAtlasPipeline(OptionsFromPassAndEntity(pass, entity));
195-
cmd.stencil_reference = entity.GetStencilDepth();
196-
197-
return CommonRender<GlyphAtlasPipeline>(renderer, entity, pass, color_,
198-
frame_, atlas, cmd);
199-
}
200-
201168
} // namespace impeller

impeller/entity/contents/text_contents.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#include "flutter/fml/macros.h"
1313
#include "impeller/entity/contents/contents.h"
1414
#include "impeller/geometry/color.h"
15-
#include "impeller/typographer/glyph_atlas.h"
1615
#include "impeller/typographer/text_frame.h"
1716

1817
namespace impeller {
1918

19+
class GlyphAtlas;
2020
class LazyGlyphAtlas;
2121
class Context;
2222

@@ -28,6 +28,8 @@ class TextContents final : public Contents {
2828

2929
void SetTextFrame(TextFrame frame);
3030

31+
void SetGlyphAtlas(std::shared_ptr<GlyphAtlas> atlas);
32+
3133
void SetGlyphAtlas(std::shared_ptr<LazyGlyphAtlas> atlas);
3234

3335
void SetColor(Color color);
@@ -40,18 +42,14 @@ class TextContents final : public Contents {
4042
const Entity& entity,
4143
RenderPass& pass) const override;
4244

43-
// TODO(dnfield): remove this https://github.com/flutter/flutter/issues/111640
44-
bool RenderSdf(const ContentContext& renderer,
45-
const Entity& entity,
46-
RenderPass& pass) const;
47-
4845
private:
4946
TextFrame frame_;
5047
Color color_;
51-
mutable std::shared_ptr<LazyGlyphAtlas> lazy_atlas_;
48+
mutable std::variant<std::shared_ptr<GlyphAtlas>,
49+
std::shared_ptr<LazyGlyphAtlas>>
50+
atlas_;
5251

5352
std::shared_ptr<GlyphAtlas> ResolveAtlas(
54-
GlyphAtlas::Type type,
5553
std::shared_ptr<Context> context) const;
5654

5755
FML_DISALLOW_COPY_AND_ASSIGN(TextContents);

impeller/entity/entity_unittests.cc

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "impeller/entity/contents/rrect_shadow_contents.h"
2121
#include "impeller/entity/contents/solid_color_contents.h"
2222
#include "impeller/entity/contents/solid_stroke_contents.h"
23-
#include "impeller/entity/contents/text_contents.h"
2423
#include "impeller/entity/contents/texture_contents.h"
2524
#include "impeller/entity/contents/vertices_contents.h"
2625
#include "impeller/entity/entity.h"
@@ -36,11 +35,8 @@
3635
#include "impeller/renderer/render_pass.h"
3736
#include "impeller/renderer/vertex_buffer_builder.h"
3837
#include "impeller/tessellator/tessellator.h"
39-
#include "impeller/typographer/backends/skia/text_frame_skia.h"
40-
#include "impeller/typographer/backends/skia/text_render_context_skia.h"
4138
#include "include/core/SkBlendMode.h"
4239
#include "third_party/imgui/imgui.h"
43-
#include "third_party/skia/include/core/SkTextBlob.h"
4440

4541
namespace impeller {
4642
namespace testing {
@@ -1980,31 +1976,5 @@ TEST_P(EntityTest, TTTBlendColor) {
19801976
}
19811977
}
19821978

1983-
TEST_P(EntityTest, SdfText) {
1984-
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1985-
SkFont font;
1986-
font.setSize(30);
1987-
auto blob = SkTextBlob::MakeFromString(
1988-
"the quick brown fox jumped over the lazy dog (but with sdf).", font);
1989-
auto frame = TextFrameFromTextBlob(blob);
1990-
auto lazy_glyph_atlas = std::make_shared<LazyGlyphAtlas>();
1991-
lazy_glyph_atlas->AddTextFrame(frame);
1992-
1993-
auto text_contents = std::make_shared<TextContents>();
1994-
text_contents->SetTextFrame(std::move(frame));
1995-
text_contents->SetGlyphAtlas(std::move(lazy_glyph_atlas));
1996-
text_contents->SetColor(Color(1.0, 0.0, 0.0, 1.0));
1997-
Entity entity;
1998-
entity.SetTransformation(
1999-
Matrix::MakeTranslation(Vector3{200.0, 200.0, 0.0}) *
2000-
Matrix::MakeScale(GetContentScale()));
2001-
entity.SetContents(text_contents);
2002-
2003-
// Force SDF rendering.
2004-
return text_contents->RenderSdf(context, entity, pass);
2005-
};
2006-
ASSERT_TRUE(OpenPlaygroundHere(callback));
2007-
}
2008-
20091979
} // namespace testing
20101980
} // namespace impeller

0 commit comments

Comments
 (0)