• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/private/SkTPin.h"
11 #include "modules/sksg/include/SkSGRenderEffect.h"
12 
13 namespace sksg {
14 
15 // Paint nodes don't generate damage on their own, but via their aggregation ancestor Draw nodes.
PaintNode()16 PaintNode::PaintNode() : INHERITED(kBubbleDamage_Trait) {}
17 
makePaint() const18 SkPaint 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 
Make(SkColor c)39 sk_sp<Color> Color::Make(SkColor c) {
40     return sk_sp<Color>(new Color(c));
41 }
42 
Color(SkColor c)43 Color::Color(SkColor c) : fColor(c) {}
44 
onRevalidate(InvalidationController * ic,const SkMatrix & ctm)45 SkRect Color::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
46     SkASSERT(this->hasInval());
47 
48     return SkRect::MakeEmpty();
49 }
50 
onApplyToPaint(SkPaint * paint) const51 void Color::onApplyToPaint(SkPaint* paint) const {
52     paint->setColor(fColor);
53 }
54 
Make(sk_sp<Shader> sh)55 sk_sp<ShaderPaint> ShaderPaint::Make(sk_sp<Shader> sh) {
56     return sh ? sk_sp<ShaderPaint>(new ShaderPaint(std::move(sh)))
57               : nullptr;
58 }
59 
ShaderPaint(sk_sp<Shader> sh)60 ShaderPaint::ShaderPaint(sk_sp<Shader> sh)
61     : fShader(std::move(sh)) {
62     this->observeInval(fShader);
63 }
64 
~ShaderPaint()65 ShaderPaint::~ShaderPaint() {
66     this->unobserveInval(fShader);
67 }
68 
onRevalidate(InvalidationController * ic,const SkMatrix & ctm)69 SkRect ShaderPaint::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
70     SkASSERT(this->hasInval());
71 
72     return fShader->revalidate(ic, ctm);
73 }
74 
onApplyToPaint(SkPaint * paint) const75 void ShaderPaint::onApplyToPaint(SkPaint* paint) const {
76     paint->setShader(fShader->getShader());
77 }
78 
79 } // namespace sksg
80