Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dl_sk_paint_dispatcher.h
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#ifndef FLUTTER_DISPLAY_LIST_SKIA_DL_SK_PAINT_DISPATCHER_H_
6#define FLUTTER_DISPLAY_LIST_SKIA_DL_SK_PAINT_DISPATCHER_H_
7
8#include "flutter/display_list/dl_op_receiver.h"
9#include "flutter/display_list/skia/dl_sk_types.h"
10
11namespace flutter {
12
13// A utility class that will monitor the DlOpReceiver methods relating
14// to the rendering attributes and accumulate them into an SkPaint
15// which can be accessed at any time via paint().
16class DlSkPaintDispatchHelper : public virtual DlOpReceiver {
17 public:
19 : current_color_(SK_ColorBLACK), opacity_(opacity) {
20 if (opacity < SK_Scalar1) {
21 paint_.setAlphaf(opacity);
22 }
23 }
24
25 void setAntiAlias(bool aa) override;
26 void setDrawStyle(DlDrawStyle style) override;
27 void setColor(DlColor color) override;
28 void setStrokeWidth(SkScalar width) override;
29 void setStrokeMiter(SkScalar limit) override;
30 void setStrokeCap(DlStrokeCap cap) override;
31 void setStrokeJoin(DlStrokeJoin join) override;
32 void setColorSource(const DlColorSource* source) override;
33 void setColorFilter(const DlColorFilter* filter) override;
34 void setInvertColors(bool invert) override;
35 void setBlendMode(DlBlendMode mode) override;
36 void setPathEffect(const DlPathEffect* effect) override;
37 void setMaskFilter(const DlMaskFilter* filter) override;
38 void setImageFilter(const DlImageFilter* filter) override;
39
40 const SkPaint& paint(bool uses_shader = true) {
41 // On the Impeller backend, we will only support dithering of *gradients*,
42 // and it will be enabled by default (without the option to disable it).
43 // Until Skia support is completely removed, we only want to respect the
44 // dither flag for gradients (otherwise it will also apply to, for
45 // example, image ops and image sources, which are not dithered in
46 // Impeller) and only on those operations that use the color source.
47 //
48 // The color_source_gradient_ flag lets us know if the color source is
49 // a gradient and then the uses_shader flag passed in to this method by
50 // the rendering op lets us know if the color source is used (and is
51 // therefore the primary source of colors for the op).
52 //
53 // See https://github.com/flutter/flutter/issues/112498.
54 paint_.setDither(uses_shader && color_source_gradient_);
55 return paint_;
56 }
57 /// Returns the current opacity attribute which is used to reduce
58 /// the alpha of all setColor calls encountered in the streeam
59 SkScalar opacity() { return opacity_; }
60 /// Returns the combined opacity that includes both the current
61 /// opacity attribute and the alpha of the most recent color.
62 /// The most recently set color will have combined the two and
63 /// stored the combined value in the alpha of the paint.
64 SkScalar combined_opacity() { return paint_.getAlphaf(); }
65 /// Returns true iff the current opacity attribute is not opaque,
66 /// irrespective of the alpha of the current color
67 bool has_opacity() { return opacity_ < SK_Scalar1; }
68
69 protected:
70 void save_opacity(SkScalar opacity_for_children);
71 void restore_opacity();
72
73 private:
74 SkPaint paint_;
75 bool color_source_gradient_ = false;
76 bool invert_colors_ = false;
77 sk_sp<SkColorFilter> sk_color_filter_;
78
79 sk_sp<SkColorFilter> makeColorFilter() const;
80
81 struct SaveInfo {
82 explicit SaveInfo(SkScalar opacity) : opacity(opacity) {}
83
84 SkScalar opacity;
85 };
86 std::vector<SaveInfo> save_stack_;
87
88 void set_opacity(SkScalar opacity) {
89 if (opacity_ != opacity) {
90 opacity_ = opacity;
91 setColor(DlColor(current_color_));
92 }
93 }
94
95 SkColor current_color_;
96 SkScalar opacity_;
97};
98
99} // namespace flutter
100
101#endif // FLUTTER_DISPLAY_LIST_SKIA_DL_SK_PAINT_DISPATCHER_H_
SkColor4f color
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
#define SK_Scalar1
Definition SkScalar.h:18
void setDither(bool dither)
Definition SkPaint.h:182
float getAlphaf() const
Definition SkPaint.h:261
void setAlphaf(float a)
Definition SkPaint.cpp:130
Internal API for rendering recorded display lists to backends.
void setStrokeMiter(SkScalar limit) override
void setDrawStyle(DlDrawStyle style) override
void setMaskFilter(const DlMaskFilter *filter) override
void setColorFilter(const DlColorFilter *filter) override
DlSkPaintDispatchHelper(SkScalar opacity=SK_Scalar1)
void setPathEffect(const DlPathEffect *effect) override
const SkPaint & paint(bool uses_shader=true)
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
SkBitmap source
Definition examples.cpp:28
float SkScalar
Definition extension.cpp:12
gboolean invert
DlStrokeJoin
Definition dl_paint.h:38
DlStrokeCap
Definition dl_paint.h:29
DlDrawStyle
Definition dl_paint.h: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