| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkSVGRenderContext_DEFINED | 8 #ifndef SkSVGRenderContext_DEFINED |
| 9 #define SkSVGRenderContext_DEFINED | 9 #define SkSVGRenderContext_DEFINED |
| 10 | 10 |
| 11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
| 12 #include "SkRect.h" | 12 #include "SkRect.h" |
| 13 #include "SkSize.h" | 13 #include "SkSize.h" |
| 14 #include "SkSVGAttribute.h" |
| 14 #include "SkTLazy.h" | 15 #include "SkTLazy.h" |
| 15 #include "SkTypes.h" | 16 #include "SkTypes.h" |
| 16 | 17 |
| 17 class SkCanvas; | 18 class SkCanvas; |
| 18 class SkSVGLength; | 19 class SkSVGLength; |
| 19 | 20 |
| 20 class SkSVGLengthContext { | 21 class SkSVGLengthContext { |
| 21 public: | 22 public: |
| 22 SkSVGLengthContext(const SkSize& viewport) : fViewport(viewport) {} | 23 SkSVGLengthContext(const SkSize& viewport) : fViewport(viewport) {} |
| 23 | 24 |
| 24 enum class LengthType { | 25 enum class LengthType { |
| 25 kHorizontal, | 26 kHorizontal, |
| 26 kVertical, | 27 kVertical, |
| 27 kOther, | 28 kOther, |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 const SkSize& viewPort() const { return fViewport; } | 31 const SkSize& viewPort() const { return fViewport; } |
| 31 void setViewPort(const SkSize& viewport) { fViewport = viewport; } | 32 void setViewPort(const SkSize& viewport) { fViewport = viewport; } |
| 32 | 33 |
| 33 SkScalar resolve(const SkSVGLength&, LengthType) const; | 34 SkScalar resolve(const SkSVGLength&, LengthType) const; |
| 34 SkRect resolveRect(const SkSVGLength& x, const SkSVGLength& y, | 35 SkRect resolveRect(const SkSVGLength& x, const SkSVGLength& y, |
| 35 const SkSVGLength& w, const SkSVGLength& h) const; | 36 const SkSVGLength& w, const SkSVGLength& h) const; |
| 36 | 37 |
| 37 private: | 38 private: |
| 38 SkSize fViewport; | 39 SkSize fViewport; |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 class SkSVGPresentationContext { | 42 struct SkSVGPresentationContext { |
| 42 public: | |
| 43 SkSVGPresentationContext(); | 43 SkSVGPresentationContext(); |
| 44 SkSVGPresentationContext(const SkSVGPresentationContext&); | 44 SkSVGPresentationContext(const SkSVGPresentationContext&) = defau
lt; |
| 45 SkSVGPresentationContext& operator=(const SkSVGPresentationContext&); | 45 SkSVGPresentationContext& operator=(const SkSVGPresentationContext&) = defau
lt; |
| 46 | 46 |
| 47 const SkPaint* fillPaint() const { return fFill.getMaybeNull(); } | 47 // Inherited presentation attributes, computed for the current node. |
| 48 const SkPaint* strokePaint() const { return fStroke.getMaybeNull(); } | 48 SkSVGPresentationAttributes fInherited; |
| 49 | 49 |
| 50 void setFillColor(SkColor); | 50 // Cached paints, reflecting the current presentation attributes. |
| 51 void setStrokeColor(SkColor); | 51 SkPaint fFillPaint; |
| 52 | 52 SkPaint fStrokePaint; |
| 53 private: | |
| 54 void initFrom(const SkSVGPresentationContext&); | |
| 55 | |
| 56 SkPaint& ensureFill(); | |
| 57 SkPaint& ensureStroke(); | |
| 58 | |
| 59 // TODO: convert to regular SkPaints and track explicit attribute values ins
tead. | |
| 60 SkTLazy<SkPaint> fFill; | |
| 61 SkTLazy<SkPaint> fStroke; | |
| 62 }; | 53 }; |
| 63 | 54 |
| 64 class SkSVGRenderContext { | 55 class SkSVGRenderContext { |
| 65 public: | 56 public: |
| 66 SkSVGRenderContext(SkCanvas*, const SkSVGLengthContext&, const SkSVGPresenta
tionContext&); | 57 SkSVGRenderContext(SkCanvas*, const SkSVGLengthContext&, const SkSVGPresenta
tionContext&); |
| 67 SkSVGRenderContext(const SkSVGRenderContext&); | 58 SkSVGRenderContext(const SkSVGRenderContext&); |
| 68 ~SkSVGRenderContext(); | 59 ~SkSVGRenderContext(); |
| 69 | 60 |
| 70 const SkSVGLengthContext& lengthContext() const { return *fLengthContext; } | 61 const SkSVGLengthContext& lengthContext() const { return *fLengthContext; } |
| 71 SkSVGLengthContext* writableLengthContext() { return fLengthContext.writable
(); } | 62 SkSVGLengthContext* writableLengthContext() { return fLengthContext.writable
(); } |
| 72 | 63 |
| 73 const SkSVGPresentationContext& presentationContext() const { return *fPrese
ntationContext; } | 64 SkCanvas* canvas() const { return fCanvas; } |
| 74 SkSVGPresentationContext* writablePresentationContext() { | |
| 75 return fPresentationContext.writable(); | |
| 76 } | |
| 77 | 65 |
| 78 SkCanvas* canvas() const { return fCanvas; } | 66 void applyPresentationAttributes(const SkSVGPresentationAttributes&); |
| 67 |
| 68 const SkPaint* fillPaint() const; |
| 69 const SkPaint* strokePaint() const; |
| 79 | 70 |
| 80 private: | 71 private: |
| 81 // Stack-only | 72 // Stack-only |
| 82 void* operator new(size_t) = delete; | 73 void* operator new(size_t) = delete; |
| 83 void* operator new(size_t, void*) = delete; | 74 void* operator new(size_t, void*) = delete; |
| 84 SkSVGRenderContext& operator=(const SkSVGRenderContext&) = delete; | 75 SkSVGRenderContext& operator=(const SkSVGRenderContext&) = delete; |
| 85 | 76 |
| 86 SkTCopyOnFirstWrite<SkSVGLengthContext> fLengthContext; | 77 SkTCopyOnFirstWrite<SkSVGLengthContext> fLengthContext; |
| 87 SkTCopyOnFirstWrite<SkSVGPresentationContext> fPresentationContext; | 78 SkTCopyOnFirstWrite<SkSVGPresentationContext> fPresentationContext; |
| 88 SkCanvas* fCanvas; | 79 SkCanvas* fCanvas; |
| 89 // The save count on 'fCanvas' at construction time. | 80 // The save count on 'fCanvas' at construction time. |
| 90 // A restoreToCount() will be issued on destruction. | 81 // A restoreToCount() will be issued on destruction. |
| 91 int fCanvasSaveCount; | 82 int fCanvasSaveCount; |
| 92 }; | 83 }; |
| 93 | 84 |
| 94 #endif // SkSVGRenderContext_DEFINED | 85 #endif // SkSVGRenderContext_DEFINED |
| OLD | NEW |