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" | |
12 #include "SkRect.h" | |
11 #include "SkSize.h" | 13 #include "SkSize.h" |
12 #include "SkPaint.h" | |
13 #include "SkTLazy.h" | 14 #include "SkTLazy.h" |
15 #include "SkTypes.h" | |
14 | 16 |
15 class SkPaint; | 17 class SkCanvas; |
16 class SkSVGLength; | 18 class SkSVGLength; |
17 | 19 |
18 class SkSVGLengthContext { | 20 class SkSVGLengthContext { |
19 public: | 21 public: |
20 SkSVGLengthContext(const SkSize& viewport) : fViewport(viewport) {} | 22 SkSVGLengthContext(const SkSize& viewport) : fViewport(viewport) {} |
21 | 23 |
22 enum class LengthType { | 24 enum class LengthType { |
23 kHorizontal, | 25 kHorizontal, |
24 kVertical, | 26 kVertical, |
25 kOther, | 27 kOther, |
26 }; | 28 }; |
27 | 29 |
30 const SkSize& viewPort() const { return fViewport; } | |
28 void setViewPort(const SkSize& viewport) { fViewport = viewport; } | 31 void setViewPort(const SkSize& viewport) { fViewport = viewport; } |
29 | 32 |
30 SkScalar resolve(const SkSVGLength&, LengthType) const; | 33 SkScalar resolve(const SkSVGLength&, LengthType) const; |
34 SkRect resolveRect(const SkSVGLength& x, const SkSVGLength& y, | |
35 const SkSVGLength& w, const SkSVGLength& h) const; | |
31 | 36 |
32 private: | 37 private: |
33 SkSize fViewport; | 38 SkSize fViewport; |
34 }; | 39 }; |
35 | 40 |
36 class SkSVGRenderContext { | 41 class SkSVGPresentationContext { |
37 public: | 42 public: |
38 explicit SkSVGRenderContext(const SkSize& initialViewport); | 43 SkSVGPresentationContext(); |
39 SkSVGRenderContext(const SkSVGRenderContext&) = default; | 44 SkSVGPresentationContext(const SkSVGPresentationContext&); |
40 SkSVGRenderContext& operator=(const SkSVGRenderContext&); | 45 SkSVGPresentationContext& operator=(const SkSVGPresentationContext&); |
41 | |
42 const SkSVGLengthContext& lengthContext() const { return fLengthContext; } | |
43 | 46 |
44 const SkPaint* fillPaint() const { return fFill.getMaybeNull(); } | 47 const SkPaint* fillPaint() const { return fFill.getMaybeNull(); } |
45 const SkPaint* strokePaint() const { return fStroke.getMaybeNull(); } | 48 const SkPaint* strokePaint() const { return fStroke.getMaybeNull(); } |
46 | 49 |
47 void setFillColor(SkColor); | 50 void setFillColor(SkColor); |
48 void setStrokeColor(SkColor); | 51 void setStrokeColor(SkColor); |
49 | 52 |
50 private: | 53 private: |
54 void initFrom(const SkSVGPresentationContext&); | |
55 | |
51 SkPaint& ensureFill(); | 56 SkPaint& ensureFill(); |
52 SkPaint& ensureStroke(); | 57 SkPaint& ensureStroke(); |
53 | 58 |
54 SkSVGLengthContext fLengthContext; | 59 // TODO: convert to regular SkPaints and track explicit attribute values ins tead. |
55 SkTLazy<SkPaint> fFill; | 60 SkTLazy<SkPaint> fFill; |
56 SkTLazy<SkPaint> fStroke; | 61 SkTLazy<SkPaint> fStroke; |
62 }; | |
63 | |
64 class SkSVGRenderContext { | |
65 public: | |
66 SkSVGRenderContext(SkCanvas*, const SkSVGLengthContext&, const SkSVGPresenta tionContext&); | |
67 SkSVGRenderContext(const SkSVGRenderContext&); | |
68 ~SkSVGRenderContext(); | |
69 | |
70 const SkSVGLengthContext& lengthContext() const { return *fLengthContext; } | |
71 SkSVGLengthContext* writableLengthContext() { return fLengthContext.writable (); } | |
72 | |
73 const SkSVGPresentationContext& presentationContext() const { return *fPrese ntationContext; } | |
74 SkSVGPresentationContext* writablePresentationContext() { | |
75 return fPresentationContext.writable(); | |
76 } | |
77 | |
78 SkCanvas* canvas() const { return fCanvas; } | |
79 | |
80 private: | |
81 // Stack-only | |
82 void* operator new(size_t) = delete; | |
83 void* operator new(size_t, void*) = delete; | |
84 SkSVGRenderContext& operator=(const SkSVGRenderContext&) = delete; | |
85 | |
86 SkTCopyOnFirstWrite<SkSVGLengthContext> fLengthContext; | |
87 SkTCopyOnFirstWrite<SkSVGPresentationContext> fPresentationContext; | |
88 SkCanvas* fCanvas; | |
robertphillips
2016/08/08 13:55:28
// This is the save count on 'fCanvas' at construc
f(malita)
2016/08/08 17:13:29
Done.
| |
89 int fCanvasSaveCount; | |
57 }; | 90 }; |
58 | 91 |
59 #endif // SkSVGRenderContext_DEFINED | 92 #endif // SkSVGRenderContext_DEFINED |
OLD | NEW |