Flutter Engine
The Flutter Engine
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
5#include "flutter/display_list/skia/dl_sk_paint_dispatcher.h"
6
7#include <math.h>
8#include <optional>
9#include <type_traits>
10
11#include "flutter/display_list/dl_blend_mode.h"
12#include "flutter/display_list/skia/dl_sk_conversions.h"
13#include "flutter/fml/logging.h"
14
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
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_ = ToSk(color);
64 paint_.setColor(ToSk(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 =
101 if (sk_color_filter_) {
102 invert_filter = invert_filter->makeComposed(sk_color_filter_);
103 }
104 return invert_filter;
105}
106
107} // namespace flutter
sk_sp< SkColorFilter > makeComposed(sk_sp< SkColorFilter > inner) const
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setStrokeMiter(SkScalar miter)
Definition: SkPaint.cpp:169
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
void setStrokeJoin(Join join)
Definition: SkPaint.cpp:189
void setMaskFilter(sk_sp< SkMaskFilter > maskFilter)
void setShader(sk_sp< SkShader > shader)
float getAlphaf() const
Definition: SkPaint.h:261
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
void setColorFilter(sk_sp< SkColorFilter > colorFilter)
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
void setAlphaf(float a)
Definition: SkPaint.cpp:130
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
DlColor color
SkBitmap source
Definition: examples.cpp:28
float SkScalar
Definition: extension.cpp:12
gboolean invert
SkPaint ToSk(const DlPaint &paint)
DlStrokeJoin
Definition: dl_paint.h:37
DlStrokeCap
Definition: dl_paint.h:28
DlDrawStyle
Definition: dl_paint.h:19
constexpr float kInvertColorMatrix[20]
it will be possible to load the file into Perfetto s trace viewer 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
Definition: switches.h:228
int32_t width
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741