[Impeller] Simplify color source + text with new Skia API. (flutter/engine#45090)
The original implementation of arbitrary color source + text was quite complicated due to the fact that I had to use blending to emulate this functionality. Now that we can get paths from a given text data, I can instead make non solid color color sources and text just use the regular geometry + color source pipelines. Fixes https://github.com/flutter/flutter/issues/132928 Fixes https://github.com/flutter/flutter/issues/132972
This commit is contained in:
@@ -1185,8 +1185,6 @@ ORIGIN: ../../../flutter/impeller/entity/contents/clip_contents.cc + ../../../fl
|
||||
ORIGIN: ../../../flutter/impeller/entity/contents/clip_contents.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/impeller/entity/contents/color_source_contents.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/impeller/entity/contents/color_source_contents.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/impeller/entity/contents/color_source_text_contents.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/impeller/entity/contents/color_source_text_contents.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/impeller/entity/contents/conical_gradient_contents.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/impeller/entity/contents/conical_gradient_contents.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/impeller/entity/contents/content_context.cc + ../../../flutter/LICENSE
|
||||
@@ -3932,8 +3930,6 @@ FILE: ../../../flutter/impeller/entity/contents/clip_contents.cc
|
||||
FILE: ../../../flutter/impeller/entity/contents/clip_contents.h
|
||||
FILE: ../../../flutter/impeller/entity/contents/color_source_contents.cc
|
||||
FILE: ../../../flutter/impeller/entity/contents/color_source_contents.h
|
||||
FILE: ../../../flutter/impeller/entity/contents/color_source_text_contents.cc
|
||||
FILE: ../../../flutter/impeller/entity/contents/color_source_text_contents.h
|
||||
FILE: ../../../flutter/impeller/entity/contents/conical_gradient_contents.cc
|
||||
FILE: ../../../flutter/impeller/entity/contents/conical_gradient_contents.h
|
||||
FILE: ../../../flutter/impeller/entity/contents/content_context.cc
|
||||
|
||||
@@ -3031,6 +3031,9 @@ TEST_P(AiksTest, CanDrawPointsWithTextureMap) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
// This currently renders solid blue, as the support for text color sources was
|
||||
// moved into DLDispatching. Path data requires the SkTextBlobs which are not
|
||||
// used in impeller::TextFrames.
|
||||
TEST_P(AiksTest, TextForegroundShaderWithTransform) {
|
||||
auto mapping = OpenFixtureAsSkData("Roboto-Regular.ttf");
|
||||
ASSERT_NE(mapping, nullptr);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "impeller/aiks/paint_pass_delegate.h"
|
||||
#include "impeller/entity/contents/atlas_contents.h"
|
||||
#include "impeller/entity/contents/clip_contents.h"
|
||||
#include "impeller/entity/contents/color_source_text_contents.h"
|
||||
#include "impeller/entity/contents/solid_rrect_blur_contents.h"
|
||||
#include "impeller/entity/contents/text_contents.h"
|
||||
#include "impeller/entity/contents/texture_contents.h"
|
||||
@@ -543,37 +542,6 @@ void Canvas::DrawTextFrame(const TextFrame& text_frame,
|
||||
|
||||
auto text_contents = std::make_shared<TextContents>();
|
||||
text_contents->SetTextFrame(TextFrame(text_frame));
|
||||
|
||||
if (paint.color_source.GetType() != ColorSource::Type::kColor) {
|
||||
auto color_text_contents = std::make_shared<ColorSourceTextContents>();
|
||||
entity.SetTransformation(GetCurrentTransformation());
|
||||
|
||||
Entity test;
|
||||
auto maybe_cvg = text_contents->GetCoverage(test);
|
||||
FML_CHECK(maybe_cvg.has_value());
|
||||
// Covered by FML_CHECK.
|
||||
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
||||
auto cvg = maybe_cvg.value();
|
||||
color_text_contents->SetTextPosition(cvg.origin + position);
|
||||
|
||||
text_contents->SetOffset(-cvg.origin);
|
||||
color_text_contents->SetTextContents(std::move(text_contents));
|
||||
color_text_contents->SetColorSourceContents(
|
||||
paint.color_source.GetContents(paint));
|
||||
|
||||
// TODO(bdero): This mask blur application is a hack. It will always wind up
|
||||
// doing a gaussian blur that affects the color source itself
|
||||
// instead of just the mask. The color filter text support
|
||||
// needs to be reworked in order to interact correctly with
|
||||
// mask filters.
|
||||
// https://github.com/flutter/flutter/issues/133297
|
||||
entity.SetContents(paint.WithFilters(
|
||||
paint.WithMaskBlur(std::move(color_text_contents), true)));
|
||||
|
||||
GetCurrentPass().AddEntity(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
text_contents->SetColor(paint.color);
|
||||
|
||||
entity.SetTransformation(GetCurrentTransformation() *
|
||||
|
||||
@@ -1111,7 +1111,9 @@ void DlDispatcher::drawDisplayList(
|
||||
void DlDispatcher::drawTextBlob(const sk_sp<SkTextBlob>& blob,
|
||||
SkScalar x,
|
||||
SkScalar y) {
|
||||
if (paint_.style == Paint::Style::kStroke) {
|
||||
const auto text_frame = MakeTextFrameFromTextBlobSkia(blob);
|
||||
if (paint_.style == Paint::Style::kStroke ||
|
||||
paint_.color_source.GetType() != ColorSource::Type::kColor) {
|
||||
auto path = skia_conversions::PathDataFromTextBlob(blob);
|
||||
auto bounds = blob->bounds();
|
||||
canvas_.Save();
|
||||
@@ -1121,7 +1123,6 @@ void DlDispatcher::drawTextBlob(const sk_sp<SkTextBlob>& blob,
|
||||
return;
|
||||
}
|
||||
|
||||
const auto text_frame = MakeTextFrameFromTextBlobSkia(blob);
|
||||
canvas_.DrawTextFrame(text_frame, //
|
||||
impeller::Point{x, y}, //
|
||||
paint_ //
|
||||
|
||||
@@ -151,8 +151,6 @@ impeller_component("entity") {
|
||||
"contents/clip_contents.h",
|
||||
"contents/color_source_contents.cc",
|
||||
"contents/color_source_contents.h",
|
||||
"contents/color_source_text_contents.cc",
|
||||
"contents/color_source_text_contents.h",
|
||||
"contents/conical_gradient_contents.cc",
|
||||
"contents/conical_gradient_contents.h",
|
||||
"contents/content_context.cc",
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/entity/contents/color_source_text_contents.h"
|
||||
|
||||
#include "color_source_text_contents.h"
|
||||
#include "impeller/entity/contents/content_context.h"
|
||||
#include "impeller/entity/contents/texture_contents.h"
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
ColorSourceTextContents::ColorSourceTextContents() = default;
|
||||
|
||||
ColorSourceTextContents::~ColorSourceTextContents() = default;
|
||||
|
||||
void ColorSourceTextContents::SetTextContents(
|
||||
std::shared_ptr<TextContents> text_contents) {
|
||||
text_contents_ = std::move(text_contents);
|
||||
}
|
||||
|
||||
void ColorSourceTextContents::SetColorSourceContents(
|
||||
std::shared_ptr<ColorSourceContents> color_source_contents) {
|
||||
color_source_contents_ = std::move(color_source_contents);
|
||||
}
|
||||
|
||||
std::optional<Rect> ColorSourceTextContents::GetCoverage(
|
||||
const Entity& entity) const {
|
||||
return text_contents_->GetCoverage(entity);
|
||||
}
|
||||
|
||||
void ColorSourceTextContents::SetTextPosition(Point position) {
|
||||
position_ = position;
|
||||
}
|
||||
|
||||
void ColorSourceTextContents::PopulateGlyphAtlas(
|
||||
const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
|
||||
Scalar scale) {
|
||||
text_contents_->PopulateGlyphAtlas(lazy_glyph_atlas, scale);
|
||||
}
|
||||
|
||||
bool ColorSourceTextContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
auto text_bounds = text_contents_->GetTextFrameBounds();
|
||||
if (!text_bounds.has_value()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
text_contents_->SetColor(Color::Black());
|
||||
color_source_contents_->SetGeometry(
|
||||
Geometry::MakeRect(Rect::MakeSize(text_bounds->size)));
|
||||
|
||||
// offset the color source so it behaves as if it were drawn in the original
|
||||
// position.
|
||||
auto effect_transform =
|
||||
color_source_contents_->GetInverseEffectTransform().Invert().Translate(
|
||||
-position_);
|
||||
color_source_contents_->SetEffectTransform(effect_transform);
|
||||
|
||||
auto new_texture = renderer.MakeSubpass(
|
||||
"Text Color Blending", ISize::Ceil(text_bounds.value().size),
|
||||
[&](const ContentContext& context, RenderPass& pass) {
|
||||
Entity sub_entity;
|
||||
sub_entity.SetContents(text_contents_);
|
||||
sub_entity.SetBlendMode(BlendMode::kSource);
|
||||
if (!sub_entity.Render(context, pass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sub_entity.SetContents(color_source_contents_);
|
||||
sub_entity.SetBlendMode(BlendMode::kSourceIn);
|
||||
return sub_entity.Render(context, pass);
|
||||
});
|
||||
if (!new_texture) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto dest_rect = Rect::MakeSize(new_texture->GetSize()).Shift(position_);
|
||||
|
||||
auto texture_contents = TextureContents::MakeRect(dest_rect);
|
||||
texture_contents->SetTexture(new_texture);
|
||||
texture_contents->SetSourceRect(Rect::MakeSize(new_texture->GetSize()));
|
||||
return texture_contents->Render(renderer, entity, pass);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/entity/contents/color_source_contents.h"
|
||||
#include "impeller/entity/contents/contents.h"
|
||||
#include "impeller/entity/contents/text_contents.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class ColorSourceTextContents final : public Contents {
|
||||
public:
|
||||
ColorSourceTextContents();
|
||||
|
||||
~ColorSourceTextContents();
|
||||
|
||||
void SetTextContents(std::shared_ptr<TextContents> text_contents);
|
||||
|
||||
void SetColorSourceContents(
|
||||
std::shared_ptr<ColorSourceContents> color_source_contents);
|
||||
|
||||
void SetTextPosition(Point position);
|
||||
|
||||
// |Contents|
|
||||
std::optional<Rect> GetCoverage(const Entity& entity) const override;
|
||||
|
||||
// |Contents|
|
||||
void PopulateGlyphAtlas(
|
||||
const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
|
||||
Scalar scale) override;
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
private:
|
||||
Point position_;
|
||||
std::shared_ptr<TextContents> text_contents_;
|
||||
std::shared_ptr<ColorSourceContents> color_source_contents_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ColorSourceTextContents);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
Reference in New Issue
Block a user