- Revision
- 93157
- Author
- [email protected]
- Date
- 2011-08-16 14:32:39 -0700 (Tue, 16 Aug 2011)
Log Message
Canvas resizing can be slow
https://bugs.webkit.org/show_bug.cgi?id=66251
Canvas resizing was slow due to re-allocation of the ImageBuffer on
each size change (width or height). This was introduced inadvertently
by calls to isAccelerated() during canvas reset(). Since we won't
know if we have successfully accelerated until ImageBuffer creation,
move the compositor invalidation to createImageBuffer() as well.
This patch also attempts to unify the Skia and CG accelerated canvas
paths. The DrawingBuffer used by the Skia path is now owned by
ImageBuffer[Skia], similar to how the IOSurface is owned by
ImageBuffer[CG]. Some of the logic for when to accelerate was moved
into HTMLCanvasElement and unified with the CG path. Acceleration is
also now enabled by the same "Accelerated" ImageBuffer create flag
used by the CG path. DrawingBuffer is now re-created even for a
same-size change (same as the memory buffer), but we speed it up
by calling GraphicsContext3D::texImage2D() with a NULL pixels ptr
instead of GraphicsContext3D::teximage2DResourceSafe() (no need to
clear it, since it's done with a glClear anyway).
Reviewed by Kenneth Russell.
Covered by existing tests in fast/canvas and canvas/philip.
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::reset):
Don't call isAccelerated() from reset(), since we don't want to
inadvertently create the ImageBuffer. Also, since we won't know if
we have successfully accelerated until createImageBuffer() is
called, defer the compositor invalidation to createImageBuffer() as
well.
(WebCore::HTMLCanvasElement::shouldAccelerate):
Unify the CG and Skia ports' logic for when to accelerate (Skia
logic moved in from CanvasRenderingContext2D).
(WebCore::HTMLCanvasElement::createImageBuffer):
Use the unified shouldAccelerate() logic, and pass it as a flag
to ImageBuffer. Do compositor invalidation as well.
* html/HTMLCanvasElement.h:
(WebCore::HTMLCanvasElement::hasCreatedImageBuffer):
Expose hasCreatedImageBuffer() publically, so
CanvasRenderingContext2D::isAccelerated() doesn't inadvertently create
it.
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
(WebCore::CanvasRenderingContext2D::~CanvasRenderingContext2D):
Remove all acceleration setting and resetting, since it's now done
during ImageBuffer creation.
(WebCore::CanvasRenderingContext2D::isAccelerated):
Check if the image buffer was created, so we don't inadvertently
create it here.
(WebCore::CanvasRenderingContext2D::paintsIntoCanvasBuffer):
Don't call GraphicsContext3D::paintsIntoCanvasBuffer(), since its
WebViewImpl may be null. Ask the render tree instead.
(WebCore::CanvasRenderingContext2D::reset):
Don't reset acceleration here, since we don't own it anymore.
(WebCore::CanvasRenderingContext2D::platformLayer):
Call into the ImageBuffer to get our PlatformLayer.
* html/canvas/CanvasRenderingContext2D.h:
Remove m_drawingBuffer, and all acceleration-related calls.
* platform/graphics/GraphicsContext.cpp:
* platform/graphics/GraphicsContext.h:
Remove setGraphicsContext3D(), and paintsIntoImageBuffer().
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::platformLayer):
Implement a dummy platformLayer() call for non-skia ports.
* platform/graphics/ImageBuffer.h:
Declare a platformLayer() call (USE(ACCELERATED_COMPOSITING) only).
* platform/graphics/chromium/ImageBufferDataSkia.h:
Add a DrawingBuffer data member.
* platform/graphics/gpu/DrawingBuffer.cpp:
(WebCore::DrawingBuffer::reset):
Use texImage2D() with a NULL ptr, not texImage2DResourceSafe().
Since we immediately clear the framebuffer via glClear(), this whole
resource safe business is overkill.
* platform/graphics/skia/GraphicsContextSkia.cpp:
Remove setGraphicsContext3D() and paintsIntoImageBuffer(). This
functionality is handled by ImageBuffer now.
* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::ImageBuffer::ImageBuffer):
Give the ImageBufferData ownership of the DrawingBuffer.
(WebCore::ImageBuffer::platformLayer):
Implement an accessor for the DrawingBuffer's PlatformLayer.
* platform/graphics/skia/PlatformContextSkia.cpp:
(WebCore::PlatformContextSkia::setGraphicsContext3D):
* platform/graphics/skia/PlatformContextSkia.h:
Remove isPathSkiaSafe() extern (unused).
Remove paintsIntoImageBuffer() (now unused). Remove IntSize param
from setGraphicsContext3D() (unused).
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (93156 => 93157)
--- trunk/Source/WebCore/ChangeLog 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/ChangeLog 2011-08-16 21:32:39 UTC (rev 93157)
@@ -1,3 +1,94 @@
+2011-08-15 Stephen White <[email protected]>
+
+ Canvas resizing can be slow
+ https://bugs.webkit.org/show_bug.cgi?id=66251
+
+ Canvas resizing was slow due to re-allocation of the ImageBuffer on
+ each size change (width or height). This was introduced inadvertently
+ by calls to isAccelerated() during canvas reset(). Since we won't
+ know if we have successfully accelerated until ImageBuffer creation,
+ move the compositor invalidation to createImageBuffer() as well.
+ This patch also attempts to unify the Skia and CG accelerated canvas
+ paths. The DrawingBuffer used by the Skia path is now owned by
+ ImageBuffer[Skia], similar to how the IOSurface is owned by
+ ImageBuffer[CG]. Some of the logic for when to accelerate was moved
+ into HTMLCanvasElement and unified with the CG path. Acceleration is
+ also now enabled by the same "Accelerated" ImageBuffer create flag
+ used by the CG path. DrawingBuffer is now re-created even for a
+ same-size change (same as the memory buffer), but we speed it up
+ by calling GraphicsContext3D::texImage2D() with a NULL pixels ptr
+ instead of GraphicsContext3D::teximage2DResourceSafe() (no need to
+ clear it, since it's done with a glClear anyway).
+
+ Reviewed by Kenneth Russell.
+
+ Covered by existing tests in fast/canvas and canvas/philip.
+
+ * html/HTMLCanvasElement.cpp:
+ (WebCore::HTMLCanvasElement::reset):
+ Don't call isAccelerated() from reset(), since we don't want to
+ inadvertently create the ImageBuffer. Also, since we won't know if
+ we have successfully accelerated until createImageBuffer() is
+ called, defer the compositor invalidation to createImageBuffer() as
+ well.
+ (WebCore::HTMLCanvasElement::shouldAccelerate):
+ Unify the CG and Skia ports' logic for when to accelerate (Skia
+ logic moved in from CanvasRenderingContext2D).
+ (WebCore::HTMLCanvasElement::createImageBuffer):
+ Use the unified shouldAccelerate() logic, and pass it as a flag
+ to ImageBuffer. Do compositor invalidation as well.
+ * html/HTMLCanvasElement.h:
+ (WebCore::HTMLCanvasElement::hasCreatedImageBuffer):
+ Expose hasCreatedImageBuffer() publically, so
+ CanvasRenderingContext2D::isAccelerated() doesn't inadvertently create
+ it.
+ * html/canvas/CanvasRenderingContext2D.cpp:
+ (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
+ (WebCore::CanvasRenderingContext2D::~CanvasRenderingContext2D):
+ Remove all acceleration setting and resetting, since it's now done
+ during ImageBuffer creation.
+ (WebCore::CanvasRenderingContext2D::isAccelerated):
+ Check if the image buffer was created, so we don't inadvertently
+ create it here.
+ (WebCore::CanvasRenderingContext2D::paintsIntoCanvasBuffer):
+ Don't call GraphicsContext3D::paintsIntoCanvasBuffer(), since its
+ WebViewImpl may be null. Ask the render tree instead.
+ (WebCore::CanvasRenderingContext2D::reset):
+ Don't reset acceleration here, since we don't own it anymore.
+ (WebCore::CanvasRenderingContext2D::platformLayer):
+ Call into the ImageBuffer to get our PlatformLayer.
+ * html/canvas/CanvasRenderingContext2D.h:
+ Remove m_drawingBuffer, and all acceleration-related calls.
+ * platform/graphics/GraphicsContext.cpp:
+ * platform/graphics/GraphicsContext.h:
+ Remove setGraphicsContext3D(), and paintsIntoImageBuffer().
+ * platform/graphics/ImageBuffer.cpp:
+ (WebCore::ImageBuffer::platformLayer):
+ Implement a dummy platformLayer() call for non-skia ports.
+ * platform/graphics/ImageBuffer.h:
+ Declare a platformLayer() call (USE(ACCELERATED_COMPOSITING) only).
+ * platform/graphics/chromium/ImageBufferDataSkia.h:
+ Add a DrawingBuffer data member.
+ * platform/graphics/gpu/DrawingBuffer.cpp:
+ (WebCore::DrawingBuffer::reset):
+ Use texImage2D() with a NULL ptr, not texImage2DResourceSafe().
+ Since we immediately clear the framebuffer via glClear(), this whole
+ resource safe business is overkill.
+ * platform/graphics/skia/GraphicsContextSkia.cpp:
+ Remove setGraphicsContext3D() and paintsIntoImageBuffer(). This
+ functionality is handled by ImageBuffer now.
+ * platform/graphics/skia/ImageBufferSkia.cpp:
+ (WebCore::ImageBuffer::ImageBuffer):
+ Give the ImageBufferData ownership of the DrawingBuffer.
+ (WebCore::ImageBuffer::platformLayer):
+ Implement an accessor for the DrawingBuffer's PlatformLayer.
+ * platform/graphics/skia/PlatformContextSkia.cpp:
+ (WebCore::PlatformContextSkia::setGraphicsContext3D):
+ * platform/graphics/skia/PlatformContextSkia.h:
+ Remove isPathSkiaSafe() extern (unused).
+ Remove paintsIntoImageBuffer() (now unused). Remove IntSize param
+ from setGraphicsContext3D() (unused).
+
2011-08-16 Joseph Pecoraro <[email protected]>
Unreviewed Chromium Windows build fix after r93140. Take 3.
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (93156 => 93157)
--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2011-08-16 21:32:39 UTC (rev 93157)
@@ -247,15 +247,7 @@
if (m_context && m_context->is2d()) {
CanvasRenderingContext2D* context2D = static_cast<CanvasRenderingContext2D*>(m_context.get());
- bool wasAccelerated = context2D->isAccelerated();
context2D->reset();
-#if USE(IOSURFACE_CANVAS_BACKING_STORE) || (ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING))
- // Recalculate compositing requirements if acceleration state changed.
- if (context2D->isAccelerated() != wasAccelerated)
- setNeedsStyleRecalc(SyntheticStyleChange);
-#else
- UNUSED_PARAM(wasAccelerated);
-#endif
}
if (RenderObject* renderer = this->renderer()) {
@@ -424,6 +416,30 @@
return document()->styleSelector();
}
+bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const
+{
+#if USE(IOSURFACE_CANVAS_BACKING_STORE)
+ UNUSED_PARAM(size);
+ return document()->settings()->canvasUsesAcceleratedDrawing();
+#elif ENABLE(ACCELERATED_2D_CANVAS)
+ if (m_context && !m_context->is2d())
+ return false;
+
+ Settings* settings = document()->settings();
+ if (!settings->accelerated2dCanvasEnabled())
+ return false;
+
+ // Do not use acceleration for small canvas.
+ if (size.width() * size.height() < settings->minimumAccelerated2dCanvasSize())
+ return false;
+
+ return true;
+#else
+ UNUSED_PARAM(size);
+ return false;
+#endif
+}
+
void HTMLCanvasElement::createImageBuffer() const
{
ASSERT(!m_imageBuffer);
@@ -435,14 +451,8 @@
if (!size.width() || !size.height())
return;
-#if USE(IOSURFACE_CANVAS_BACKING_STORE)
- if (document()->settings()->canvasUsesAcceleratedDrawing())
- m_imageBuffer = ImageBuffer::create(size, ColorSpaceDeviceRGB, Accelerated);
- else
- m_imageBuffer = ImageBuffer::create(size, ColorSpaceDeviceRGB, Unaccelerated);
-#else
- m_imageBuffer = ImageBuffer::create(size);
-#endif
+ RenderingMode renderingMode = shouldAccelerate(size) ? Accelerated : Unaccelerated;
+ m_imageBuffer = ImageBuffer::create(size, ColorSpaceDeviceRGB, renderingMode);
// The convertLogicalToDevice MaxCanvasArea check should prevent common cases
// where ImageBuffer::create() returns 0, however we could still be low on memory.
if (!m_imageBuffer)
@@ -455,6 +465,12 @@
JSC::JSLock lock(JSC::SilenceAssertionsOnly);
scriptExecutionContext()->globalData()->heap.reportExtraMemoryCost(m_imageBuffer->dataSize());
#endif
+
+#if USE(IOSURFACE_CANVAS_BACKING_STORE) || (ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING))
+ if (m_context && m_context->is2d())
+ // Recalculate compositing requirements if acceleration state changed.
+ const_cast<HTMLCanvasElement*>(this)->setNeedsStyleRecalc(SyntheticStyleChange);
+#endif
}
GraphicsContext* HTMLCanvasElement::drawingContext() const
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (93156 => 93157)
--- trunk/Source/WebCore/html/HTMLCanvasElement.h 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h 2011-08-16 21:32:39 UTC (rev 93157)
@@ -128,6 +128,7 @@
#endif
void makeRenderingResultsAvailable();
+ bool hasCreatedImageBuffer() const { return m_hasCreatedImageBuffer; }
private:
HTMLCanvasElement(const QualifiedName&, Document*);
@@ -137,10 +138,10 @@
void reset();
+ bool shouldAccelerate(const IntSize&) const;
void createImageBuffer() const;
void setSurfaceSize(const IntSize&);
- bool hasCreatedImageBuffer() const { return m_hasCreatedImageBuffer; }
HashSet<CanvasObserver*> m_observers;
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (93156 => 93157)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2011-08-16 21:32:39 UTC (rev 93157)
@@ -61,16 +61,9 @@
#include "TextMetrics.h"
#include "TextRun.h"
-#if ENABLE(ACCELERATED_2D_CANVAS)
-#include "Chrome.h"
-#include "ChromeClient.h"
-#include "DrawingBuffer.h"
-#include "FrameView.h"
-#include "SharedGraphicsContext3D.h"
#if USE(ACCELERATED_COMPOSITING)
#include "RenderLayer.h"
#endif
-#endif
#include <wtf/ByteArray.h>
#include <wtf/MathExtras.h>
@@ -98,25 +91,6 @@
return !securityOrigin->taintsCanvas(cachedImage->response().url());
}
-#if ENABLE(ACCELERATED_2D_CANVAS)
-static bool shouldAccelerateCanvas(const HTMLCanvasElement* canvas)
-{
- const Page* page = canvas->document()->page();
- if (!page)
- return false;
-
- const Settings* settings = page->settings();
- if (!settings->accelerated2dCanvasEnabled())
- return false;
-
- // Do not use acceleration for small canvas.
- if (canvas->width() * canvas->height() < settings->minimumAccelerated2dCanvasSize())
- return false;
-
- return true;
-}
-#endif
-
class CanvasStrokeStyleApplier : public StrokeStyleApplier {
public:
CanvasStrokeStyleApplier(CanvasRenderingContext2D* canvasContext)
@@ -151,10 +125,6 @@
// 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)
- resetAcceleration();
-#endif
}
CanvasRenderingContext2D::~CanvasRenderingContext2D()
@@ -170,11 +140,6 @@
}
}
#endif
-
-#if ENABLE(ACCELERATED_2D_CANVAS)
- if (GraphicsContext* context = drawingContext())
- context->setGraphicsContext3D(0, 0, IntSize());
-#endif
}
bool CanvasRenderingContext2D::isAccelerated() const
@@ -183,7 +148,7 @@
ImageBuffer* buffer = canvas()->buffer();
return buffer ? buffer->isAccelerated() : false;
#elif ENABLE(ACCELERATED_2D_CANVAS)
- return drawingContext() && drawingContext()->isAcceleratedContext();
+ return canvas()->hasCreatedImageBuffer() && drawingContext() && drawingContext()->isAcceleratedContext();
#else
return false;
#endif
@@ -191,9 +156,13 @@
bool CanvasRenderingContext2D::paintsIntoCanvasBuffer() const
{
-#if ENABLE(ACCELERATED_2D_CANVAS)
- if (drawingContext())
- return drawingContext()->paintsIntoImageBuffer();
+#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
+ if (!isAccelerated())
+ return true;
+
+ RenderBox* renderBox = canvas()->renderBox();
+ if (renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing())
+ return false;
#endif
return true;
}
@@ -204,14 +173,11 @@
m_stateStack.resize(1);
m_stateStack.first() = State();
m_path.clear();
-#if ENABLE(ACCELERATED_2D_CANVAS)
- resetAcceleration();
#if USE(ACCELERATED_COMPOSITING)
RenderBox* renderBox = canvas()->renderBox();
if (renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing())
renderBox->layer()->contentChanged(RenderLayer::CanvasChanged);
#endif
-#endif
}
CanvasRenderingContext2D::State::State()
@@ -2015,58 +1981,11 @@
return state().m_font;
}
-#if ENABLE(ACCELERATED_2D_CANVAS)
-#if USE(ACCELERATED_COMPOSITING)
+#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
PlatformLayer* CanvasRenderingContext2D::platformLayer() const
{
- return m_drawingBuffer ? m_drawingBuffer->platformLayer() : 0;
+ return canvas()->buffer() ? canvas()->buffer()->platformLayer() : 0;
}
#endif
-void CanvasRenderingContext2D::clearAcceleration()
-{
- if (GraphicsContext* ctx = drawingContext())
- ctx->setGraphicsContext3D(0, 0, IntSize());
-
- m_drawingBuffer.clear();
-}
-
-void CanvasRenderingContext2D::resetAcceleration()
-{
- if (!shouldAccelerateCanvas(canvas())) {
- clearAcceleration();
- return;
- }
-
- // Try to accelerate.
- GraphicsContext* ctx = drawingContext();
- if (!ctx) {
- clearAcceleration();
- return;
- }
-
- Page* page = canvas()->document()->page();
- GraphicsContext3D* context3D = SharedGraphicsContext3D::create(page->chrome());
- if (!context3D) {
- clearAcceleration();
- return;
- }
-
- if (m_drawingBuffer) {
- if (!m_drawingBuffer->reset(canvas()->size())) {
- clearAcceleration();
- return;
- }
- } else {
- m_drawingBuffer = context3D->createDrawingBuffer(canvas()->size());
- if (!m_drawingBuffer) {
- clearAcceleration();
- return;
- }
- }
-
- ctx->setGraphicsContext3D(context3D, m_drawingBuffer.get(), canvas()->size());
-}
-#endif
-
} // namespace WebCore
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h (93156 => 93157)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h 2011-08-16 21:32:39 UTC (rev 93157)
@@ -53,11 +53,6 @@
class ImageData;
class TextMetrics;
-#if ENABLE(ACCELERATED_2D_CANVAS)
-class DrawingBuffer;
-class SharedGraphicsContext3D;
-#endif
-
typedef int ExceptionCode;
class CanvasRenderingContext2D : public CanvasRenderingContext {
@@ -294,20 +289,11 @@
void prepareGradientForDashboard(CanvasGradient* gradient) const;
-#if ENABLE(ACCELERATED_2D_CANVAS)
- void clearAcceleration();
- void resetAcceleration();
-#endif
-
Vector<State, 1> m_stateStack;
bool m_usesCSSCompatibilityParseMode;
#if ENABLE(DASHBOARD_SUPPORT)
bool m_usesDashboardCompatibilityMode;
#endif
-
-#if ENABLE(ACCELERATED_2D_CANVAS)
- RefPtr<DrawingBuffer> m_drawingBuffer;
-#endif
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp 2011-08-16 21:32:39 UTC (rev 93157)
@@ -684,12 +684,6 @@
}
#endif
-#if !USE(SKIA)
-void GraphicsContext::setGraphicsContext3D(GraphicsContext3D*, DrawingBuffer*, const IntSize&)
-{
-}
-#endif
-
#if !USE(SKIA) && !USE(CG)
bool GraphicsContext::isAcceleratedContext() const
{
@@ -697,13 +691,6 @@
}
#endif
-#if !USE(SKIA)
-bool GraphicsContext::paintsIntoImageBuffer() const
-{
- return true;
-}
-#endif
-
void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle penStyle)
{
// For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h 2011-08-16 21:32:39 UTC (rev 93157)
@@ -275,7 +275,6 @@
void setIsAcceleratedContext(bool);
#endif
bool isAcceleratedContext() const;
- bool paintsIntoImageBuffer() const;
void save();
void restore();
@@ -509,8 +508,6 @@
pattern getHaikuStrokeStyle();
#endif
- void setGraphicsContext3D(GraphicsContext3D*, DrawingBuffer*, const IntSize&);
-
static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle);
private:
Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp 2011-08-16 21:32:39 UTC (rev 93157)
@@ -95,4 +95,11 @@
genericConvertToLuminanceMask();
}
+#if USE(ACCELERATED_COMPOSITING) && !USE(SKIA)
+PlatformLayer* ImageBuffer::platformLayer() const
+{
+ return 0;
}
+#endif
+
+}
Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h 2011-08-16 21:32:39 UTC (rev 93157)
@@ -31,6 +31,9 @@
#include "AffineTransform.h"
#include "ColorSpace.h"
#include "FloatRect.h"
+#if USE(ACCELERATED_COMPOSITING)
+#include "GraphicsLayer.h"
+#endif
#include "GraphicsTypes.h"
#include "IntSize.h"
#include "ImageBufferData.h"
@@ -106,6 +109,9 @@
#else
AffineTransform baseTransform() const { return AffineTransform(1, 0, 0, -1, 0, m_size.height()); }
#endif
+#if USE(ACCELERATED_COMPOSITING)
+ PlatformLayer* platformLayer() const;
+#endif
private:
#if USE(CG)
Modified: trunk/Source/WebCore/platform/graphics/chromium/ImageBufferDataSkia.h (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/chromium/ImageBufferDataSkia.h 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/chromium/ImageBufferDataSkia.h 2011-08-16 21:32:39 UTC (rev 93157)
@@ -28,6 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "DrawingBuffer.h"
#include "PlatformContextSkia.h"
#include "skia/ext/platform_canvas.h"
@@ -40,6 +41,7 @@
OwnPtr<SkCanvas> m_canvas;
PlatformContextSkia m_platformContext;
+ RefPtr<DrawingBuffer> m_drawingBuffer;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp 2011-08-16 21:32:39 UTC (rev 93157)
@@ -270,7 +270,7 @@
m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
- m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE);
+ m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
Modified: trunk/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp 2011-08-16 21:32:39 UTC (rev 93157)
@@ -1203,21 +1203,11 @@
WebCoreFloatToSkScalar(h));
}
-void GraphicsContext::setGraphicsContext3D(GraphicsContext3D* context, DrawingBuffer* drawingBuffer, const IntSize& size)
-{
- platformContext()->setGraphicsContext3D(context, drawingBuffer, size);
-}
-
bool GraphicsContext::isAcceleratedContext() const
{
return platformContext()->isAccelerated();
}
-bool GraphicsContext::paintsIntoImageBuffer() const
-{
- return platformContext()->paintsIntoImageBuffer();
-}
-
#if PLATFORM(CHROMIUM) && OS(DARWIN)
CGColorSpaceRef deviceRGBColorSpaceRef()
{
Modified: trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp 2011-08-16 21:32:39 UTC (rev 93157)
@@ -43,6 +43,7 @@
#include "MIMETypeRegistry.h"
#include "PNGImageEncoder.h"
#include "PlatformContextSkia.h"
+#include "SharedGraphicsContext3D.h"
#include "SkColorPriv.h"
#include "SkiaUtils.h"
@@ -61,7 +62,7 @@
{
}
-ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, RenderingMode, bool& success)
+ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, RenderingMode renderingMode, bool& success)
: m_data(size)
, m_size(size)
{
@@ -80,6 +81,15 @@
// required, but the canvas is currently filled with the magic transparency
// color. Can we have another way to manage this?
m_data.m_canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
+ if (renderingMode == Accelerated) {
+ GraphicsContext3D* context3D = SharedGraphicsContext3D::create(0);
+ if (context3D) {
+ m_data.m_drawingBuffer = context3D->createDrawingBuffer(size);
+ if (m_data.m_drawingBuffer)
+ m_data.m_platformContext.setGraphicsContext3D(context3D, m_data.m_drawingBuffer.get());
+ }
+ }
+
success = true;
}
@@ -366,6 +376,11 @@
return ImageToDataURL(device->accessBitmap(false), mimeType, quality);
}
+PlatformLayer* ImageBuffer::platformLayer() const
+{
+ return m_data.m_drawingBuffer ? m_data.m_drawingBuffer->platformLayer() : 0;
+}
+
String ImageDataToDataURL(const ImageData& source, const String& mimeType, const double* quality)
{
return ImageToDataURL(source, mimeType, quality);
Modified: trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp 2011-08-16 21:32:39 UTC (rev 93157)
@@ -59,8 +59,6 @@
namespace WebCore {
-extern bool isPathSkiaSafe(const SkMatrix& transform, const SkPath& path);
-
// State -----------------------------------------------------------------------
// Encapsulates the additional painting state information we store for each
@@ -652,7 +650,7 @@
m_canvas->restore();
}
-void PlatformContextSkia::setGraphicsContext3D(GraphicsContext3D* context, DrawingBuffer* drawingBuffer, const WebCore::IntSize& size)
+void PlatformContextSkia::setGraphicsContext3D(GraphicsContext3D* context, DrawingBuffer* drawingBuffer)
{
m_gpuContext = context;
#if ENABLE(ACCELERATED_2D_CANVAS)
@@ -682,9 +680,4 @@
m_gpuContext->makeContextCurrent();
}
-bool PlatformContextSkia::paintsIntoImageBuffer() const
-{
- return m_gpuContext ? m_gpuContext->paintsIntoCanvasBuffer() : true;
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h (93156 => 93157)
--- trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h 2011-08-16 21:19:11 UTC (rev 93156)
+++ trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h 2011-08-16 21:32:39 UTC (rev 93157)
@@ -178,8 +178,7 @@
bool hasImageResamplingHint() const;
bool isAccelerated() const { return m_gpuContext; }
- void setGraphicsContext3D(GraphicsContext3D*, DrawingBuffer*, const IntSize&);
- bool paintsIntoImageBuffer() const;
+ void setGraphicsContext3D(GraphicsContext3D*, DrawingBuffer*);
void makeGrContextCurrent();
private: