2010-09-03 James Robinson <jamesr@chromium.org>
authorjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Sep 2010 18:38:37 +0000 (18:38 +0000)
committerjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Sep 2010 18:38:37 +0000 (18:38 +0000)
        Reviewed by Chris Marrin.

        Multiple accelerated 2D canvases should be able to use the same GraphicsContext3D
        https://bugs.webkit.org/show_bug.cgi?id=44926

        This allows many accelerated 2d canvases to render using a single underlying GraphicsContext3D.
        It introduces a new class SharedGraphicsContext3D that manages several callers.  This class could
        also cache the current state to avoid issuing redundant calls, although in this first cut it doesn't.
        The SharedGraphicsContext3D is provided through the ChromeClient so that its lifetime can be tied to that
        of the platform-specific compositor infrastructure.

        Accelerated 2d canvases maintain a reference to a SharedGraphicsContext3D and have ownership of a CanvasFramebuffer,
        which represents the canvas's rendering target.  The compositing layer for an accelerated 2d canvas is
        aware only of the canvas's CanvasFramebuffer.  This means that WebGL and 2d canvases are no longer treated
        as the same time of layer by the compositor.

        Covered by existing canvas tests.

        * WebCore.gypi:
        * html/canvas/CanvasRenderingContext.cpp:
        * html/canvas/CanvasRenderingContext.h:
        (WebCore::CanvasRenderingContext::paintsIntoCanvasBuffer):
        (WebCore::CanvasRenderingContext::platformLayer):
        * html/canvas/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
        (WebCore::CanvasRenderingContext2D::paintsIntoCanvasBuffer):
        (WebCore::CanvasRenderingContext2D::reset):
        (WebCore::CanvasRenderingContext2D::didDraw):
        (WebCore::CanvasRenderingContext2D::platformLayer):
        * html/canvas/CanvasRenderingContext2D.h:
        * html/canvas/WebGLRenderingContext.cpp:
        (WebCore::WebGLRenderingContext::paintsIntoCanvasBuffer):
        * html/canvas/WebGLRenderingContext.h:
        (WebCore::WebGLRenderingContext::graphicsContext3D):
        (WebCore::WebGLRenderingContext::platformLayer):
        * loader/EmptyClients.h:
        (WebCore::EmptyChromeClient::attachRootGraphicsLayer):
        (WebCore::EmptyChromeClient::setNeedsOneShotDrawingSynchronization):
        (WebCore::EmptyChromeClient::scheduleCompositingLayerSync):
        * page/ChromeClient.h:
        (WebCore::ChromeClient::getSharedGraphicsContext3D):
        * platform/graphics/GraphicsContext.cpp:
        (WebCore::GraphicsContext::setSharedGraphicsContext3D):
        (WebCore::GraphicsContext::syncSoftwareCanvas):
        * platform/graphics/GraphicsContext.h:
        * platform/graphics/chromium/Canvas2DLayerChromium.cpp: Added.
        (WebCore::Canvas2DLayerChromium::create):
        (WebCore::Canvas2DLayerChromium::Canvas2DLayerChromium):
        (WebCore::Canvas2DLayerChromium::~Canvas2DLayerChromium):
        (WebCore::Canvas2DLayerChromium::updateContents):
        (WebCore::Canvas2DLayerChromium::setTextureChanged):
        (WebCore::Canvas2DLayerChromium::textureId):
        * platform/graphics/chromium/Canvas2DLayerChromium.h: Added.
        (WebCore::Canvas2DLayerChromium::drawsContent):
        * platform/graphics/chromium/CanvasLayerChromium.cpp:
        (WebCore::CanvasLayerChromium::CanvasLayerChromium):
        (WebCore::CanvasLayerChromium::~CanvasLayerChromium):
        (WebCore::CanvasLayerChromium::draw):
        * platform/graphics/chromium/CanvasLayerChromium.h:
        * platform/graphics/chromium/DrawingBufferChromium.cpp: Added.
        (WebCore::generateColorTexture):
        (WebCore::DrawingBuffer::DrawingBuffer):
        (WebCore::DrawingBuffer::~DrawingBuffer):
        (WebCore::DrawingBuffer::publishToPlatformLayer):
        (WebCore::DrawingBuffer::reset):
        (WebCore::DrawingBuffer::platformLayer):
        * platform/graphics/chromium/GLES2Canvas.cpp:
        (WebCore::GLES2Canvas::GLES2Canvas):
        (WebCore::GLES2Canvas::~GLES2Canvas):
        (WebCore::GLES2Canvas::bindFramebuffer):
        (WebCore::GLES2Canvas::clearRect):
        (WebCore::GLES2Canvas::fillRect):
        (WebCore::GLES2Canvas::drawTexturedRect):
        (WebCore::GLES2Canvas::drawTexturedRectTile):
        (WebCore::GLES2Canvas::drawQuad):
        (WebCore::GLES2Canvas::createTexture):
        (WebCore::GLES2Canvas::getTexture):
        * platform/graphics/chromium/GLES2Canvas.h:
        (WebCore::GLES2Canvas::context):
        (WebCore::GLES2Canvas::drawingBuffer):
        * platform/graphics/chromium/GraphicsLayerChromium.cpp:
        (WebCore::GraphicsLayerChromium::setContentsToCanvas):
        * platform/graphics/chromium/GraphicsLayerChromium.h:
        * platform/graphics/chromium/WebGLLayerChromium.cpp: Added.
        (WebCore::WebGLLayerChromium::create):
        (WebCore::WebGLLayerChromium::WebGLLayerChromium):
        (WebCore::WebGLLayerChromium::updateContents):
        (WebCore::WebGLLayerChromium::setContext):
        * platform/graphics/chromium/WebGLLayerChromium.h: Added.
        (WebCore::WebGLLayerChromium::drawsContent):
        * platform/graphics/gpu/DrawingBuffer.cpp: Added.
        (WebCore::DrawingBuffer::create):
        (WebCore::DrawingBuffer::bind):
        (WebCore::DrawingBuffer::setWillPublishCallback):
        * platform/graphics/gpu/DrawingBuffer.h: Added.
        (WebCore::DrawingBuffer::size):
        * platform/graphics/gpu/SharedGraphicsContext3D.cpp: Added.
        (WebCore::SharedGraphicsContext3D::create):
        (WebCore::SharedGraphicsContext3D::SharedGraphicsContext3D):
        (WebCore::SharedGraphicsContext3D::~SharedGraphicsContext3D):
        (WebCore::SharedGraphicsContext3D::makeContextCurrent):
        (WebCore::SharedGraphicsContext3D::scissor):
        (WebCore::SharedGraphicsContext3D::enable):
        (WebCore::SharedGraphicsContext3D::disable):
        (WebCore::SharedGraphicsContext3D::clearColor):
        (WebCore::SharedGraphicsContext3D::clear):
        (WebCore::SharedGraphicsContext3D::drawArrays):
        (WebCore::SharedGraphicsContext3D::getError):
        (WebCore::SharedGraphicsContext3D::getIntegerv):
        (WebCore::SharedGraphicsContext3D::createFramebuffer):
        (WebCore::SharedGraphicsContext3D::createTexture):
        (WebCore::SharedGraphicsContext3D::deleteFramebuffer):
        (WebCore::SharedGraphicsContext3D::deleteTexture):
        (WebCore::SharedGraphicsContext3D::framebufferTexture2D):
        (WebCore::SharedGraphicsContext3D::texParameteri):
        (WebCore::SharedGraphicsContext3D::texImage2D):
        (WebCore::SharedGraphicsContext3D::texSubImage2D):
        (WebCore::SharedGraphicsContext3D::readPixels):
        (WebCore::SharedGraphicsContext3D::supportsBGRA):
        (WebCore::SharedGraphicsContext3D::getTexture):
        (WebCore::SharedGraphicsContext3D::applyCompositeOperator):
        (WebCore::SharedGraphicsContext3D::useQuadVertices):
        (WebCore::SharedGraphicsContext3D::setActiveTexture):
        (WebCore::SharedGraphicsContext3D::bindTexture):
        (WebCore::SharedGraphicsContext3D::useFillSolidProgram):
        (WebCore::SharedGraphicsContext3D::useTextureProgram):
        (WebCore::SharedGraphicsContext3D::bindFramebuffer):
        (WebCore::SharedGraphicsContext3D::setViewport):
        (WebCore::SharedGraphicsContext3D::paintsIntoCanvasBuffer):
        * platform/graphics/gpu/SharedGraphicsContext3D.h: Added.
        * platform/graphics/gpu/Texture.cpp:
        * platform/graphics/skia/GraphicsContextSkia.cpp:
        (WebCore::GraphicsContext::syncSoftwareCanvas):
        (WebCore::GraphicsContext::setSharedGraphicsContext3D):
        * platform/graphics/skia/ImageSkia.cpp:
        * platform/graphics/skia/PlatformContextSkia.cpp:
        (WebCore::PlatformContextSkia::~PlatformContextSkia):
        (WebCore::WillPublishCallbackImpl::create):
        (WebCore::WillPublishCallbackImpl::willPublish):
        (WebCore::WillPublishCallbackImpl::WillPublishCallbackImpl):
        (WebCore::PlatformContextSkia::setSharedGraphicsContext3D):
        (WebCore::PlatformContextSkia::uploadSoftwareToHardware):
        (WebCore::PlatformContextSkia::readbackHardwareToSoftware):
        * platform/graphics/skia/PlatformContextSkia.h:
        * rendering/RenderLayerBacking.cpp:
        (WebCore::RenderLayerBacking::updateGraphicsLayerConfiguration):
2010-09-03  James Robinson  <jamesr@chromium.org>

        Reviewed by Chris Marrin.

        Multiple accelerated 2D canvases should be able to use the same GraphicsContext3D
        https://bugs.webkit.org/show_bug.cgi?id=44926

        Adds a SharedContext3D to WebViewImpl. The SharedContext3D has to live on WebViewImpl to be
        tied to the lifetime of the compositor context.

        * src/ChromeClientImpl.cpp:
        (WebKit::ChromeClientImpl::getSharedGraphicsContext3D):
        * src/ChromeClientImpl.h:
        * src/GraphicsContext3D.cpp:
        (WebCore::GraphicsContext3DInternal::initialize):
        (WebCore::GraphicsContext3DInternal::platformLayer):
        (WebCore::GraphicsContext3D::platformLayer):
        * src/WebViewImpl.cpp:
        (WebKit::WebViewImpl::getSharedGraphicsContext3D):
        * src/WebViewImpl.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@66746 268f45cc-cd09-0410-ab3c-d52691b4dbfc

