blob: fc89cd0e0b37ad7614ee569b76dd71064813f592 [file] [log] [blame]
Florin Malitafb4bce82019-04-01 13:40:58 -04001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "modules/sksg/include/SkSGPaint.h"
Florin Malitafb4bce82019-04-01 13:40:58 -04009
Mike Klein8aa0edf2020-10-16 11:04:18 -050010#include "include/private/SkTPin.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "modules/sksg/include/SkSGRenderEffect.h"
Florin Malitafb4bce82019-04-01 13:40:58 -040012
13namespace sksg {
14
15// Paint nodes don't generate damage on their own, but via their aggregation ancestor Draw nodes.
16PaintNode::PaintNode() : INHERITED(kBubbleDamage_Trait) {}
17
18SkPaint PaintNode::makePaint() const {
19 SkASSERT(!this->hasInval());
20
21 SkPaint paint;
22
23 paint.setAntiAlias(fAntiAlias);
24 paint.setBlendMode(fBlendMode);
25 paint.setStyle(fStyle);
26 paint.setStrokeWidth(fStrokeWidth);
27 paint.setStrokeMiter(fStrokeMiter);
28 paint.setStrokeJoin(fStrokeJoin);
29 paint.setStrokeCap(fStrokeCap);
30
31 this->onApplyToPaint(&paint);
32
33 // Compose opacity on top of the subclass value.
34 paint.setAlpha(SkScalarRoundToInt(paint.getAlpha() * SkTPin<SkScalar>(fOpacity, 0, 1)));
35
36 return paint;
37}
38
39sk_sp<Color> Color::Make(SkColor c) {
40 return sk_sp<Color>(new Color(c));
41}
42
43Color::Color(SkColor c) : fColor(c) {}
44
45SkRect Color::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
46 SkASSERT(this->hasInval());
47
48 return SkRect::MakeEmpty();
49}
50
51void Color::onApplyToPaint(SkPaint* paint) const {
52 paint->setColor(fColor);
53}
54
55sk_sp<ShaderPaint> ShaderPaint::Make(sk_sp<Shader> sh) {
56 return sh ? sk_sp<ShaderPaint>(new ShaderPaint(std::move(sh)))
57 : nullptr;
58}
59
60ShaderPaint::ShaderPaint(sk_sp<Shader> sh)
61 : fShader(std::move(sh)) {
62 this->observeInval(fShader);
63}
64
65ShaderPaint::~ShaderPaint() {
66 this->unobserveInval(fShader);
67}
68
69SkRect ShaderPaint::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
70 SkASSERT(this->hasInval());
71
72 return fShader->revalidate(ic, ctm);
73}
74
75void ShaderPaint::onApplyToPaint(SkPaint* paint) const {
76 paint->setShader(fShader->getShader());
77}
78
79} // namespace sksg