| 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 21 matching lines...) Expand all Loading... |
| 32 #include "HTMLNames.h" | 32 #include "HTMLNames.h" |
| 33 #include "bindings/v8/ScriptController.h" | 33 #include "bindings/v8/ScriptController.h" |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
| 36 #include "core/html/ImageData.h" | 36 #include "core/html/ImageData.h" |
| 37 #include "core/html/canvas/Canvas2DContextAttributes.h" | 37 #include "core/html/canvas/Canvas2DContextAttributes.h" |
| 38 #include "core/html/canvas/CanvasRenderingContext2D.h" | 38 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 39 #include "core/page/Frame.h" | 39 #include "core/page/Frame.h" |
| 40 #include "RuntimeEnabledFeatures.h" | 40 #include "RuntimeEnabledFeatures.h" |
| 41 #include "core/page/Settings.h" | 41 #include "core/page/Settings.h" |
| 42 #include "core/platform/HistogramSupport.h" |
| 42 #include "core/platform/MIMETypeRegistry.h" | 43 #include "core/platform/MIMETypeRegistry.h" |
| 43 #include "core/platform/graphics/GraphicsContextStateSaver.h" | 44 #include "core/platform/graphics/GraphicsContextStateSaver.h" |
| 44 #include "core/platform/graphics/ImageBuffer.h" | 45 #include "core/platform/graphics/ImageBuffer.h" |
| 45 #include "core/rendering/RenderHTMLCanvas.h" | 46 #include "core/rendering/RenderHTMLCanvas.h" |
| 46 | 47 |
| 47 #include "core/html/canvas/WebGLContextAttributes.h" | 48 #include "core/html/canvas/WebGLContextAttributes.h" |
| 48 #include "core/html/canvas/WebGLRenderingContext.h" | 49 #include "core/html/canvas/WebGLRenderingContext.h" |
| 49 | 50 |
| 50 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
| 51 | 52 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 { | 146 { |
| 146 setAttribute(widthAttr, String::number(value)); | 147 setAttribute(widthAttr, String::number(value)); |
| 147 } | 148 } |
| 148 | 149 |
| 149 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas
ContextAttributes* attrs) | 150 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas
ContextAttributes* attrs) |
| 150 { | 151 { |
| 151 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2
D canvas and the existing | 152 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2
D canvas and the existing |
| 152 // context is already 2D, just return that. If the existing context is WebGL
, then destroy it | 153 // context is already 2D, just return that. If the existing context is WebGL
, then destroy it |
| 153 // before creating a new 2D context. Vice versa when requesting a WebGL canv
as. Requesting a | 154 // before creating a new 2D context. Vice versa when requesting a WebGL canv
as. Requesting a |
| 154 // context with any other type string will destroy any existing context. | 155 // context with any other type string will destroy any existing context. |
| 156 enum ContextType { |
| 157 Context2d, |
| 158 ContextWebkit3d, |
| 159 ContextExperimentalWebgl, |
| 160 ContextWebgl, |
| 161 // Only add new items to the end and keep the order of existing items. |
| 162 ContextTypeCount, |
| 163 }; |
| 155 | 164 |
| 156 // FIXME - The code depends on the context not going away once created, to p
revent JS from | 165 // FIXME - The code depends on the context not going away once created, to p
revent JS from |
| 157 // seeing a dangling pointer. So for now we will disallow the context from b
eing changed | 166 // seeing a dangling pointer. So for now we will disallow the context from b
eing changed |
| 158 // once it is created. | 167 // once it is created. |
| 159 if (type == "2d") { | 168 if (type == "2d") { |
| 160 if (m_context && !m_context->is2d()) | 169 if (m_context && !m_context->is2d()) |
| 161 return 0; | 170 return 0; |
| 162 if (!m_context) { | 171 if (!m_context) { |
| 172 HistogramSupport::histogramEnumeration("Canvas.ContextType", Context
2d, ContextTypeCount); |
| 163 m_context = CanvasRenderingContext2D::create(this, RuntimeEnabledFea
tures::experimentalCanvasFeaturesEnabled() ? static_cast<Canvas2DContextAttribut
es*>(attrs) : 0, document()->inQuirksMode()); | 173 m_context = CanvasRenderingContext2D::create(this, RuntimeEnabledFea
tures::experimentalCanvasFeaturesEnabled() ? static_cast<Canvas2DContextAttribut
es*>(attrs) : 0, document()->inQuirksMode()); |
| 164 if (m_context) | 174 if (m_context) |
| 165 scheduleLayerUpdate(); | 175 scheduleLayerUpdate(); |
| 166 } | 176 } |
| 167 return m_context.get(); | 177 return m_context.get(); |
| 168 } | 178 } |
| 169 | 179 |
| 170 Settings* settings = document()->settings(); | 180 Settings* settings = document()->settings(); |
| 171 if (settings && settings->webGLEnabled()) { | 181 if (settings && settings->webGLEnabled()) { |
| 172 | |
| 173 // Accept the legacy "webkit-3d" name as well as the provisional "experi
mental-webgl" name. | 182 // Accept the legacy "webkit-3d" name as well as the provisional "experi
mental-webgl" name. |
| 174 bool is3dContext = (type == "webkit-3d") || (type == "experimental-webgl
"); | |
| 175 | |
| 176 // Now that WebGL is ratified, we will also accept "webgl" as the contex
t name in Chrome. | 183 // Now that WebGL is ratified, we will also accept "webgl" as the contex
t name in Chrome. |
| 177 is3dContext |= (type == "webgl"); | 184 ContextType contextType; |
| 185 bool is3dContext = true; |
| 186 if (type == "webkit-3d") |
| 187 contextType = ContextWebkit3d; |
| 188 else if (type == "experimental-webgl") |
| 189 contextType = ContextExperimentalWebgl; |
| 190 else if (type == "webgl") |
| 191 contextType = ContextWebgl; |
| 192 else |
| 193 is3dContext = false; |
| 178 | 194 |
| 179 if (is3dContext) { | 195 if (is3dContext) { |
| 180 if (m_context && !m_context->is3d()) | 196 if (m_context && !m_context->is3d()) |
| 181 return 0; | 197 return 0; |
| 182 if (!m_context) { | 198 if (!m_context) { |
| 199 HistogramSupport::histogramEnumeration("Canvas.ContextType", con
textType, ContextTypeCount); |
| 183 m_context = WebGLRenderingContext::create(this, static_cast<WebG
LContextAttributes*>(attrs)); | 200 m_context = WebGLRenderingContext::create(this, static_cast<WebG
LContextAttributes*>(attrs)); |
| 184 if (m_context) | 201 if (m_context) |
| 185 scheduleLayerUpdate(); | 202 scheduleLayerUpdate(); |
| 186 } | 203 } |
| 187 return m_context.get(); | 204 return m_context.get(); |
| 188 } | 205 } |
| 189 } | 206 } |
| 190 return 0; | 207 return 0; |
| 191 } | 208 } |
| 192 | 209 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 FloatSize unscaledSize = size(); | 584 FloatSize unscaledSize = size(); |
| 568 FloatSize deviceSize = convertLogicalToDevice(unscaledSize); | 585 FloatSize deviceSize = convertLogicalToDevice(unscaledSize); |
| 569 IntSize size(deviceSize.width(), deviceSize.height()); | 586 IntSize size(deviceSize.width(), deviceSize.height()); |
| 570 AffineTransform transform; | 587 AffineTransform transform; |
| 571 if (size.width() && size.height()) | 588 if (size.width() && size.height()) |
| 572 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig
ht() / unscaledSize.height()); | 589 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig
ht() / unscaledSize.height()); |
| 573 return m_imageBuffer->baseTransform() * transform; | 590 return m_imageBuffer->baseTransform() * transform; |
| 574 } | 591 } |
| 575 | 592 |
| 576 } | 593 } |
| OLD | NEW |