40 files changed:
WebCore/ChangeLog
WebCore/WebCore.gypi
WebCore/html/canvas/CanvasRenderingContext.cpp
WebCore/html/canvas/CanvasRenderingContext.h
WebCore/html/canvas/CanvasRenderingContext2D.cpp
WebCore/html/canvas/CanvasRenderingContext2D.h
WebCore/html/canvas/WebGLRenderingContext.cpp
WebCore/html/canvas/WebGLRenderingContext.h
WebCore/loader/EmptyClients.h
WebCore/page/ChromeClient.h
WebCore/platform/graphics/GraphicsContext.cpp
WebCore/platform/graphics/GraphicsContext.h
WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp [new file with mode: 0644]
WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h [new file with mode: 0644]
WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp
WebCore/platform/graphics/chromium/CanvasLayerChromium.h
WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp [new file with mode: 0644]
WebCore/platform/graphics/chromium/GLES2Canvas.cpp
WebCore/platform/graphics/chromium/GLES2Canvas.h
WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
WebCore/platform/graphics/chromium/GraphicsLayerChromium.h
WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp [new file with mode: 0644]
WebCore/platform/graphics/chromium/WebGLLayerChromium.h [new file with mode: 0644]
WebCore/platform/graphics/gpu/DrawingBuffer.cpp [new file with mode: 0644]
WebCore/platform/graphics/gpu/DrawingBuffer.h [new file with mode: 0644]
WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp [new file with mode: 0644]
WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h [new file with mode: 0644]
WebCore/platform/graphics/gpu/Texture.cpp
WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
WebCore/platform/graphics/skia/ImageSkia.cpp
WebCore/platform/graphics/skia/PlatformContextSkia.cpp
WebCore/platform/graphics/skia/PlatformContextSkia.h
WebCore/rendering/RenderLayerBacking.cpp
WebKit/chromium/ChangeLog
WebKit/chromium/src/ChromeClientImpl.cpp
WebKit/chromium/src/ChromeClientImpl.h
WebKit/chromium/src/GraphicsContext3D.cpp
WebKit/chromium/src/WebViewImpl.cpp
WebKit/chromium/src/WebViewImpl.h

index b5a59b3..e8091a2 100644 (file)
@@ -1,3 +1,152 @@
+2010-09-03  James Robinson  <jamesr@chromium.org>
+
+        Reviewed by Chris Marrin.
+
+        Multiple accelerated 2D canvases should be able to use the same GraphicsContext3D
+        https://bugs.webkit.org/show_bug.cgi?id=44926
+
+        This allows many accelerated 2d canvases to render using a single underlying GraphicsContext3D.
+        It introduces a new class SharedGraphicsContext3D that manages several callers.  This class could
+        also cache the current state to avoid issuing redundant calls, although in this first cut it doesn't.
+        The SharedGraphicsContext3D is provided through the ChromeClient so that its lifetime can be tied to that
+        of the platform-specific compositor infrastructure.
+
+        Accelerated 2d canvases maintain a reference to a SharedGraphicsContext3D and have ownership of a CanvasFramebuffer,
+        which represents the canvas's rendering target.  The compositing layer for an accelerated 2d canvas is
+        aware only of the canvas's CanvasFramebuffer.  This means that WebGL and 2d canvases are no longer treated
+        as the same time of layer by the compositor.
+
+        Covered by existing canvas tests.
+
+        * WebCore.gypi:
+        * html/canvas/CanvasRenderingContext.cpp:
+        * html/canvas/CanvasRenderingContext.h:
+        (WebCore::CanvasRenderingContext::paintsIntoCanvasBuffer):
+        (WebCore::CanvasRenderingContext::platformLayer):
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
+        (WebCore::CanvasRenderingContext2D::paintsIntoCanvasBuffer):
+        (WebCore::CanvasRenderingContext2D::reset):
+        (WebCore::CanvasRenderingContext2D::didDraw):
+        (WebCore::CanvasRenderingContext2D::platformLayer):
+        * html/canvas/CanvasRenderingContext2D.h:
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::paintsIntoCanvasBuffer):
+        * html/canvas/WebGLRenderingContext.h:
+        (WebCore::WebGLRenderingContext::graphicsContext3D):
+        (WebCore::WebGLRenderingContext::platformLayer):
+        * loader/EmptyClients.h:
+        (WebCore::EmptyChromeClient::attachRootGraphicsLayer):
+        (WebCore::EmptyChromeClient::setNeedsOneShotDrawingSynchronization):
+        (WebCore::EmptyChromeClient::scheduleCompositingLayerSync):
+        * page/ChromeClient.h:
+        (WebCore::ChromeClient::getSharedGraphicsContext3D):
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::setSharedGraphicsContext3D):
+        (WebCore::GraphicsContext::syncSoftwareCanvas):
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/chromium/Canvas2DLayerChromium.cpp: Added.
+        (WebCore::Canvas2DLayerChromium::create):
+        (WebCore::Canvas2DLayerChromium::Canvas2DLayerChromium):
+        (WebCore::Canvas2DLayerChromium::~Canvas2DLayerChromium):
+        (WebCore::Canvas2DLayerChromium::updateContents):
+        (WebCore::Canvas2DLayerChromium::setTextureChanged):
+        (WebCore::Canvas2DLayerChromium::textureId):
+        * platform/graphics/chromium/Canvas2DLayerChromium.h: Added.
+        (WebCore::Canvas2DLayerChromium::drawsContent):
+        * platform/graphics/chromium/CanvasLayerChromium.cpp:
+        (WebCore::CanvasLayerChromium::CanvasLayerChromium):
+        (WebCore::CanvasLayerChromium::~CanvasLayerChromium):
+        (WebCore::CanvasLayerChromium::draw):
+        * platform/graphics/chromium/CanvasLayerChromium.h:
+        * platform/graphics/chromium/DrawingBufferChromium.cpp: Added.
+        (WebCore::generateColorTexture):
+        (WebCore::DrawingBuffer::DrawingBuffer):
+        (WebCore::DrawingBuffer::~DrawingBuffer):
+        (WebCore::DrawingBuffer::publishToPlatformLayer):
+        (WebCore::DrawingBuffer::reset):
+        (WebCore::DrawingBuffer::platformLayer):
+        * platform/graphics/chromium/GLES2Canvas.cpp:
+        (WebCore::GLES2Canvas::GLES2Canvas):
+        (WebCore::GLES2Canvas::~GLES2Canvas):
+        (WebCore::GLES2Canvas::bindFramebuffer):
+        (WebCore::GLES2Canvas::clearRect):
+        (WebCore::GLES2Canvas::fillRect):
+        (WebCore::GLES2Canvas::drawTexturedRect):
+        (WebCore::GLES2Canvas::drawTexturedRectTile):
+        (WebCore::GLES2Canvas::drawQuad):
+        (WebCore::GLES2Canvas::createTexture):
+        (WebCore::GLES2Canvas::getTexture):
+        * platform/graphics/chromium/GLES2Canvas.h:
+        (WebCore::GLES2Canvas::context):
+        (WebCore::GLES2Canvas::drawingBuffer):
+        * platform/graphics/chromium/GraphicsLayerChromium.cpp:
+        (WebCore::GraphicsLayerChromium::setContentsToCanvas):
+        * platform/graphics/chromium/GraphicsLayerChromium.h:
+        * platform/graphics/chromium/WebGLLayerChromium.cpp: Added.
+        (WebCore::WebGLLayerChromium::create):
+        (WebCore::WebGLLayerChromium::WebGLLayerChromium):
+        (WebCore::WebGLLayerChromium::updateContents):
+        (WebCore::WebGLLayerChromium::setContext):
+        * platform/graphics/chromium/WebGLLayerChromium.h: Added.
+        (WebCore::WebGLLayerChromium::drawsContent):
+        * platform/graphics/gpu/DrawingBuffer.cpp: Added.
+        (WebCore::DrawingBuffer::create):
+        (WebCore::DrawingBuffer::bind):
+        (WebCore::DrawingBuffer::setWillPublishCallback):
+        * platform/graphics/gpu/DrawingBuffer.h: Added.
+        (WebCore::DrawingBuffer::size):
+        * platform/graphics/gpu/SharedGraphicsContext3D.cpp: Added.
+        (WebCore::SharedGraphicsContext3D::create):
+        (WebCore::SharedGraphicsContext3D::SharedGraphicsContext3D):
+        (WebCore::SharedGraphicsContext3D::~SharedGraphicsContext3D):
+        (WebCore::SharedGraphicsContext3D::makeContextCurrent):
+        (WebCore::SharedGraphicsContext3D::scissor):
+        (WebCore::SharedGraphicsContext3D::enable):
+        (WebCore::SharedGraphicsContext3D::disable):
+        (WebCore::SharedGraphicsContext3D::clearColor):
+        (WebCore::SharedGraphicsContext3D::clear):
+        (WebCore::SharedGraphicsContext3D::drawArrays):
+        (WebCore::SharedGraphicsContext3D::getError):
+        (WebCore::SharedGraphicsContext3D::getIntegerv):
+        (WebCore::SharedGraphicsContext3D::createFramebuffer):
+        (WebCore::SharedGraphicsContext3D::createTexture):
+        (WebCore::SharedGraphicsContext3D::deleteFramebuffer):
+        (WebCore::SharedGraphicsContext3D::deleteTexture):
+        (WebCore::SharedGraphicsContext3D::framebufferTexture2D):
+        (WebCore::SharedGraphicsContext3D::texParameteri):
+        (WebCore::SharedGraphicsContext3D::texImage2D):
+        (WebCore::SharedGraphicsContext3D::texSubImage2D):
+        (WebCore::SharedGraphicsContext3D::readPixels):
+        (WebCore::SharedGraphicsContext3D::supportsBGRA):
+        (WebCore::SharedGraphicsContext3D::getTexture):
+        (WebCore::SharedGraphicsContext3D::applyCompositeOperator):
+        (WebCore::SharedGraphicsContext3D::useQuadVertices):
+        (WebCore::SharedGraphicsContext3D::setActiveTexture):
+        (WebCore::SharedGraphicsContext3D::bindTexture):
+        (WebCore::SharedGraphicsContext3D::useFillSolidProgram):
+        (WebCore::SharedGraphicsContext3D::useTextureProgram):
+        (WebCore::SharedGraphicsContext3D::bindFramebuffer):
+        (WebCore::SharedGraphicsContext3D::setViewport):
+        (WebCore::SharedGraphicsContext3D::paintsIntoCanvasBuffer):
+        * platform/graphics/gpu/SharedGraphicsContext3D.h: Added.
+        * platform/graphics/gpu/Texture.cpp:
+        * platform/graphics/skia/GraphicsContextSkia.cpp:
+        (WebCore::GraphicsContext::syncSoftwareCanvas):
+        (WebCore::GraphicsContext::setSharedGraphicsContext3D):
+        * platform/graphics/skia/ImageSkia.cpp:
+        * platform/graphics/skia/PlatformContextSkia.cpp:
+        (WebCore::PlatformContextSkia::~PlatformContextSkia):
+        (WebCore::WillPublishCallbackImpl::create):
+        (WebCore::WillPublishCallbackImpl::willPublish):
+        (WebCore::WillPublishCallbackImpl::WillPublishCallbackImpl):
+        (WebCore::PlatformContextSkia::setSharedGraphicsContext3D):
+        (WebCore::PlatformContextSkia::uploadSoftwareToHardware):
+        (WebCore::PlatformContextSkia::readbackHardwareToSoftware):
+        * platform/graphics/skia/PlatformContextSkia.h:
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateGraphicsLayerConfiguration):
+
 2010-09-03  Chris Rogers  <crogers@google.com>
 
         Reviewed by Kenneth Russell.
index 6502202..99e891d 100644 (file)
             'platform/graphics/cg/PathCG.cpp',
             'platform/graphics/cg/PatternCG.cpp',
             'platform/graphics/cg/TransformationMatrixCG.cpp',
+            'platform/graphics/chromium/Canvas2DLayerChromium.cpp',
+            'platform/graphics/chromium/Canvas2DLayerChromium.h',
             'platform/graphics/chromium/CanvasLayerChromium.cpp',
             'platform/graphics/chromium/CanvasLayerChromium.h',
+            'platform/graphics/chromium/DrawingBufferChromium.cpp',
             'platform/graphics/chromium/ContentLayerChromium.cpp',
             'platform/graphics/chromium/ContentLayerChromium.h',
             'platform/graphics/chromium/CrossProcessFontLoading.h',
             'platform/graphics/chromium/UniscribeHelperTextRun.h',
             'platform/graphics/chromium/VideoLayerChromium.cpp',
             'platform/graphics/chromium/VideoLayerChromium.h',
