Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: Source/core/html/HTMLCanvasElement.cpp

Issue 21861002: Add canvas context type histogram (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 ContextTypeCount,
162 };
Mark P 2013/08/02 15:40:55 Please add a note that new elements should only be
Sami 2013/08/02 16:05:25 Done.
155 163
156 // FIXME - The code depends on the context not going away once created, to p revent JS from 164 // 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 165 // seeing a dangling pointer. So for now we will disallow the context from b eing changed
158 // once it is created. 166 // once it is created.
159 if (type == "2d") { 167 if (type == "2d") {
160 if (m_context && !m_context->is2d()) 168 if (m_context && !m_context->is2d())
161 return 0; 169 return 0;
162 if (!m_context) { 170 if (!m_context) {
171 HistogramSupport::histogramEnumeration("Canvas.ContextType", Context 2d, ContextTypeCount);
163 m_context = CanvasRenderingContext2D::create(this, RuntimeEnabledFea tures::experimentalCanvasFeaturesEnabled() ? static_cast<Canvas2DContextAttribut es*>(attrs) : 0, document()->inQuirksMode()); 172 m_context = CanvasRenderingContext2D::create(this, RuntimeEnabledFea tures::experimentalCanvasFeaturesEnabled() ? static_cast<Canvas2DContextAttribut es*>(attrs) : 0, document()->inQuirksMode());
164 if (m_context) 173 if (m_context)
165 scheduleLayerUpdate(); 174 scheduleLayerUpdate();
166 } 175 }
167 return m_context.get(); 176 return m_context.get();
168 } 177 }
169 178
170 Settings* settings = document()->settings(); 179 Settings* settings = document()->settings();
171 if (settings && settings->webGLEnabled()) { 180 if (settings && settings->webGLEnabled()) {
172
173 // Accept the legacy "webkit-3d" name as well as the provisional "experi mental-webgl" name. 181 // 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. 182 // Now that WebGL is ratified, we will also accept "webgl" as the contex t name in Chrome.
177 is3dContext |= (type == "webgl"); 183 ContextType contextType;
184 bool is3dContext = true;
185 if (type == "webkit-3d")
186 contextType = ContextWebkit3d;
187 else if (type == "experimental-webgl")
188 contextType = ContextExperimentalWebgl;
189 else if (type == "webgl")
190 contextType = ContextWebgl;
191 else
192 is3dContext = false;
178 193
179 if (is3dContext) { 194 if (is3dContext) {
180 if (m_context && !m_context->is3d()) 195 if (m_context && !m_context->is3d())
181 return 0; 196 return 0;
182 if (!m_context) { 197 if (!m_context) {
198 HistogramSupport::histogramEnumeration("Canvas.ContextType", con textType, ContextTypeCount);
183 m_context = WebGLRenderingContext::create(this, static_cast<WebG LContextAttributes*>(attrs)); 199 m_context = WebGLRenderingContext::create(this, static_cast<WebG LContextAttributes*>(attrs));
184 if (m_context) 200 if (m_context)
185 scheduleLayerUpdate(); 201 scheduleLayerUpdate();
186 } 202 }
187 return m_context.get(); 203 return m_context.get();
188 } 204 }
189 } 205 }
190 return 0; 206 return 0;
191 } 207 }
192 208
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 FloatSize unscaledSize = size(); 583 FloatSize unscaledSize = size();
568 FloatSize deviceSize = convertLogicalToDevice(unscaledSize); 584 FloatSize deviceSize = convertLogicalToDevice(unscaledSize);
569 IntSize size(deviceSize.width(), deviceSize.height()); 585 IntSize size(deviceSize.width(), deviceSize.height());
570 AffineTransform transform; 586 AffineTransform transform;
571 if (size.width() && size.height()) 587 if (size.width() && size.height())
572 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig ht() / unscaledSize.height()); 588 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig ht() / unscaledSize.height());
573 return m_imageBuffer->baseTransform() * transform; 589 return m_imageBuffer->baseTransform() * transform;
574 } 590 }
575 591
576 } 592 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698