Florin Malita | fb4bce8 | 2019-04-01 13:40:58 -0400 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "modules/sksg/include/SkSGPaint.h" |
Florin Malita | fb4bce8 | 2019-04-01 13:40:58 -0400 | [diff] [blame] | 9 | |
Mike Klein | 8aa0edf | 2020-10-16 11:04:18 -0500 | [diff] [blame] | 10 | #include "include/private/SkTPin.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "modules/sksg/include/SkSGRenderEffect.h" |
Florin Malita | fb4bce8 | 2019-04-01 13:40:58 -0400 | [diff] [blame] | 12 | |
| 13 | namespace sksg { |
| 14 | |
| 15 | // Paint nodes don't generate damage on their own, but via their aggregation ancestor Draw nodes. |
| 16 | PaintNode::PaintNode() : INHERITED(kBubbleDamage_Trait) {} |
| 17 | |
| 18 | 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 | |
| 39 | sk_sp<Color> Color::Make(SkColor c) { |
| 40 | return sk_sp<Color>(new Color(c)); |
| 41 | } |
| 42 | |
| 43 | Color::Color(SkColor c) : fColor(c) {} |
| 44 | |
| 45 | SkRect Color::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { |
| 46 | SkASSERT(this->hasInval()); |
| 47 | |
| 48 | return SkRect::MakeEmpty(); |
| 49 | } |
| 50 | |
| 51 | void Color::onApplyToPaint(SkPaint* paint) const { |
| 52 | paint->setColor(fColor); |
| 53 | } |
| 54 | |
| 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 | |
| 60 | ShaderPaint::ShaderPaint(sk_sp<Shader> sh) |
| 61 | : fShader(std::move(sh)) { |
| 62 | this->observeInval(fShader); |
| 63 | } |
| 64 | |
| 65 | ShaderPaint::~ShaderPaint() { |
| 66 | this->unobserveInval(fShader); |
| 67 | } |
| 68 | |
| 69 | SkRect ShaderPaint::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { |
| 70 | SkASSERT(this->hasInval()); |
| 71 | |
| 72 | return fShader->revalidate(ic, ctm); |
| 73 | } |
| 74 | |
| 75 | void ShaderPaint::onApplyToPaint(SkPaint* paint) const { |
| 76 | paint->setShader(fShader->getShader()); |
| 77 | } |
| 78 | |
| 79 | } // namespace sksg |