OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. |
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
10 * | 10 * |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 using namespace std; | 72 using namespace std; |
73 | 73 |
74 namespace WebCore { | 74 namespace WebCore { |
75 | 75 |
76 static const int defaultFontSize = 10; | 76 static const int defaultFontSize = 10; |
77 static const char defaultFontFamily[] = "sans-serif"; | 77 static const char defaultFontFamily[] = "sans-serif"; |
78 static const char defaultFont[] = "10px sans-serif"; | 78 static const char defaultFont[] = "10px sans-serif"; |
79 | 79 |
80 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co
nst Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode) | 80 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co
nst Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode) |
81 : CanvasRenderingContext(canvas) | 81 : CanvasRenderingContext(canvas) |
82 , m_stateStack(1) | |
83 , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) | 82 , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) |
84 , m_hasAlpha(!attrs || attrs->alpha()) | 83 , m_hasAlpha(!attrs || attrs->alpha()) |
85 { | 84 { |
| 85 m_stateStack.append(adoptPtrWillBeNoop(new State())); |
86 ScriptWrappable::init(this); | 86 ScriptWrappable::init(this); |
87 } | 87 } |
88 | 88 |
89 void CanvasRenderingContext2D::unwindStateStack() | 89 void CanvasRenderingContext2D::unwindStateStack() |
90 { | 90 { |
91 // Ensure that the state stack in the ImageBuffer's context | 91 // Ensure that the state stack in the ImageBuffer's context |
92 // is cleared before destruction, to avoid assertions in the | 92 // is cleared before destruction, to avoid assertions in the |
93 // GraphicsContext dtor. | 93 // GraphicsContext dtor. |
94 if (size_t stackSize = m_stateStack.size()) { | 94 if (size_t stackSize = m_stateStack.size()) { |
95 if (GraphicsContext* context = canvas()->existingDrawingContext()) { | 95 if (GraphicsContext* context = canvas()->existingDrawingContext()) { |
(...skipping 15 matching lines...) Expand all Loading... |
111 if (!canvas()->hasImageBuffer()) | 111 if (!canvas()->hasImageBuffer()) |
112 return false; | 112 return false; |
113 GraphicsContext* context = drawingContext(); | 113 GraphicsContext* context = drawingContext(); |
114 return context && context->isAccelerated(); | 114 return context && context->isAccelerated(); |
115 } | 115 } |
116 | 116 |
117 void CanvasRenderingContext2D::reset() | 117 void CanvasRenderingContext2D::reset() |
118 { | 118 { |
119 unwindStateStack(); | 119 unwindStateStack(); |
120 m_stateStack.resize(1); | 120 m_stateStack.resize(1); |
121 m_stateStack.first() = State(); | 121 m_stateStack.first() = adoptPtrWillBeNoop(new State()); |
122 m_path.clear(); | 122 m_path.clear(); |
123 } | 123 } |
124 | 124 |
125 // Important: Several of these properties are also stored in GraphicsContext's | 125 // Important: Several of these properties are also stored in GraphicsContext's |
126 // StrokeData. The default values that StrokeData uses may not the same values | 126 // StrokeData. The default values that StrokeData uses may not the same values |
127 // that the canvas 2d spec specifies. Make sure to sync the initial state of the | 127 // that the canvas 2d spec specifies. Make sure to sync the initial state of the |
128 // GraphicsContext in HTMLCanvasElement::createImageBuffer()! | 128 // GraphicsContext in HTMLCanvasElement::createImageBuffer()! |
129 CanvasRenderingContext2D::State::State() | 129 CanvasRenderingContext2D::State::State() |
130 : m_unrealizedSaveCount(0) | 130 : m_unrealizedSaveCount(0) |
131 , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black)) | 131 , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black)) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 { | 178 { |
179 if (m_realizedFont) | 179 if (m_realizedFont) |
180 static_cast<CSSFontSelector*>(m_font.fontSelector())->registerForInvalid
ationCallbacks(this); | 180 static_cast<CSSFontSelector*>(m_font.fontSelector())->registerForInvalid
ationCallbacks(this); |
181 } | 181 } |
182 | 182 |
183 CanvasRenderingContext2D::State& CanvasRenderingContext2D::State::operator=(cons
t State& other) | 183 CanvasRenderingContext2D::State& CanvasRenderingContext2D::State::operator=(cons
t State& other) |
184 { | 184 { |
185 if (this == &other) | 185 if (this == &other) |
186 return *this; | 186 return *this; |
187 | 187 |
| 188 #if !ENABLE(OILPAN) |
188 if (m_realizedFont) | 189 if (m_realizedFont) |
189 static_cast<CSSFontSelector*>(m_font.fontSelector())->unregisterForInval
idationCallbacks(this); | 190 static_cast<CSSFontSelector*>(m_font.fontSelector())->unregisterForInval
idationCallbacks(this); |
| 191 #endif |
190 | 192 |
191 m_unrealizedSaveCount = other.m_unrealizedSaveCount; | 193 m_unrealizedSaveCount = other.m_unrealizedSaveCount; |
192 m_unparsedStrokeColor = other.m_unparsedStrokeColor; | 194 m_unparsedStrokeColor = other.m_unparsedStrokeColor; |
193 m_unparsedFillColor = other.m_unparsedFillColor; | 195 m_unparsedFillColor = other.m_unparsedFillColor; |
194 m_strokeStyle = other.m_strokeStyle; | 196 m_strokeStyle = other.m_strokeStyle; |
195 m_fillStyle = other.m_fillStyle; | 197 m_fillStyle = other.m_fillStyle; |
196 m_lineWidth = other.m_lineWidth; | 198 m_lineWidth = other.m_lineWidth; |
197 m_lineCap = other.m_lineCap; | 199 m_lineCap = other.m_lineCap; |
198 m_lineJoin = other.m_lineJoin; | 200 m_lineJoin = other.m_lineJoin; |
199 m_miterLimit = other.m_miterLimit; | 201 m_miterLimit = other.m_miterLimit; |
(...skipping 13 matching lines...) Expand all Loading... |
213 m_realizedFont = other.m_realizedFont; | 215 m_realizedFont = other.m_realizedFont; |
214 | 216 |
215 if (m_realizedFont) | 217 if (m_realizedFont) |
216 static_cast<CSSFontSelector*>(m_font.fontSelector())->registerForInvalid
ationCallbacks(this); | 218 static_cast<CSSFontSelector*>(m_font.fontSelector())->registerForInvalid
ationCallbacks(this); |
217 | 219 |
218 return *this; | 220 return *this; |
219 } | 221 } |
220 | 222 |
221 CanvasRenderingContext2D::State::~State() | 223 CanvasRenderingContext2D::State::~State() |
222 { | 224 { |
| 225 #if !ENABLE(OILPAN) |
223 if (m_realizedFont) | 226 if (m_realizedFont) |
224 static_cast<CSSFontSelector*>(m_font.fontSelector())->unregisterForInval
idationCallbacks(this); | 227 static_cast<CSSFontSelector*>(m_font.fontSelector())->unregisterForInval
idationCallbacks(this); |
| 228 #endif |
225 } | 229 } |
226 | 230 |
227 void CanvasRenderingContext2D::State::fontsNeedUpdate(CSSFontSelector* fontSelec
tor) | 231 void CanvasRenderingContext2D::State::fontsNeedUpdate(CSSFontSelector* fontSelec
tor) |
228 { | 232 { |
229 ASSERT_ARG(fontSelector, fontSelector == m_font.fontSelector()); | 233 ASSERT_ARG(fontSelector, fontSelector == m_font.fontSelector()); |
230 ASSERT(m_realizedFont); | 234 ASSERT(m_realizedFont); |
231 | 235 |
232 m_font.update(fontSelector); | 236 m_font.update(fontSelector); |
233 } | 237 } |
234 | 238 |
235 void CanvasRenderingContext2D::realizeSaves() | 239 void CanvasRenderingContext2D::realizeSaves() |
236 { | 240 { |
237 if (state().m_unrealizedSaveCount) { | 241 if (state().m_unrealizedSaveCount) { |
238 ASSERT(m_stateStack.size() >= 1); | 242 ASSERT(m_stateStack.size() >= 1); |
239 // Reduce the current state's unrealized count by one now, | 243 // Reduce the current state's unrealized count by one now, |
240 // to reflect the fact we are saving one state. | 244 // to reflect the fact we are saving one state. |
241 m_stateStack.last().m_unrealizedSaveCount--; | 245 m_stateStack.last()->m_unrealizedSaveCount--; |
242 m_stateStack.append(state()); | 246 m_stateStack.append(adoptPtrWillBeNoop(new State(state()))); |
243 // Set the new state's unrealized count to 0, because it has no outstand
ing saves. | 247 // Set the new state's unrealized count to 0, because it has no outstand
ing saves. |
244 // We need to do this explicitly because the copy constructor and operat
or= used | 248 // We need to do this explicitly because the copy constructor and operat
or= used |
245 // by the Vector operations copy the unrealized count from the previous
state (in | 249 // by the Vector operations copy the unrealized count from the previous
state (in |
246 // turn necessary to support correct resizing and unwinding of the stack
). | 250 // turn necessary to support correct resizing and unwinding of the stack
). |
247 m_stateStack.last().m_unrealizedSaveCount = 0; | 251 m_stateStack.last()->m_unrealizedSaveCount = 0; |
248 GraphicsContext* context = drawingContext(); | 252 GraphicsContext* context = drawingContext(); |
249 if (context) | 253 if (context) |
250 context->save(); | 254 context->save(); |
251 } | 255 } |
252 } | 256 } |
253 | 257 |
254 void CanvasRenderingContext2D::restore() | 258 void CanvasRenderingContext2D::restore() |
255 { | 259 { |
256 if (state().m_unrealizedSaveCount) { | 260 if (state().m_unrealizedSaveCount) { |
257 // We never realized the save, so just record that it was unnecessary. | 261 // We never realized the save, so just record that it was unnecessary. |
258 --m_stateStack.last().m_unrealizedSaveCount; | 262 --m_stateStack.last()->m_unrealizedSaveCount; |
259 return; | 263 return; |
260 } | 264 } |
261 ASSERT(m_stateStack.size() >= 1); | 265 ASSERT(m_stateStack.size() >= 1); |
262 if (m_stateStack.size() <= 1) | 266 if (m_stateStack.size() <= 1) |
263 return; | 267 return; |
264 m_path.transform(state().m_transform); | 268 m_path.transform(state().m_transform); |
265 m_stateStack.removeLast(); | 269 m_stateStack.removeLast(); |
266 m_path.transform(state().m_transform.inverse()); | 270 m_path.transform(state().m_transform.inverse()); |
267 GraphicsContext* c = drawingContext(); | 271 GraphicsContext* c = drawingContext(); |
268 if (c) | 272 if (c) |
(...skipping 1648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1917 CSSPropertyValue(CSSPropertyFontStyle, *parsedStyle), | 1921 CSSPropertyValue(CSSPropertyFontStyle, *parsedStyle), |
1918 CSSPropertyValue(CSSPropertyFontVariant, *parsedStyle), | 1922 CSSPropertyValue(CSSPropertyFontVariant, *parsedStyle), |
1919 CSSPropertyValue(CSSPropertyFontWeight, *parsedStyle), | 1923 CSSPropertyValue(CSSPropertyFontWeight, *parsedStyle), |
1920 CSSPropertyValue(CSSPropertyFontSize, *parsedStyle), | 1924 CSSPropertyValue(CSSPropertyFontSize, *parsedStyle), |
1921 CSSPropertyValue(CSSPropertyLineHeight, *parsedStyle), | 1925 CSSPropertyValue(CSSPropertyLineHeight, *parsedStyle), |
1922 }; | 1926 }; |
1923 | 1927 |
1924 StyleResolver& styleResolver = canvas()->document().ensureStyleResolver(); | 1928 StyleResolver& styleResolver = canvas()->document().ensureStyleResolver(); |
1925 styleResolver.applyPropertiesToStyle(properties, WTF_ARRAY_LENGTH(properties
), newStyle.get()); | 1929 styleResolver.applyPropertiesToStyle(properties, WTF_ARRAY_LENGTH(properties
), newStyle.get()); |
1926 | 1930 |
| 1931 #if !ENABLE(OILPAN) |
1927 if (state().m_realizedFont) | 1932 if (state().m_realizedFont) |
1928 static_cast<CSSFontSelector*>(state().m_font.fontSelector())->unregister
ForInvalidationCallbacks(&modifiableState()); | 1933 static_cast<CSSFontSelector*>(state().m_font.fontSelector())->unregister
ForInvalidationCallbacks(&modifiableState()); |
| 1934 #endif |
1929 modifiableState().m_font = newStyle->font(); | 1935 modifiableState().m_font = newStyle->font(); |
1930 modifiableState().m_font.update(canvas()->document().styleEngine()->fontSele
ctor()); | 1936 modifiableState().m_font.update(canvas()->document().styleEngine()->fontSele
ctor()); |
1931 modifiableState().m_realizedFont = true; | 1937 modifiableState().m_realizedFont = true; |
1932 canvas()->document().styleEngine()->fontSelector()->registerForInvalidationC
allbacks(&modifiableState()); | 1938 canvas()->document().styleEngine()->fontSelector()->registerForInvalidationC
allbacks(&modifiableState()); |
1933 } | 1939 } |
1934 | 1940 |
1935 String CanvasRenderingContext2D::textAlign() const | 1941 String CanvasRenderingContext2D::textAlign() const |
1936 { | 1942 { |
1937 return textAlignName(state().m_textAlign); | 1943 return textAlignName(state().m_textAlign); |
1938 } | 1944 } |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 c->setAlphaAsFloat(1.0); | 2306 c->setAlphaAsFloat(1.0); |
2301 c->clearShadow(); | 2307 c->clearShadow(); |
2302 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); | 2308 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); |
2303 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2309 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
2304 c->restore(); | 2310 c->restore(); |
2305 | 2311 |
2306 didDraw(dirtyRect); | 2312 didDraw(dirtyRect); |
2307 } | 2313 } |
2308 | 2314 |
2309 } // namespace WebCore | 2315 } // namespace WebCore |
OLD | NEW |