Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] add mechanism for sharing bdf inputs. #55701

Merged
merged 24 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions display_list/benchmarking/dl_complexity_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ unsigned int DisplayListGLComplexityCalculator::GLHelper::BatchedComplexity() {
void DisplayListGLComplexityCalculator::GLHelper::saveLayer(
const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) {
if (IsComplex()) {
return;
}
Expand Down Expand Up @@ -627,7 +628,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDisplayList(
GLHelper helper(Ceiling() - CurrentComplexityScore());
if (opacity < SK_Scalar1 && !display_list->can_apply_group_opacity()) {
auto bounds = display_list->GetBounds();
helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr);
helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr,
/*backdrop_id=*/-1);
}
display_list->Dispatch(helper);
AccumulateComplexity(helper.ComplexityScore());
Expand Down
3 changes: 2 additions & 1 deletion display_list/benchmarking/dl_complexity_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class DisplayListGLComplexityCalculator

void saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) override;
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override;

void drawLine(const DlPoint& p0, const DlPoint& p1) override;
void drawDashedLine(const DlPoint& p0,
Expand Down
6 changes: 4 additions & 2 deletions display_list/benchmarking/dl_complexity_metal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ DisplayListMetalComplexityCalculator::MetalHelper::BatchedComplexity() {
void DisplayListMetalComplexityCalculator::MetalHelper::saveLayer(
const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) {
if (IsComplex()) {
return;
}
Expand Down Expand Up @@ -571,7 +572,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawDisplayList(
MetalHelper helper(Ceiling() - CurrentComplexityScore());
if (opacity < SK_Scalar1 && !display_list->can_apply_group_opacity()) {
auto bounds = display_list->GetBounds();
helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr);
helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr,
/*backdrop_id=*/-1);
}
display_list->Dispatch(helper);
AccumulateComplexity(helper.ComplexityScore());
Expand Down
3 changes: 2 additions & 1 deletion display_list/benchmarking/dl_complexity_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class DisplayListMetalComplexityCalculator

void saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) override;
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override;

void drawLine(const DlPoint& p0, const DlPoint& p1) override;
void drawDashedLine(const DlPoint& p0,
Expand Down
15 changes: 10 additions & 5 deletions display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1483,15 +1483,17 @@ class SaveLayerExpector : public virtual DlOpReceiver,

void saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) override {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override {
FML_UNREACHABLE();
}

virtual void saveLayer(const DlRect& bounds,
const SaveLayerOptions& options,
uint32_t total_content_depth,
DlBlendMode max_content_blend_mode,
const DlImageFilter* backdrop = nullptr) {
const DlImageFilter* backdrop = nullptr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are implementations, aren't they? Do they need the default values?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Or all of these virtual tags?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not overrides so I think they need the default values. overrides of a virtual method don't need to re-specify them.

std::optional<int64_t> backdrop_id = std::nullopt) {
ASSERT_LT(save_layer_count_, expected_.size()) << label();
auto expect = expected_[save_layer_count_];
if (expect.options.has_value()) {
Expand Down Expand Up @@ -3666,7 +3668,8 @@ class SaveLayerBoundsExpector : public virtual DlOpReceiver,

void saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) override {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override {
ASSERT_LT(save_layer_count_, expected_.size());
auto expected = expected_[save_layer_count_];
EXPECT_EQ(options.bounds_from_caller(),
Expand Down Expand Up @@ -4131,7 +4134,8 @@ class DepthExpector : public virtual DlOpReceiver,

void saveLayer(const DlRect& bounds,
SaveLayerOptions options,
const DlImageFilter* backdrop) override {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override {
// This method should not be called since we override the variant with
// the total_content_depth parameter.
FAIL() << "saveLayer(no depth parameter) method should not be called";
Expand All @@ -4141,7 +4145,8 @@ class DepthExpector : public virtual DlOpReceiver,
const SaveLayerOptions& options,
uint32_t total_content_depth,
DlBlendMode max_content_mode,
const DlImageFilter* backdrop) override {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override {
ASSERT_LT(index_, depth_expectations_.size());
EXPECT_EQ(depth_expectations_[index_], total_content_depth)
<< "at index " << index_;
Expand Down
11 changes: 7 additions & 4 deletions display_list/dl_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ void DisplayListBuilder::Save() {

void DisplayListBuilder::saveLayer(const DlRect& bounds,
const SaveLayerOptions in_options,
const DlImageFilter* backdrop) {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) {
SaveLayerOptions options = in_options.without_optimizations();
DisplayListAttributeFlags flags = options.renders_with_attributes()
? kSaveLayerWithPaintFlags
Expand Down Expand Up @@ -524,7 +525,8 @@ void DisplayListBuilder::saveLayer(const DlRect& bounds,
}

if (backdrop) {
Push<SaveLayerBackdropOp>(0, options, record_bounds, backdrop);
Push<SaveLayerBackdropOp>(0, options, record_bounds, backdrop,
backdrop_id);
} else {
Push<SaveLayerOp>(0, options, record_bounds);
}
Expand All @@ -542,7 +544,8 @@ void DisplayListBuilder::saveLayer(const DlRect& bounds,
}
void DisplayListBuilder::SaveLayer(std::optional<const DlRect>& bounds,
const DlPaint* paint,
const DlImageFilter* backdrop) {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) {
SaveLayerOptions options;
DlRect temp_bounds;
if (bounds.has_value()) {
Expand All @@ -556,7 +559,7 @@ void DisplayListBuilder::SaveLayer(std::optional<const DlRect>& bounds,
SetAttributesFromPaint(*paint,
DisplayListOpFlags::kSaveLayerWithPaintFlags);
}
saveLayer(temp_bounds, options, backdrop);
saveLayer(temp_bounds, options, backdrop, backdrop_id);
}

void DisplayListBuilder::Restore() {
Expand Down
6 changes: 4 additions & 2 deletions display_list/dl_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class DisplayListBuilder final : public virtual DlCanvas,
// |DlCanvas|
void SaveLayer(std::optional<const DlRect>& bounds,
const DlPaint* paint = nullptr,
const DlImageFilter* backdrop = nullptr) override;
const DlImageFilter* backdrop = nullptr,
std::optional<int64_t> backdrop_id = std::nullopt) override;
// |DlCanvas|
void Restore() override;
// |DlCanvas|
Expand Down Expand Up @@ -354,7 +355,8 @@ class DisplayListBuilder final : public virtual DlCanvas,
// |DlOpReceiver|
void saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) override;
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override;
// |DlOpReceiver|
void restore() override { Restore(); }

Expand Down
8 changes: 5 additions & 3 deletions display_list/dl_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class DlCanvas {
virtual void Save() = 0;
virtual void SaveLayer(std::optional<const DlRect>& bounds,
const DlPaint* paint = nullptr,
const DlImageFilter* backdrop = nullptr) = 0;
const DlImageFilter* backdrop = nullptr,
std::optional<int64_t> backdrop_id = std::nullopt) = 0;
gaaclarke marked this conversation as resolved.
Show resolved Hide resolved
virtual void Restore() = 0;
virtual int GetSaveCount() const = 0;
virtual void RestoreToCount(int restore_count) = 0;
Expand Down Expand Up @@ -233,9 +234,10 @@ class DlCanvas {

void SaveLayer(const SkRect* bounds,
const DlPaint* paint = nullptr,
const DlImageFilter* backdrop = nullptr) {
const DlImageFilter* backdrop = nullptr,
std::optional<int64_t> backdrop_id = std::nullopt) {
auto optional_bounds = ToOptDlRect(bounds);
SaveLayer(optional_bounds, paint, backdrop);
SaveLayer(optional_bounds, paint, backdrop, backdrop_id);
}

void Transform(const SkMatrix* matrix) {
Expand Down
24 changes: 14 additions & 10 deletions display_list/dl_op_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "flutter/display_list/effects/dl_mask_filter.h"
#include "flutter/display_list/image/dl_image.h"

#include "flutter/impeller/geometry/path.h"

namespace flutter {

class DisplayList;
Expand Down Expand Up @@ -143,15 +141,17 @@ class DlOpReceiver {
// layer before further rendering happens.
virtual void saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop = nullptr) = 0;
const DlImageFilter* backdrop = nullptr,
std::optional<int64_t> backdrop_id = std::nullopt) = 0;
// Optional variant of saveLayer() that passes the total depth count of
// all rendering operations that occur until the next restore() call.
virtual void saveLayer(const DlRect& bounds,
const SaveLayerOptions& options,
uint32_t total_content_depth,
DlBlendMode max_content_blend_mode,
const DlImageFilter* backdrop = nullptr) {
saveLayer(bounds, options, backdrop);
const DlImageFilter* backdrop = nullptr,
std::optional<int64_t> backdrop_id = std::nullopt) {
saveLayer(bounds, options, backdrop, backdrop_id);
}
virtual void restore() = 0;

Expand All @@ -170,13 +170,17 @@ class DlOpReceiver {
// public DisplayListBuilder/DlCanvas public interfaces where possible,
// as tracked in:
// https://github.com/flutter/flutter/issues/144070
virtual void saveLayer(const DlRect* bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop = nullptr) final {
virtual void saveLayer(
const DlRect* bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop = nullptr,
std::optional<int64_t> backdrop_id = std::nullopt) final {
if (bounds) {
saveLayer(*bounds, options.with_bounds_from_caller(), backdrop);
saveLayer(*bounds, options.with_bounds_from_caller(), backdrop,
backdrop_id);
} else {
saveLayer(DlRect(), options.without_bounds_from_caller(), backdrop);
saveLayer(DlRect(), options.without_bounds_from_caller(), backdrop,
backdrop_id);
}
}
// ---------------------------------------------------------------------
Expand Down
13 changes: 9 additions & 4 deletions display_list/dl_op_records.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,24 @@ struct SaveLayerBackdropOp final : SaveLayerOpBase {

SaveLayerBackdropOp(const SaveLayerOptions& options,
const DlRect& rect,
const DlImageFilter* backdrop)
: SaveLayerOpBase(options, rect), backdrop(backdrop->shared()) {}
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id)
: SaveLayerOpBase(options, rect),
backdrop(backdrop->shared()),
backdrop_id_(backdrop_id) {}

const std::shared_ptr<DlImageFilter> backdrop;
std::optional<int64_t> backdrop_id_;

void dispatch(DlOpReceiver& receiver) const {
receiver.saveLayer(rect, options, total_content_depth, max_blend_mode,
backdrop.get());
backdrop.get(), backdrop_id_);
}

DisplayListCompare equals(const SaveLayerBackdropOp* other) const {
return (options == other->options && rect == other->rect &&
Equals(backdrop, other->backdrop))
Equals(backdrop, other->backdrop) &&
backdrop_id_ == other->backdrop_id_)
? DisplayListCompare::kEqual
: DisplayListCompare::kNotEqual;
}
Expand Down
3 changes: 2 additions & 1 deletion display_list/effects/dl_image_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ class DlBlurImageFilter final : public DlImageFilter {
bool equals_(const DlImageFilter& other) const override {
FML_DCHECK(other.type() == DlImageFilterType::kBlur);
auto that = static_cast<const DlBlurImageFilter*>(&other);
return (sigma_x_ == that->sigma_x_ && sigma_y_ == that->sigma_y_ &&
return (SkScalarNearlyEqual(sigma_x_, that->sigma_x_) &&
SkScalarNearlyEqual(sigma_y_, that->sigma_y_) &&
tile_mode_ == that->tile_mode_);
}

Expand Down
3 changes: 2 additions & 1 deletion display_list/skia/dl_sk_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ void DlSkCanvasAdapter::Save() {

void DlSkCanvasAdapter::SaveLayer(std::optional<const DlRect>& bounds,
const DlPaint* paint,
const DlImageFilter* backdrop) {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) {
sk_sp<SkImageFilter> sk_backdrop = ToSk(backdrop);
SkOptionalPaint sk_paint(paint);
TRACE_EVENT0("flutter", "Canvas::saveLayer");
Expand Down
3 changes: 2 additions & 1 deletion display_list/skia/dl_sk_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class DlSkCanvasAdapter final : public virtual DlCanvas {
void Save() override;
void SaveLayer(std::optional<const DlRect>& bounds,
const DlPaint* paint = nullptr,
const DlImageFilter* backdrop = nullptr) override;
const DlImageFilter* backdrop = nullptr,
std::optional<int64_t> backdrop_id = std::nullopt) override;
void Restore() override;
int GetSaveCount() const override;
void RestoreToCount(int restore_count) override;
Expand Down
4 changes: 3 additions & 1 deletion display_list/skia/dl_sk_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "flutter/display_list/skia/dl_sk_dispatcher.h"
#include <cstdint>

#include "flutter/display_list/dl_blend_mode.h"
#include "flutter/display_list/skia/dl_sk_conversions.h"
Expand Down Expand Up @@ -46,7 +47,8 @@ void DlSkCanvasDispatcher::restore() {
}
void DlSkCanvasDispatcher::saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) {
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) {
if (!options.content_is_clipped() && options.can_distribute_opacity() &&
backdrop == nullptr) {
// We know that:
Expand Down
3 changes: 2 additions & 1 deletion display_list/skia/dl_sk_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class DlSkCanvasDispatcher : public virtual DlOpReceiver,
void restore() override;
void saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) override;
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override;

void translate(DlScalar tx, DlScalar ty) override;
void scale(DlScalar sx, DlScalar sy) override;
Expand Down
8 changes: 4 additions & 4 deletions display_list/testing/dl_test_snippets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ std::vector<DisplayListInvocationGroup> CreateAllSaveRestoreOps() {
r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20));
r.restore();
}},
{5, 136, 3,
{5, 152, 3,
[](DlOpReceiver& r) {
r.saveLayer(nullptr, SaveLayerOptions::kNoAttributes,
&kTestCFImageFilter1);
Expand All @@ -337,7 +337,7 @@ std::vector<DisplayListInvocationGroup> CreateAllSaveRestoreOps() {
r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20));
r.restore();
}},
{5, 136, 3,
{5, 152, 3,
[](DlOpReceiver& r) {
r.saveLayer(nullptr, SaveLayerOptions::kWithAttributes,
&kTestCFImageFilter1);
Expand All @@ -347,7 +347,7 @@ std::vector<DisplayListInvocationGroup> CreateAllSaveRestoreOps() {
r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20));
r.restore();
}},
{5, 136, 3,
{5, 152, 3,
[](DlOpReceiver& r) {
r.saveLayer(&kTestBounds, SaveLayerOptions::kNoAttributes,
&kTestCFImageFilter1);
Expand All @@ -357,7 +357,7 @@ std::vector<DisplayListInvocationGroup> CreateAllSaveRestoreOps() {
r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20));
r.restore();
}},
{5, 136, 3,
{5, 152, 3,
[](DlOpReceiver& r) {
r.saveLayer(&kTestBounds, SaveLayerOptions::kWithAttributes,
&kTestCFImageFilter1);
Expand Down
3 changes: 2 additions & 1 deletion display_list/utils/dl_receiver_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class IgnoreDrawDispatchHelper : public virtual DlOpReceiver {
void save() override {}
void saveLayer(const DlRect& bounds,
const SaveLayerOptions options,
const DlImageFilter* backdrop) override {}
const DlImageFilter* backdrop,
std::optional<int64_t> backdrop_id) override {}
void restore() override {}
void drawColor(DlColor color, DlBlendMode mode) override {}
void drawPaint() override {}
Expand Down
Loading