Flutter Engine
The Flutter Engine
SkSGPaint.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
13
14#include <utility>
15
16class SkMatrix;
17
18namespace sksg {
19
20// Paint nodes don't generate damage on their own, but via their aggregation ancestor Draw nodes.
21PaintNode::PaintNode() : INHERITED(kBubbleDamage_Trait) {}
22
24 SkASSERT(!this->hasInval());
25
27
28 paint.setAntiAlias(fAntiAlias);
29 paint.setBlendMode(fBlendMode);
30 paint.setStyle(fStyle);
31 paint.setStrokeWidth(fStrokeWidth);
32 paint.setStrokeMiter(fStrokeMiter);
33 paint.setStrokeJoin(fStrokeJoin);
34 paint.setStrokeCap(fStrokeCap);
35
36 this->onApplyToPaint(&paint);
37
38 // Compose opacity on top of the subclass value.
39 paint.setAlpha(SkScalarRoundToInt(paint.getAlpha() * SkTPin<SkScalar>(fOpacity, 0, 1)));
40
41 return paint;
42}
43
45 return sk_sp<Color>(new Color(c));
46}
47
48Color::Color(SkColor c) : fColor(c) {}
49
51 SkASSERT(this->hasInval());
52
53 return SkRect::MakeEmpty();
54}
55
57 paint->setColor(fColor);
58}
59
61 return sh ? sk_sp<ShaderPaint>(new ShaderPaint(std::move(sh)))
62 : nullptr;
63}
64
65ShaderPaint::ShaderPaint(sk_sp<Shader> sh)
66 : fShader(std::move(sh)) {
67 this->observeInval(fShader);
68}
69
71 this->unobserveInval(fShader);
72}
73
75 SkASSERT(this->hasInval());
76
77 return fShader->revalidate(ic, ctm);
78}
79
81 paint->setShader(fShader->getShader());
82}
83
84} // namespace sksg
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint32_t SkColor
Definition: SkColor.h:37
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition: SkSGPaint.cpp:50
void onApplyToPaint(SkPaint *) const override
Definition: SkSGPaint.cpp:56
static sk_sp< Color > Make(SkColor c)
Definition: SkSGPaint.cpp:44
void observeInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:61
void unobserveInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:84
bool hasInval() const
Definition: SkSGNode.h:60
SkPaint makePaint() const
Definition: SkSGPaint.cpp:23
virtual void onApplyToPaint(SkPaint *) const =0
~ShaderPaint() override
Definition: SkSGPaint.cpp:70
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition: SkSGPaint.cpp:74
static sk_sp< ShaderPaint > Make(sk_sp< Shader >)
Definition: SkSGPaint.cpp:60
void onApplyToPaint(SkPaint *) const override
Definition: SkSGPaint.cpp:80
const Paint & paint
Definition: color_source.cc:38
sh
Definition: run_sh.py:10
Definition: Skottie.h:32
Definition: ref_ptr.h:256
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595