mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] Move glyph atlas state from context into lazy glyph atlas. (flutter/engine#43748)
No impact on behavior. Rather that separately cache the lazy glyph atlas and the underlying state (bitmap, atlas, texture), move the state into the lazy glyph atlas. To do make this behave correctly, we need to "reset" the lazy glyph atlas instead of deleting it on each frame. Reseting it clears out the text runs and cached atlas, which has the same impact as deleting it in the previous behavior. This refactor is required in order to move to platform specific glyph atlases, to solve issues such as https://github.com/flutter/flutter/issues/126104
This commit is contained in:
parent
1f46e61e01
commit
077440458f
@ -160,9 +160,8 @@ static std::unique_ptr<PipelineT> CreateDefaultPipeline(
|
||||
|
||||
ContentContext::ContentContext(std::shared_ptr<Context> context)
|
||||
: context_(std::move(context)),
|
||||
lazy_glyph_atlas_(std::make_shared<LazyGlyphAtlas>()),
|
||||
tessellator_(std::make_shared<Tessellator>()),
|
||||
alpha_glyph_atlas_context_(std::make_shared<GlyphAtlasContext>()),
|
||||
color_glyph_atlas_context_(std::make_shared<GlyphAtlasContext>()),
|
||||
scene_context_(std::make_shared<scene::SceneContext>(context_)) {
|
||||
if (!context_ || !context_->IsValid()) {
|
||||
return;
|
||||
@ -411,12 +410,6 @@ std::shared_ptr<Tessellator> ContentContext::GetTessellator() const {
|
||||
return tessellator_;
|
||||
}
|
||||
|
||||
std::shared_ptr<GlyphAtlasContext> ContentContext::GetGlyphAtlasContext(
|
||||
GlyphAtlas::Type type) const {
|
||||
return type == GlyphAtlas::Type::kAlphaBitmap ? alpha_glyph_atlas_context_
|
||||
: color_glyph_atlas_context_;
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> ContentContext::GetContext() const {
|
||||
return context_;
|
||||
}
|
||||
|
||||
@ -680,9 +680,6 @@ class ContentContext {
|
||||
|
||||
std::shared_ptr<Context> GetContext() const;
|
||||
|
||||
std::shared_ptr<GlyphAtlasContext> GetGlyphAtlasContext(
|
||||
GlyphAtlas::Type type) const;
|
||||
|
||||
const Capabilities& GetDeviceCapabilities() const;
|
||||
|
||||
void SetWireframe(bool wireframe);
|
||||
@ -697,11 +694,6 @@ class ContentContext {
|
||||
const SubpassCallback& subpass_callback,
|
||||
bool msaa_enabled = true) const;
|
||||
|
||||
void SetLazyGlyphAtlas(
|
||||
const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas) {
|
||||
lazy_glyph_atlas_ = lazy_glyph_atlas;
|
||||
}
|
||||
|
||||
std::shared_ptr<LazyGlyphAtlas> GetLazyGlyphAtlas() const {
|
||||
return lazy_glyph_atlas_;
|
||||
}
|
||||
@ -861,8 +853,6 @@ class ContentContext {
|
||||
|
||||
bool is_valid_ = false;
|
||||
std::shared_ptr<Tessellator> tessellator_;
|
||||
std::shared_ptr<GlyphAtlasContext> alpha_glyph_atlas_context_;
|
||||
std::shared_ptr<GlyphAtlasContext> color_glyph_atlas_context_;
|
||||
std::shared_ptr<scene::SceneContext> scene_context_;
|
||||
bool wireframe_ = false;
|
||||
|
||||
|
||||
@ -32,12 +32,10 @@ void TextContents::SetTextFrame(const TextFrame& frame) {
|
||||
std::shared_ptr<GlyphAtlas> TextContents::ResolveAtlas(
|
||||
GlyphAtlas::Type type,
|
||||
const std::shared_ptr<LazyGlyphAtlas>& lazy_atlas,
|
||||
std::shared_ptr<GlyphAtlasContext> atlas_context,
|
||||
std::shared_ptr<Context> context) const {
|
||||
FML_DCHECK(lazy_atlas);
|
||||
if (lazy_atlas) {
|
||||
return lazy_atlas->CreateOrGetGlyphAtlas(type, std::move(atlas_context),
|
||||
std::move(context));
|
||||
return lazy_atlas->CreateOrGetGlyphAtlas(type, std::move(context));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@ -92,8 +90,7 @@ bool TextContents::Render(const ContentContext& renderer,
|
||||
|
||||
auto type = frame_.GetAtlasType();
|
||||
auto atlas =
|
||||
ResolveAtlas(type, renderer.GetLazyGlyphAtlas(),
|
||||
renderer.GetGlyphAtlasContext(type), renderer.GetContext());
|
||||
ResolveAtlas(type, renderer.GetLazyGlyphAtlas(), renderer.GetContext());
|
||||
|
||||
if (!atlas || !atlas->IsValid()) {
|
||||
VALIDATION_LOG << "Cannot render glyphs without prepared atlas.";
|
||||
|
||||
@ -65,7 +65,6 @@ class TextContents final : public Contents {
|
||||
std::shared_ptr<GlyphAtlas> ResolveAtlas(
|
||||
GlyphAtlas::Type type,
|
||||
const std::shared_ptr<LazyGlyphAtlas>& lazy_atlas,
|
||||
std::shared_ptr<GlyphAtlasContext> atlas_context,
|
||||
std::shared_ptr<Context> context) const;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(TextContents);
|
||||
|
||||
@ -254,9 +254,8 @@ bool EntityPass::Render(ContentContext& renderer,
|
||||
return false;
|
||||
}
|
||||
|
||||
renderer.SetLazyGlyphAtlas(std::make_shared<LazyGlyphAtlas>());
|
||||
fml::ScopedCleanupClosure reset_lazy_glyph_atlas(
|
||||
[&renderer]() { renderer.SetLazyGlyphAtlas(nullptr); });
|
||||
[&renderer]() { renderer.GetLazyGlyphAtlas()->ResetTextFrames(); });
|
||||
|
||||
IterateAllEntities([lazy_glyph_atlas =
|
||||
renderer.GetLazyGlyphAtlas()](const Entity& entity) {
|
||||
|
||||
@ -11,7 +11,9 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
LazyGlyphAtlas::LazyGlyphAtlas() = default;
|
||||
LazyGlyphAtlas::LazyGlyphAtlas()
|
||||
: alpha_context_(std::make_shared<GlyphAtlasContext>()),
|
||||
color_context_(std::make_shared<GlyphAtlasContext>()) {}
|
||||
|
||||
LazyGlyphAtlas::~LazyGlyphAtlas() = default;
|
||||
|
||||
@ -24,9 +26,14 @@ void LazyGlyphAtlas::AddTextFrame(const TextFrame& frame, Scalar scale) {
|
||||
}
|
||||
}
|
||||
|
||||
void LazyGlyphAtlas::ResetTextFrames() {
|
||||
alpha_set_.clear();
|
||||
color_set_.clear();
|
||||
atlas_map_.clear();
|
||||
}
|
||||
|
||||
std::shared_ptr<GlyphAtlas> LazyGlyphAtlas::CreateOrGetGlyphAtlas(
|
||||
GlyphAtlas::Type type,
|
||||
std::shared_ptr<GlyphAtlasContext> atlas_context,
|
||||
std::shared_ptr<Context> context) const {
|
||||
{
|
||||
auto atlas_it = atlas_map_.find(type);
|
||||
@ -40,8 +47,9 @@ std::shared_ptr<GlyphAtlas> LazyGlyphAtlas::CreateOrGetGlyphAtlas(
|
||||
return nullptr;
|
||||
}
|
||||
auto& set = type == GlyphAtlas::Type::kAlphaBitmap ? alpha_set_ : color_set_;
|
||||
auto atlas =
|
||||
text_context->CreateGlyphAtlas(type, std::move(atlas_context), set);
|
||||
auto atlas_context =
|
||||
type == GlyphAtlas::Type::kAlphaBitmap ? alpha_context_ : color_context_;
|
||||
auto atlas = text_context->CreateGlyphAtlas(type, atlas_context, set);
|
||||
if (!atlas || !atlas->IsValid()) {
|
||||
VALIDATION_LOG << "Could not create valid atlas.";
|
||||
return nullptr;
|
||||
|
||||
@ -21,14 +21,17 @@ class LazyGlyphAtlas {
|
||||
|
||||
void AddTextFrame(const TextFrame& frame, Scalar scale);
|
||||
|
||||
void ResetTextFrames();
|
||||
|
||||
std::shared_ptr<GlyphAtlas> CreateOrGetGlyphAtlas(
|
||||
GlyphAtlas::Type type,
|
||||
std::shared_ptr<GlyphAtlasContext> atlas_context,
|
||||
std::shared_ptr<Context> context) const;
|
||||
|
||||
private:
|
||||
FontGlyphPair::Set alpha_set_;
|
||||
FontGlyphPair::Set color_set_;
|
||||
std::shared_ptr<GlyphAtlasContext> alpha_context_;
|
||||
std::shared_ptr<GlyphAtlasContext> color_context_;
|
||||
mutable std::unordered_map<GlyphAtlas::Type, std::shared_ptr<GlyphAtlas>>
|
||||
atlas_map_;
|
||||
|
||||
|
||||
@ -122,13 +122,11 @@ TEST_P(TypographerTest, LazyAtlasTracksColor) {
|
||||
lazy_atlas.AddTextFrame(frame, 1.0f);
|
||||
|
||||
// Creates different atlases for color and alpha bitmap.
|
||||
auto color_context = std::make_shared<GlyphAtlasContext>();
|
||||
auto bitmap_context = std::make_shared<GlyphAtlasContext>();
|
||||
auto color_atlas = lazy_atlas.CreateOrGetGlyphAtlas(
|
||||
GlyphAtlas::Type::kColorBitmap, color_context, GetContext());
|
||||
GlyphAtlas::Type::kColorBitmap, GetContext());
|
||||
|
||||
auto bitmap_atlas = lazy_atlas.CreateOrGetGlyphAtlas(
|
||||
GlyphAtlas::Type::kAlphaBitmap, bitmap_context, GetContext());
|
||||
GlyphAtlas::Type::kAlphaBitmap, GetContext());
|
||||
|
||||
ASSERT_FALSE(color_atlas == bitmap_atlas);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user