OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CanvasRenderingContext2DState_h | 5 #ifndef CanvasRenderingContext2DState_h |
6 #define CanvasRenderingContext2DState_h | 6 #define CanvasRenderingContext2DState_h |
7 | 7 |
8 #include "core/css/CSSFontSelectorClient.h" | 8 #include "core/css/CSSFontSelectorClient.h" |
9 #include "core/html/canvas/ClipList.h" | 9 #include "core/html/canvas/ClipList.h" |
10 #include "platform/fonts/Font.h" | 10 #include "platform/fonts/Font.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 virtual void fontsNeedUpdate(CSSFontSelector*) override; | 34 virtual void fontsNeedUpdate(CSSFontSelector*) override; |
35 | 35 |
36 bool hasUnrealizedSaves() const { return m_unrealizedSaveCount; } | 36 bool hasUnrealizedSaves() const { return m_unrealizedSaveCount; } |
37 void save() { ++m_unrealizedSaveCount; } | 37 void save() { ++m_unrealizedSaveCount; } |
38 void restore() { --m_unrealizedSaveCount; } | 38 void restore() { --m_unrealizedSaveCount; } |
39 void resetUnrealizedSaveCount() { m_unrealizedSaveCount = 0; } | 39 void resetUnrealizedSaveCount() { m_unrealizedSaveCount = 0; } |
40 | 40 |
41 void setLineDash(const Vector<float>&); | 41 void setLineDash(const Vector<float>&); |
42 const Vector<float>& lineDash() const { return m_lineDash; } | 42 const Vector<float>& lineDash() const { return m_lineDash; } |
43 | 43 |
44 void setLineDashOffset(float offset) { m_lineDashOffset = offset; } | 44 void setLineDashOffset(float); |
45 float lineDashOffset() const { return m_lineDashOffset; } | 45 float lineDashOffset() const { return m_lineDashOffset; } |
46 | 46 |
47 // setTransform returns true iff transform is invertible; | 47 // setTransform returns true iff transform is invertible; |
48 void setTransform(const AffineTransform&); | 48 void setTransform(const AffineTransform&); |
49 void resetTransform(); | 49 void resetTransform(); |
50 AffineTransform transform() const { return m_transform; } | 50 AffineTransform transform() const { return m_transform; } |
51 bool isTransformInvertible() const { return m_isTransformInvertible; } | 51 bool isTransformInvertible() const { return m_isTransformInvertible; } |
52 | 52 |
53 void clipPath(const SkPath&, AntiAliasingMode); | 53 void clipPath(const SkPath&, AntiAliasingMode); |
54 bool hasClip() const { return m_hasClip; } | 54 bool hasClip() const { return m_hasClip; } |
55 bool hasComplexClip() const { return m_hasComplexClip; } | 55 bool hasComplexClip() const { return m_hasComplexClip; } |
56 void playbackClips(SkCanvas* canvas) const { m_clipList.playback(canvas); } | 56 void playbackClips(SkCanvas* canvas) const { m_clipList.playback(canvas); } |
57 | 57 |
58 void setFont(const Font&, CSSFontSelector*); | 58 void setFont(const Font&, CSSFontSelector*); |
59 const Font& font() const; | 59 const Font& font() const; |
60 bool hasRealizedFont() const { return m_realizedFont; } | 60 bool hasRealizedFont() const { return m_realizedFont; } |
61 void setUnparsedFont(const String& font) { m_unparsedFont = font; } | 61 void setUnparsedFont(const String& font) { m_unparsedFont = font; } |
62 const String& unparsedFont() const { return m_unparsedFont; } | 62 const String& unparsedFont() const { return m_unparsedFont; } |
63 | 63 |
64 void setStrokeStyle(PassRefPtrWillBeRawPtr<CanvasStyle> style) { m_strokeSty le = style; } | 64 void setStrokeStyle(PassRefPtrWillBeRawPtr<CanvasStyle>); |
65 CanvasStyle* strokeStyle() const { return m_strokeStyle.get(); } | 65 CanvasStyle* strokeStyle() const { return m_strokeStyle.get(); } |
66 | 66 |
67 void setFillStyle(PassRefPtrWillBeRawPtr<CanvasStyle> style) { m_fillStyle = style; } | 67 void setFillStyle(PassRefPtrWillBeRawPtr<CanvasStyle>); |
68 CanvasStyle* fillStyle() const { return m_fillStyle.get(); } | 68 CanvasStyle* fillStyle() const { return m_fillStyle.get(); } |
69 | 69 |
70 enum Direction { | 70 enum Direction { |
71 DirectionInherit, | 71 DirectionInherit, |
72 DirectionRTL, | 72 DirectionRTL, |
73 DirectionLTR | 73 DirectionLTR |
74 }; | 74 }; |
75 | 75 |
76 void setDirection(Direction direction) { m_direction = direction; } | 76 void setDirection(Direction direction) { m_direction = direction; } |
77 Direction direction() const { return m_direction; } | 77 Direction direction() const { return static_cast<Direction>(m_direction); } |
78 | 78 |
79 void setTextAlign(TextAlign align) { m_textAlign = align; } | 79 void setTextAlign(TextAlign align) { m_textAlign = align; } |
80 TextAlign textAlign() const { return m_textAlign; } | 80 TextAlign textAlign() const { return static_cast<TextAlign>(m_textAlign); } |
81 | 81 |
82 void setTextBaseline(TextBaseline baseline) { m_textBaseline = baseline; } | 82 void setTextBaseline(TextBaseline baseline) { m_textBaseline = baseline; } |
83 TextBaseline textBaseline() const { return m_textBaseline; } | 83 TextBaseline textBaseline() const { return static_cast<TextBaseline>(m_textB aseline); } |
84 | 84 |
85 void setLineWidth(float lineWidth) { m_lineWidth = lineWidth; } | 85 void setLineWidth(float lineWidth) { m_strokePaint.setStrokeWidth(lineWidth) ; } |
86 float lineWidth() const { return m_lineWidth; } | 86 float lineWidth() const { return m_strokePaint.getStrokeWidth(); } |
87 | 87 |
88 void setLineCap(LineCap lineCap) { m_lineCap = lineCap; } | 88 void setLineCap(LineCap lineCap) { m_strokePaint.setStrokeCap(static_cast<Sk Paint::Cap>(lineCap)); } |
89 LineCap lineCap() const { return m_lineCap; } | 89 LineCap lineCap() const { return static_cast<LineCap>(m_strokePaint.getStrok eCap()); } |
90 | 90 |
91 void setLineJoin(LineJoin lineJoin) { m_lineJoin = lineJoin; } | 91 void setLineJoin(LineJoin lineJoin) { m_strokePaint.setStrokeJoin(static_cas t<SkPaint::Join>(lineJoin)); } |
92 LineJoin lineJoin() const { return m_lineJoin; } | 92 LineJoin lineJoin() const { return static_cast<LineJoin>(m_strokePaint.getSt rokeJoin()); } |
93 | 93 |
94 void setMiterLimit(float miterLimit) { m_miterLimit = miterLimit; } | 94 void setMiterLimit(float miterLimit) { m_strokePaint.setStrokeMiter(miterLim it); } |
95 float miterLimit() const { return m_miterLimit; } | 95 float miterLimit() const { return m_strokePaint.getStrokeMiter(); } |
96 | 96 |
97 void setShadowOffsetX(float x) { m_shadowOffset.setWidth(x); } | 97 void setShadowOffsetX(float); |
98 void setShadowOffsetY(float y) { m_shadowOffset.setHeight(y); } | 98 void setShadowOffsetY(float); |
99 const FloatSize& shadowOffset() const { return m_shadowOffset; } | 99 const FloatSize& shadowOffset() const { return m_shadowOffset; } |
100 | 100 |
101 void setShadowBlur(float shadowBlur) { m_shadowBlur = shadowBlur; } | 101 void setShadowBlur(float); |
102 float shadowBlur() const { return m_shadowBlur; } | 102 float shadowBlur() const { return m_shadowBlur; } |
103 | 103 |
104 void setShadowColor(SkColor shadowColor) { m_shadowColor = shadowColor; } | 104 void setShadowColor(SkColor); |
105 SkColor shadowColor() const { return m_shadowColor; } | 105 SkColor shadowColor() const { return m_shadowColor; } |
106 | 106 |
107 void setGlobalAlpha(float alpha) { m_globalAlpha = alpha; } | 107 void setGlobalAlpha(float); |
108 float globalAlpha() const { return m_globalAlpha; } | 108 float globalAlpha() const { return m_globalAlpha; } |
109 | 109 |
110 void setGlobalComposite(SkXfermode::Mode mode) { m_globalComposite = mode; } | 110 void setGlobalComposite(SkXfermode::Mode); |
111 SkXfermode::Mode globalComposite() const { return m_globalComposite; } | 111 SkXfermode::Mode globalComposite() const; |
112 | 112 |
113 void setImageSmoothingEnabled(bool enabled) { m_imageSmoothingEnabled = enab led; } | 113 void setImageSmoothingEnabled(bool); |
114 bool imageSmoothingEnabled() const { return m_imageSmoothingEnabled; } | 114 bool imageSmoothingEnabled() const; |
115 | 115 |
116 void setUnparsedStrokeColor(const String& color) { m_unparsedStrokeColor = c olor; } | 116 void setUnparsedStrokeColor(const String& color) { m_unparsedStrokeColor = c olor; } |
117 const String& unparsedStrokeColor() const { return m_unparsedStrokeColor; } | 117 const String& unparsedStrokeColor() const { return m_unparsedStrokeColor; } |
118 | 118 |
119 void setUnparsedFillColor(const String& color) { m_unparsedFillColor = color ; } | 119 void setUnparsedFillColor(const String& color) { m_unparsedFillColor = color ; } |
120 const String& unparsedFillColor() const { return m_unparsedFillColor; } | 120 const String& unparsedFillColor() const { return m_unparsedFillColor; } |
121 | 121 |
122 bool shouldDrawShadows() const; | |
123 | |
124 const SkPaint* skPaint(CanvasPaintType, ShadowMode, CanvasShadowStrategy) co nst; | |
Stephen White
2015/03/18 22:09:34
Since this is more than just an accessor, maybe it
| |
125 | |
122 private: | 126 private: |
127 void updateLineDash() const; | |
128 void updateStrokeStyle() const; | |
129 void updateFillStyle() const; | |
130 void shadowParameterChanged(); | |
131 SkDrawLooper* emptyDrawLooper() const; | |
132 SkDrawLooper* shadowOnlyDrawLooper() const; | |
133 SkDrawLooper* shadowAndForegroundDrawLooper() const; | |
134 SkImageFilter* shadowOnlyImageFilter() const; | |
135 SkImageFilter* shadowAndForegroundImageFilter() const; | |
136 | |
123 unsigned m_unrealizedSaveCount; | 137 unsigned m_unrealizedSaveCount; |
124 | 138 |
125 String m_unparsedStrokeColor; | 139 String m_unparsedStrokeColor; |
126 String m_unparsedFillColor; | 140 String m_unparsedFillColor; |
127 RefPtrWillBeMember<CanvasStyle> m_strokeStyle; | 141 RefPtrWillBeMember<CanvasStyle> m_strokeStyle; |
128 RefPtrWillBeMember<CanvasStyle> m_fillStyle; | 142 RefPtrWillBeMember<CanvasStyle> m_fillStyle; |
129 | 143 |
130 float m_lineWidth; | 144 mutable SkPaint m_strokePaint; |
131 LineCap m_lineCap; | 145 mutable SkPaint m_fillPaint; |
132 LineJoin m_lineJoin; | 146 |
133 float m_miterLimit; | |
134 FloatSize m_shadowOffset; | 147 FloatSize m_shadowOffset; |
135 float m_shadowBlur; | 148 float m_shadowBlur; |
136 SkColor m_shadowColor; | 149 SkColor m_shadowColor; |
150 mutable RefPtr<SkDrawLooper> m_emptyDrawLooper; | |
151 mutable RefPtr<SkDrawLooper> m_shadowOnlyDrawLooper; | |
152 mutable RefPtr<SkDrawLooper> m_shadowAndForegroundDrawLooper; | |
153 mutable RefPtr<SkImageFilter> m_shadowOnlyImageFilter; | |
154 mutable RefPtr<SkImageFilter> m_shadowAndForegroundImageFilter; | |
155 | |
137 float m_globalAlpha; | 156 float m_globalAlpha; |
138 SkXfermode::Mode m_globalComposite; | |
139 AffineTransform m_transform; | 157 AffineTransform m_transform; |
140 bool m_isTransformInvertible; | |
141 Vector<float> m_lineDash; | 158 Vector<float> m_lineDash; |
142 float m_lineDashOffset; | 159 float m_lineDashOffset; |
143 bool m_imageSmoothingEnabled; | |
144 | |
145 // Text state. | |
146 TextAlign m_textAlign; | |
147 TextBaseline m_textBaseline; | |
148 Direction m_direction; | |
149 | 160 |
150 String m_unparsedFont; | 161 String m_unparsedFont; |
151 Font m_font; | 162 Font m_font; |
152 bool m_realizedFont; | |
153 | 163 |
154 bool m_hasClip; | 164 // Text state. |
155 bool m_hasComplexClip; | 165 unsigned m_textAlign : 3; |
Stephen White
2015/03/18 22:09:35
Could we hold off on using bitfields here until we
| |
166 unsigned m_textBaseline : 3; | |
167 unsigned m_direction : 2; | |
168 | |
169 bool m_realizedFont : 1; | |
170 bool m_isTransformInvertible : 1; | |
171 bool m_hasClip : 1; | |
172 bool m_hasComplexClip : 1; | |
173 mutable bool m_fillStyleDirty : 1; | |
174 mutable bool m_strokeStyleDirty : 1; | |
175 mutable bool m_lineDashDirty : 1; | |
156 | 176 |
157 ClipList m_clipList; | 177 ClipList m_clipList; |
158 }; | 178 }; |
159 | 179 |
160 } // blink | 180 } // blink |
161 | 181 |
162 #endif | 182 #endif |
OLD | NEW |