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 13 matching lines...) Expand all Loading... | |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "HTMLCanvasElement.h" | 29 #include "HTMLCanvasElement.h" |
| 30 | 30 |
| 31 #include <math.h> | 31 #include <math.h> |
| 32 #include <stdio.h> | 32 #include <stdio.h> |
| 33 #include "Attribute.h" | 33 #include "Attribute.h" |
| 34 #include "CanvasContextAttributes.h" | 34 #include "Canvas2DContextAttributes.h" |
| 35 #include "CanvasGradient.h" | 35 #include "CanvasGradient.h" |
| 36 #include "CanvasPattern.h" | 36 #include "CanvasPattern.h" |
| 37 #include "CanvasRenderingContext2D.h" | 37 #include "CanvasRenderingContext2D.h" |
| 38 #include "CanvasStyle.h" | 38 #include "CanvasStyle.h" |
| 39 #include "Document.h" | 39 #include "Document.h" |
| 40 #include "ExceptionCode.h" | 40 #include "ExceptionCode.h" |
| 41 #include "HTMLNames.h" | 41 #include "HTMLNames.h" |
| 42 #include "ImageData.h" | 42 #include "ImageData.h" |
| 43 #include "ScriptController.h" | 43 #include "ScriptController.h" |
| 44 #include "WebCoreMemoryInstrumentation.h" | 44 #include "WebCoreMemoryInstrumentation.h" |
| 45 #include "core/page/Chrome.h" | 45 #include "core/page/Chrome.h" |
| 46 #include "core/page/Frame.h" | 46 #include "core/page/Frame.h" |
| 47 #include "core/page/Page.h" | 47 #include "core/page/Page.h" |
| 48 #include "core/page/RuntimeEnabledFeatures.h" | |
| 48 #include "core/page/Settings.h" | 49 #include "core/page/Settings.h" |
| 49 #include "core/platform/MIMETypeRegistry.h" | 50 #include "core/platform/MIMETypeRegistry.h" |
| 50 #include "core/platform/graphics/GraphicsContext.h" | 51 #include "core/platform/graphics/GraphicsContext.h" |
| 51 #include "core/platform/graphics/ImageBuffer.h" | 52 #include "core/platform/graphics/ImageBuffer.h" |
| 52 #include "core/rendering/RenderHTMLCanvas.h" | 53 #include "core/rendering/RenderHTMLCanvas.h" |
| 53 | 54 |
| 54 #include "WebGLContextAttributes.h" | 55 #include "WebGLContextAttributes.h" |
| 55 #include "WebGLRenderingContext.h" | 56 #include "WebGLRenderingContext.h" |
| 56 | 57 |
| 57 #include <public/Platform.h> | 58 #include <public/Platform.h> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas ContextAttributes* attrs) | 154 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas ContextAttributes* attrs) |
| 154 { | 155 { |
| 155 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing | 156 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing |
| 156 // context is already 2D, just return that. If the existing context is WebGL , then destroy it | 157 // context is already 2D, just return that. If the existing context is WebGL , then destroy it |
| 157 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a | 158 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a |
| 158 // context with any other type string will destroy any existing context. | 159 // context with any other type string will destroy any existing context. |
| 159 | 160 |
| 160 // FIXME - The code depends on the context not going away once created, to p revent JS from | 161 // FIXME - The code depends on the context not going away once created, to p revent JS from |
| 161 // seeing a dangling pointer. So for now we will disallow the context from b eing changed | 162 // seeing a dangling pointer. So for now we will disallow the context from b eing changed |
| 162 // once it is created. | 163 // once it is created. |
| 164 Settings* settings = document()->settings(); | |
|
jamesr
2013/04/26 18:30:09
not sure why this moved, it doesn't appear to be u
Stephen White
2013/04/26 18:53:18
Leftover from an earlier change. Reverted.
| |
| 163 if (type == "2d") { | 165 if (type == "2d") { |
| 164 if (m_context && !m_context->is2d()) | 166 if (m_context && !m_context->is2d()) |
| 165 return 0; | 167 return 0; |
| 166 if (!m_context) { | 168 if (!m_context) { |
| 167 m_context = CanvasRenderingContext2D::create(this, document()->inQui rksMode()); | 169 m_context = CanvasRenderingContext2D::create(this, RuntimeEnabledFea tures::experimentalCanvasFeaturesEnabled() ? static_cast<Canvas2DContextAttribut es*>(attrs) : 0, document()->inQuirksMode()); |
| 168 if (m_context) { | 170 if (m_context) { |
| 169 // Need to make sure a RenderLayer and compositing layer get cre ated for the Canvas | 171 // Need to make sure a RenderLayer and compositing layer get cre ated for the Canvas |
| 170 setNeedsStyleRecalc(SyntheticStyleChange); | 172 setNeedsStyleRecalc(SyntheticStyleChange); |
| 171 } | 173 } |
| 172 } | 174 } |
| 173 return m_context.get(); | 175 return m_context.get(); |
| 174 } | 176 } |
| 175 | 177 |
| 176 Settings* settings = document()->settings(); | |
| 177 if (settings && settings->webGLEnabled()) { | 178 if (settings && settings->webGLEnabled()) { |
| 178 | 179 |
| 179 // Accept the legacy "webkit-3d" name as well as the provisional "experi mental-webgl" name. | 180 // Accept the legacy "webkit-3d" name as well as the provisional "experi mental-webgl" name. |
| 180 bool is3dContext = (type == "webkit-3d") || (type == "experimental-webgl "); | 181 bool is3dContext = (type == "webkit-3d") || (type == "experimental-webgl "); |
| 181 | 182 |
| 182 #if !OS(ANDROID) | 183 #if !OS(ANDROID) |
| 183 // Now that WebGL is ratified, we will also accept "webgl" as the contex t name in Chrome. | 184 // Now that WebGL is ratified, we will also accept "webgl" as the contex t name in Chrome. |
| 184 is3dContext |= (type == "webgl"); | 185 is3dContext |= (type == "webgl"); |
| 185 #endif | 186 #endif |
| 186 | 187 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 if (m_context) { | 327 if (m_context) { |
| 327 if (!paintsIntoCanvasBuffer() && !document()->printing()) | 328 if (!paintsIntoCanvasBuffer() && !document()->printing()) |
| 328 return; | 329 return; |
| 329 m_context->paintRenderingResultsToCanvas(); | 330 m_context->paintRenderingResultsToCanvas(); |
| 330 } | 331 } |
| 331 | 332 |
| 332 if (hasCreatedImageBuffer()) { | 333 if (hasCreatedImageBuffer()) { |
| 333 ImageBuffer* imageBuffer = buffer(); | 334 ImageBuffer* imageBuffer = buffer(); |
| 334 if (imageBuffer) { | 335 if (imageBuffer) { |
| 335 if (m_presentedImage) | 336 if (m_presentedImage) |
| 336 context->drawImage(m_presentedImage.get(), ColorSpaceDeviceRGB, pixelSnappedIntRect(r), CompositeSourceOver, DoNotRespectImageOrientation, useLo wQualityScale); | 337 context->drawImage(m_presentedImage.get(), ColorSpaceDeviceRGB, pixelSnappedIntRect(r), !m_context || m_context->hasAlpha() ? CompositeSourceOve r : CompositeCopy, DoNotRespectImageOrientation, useLowQualityScale); |
|
jamesr
2013/04/26 18:30:09
i'd suggest moving the ternary bit out to a local
Stephen White
2013/04/26 18:53:18
Done.
| |
| 337 else | 338 else |
| 338 context->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, pixel SnappedIntRect(r), CompositeSourceOver, BlendModeNormal, useLowQualityScale); | 339 context->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, pixel SnappedIntRect(r), !m_context || m_context->hasAlpha() ? CompositeSourceOver : C ompositeCopy, BlendModeNormal, useLowQualityScale); |
| 339 } | 340 } |
| 340 } | 341 } |
| 341 | 342 |
| 342 if (is3D()) | 343 if (is3D()) |
| 343 static_cast<WebGLRenderingContext*>(m_context.get())->markLayerComposite d(); | 344 static_cast<WebGLRenderingContext*>(m_context.get())->markLayerComposite d(); |
| 344 } | 345 } |
| 345 | 346 |
| 346 bool HTMLCanvasElement::is3D() const | 347 bool HTMLCanvasElement::is3D() const |
| 347 { | 348 { |
| 348 return m_context && m_context->is3d(); | 349 return m_context && m_context->is3d(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 return; | 497 return; |
| 497 | 498 |
| 498 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim) | 499 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim) |
| 499 return; | 500 return; |
| 500 | 501 |
| 501 IntSize bufferSize(deviceSize.width(), deviceSize.height()); | 502 IntSize bufferSize(deviceSize.width(), deviceSize.height()); |
| 502 if (!bufferSize.width() || !bufferSize.height()) | 503 if (!bufferSize.width() || !bufferSize.height()) |
| 503 return; | 504 return; |
| 504 | 505 |
| 505 RenderingMode renderingMode = shouldAccelerate(bufferSize) ? Accelerated : U nacceleratedNonPlatformBuffer; | 506 RenderingMode renderingMode = shouldAccelerate(bufferSize) ? Accelerated : U nacceleratedNonPlatformBuffer; |
| 506 | 507 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; |
| 507 m_imageBuffer = ImageBuffer::create(size(), m_deviceScaleFactor, ColorSpaceD eviceRGB, renderingMode); | 508 m_imageBuffer = ImageBuffer::create(size(), m_deviceScaleFactor, ColorSpaceD eviceRGB, renderingMode, opacityMode); |
| 508 if (!m_imageBuffer) | 509 if (!m_imageBuffer) |
| 509 return; | 510 return; |
| 510 m_imageBuffer->context()->setShadowsIgnoreTransforms(true); | 511 m_imageBuffer->context()->setShadowsIgnoreTransforms(true); |
| 511 m_imageBuffer->context()->setImageInterpolationQuality(DefaultInterpolationQ uality); | 512 m_imageBuffer->context()->setImageInterpolationQuality(DefaultInterpolationQ uality); |
| 512 if (document()->settings() && !document()->settings()->antialiased2dCanvasEn abled()) | 513 if (document()->settings() && !document()->settings()->antialiased2dCanvasEn abled()) |
| 513 m_imageBuffer->context()->setShouldAntialias(false); | 514 m_imageBuffer->context()->setShouldAntialias(false); |
| 514 m_imageBuffer->context()->setStrokeThickness(1); | 515 m_imageBuffer->context()->setStrokeThickness(1); |
| 515 m_contextStateSaver = adoptPtr(new GraphicsContextStateSaver(*m_imageBuffer- >context())); | 516 m_contextStateSaver = adoptPtr(new GraphicsContextStateSaver(*m_imageBuffer- >context())); |
| 516 | 517 |
| 517 if (m_context && m_context->is2d()) { | 518 if (m_context && m_context->is2d()) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 HTMLElement::reportMemoryUsage(memoryObjectInfo); | 590 HTMLElement::reportMemoryUsage(memoryObjectInfo); |
| 590 info.addMember(m_observers, "observers"); | 591 info.addMember(m_observers, "observers"); |
| 591 info.addMember(m_context, "context"); | 592 info.addMember(m_context, "context"); |
| 592 info.addMember(m_imageBuffer, "imageBuffer"); | 593 info.addMember(m_imageBuffer, "imageBuffer"); |
| 593 info.addMember(m_contextStateSaver, "contextStateSaver"); | 594 info.addMember(m_contextStateSaver, "contextStateSaver"); |
| 594 info.addMember(m_presentedImage, "presentedImage"); | 595 info.addMember(m_presentedImage, "presentedImage"); |
| 595 info.addMember(m_copiedImage, "copiedImage"); | 596 info.addMember(m_copiedImage, "copiedImage"); |
| 596 } | 597 } |
| 597 | 598 |
| 598 } | 599 } |
| OLD | NEW |