+            'platform/graphics/chromium/WebGLLayerChromium.cpp',
+            'platform/graphics/chromium/WebGLLayerChromium.h',
             'platform/graphics/cocoa/FontPlatformData.h',
             'platform/graphics/cocoa/FontPlatformDataCocoa.mm',
             'platform/graphics/filters/FEBlend.cpp',
             'platform/graphics/filters/SourceAlpha.h',
             'platform/graphics/filters/SourceGraphic.cpp',
             'platform/graphics/filters/SourceGraphic.h',
+            'platform/graphics/gpu/DrawingBuffer.cpp',
+            'platform/graphics/gpu/DrawingBuffer.h',
             'platform/graphics/gpu/PODArena.h',
             'platform/graphics/gpu/PODRedBlackTree.h',
+            'platform/graphics/gpu/SharedGraphicsContext3D.cpp',
+            'platform/graphics/gpu/SharedGraphicsContext3D.h',
             'platform/graphics/gpu/Shader.cpp',
             'platform/graphics/gpu/Shader.h',
             'platform/graphics/gpu/SolidFillShader.cpp',
             'platform/graphics/ImageBuffer.cpp',
             'platform/graphics/ImageBuffer.h',
             'platform/graphics/ImageObserver.h',
-            'platform/graphics/ImageSource.h',
             'platform/graphics/ImageSource.cpp',
+            'platform/graphics/ImageSource.h',
             'platform/graphics/IntPoint.h',
             'platform/graphics/IntRect.cpp',
             'platform/graphics/IntRect.h',
index 1e897d3..e019332 100644 (file)
@@ -25,9 +25,6 @@
 
 #include "config.h"
 #include "CanvasRenderingContext.h"
-#if ENABLE(ACCELERATED_2D_CANVAS) || ENABLE(3D_CANVAS)
-#include "GraphicsContext3D.h"
-#endif
 #include "HTMLCanvasElement.h"
 
 namespace WebCore {
@@ -47,13 +44,4 @@ void CanvasRenderingContext::deref()
     m_canvas->deref(); 
 }
 
-bool CanvasRenderingContext::paintsIntoCanvasBuffer() const
-{
-#if ENABLE(ACCELERATED_2D_CANVAS) || ENABLE(3D_CANVAS)
-    if (GraphicsContext3D* context3D = graphicsContext3D())
-        return context3D->paintsIntoCanvasBuffer();
-#endif
-    return true;
-}
-
 } // namespace WebCore
index 2cdbe1d..8499b47 100644 (file)
 #ifndef CanvasRenderingContext_h
 #define CanvasRenderingContext_h
 
+#include "GraphicsLayer.h"
+
 #include <wtf/Noncopyable.h>
 
 namespace WebCore {
 
     class WebGLObject;
-    class GraphicsContext3D;
     class HTMLCanvasElement;
 
     class CanvasRenderingContext : public Noncopyable {
@@ -49,12 +50,12 @@ namespace WebCore {
         virtual bool is3d() const { return false; }
         virtual bool isAccelerated() const { return false; }
         
-        // For accelerated canvases, returns a pointer to the underlying GraphicsContext3D.
-        // For non accelerated canvases returns 0.
-        virtual GraphicsContext3D* graphicsContext3D() const { return 0; }
-
         virtual void paintRenderingResultsToCanvas() {}
-        bool paintsIntoCanvasBuffer() const;
+        virtual bool paintsIntoCanvasBuffer() const { return true; }
+
+#if USE(ACCELERATED_COMPOSITING)
+        virtual PlatformLayer* platformLayer() const { return 0; }
+#endif
 
     private:
         HTMLCanvasElement* m_canvas;
index 6df6abf..22d3e2d 100644 (file)
 #include "TextMetrics.h"
 
 #if ENABLE(ACCELERATED_2D_CANVAS)
+#include "Chrome.h"
+#include "ChromeClient.h"
+#include "DrawingBuffer.h"
 #include "FrameView.h"
 #include "GraphicsContext3D.h"
+#include "SharedGraphicsContext3D.h"
 #if USE(ACCELERATED_COMPOSITING)
 #include "RenderLayer.h"
 #endif
@@ -124,17 +128,11 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo
         return;
     if (!p->settings()->accelerated2dCanvasEnabled())
         return;
-    if (FrameView* view = canvas->document()->view()) {
-        if (ScrollView* rootView = view->root()) {
-            if (HostWindow* hostWindow = rootView->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()));
-            }
+    m_context3D = p->chrome()->client()->getSharedGraphicsContext3D();
+    if (m_context3D) {
+        if (GraphicsContext* c = drawingContext()) {
+            m_drawingBuffer = DrawingBuffer::create(m_context3D.get(), IntSize(canvas->width(), canvas->height()));
+            c->setSharedGraphicsContext3D(m_context3D.get(), m_drawingBuffer.get(), IntSize(canvas->width(), canvas->height()));
         }
     }
 #endif
@@ -153,6 +151,16 @@ bool CanvasRenderingContext2D::isAccelerated() const
 #endif
 }
 
+bool CanvasRenderingContext2D::paintsIntoCanvasBuffer() const
+{
+#if ENABLE(ACCELERATED_2D_CANVAS)
+    if (m_context3D)
+        return m_context3D->paintsIntoCanvasBuffer();
+#endif
+    return true;
+}
+
+
 void CanvasRenderingContext2D::reset()
 {
     m_stateStack.resize(1);
@@ -160,8 +168,10 @@ void CanvasRenderingContext2D::reset()
     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()));
+        if (GraphicsContext* c = drawingContext()) {
+            m_drawingBuffer->reset(IntSize(canvas()->width(), canvas()->height()));
+            c->setSharedGraphicsContext3D(m_context3D.get(), m_drawingBuffer.get(), IntSize(canvas()->width(), canvas()->height()));
+        }
     }
 #endif
 }
@@ -1504,7 +1514,7 @@ void CanvasRenderingContext2D::didDraw(const FloatRect& r, unsigned options)
 #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())
+    if (isAccelerated() && renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing())
         renderBox->layer()->rendererContentChanged();
     else
 #endif
@@ -1877,4 +1887,11 @@ void CanvasRenderingContext2D::paintRenderingResultsToCanvas()
 #endif
 }
 
+#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
+PlatformLayer* CanvasRenderingContext2D::platformLayer() const
+{
+    return m_drawingBuffer->platformLayer();
+}
+#endif
+
 } // namespace WebCore
index 9857344..d9d8597 100644 (file)
@@ -61,7 +61,8 @@ class KURL;
 class TextMetrics;
 
 #if ENABLE(ACCELERATED_2D_CANVAS)
-class GraphicsContext3D;
+class DrawingBuffer;
+class SharedGraphicsContext3D;
 #endif
 
 typedef int ExceptionCode;
@@ -74,6 +75,7 @@ public:
 
     virtual bool is2d() const { return true; }
     virtual bool isAccelerated() const;
+    virtual bool paintsIntoCanvasBuffer() const;
 
     CanvasStyle* strokeStyle() const;
     void setStrokeStyle(PassRefPtr<CanvasStyle>);
@@ -223,8 +225,8 @@ public:
 
     virtual void paintRenderingResultsToCanvas();
 
-#if ENABLE(ACCELERATED_2D_CANVAS)
-    virtual GraphicsContext3D* graphicsContext3D() const { return m_context3D.get(); }
+#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
+    virtual PlatformLayer* platformLayer() const;
 #endif
 
 private:
@@ -298,7 +300,8 @@ private:
 #endif
 
 #if ENABLE(ACCELERATED_2D_CANVAS)
-    OwnPtr<GraphicsContext3D> m_context3D;
+    OwnPtr<DrawingBuffer> m_drawingBuffer;
+    RefPtr<SharedGraphicsContext3D> m_context3D;
 #endif
 };
 
index 2a1464a..bda3569 100644 (file)
@@ -170,6 +170,11 @@ void WebGLRenderingContext::paintRenderingResultsToCanvas()
     m_context->paintRenderingResultsToCanvas(this);
 }
 
+bool WebGLRenderingContext::paintsIntoCanvasBuffer() const
+{
+    return m_context->paintsIntoCanvasBuffer();
+}
+
 void WebGLRenderingContext::reshape(int width, int height)
 {
     if (m_needsUpdate) {
index 66ec8d8..d812c69 100644 (file)
@@ -63,6 +63,7 @@ public:
 
     virtual bool is3d() const { return true; }
     virtual bool isAccelerated() const { return true; }
+    virtual bool paintsIntoCanvasBuffer() const;
 
     void activeTexture(unsigned long texture, ExceptionCode& ec);
     void attachShader(WebGLProgram*, WebGLShader*, ExceptionCode& ec);
@@ -277,7 +278,10 @@ public:
 
     void viewport(long x, long y, unsigned long width, unsigned long height);
 
-    virtual GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
+    GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
+#if USE(ACCELERATED_COMPOSITING)
+    virtual PlatformLayer* platformLayer() const { return m_context->platformLayer(); }
+#endif
 
     void reshape(int width, int height);
 
index 46b611b..25ae2cd 100644 (file)
@@ -61,6 +61,8 @@
 
 namespace WebCore {
 
+class SharedGraphicsContext3D;
+
 class EmptyPopupMenu : public PopupMenu {
 public:
     virtual void show(const IntRect&, FrameView*, int) {}
@@ -190,9 +192,9 @@ public:
     virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) {}
 
 #if USE(ACCELERATED_COMPOSITING)
-    virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) {};
-    virtual void setNeedsOneShotDrawingSynchronization() {};
-    virtual void scheduleCompositingLayerSync() {};
+    virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) {}
+    virtual void setNeedsOneShotDrawingSynchronization() {}
+    virtual void scheduleCompositingLayerSync() {}
 #endif
 
 #if PLATFORM(WIN)
index d3e1662..bd9de6b 100644 (file)
@@ -57,6 +57,7 @@ namespace WebCore {
     class Node;
     class Page;
     class SecurityOrigin;
+    class SharedGraphicsContext3D;
     class PopupMenuClient;
     class Widget;
 
@@ -230,6 +231,8 @@ namespace WebCore {
         virtual bool allowsAcceleratedCompositing() const { return true; }
 #endif
 
+        virtual SharedGraphicsContext3D* getSharedGraphicsContext3D() { return 0; }
+
         virtual bool supportsFullscreenForNode(const Node*) { return false; }
         virtual void enterFullscreenForNode(Node*) { }
         virtual void exitFullscreenForNode(Node*) { }
index 47384b9..ea6c448 100644 (file)
@@ -571,6 +571,17 @@ void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle&)
 }
 #endif
 
+#if !PLATFORM(SKIA)
+void GraphicsContext::setSharedGraphicsContext3D(SharedGraphicsContext3D*, DrawingBuffer*, const IntSize&)
+{
+}
+
+void GraphicsContext::syncSoftwareCanvas()
+{
+}
+#endif
+
+
 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle& penStyle)
 {
     // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
@@ -600,14 +611,4 @@ void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2
     }
 }
 
-#if !PLATFORM(SKIA)
-void GraphicsContext::setGraphicsContext3D(GraphicsContext3D*, const IntSize&)
-{
-}
-
-void GraphicsContext::syncSoftwareCanvas()
-{
-}
-#endif
-
 }
