Flutter Engine
 
Loading...
Searching...
No Matches
dl_sk_paint_dispatcher.cc
Go to the documentation of this file.
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
6
7#include <math.h>
8#include <optional>
9#include <type_traits>
10
13#include "flutter/fml/logging.h"
14
15#include "third_party/skia/include/core/SkColorFilter.h"
16
17namespace flutter {
18
19// clang-format off
20constexpr float kInvertColorMatrix[20] = {
21 -1.0, 0, 0, 1.0, 0,
22 0, -1.0, 0, 1.0, 0,
23 0, 0, -1.0, 1.0, 0,
24 1.0, 1.0, 1.0, 1.0, 0
25};
26// clang-format on
27
28void DlSkPaintDispatchHelper::save_opacity(SkScalar child_opacity) {
29 save_stack_.emplace_back(opacity_);
30 set_opacity(child_opacity);
31}
33 if (save_stack_.empty()) {
34 return;
35 }
36 set_opacity(save_stack_.back().opacity);
37 save_stack_.pop_back();
38}
39
41 paint_.setAntiAlias(aa);
42}
44 invert_colors_ = invert;
45 paint_.setColorFilter(makeColorFilter());
46}
48 paint_.setStrokeCap(ToSk(cap));
49}
51 paint_.setStrokeJoin(ToSk(join));
52}
54 paint_.setStyle(ToSk(style));
55}
57 paint_.setStrokeWidth(width);
58}
60 paint_.setStrokeMiter(limit);
61}
63 current_color_ = color;
64 paint_.setColor(ToSkColor4f(color));
65 if (has_opacity()) {
66 paint_.setAlphaf(paint_.getAlphaf() * opacity());
67 }
68}
70 paint_.setBlendMode(ToSk(mode));
71}
73 // On the Impeller backend, we only support dithering of *gradients*, and
74 // so we need to set the dither flag whenever we render a gradient.
75 //
76 // In this method we can determine whether or not the source is a gradient,
77 // but we don't have the other half of the information which is what
78 // rendering op is being performed. So, we simply record whether the
79 // source is a gradient here and let the |paint()| method figure out
80 // the rest (i.e. whether the color source will be used).
81 color_source_gradient_ = source && source->isGradient();
82 paint_.setShader(ToSk(source));
83}
85 paint_.setImageFilter(ToSk(filter));
86}
88 sk_color_filter_ = ToSk(filter);
89 paint_.setColorFilter(makeColorFilter());
90}
92 paint_.setMaskFilter(ToSk(filter));
93}
94
95sk_sp<SkColorFilter> DlSkPaintDispatchHelper::makeColorFilter() const {
96 if (!invert_colors_) {
97 return sk_color_filter_;
98 }
99 sk_sp<SkColorFilter> invert_filter =
100 SkColorFilters::Matrix(kInvertColorMatrix);
101 if (sk_color_filter_) {
102 invert_filter = invert_filter->makeComposed(sk_color_filter_);
103 }
104 return invert_filter;
105}
106
107} // namespace flutter
virtual bool isGradient() const
If the underlying platform data represents a gradient.
void setStrokeMiter(SkScalar limit) override
void setDrawStyle(DlDrawStyle style) override
void setMaskFilter(const DlMaskFilter *filter) override
void setColorFilter(const DlColorFilter *filter) override
void setStrokeCap(DlStrokeCap cap) override
void setBlendMode(DlBlendMode mode) override
void setColorSource(const DlColorSource *source) override
void setStrokeWidth(SkScalar width) override
void save_opacity(SkScalar opacity_for_children)
void setImageFilter(const DlImageFilter *filter) override
void setColor(DlColor color) override
void setInvertColors(bool invert) override
void setStrokeJoin(DlStrokeJoin join) override
SkPaint ToSk(const DlPaint &paint)
DlStrokeJoin
Definition dl_paint.h:37
DlStrokeCap
Definition dl_paint.h:28
SkColor4f ToSkColor4f(DlColor color)
DlDrawStyle
Definition dl_paint.h:19
constexpr float kInvertColorMatrix[20]
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
BlendMode
Definition color.h:58
int32_t width