Skip to content

Commit

Permalink
Add DlColorSource objects to hold information for SkShaders (flutter#…
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored Mar 15, 2022
1 parent cd7a1e2 commit dc22c4c
Show file tree
Hide file tree
Showing 34 changed files with 2,341 additions and 329 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + '8cbf38af7d48cc298ae86e614533b4b2d0dc6758',

'src/flutter/impeller':
Var('github_git') + '/flutter/impeller' + '@' + 'c54ddfab21691cf5693c15a4f84d9156fb7d8cfb',
Var('github_git') + '/flutter/impeller' + '@' + 'c1572a3335c4a533dacc28b86cbebdf08b5a57ed',

# Fuchsia compatibility
#
Expand Down
6 changes: 6 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ FILE: ../../../flutter/common/task_runners.h
FILE: ../../../flutter/display_list/display_list.cc
FILE: ../../../flutter/display_list/display_list.h
FILE: ../../../flutter/display_list/display_list_attributes.h
FILE: ../../../flutter/display_list/display_list_attributes_testing.h
FILE: ../../../flutter/display_list/display_list_benchmarks.cc
FILE: ../../../flutter/display_list/display_list_benchmarks.h
FILE: ../../../flutter/display_list/display_list_benchmarks_canvas_provider.h
Expand All @@ -56,6 +57,9 @@ FILE: ../../../flutter/display_list/display_list_canvas_unittests.cc
FILE: ../../../flutter/display_list/display_list_color_filter.cc
FILE: ../../../flutter/display_list/display_list_color_filter.h
FILE: ../../../flutter/display_list/display_list_color_filter_unittests.cc
FILE: ../../../flutter/display_list/display_list_color_source.cc
FILE: ../../../flutter/display_list/display_list_color_source.h
FILE: ../../../flutter/display_list/display_list_color_source_unittests.cc
FILE: ../../../flutter/display_list/display_list_comparable.h
FILE: ../../../flutter/display_list/display_list_complexity.cc
FILE: ../../../flutter/display_list/display_list_complexity.h
Expand All @@ -67,6 +71,7 @@ FILE: ../../../flutter/display_list/display_list_complexity_metal.h
FILE: ../../../flutter/display_list/display_list_complexity_unittests.cc
FILE: ../../../flutter/display_list/display_list_dispatcher.cc
FILE: ../../../flutter/display_list/display_list_dispatcher.h
FILE: ../../../flutter/display_list/display_list_enum_unittests.cc
FILE: ../../../flutter/display_list/display_list_flags.cc
FILE: ../../../flutter/display_list/display_list_flags.h
FILE: ../../../flutter/display_list/display_list_mask_filter.cc
Expand All @@ -76,6 +81,7 @@ FILE: ../../../flutter/display_list/display_list_ops.cc
FILE: ../../../flutter/display_list/display_list_ops.h
FILE: ../../../flutter/display_list/display_list_test_utils.cc
FILE: ../../../flutter/display_list/display_list_test_utils.h
FILE: ../../../flutter/display_list/display_list_tile_mode.h
FILE: ../../../flutter/display_list/display_list_unittests.cc
FILE: ../../../flutter/display_list/display_list_utils.cc
FILE: ../../../flutter/display_list/display_list_utils.h
Expand Down
6 changes: 6 additions & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ source_set("display_list") {
"display_list_canvas_recorder.h",
"display_list_color_filter.cc",
"display_list_color_filter.h",
"display_list_color_source.cc",
"display_list_color_source.h",
"display_list_complexity.cc",
"display_list_complexity.h",
"display_list_complexity_gl.cc",
Expand All @@ -31,6 +33,7 @@ source_set("display_list") {
"display_list_mask_filter.h",
"display_list_ops.cc",
"display_list_ops.h",
"display_list_tile_mode.h",
"display_list_utils.cc",
"display_list_utils.h",
"types.h",
Expand All @@ -48,9 +51,12 @@ source_set("unittests") {
testonly = true

sources = [
"display_list_attributes_testing.h",
"display_list_canvas_unittests.cc",
"display_list_color_filter_unittests.cc",
"display_list_color_source_unittests.cc",
"display_list_complexity_unittests.cc",
"display_list_enum_unittests.cc",
"display_list_mask_filter_unittests.cc",
"display_list_test_utils.cc",
"display_list_test_utils.h",
Expand Down
11 changes: 7 additions & 4 deletions display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,22 @@ namespace flutter {
\
V(SetBlender) \
V(ClearBlender) \
V(SetShader) \
V(ClearShader) \
V(SetImageFilter) \
V(ClearImageFilter) \
V(SetPathEffect) \
V(ClearPathEffect) \
\
V(ClearColorFilter) \
V(SetColorFilter) \
V(SetPodColorFilter) \
V(SetSkColorFilter) \
\
V(ClearColorSource) \
V(SetPodColorSource) \
V(SetSkColorSource) \
V(SetImageColorSource) \
\
V(ClearMaskFilter) \
V(SetMaskFilter) \
V(SetPodMaskFilter) \
V(SetSkMaskFilter) \
\
V(Save) \
Expand Down
42 changes: 42 additions & 0 deletions display_list/display_list_attributes_testing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.

#ifndef FLUTTER_DISPLAY_LIST_DISPLAY_LIST_ATTRIBUTES_TESTING_H_
#define FLUTTER_DISPLAY_LIST_DISPLAY_LIST_ATTRIBUTES_TESTING_H_

#include "flutter/display_list/display_list_attributes.h"
#include "flutter/display_list/display_list_comparable.h"
#include "gtest/gtest.h"

namespace flutter {
namespace testing {

template <class T>
static void TestEquals(T& source1, T& source2) {
ASSERT_TRUE(source1 == source2);
ASSERT_TRUE(source2 == source1);
ASSERT_FALSE(source1 != source2);
ASSERT_FALSE(source2 != source1);
ASSERT_EQ(source1, source2);
ASSERT_EQ(source2, source1);
ASSERT_TRUE(Equals(&source1, &source2));
ASSERT_TRUE(Equals(source1.shared(), source2.shared()));
}

template <class T>
static void TestNotEquals(T& source1, T& source2, std::string label) {
ASSERT_FALSE(source1 == source2) << label;
ASSERT_FALSE(source2 == source1) << label;
ASSERT_TRUE(source1 != source2) << label;
ASSERT_TRUE(source2 != source1) << label;
ASSERT_NE(source1, source2) << label;
ASSERT_NE(source2, source1) << label;
ASSERT_TRUE(NotEquals(&source1, &source2));
ASSERT_TRUE(NotEquals(source1.shared(), source2.shared()));
}

} // namespace testing
} // namespace flutter

#endif // FLUTTER_DISPLAY_LIST_DISPLAY_LIST_ATTRIBUTES_TESTING_H_
70 changes: 60 additions & 10 deletions display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,59 @@ void DisplayListBuilder::onSetBlender(sk_sp<SkBlender> blender) {
UpdateCurrentOpacityCompatibility();
}
}
void DisplayListBuilder::onSetShader(sk_sp<SkShader> shader) {
(current_shader_ = shader) //
? Push<SetShaderOp>(0, 0, std::move(shader))
: Push<ClearShaderOp>(0, 0);
void DisplayListBuilder::onSetColorSource(const DlColorSource* source) {
if (source == nullptr) {
current_color_source_ = nullptr;
Push<ClearColorSourceOp>(0, 0);
} else {
current_color_source_ = source->shared();
switch (source->type()) {
case DlColorSourceType::kColor: {
const DlColorColorSource* color_source = source->asColor();
current_color_source_ = nullptr;
setColor(color_source->color());
break;
}
case DlColorSourceType::kImage: {
const DlImageColorSource* image_source = source->asImage();
FML_DCHECK(image_source);
Push<SetImageColorSourceOp>(0, 0, image_source);
break;
}
case DlColorSourceType::kLinearGradient: {
const DlLinearGradientColorSource* linear = source->asLinearGradient();
FML_DCHECK(linear);
void* pod = Push<SetPodColorSourceOp>(linear->size(), 0);
new (pod) DlLinearGradientColorSource(linear);
break;
}
case DlColorSourceType::kRadialGradient: {
const DlRadialGradientColorSource* radial = source->asRadialGradient();
FML_DCHECK(radial);
void* pod = Push<SetPodColorSourceOp>(radial->size(), 0);
new (pod) DlRadialGradientColorSource(radial);
break;
}
case DlColorSourceType::kConicalGradient: {
const DlConicalGradientColorSource* conical =
source->asConicalGradient();
FML_DCHECK(conical);
void* pod = Push<SetPodColorSourceOp>(conical->size(), 0);
new (pod) DlConicalGradientColorSource(conical);
break;
}
case DlColorSourceType::kSweepGradient: {
const DlSweepGradientColorSource* sweep = source->asSweepGradient();
FML_DCHECK(sweep);
void* pod = Push<SetPodColorSourceOp>(sweep->size(), 0);
new (pod) DlSweepGradientColorSource(sweep);
break;
}
case DlColorSourceType::kUnknown:
Push<SetSkColorSourceOp>(0, 0, source->skia_object());
break;
}
}
}
void DisplayListBuilder::onSetImageFilter(sk_sp<SkImageFilter> filter) {
(current_image_filter_ = filter) //
Expand All @@ -144,24 +193,24 @@ void DisplayListBuilder::onSetColorFilter(const DlColorFilter* filter) {
case DlColorFilterType::kBlend: {
const DlBlendColorFilter* blend_filter = filter->asBlend();
FML_DCHECK(blend_filter);
void* pod = Push<SetColorFilterOp>(blend_filter->size(), 0);
void* pod = Push<SetPodColorFilterOp>(blend_filter->size(), 0);
new (pod) DlBlendColorFilter(blend_filter);
break;
}
case DlColorFilterType::kMatrix: {
const DlMatrixColorFilter* matrix_filter = filter->asMatrix();
FML_DCHECK(matrix_filter);
void* pod = Push<SetColorFilterOp>(matrix_filter->size(), 0);
void* pod = Push<SetPodColorFilterOp>(matrix_filter->size(), 0);
new (pod) DlMatrixColorFilter(matrix_filter);
break;
}
case DlColorFilterType::kSrgbToLinearGamma: {
void* pod = Push<SetColorFilterOp>(filter->size(), 0);
void* pod = Push<SetPodColorFilterOp>(filter->size(), 0);
new (pod) DlSrgbToLinearGammaColorFilter();
break;
}
case DlColorFilterType::kLinearToSrgbGamma: {
void* pod = Push<SetColorFilterOp>(filter->size(), 0);
void* pod = Push<SetPodColorFilterOp>(filter->size(), 0);
new (pod) DlLinearToSrgbGammaColorFilter();
break;
}
Expand All @@ -188,7 +237,7 @@ void DisplayListBuilder::onSetMaskFilter(const DlMaskFilter* filter) {
case DlMaskFilterType::kBlur: {
const DlBlurMaskFilter* blur_filter = filter->asBlur();
FML_DCHECK(blur_filter);
void* pod = Push<SetMaskFilterOp>(blur_filter->size(), 0);
void* pod = Push<SetPodMaskFilterOp>(blur_filter->size(), 0);
new (pod) DlBlurMaskFilter(blur_filter);
break;
}
Expand Down Expand Up @@ -229,7 +278,8 @@ void DisplayListBuilder::setAttributesFromPaint(
setStrokeJoin(paint.getStrokeJoin());
}
if (flags.applies_shader()) {
setShader(sk_ref_sp(paint.getShader()));
SkShader* shader = paint.getShader();
setColorSource(DlColorSource::From(shader).get());
}
if (flags.applies_color_filter()) {
// invert colors is a Flutter::Paint thing, not an SkPaint thing
Expand Down
14 changes: 8 additions & 6 deletions display_list/display_list_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class DisplayListBuilder final : public virtual Dispatcher,
onSetBlender(std::move(blender));
}
}
void setShader(sk_sp<SkShader> shader) override {
if (current_shader_ != shader) {
onSetShader(std::move(shader));
void setColorSource(const DlColorSource* source) override {
if (NotEquals(current_color_source_, source)) {
onSetColorSource(source);
}
}
void setImageFilter(sk_sp<SkImageFilter> filter) override {
Expand Down Expand Up @@ -118,7 +118,9 @@ class DisplayListBuilder final : public virtual Dispatcher,
SkScalar getStrokeMiter() const { return current_stroke_miter_; }
SkPaint::Cap getStrokeCap() const { return current_stroke_cap_; }
SkPaint::Join getStrokeJoin() const { return current_stroke_join_; }
sk_sp<SkShader> getShader() const { return current_shader_; }
std::shared_ptr<const DlColorSource> getColorSource() const {
return current_color_source_;
}
std::shared_ptr<const DlColorFilter> getColorFilter() const {
return current_color_filter_;
}
Expand Down Expand Up @@ -376,7 +378,7 @@ class DisplayListBuilder final : public virtual Dispatcher,
void onSetColor(SkColor color);
void onSetBlendMode(SkBlendMode mode);
void onSetBlender(sk_sp<SkBlender> blender);
void onSetShader(sk_sp<SkShader> shader);
void onSetColorSource(const DlColorSource* source);
void onSetImageFilter(sk_sp<SkImageFilter> filter);
void onSetColorFilter(const DlColorFilter* filter);
void onSetPathEffect(sk_sp<SkPathEffect> effect);
Expand All @@ -396,7 +398,7 @@ class DisplayListBuilder final : public virtual Dispatcher,
// If |current_blender_| is set then |current_blend_mode_| should be ignored
SkBlendMode current_blend_mode_ = SkBlendMode::kSrcOver;
sk_sp<SkBlender> current_blender_;
sk_sp<SkShader> current_shader_;
std::shared_ptr<const DlColorSource> current_color_source_;
std::shared_ptr<const DlColorFilter> current_color_filter_;
sk_sp<SkImageFilter> current_image_filter_;
sk_sp<SkPathEffect> current_path_effect_;
Expand Down
Loading

0 comments on commit dc22c4c

Please sign in to comment.