OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 { | 89 { |
90 } | 90 } |
91 | 91 |
92 DEFINE_NODE_FACTORY(HTMLCanvasElement) | 92 DEFINE_NODE_FACTORY(HTMLCanvasElement) |
93 | 93 |
94 HTMLCanvasElement::~HTMLCanvasElement() | 94 HTMLCanvasElement::~HTMLCanvasElement() |
95 { | 95 { |
96 resetDirtyRect(); | 96 resetDirtyRect(); |
97 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external
lyAllocatedMemory); | 97 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external
lyAllocatedMemory); |
98 #if !ENABLE(OILPAN) | 98 #if !ENABLE(OILPAN) |
99 HashSet<RawPtr<CanvasObserver> >::iterator end = m_observers.end(); | 99 for (CanvasObserver* canvasObserver : m_observers) |
100 for (HashSet<RawPtr<CanvasObserver> >::iterator it = m_observers.begin(); it
!= end; ++it) | 100 canvasObserver->canvasDestroyed(this); |
101 (*it)->canvasDestroyed(this); | |
102 // Ensure these go away before the ImageBuffer. | 101 // Ensure these go away before the ImageBuffer. |
103 m_contextStateSaver.clear(); | 102 m_contextStateSaver.clear(); |
104 m_context.clear(); | 103 m_context.clear(); |
105 #endif | 104 #endif |
106 } | 105 } |
107 | 106 |
108 void HTMLCanvasElement::parseAttribute(const QualifiedName& name, const AtomicSt
ring& value) | 107 void HTMLCanvasElement::parseAttribute(const QualifiedName& name, const AtomicSt
ring& value) |
109 { | 108 { |
110 if (name == widthAttr || name == heightAttr) | 109 if (name == widthAttr || name == heightAttr) |
111 reset(); | 110 reset(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 ContextExperimentalWebgl = 2, | 157 ContextExperimentalWebgl = 2, |
159 ContextWebgl = 3, | 158 ContextWebgl = 3, |
160 ContextTypeCount, | 159 ContextTypeCount, |
161 }; | 160 }; |
162 | 161 |
163 // FIXME - The code depends on the context not going away once created, to p
revent JS from | 162 // FIXME - The code depends on the context not going away once created, to p
revent JS from |
164 // seeing a dangling pointer. So for now we will disallow the context from b
eing changed | 163 // seeing a dangling pointer. So for now we will disallow the context from b
eing changed |
165 // once it is created. | 164 // once it is created. |
166 if (type == "2d") { | 165 if (type == "2d") { |
167 if (m_context && !m_context->is2d()) | 166 if (m_context && !m_context->is2d()) |
168 return 0; | 167 return nullptr; |
169 if (!m_context) { | 168 if (!m_context) { |
170 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", Context2d, ContextTypeCount); | 169 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", Context2d, ContextTypeCount); |
171 | 170 |
172 m_context = CanvasRenderingContext2D::create(this, static_cast<Canva
s2DContextAttributes*>(attrs), document()); | 171 m_context = CanvasRenderingContext2D::create(this, static_cast<Canva
s2DContextAttributes*>(attrs), document()); |
173 setNeedsCompositingUpdate(); | 172 setNeedsCompositingUpdate(); |
174 } | 173 } |
175 return m_context.get(); | 174 return m_context.get(); |
176 } | 175 } |
177 | 176 |
178 // Accept the the provisional "experimental-webgl" or official "webgl" conte
xt ID. | 177 // Accept the the provisional "experimental-webgl" or official "webgl" conte
xt ID. |
179 if (type == "webgl" || type == "experimental-webgl") { | 178 if (type == "webgl" || type == "experimental-webgl") { |
180 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExpe
rimentalWebgl; | 179 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExpe
rimentalWebgl; |
181 if (!m_context) { | 180 if (!m_context) { |
182 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", contextType, ContextTypeCount); | 181 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", contextType, ContextTypeCount); |
183 m_context = WebGLRenderingContext::create(this, static_cast<WebGLCon
textAttributes*>(attrs)); | 182 m_context = WebGLRenderingContext::create(this, static_cast<WebGLCon
textAttributes*>(attrs)); |
184 setNeedsCompositingUpdate(); | 183 setNeedsCompositingUpdate(); |
185 updateExternallyAllocatedMemory(); | 184 updateExternallyAllocatedMemory(); |
186 } else if (!m_context->is3d()) { | 185 } else if (!m_context->is3d()) { |
187 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext
creationerror, false, true, "Canvas has an existing, non-WebGL context")); | 186 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext
creationerror, false, true, "Canvas has an existing, non-WebGL context")); |
188 return 0; | 187 return nullptr; |
189 } | 188 } |
190 return m_context.get(); | 189 return m_context.get(); |
191 } | 190 } |
192 | 191 |
193 return 0; | 192 return nullptr; |
194 } | 193 } |
195 | 194 |
196 void HTMLCanvasElement::didDraw(const FloatRect& rect) | 195 void HTMLCanvasElement::didDraw(const FloatRect& rect) |
197 { | 196 { |
198 if (rect.isEmpty()) | 197 if (rect.isEmpty()) |
199 return; | 198 return; |
200 clearCopiedImage(); | 199 clearCopiedImage(); |
201 if (m_dirtyRect.isEmpty()) | 200 if (m_dirtyRect.isEmpty()) |
202 blink::Platform::current()->currentThread()->addTaskObserver(this); | 201 blink::Platform::current()->currentThread()->addTaskObserver(this); |
203 m_dirtyRect.unite(rect); | 202 m_dirtyRect.unite(rect); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 ASSERT(m_dirtyRect.isEmpty()); | 244 ASSERT(m_dirtyRect.isEmpty()); |
246 } | 245 } |
247 | 246 |
248 void HTMLCanvasElement::willProcessTask() | 247 void HTMLCanvasElement::willProcessTask() |
249 { | 248 { |
250 ASSERT_NOT_REACHED(); | 249 ASSERT_NOT_REACHED(); |
251 } | 250 } |
252 | 251 |
253 void HTMLCanvasElement::notifyObserversCanvasChanged(const FloatRect& rect) | 252 void HTMLCanvasElement::notifyObserversCanvasChanged(const FloatRect& rect) |
254 { | 253 { |
255 WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator end = m
_observers.end(); | 254 for (CanvasObserver* canvasObserver : m_observers) |
256 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator it
= m_observers.begin(); it != end; ++it) | 255 canvasObserver->canvasChanged(this, rect); |
257 (*it)->canvasChanged(this, rect); | |
258 } | 256 } |
259 | 257 |
260 void HTMLCanvasElement::reset() | 258 void HTMLCanvasElement::reset() |
261 { | 259 { |
262 if (m_ignoreReset) | 260 if (m_ignoreReset) |
263 return; | 261 return; |
264 | 262 |
265 resetDirtyRect(); | 263 resetDirtyRect(); |
266 | 264 |
267 bool ok; | 265 bool ok; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 if (oldSize != size()) { | 303 if (oldSize != size()) { |
306 toRenderHTMLCanvas(renderer)->canvasSizeChanged(); | 304 toRenderHTMLCanvas(renderer)->canvasSizeChanged(); |
307 if (renderBox() && renderBox()->hasAcceleratedCompositing()) | 305 if (renderBox() && renderBox()->hasAcceleratedCompositing()) |
308 renderBox()->contentChanged(CanvasChanged); | 306 renderBox()->contentChanged(CanvasChanged); |
309 } | 307 } |
310 if (hadImageBuffer) | 308 if (hadImageBuffer) |
311 renderer->setShouldDoFullPaintInvalidation(); | 309 renderer->setShouldDoFullPaintInvalidation(); |
312 } | 310 } |
313 } | 311 } |
314 | 312 |
315 WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator end = m
_observers.end(); | 313 for (CanvasObserver* canvasObserver : m_observers) |
316 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator it
= m_observers.begin(); it != end; ++it) | 314 canvasObserver->canvasResized(this); |
317 (*it)->canvasResized(this); | |
318 } | 315 } |
319 | 316 |
320 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const | 317 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const |
321 { | 318 { |
322 ASSERT(m_context); | 319 ASSERT(m_context); |
323 | 320 |
324 if (!m_context->isAccelerated()) | 321 if (!m_context->isAccelerated()) |
325 return true; | 322 return true; |
326 | 323 |
327 if (renderBox() && renderBox()->hasAcceleratedCompositing()) | 324 if (renderBox() && renderBox()->hasAcceleratedCompositing()) |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 662 } |
666 | 663 |
667 GraphicsContext* HTMLCanvasElement::drawingContext() const | 664 GraphicsContext* HTMLCanvasElement::drawingContext() const |
668 { | 665 { |
669 return buffer() ? m_imageBuffer->context() : 0; | 666 return buffer() ? m_imageBuffer->context() : 0; |
670 } | 667 } |
671 | 668 |
672 GraphicsContext* HTMLCanvasElement::existingDrawingContext() const | 669 GraphicsContext* HTMLCanvasElement::existingDrawingContext() const |
673 { | 670 { |
674 if (!hasImageBuffer()) | 671 if (!hasImageBuffer()) |
675 return 0; | 672 return nullptr; |
676 | 673 |
677 return drawingContext(); | 674 return drawingContext(); |
678 } | 675 } |
679 | 676 |
680 ImageBuffer* HTMLCanvasElement::buffer() const | 677 ImageBuffer* HTMLCanvasElement::buffer() const |
681 { | 678 { |
682 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer) | 679 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer) |
683 const_cast<HTMLCanvasElement*>(this)->createImageBuffer(); | 680 const_cast<HTMLCanvasElement*>(this)->createImageBuffer(); |
684 return m_imageBuffer.get(); | 681 return m_imageBuffer.get(); |
685 } | 682 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 { | 805 { |
809 return !originClean(); | 806 return !originClean(); |
810 } | 807 } |
811 | 808 |
812 FloatSize HTMLCanvasElement::sourceSize() const | 809 FloatSize HTMLCanvasElement::sourceSize() const |
813 { | 810 { |
814 return FloatSize(width(), height()); | 811 return FloatSize(width(), height()); |
815 } | 812 } |
816 | 813 |
817 } | 814 } |
OLD | NEW |