Skip to content

Commit

Permalink
Use new DlColorSource objects (flutter#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored and dnfield committed Apr 27, 2022
1 parent 47cb97c commit f5db75a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
62 changes: 31 additions & 31 deletions impeller/display_list/display_list_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -90,40 +89,41 @@ static Color ToColor(const SkColor& color) {
}

// |flutter::Dispatcher|
void DisplayListDispatcher::setShader(sk_sp<SkShader> 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<LinearGradientContents>();
contents->SetEndPoints(ToPoint(info.fPoint[0]),
ToPoint(info.fPoint[1]));
std::vector<Color> 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<LinearGradientContents>();
contents->SetEndPoints(ToPoint(linear->p0()),
ToPoint(linear->p1()));
std::vector<Color> 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
Expand Down
2 changes: 1 addition & 1 deletion impeller/display_list/display_list_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DisplayListDispatcher final : public flutter::Dispatcher {
void setStrokeJoin(SkPaint::Join join) override;

// |flutter::Dispatcher|
void setShader(sk_sp<SkShader> shader) override;
void setColorSource(const flutter::DlColorSource* source) override;

// |flutter::Dispatcher|
void setColorFilter(const flutter::DlColorFilter* filter) override;
Expand Down

0 comments on commit f5db75a

Please sign in to comment.