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

Commit 0325408

Browse files
committed
Refactor color source resolution to use explicit factory types
1 parent 21a572e commit 0325408

15 files changed

+1001
-582
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,8 @@ FILE: ../../../flutter/impeller/aiks/aiks_playground.h
10301030
FILE: ../../../flutter/impeller/aiks/aiks_unittests.cc
10311031
FILE: ../../../flutter/impeller/aiks/canvas.cc
10321032
FILE: ../../../flutter/impeller/aiks/canvas.h
1033+
FILE: ../../../flutter/impeller/aiks/color_source_factory.cc
1034+
FILE: ../../../flutter/impeller/aiks/color_source_factory.h
10331035
FILE: ../../../flutter/impeller/aiks/image.cc
10341036
FILE: ../../../flutter/impeller/aiks/image.h
10351037
FILE: ../../../flutter/impeller/aiks/paint.cc
@@ -1129,6 +1131,10 @@ FILE: ../../../flutter/impeller/compiler/types.cc
11291131
FILE: ../../../flutter/impeller/compiler/types.h
11301132
FILE: ../../../flutter/impeller/compiler/utilities.cc
11311133
FILE: ../../../flutter/impeller/compiler/utilities.h
1134+
FILE: ../../../flutter/impeller/display_list/conversion_utilities.cc
1135+
FILE: ../../../flutter/impeller/display_list/conversion_utilities.h
1136+
FILE: ../../../flutter/impeller/display_list/display_list_color_source_factory.cc
1137+
FILE: ../../../flutter/impeller/display_list/display_list_color_source_factory.h
11321138
FILE: ../../../flutter/impeller/display_list/display_list_dispatcher.cc
11331139
FILE: ../../../flutter/impeller/display_list/display_list_dispatcher.h
11341140
FILE: ../../../flutter/impeller/display_list/display_list_image_impeller.cc

