Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 33 #include "bindings/core/v8/ScriptController.h" | 33 #include "bindings/core/v8/ScriptController.h" |
| 34 #include "bindings/core/v8/WrapCanvasContext.h" | 34 #include "bindings/core/v8/WrapCanvasContext.h" |
| 35 #include "core/HTMLNames.h" | 35 #include "core/HTMLNames.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
| 38 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
| 39 #include "core/frame/Settings.h" | 39 #include "core/frame/Settings.h" |
| 40 #include "core/html/ImageData.h" | 40 #include "core/html/ImageData.h" |
| 41 #include "core/html/canvas/Canvas2DContextAttributes.h" | 41 #include "core/html/canvas/Canvas2DContextAttributes.h" |
| 42 #include "core/html/canvas/CanvasRenderingContext2D.h" | 42 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 43 #include "core/html/canvas/WebGL2RenderingContext.h" | |
| 43 #include "core/html/canvas/WebGLContextAttributes.h" | 44 #include "core/html/canvas/WebGLContextAttributes.h" |
| 44 #include "core/html/canvas/WebGLContextEvent.h" | 45 #include "core/html/canvas/WebGLContextEvent.h" |
| 45 #include "core/html/canvas/WebGLRenderingContext.h" | 46 #include "core/html/canvas/WebGLRenderingContext.h" |
| 46 #include "core/rendering/RenderHTMLCanvas.h" | 47 #include "core/rendering/RenderHTMLCanvas.h" |
| 47 #include "core/rendering/RenderLayer.h" | 48 #include "core/rendering/RenderLayer.h" |
| 48 #include "platform/MIMETypeRegistry.h" | 49 #include "platform/MIMETypeRegistry.h" |
| 49 #include "platform/RuntimeEnabledFeatures.h" | 50 #include "platform/RuntimeEnabledFeatures.h" |
| 50 #include "platform/graphics/BitmapImage.h" | 51 #include "platform/graphics/BitmapImage.h" |
| 51 #include "platform/graphics/Canvas2DImageBufferSurface.h" | 52 #include "platform/graphics/Canvas2DImageBufferSurface.h" |
| 52 #include "platform/graphics/GraphicsContextStateSaver.h" | 53 #include "platform/graphics/GraphicsContextStateSaver.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 { | 203 { |
| 203 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing | 204 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing |
| 204 // context is already 2D, just return that. If the existing context is WebGL , then destroy it | 205 // context is already 2D, just return that. If the existing context is WebGL , then destroy it |
| 205 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a | 206 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a |
| 206 // context with any other type string will destroy any existing context. | 207 // context with any other type string will destroy any existing context. |
| 207 enum ContextType { | 208 enum ContextType { |
| 208 // Do not change assigned numbers of existing items: add new features to the end of the list. | 209 // Do not change assigned numbers of existing items: add new features to the end of the list. |
| 209 Context2d = 0, | 210 Context2d = 0, |
| 210 ContextExperimentalWebgl = 2, | 211 ContextExperimentalWebgl = 2, |
| 211 ContextWebgl = 3, | 212 ContextWebgl = 3, |
| 213 ContextWebgl2 = 4, | |
| 212 ContextTypeCount, | 214 ContextTypeCount, |
| 213 }; | 215 }; |
| 214 | 216 |
| 215 // FIXME - The code depends on the context not going away once created, to p revent JS from | 217 // FIXME - The code depends on the context not going away once created, to p revent JS from |
| 216 // seeing a dangling pointer. So for now we will disallow the context from b eing changed | 218 // seeing a dangling pointer. So for now we will disallow the context from b eing changed |
| 217 // once it is created. | 219 // once it is created. |
| 218 if (type == "2d") { | 220 if (type == "2d") { |
| 219 if (m_context && !m_context->is2d()) | 221 if (m_context && !m_context->is2d()) |
| 220 return; | 222 return; |
| 221 if (!m_context) { | 223 if (!m_context) { |
| 222 blink::Platform::current()->histogramEnumeration("Canvas.ContextType ", Context2d, ContextTypeCount); | 224 blink::Platform::current()->histogramEnumeration("Canvas.ContextType ", Context2d, ContextTypeCount); |
| 223 | 225 |
| 224 m_context = CanvasRenderingContext2D::create(this, attributes, docum ent()); | 226 m_context = CanvasRenderingContext2D::create(this, attributes, docum ent()); |
| 225 setNeedsCompositingUpdate(); | 227 setNeedsCompositingUpdate(); |
| 226 } | 228 } |
| 227 result.setCanvasRenderingContext2D(static_cast<CanvasRenderingContext2D* >(m_context.get())); | 229 result.setCanvasRenderingContext2D(static_cast<CanvasRenderingContext2D* >(m_context.get())); |
| 228 return; | 230 return; |
| 229 } | 231 } |
| 230 | 232 |
| 231 // Accept the the provisional "experimental-webgl" or official "webgl" conte xt ID. | 233 // Accept the the provisional "experimental-webgl" or official "webgl" conte xt ID. |
| 232 if (type == "webgl" || type == "experimental-webgl") { | 234 ContextType contextType; |
| 233 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExpe rimentalWebgl; | 235 bool is3dContext = true; |
| 236 if (type == "experimental-webgl") | |
| 237 contextType = ContextExperimentalWebgl; | |
| 238 else if (type == "webgl") | |
| 239 contextType = ContextWebgl; | |
| 240 else if (type == "webgl2") | |
| 241 contextType = ContextWebgl2; | |
| 242 else | |
| 243 is3dContext = false; | |
| 244 | |
| 245 if (is3dContext) { | |
| 234 if (!m_context) { | 246 if (!m_context) { |
| 235 blink::Platform::current()->histogramEnumeration("Canvas.ContextType ", contextType, ContextTypeCount); | 247 blink::Platform::current()->histogramEnumeration("Canvas.ContextType ", contextType, ContextTypeCount); |
|
Ken Russell (switch to Gerrit)
2015/02/03 01:23:24
Does any histogram need to be updated on the Chrom
| |
| 236 m_context = WebGLRenderingContext::create(this, attributes); | 248 if (contextType == ContextWebgl2) { |
| 249 m_context = WebGL2RenderingContext::create(this, attributes); | |
| 250 } else { | |
| 251 m_context = WebGLRenderingContext::create(this, attributes); | |
| 252 } | |
| 237 RenderStyle* style = computedStyle(); | 253 RenderStyle* style = computedStyle(); |
| 238 if (style && m_context) | 254 if (style && m_context) |
| 239 toWebGLRenderingContext(m_context.get())->setFilterLevel(style-> imageRendering() == ImageRenderingPixelated ? SkPaint::kNone_FilterLevel : SkPai nt::kLow_FilterLevel); | 255 toWebGLRenderingContext(m_context.get())->setFilterLevel(style-> imageRendering() == ImageRenderingPixelated ? SkPaint::kNone_FilterLevel : SkPai nt::kLow_FilterLevel); |
| 240 setNeedsCompositingUpdate(); | 256 setNeedsCompositingUpdate(); |
| 241 updateExternallyAllocatedMemory(); | 257 updateExternallyAllocatedMemory(); |
| 242 } else if (!m_context->is3d()) { | 258 } else if (!m_context->is3d()) { |
| 243 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext creationerror, false, true, "Canvas has an existing, non-WebGL context")); | 259 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext creationerror, false, true, "Canvas has an existing, non-WebGL context")); |
| 244 return; | 260 return; |
| 245 } | 261 } |
| 246 result.setWebGLRenderingContext(static_cast<WebGLRenderingContext*>(m_co ntext.get())); | 262 result.setWebGLRenderingContext(static_cast<WebGLRenderingContext*>(m_co ntext.get())); |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 { | 853 { |
| 838 return !originClean(); | 854 return !originClean(); |
| 839 } | 855 } |
| 840 | 856 |
| 841 FloatSize HTMLCanvasElement::sourceSize() const | 857 FloatSize HTMLCanvasElement::sourceSize() const |
| 842 { | 858 { |
| 843 return FloatSize(width(), height()); | 859 return FloatSize(width(), height()); |
| 844 } | 860 } |
| 845 | 861 |
| 846 } | 862 } |
| OLD | NEW |