diff options
author | Ben Murdoch <benm@google.com> | 2010-08-13 05:20:16 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-08-13 05:20:16 -0700 |
commit | f4958a7d95cd5fbc1c74905e229b02c95cd5ee78 (patch) | |
tree | 14a0f1b07a19948c2ed93d0d8547caa7fe10aa0e /WebCore/html/canvas/CanvasRenderingContext2D.cpp | |
parent | d074a7997da8ce379434eb6e208b97cde8a0841c (diff) | |
parent | f964bc1fd59a545a80a0cc2529ad8830be514871 (diff) | |
download | external_webkit-f4958a7d95cd5fbc1c74905e229b02c95cd5ee78.zip external_webkit-f4958a7d95cd5fbc1c74905e229b02c95cd5ee78.tar.gz external_webkit-f4958a7d95cd5fbc1c74905e229b02c95cd5ee78.tar.bz2 |
Merge changes I60a96064,I6929172f,Idefd9bec,I8cf448f2,I8791737a,I992c56b0,Ibb4b089d,I779a8ec0,Ife412e30,I2da1ae98,Ibcf41849
* changes:
Merge WebKit at r65072 : Update WebKit revision number.
Merge WebKit at r65072 : Update test_expectations.
Merge WebKit at r65072 : Complete cherry-pick of WebKit change 43848 to add EmptyDeviceMotionClient
Merge WebKit at r65072 : Implement DeviceMotionClientAndroid
Merge WebKit at r65072: JSC build fix in InspectorController.h
Merge WebKit at r65072: Fix V8 code generator.
Merge WebKit at r65072 : Build fix for JSC, update ambiguous usage of JSLock.
Merge WebKit at r65072: String class has moved to the WTF namespace.
Merge Webkit at r65072 : Fix conflicts.
Merge Webkit at r65072 : Fix Makefiles.
Merge WebKit at r65072 : Initial merge by git.
Diffstat (limited to 'WebCore/html/canvas/CanvasRenderingContext2D.cpp')
-rw-r--r-- | WebCore/html/canvas/CanvasRenderingContext2D.cpp | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp index 3b05348..559ddda 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp @@ -58,7 +58,13 @@ #include "StrokeStyleApplier.h" #include "TextMetrics.h" -#include <stdio.h> +#if ENABLE(ACCELERATED_2D_CANVAS) +#include "FrameView.h" +#include "GraphicsContext3D.h" +#if USE(ACCELERATED_COMPOSITING) +#include "RenderLayer.h" +#endif +#endif #include <wtf/ByteArray.h> #include <wtf/MathExtras.h> @@ -100,6 +106,9 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo #if ENABLE(DASHBOARD_SUPPORT) , m_usesDashboardCompatibilityMode(usesDashboardCompatibilityMode) #endif +#if ENABLE(ACCELERATED_2D_CANVAS) + , m_context3D(0) +#endif { #if !ENABLE(DASHBOARD_SUPPORT) ASSERT_UNUSED(usesDashboardCompatibilityMode, !usesDashboardCompatibilityMode); @@ -108,17 +117,53 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo // Make sure that even if the drawingContext() has a different default // thickness, it is in sync with the canvas thickness. setLineWidth(lineWidth()); + +#if ENABLE(ACCELERATED_2D_CANVAS) + Page* p = canvas->document()->page(); + if (!p) + return; + if (!p->settings()->accelerated2dCanvasEnabled()) + return; + if (FrameView* view = canvas->document()->view()) { + if (ScrollView* rootView = view->root()) { + if (HostWindow* hostWindow = view->root()->hostWindow()) { + // Set up our context + GraphicsContext3D::Attributes attr; + attr.stencil = true; + m_context3D = GraphicsContext3D::create(attr, hostWindow); + if (m_context3D) + if (GraphicsContext* c = drawingContext()) + c->setGraphicsContext3D(m_context3D.get(), IntSize(canvas->width(), canvas->height())); + } + } + } +#endif } CanvasRenderingContext2D::~CanvasRenderingContext2D() { } +bool CanvasRenderingContext2D::isAccelerated() const +{ +#if ENABLE(ACCELERATED_2D_CANVAS) + return m_context3D; +#else + return false; +#endif +} + void CanvasRenderingContext2D::reset() { m_stateStack.resize(1); m_stateStack.first() = State(); m_path.clear(); +#if ENABLE(ACCELERATED_2D_CANVAS) + if (m_context3D) { + if (GraphicsContext* c = drawingContext()) + c->setGraphicsContext3D(m_context3D.get(), IntSize(canvas()->width(), canvas()->height())); + } +#endif } CanvasRenderingContext2D::State::State() @@ -511,6 +556,8 @@ void CanvasRenderingContext2D::setStrokeColor(const String& color) void CanvasRenderingContext2D::setStrokeColor(float grayLevel) { + if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(grayLevel, grayLevel, grayLevel, 1.0f)) + return; setStrokeStyle(CanvasStyle::create(grayLevel, 1)); } @@ -521,16 +568,22 @@ void CanvasRenderingContext2D::setStrokeColor(const String& color, float alpha) void CanvasRenderingContext2D::setStrokeColor(float grayLevel, float alpha) { + if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(grayLevel, grayLevel, grayLevel, alpha)) + return; setStrokeStyle(CanvasStyle::create(grayLevel, alpha)); } void CanvasRenderingContext2D::setStrokeColor(float r, float g, float b, float a) { + if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(r, g, b, a)) + return; setStrokeStyle(CanvasStyle::create(r, g, b, a)); } void CanvasRenderingContext2D::setStrokeColor(float c, float m, float y, float k, float a) { + if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(c, m, y, k, a)) + return; setStrokeStyle(CanvasStyle::create(c, m, y, k, a)); } @@ -544,6 +597,8 @@ void CanvasRenderingContext2D::setFillColor(const String& color) void CanvasRenderingContext2D::setFillColor(float grayLevel) { + if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(grayLevel, grayLevel, grayLevel, 1.0f)) + return; setFillStyle(CanvasStyle::create(grayLevel, 1)); } @@ -554,16 +609,22 @@ void CanvasRenderingContext2D::setFillColor(const String& color, float alpha) void CanvasRenderingContext2D::setFillColor(float grayLevel, float alpha) { + if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(grayLevel, grayLevel, grayLevel, alpha)) + return; setFillStyle(CanvasStyle::create(grayLevel, alpha)); } void CanvasRenderingContext2D::setFillColor(float r, float g, float b, float a) { + if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(r, g, b, a)) + return; setFillStyle(CanvasStyle::create(r, g, b, a)); } void CanvasRenderingContext2D::setFillColor(float c, float m, float y, float k, float a) { + if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(c, m, y, k, a)) + return; setFillStyle(CanvasStyle::create(c, m, y, k, a)); } @@ -1434,7 +1495,14 @@ void CanvasRenderingContext2D::willDraw(const FloatRect& r, unsigned options) // we'd have to keep the clip path around. } - canvas()->willDraw(dirtyRect); +#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING) + // If we are drawing to hardware and we have a composited layer, just call rendererContentChanged(). + RenderBox* renderBox = canvas()->renderBox(); + if (m_context3D && renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing()) + renderBox->layer()->rendererContentChanged(); + else +#endif + canvas()->willDraw(dirtyRect); } GraphicsContext* CanvasRenderingContext2D::drawingContext() const @@ -1772,4 +1840,11 @@ const Font& CanvasRenderingContext2D::accessFont() return state().m_font; } +void CanvasRenderingContext2D::paintRenderingResultsToCanvas() +{ +#if ENABLE(ACCELERATED_2D_CANVAS) + drawingContext()->syncSoftwareCanvas(); +#endif +} + } // namespace WebCore |