| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include <math.h> | 31 #include <math.h> |
| 32 #include <stdio.h> | 32 #include <stdio.h> |
| 33 #include "HTMLNames.h" | 33 #include "HTMLNames.h" |
| 34 #include "bindings/v8/ScriptController.h" | 34 #include "bindings/v8/ScriptController.h" |
| 35 #include "core/dom/Attribute.h" | 35 #include "core/dom/Attribute.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/dom/WebCoreMemoryInstrumentation.h" | 38 #include "core/dom/WebCoreMemoryInstrumentation.h" |
| 39 #include "core/html/ImageData.h" | 39 #include "core/html/ImageData.h" |
| 40 #include "core/html/canvas/CanvasContextAttributes.h" | 40 #include "core/html/canvas/Canvas2DContextAttributes.h" |
| 41 #include "core/html/canvas/CanvasGradient.h" | 41 #include "core/html/canvas/CanvasGradient.h" |
| 42 #include "core/html/canvas/CanvasPattern.h" | 42 #include "core/html/canvas/CanvasPattern.h" |
| 43 #include "core/html/canvas/CanvasRenderingContext2D.h" | 43 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 44 #include "core/html/canvas/CanvasStyle.h" | 44 #include "core/html/canvas/CanvasStyle.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 "core/html/canvas/WebGLContextAttributes.h" | 55 #include "core/html/canvas/WebGLContextAttributes.h" |
| 55 #include "core/html/canvas/WebGLRenderingContext.h" | 56 #include "core/html/canvas/WebGLRenderingContext.h" |
| 56 | 57 |
| 57 #include <public/Platform.h> | 58 #include <public/Platform.h> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 163 if (type == "2d") { | 164 if (type == "2d") { |
| 164 if (m_context && !m_context->is2d()) | 165 if (m_context && !m_context->is2d()) |
| 165 return 0; | 166 return 0; |
| 166 if (!m_context) { | 167 if (!m_context) { |
| 167 m_context = CanvasRenderingContext2D::create(this, document()->inQui
rksMode()); | 168 m_context = CanvasRenderingContext2D::create(this, RuntimeEnabledFea
tures::experimentalCanvasFeaturesEnabled() ? static_cast<Canvas2DContextAttribut
es*>(attrs) : 0, document()->inQuirksMode()); |
| 168 if (m_context) { | 169 if (m_context) { |
| 169 // Need to make sure a RenderLayer and compositing layer get cre
ated for the Canvas | 170 // Need to make sure a RenderLayer and compositing layer get cre
ated for the Canvas |
| 170 setNeedsStyleRecalc(SyntheticStyleChange); | 171 setNeedsStyleRecalc(SyntheticStyleChange); |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 return m_context.get(); | 174 return m_context.get(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 Settings* settings = document()->settings(); | 177 Settings* settings = document()->settings(); |
| 177 if (settings && settings->webGLEnabled()) { | 178 if (settings && settings->webGLEnabled()) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 322 |
| 322 if (m_context) { | 323 if (m_context) { |
| 323 if (!paintsIntoCanvasBuffer() && !document()->printing()) | 324 if (!paintsIntoCanvasBuffer() && !document()->printing()) |
| 324 return; | 325 return; |
| 325 m_context->paintRenderingResultsToCanvas(); | 326 m_context->paintRenderingResultsToCanvas(); |
| 326 } | 327 } |
| 327 | 328 |
| 328 if (hasCreatedImageBuffer()) { | 329 if (hasCreatedImageBuffer()) { |
| 329 ImageBuffer* imageBuffer = buffer(); | 330 ImageBuffer* imageBuffer = buffer(); |
| 330 if (imageBuffer) { | 331 if (imageBuffer) { |
| 332 CompositeOperator compositeOperator = !m_context || m_context->hasAl
pha() ? CompositeSourceOver : CompositeCopy; |
| 331 if (m_presentedImage) | 333 if (m_presentedImage) |
| 332 context->drawImage(m_presentedImage.get(), ColorSpaceDeviceRGB,
pixelSnappedIntRect(r), CompositeSourceOver, DoNotRespectImageOrientation, useLo
wQualityScale); | 334 context->drawImage(m_presentedImage.get(), ColorSpaceDeviceRGB,
pixelSnappedIntRect(r), compositeOperator, DoNotRespectImageOrientation, useLowQ
ualityScale); |
| 333 else | 335 else |
| 334 context->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, pixel
SnappedIntRect(r), CompositeSourceOver, BlendModeNormal, useLowQualityScale); | 336 context->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, pixel
SnappedIntRect(r), compositeOperator, BlendModeNormal, useLowQualityScale); |
| 335 } | 337 } |
| 336 } | 338 } |
| 337 | 339 |
| 338 if (is3D()) | 340 if (is3D()) |
| 339 static_cast<WebGLRenderingContext*>(m_context.get())->markLayerComposite
d(); | 341 static_cast<WebGLRenderingContext*>(m_context.get())->markLayerComposite
d(); |
| 340 } | 342 } |
| 341 | 343 |
| 342 bool HTMLCanvasElement::is3D() const | 344 bool HTMLCanvasElement::is3D() const |
| 343 { | 345 { |
| 344 return m_context && m_context->is3d(); | 346 return m_context && m_context->is3d(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 return; | 494 return; |
| 493 | 495 |
| 494 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim) | 496 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim) |
| 495 return; | 497 return; |
| 496 | 498 |
| 497 IntSize bufferSize(deviceSize.width(), deviceSize.height()); | 499 IntSize bufferSize(deviceSize.width(), deviceSize.height()); |
| 498 if (!bufferSize.width() || !bufferSize.height()) | 500 if (!bufferSize.width() || !bufferSize.height()) |
| 499 return; | 501 return; |
| 500 | 502 |
| 501 RenderingMode renderingMode = shouldAccelerate(bufferSize) ? Accelerated : U
nacceleratedNonPlatformBuffer; | 503 RenderingMode renderingMode = shouldAccelerate(bufferSize) ? Accelerated : U
nacceleratedNonPlatformBuffer; |
| 502 | 504 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque :
Opaque; |
| 503 m_imageBuffer = ImageBuffer::create(size(), m_deviceScaleFactor, ColorSpaceD
eviceRGB, renderingMode); | 505 m_imageBuffer = ImageBuffer::create(size(), m_deviceScaleFactor, ColorSpaceD
eviceRGB, renderingMode, opacityMode); |
| 504 if (!m_imageBuffer) | 506 if (!m_imageBuffer) |
| 505 return; | 507 return; |
| 506 m_imageBuffer->context()->setShadowsIgnoreTransforms(true); | 508 m_imageBuffer->context()->setShadowsIgnoreTransforms(true); |
| 507 m_imageBuffer->context()->setImageInterpolationQuality(DefaultInterpolationQ
uality); | 509 m_imageBuffer->context()->setImageInterpolationQuality(DefaultInterpolationQ
uality); |
| 508 if (document()->settings() && !document()->settings()->antialiased2dCanvasEn
abled()) | 510 if (document()->settings() && !document()->settings()->antialiased2dCanvasEn
abled()) |
| 509 m_imageBuffer->context()->setShouldAntialias(false); | 511 m_imageBuffer->context()->setShouldAntialias(false); |
| 510 m_imageBuffer->context()->setStrokeThickness(1); | 512 m_imageBuffer->context()->setStrokeThickness(1); |
| 511 m_contextStateSaver = adoptPtr(new GraphicsContextStateSaver(*m_imageBuffer-
>context())); | 513 m_contextStateSaver = adoptPtr(new GraphicsContextStateSaver(*m_imageBuffer-
>context())); |
| 512 | 514 |
| 513 if (m_context && m_context->is2d()) { | 515 if (m_context && m_context->is2d()) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 HTMLElement::reportMemoryUsage(memoryObjectInfo); | 587 HTMLElement::reportMemoryUsage(memoryObjectInfo); |
| 586 info.addMember(m_observers, "observers"); | 588 info.addMember(m_observers, "observers"); |
| 587 info.addMember(m_context, "context"); | 589 info.addMember(m_context, "context"); |
| 588 info.addMember(m_imageBuffer, "imageBuffer"); | 590 info.addMember(m_imageBuffer, "imageBuffer"); |
| 589 info.addMember(m_contextStateSaver, "contextStateSaver"); | 591 info.addMember(m_contextStateSaver, "contextStateSaver"); |
| 590 info.addMember(m_presentedImage, "presentedImage"); | 592 info.addMember(m_presentedImage, "presentedImage"); |
| 591 info.addMember(m_copiedImage, "copiedImage"); | 593 info.addMember(m_copiedImage, "copiedImage"); |
| 592 } | 594 } |
| 593 | 595 |
| 594 } | 596 } |
| OLD | NEW |