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