index 45ddee3..c3b20a9 100644 (file)
@@ -123,16 +123,17 @@ namespace WebCore {
     const int cMisspellingLinePatternGapWidth = 1;
 
     class AffineTransform;
+    class DrawingBuffer;
     class Font;
     class Generator;
     class Gradient;
-    class GraphicsContext3D;
     class GraphicsContextPlatformPrivate;
     class GraphicsContextPrivate;
     class ImageBuffer;
     class KURL;
     class Path;
     class Pattern;
+    class SharedGraphicsContext3D;
     class TextRun;
 
     // These bits can be ORed together for a total of 8 possible text drawing modes.
@@ -421,7 +422,7 @@ namespace WebCore {
         pattern getHaikuStrokeStyle();
 #endif
 
-        void setGraphicsContext3D(GraphicsContext3D*, const IntSize&);
+        void setSharedGraphicsContext3D(SharedGraphicsContext3D*, DrawingBuffer*, const IntSize&);
         void syncSoftwareCanvas();
 
     private:
diff --git a/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp b/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp
new file mode 100644 (file)
index 0000000..345c420
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "Canvas2DLayerChromium.h"
+
+#include "DrawingBuffer.h"
+
+#include <GLES2/gl2.h>
+
+namespace WebCore {
+
+PassRefPtr<Canvas2DLayerChromium> Canvas2DLayerChromium::create(DrawingBuffer* drawingBuffer, GraphicsLayerChromium* owner)
+{
+    return adoptRef(new Canvas2DLayerChromium(drawingBuffer, owner));
+}
+
+Canvas2DLayerChromium::Canvas2DLayerChromium(DrawingBuffer* drawingBuffer, GraphicsLayerChromium* owner)
+    : CanvasLayerChromium(owner)
+    , m_drawingBuffer(drawingBuffer)
+{
+}
+
+Canvas2DLayerChromium::~Canvas2DLayerChromium()
+{
+    if (m_textureId)
+        glDeleteTextures(1, &m_textureId);
+}
+
+void Canvas2DLayerChromium::updateContents()
+{
+    if (!m_drawingBuffer)
+        return;
+    if (m_textureChanged) { // We have to generate a new backing texture.
+        if (m_textureId)
+            glDeleteTextures(1, &m_textureId);
+        glGenTextures(1, &m_textureId);
+        glActiveTexture(GL_TEXTURE0);
+        glBindTexture(GL_TEXTURE_2D, m_textureId);
+        IntSize size = m_drawingBuffer->size();
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+        // Set the min-mag filters to linear and wrap modes to GL_CLAMP_TO_EDGE
+        // to get around NPOT texture limitations of GLES.
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        m_textureChanged = false;
+        // FIXME: The glFinish() here is required because we have to make sure that the texture created in this
+        // context (the compositor context) is actually created by the service side before the child context
+        // attempts to use it (in publishToPlatformLayer).  glFinish() is currently the only call with strong
+        // enough semantics to promise this, but is actually much stronger.  Ideally we'd do something like
+        // inserting a fence here and waiting for it before trying to publish.
+        glFinish();
+    }
+    // Update the contents of the texture used by the compositor.
+    if (m_contentsDirty) {
+        m_drawingBuffer->publishToPlatformLayer();
+        m_contentsDirty = false;
+    }
+}
+
+void Canvas2DLayerChromium::setTextureChanged()
+{
+    m_textureChanged = true;
+}
+
+unsigned Canvas2DLayerChromium::textureId() const
+{
+    return m_textureId;
+}
+
+}
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h b/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h
new file mode 100644 (file)
index 0000000..4693c0b
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef Canvas2DLayerChromium_h
+#define Canvas2DLayerChromium_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "CanvasLayerChromium.h"
+
+namespace WebCore {
+
+class DrawingBuffer;
+
+// A layer containing an accelerated 2d canvas
+class Canvas2DLayerChromium : public CanvasLayerChromium {
+public:
+    static PassRefPtr<Canvas2DLayerChromium> create(DrawingBuffer*, GraphicsLayerChromium* owner);
+    virtual ~Canvas2DLayerChromium();
+    virtual bool drawsContent() { return true; }
+    virtual void updateContents();
+
+    void setTextureChanged();
+    unsigned textureId() const;
+
+private:
+    explicit Canvas2DLayerChromium(DrawingBuffer*, GraphicsLayerChromium* owner);
+    DrawingBuffer* m_drawingBuffer;
+
+    static unsigned m_shaderProgramId;
+};
+
+}
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif
index bbf091c..56a7262 100644 (file)
 
 #include "CanvasLayerChromium.h"
 
-#include "GraphicsContext3D.h"
 #include "LayerRendererChromium.h"
+
 #include <GLES2/gl2.h>
 
 namespace WebCore {
 
+unsigned CanvasLayerChromium::m_shaderProgramId = 0;
+
 CanvasLayerChromium::SharedValues::SharedValues()
     : m_canvasShaderProgram(0)
     , m_shaderSamplerLocation(-1)
@@ -93,49 +95,15 @@ CanvasLayerChromium::SharedValues::~SharedValues()
         GLC(glDeleteProgram(m_canvasShaderProgram));
 }
 
-PassRefPtr<CanvasLayerChromium> CanvasLayerChromium::create(GraphicsLayerChromium* owner)
-{
-    return adoptRef(new CanvasLayerChromium(owner));
-}
-
 CanvasLayerChromium::CanvasLayerChromium(GraphicsLayerChromium* owner)
     : LayerChromium(owner)
-    , m_context(0)
+    , m_textureChanged(true)
     , m_textureId(0)
-    , m_textureChanged(false)
-{
-}
-
-void CanvasLayerChromium::updateContents()
 {
-    ASSERT(m_context);
-    if (m_textureChanged) {
-        glBindTexture(GL_TEXTURE_2D, m_textureId);
-        // Set the min-mag filters to linear and wrap modes to GL_CLAMP_TO_EDGE
-        // to get around NPOT texture limitations of GLES.
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-        m_textureChanged = false;
-    }
-    // Update the contents of the texture used by the compositor.
-    if (m_contentsDirty) {
-        if (m_prepareTextureCallback)
-            m_prepareTextureCallback->willPrepareTexture();
-        m_context->prepareTexture();
-        m_contentsDirty = false;
-    }
 }
 
-void CanvasLayerChromium::setContext(const GraphicsContext3D* context)
+CanvasLayerChromium::~CanvasLayerChromium()
 {
-    m_context = const_cast<GraphicsContext3D*>(context);
-
-    unsigned int textureId = m_context->platformTexture();
-    if (textureId != m_textureId)
-        m_textureChanged = true;
-    m_textureId = textureId;
 }
 
 void CanvasLayerChromium::draw()
@@ -150,6 +118,7 @@ void CanvasLayerChromium::draw()
     drawTexturedQuad(layerRenderer()->projectionMatrix(), drawTransform(),
                      bounds().width(), bounds().height(), drawOpacity(),
                      sv->shaderMatrixLocation(), sv->shaderAlphaLocation());
+
 }
 
 }
index 053efff..d591c73 100644 (file)
 
 namespace WebCore {
 
-class GraphicsContext3D;
-
-// A Layer containing a WebGL or accelerated 2d canvas
+// Base class for WebGL and accelerated 2d canvases.
 class CanvasLayerChromium : public LayerChromium {
 public:
-    static PassRefPtr<CanvasLayerChromium> create(GraphicsLayerChromium* owner = 0);
-    virtual bool drawsContent() { return m_context; }
-    virtual void updateContents();
-    virtual void draw();
+    virtual ~CanvasLayerChromium();
 
-    void setContext(const GraphicsContext3D* context);
+    virtual void draw();
 
     class SharedValues {
     public:
@@ -69,21 +64,16 @@ public:
         bool m_initialized;
     };
 
-    class PrepareTextureCallback : public Noncopyable {
-    public:
-        virtual void willPrepareTexture() = 0;
-    };
-    void setPrepareTextureCallback(PassOwnPtr<PrepareTextureCallback> callback) { m_prepareTextureCallback = callback; }
-
-private:
+protected:
     explicit CanvasLayerChromium(GraphicsLayerChromium* owner);
-    GraphicsContext3D* m_context;
-    unsigned m_textureId;
     bool m_textureChanged;
-    OwnPtr<PrepareTextureCallback> m_prepareTextureCallback;
+    unsigned m_textureId;
+
+private:
+    static unsigned m_shaderProgramId;
 };
 
 }
 #endif // USE(ACCELERATED_COMPOSITING)
 
-#endif
+#endif // CanvasLayerChromium_h
diff --git a/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp b/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp
new file mode 100644 (file)
index 0000000..8e6f103
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "DrawingBuffer.h"
+
+#include "Canvas2DLayerChromium.h"
+#include "GraphicsContext3D.h"
+#include "SharedGraphicsContext3D.h"
+
+#include <GLES2/gl2.h>
+#ifndef GL_GLEXT_PROTOTYPES
+#define GL_GLEXT_PROTOTYPES 1
+#endif
+#include <GLES2/gl2ext.h>
+
+namespace WebCore {
+
+struct DrawingBufferInternal {
+    unsigned offscreenColorTexture;
+    RefPtr<Canvas2DLayerChromium> platformLayer;
+};
+
+static unsigned generateColorTexture(SharedGraphicsContext3D* context, const IntSize& size)
+{
+    unsigned offscreenColorTexture = context->createTexture();
+    if (!offscreenColorTexture)
+        return 0;
+
+    context->bindTexture(GraphicsContext3D::TEXTURE_2D, offscreenColorTexture);
+    context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::NEAREST);
+    context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::NEAREST);
+    context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
+    context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
+    context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, 0);
+    context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, offscreenColorTexture, 0);
+
+    return offscreenColorTexture;
+}
+
+
+DrawingBuffer::DrawingBuffer(SharedGraphicsContext3D* context, const IntSize& size, unsigned framebuffer)
+    : m_context(context)
+    , m_size(size)
+    , m_framebuffer(framebuffer)
+    , m_internal(new DrawingBufferInternal)
+{
+    context->bindFramebuffer(framebuffer);
+    m_internal->offscreenColorTexture = generateColorTexture(context, size);
+}
+
+DrawingBuffer::~DrawingBuffer()
+{
+    m_context->deleteFramebuffer(m_framebuffer);
+}
+
+void DrawingBuffer::publishToPlatformLayer()
+{
+    if (m_callback)
+        m_callback->willPublish();
+    unsigned parentTexture = m_internal->platformLayer->textureId();
+    // FIXME: We do the copy in the canvas' (child) context so that it executes in the correct order relative to
+    // other commands in the child context.  This ensures that the parent texture always contains a complete
+    // frame and not some intermediate result.  However, there is no synchronization to ensure that this copy
+    // happens before the compositor draws.  This means we might draw stale frames sometimes.  Ideally this
+    // would insert a fence into the child command stream that the compositor could wait for.
+    m_context->makeContextCurrent();
+    glCopyTextureToParentTexture(m_internal->offscreenColorTexture, parentTexture);
+    glFlush();
+}
+
+void DrawingBuffer::reset(const IntSize& newSize)
+{
+    if (m_size == newSize)
+        return;
+    m_size = newSize;
+    m_context->deleteTexture(m_internal->offscreenColorTexture);
+    m_context->bindFramebuffer(m_framebuffer);
+    m_internal->offscreenColorTexture = generateColorTexture(m_context, m_size);
+
+    if (m_internal->platformLayer)
+        m_internal->platformLayer->setTextureChanged();
+}
+
+PlatformLayer* DrawingBuffer::platformLayer()
+{
+    if (!m_internal->platformLayer)
+        m_internal->platformLayer = Canvas2DLayerChromium::create(this, 0);
+    return m_internal->platformLayer.get();
+}
+
+}
index 82d4c0b..46aecf4 100644 (file)
 
 #include "GLES2Canvas.h"
 
