From f5db75a15726d6aea9f26604c4283440ec5437f3 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Tue, 15 Mar 2022 13:47:09 -0700 Subject: [PATCH] Use new DlColorSource objects (#73) --- .../display_list/display_list_dispatcher.cc | 62 +++++++++---------- .../display_list/display_list_dispatcher.h | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/impeller/display_list/display_list_dispatcher.cc b/impeller/display_list/display_list_dispatcher.cc index fef486e321270..3ae258e025835 100644 --- a/impeller/display_list/display_list_dispatcher.cc +++ b/impeller/display_list/display_list_dispatcher.cc @@ -9,7 +9,6 @@ #include "impeller/geometry/path_builder.h" #include "impeller/typographer/backends/skia/text_frame_skia.h" #include "third_party/skia/include/core/SkColor.h" -#include "third_party/skia/include/core/SkShader.h" namespace impeller { @@ -90,40 +89,41 @@ static Color ToColor(const SkColor& color) { } // |flutter::Dispatcher| -void DisplayListDispatcher::setShader(sk_sp shader) { - if (!shader) { +void DisplayListDispatcher::setColorSource(const flutter::DlColorSource* source) { + if (!source) { + paint_.contents = nullptr; return; } - { - SkShader::GradientInfo info = {}; - constexpr auto kColorsArrayCount = 2u; - info.fColorCount = kColorsArrayCount; - SkColor sk_colors[kColorsArrayCount]; - info.fColors = sk_colors; - auto gradient_type = shader->asAGradient(&info); - switch (gradient_type) { - case SkShader::kLinear_GradientType: { - auto contents = std::make_shared(); - contents->SetEndPoints(ToPoint(info.fPoint[0]), - ToPoint(info.fPoint[1])); - std::vector colors; - for (auto i = 0; i < info.fColorCount; i++) { - colors.emplace_back(ToColor(sk_colors[i])); - } - contents->SetColors(std::move(colors)); - paint_.contents = std::move(contents); - return; - } break; - case SkShader::kNone_GradientType: - case SkShader::kColor_GradientType: - case SkShader::kRadial_GradientType: - case SkShader::kSweep_GradientType: - case SkShader::kConical_GradientType: - default: - UNIMPLEMENTED; - break; + switch(source->type()) { + case flutter::DlColorSourceType::kColor: { + const flutter::DlColorColorSource* color = source->asColor(); + paint_.contents = nullptr; + setColor(color->color()); + FML_DCHECK(color); + return; } + case flutter::DlColorSourceType::kLinearGradient: { + const flutter::DlLinearGradientColorSource* linear = source->asLinearGradient(); + FML_DCHECK(linear); + auto contents = std::make_shared(); + contents->SetEndPoints(ToPoint(linear->p0()), + ToPoint(linear->p1())); + std::vector colors; + for (auto i = 0; i < linear->stop_count(); i++) { + colors.emplace_back(ToColor(linear->colors()[i])); + } + contents->SetColors(std::move(colors)); + paint_.contents = std::move(contents); + return; + } + case flutter::DlColorSourceType::kImage: + case flutter::DlColorSourceType::kRadialGradient: + case flutter::DlColorSourceType::kConicalGradient: + case flutter::DlColorSourceType::kSweepGradient: + case flutter::DlColorSourceType::kUnknown: + UNIMPLEMENTED; + break; } // Needs https://github.com/flutter/flutter/issues/95434 diff --git a/impeller/display_list/display_list_dispatcher.h b/impeller/display_list/display_list_dispatcher.h index 8995a3d803493..660ab1c07ecda 100644 --- a/impeller/display_list/display_list_dispatcher.h +++ b/impeller/display_list/display_list_dispatcher.h @@ -45,7 +45,7 @@ class DisplayListDispatcher final : public flutter::Dispatcher { void setStrokeJoin(SkPaint::Join join) override; // |flutter::Dispatcher| - void setShader(sk_sp shader) override; + void setColorSource(const flutter::DlColorSource* source) override; // |flutter::Dispatcher| void setColorFilter(const flutter::DlColorFilter* filter) override;