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" |
11 #include "platform/transforms/AffineTransform.h" | 11 #include "platform/transforms/AffineTransform.h" |
12 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class CanvasStyle; | 16 class CanvasStyle; |
17 | 17 |
18 class CanvasRenderingContext2DState final : public CSSFontSelectorClient { | 18 class CanvasRenderingContext2DState final : public CSSFontSelectorClient { |
19 public: | 19 public: |
20 CanvasRenderingContext2DState(); | 20 CanvasRenderingContext2DState(); |
21 virtual ~CanvasRenderingContext2DState(); | 21 virtual ~CanvasRenderingContext2DState(); |
22 | 22 |
23 DECLARE_VIRTUAL_TRACE(); | 23 DECLARE_VIRTUAL_TRACE(); |
24 | 24 |
25 enum ClipListCopyMode { | 25 enum ClipListCopyMode { |
26 CopyClipList, | 26 CopyClipList, |
27 DontCopyClipList | 27 DontCopyClipList |
28 }; | 28 }; |
29 | 29 |
| 30 enum PaintType { |
| 31 FillPaintType, |
| 32 StrokePaintType, |
| 33 }; |
| 34 |
30 CanvasRenderingContext2DState(const CanvasRenderingContext2DState&, ClipList
CopyMode = CopyClipList); | 35 CanvasRenderingContext2DState(const CanvasRenderingContext2DState&, ClipList
CopyMode = CopyClipList); |
31 CanvasRenderingContext2DState& operator=(const CanvasRenderingContext2DState
&); | 36 CanvasRenderingContext2DState& operator=(const CanvasRenderingContext2DState
&); |
32 | 37 |
33 // CSSFontSelectorClient implementation | 38 // CSSFontSelectorClient implementation |
34 virtual void fontsNeedUpdate(CSSFontSelector*) override; | 39 virtual void fontsNeedUpdate(CSSFontSelector*) override; |
35 | 40 |
36 bool hasUnrealizedSaves() const { return m_unrealizedSaveCount; } | 41 bool hasUnrealizedSaves() const { return m_unrealizedSaveCount; } |
37 void save() { ++m_unrealizedSaveCount; } | 42 void save() { ++m_unrealizedSaveCount; } |
38 void restore() { --m_unrealizedSaveCount; } | 43 void restore() { --m_unrealizedSaveCount; } |
39 void resetUnrealizedSaveCount() { m_unrealizedSaveCount = 0; } | 44 void resetUnrealizedSaveCount() { m_unrealizedSaveCount = 0; } |
40 | 45 |
41 void setLineDash(const Vector<float>&); | 46 void setLineDash(const Vector<float>&); |
42 const Vector<float>& lineDash() const { return m_lineDash; } | 47 const Vector<float>& lineDash() const { return m_lineDash; } |
43 | 48 |
44 void setLineDashOffset(float offset) { m_lineDashOffset = offset; } | 49 void setLineDashOffset(float); |
45 float lineDashOffset() const { return m_lineDashOffset; } | 50 float lineDashOffset() const { return m_lineDashOffset; } |
46 | 51 |
47 // setTransform returns true iff transform is invertible; | 52 // setTransform returns true iff transform is invertible; |
48 void setTransform(const AffineTransform&); | 53 void setTransform(const AffineTransform&); |
49 void resetTransform(); | 54 void resetTransform(); |
50 AffineTransform transform() const { return m_transform; } | 55 AffineTransform transform() const { return m_transform; } |
51 bool isTransformInvertible() const { return m_isTransformInvertible; } | 56 bool isTransformInvertible() const { return m_isTransformInvertible; } |
52 | 57 |
53 void clipPath(const SkPath&, AntiAliasingMode); | 58 void clipPath(const SkPath&, AntiAliasingMode); |
54 bool hasClip() const { return m_hasClip; } | 59 bool hasClip() const { return m_hasClip; } |
55 bool hasComplexClip() const { return m_hasComplexClip; } | 60 bool hasComplexClip() const { return m_hasComplexClip; } |
56 void playbackClips(SkCanvas* canvas) const { m_clipList.playback(canvas); } | 61 void playbackClips(SkCanvas* canvas) const { m_clipList.playback(canvas); } |
57 | 62 |
58 void setFont(const Font&, CSSFontSelector*); | 63 void setFont(const Font&, CSSFontSelector*); |
59 const Font& font() const; | 64 const Font& font() const; |
60 bool hasRealizedFont() const { return m_realizedFont; } | 65 bool hasRealizedFont() const { return m_realizedFont; } |
61 void setUnparsedFont(const String& font) { m_unparsedFont = font; } | 66 void setUnparsedFont(const String& font) { m_unparsedFont = font; } |
62 const String& unparsedFont() const { return m_unparsedFont; } | 67 const String& unparsedFont() const { return m_unparsedFont; } |
63 | 68 |
64 void setStrokeStyle(PassRefPtrWillBeRawPtr<CanvasStyle> style) { m_strokeSty
le = style; } | 69 void setStrokeStyle(PassRefPtrWillBeRawPtr<CanvasStyle>); |
65 CanvasStyle* strokeStyle() const { return m_strokeStyle.get(); } | 70 CanvasStyle* strokeStyle() const { return m_strokeStyle.get(); } |
66 | 71 |
67 void setFillStyle(PassRefPtrWillBeRawPtr<CanvasStyle> style) { m_fillStyle =
style; } | 72 void setFillStyle(PassRefPtrWillBeRawPtr<CanvasStyle>); |
68 CanvasStyle* fillStyle() const { return m_fillStyle.get(); } | 73 CanvasStyle* fillStyle() const { return m_fillStyle.get(); } |
69 | 74 |
70 enum Direction { | 75 enum Direction { |
71 DirectionInherit, | 76 DirectionInherit, |
72 DirectionRTL, | 77 DirectionRTL, |
73 DirectionLTR | 78 DirectionLTR |
74 }; | 79 }; |
75 | 80 |
76 void setDirection(Direction direction) { m_direction = direction; } | 81 void setDirection(Direction direction) { m_direction = direction; } |
77 Direction direction() const { return m_direction; } | 82 Direction direction() const { return m_direction; } |
78 | 83 |
79 void setTextAlign(TextAlign align) { m_textAlign = align; } | 84 void setTextAlign(TextAlign align) { m_textAlign = align; } |
80 TextAlign textAlign() const { return m_textAlign; } | 85 TextAlign textAlign() const { return m_textAlign; } |
81 | 86 |
82 void setTextBaseline(TextBaseline baseline) { m_textBaseline = baseline; } | 87 void setTextBaseline(TextBaseline baseline) { m_textBaseline = baseline; } |
83 TextBaseline textBaseline() const { return m_textBaseline; } | 88 TextBaseline textBaseline() const { return m_textBaseline; } |
84 | 89 |
85 void setLineWidth(float lineWidth) { m_lineWidth = lineWidth; } | 90 void setLineWidth(float lineWidth) { m_strokePaint.setStrokeWidth(lineWidth)
; } |
86 float lineWidth() const { return m_lineWidth; } | 91 float lineWidth() const { return m_strokePaint.getStrokeWidth(); } |
87 | 92 |
88 void setLineCap(LineCap lineCap) { m_lineCap = lineCap; } | 93 void setLineCap(LineCap lineCap) { m_strokePaint.setStrokeCap(static_cast<Sk
Paint::Cap>(lineCap)); } |
89 LineCap lineCap() const { return m_lineCap; } | 94 LineCap lineCap() const { return static_cast<LineCap>(m_strokePaint.getStrok
eCap()); } |
90 | 95 |
91 void setLineJoin(LineJoin lineJoin) { m_lineJoin = lineJoin; } | 96 void setLineJoin(LineJoin lineJoin) { m_strokePaint.setStrokeJoin(static_cas
t<SkPaint::Join>(lineJoin)); } |
92 LineJoin lineJoin() const { return m_lineJoin; } | 97 LineJoin lineJoin() const { return static_cast<LineJoin>(m_strokePaint.getSt
rokeJoin()); } |
93 | 98 |
94 void setMiterLimit(float miterLimit) { m_miterLimit = miterLimit; } | 99 void setMiterLimit(float miterLimit) { m_strokePaint.setStrokeMiter(miterLim
it); } |
95 float miterLimit() const { return m_miterLimit; } | 100 float miterLimit() const { return m_strokePaint.getStrokeMiter(); } |
96 | 101 |
97 void setShadowOffsetX(float x) { m_shadowOffset.setWidth(x); } | 102 void setShadowOffsetX(float); |
98 void setShadowOffsetY(float y) { m_shadowOffset.setHeight(y); } | 103 void setShadowOffsetY(float); |
99 const FloatSize& shadowOffset() const { return m_shadowOffset; } | 104 const FloatSize& shadowOffset() const { return m_shadowOffset; } |
100 | 105 |
101 void setShadowBlur(float shadowBlur) { m_shadowBlur = shadowBlur; } | 106 void setShadowBlur(float); |
102 float shadowBlur() const { return m_shadowBlur; } | 107 float shadowBlur() const { return m_shadowBlur; } |
103 | 108 |
104 void setShadowColor(SkColor shadowColor) { m_shadowColor = shadowColor; } | 109 void setShadowColor(SkColor); |
105 SkColor shadowColor() const { return m_shadowColor; } | 110 SkColor shadowColor() const { return m_shadowColor; } |
106 | 111 |
107 void setGlobalAlpha(float alpha) { m_globalAlpha = alpha; } | 112 void setGlobalAlpha(float); |
108 float globalAlpha() const { return m_globalAlpha; } | 113 float globalAlpha() const { return m_globalAlpha; } |
109 | 114 |
110 void setGlobalComposite(SkXfermode::Mode mode) { m_globalComposite = mode; } | 115 void setGlobalComposite(SkXfermode::Mode); |
111 SkXfermode::Mode globalComposite() const { return m_globalComposite; } | 116 SkXfermode::Mode globalComposite() const; |
112 | 117 |
113 void setImageSmoothingEnabled(bool enabled) { m_imageSmoothingEnabled = enab
led; } | 118 void setImageSmoothingEnabled(bool); |
114 bool imageSmoothingEnabled() const { return m_imageSmoothingEnabled; } | 119 bool imageSmoothingEnabled() const; |
115 | 120 |
116 void setUnparsedStrokeColor(const String& color) { m_unparsedStrokeColor = c
olor; } | 121 void setUnparsedStrokeColor(const String& color) { m_unparsedStrokeColor = c
olor; } |
117 const String& unparsedStrokeColor() const { return m_unparsedStrokeColor; } | 122 const String& unparsedStrokeColor() const { return m_unparsedStrokeColor; } |
118 | 123 |
119 void setUnparsedFillColor(const String& color) { m_unparsedFillColor = color
; } | 124 void setUnparsedFillColor(const String& color) { m_unparsedFillColor = color
; } |
120 const String& unparsedFillColor() const { return m_unparsedFillColor; } | 125 const String& unparsedFillColor() const { return m_unparsedFillColor; } |
121 | 126 |
| 127 bool shouldDrawShadows() const; |
| 128 |
| 129 // If paint will not be used for painting a bitmap, set bitmapOpacity to Opa
que |
| 130 const SkPaint* getPaint(PaintType, ShadowMode, OpacityMode bitmapOpacity = O
paque) const; |
| 131 |
122 private: | 132 private: |
| 133 void updateLineDash() const; |
| 134 void updateStrokeStyle() const; |
| 135 void updateFillStyle() const; |
| 136 void shadowParameterChanged(); |
| 137 SkDrawLooper* emptyDrawLooper() const; |
| 138 SkDrawLooper* shadowOnlyDrawLooper() const; |
| 139 SkDrawLooper* shadowAndForegroundDrawLooper() const; |
| 140 SkImageFilter* shadowOnlyImageFilter() const; |
| 141 SkImageFilter* shadowAndForegroundImageFilter() const; |
| 142 |
123 unsigned m_unrealizedSaveCount; | 143 unsigned m_unrealizedSaveCount; |
124 | 144 |
125 String m_unparsedStrokeColor; | 145 String m_unparsedStrokeColor; |
126 String m_unparsedFillColor; | 146 String m_unparsedFillColor; |
127 RefPtrWillBeMember<CanvasStyle> m_strokeStyle; | 147 RefPtrWillBeMember<CanvasStyle> m_strokeStyle; |
128 RefPtrWillBeMember<CanvasStyle> m_fillStyle; | 148 RefPtrWillBeMember<CanvasStyle> m_fillStyle; |
129 | 149 |
130 float m_lineWidth; | 150 mutable SkPaint m_strokePaint; |
131 LineCap m_lineCap; | 151 mutable SkPaint m_fillPaint; |
132 LineJoin m_lineJoin; | 152 |
133 float m_miterLimit; | |
134 FloatSize m_shadowOffset; | 153 FloatSize m_shadowOffset; |
135 float m_shadowBlur; | 154 float m_shadowBlur; |
136 SkColor m_shadowColor; | 155 SkColor m_shadowColor; |
| 156 mutable RefPtr<SkDrawLooper> m_emptyDrawLooper; |
| 157 mutable RefPtr<SkDrawLooper> m_shadowOnlyDrawLooper; |
| 158 mutable RefPtr<SkDrawLooper> m_shadowAndForegroundDrawLooper; |
| 159 mutable RefPtr<SkImageFilter> m_shadowOnlyImageFilter; |
| 160 mutable RefPtr<SkImageFilter> m_shadowAndForegroundImageFilter; |
| 161 |
137 float m_globalAlpha; | 162 float m_globalAlpha; |
138 SkXfermode::Mode m_globalComposite; | |
139 AffineTransform m_transform; | 163 AffineTransform m_transform; |
140 bool m_isTransformInvertible; | |
141 Vector<float> m_lineDash; | 164 Vector<float> m_lineDash; |
142 float m_lineDashOffset; | 165 float m_lineDashOffset; |
143 bool m_imageSmoothingEnabled; | 166 |
| 167 String m_unparsedFont; |
| 168 Font m_font; |
144 | 169 |
145 // Text state. | 170 // Text state. |
146 TextAlign m_textAlign; | 171 TextAlign m_textAlign; |
147 TextBaseline m_textBaseline; | 172 TextBaseline m_textBaseline; |
148 Direction m_direction; | 173 Direction m_direction; |
149 | 174 |
150 String m_unparsedFont; | 175 bool m_realizedFont : 1; |
151 Font m_font; | 176 bool m_isTransformInvertible : 1; |
152 bool m_realizedFont; | 177 bool m_hasClip : 1; |
153 | 178 bool m_hasComplexClip : 1; |
154 bool m_hasClip; | 179 mutable bool m_fillStyleDirty : 1; |
155 bool m_hasComplexClip; | 180 mutable bool m_strokeStyleDirty : 1; |
| 181 mutable bool m_lineDashDirty : 1; |
156 | 182 |
157 ClipList m_clipList; | 183 ClipList m_clipList; |
158 }; | 184 }; |
159 | 185 |
160 } // blink | 186 } // blink |
161 | 187 |
162 #endif | 188 #endif |
OLD | NEW |