+#include "DrawingBuffer.h"
 #include "FloatRect.h"
 #include "GraphicsContext3D.h"
 #include "IntRect.h"
 #include "PlatformString.h"
+#include "SharedGraphicsContext3D.h"
 #include "SolidFillShader.h"
 #include "TexShader.h"
 #include "Texture.h"
@@ -61,37 +63,35 @@ struct GLES2Canvas::State {
     AffineTransform m_ctm;
 };
 
-GLES2Canvas::GLES2Canvas(GraphicsContext3D* context, const IntSize& size)
-    : m_context(context)
+GLES2Canvas::GLES2Canvas(SharedGraphicsContext3D* context, DrawingBuffer* drawingBuffer, const IntSize& size)
+    : m_size(size)
+    , m_context(context)
+    , m_drawingBuffer(drawingBuffer)
     , m_state(0)
-    , m_quadVertices(0)
-    , m_solidFillShader(SolidFillShader::create(context))
-    , m_texShader(TexShader::create(context))
 {
     m_flipMatrix.translate(-1.0f, 1.0f);
     m_flipMatrix.scale(2.0f / size.width(), -2.0f / size.height());
 
-    m_context->reshape(size.width(), size.height());
-    m_context->viewport(0, 0, size.width(), size.height());
-
     m_stateStack.append(State());
     m_state = &m_stateStack.last();
-
-    // Force the source over composite mode to be applied.
-    m_lastCompositeOp = CompositeClear;
-    applyCompositeOperator(CompositeSourceOver);
 }
 
 GLES2Canvas::~GLES2Canvas()
 {
-    m_context->deleteBuffer(m_quadVertices);
+}
+
+void GLES2Canvas::bindFramebuffer()
+{
+    m_drawingBuffer->bind();
 }
 
 void GLES2Canvas::clearRect(const FloatRect& rect)
 {
+    bindFramebuffer();
     if (m_state->m_ctm.isIdentity()) {
-        m_context->scissor(rect.x(), rect.y(), rect.width(), rect.height());
+        m_context->scissor(rect);
         m_context->enable(GraphicsContext3D::SCISSOR_TEST);
+        m_context->clearColor(Color(RGBA32(0)));
         m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
         m_context->disable(GraphicsContext3D::SCISSOR_TEST);
     } else {
@@ -104,16 +104,17 @@ void GLES2Canvas::clearRect(const FloatRect& rect)
 
 void GLES2Canvas::fillRect(const FloatRect& rect, const Color& color, ColorSpace colorSpace)
 {
-    applyCompositeOperator(m_state->m_compositeOp);
-
-    m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
+    m_context->applyCompositeOperator(m_state->m_compositeOp);
+    m_context->useQuadVertices();
 
     AffineTransform matrix(m_flipMatrix);
     matrix.multLeft(m_state->m_ctm);
     matrix.translate(rect.x(), rect.y());
     matrix.scale(rect.width(), rect.height());
-    m_solidFillShader->use(matrix, color);
 
+    m_context->useFillSolidProgram(matrix, color);
+
+    bindFramebuffer();
     m_context->drawArrays(GraphicsContext3D::TRIANGLE_STRIP, 0, 4);
 }
 
@@ -165,21 +166,33 @@ void GLES2Canvas::restore()
     m_state = &m_stateStack.last();
 }
 
+void GLES2Canvas::drawTexturedRect(unsigned texture, const IntSize& textureSize, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace colorSpace, CompositeOperator compositeOp)
+{
+    m_context->applyCompositeOperator(compositeOp);
+
+    m_context->useQuadVertices();
+    m_context->setActiveTexture(GraphicsContext3D::TEXTURE0);
+
+    m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, texture);
+
+    drawQuad(textureSize, srcRect, dstRect, m_state->m_ctm, m_state->m_alpha);
+}
+
 void GLES2Canvas::drawTexturedRect(Texture* texture, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace colorSpace, CompositeOperator compositeOp)
 {
     drawTexturedRect(texture, srcRect, dstRect, m_state->m_ctm, m_state->m_alpha, colorSpace, compositeOp);
 }
 
+
 void GLES2Canvas::drawTexturedRect(Texture* texture, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform& transform, float alpha, ColorSpace colorSpace, CompositeOperator compositeOp)
 {
-    applyCompositeOperator(compositeOp);
-
-    m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
-    checkGLError("glBindBuffer");
-
+    m_context->applyCompositeOperator(compositeOp);
     const TilingData& tiles = texture->tiles();
     IntRect tileIdxRect = tiles.overlappedTileIndices(srcRect);
 
+    m_context->useQuadVertices();
+    m_context->setActiveTexture(GraphicsContext3D::TEXTURE0);
+
     for (int y = tileIdxRect.y(); y <= tileIdxRect.bottom(); y++) {
         for (int x = tileIdxRect.x(); x <= tileIdxRect.right(); x++)
             drawTexturedRectTile(texture, tiles.tileIndex(x, y), srcRect, dstRect, transform, alpha);
@@ -193,7 +206,6 @@ void GLES2Canvas::drawTexturedRectTile(Texture* texture, int tile, const FloatRe
 
     const TilingData& tiles = texture->tiles();
 
-    m_context->activeTexture(GraphicsContext3D::TEXTURE0);
     texture->bindTile(tile);
 
     FloatRect srcRectClippedInTileSpace;
@@ -202,18 +214,24 @@ void GLES2Canvas::drawTexturedRectTile(Texture* texture, int tile, const FloatRe
 
     IntRect tileBoundsWithBorder = tiles.tileBoundsWithBorder(tile);
 
+    drawQuad(tileBoundsWithBorder.size(), srcRectClippedInTileSpace, dstRectIntersected, transform, alpha);
+}
+
+void GLES2Canvas::drawQuad(const IntSize& textureSize, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform& transform, float alpha)
+{
     AffineTransform matrix(m_flipMatrix);
     matrix.multLeft(transform);
-    matrix.translate(dstRectIntersected.x(), dstRectIntersected.y());
-    matrix.scale(dstRectIntersected.width(), dstRectIntersected.height());
+    matrix.translate(dstRect.x(), dstRect.y());
+    matrix.scale(dstRect.width(), dstRect.height());
 
     AffineTransform texMatrix;
-    texMatrix.scale(1.0f / tileBoundsWithBorder.width(), 1.0f / tileBoundsWithBorder.height());
-    texMatrix.translate(srcRectClippedInTileSpace.x(), srcRectClippedInTileSpace.y());
-    texMatrix.scale(srcRectClippedInTileSpace.width(), srcRectClippedInTileSpace.height());
+    texMatrix.scale(1.0f / textureSize.width(), 1.0f / textureSize.height());
+    texMatrix.translate(srcRect.x(), srcRect.y());
+    texMatrix.scale(srcRect.width(), srcRect.height());
 
-    m_texShader->use(matrix, texMatrix, 0, alpha);
+    bindFramebuffer();
 
+    m_context->useTextureProgram(matrix, texMatrix, alpha);
     m_context->drawArrays(GraphicsContext3D::TRIANGLE_STRIP, 0, 4);
     checkGLError("glDrawArrays");
 }
@@ -223,98 +241,14 @@ void GLES2Canvas::setCompositeOperation(CompositeOperator op)
     m_state->m_compositeOp = op;
 }
 
-void GLES2Canvas::applyCompositeOperator(CompositeOperator op)
-{
-    if (op == m_lastCompositeOp)
-        return;
-
-    switch (op) {
-    case CompositeClear:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ZERO);
-        break;
-    case CompositeCopy:
-        m_context->disable(GraphicsContext3D::BLEND);
-        break;
-    case CompositeSourceOver:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
-        break;
-    case CompositeSourceIn:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ZERO);
-        break;
-    case CompositeSourceOut:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ZERO);
-        break;
-    case CompositeSourceAtop:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
-        break;
-    case CompositeDestinationOver:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE);
-        break;
-    case CompositeDestinationIn:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::SRC_ALPHA);
-        break;
-    case CompositeDestinationOut:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
-        break;
-    case CompositeDestinationAtop:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::SRC_ALPHA);
-        break;
-    case CompositeXOR:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
-        break;
-    case CompositePlusDarker:
-    case CompositeHighlight:
-        // unsupported
-        m_context->disable(GraphicsContext3D::BLEND);
-        break;
-    case CompositePlusLighter:
-        m_context->enable(GraphicsContext3D::BLEND);
-        m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE);
-        break;
-    }
-    m_lastCompositeOp = op;
-}
-
-unsigned GLES2Canvas::getQuadVertices()
-{
-    if (!m_quadVertices) {
-        float vertices[] = { 0.0f, 0.0f, 1.0f,
-                             1.0f, 0.0f, 1.0f,
-                             0.0f, 1.0f, 1.0f,
-                             1.0f, 1.0f, 1.0f };
-        m_quadVertices = m_context->createBuffer();
-        m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices);
-        m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, sizeof(vertices), vertices, GraphicsContext3D::STATIC_DRAW);
-    }
-    return m_quadVertices;
-}
-
 Texture* GLES2Canvas::createTexture(NativeImagePtr ptr, Texture::Format format, int width, int height)
 {
-    PassRefPtr<Texture> texture = m_textures.get(ptr);
-    if (texture)
-        return texture.get();
-
-    texture = Texture::create(m_context, format, width, height);
-    Texture* t = texture.get();
-    m_textures.set(ptr, texture);
-    return t;
+    return m_context->createTexture(ptr, format, width, height);
 }
 
 Texture* GLES2Canvas::getTexture(NativeImagePtr ptr)
 {
-    PassRefPtr<Texture> texture = m_textures.get(ptr);
-    return texture ? texture.get() : 0;
+    return m_context->getTexture(ptr);
 }
 
 void GLES2Canvas::checkGLError(const char* header)
index f49ac8b..6fc1a0e 100644 (file)
 namespace WebCore {
 
 class Color;
+class DrawingBuffer;
 class FloatRect;
 class GraphicsContext3D;
-class SolidFillShader;
-class TexShader;
-
-typedef HashMap<NativeImagePtr, RefPtr<Texture> > TextureHashMap;
+class SharedGraphicsContext3D;
 
 class GLES2Canvas : public Noncopyable {
 public:
-    GLES2Canvas(GraphicsContext3D*, const IntSize&);
+    GLES2Canvas(SharedGraphicsContext3D*, DrawingBuffer*, const IntSize&);
     ~GLES2Canvas();
 
     void fillRect(const FloatRect&, const Color&, ColorSpace);
@@ -74,28 +72,33 @@ public:
     // non-standard functions
     // These are not standard GraphicsContext functions, and should be pushed
     // down into a PlatformContextGLES2 at some point.
+    void drawTexturedRect(unsigned texture, const IntSize& textureSize, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace, CompositeOperator);
     void drawTexturedRect(Texture*, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform&, float alpha, ColorSpace, CompositeOperator);
     void drawTexturedRect(Texture*, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace, CompositeOperator);
-    GraphicsContext3D* context() { return m_context; }
     Texture* createTexture(NativeImagePtr, Texture::Format, int width, int height);
     Texture* getTexture(NativeImagePtr);
 
+    SharedGraphicsContext3D* context() const { return m_context; }
+
+    void bindFramebuffer();
+
+    DrawingBuffer* drawingBuffer() const { return m_drawingBuffer; }
+
 private:
     void drawTexturedRectTile(Texture* texture, int tile, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform&, float alpha);
+    void drawQuad(const IntSize& textureSize, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform&, float alpha);
     void applyCompositeOperator(CompositeOperator);
     void checkGLError(const char* header);
-    unsigned getQuadVertices();
 
-    GraphicsContext3D* m_context;
+    IntSize m_size;
+
+    SharedGraphicsContext3D* m_context;
+    DrawingBuffer* m_drawingBuffer;
+
     struct State;
     WTF::Vector<State> m_stateStack;
     State* m_state;
-    unsigned m_quadVertices;
-    OwnPtr<SolidFillShader> m_solidFillShader;
-    OwnPtr<TexShader> m_texShader;
     AffineTransform m_flipMatrix;
-    TextureHashMap m_textures;
-    CompositeOperator m_lastCompositeOp; // This is the one last set, not necessarily the one in the state stack.
 };
 
 }
