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