Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] dont apply opacity peephole to runtime effect. #56621

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
80 changes: 80 additions & 0 deletions impeller/display_list/canvas_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include <unordered_map>

#include "display_list/dl_color.h"
#include "display_list/dl_tile_mode.h"
#include "display_list/effects/dl_color_filter.h"
#include "display_list/effects/dl_color_source.h"
#include "display_list/effects/dl_image_filter.h"
#include "display_list/geometry/dl_geometry_types.h"
#include "flutter/testing/testing.h"
Expand All @@ -13,6 +16,8 @@
#include "impeller/core/texture_descriptor.h"
#include "impeller/display_list/aiks_unittests.h"
#include "impeller/display_list/canvas.h"
#include "impeller/display_list/dl_dispatcher.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/geometry_asserts.h"
#include "impeller/renderer/render_target.h"

Expand Down Expand Up @@ -276,5 +281,80 @@ TEST_P(AiksTest, BackdropCountDownWithNestedSaveLayers) {
EXPECT_TRUE(canvas->RequiresReadback());
}

TEST_P(AiksTest, PaintOpacityPeephole) {
{
Paint paint;

EXPECT_TRUE(Paint::CanApplyOpacityPeephole(paint));
}

{
Paint paint;
paint.blend_mode = BlendMode::kColorBurn;

EXPECT_FALSE(Paint::CanApplyOpacityPeephole(paint));
}

{
Paint paint;
paint.mask_blur_descriptor = Paint::MaskBlurDescriptor{
.sigma = Sigma(4),
.respect_ctm = true,
};

EXPECT_FALSE(Paint::CanApplyOpacityPeephole(paint));
}

{
auto image_filter =
flutter::DlBlurImageFilter::Make(1, 1, flutter::DlTileMode::kClamp);
Paint paint;
paint.image_filter = image_filter.get();

EXPECT_FALSE(Paint::CanApplyOpacityPeephole(paint));
}

{
auto color_filter = flutter::DlBlendColorFilter::Make(
flutter::DlColor::kRed(), flutter::DlBlendMode::kDarken);
Paint paint;
paint.color_filter = color_filter.get();

EXPECT_FALSE(Paint::CanApplyOpacityPeephole(paint));
}

{
std::vector<flutter::DlColor> colors = {flutter::DlColor::kRed(),
flutter::DlColor::kBlack()};
std::vector<flutter::DlScalar> stops = {0, 1};
auto color_source = flutter::DlColorSource::MakeLinear(
SkPoint{0, 0}, SkPoint{100, 100}, 2, colors.data(), stops.data(),
flutter::DlTileMode::kClamp);
Paint paint;
paint.color_source = color_source.get();

EXPECT_TRUE(Paint::CanApplyOpacityPeephole(paint));
}

{
auto runtime_stages =
OpenAssetAsRuntimeStage("runtime_stage_simple.frag.iplr");

auto runtime_stage =
runtime_stages[PlaygroundBackendToRuntimeStageBackend(GetBackend())];
ASSERT_TRUE(runtime_stage);

auto runtime_effect = flutter::DlRuntimeEffect::MakeImpeller(runtime_stage);
auto uniform_data = std::make_shared<std::vector<uint8_t>>();
auto color_source = flutter::DlColorSource::MakeRuntimeEffect(
runtime_effect, {}, uniform_data);

Paint paint;
paint.color_source = color_source.get();

EXPECT_FALSE(Paint::CanApplyOpacityPeephole(paint));
}
}

} // namespace testing
} // namespace impeller
17 changes: 17 additions & 0 deletions impeller/display_list/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "display_list/geometry/dl_path.h"
#include "fml/logging.h"
#include "impeller/display_list/color_filter.h"
#include "impeller/display_list/image_filter.h"
#include "impeller/display_list/skia_conversions.h"
#include "impeller/entity/contents/color_source_contents.h"
#include "impeller/entity/contents/conical_gradient_contents.h"
Expand All @@ -34,6 +35,22 @@ using DlRect = flutter::DlRect;
using DlIRect = flutter::DlIRect;
using DlPath = flutter::DlPath;

// static
bool Paint::CanApplyOpacityPeephole(const Paint& paint) {
if (paint.blend_mode != BlendMode::kSourceOver) {
return false;
}
if (paint.invert_colors || paint.mask_blur_descriptor.has_value() ||
Copy link
Contributor

@flar flar Nov 15, 2024

Choose a reason for hiding this comment

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

Also, SaveLayer shouldn't apply mask blur either.

Only alpha of the color, IF, CF and blend.

paint.image_filter || paint.color_filter) {
return false;
}
if (paint.color_source && paint.color_source->type() ==
flutter::DlColorSourceType::kRuntimeEffect) {
return false;
}
return true;
}

std::shared_ptr<ColorSourceContents> Paint::CreateContents() const {
if (color_source == nullptr) {
auto contents = std::make_shared<SolidColorContents>();
Expand Down
10 changes: 1 addition & 9 deletions impeller/display_list/paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
#include "display_list/effects/dl_color_filter.h"
#include "display_list/effects/dl_color_source.h"
#include "display_list/effects/dl_image_filter.h"
#include "impeller/display_list/color_filter.h"
#include "impeller/display_list/image_filter.h"
#include "impeller/entity/contents/color_source_contents.h"
#include "impeller/entity/contents/contents.h"
#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/entity/contents/filters/filter_contents.h"
#include "impeller/entity/contents/texture_contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/geometry/geometry.h"
#include "impeller/geometry/color.h"

namespace impeller {
Expand All @@ -36,12 +33,7 @@ struct Paint {

/// @brief Whether or not a save layer with the provided paint can perform the
/// opacity peephole optimization.
static bool CanApplyOpacityPeephole(const Paint& paint) {
return paint.blend_mode == BlendMode::kSourceOver &&
paint.invert_colors == false &&
!paint.mask_blur_descriptor.has_value() &&
paint.image_filter == nullptr && paint.color_filter == nullptr;
}
static bool CanApplyOpacityPeephole(const Paint& paint);
Copy link
Contributor

Choose a reason for hiding this comment

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

SaveLayer operations ignore the color source. If this is having an impact then something must be going wrong in how we handle SaveLayers.


enum class Style {
kFill,
Expand Down