impeller/aiks/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ impeller_component("aiks") {
1010
"aiks_context.h",
1111
"canvas.cc",
1212
"canvas.h",
13+
"color_source_factory.cc",
14+
"color_source_factory.h",
1315
"image.cc",
1416
"image.h",
1517
"paint.cc",

impeller/aiks/aiks_unittests.cc

Lines changed: 234 additions & 191 deletions
Large diffs are not rendered by default.

impeller/aiks/canvas.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ void Canvas::DrawPaint(const Paint& paint) {
160160
bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
161161
Scalar corner_radius,
162162
const Paint& paint) {
163-
if (paint.color_source == nullptr ||
164-
paint.color_source_type != Paint::ColorSourceType::kColor ||
165-
paint.style != Paint::Style::kFill) {
163+
if (!paint.color_source || paint.style != Paint::Style::kFill) {
166164
return false;
167165
}
168166

@@ -375,17 +373,16 @@ void Canvas::DrawTextFrame(const TextFrame& text_frame,
375373

376374
void Canvas::DrawVertices(const Vertices& vertices,
377375
BlendMode blend_mode,
378-
Paint paint) {
376+
const Paint& paint) {
379377
auto geometry = Geometry::MakeVertices(vertices);
380378

381379
Entity entity;
382380
entity.SetTransformation(GetCurrentTransformation());
383381
entity.SetStencilDepth(GetStencilDepth());
384382
entity.SetBlendMode(paint.blend_mode);
385383

386-
if (paint.color_source.has_value()) {
387-
auto& source = paint.color_source.value();
388-
auto contents = source();
384+
if (paint.color_source) {
385+
auto contents = paint.color_source->MakeContents();
389386
contents->SetGeometry(std::move(geometry));
390387
contents->SetAlpha(paint.color.alpha);
391388
entity.SetContents(paint.WithFilters(std::move(contents), true));

impeller/aiks/canvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Canvas {
9999

100100
void DrawVertices(const Vertices& vertices,
101101
BlendMode blend_mode,
102-
Paint paint);
102+
const Paint& paint);
103103

104104
void DrawAtlas(const std::shared_ptr<Image>& atlas,
105105
std::vector<Matrix> transforms,

impeller/aiks/color_source_factory.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "impeller/aiks/color_source_factory.h"
6+
7+
namespace impeller {
8+
9+
ColorSourceFactory::~ColorSourceFactory() = default;
10+
11+
} // namespace impeller

impeller/aiks/color_source_factory.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#pragma once
6+
7+
#include <memory>
8+
9+
#include "impeller/entity/contents/color_source_contents.h"
10+
11+
namespace impeller {
12+
13+
class ColorSourceFactory {
14+
public:
15+
enum class ColorSourceType {
16+
kColor,
17+
kImage,
18+
kLinearGradient,
19+
kRadialGradient,
20+
kConicalGradient,
21+
kSweepGradient,
22+
kRuntimeEffect,
23+
};
24+
25+
virtual ~ColorSourceFactory();
26+
27+
virtual std::shared_ptr<ColorSourceContents> MakeContents() = 0;
28+
29+
virtual ColorSourceType GetType() = 0;
30+
};
31+
32+
} // namespace impeller

impeller/aiks/paint.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ std::shared_ptr<Contents> Paint::CreateContentsForEntity(const Path& path,
2727

2828
std::shared_ptr<Contents> Paint::CreateContentsForGeometry(
2929
std::unique_ptr<Geometry> geometry) const {
30-
if (color_source.has_value()) {
31-
auto& source = color_source.value();
32-
auto contents = source();
30+
if (color_source) {
31+
auto contents = color_source->MakeContents();
3332
contents->SetGeometry(std::move(geometry));
3433
contents->SetAlpha(color.alpha);
3534
return contents;

impeller/aiks/paint.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <memory>
88

99
#include "flutter/fml/macros.h"
10+
#include "impeller/aiks/color_source_factory.h"
1011
#include "impeller/entity/contents/contents.h"
1112
#include "impeller/entity/contents/filters/color_filter_contents.h"
1213
#include "impeller/entity/contents/filters/filter_contents.h"
@@ -29,23 +30,12 @@ struct Paint {
2930
FilterInput::Ref,
3031
bool is_solid_color,
3132
const Matrix& effect_transform)>;
32-
using ColorSourceProc = std::function<std::shared_ptr<ColorSourceContents>()>;
3333

3434
enum class Style {
3535
kFill,
3636
kStroke,
3737
};
3838

39-
enum class ColorSourceType {
40-
kColor,
41-
kImage,
42-
kLinearGradient,
43-
kRadialGradient,
44-
kConicalGradient,
45-
kSweepGradient,
46-
kRuntimeEffect,
47-
};
48-
4939
struct MaskBlurDescriptor {
5040
FilterContents::BlurStyle style;
5141
Sigma sigma;
@@ -56,10 +46,9 @@ struct Paint {
5646
const Matrix& effect_matrix) const;
5747
};
5848

59-
Color color = Color::Black();
60-
std::optional<ColorSourceProc> color_source;
61-
ColorSourceType color_source_type = ColorSourceType::kColor;
49+
std::shared_ptr<ColorSourceFactory> color_source;
6250

51+
Color color = Color::Black();
6352
Scalar stroke_width = 0.0;
6453
Cap stroke_cap = Cap::kButt;
6554
Join stroke_join = Join::kMiter;

impeller/display_list/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import("//flutter/impeller/tools/impeller.gni")
66

77
impeller_component("display_list") {
88
sources = [
9+
"conversion_utilities.cc",
10+
"conversion_utilities.h",
11+
"display_list_color_source_factory.cc",
12+
"display_list_color_source_factory.h",
913
"display_list_dispatcher.cc",
1014
"display_list_dispatcher.h",
1115
"display_list_image_impeller.cc",

0 commit comments

Comments
 (0)