| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void HTMLCanvasElement::setHeight(int value) | 163 void HTMLCanvasElement::setHeight(int value) |
| 164 { | 164 { |
| 165 setIntegralAttribute(heightAttr, value); | 165 setIntegralAttribute(heightAttr, value); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void HTMLCanvasElement::setWidth(int value) | 168 void HTMLCanvasElement::setWidth(int value) |
| 169 { | 169 { |
| 170 setIntegralAttribute(widthAttr, value); | 170 setIntegralAttribute(widthAttr, value); |
| 171 } | 171 } |
| 172 | 172 |
| 173 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas
ContextAttributes* attrs) | 173 void HTMLCanvasElement::getContext(const String& type, const CanvasContextCreati
onAttributes& attributes, CanvasRenderingContext2DOrWebGLRenderingContext& resul
t) |
| 174 { | 174 { |
| 175 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2
D canvas and the existing | 175 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2
D canvas and the existing |
| 176 // context is already 2D, just return that. If the existing context is WebGL
, then destroy it | 176 // context is already 2D, just return that. If the existing context is WebGL
, then destroy it |
| 177 // before creating a new 2D context. Vice versa when requesting a WebGL canv
as. Requesting a | 177 // before creating a new 2D context. Vice versa when requesting a WebGL canv
as. Requesting a |
| 178 // context with any other type string will destroy any existing context. | 178 // context with any other type string will destroy any existing context. |
| 179 enum ContextType { | 179 enum ContextType { |
| 180 // Do not change assigned numbers of existing items: add new features to
the end of the list. | 180 // Do not change assigned numbers of existing items: add new features to
the end of the list. |
| 181 Context2d = 0, | 181 Context2d = 0, |
| 182 ContextExperimentalWebgl = 2, | 182 ContextExperimentalWebgl = 2, |
| 183 ContextWebgl = 3, | 183 ContextWebgl = 3, |
| 184 ContextTypeCount, | 184 ContextTypeCount, |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 // FIXME - The code depends on the context not going away once created, to p
revent JS from | 187 // FIXME - The code depends on the context not going away once created, to p
revent JS from |
| 188 // seeing a dangling pointer. So for now we will disallow the context from b
eing changed | 188 // seeing a dangling pointer. So for now we will disallow the context from b
eing changed |
| 189 // once it is created. | 189 // once it is created. |
| 190 if (type == "2d") { | 190 if (type == "2d") { |
| 191 if (m_context && !m_context->is2d()) | 191 if (m_context && !m_context->is2d()) |
| 192 return nullptr; | 192 return; |
| 193 if (!m_context) { | 193 if (!m_context) { |
| 194 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", Context2d, ContextTypeCount); | 194 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", Context2d, ContextTypeCount); |
| 195 | 195 |
| 196 m_context = CanvasRenderingContext2D::create(this, static_cast<Canva
s2DContextAttributes*>(attrs), document()); | 196 m_context = CanvasRenderingContext2D::create(this, attributes, docum
ent()); |
| 197 setNeedsCompositingUpdate(); | 197 setNeedsCompositingUpdate(); |
| 198 } | 198 } |
| 199 return m_context.get(); | 199 result.setCanvasRenderingContext2D(static_cast<CanvasRenderingContext2D*
>(m_context.get())); |
| 200 return; |
| 200 } | 201 } |
| 201 | 202 |
| 202 // Accept the the provisional "experimental-webgl" or official "webgl" conte
xt ID. | 203 // Accept the the provisional "experimental-webgl" or official "webgl" conte
xt ID. |
| 203 if (type == "webgl" || type == "experimental-webgl") { | 204 if (type == "webgl" || type == "experimental-webgl") { |
| 204 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExpe
rimentalWebgl; | 205 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExpe
rimentalWebgl; |
| 205 if (!m_context) { | 206 if (!m_context) { |
| 206 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", contextType, ContextTypeCount); | 207 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", contextType, ContextTypeCount); |
| 207 m_context = WebGLRenderingContext::create(this, static_cast<WebGLCon
textAttributes*>(attrs)); | 208 m_context = WebGLRenderingContext::create(this, attributes); |
| 208 setNeedsCompositingUpdate(); | 209 setNeedsCompositingUpdate(); |
| 209 updateExternallyAllocatedMemory(); | 210 updateExternallyAllocatedMemory(); |
| 210 } else if (!m_context->is3d()) { | 211 } else if (!m_context->is3d()) { |
| 211 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext
creationerror, false, true, "Canvas has an existing, non-WebGL context")); | 212 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext
creationerror, false, true, "Canvas has an existing, non-WebGL context")); |
| 212 return nullptr; | 213 return; |
| 213 } | 214 } |
| 214 return m_context.get(); | 215 result.setWebGLRenderingContext(static_cast<WebGLRenderingContext*>(m_co
ntext.get())); |
| 215 } | 216 } |
| 216 | 217 |
| 217 return nullptr; | 218 return; |
| 218 } | 219 } |
| 219 | 220 |
| 220 bool HTMLCanvasElement::isPaintable() const | 221 bool HTMLCanvasElement::isPaintable() const |
| 221 { | 222 { |
| 222 if (!m_context) | 223 if (!m_context) |
| 223 return canCreateImageBuffer(size()); | 224 return canCreateImageBuffer(size()); |
| 224 return buffer(); | 225 return buffer(); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void HTMLCanvasElement::didDraw(const FloatRect& rect) | 228 void HTMLCanvasElement::didDraw(const FloatRect& rect) |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 { | 802 { |
| 802 return !originClean(); | 803 return !originClean(); |
| 803 } | 804 } |
| 804 | 805 |
| 805 FloatSize HTMLCanvasElement::sourceSize() const | 806 FloatSize HTMLCanvasElement::sourceSize() const |
| 806 { | 807 { |
| 807 return FloatSize(width(), height()); | 808 return FloatSize(width(), height()); |
| 808 } | 809 } |
| 809 | 810 |
| 810 } | 811 } |
| OLD | NEW |