index 648e35f..92cc891 100644 (file)
@@ -45,7 +45,9 @@
 
 #include "GraphicsLayerChromium.h"
 
+#include "Canvas2DLayerChromium.h"
 #include "ContentLayerChromium.h"
+#include "DrawingBuffer.h"
 #include "FloatConversion.h"
 #include "FloatRect.h"
 #include "Image.h"
@@ -290,6 +292,7 @@ void GraphicsLayerChromium::setContentsNeedsDisplay()
     if (m_contentsLayer)
         m_contentsLayer->setNeedsDisplay();
 }
+
 void GraphicsLayerChromium::setNeedsDisplay()
 {
     if (drawsContent())
@@ -344,13 +347,13 @@ void GraphicsLayerChromium::setContentsToCanvas(PlatformLayer* platformLayer)
     bool childrenChanged = false;
     if (platformLayer) {
         platformLayer->setOwner(this);
-        if (!m_contentsLayer.get() || m_contentsLayerPurpose != ContentsLayerForCanvas) {
+        if (m_contentsLayer.get() != platformLayer) {
             setupContentsLayer(platformLayer);
             m_contentsLayer = platformLayer;
             m_contentsLayerPurpose = ContentsLayerForCanvas;
             childrenChanged = true;
         }
-        platformLayer->setNeedsDisplay();
+        m_contentsLayer->setNeedsDisplay();
         updateContentsRect();
     } else {
         if (m_contentsLayer) {
index 9dff66a..dde443d 100644 (file)
@@ -138,7 +138,7 @@ private:
         NoContentsLayer = 0,
         ContentsLayerForImage,
         ContentsLayerForVideo,
-        ContentsLayerForCanvas
+        ContentsLayerForCanvas,
     };
 
     ContentsLayerPurpose m_contentsLayerPurpose;
index 50338d2..f490970 100644 (file)
 #if USE(ACCELERATED_COMPOSITING)
 #include "LayerRendererChromium.h"
 
-#include "CanvasLayerChromium.h"
-#include "ContentLayerChromium.h"
+#include "Canvas2DLayerChromium.h"
 #include "GLES2Context.h"
 #include "LayerChromium.h"
 #include "NotImplemented.h"
+#include "WebGLLayerChromium.h"
 #if PLATFORM(SKIA)
 #include "NativeImageSkia.h"
 #include "PlatformContextSkia.h"
diff --git a/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp b/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp
new file mode 100644 (file)
index 0000000..411f416
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "WebGLLayerChromium.h"
+
+#include "GraphicsContext3D.h"
+#include "LayerRendererChromium.h"
+#include <GLES2/gl2.h>
+
+namespace WebCore {
+
+PassRefPtr<WebGLLayerChromium> WebGLLayerChromium::create(GraphicsLayerChromium* owner)
+{
+    return adoptRef(new WebGLLayerChromium(owner));
+}
+
+WebGLLayerChromium::WebGLLayerChromium(GraphicsLayerChromium* owner)
+    : CanvasLayerChromium(owner)
+    , m_context(0)
+{
+}
+
+void WebGLLayerChromium::updateContents()
+{
+    ASSERT(m_context);
+    if (m_textureChanged) {
+        glBindTexture(GL_TEXTURE_2D, m_textureId);
+        // Set the min-mag filters to linear and wrap modes to GL_CLAMP_TO_EDGE
+        // to get around NPOT texture limitations of GLES.
+        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        m_textureChanged = false;
+    }
+    // Update the contents of the texture used by the compositor.
+    if (m_contentsDirty) {
+        m_context->prepareTexture();
+        m_contentsDirty = false;
+    }
+}
+
+void WebGLLayerChromium::setContext(const GraphicsContext3D* context)
+{
+    m_context = const_cast<GraphicsContext3D*>(context);
+
+    unsigned int textureId = m_context->platformTexture();
+    if (textureId != m_textureId)
+        m_textureChanged = true;
+    m_textureId = textureId;
+}
+
+}
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/chromium/WebGLLayerChromium.h b/WebCore/platform/graphics/chromium/WebGLLayerChromium.h
new file mode 100644 (file)
index 0000000..11b8db7
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef WebGLLayerChromium_h
+#define WebGLLayerChromium_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "CanvasLayerChromium.h"
+
+namespace WebCore {
+
+class GraphicsContext3D;
+
+// A Layer containing a WebGL canvas
+class WebGLLayerChromium : public CanvasLayerChromium {
+public:
+    static PassRefPtr<WebGLLayerChromium> create(GraphicsLayerChromium* owner = 0);
+    virtual bool drawsContent() { return m_context; }
+    virtual void updateContents();
+
+    void setContext(const GraphicsContext3D* context);
+
+private:
+    explicit WebGLLayerChromium(GraphicsLayerChromium* owner);
+    GraphicsContext3D* m_context;
+};
+
+}
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif
diff --git a/WebCore/platform/graphics/gpu/DrawingBuffer.cpp b/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
new file mode 100644 (file)
index 0000000..dc80954
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "DrawingBuffer.h"
+
+#include "GraphicsContext3D.h"
+#include "SharedGraphicsContext3D.h"
+
+namespace WebCore {
+
+PassOwnPtr<DrawingBuffer> DrawingBuffer::create(SharedGraphicsContext3D* context, const IntSize& size)
+{
+    unsigned framebuffer = context->createFramebuffer();
+    ASSERT(framebuffer);
+    if (!framebuffer)
+        return 0;
+    return adoptPtr(new DrawingBuffer(context, size, framebuffer));
+}
+
+void DrawingBuffer::bind()
+{
+    m_context->bindFramebuffer(m_framebuffer);
+    m_context->setViewport(m_size);
+}
+
+void DrawingBuffer::setWillPublishCallback(PassOwnPtr<WillPublishCallback> callback)
+{
+    m_callback = callback;
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/graphics/gpu/DrawingBuffer.h b/WebCore/platform/graphics/gpu/DrawingBuffer.h
new file mode 100644 (file)
index 0000000..1b44f4d
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DrawingBuffer_h
+#define DrawingBuffer_h
+
+#include "GraphicsLayer.h"
+#include "IntSize.h"
+
+#include <wtf/Noncopyable.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class SharedGraphicsContext3D;
+
+struct DrawingBufferInternal;
+
+// Manages a rendering target (framebuffer + attachment) for a canvas.  Can publish its rendering
+// results to a PlatformLayer for compositing.
+class DrawingBuffer : public Noncopyable {
+public:
+    static PassOwnPtr<DrawingBuffer> create(SharedGraphicsContext3D*, const IntSize&);
+    ~DrawingBuffer();
+
+    void reset(const IntSize&);
+    PlatformLayer* platformLayer();
+
+    void bind();
+    void publishToPlatformLayer();
+    IntSize size() const { return m_size; }
+
+    class WillPublishCallback : public Noncopyable {
+    public:
+        virtual void willPublish() = 0;
+    };
+
+    void setWillPublishCallback(PassOwnPtr<WillPublishCallback>);
+private:
+    DrawingBuffer(SharedGraphicsContext3D*, const IntSize&, unsigned framebuffer);
+
+    SharedGraphicsContext3D* m_context;
+    IntSize m_size;
+    unsigned m_framebuffer;
+
+    OwnPtr<WillPublishCallback> m_callback;
+    OwnPtr<DrawingBufferInternal> m_internal;
+};
+
+} // namespace WebCore
+
+#endif // DrawingBuffer_h
diff --git a/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp b/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
new file mode 100644 (file)
index 0000000..fa75b95
--- /dev/null
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "SharedGraphicsContext3D.h"
+
+#include "AffineTransform.h"
+#include "Color.h"
+#include "FloatRect.h"
+#include "GraphicsContext3D.h"
+#include "GraphicsTypes.h"
+#include "IntSize.h"
+#include "SolidFillShader.h"
+#include "TexShader.h"
+
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+// static
+PassRefPtr<SharedGraphicsContext3D> SharedGraphicsContext3D::create(PassOwnPtr<GraphicsContext3D> context)
+{
+    return adoptRef(new SharedGraphicsContext3D(context));
+}
+
+SharedGraphicsContext3D::SharedGraphicsContext3D(PassOwnPtr<GraphicsContext3D> context)
+    : m_context(context)
+    , m_quadVertices(0)
+    , m_solidFillShader(SolidFillShader::create(m_context.get()))
+    , m_texShader(TexShader::create(m_context.get()))
+{
+}
+
+SharedGraphicsContext3D::~SharedGraphicsContext3D()
+{
+    m_context->deleteBuffer(m_quadVertices);
+}
+
+void SharedGraphicsContext3D::makeContextCurrent()
+{
+    m_context->makeContextCurrent();
+}
+
+void SharedGraphicsContext3D::scissor(const FloatRect& rect)
+{
+    m_context->scissor(rect.x(), rect.y(), rect.width(), rect.height());
+}
+
+void SharedGraphicsContext3D::enable(unsigned capacity)
+{
+    m_context->enable(capacity);
+}
+
+void SharedGraphicsContext3D::disable(unsigned capacity)
+{
+    m_context->disable(capacity);
+}
+
+void SharedGraphicsContext3D::clearColor(const Color& color)
+{
+    float rgba[4];
+    color.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
+    m_context->clearColor(rgba[0], rgba[1], rgba[2], rgba[3]);
+}
+
+void SharedGraphicsContext3D::clear(unsigned mask)
+{
+    m_context->clear(mask);
+}
+
+void SharedGraphicsContext3D::drawArrays(unsigned long mode, long first, long count)
+{
+    m_context->drawArrays(mode, first, count);
+}
+
+unsigned long SharedGraphicsContext3D::getError()
+{
+    return m_context->getError();
+}
+
+void SharedGraphicsContext3D::getIntegerv(unsigned long pname, int* value)
+{
+    m_context->getIntegerv(pname, value);
+}
+
+unsigned SharedGraphicsContext3D::createFramebuffer()
+{
+    return m_context->createFramebuffer();
+}
+
+unsigned SharedGraphicsContext3D::createTexture()
+{
+    return m_context->createTexture();
+}
+
+void SharedGraphicsContext3D::deleteFramebuffer(unsigned framebuffer)
+{
+    m_context->deleteFramebuffer(framebuffer);
+}
+
+void SharedGraphicsContext3D::deleteTexture(unsigned texture)
+{
+    m_context->deleteTexture(texture);
+}
+
+void SharedGraphicsContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, unsigned texture, long level)
+{
+    m_context->framebufferTexture2D(target, attachment, textarget, texture, level);
+}
+
+void SharedGraphicsContext3D::texParameteri(unsigned target, unsigned pname, int param)
+{
+    m_context->texParameteri(target, pname, param);
+}
+
+int SharedGraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels)
+{
+    m_context->texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
+}
+
+int SharedGraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels)
+{
+    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
+}
+
+void SharedGraphicsContext3D::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* data)
+{
+    m_context->readPixels(x, y, width, height, format, type, data);
+}
+
+bool SharedGraphicsContext3D::supportsBGRA()
+{
+    return m_context->supportsBGRA();
+}
+
+Texture* SharedGraphicsContext3D::createTexture(NativeImagePtr ptr, Texture::Format format, int width, int height)
+{
+    RefPtr<Texture> texture = m_textures.get(ptr);
+    if (texture)
+        return texture.get();
+
+    texture = Texture::create(m_context.get(), format, width, height);
+    Texture* t = texture.get();
+    m_textures.set(ptr, texture);
+    return t;
+}
+
+Texture* SharedGraphicsContext3D::getTexture(NativeImagePtr ptr)
+{
+    RefPtr<Texture> texture = m_textures.get(ptr);
+    return texture ? texture.get() : 0;
+}
+
+PassRefPtr<Texture> SharedGraphicsContext3D::createTexture(Texture::Format format, int width, int height)
+{
+    return Texture::create(m_context.get(), format, width, height);
+}
+
+void SharedGraphicsContext3D::applyCompositeOperator(CompositeOperator op)
+{
+    switch (op) {
+    case CompositeClear:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ZERO);
+        break;
+    case CompositeCopy:
+        m_context->disable(GraphicsContext3D::BLEND);
+        break;
+    case CompositeSourceOver:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
+        break;
+    case CompositeSourceIn:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ZERO);
+        break;
+    case CompositeSourceOut:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ZERO);
+        break;
+    case CompositeSourceAtop:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
+        break;
+    case CompositeDestinationOver:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE);
+        break;
+    case CompositeDestinationIn:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::SRC_ALPHA);
+        break;
+    case CompositeDestinationOut:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
+        break;
+    case CompositeDestinationAtop:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::SRC_ALPHA);
+        break;
+    case CompositeXOR:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
+        break;
+    case CompositePlusDarker:
+    case CompositeHighlight:
+        // unsupported
+        m_context->disable(GraphicsContext3D::BLEND);
+        break;
+    case CompositePlusLighter:
+        m_context->enable(GraphicsContext3D::BLEND);
+        m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE);
+        break;
+    }
+}
+
+void SharedGraphicsContext3D::useQuadVertices()
+{
+    if (!m_quadVertices) {
+        float vertices[] = { 0.0f, 0.0f, 1.0f,
+                             1.0f, 0.0f, 1.0f,
+                             0.0f, 1.0f, 1.0f,
+                             1.0f, 1.0f, 1.0f };
+        m_quadVertices = m_context->createBuffer();
+        m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices);
+        m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, sizeof(vertices), vertices, GraphicsContext3D::STATIC_DRAW);
+    } else {
+        m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices);
+    }
+}
+
+void SharedGraphicsContext3D::setActiveTexture(unsigned textureUnit)
+{
+    m_context->activeTexture(textureUnit);
+}
+
+void SharedGraphicsContext3D::bindTexture(unsigned target, unsigned texture)
+{
+    m_context->bindTexture(target, texture);
+}
+
+void SharedGraphicsContext3D::useFillSolidProgram(const AffineTransform& transform, const Color& color)
+{
+    m_solidFillShader->use(transform, color);
+}
+
+void SharedGraphicsContext3D::useTextureProgram(const AffineTransform& transform, const AffineTransform& texTransform, float alpha)
+{
+    m_texShader->use(transform, texTransform, 0, alpha);
+}
+
+void SharedGraphicsContext3D::bindFramebuffer(unsigned framebuffer)
+{
+    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, framebuffer);
+}
+
+void SharedGraphicsContext3D::setViewport(const IntSize& size)
+{
+    m_context->viewport(0, 0, size.width(), size.height());
+}
+
+bool SharedGraphicsContext3D::paintsIntoCanvasBuffer() const
+{
+    return m_context->paintsIntoCanvasBuffer();
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h b/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h
new file mode 100644 (file)
index 0000000..1baa0f6
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SharedGraphicsContext3D_h
+#define SharedGraphicsContext3D_h
+
+#include "GraphicsTypes.h"
+#include "ImageSource.h"
+#include "Texture.h"
+
+#include <wtf/HashMap.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class AffineTransform;
+class Color;
+class GraphicsContext3D;
+class FloatRect;
+class IntSize;
+class SolidFillShader;
+class TexShader;
+
+typedef HashMap<NativeImagePtr, RefPtr<Texture> > TextureHashMap;
+
+class SharedGraphicsContext3D : public RefCounted<SharedGraphicsContext3D> {
+public:
+    static PassRefPtr<SharedGraphicsContext3D> create(PassOwnPtr<GraphicsContext3D>);
+    ~SharedGraphicsContext3D();
+
+    // Functions that delegate directly to GraphicsContext3D, with caching
+    void makeContextCurrent();
+    void bindFramebuffer(unsigned framebuffer);
+    void setViewport(const IntSize&);
+    void scissor(const FloatRect&);
+    void enable(unsigned capacity);
+    void disable(unsigned capacity);
+    void clearColor(const Color&);
+    void clear(unsigned mask);
+    void drawArrays(unsigned long mode, long first, long count);
+    unsigned long getError();
+    void getIntegerv(unsigned long pname, int* value);
+
+    unsigned createFramebuffer();
+    unsigned createTexture();
+
+    void deleteFramebuffer(unsigned framebuffer);
+    void deleteTexture(unsigned texture);
+
+    void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, unsigned, long level);
+    void texParameteri(unsigned target, unsigned pname, int param);
+    int texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels);
+    int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels);
+
+    void readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* data);
+
+    bool paintsIntoCanvasBuffer() const;
+
+    // Shared logic for canvas 2d
+    void applyCompositeOperator(CompositeOperator);
+    void useQuadVertices();
+
+    void useFillSolidProgram(const AffineTransform&, const Color&);
+    void useTextureProgram(const AffineTransform&, const AffineTransform&, float alpha);
+
+    void setActiveTexture(unsigned textureUnit);
+    void bindTexture(unsigned target, unsigned texture);
+
+    bool supportsBGRA();
+
+    // Creates a texture associated with the given image.  Is owned by this context's
+    // TextureHashMap.
+    Texture* createTexture(NativeImagePtr, Texture::Format, int width, int height);
+    Texture* getTexture(NativeImagePtr);
+
+    // Creates a texture that is not associated with any image.  The caller takes ownership of
+    // the texture.
+    PassRefPtr<Texture> createTexture(Texture::Format, int width, int height);
+
+private:
+    SharedGraphicsContext3D(PassOwnPtr<GraphicsContext3D> context);
+
+    OwnPtr<GraphicsContext3D> m_context;
+
+    unsigned m_quadVertices;
+
+    OwnPtr<SolidFillShader> m_solidFillShader;
+    OwnPtr<TexShader> m_texShader;
+
+    TextureHashMap m_textures;
+};
+
+} // namespace WebCore
+
+#endif // SharedGraphicsContext3D_h
index 557603c..36e4ad5 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "GraphicsContext3D.h"
 #include "IntRect.h"
