Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: experimental/svg/model/SkSVGRenderContext.h

Issue 2222793002: [SVGDom] Add <svg> viewBox support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: typo Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/svg/model/SkSVGRect.cpp ('k') | experimental/svg/model/SkSVGRenderContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
89 // The save count on 'fCanvas' at construction time.
90 // A restoreToCount() will be issued on destruction.
91 int fCanvasSaveCount;
57 }; 92 };
58 93
59 #endif // SkSVGRenderContext_DEFINED 94 #endif // SkSVGRenderContext_DEFINED
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGRect.cpp ('k') | experimental/svg/model/SkSVGRenderContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698