+
 #include <wtf/OwnArrayPtr.h>
 
 namespace WebCore {
index 1c80d49..a7402b9 100644 (file)
@@ -1240,14 +1240,14 @@ void GraphicsContext::translate(float w, float h)
                                            WebCoreFloatToSkScalar(h));
 }
 
-void GraphicsContext::setGraphicsContext3D(GraphicsContext3D* context3D, const IntSize& size)
+void GraphicsContext::syncSoftwareCanvas()
 {
-    platformContext()->setGraphicsContext3D(context3D, size);
+    platformContext()->syncSoftwareCanvas();
 }
 
-void GraphicsContext::syncSoftwareCanvas()
+void GraphicsContext::setSharedGraphicsContext3D(SharedGraphicsContext3D* context, DrawingBuffer* framebuffer, const IntSize& size)
 {
-    platformContext()->syncSoftwareCanvas();
+    platformContext()->setSharedGraphicsContext3D(context, framebuffer, size);
 }
 
 }  // namespace WebCore
index aed289f..5b5962a 100644 (file)
@@ -47,6 +47,7 @@
 #include "SkRect.h"
 #include "SkShader.h"
 #include "SkiaUtils.h"
+#include "Texture.h"
 
 #include "skia/ext/image_operations.h"
 #include "skia/ext/platform_canvas.h"
index 3b1d015..52fe327 100644 (file)
 #include "PlatformContextSkia.h"
 
 #include "AffineTransform.h"
-#include "CanvasLayerChromium.h"
+#include "DrawingBuffer.h"
 #include "GLES2Canvas.h"
 #include "GraphicsContext.h"
 #include "GraphicsContext3D.h"
 #include "ImageBuffer.h"
 #include "NativeImageSkia.h"
+#include "SharedGraphicsContext3D.h"
 #include "SkiaUtils.h"
 #include "Texture.h"
 #include "TilingData.h"
@@ -216,12 +217,8 @@ PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas)
 
 PlatformContextSkia::~PlatformContextSkia()
 {
-#if USE(ACCELERATED_COMPOSITING)
-    if (m_gpuCanvas) {
-        CanvasLayerChromium* layer = static_cast<CanvasLayerChromium*>(m_gpuCanvas->context()->platformLayer());
-        layer->setPrepareTextureCallback(0);
-    }
-#endif
+    if (m_gpuCanvas)
+        m_gpuCanvas->drawingBuffer()->setWillPublishCallback(0);
 }
 
 void PlatformContextSkia::setCanvas(skia::PlatformCanvas* canvas)
@@ -678,33 +675,33 @@ void PlatformContextSkia::applyAntiAliasedClipPaths(WTF::Vector<SkPath>& paths)
     m_canvas->restore();
 }
 
-#if USE(ACCELERATED_COMPOSITING)
-class PrepareTextureCallbackImpl : public CanvasLayerChromium::PrepareTextureCallback {
+class WillPublishCallbackImpl : public DrawingBuffer::WillPublishCallback {
 public:
-    static PassOwnPtr<PrepareTextureCallbackImpl> create(PlatformContextSkia* pcs)
+    static PassOwnPtr<WillPublishCallback> create(PlatformContextSkia* pcs)
     {
-        return new PrepareTextureCallbackImpl(pcs);
+        return adoptPtr(new WillPublishCallbackImpl(pcs));
     }
 
-    virtual void willPrepareTexture()
+    virtual void willPublish()
     {
         m_pcs->prepareForHardwareDraw();
     }
+
 private:
-    explicit PrepareTextureCallbackImpl(PlatformContextSkia* pcs) : m_pcs(pcs) {}
+    explicit WillPublishCallbackImpl(PlatformContextSkia* pcs)
+        : m_pcs(pcs)
+    {
+    }
+
     PlatformContextSkia* m_pcs;
 };
-#endif
 
-void PlatformContextSkia::setGraphicsContext3D(GraphicsContext3D* context, const WebCore::IntSize& size)
+void PlatformContextSkia::setSharedGraphicsContext3D(SharedGraphicsContext3D* context, DrawingBuffer* drawingBuffer, const WebCore::IntSize& size)
 {
     m_useGPU = true;
-    m_gpuCanvas = new GLES2Canvas(context, size);
+    m_gpuCanvas = new GLES2Canvas(context, drawingBuffer, size);
     m_uploadTexture.clear();
-#if USE(ACCELERATED_COMPOSITING)
-    CanvasLayerChromium* layer = static_cast<CanvasLayerChromium*>(context->platformLayer());
-    layer->setPrepareTextureCallback(PrepareTextureCallbackImpl::create(this));
-#endif
+    drawingBuffer->setWillPublishCallback(WillPublishCallbackImpl::create(this));
 }
 
 void PlatformContextSkia::prepareForSoftwareDraw() const
@@ -784,9 +781,9 @@ void PlatformContextSkia::uploadSoftwareToHardware(CompositeOperator op) const
 {
     const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(false);
     SkAutoLockPixels lock(bitmap);
-    GraphicsContext3D* context = m_gpuCanvas->context();
+    SharedGraphicsContext3D* context = m_gpuCanvas->context();
     if (!m_uploadTexture || m_uploadTexture->tiles().totalSizeX() < bitmap.width() || m_uploadTexture->tiles().totalSizeY() < bitmap.height())
-        m_uploadTexture = Texture::create(context, Texture::BGRA8, bitmap.width(), bitmap.height());
+        m_uploadTexture = context->createTexture(Texture::BGRA8, bitmap.width(), bitmap.height());
     m_uploadTexture->load(bitmap.getPixels());
     IntRect rect(0, 0, bitmap.width(), bitmap.height());
     AffineTransform identity;
@@ -799,7 +796,8 @@ void PlatformContextSkia::readbackHardwareToSoftware() const
     SkAutoLockPixels lock(bitmap);
     int width = bitmap.width(), height = bitmap.height();
     OwnArrayPtr<uint32_t> buf(new uint32_t[width]);
-    GraphicsContext3D* context = m_gpuCanvas->context();
+    SharedGraphicsContext3D* context = m_gpuCanvas->context();
+    m_gpuCanvas->bindFramebuffer();
     // Flips the image vertically.
     for (int y = 0; y < height; ++y) {
         uint32_t* pixels = bitmap.getAddr32(0, y);
index 82edc16..2606240 100644 (file)
@@ -35,7 +35,6 @@
 #include "Noncopyable.h"
 
 #include "SkDashPathEffect.h"
-#include "SkDeque.h"
 #include "SkDrawLooper.h"
 #include "SkPaint.h"
 #include "SkPath.h"
 namespace WebCore {
 
 enum CompositeOperator;
+class DrawingBuffer;
 class GLES2Canvas;
-class Texture;
 class GraphicsContext3D;
+class Texture;
 
 // This class holds the platform-specific state for GraphicsContext. We put
 // most of our Skia wrappers on this class. In theory, a lot of this stuff could
@@ -181,7 +181,7 @@ public:
     void clearImageResamplingHint();
     bool hasImageResamplingHint() const;
     bool useGPU() { return m_useGPU; }
-    void setGraphicsContext3D(GraphicsContext3D*, const IntSize&);
+    void setSharedGraphicsContext3D(SharedGraphicsContext3D*, DrawingBuffer*, const IntSize&);
     GLES2Canvas* gpuCanvas() const { return m_gpuCanvas.get(); }
 
     // Call these before making a call that manipulates the underlying
index 0ba907b..f9090ba 100644 (file)
 
 #if USE(ACCELERATED_COMPOSITING)
 
+#include "RenderLayerBacking.h"
+
 #include "AnimationController.h"
 #include "CanvasRenderingContext.h"
+#include "CanvasRenderingContext2D.h"
 #include "CSSPropertyNames.h"
 #include "CSSStyleSelector.h"
 #include "FrameView.h"
@@ -51,8 +54,7 @@
 #include "RenderVideo.h"
 #include "RenderView.h"
 #include "Settings.h"
-
-#include "RenderLayerBacking.h"
+#include "WebGLRenderingContext.h"
 
 using namespace std;
 
@@ -258,9 +260,8 @@ bool RenderLayerBacking::updateGraphicsLayerConfiguration()
     else if (isAcceleratedCanvas(renderer())) {
         HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer()->node());
         if (CanvasRenderingContext* context = canvas->renderingContext())
-            if (context->graphicsContext3D())
-                if (PlatformLayer* pl = context->graphicsContext3D()->platformLayer())
-                    m_graphicsLayer->setContentsToCanvas(pl);
+            m_graphicsLayer->setContentsToCanvas(context->platformLayer());
+        layerConfigChanged = true;
     }
 #endif
 
index 9e00302..fba5789 100644 (file)
@@ -1,3 +1,24 @@
+2010-09-03  James Robinson  <jamesr@chromium.org>
+
+        Reviewed by Chris Marrin.
+
+        Multiple accelerated 2D canvases should be able to use the same GraphicsContext3D
+        https://bugs.webkit.org/show_bug.cgi?id=44926
+
+        Adds a SharedContext3D to WebViewImpl. The SharedContext3D has to live on WebViewImpl to be
+        tied to the lifetime of the compositor context.
+
+        * src/ChromeClientImpl.cpp:
+        (WebKit::ChromeClientImpl::getSharedGraphicsContext3D):
+        * src/ChromeClientImpl.h:
+        * src/GraphicsContext3D.cpp:
+        (WebCore::GraphicsContext3DInternal::initialize):
+        (WebCore::GraphicsContext3DInternal::platformLayer):
+        (WebCore::GraphicsContext3D::platformLayer):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::getSharedGraphicsContext3D):
+        * src/WebViewImpl.h:
+
 2010-08-31  Jeremy Orlow  <jorlow@chromium.org>
 
         Reviewed by Steve Block.
index e6f1400..9edee02 100644 (file)
@@ -59,6 +59,7 @@
 #include "SearchPopupMenuChromium.h"
 #include "ScriptController.h"
 #include "SecurityOrigin.h"
+#include "SharedGraphicsContext3D.h"
 #include "WebGeolocationService.h"
 #if USE(V8)
 #include "V8Proxy.h"
@@ -751,6 +752,11 @@ void ChromeClientImpl::scheduleCompositingLayerSync()
 }
 #endif
 
+WebCore::SharedGraphicsContext3D* ChromeClientImpl::getSharedGraphicsContext3D()
+{
+    return m_webView->getSharedGraphicsContext3D();
+}
+
 bool ChromeClientImpl::supportsFullscreenForNode(const WebCore::Node* node)
 {
     if (m_webView->client() && node->hasTagName(WebCore::HTMLNames::videoTag))
index bff9f90..d7b5c86 100644 (file)
@@ -152,6 +152,8 @@ public:
     virtual void scheduleCompositingLayerSync();
 #endif
 
+    virtual WebCore::SharedGraphicsContext3D* getSharedGraphicsContext3D();
+
     virtual bool supportsFullscreenForNode(const WebCore::Node*);
     virtual void enterFullscreenForNode(WebCore::Node*);
     virtual void exitFullscreenForNode(WebCore::Node*);
index 6bc5ffe..6a9b3e4 100644 (file)
@@ -35,7 +35,7 @@
 #include "GraphicsContext3D.h"
 
 #include "CachedImage.h"
-#include "CanvasLayerChromium.h"
+#include "WebGLLayerChromium.h"
 #include "CanvasRenderingContext.h"
 #include "Chrome.h"
 #include "ChromeClientImpl.h"
@@ -103,7 +103,7 @@ public:
     void prepareTexture();
 
 #if USE(ACCELERATED_COMPOSITING)
-    CanvasLayerChromium* platformLayer() const;
+    WebGLLayerChromium* platformLayer() const;
 #endif
     bool isGLES2Compliant() const;
     bool isGLES2NPOTStrict() const;
@@ -298,7 +298,7 @@ private:
     OwnPtr<WebKit::WebGraphicsContext3D> m_impl;
     WebKit::WebViewImpl* m_webViewImpl;
 #if USE(ACCELERATED_COMPOSITING)
-    RefPtr<CanvasLayerChromium> m_compositingLayer;
+    RefPtr<WebGLLayerChromium> m_compositingLayer;
 #endif
 #if PLATFORM(SKIA)
     // If the width and height of the Canvas's backing store don't
@@ -360,7 +360,7 @@ bool GraphicsContext3DInternal::initialize(GraphicsContext3D::Attributes attrs,
     m_impl.set(webContext);
 
 #if USE(ACCELERATED_COMPOSITING)
-    m_compositingLayer = CanvasLayerChromium::create(0);
+    m_compositingLayer = WebGLLayerChromium::create(0);
 #endif
     return true;
 }
@@ -381,7 +381,7 @@ void GraphicsContext3DInternal::prepareTexture()
 }
 
 #if USE(ACCELERATED_COMPOSITING)
-CanvasLayerChromium* GraphicsContext3DInternal::platformLayer() const
+WebGLLayerChromium* GraphicsContext3DInternal::platformLayer() const
 {
     return m_compositingLayer.get();
 }
@@ -1039,7 +1039,7 @@ void GraphicsContext3D::prepareTexture()
 #if USE(ACCELERATED_COMPOSITING)
 PlatformLayer* GraphicsContext3D::platformLayer() const
 {
-    CanvasLayerChromium* canvasLayer = m_internal->platformLayer();
+    WebGLLayerChromium* canvasLayer = m_internal->platformLayer();
     canvasLayer->setContext(this);
     return canvasLayer;
 }
index 4b129d6..43f7f4b 100644 (file)
@@ -58,6 +58,7 @@
 #include "GLES2Context.h"
 #include "GLES2ContextInternal.h"
 #include "GraphicsContext.h"
+#include "GraphicsContext3D.h"
 #include "HTMLInputElement.h"
 #include "HTMLMediaElement.h"
 #include "HitTestResult.h"
@@ -86,6 +87,7 @@
 #include "SecurityOrigin.h"
 #include "SelectionController.h"
 #include "Settings.h"
+#include "SharedGraphicsContext3D.h"
 #include "Timer.h"
 #include "TypingCommand.h"
 #include "UserGestureIndicator.h"
@@ -2215,14 +2217,15 @@ PassOwnPtr<GLES2Context> WebViewImpl::getOnscreenGLES2Context()
     return GLES2Context::create(GLES2ContextInternal::create(gles2Context(), false));
 }
 
-PassOwnPtr<GLES2Context> WebViewImpl::getOffscreenGLES2Context()
+SharedGraphicsContext3D* WebViewImpl::getSharedGraphicsContext3D()
 {
-    WebGLES2Context* context = webKitClient()->createGLES2Context();
-    if (!context)
-        return 0;
-    if (!context->initialize(0, gles2Context()))
-        return 0;
-    return GLES2Context::create(GLES2ContextInternal::create(context, true));
+    if (!m_sharedContext3D) {
+        GraphicsContext3D::Attributes attr;
+        OwnPtr<GraphicsContext3D> context = GraphicsContext3D::create(attr, m_page->chrome());
+        m_sharedContext3D = SharedGraphicsContext3D::create(context.release());
+    }
+
+    return m_sharedContext3D.get();
 }
 
 // Returns the GLES2 context associated with this View. If one doesn't exist
index c296121..6ce2757 100644 (file)
@@ -329,10 +329,10 @@ public:
     // Offscreen contexts render offscreen but can share resources with the
     // onscreen context and thus can be composited.
     PassOwnPtr<WebCore::GLES2Context> getOnscreenGLES2Context();
-    PassOwnPtr<WebCore::GLES2Context> getOffscreenGLES2Context();
 
     // Returns an onscreen context
     virtual WebGLES2Context* gles2Context();
+    virtual WebCore::SharedGraphicsContext3D* getSharedGraphicsContext3D();
 
     WebCore::PopupContainer* selectPopup() const { return m_selectPopup.get(); }
 
@@ -521,6 +521,8 @@ private:
 
     OwnPtr<WebGLES2Context> m_gles2Context;
 
+    RefPtr<WebCore::SharedGraphicsContext3D> m_sharedContext3D;
+
     OwnPtr<DeviceOrientationClientProxy> m_deviceOrientationClientProxy;
 };