Title: [193630] trunk/Source
Revision
193630
Author
y...@igalia.com
Date
2015-12-07 09:15:56 -0800 (Mon, 07 Dec 2015)

Log Message

[ThreadedCompositor] Add support for PlatformLayer.
https://bugs.webkit.org/show_bug.cgi?id=143299

Reviewed by Žan Doberšek.

Source/WebCore:

This patch implements TextureMapperPlatformLayerProxy and TextureMapperPlatformLayerBuffer to
send a texture (actual texture or BitmapTexture) to the compositing thread directly.
Platform layer renderers should implement TextureMapperPlatformLayerProxyProvider to establish
a connection to the compositing thread. After the connection has been established, the renderer
can render its contents to the TextureMapperPlatformLayerBuffer and pass it to the compositing thread
via TextureMapperPlatformLayer proxy.
The buffer can be an unmanaged texture (a.k.a. platform texture) or BitmapTexture.
For the unmanaged texture, the renderer should manage its life cycle itself. For the BitmapTexture,
it will be managed by TextureMapperPlatformLayerProxy. In that case, used (swapped) buffer will be
recycled because the renderer will use same size and format until it changes its size.

No new tests needed.

* PlatformGTK.cmake:
Adds TextureMapperPlatformLayerBuffer and TextureMapperPlaytformLayerProxy.

* platform/graphics/GraphicsContext3DPrivate.cpp:
* platform/graphics/GraphicsContext3DPrivate.h:
* platform/graphics/cairo/ImageBufferCairo.cpp:
* platform/graphics/cairo/ImageBufferDataCairo.h:
Adds mock implementation.

* platform/graphics/PlatformLayer.h:
Adds TextureMapperPlatformLayerProxyProvider as a PlatformLayer for the Threaded Compositor

* platform/graphics/texmap/BitmapTextureGL.h:
(WebCore::BitmapTextureGL::internalFormat): Adds a getter to check the
internal format of texture to check reusability.

* platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
* platform/graphics/texmap/GraphicsLayerTextureMapper.h:
* platform/graphics/texmap/TextureMapperLayer.cpp:
* platform/graphics/texmap/TextureMapperLayer.h:
Exclude GraphicsLayerTextureMapper from build when we are using Coordinated Graphics.

* platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp: Added.
* platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h: Added.
* platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp: Added.
* platform/graphics/texmap/TextureMapperPlatformLayerProxy.h: Added.

* platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
(WebCore::GraphicsLayer::create):
Because we removed GraphicsLayerTextureMapper from build, we need to add own factory function.

(WebCore::CoordinatedGraphicsLayer::setContentsToPlatformLayer):
(WebCore::CoordinatedGraphicsLayer::syncPlatformLayer):
(WebCore::CoordinatedGraphicsLayer::platformLayerWillBeDestroyed):
(WebCore::CoordinatedGraphicsLayer::setPlatformLayerNeedsDisplay):
Implements sync operations for TextureMapperPlatformLayerProxy

Source/WebKit2:

* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
(WebKit::CoordinatedGraphicsScene::paintToCurrentGLContext):
Swap pending buffers of TextureMapperPlatformLayerProxies before painting contents.
(WebKit::CoordinatedGraphicsScene::syncPlatformLayerIfNeeded):
In threaded compositor, CoordinatedGraphicsScence only cares about creation and deletion
of platform layers.

(WebKit::CoordinatedGraphicsScene::onNewBufferAvailable):
Whenever new buffer comes via TextureMapperPlatformLayerProxy, CoordinatedGraphicsScene will
update the scene if it is needed.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (193629 => 193630)


--- trunk/Source/WebCore/ChangeLog	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/ChangeLog	2015-12-07 17:15:56 UTC (rev 193630)
@@ -1,5 +1,62 @@
 2015-12-07  Gwang Yoon Hwang  <y...@igalia.com>
 
+        [ThreadedCompositor] Add support for PlatformLayer.
+        https://bugs.webkit.org/show_bug.cgi?id=143299
+
+        Reviewed by Žan Doberšek.
+
+        This patch implements TextureMapperPlatformLayerProxy and TextureMapperPlatformLayerBuffer to
+        send a texture (actual texture or BitmapTexture) to the compositing thread directly.
+        Platform layer renderers should implement TextureMapperPlatformLayerProxyProvider to establish
+        a connection to the compositing thread. After the connection has been established, the renderer
+        can render its contents to the TextureMapperPlatformLayerBuffer and pass it to the compositing thread
+        via TextureMapperPlatformLayer proxy.
+        The buffer can be an unmanaged texture (a.k.a. platform texture) or BitmapTexture.
+        For the unmanaged texture, the renderer should manage its life cycle itself. For the BitmapTexture,
+        it will be managed by TextureMapperPlatformLayerProxy. In that case, used (swapped) buffer will be
+        recycled because the renderer will use same size and format until it changes its size.
+
+        No new tests needed.
+
+        * PlatformGTK.cmake:
+        Adds TextureMapperPlatformLayerBuffer and TextureMapperPlaytformLayerProxy.
+
+        * platform/graphics/GraphicsContext3DPrivate.cpp:
+        * platform/graphics/GraphicsContext3DPrivate.h:
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        * platform/graphics/cairo/ImageBufferDataCairo.h:
+        Adds mock implementation.
+
+        * platform/graphics/PlatformLayer.h:
+        Adds TextureMapperPlatformLayerProxyProvider as a PlatformLayer for the Threaded Compositor
+
+        * platform/graphics/texmap/BitmapTextureGL.h:
+        (WebCore::BitmapTextureGL::internalFormat): Adds a getter to check the
+        internal format of texture to check reusability.
+
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.h:
+        * platform/graphics/texmap/TextureMapperLayer.cpp:
+        * platform/graphics/texmap/TextureMapperLayer.h:
+        Exclude GraphicsLayerTextureMapper from build when we are using Coordinated Graphics.
+
+        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp: Added.
+        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h: Added.
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp: Added.
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxy.h: Added.
+
+        * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::create):
+        Because we removed GraphicsLayerTextureMapper from build, we need to add own factory function.
+
+        (WebCore::CoordinatedGraphicsLayer::setContentsToPlatformLayer):
+        (WebCore::CoordinatedGraphicsLayer::syncPlatformLayer):
+        (WebCore::CoordinatedGraphicsLayer::platformLayerWillBeDestroyed):
+        (WebCore::CoordinatedGraphicsLayer::setPlatformLayerNeedsDisplay):
+        Implements sync operations for TextureMapperPlatformLayerProxy
+
+2015-12-07  Gwang Yoon Hwang  <y...@igalia.com>
+
         Fix GTK+ build with GStreamer GL
         https://bugs.webkit.org/show_bug.cgi?id=151939
 

Modified: trunk/Source/WebCore/PlatformGTK.cmake (193629 => 193630)


--- trunk/Source/WebCore/PlatformGTK.cmake	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/PlatformGTK.cmake	2015-12-07 17:15:56 UTC (rev 193630)
@@ -442,6 +442,8 @@
         page/scrolling/coordinatedgraphics/ScrollingCoordinatorCoordinatedGraphics.cpp
         page/scrolling/coordinatedgraphics/ScrollingStateNodeCoordinatedGraphics.cpp
 
+        platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp
+        platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp
         platform/graphics/texmap/coordinated/AreaAllocator.cpp
         platform/graphics/texmap/coordinated/CompositingCoordinator.cpp
         platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.cpp (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.cpp	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.cpp	2015-12-07 17:15:56 UTC (rev 193630)
@@ -63,7 +63,7 @@
 
 GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
 {
-#if USE(TEXTURE_MAPPER)
+#if USE(TEXTURE_MAPPER) && !USE(COORDINATED_GRAPHICS_THREADED)
     if (client())
         client()->platformLayerWillBeDestroyed();
 #endif
@@ -79,7 +79,13 @@
     return m_glContext ? m_glContext->platformContext() : GLContext::getCurrent()->platformContext();
 }
 
-#if USE(TEXTURE_MAPPER)
+#if USE(COORDINATED_GRAPHICS_THREADED)
+RefPtr<TextureMapperPlatformLayerProxy> GraphicsContext3DPrivate::proxy() const
+{
+    notImplemented();
+    return nullptr;
+}
+#elif USE(TEXTURE_MAPPER)
 void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
 {
     if (!m_glContext)

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.h (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -23,14 +23,18 @@
 #include "GLContext.h"
 #include "GraphicsContext3D.h"
 
-#if USE(TEXTURE_MAPPER)
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include "TextureMapperPlatformLayerProxy.h"
+#elif USE(TEXTURE_MAPPER)
 #include "TextureMapperPlatformLayer.h"
 #endif
 
 namespace WebCore {
 
 class GraphicsContext3DPrivate
-#if USE(TEXTURE_MAPPER)
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    : public TextureMapperPlatformLayerProxyProvider
+#elif USE(TEXTURE_MAPPER)
     : public TextureMapperPlatformLayer
 #endif
 {
@@ -42,7 +46,10 @@
 
     GraphicsContext3D::RenderStyle renderStyle() { return m_renderStyle; }
 
-#if USE(TEXTURE_MAPPER)
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    virtual RefPtr<TextureMapperPlatformLayerProxy> proxy() const override;
+    virtual void swapBuffersIfNeeded() override { };
+#elif USE(TEXTURE_MAPPER)
     virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity);
 #endif
 

Modified: trunk/Source/WebCore/platform/graphics/PlatformLayer.h (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/PlatformLayer.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/PlatformLayer.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -31,6 +31,11 @@
 typedef CALayer PlatformLayer;
 #elif PLATFORM(WIN) && USE(CA)
 typedef struct _CACFLayer PlatformLayer;
+#elif USE(COORDINATED_GRAPHICS_THREADED)
+namespace WebCore {
+class TextureMapperPlatformLayerProxyProvider;
+typedef TextureMapperPlatformLayerProxyProvider PlatformLayer;
+};
 #elif USE(TEXTURE_MAPPER)
 namespace WebCore {
 class TextureMapperPlatformLayer;

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2015-12-07 17:15:56 UTC (rev 193630)
@@ -52,7 +52,10 @@
 #include "OpenGLShims.h"
 #include "TextureMapperGL.h"
 #include <cairo-gl.h>
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include "TextureMapperPlatformLayerProxy.h"
 #endif
+#endif
 
 using namespace std;
 
@@ -409,6 +412,13 @@
 #endif
 
 #if ENABLE(ACCELERATED_2D_CANVAS)
+#if USE(COORDINATED_GRAPHICS_THREADED)
+RefPtr<TextureMapperPlatformLayerProxy> ImageBufferData::proxy() const
+{
+    notImplemented();
+    return nullptr;
+}
+#else
 void ImageBufferData::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
 {
     ASSERT(m_texture);
@@ -421,6 +431,7 @@
     static_cast<TextureMapperGL*>(textureMapper)->drawTexture(m_texture, TextureMapperGL::ShouldBlend, m_size, targetRect, matrix, opacity);
 }
 #endif
+#endif
 
 PlatformLayer* ImageBuffer::platformLayer() const
 {

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -33,8 +33,12 @@
 
 #if ENABLE(ACCELERATED_2D_CANVAS)
 #include "TextureMapper.h"
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include "TextureMapperPlatformLayerProxy.h"
+#else
 #include "TextureMapperPlatformLayer.h"
 #endif
+#endif
 
 namespace WebCore {
 
@@ -42,8 +46,12 @@
 
 class ImageBufferData
 #if ENABLE(ACCELERATED_2D_CANVAS)
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    : public TextureMapperPlatformLayerProxyProvider
+#else
     : public TextureMapperPlatformLayer
 #endif
+#endif
 {
 public:
     ImageBufferData(const IntSize&);
@@ -54,7 +62,12 @@
     IntSize m_size;
 
 #if ENABLE(ACCELERATED_2D_CANVAS)
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    virtual RefPtr<TextureMapperPlatformLayerProxy> proxy() const override;
+    virtual void swapBuffersIfNeeded() override { };
+#else
     virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity);
+#endif
     uint32_t m_texture;
 #endif
 };

Modified: trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.h (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -69,6 +69,8 @@
     const FilterInfo* filterInfo() const { return &m_filterInfo; }
     TextureMapperGL::ClipStack& clipStack() { return m_clipStack; }
 
+    GC3Dint internalFormat() const { return m_internalFormat; }
+
 private:
 
     Platform3DObject m_id;

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp	2015-12-07 17:15:56 UTC (rev 193630)
@@ -26,7 +26,7 @@
 #include "TextureMapperAnimation.h"
 #include <wtf/CurrentTime.h>
 
-#if USE(TEXTURE_MAPPER)
+#if USE(TEXTURE_MAPPER) && !USE(COORDINATED_GRAPHICS)
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -20,7 +20,7 @@
 #ifndef GraphicsLayerTextureMapper_h
 #define GraphicsLayerTextureMapper_h
 
-#if USE(TEXTURE_MAPPER)
+#if USE(TEXTURE_MAPPER) && !USE(COORDINATED_GRAPHICS)
 
 #include "GraphicsLayer.h"
 #include "GraphicsLayerClient.h"

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp	2015-12-07 17:15:56 UTC (rev 193630)
@@ -445,12 +445,14 @@
     removeFromParent();
 }
 
+#if !USE(COORDINATED_GRAPHICS)
 void TextureMapperLayer::setChildren(const Vector<GraphicsLayer*>& newChildren)
 {
     removeAllChildren();
     for (auto* child : newChildren)
         addChild(&downcast<GraphicsLayerTextureMapper>(child)->layer());
 }
+#endif
 
 void TextureMapperLayer::setChildren(const Vector<TextureMapperLayer*>& newChildren)
 {

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -78,7 +78,9 @@
     TextureMapper* textureMapper() const { return rootLayer().m_textureMapper; }
     void setTextureMapper(TextureMapper* texmap) { m_textureMapper = texmap; }
 
+#if !USE(COORDINATED_GRAPHICS)
     void setChildren(const Vector<GraphicsLayer*>&);
+#endif
     void setChildren(const Vector<TextureMapperLayer*>&);
     void setMaskLayer(TextureMapperLayer*);
     void setReplicaLayer(TextureMapperLayer*);

Added: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp (0 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp	2015-12-07 17:15:56 UTC (rev 193630)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "TextureMapperPlatformLayerBuffer.h"
+
+namespace WebCore {
+
+TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(RefPtr<BitmapTexture>&& texture)
+    : m_texture(WTF::move(texture))
+    , m_textureID(0)
+    , m_extraFlags(0)
+    , m_hasManagedTexture(true)
+{
+}
+
+TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(GLuint textureID, const IntSize& size, TextureMapperGL::Flags flags)
+    : m_textureID(textureID)
+    , m_size(size)
+    , m_extraFlags(flags)
+    , m_hasManagedTexture(false)
+{
+}
+
+bool TextureMapperPlatformLayerBuffer::canReuseWithoutReset(const IntSize& size, GC3Dint internalFormat)
+{
+    return m_texture && (m_texture->size() == size) && (static_cast<BitmapTextureGL*>(m_texture.get())->internalFormat() == internalFormat || internalFormat == GraphicsContext3D::DONT_CARE);
+}
+
+void TextureMapperPlatformLayerBuffer::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity)
+{
+    if (m_hasManagedTexture) {
+        ASSERT(m_texture);
+        textureMapper->drawTexture(*m_texture, targetRect, modelViewMatrix, opacity);
+        return;
+    }
+
+    ASSERT(m_textureID);
+    TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
+    texmapGL->drawTexture(m_textureID, m_extraFlags, m_size, targetRect, modelViewMatrix, opacity);
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h (0 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 TextureMapperPlatformLayerBuffer_h
+#define TextureMapperPlatformLayerBuffer_h
+
+#include "BitmapTextureGL.h"
+#include "GraphicsTypes3D.h"
+#include "TextureMapperPlatformLayer.h"
+#include <wtf/CurrentTime.h>
+
+namespace WebCore {
+
+class TextureMapperPlatformLayerBuffer : public TextureMapperPlatformLayer {
+    WTF_MAKE_NONCOPYABLE(TextureMapperPlatformLayerBuffer);
+    WTF_MAKE_FAST_ALLOCATED();
+public:
+    TextureMapperPlatformLayerBuffer(RefPtr<BitmapTexture>&&);
+    TextureMapperPlatformLayerBuffer(GLuint textureID, const IntSize&, TextureMapperGL::Flags);
+
+    virtual ~TextureMapperPlatformLayerBuffer() = default;
+
+    virtual void paintToTextureMapper(TextureMapper*, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0) final;
+
+    bool canReuseWithoutReset(const IntSize&, GC3Dint internalFormat);
+    BitmapTextureGL& textureGL() { return static_cast<BitmapTextureGL&>(*m_texture); }
+
+    inline void markUsed() { m_timeLastUsed = monotonicallyIncreasingTime(); }
+    double lastUsedTime() const { return m_timeLastUsed; }
+
+    class UnmanagedBufferDataHolder {
+        WTF_MAKE_NONCOPYABLE(UnmanagedBufferDataHolder);
+        WTF_MAKE_FAST_ALLOCATED();
+    public:
+        UnmanagedBufferDataHolder() = default;
+        virtual ~UnmanagedBufferDataHolder() = default;
+    };
+
+    bool hasManagedTexture() const { return m_hasManagedTexture; }
+    void setUnmanagedBufferDataHolder(std::unique_ptr<UnmanagedBufferDataHolder> holder) { m_unmanagedBufferDataHolder = WTF::move(holder); }
+
+private:
+
+    RefPtr<BitmapTexture> m_texture;
+    double m_timeLastUsed { 0 };
+
+    GLuint m_textureID;
+    IntSize m_size;
+    TextureMapperGL::Flags m_extraFlags;
+    bool m_hasManagedTexture;
+    std::unique_ptr<UnmanagedBufferDataHolder> m_unmanagedBufferDataHolder;
+};
+
+} // namespace WebCore
+
+#endif // TextureMapperPlatformLayerBuffer_h

Added: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp (0 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp	2015-12-07 17:15:56 UTC (rev 193630)
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "TextureMapperPlatformLayerProxy.h"
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+
+#include "BitmapTextureGL.h"
+#include "TextureMapperGL.h"
+#include "TextureMapperLayer.h"
+#include "TextureMapperPlatformLayerBuffer.h"
+
+const double s_releaseUnusedSecondsTolerance = 1;
+const double s_releaseUnusedBuffersTimerInterval = 0.5;
+
+namespace WebCore {
+
+TextureMapperPlatformLayerProxy::TextureMapperPlatformLayerProxy()
+    : m_compositor(nullptr)
+    , m_targetLayer(nullptr)
+    , m_releaseUnusedBuffersTimer(RunLoop::current(), this, &TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired)
+{
+}
+
+TextureMapperPlatformLayerProxy::~TextureMapperPlatformLayerProxy()
+{
+    LockHolder locker(m_lock);
+    if (m_targetLayer)
+        m_targetLayer->setContentsLayer(nullptr);
+}
+
+void TextureMapperPlatformLayerProxy::activateOnCompositingThread(Compositor* compositor, TextureMapperLayer* targetLayer)
+{
+#ifndef NDEBUG
+    m_compositorThreadID = m_compositorThreadID ? m_compositorThreadID : WTF::currentThread();
+#endif
+    ASSERT(m_compositorThreadID == WTF::currentThread());
+    ASSERT(compositor);
+    ASSERT(targetLayer);
+    LockHolder locker(m_lock);
+    m_compositor = compositor;
+    m_targetLayer = targetLayer;
+}
+
+void TextureMapperPlatformLayerProxy::invalidate()
+{
+    ASSERT(m_compositorThreadID == WTF::currentThread());
+    LockHolder locker(m_lock);
+    m_compositor = nullptr;
+    m_targetLayer = nullptr;
+}
+
+bool TextureMapperPlatformLayerProxy::isActive()
+{
+    ASSERT(m_lock.isHeld());
+    return !!m_targetLayer && !!m_compositor;
+}
+
+void TextureMapperPlatformLayerProxy::pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer> newBuffer)
+{
+    ASSERT(m_lock.isHeld());
+    m_pendingBuffer = WTF::move(newBuffer);
+
+    if (m_compositor)
+        m_compositor->onNewBufferAvailable();
+}
+
+std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerProxy::getAvailableBuffer(const IntSize& size, GC3Dint internalFormat)
+{
+    ASSERT(m_lock.isHeld());
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> availableBuffer;
+
+    auto buffers = WTF::move(m_usedBuffers);
+    for (auto& buffer : buffers) {
+        if (!buffer)
+            continue;
+
+        if (!availableBuffer && buffer->canReuseWithoutReset(size, internalFormat)) {
+            availableBuffer = WTF::move(buffer);
+            availableBuffer->markUsed();
+            continue;
+        }
+        m_usedBuffers.append(WTF::move(buffer));
+    }
+
+    if (!m_usedBuffers.isEmpty())
+        scheduleReleaseUnusedBuffers();
+    return availableBuffer;
+}
+
+void TextureMapperPlatformLayerProxy::scheduleReleaseUnusedBuffers()
+{
+    if (!m_releaseUnusedBuffersTimer.isActive())
+        m_releaseUnusedBuffersTimer.startOneShot(s_releaseUnusedBuffersTimerInterval);
+}
+
+void TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired()
+{
+    LockHolder locker(m_lock);
+    if (m_usedBuffers.isEmpty())
+        return;
+
+    auto buffers = WTF::move(m_usedBuffers);
+    double minUsedTime = monotonicallyIncreasingTime() - s_releaseUnusedSecondsTolerance;
+
+    for (auto& buffer : buffers) {
+        if (buffer && buffer->lastUsedTime() >= minUsedTime)
+            m_usedBuffers.append(WTF::move(buffer));
+    }
+}
+
+void TextureMapperPlatformLayerProxy::swapBuffer()
+{
+    ASSERT(m_compositorThreadID == WTF::currentThread());
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> prevBuffer;
+
+    {
+        LockHolder locker(m_lock);
+        if (!m_targetLayer || !m_pendingBuffer)
+            return;
+
+        prevBuffer = WTF::move(m_currentBuffer);
+
+        m_currentBuffer = WTF::move(m_pendingBuffer);
+        m_targetLayer->setContentsLayer(m_currentBuffer.get());
+    }
+
+    if (prevBuffer && prevBuffer->hasManagedTexture())
+        m_usedBuffers.append(WTF::move(prevBuffer));
+}
+
+} // namespace WebCore
+
+#endif // USE(COORDINATED_GRAPHICS_THREADED)

Added: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h (0 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 TextureMapperPlatformLayerProxy_h
+#define TextureMapperPlatformLayerProxy_h
+
+#include "GraphicsTypes3D.h"
+#include "TextureMapper.h"
+#include "TransformationMatrix.h"
+#include <wtf/Condition.h>
+#include <wtf/Lock.h>
+#include <wtf/RunLoop.h>
+#include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/Vector.h>
+
+#ifndef NDEBUG
+#include <wtf/Threading.h>
+#endif
+
+namespace WebCore {
+
+class TextureMapperLayer;
+class TextureMapperPlatformLayerProxy;
+class TextureMapperPlatformLayerBuffer;
+
+class TextureMapperPlatformLayerProxyProvider {
+public:
+    virtual RefPtr<TextureMapperPlatformLayerProxy> proxy() const = 0;
+    virtual void swapBuffersIfNeeded() = 0;
+};
+
+class TextureMapperPlatformLayerProxy : public ThreadSafeRefCounted<TextureMapperPlatformLayerProxy> {
+    WTF_MAKE_FAST_ALLOCATED();
+public:
+    class Compositor {
+    public:
+        virtual void onNewBufferAvailable() = 0;
+    };
+
+    TextureMapperPlatformLayerProxy();
+    virtual ~TextureMapperPlatformLayerProxy();
+
+    // To avoid multiple lock/release situation to update a single frame,
+    // the implementation of TextureMapperPlatformLayerProxyProvider should
+    // aquire / release the lock explicitly to use below methods.
+    Lock& lock() { return m_lock; }
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> getAvailableBuffer(const IntSize&, GC3Dint internalFormat);
+    void pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>);
+    bool isActive();
+
+    void activateOnCompositingThread(Compositor*, TextureMapperLayer*);
+    void invalidate();
+
+    void swapBuffer();
+
+private:
+    void scheduleReleaseUnusedBuffers();
+    void releaseUnusedBuffersTimerFired();
+
+    Compositor* m_compositor;
+    TextureMapperLayer* m_targetLayer;
+
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> m_currentBuffer;
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> m_pendingBuffer;
+
+    Lock m_lock;
+
+    Vector<std::unique_ptr<TextureMapperPlatformLayerBuffer>> m_usedBuffers;
+
+    RunLoop::Timer<TextureMapperPlatformLayerProxy> m_releaseUnusedBuffersTimer;
+#ifndef NDEBUG
+    ThreadIdentifier m_compositorThreadID { 0 };
+#endif
+};
+
+} // namespace WebCore
+
+#endif // TextureMapperPlatformLayerProxy_h

Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp	2015-12-07 17:15:56 UTC (rev 193630)
@@ -30,9 +30,9 @@
 #include "FrameView.h"
 #include "GraphicsContext.h"
 #include "GraphicsLayer.h"
+#include "GraphicsLayerFactory.h"
 #include "Page.h"
 #include "ScrollableArea.h"
-#include "TextureMapperPlatformLayer.h"
 #include <wtf/CurrentTime.h>
 #include <wtf/HashMap.h>
 #ifndef NDEBUG
@@ -42,6 +42,14 @@
 
 namespace WebCore {
 
+std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
+{
+    if (!factory)
+        return std::make_unique<CoordinatedGraphicsLayer>(layerType, client);
+
+    return factory->createGraphicsLayer(layerType, client);
+}
+
 static CoordinatedLayerID toCoordinatedLayerID(GraphicsLayer* layer)
 {
     return layer ? toCoordinatedGraphicsLayer(layer)->id() : 0;
@@ -121,6 +129,9 @@
     , m_isValidPlatformLayer(false)
     , m_pendingPlatformLayerOperation(None)
 #endif
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    , m_shouldSyncPlatformLayer(false)
+#endif
     , m_coordinator(0)
     , m_compositedNativeImagePtr(0)
     , m_platformLayer(0)
@@ -406,6 +417,12 @@
     ASSERT(!(!m_platformLayerToken.isValid() && m_platformLayer));
 
     notifyFlushRequired();
+#elif USE(COORDINATED_GRAPHICS_THREADED)
+    if (m_platformLayer != platformLayer)
+        m_shouldSyncPlatformLayer = true;
+
+    m_platformLayer = platformLayer;
+    notifyFlushRequired();
 #else
     UNUSED_PARAM(platformLayer);
 #endif
@@ -694,9 +711,9 @@
     m_layerState.animationsChanged = true;
 }
 
-#if USE(GRAPHICS_SURFACE)
 void CoordinatedGraphicsLayer::syncPlatformLayer()
 {
+#if USE(GRAPHICS_SURFACE)
     destroyPlatformLayerIfNeeded();
     createPlatformLayerIfNeeded();
 
@@ -711,8 +728,20 @@
     ASSERT(m_platformLayer);
     m_layerState.platformLayerFrontBuffer = m_platformLayer->copyToGraphicsSurface();
     m_layerState.platformLayerShouldSwapBuffers = true;
+#elif USE(COORDINATED_GRAPHICS_THREADED)
+    if (!m_shouldSyncPlatformLayer)
+        return;
+
+    m_shouldSyncPlatformLayer = false;
+    m_layerState.platformLayerChanged = true;
+    if (m_platformLayer) {
+        m_platformLayer->swapBuffersIfNeeded();
+        m_layerState.platformLayerProxy = m_platformLayer->proxy();
+    }
+#endif
 }
 
+#if USE(GRAPHICS_SURFACE)
 void CoordinatedGraphicsLayer::destroyPlatformLayerIfNeeded()
 {
     if (!(m_pendingPlatformLayerOperation & DestroyPlatformLayer))
@@ -763,9 +792,7 @@
     computeTransformedVisibleRect();
     syncChildren();
     syncFilters();
-#if USE(GRAPHICS_SURFACE)
     syncPlatformLayer();
-#endif
 
     // Only unset m_movingVisibleRect after we have updated the visible rect after the animation stopped.
     if (!hasActiveTransformAnimation)
@@ -1189,5 +1216,17 @@
 {
     client().notifyAnimationStarted(this, "", m_lastAnimationStartTime);
 }
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+void CoordinatedGraphicsLayer::platformLayerWillBeDestroyed()
+{
+}
+
+void CoordinatedGraphicsLayer::setPlatformLayerNeedsDisplay()
+{
+}
+#endif
+
 } // namespace WebCore
+
 #endif // USE(COORDINATED_GRAPHICS)

Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -29,6 +29,7 @@
 #include "Image.h"
 #include "IntSize.h"
 #include "TextureMapperAnimation.h"
+#include "TextureMapperPlatformLayer.h"
 #include "TiledBackingStore.h"
 #include "TiledBackingStoreClient.h"
 #include "TransformationMatrix.h"
@@ -57,6 +58,9 @@
 
 class CoordinatedGraphicsLayer : public GraphicsLayer
     , public TiledBackingStoreClient
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    , public TextureMapperPlatformLayer::Client
+#endif
     , public CoordinatedImageBacking::Host {
 public:
     explicit CoordinatedGraphicsLayer(Type, GraphicsLayerClient&);
@@ -155,10 +159,14 @@
         RecreatePlatformLayer = CreateAndSyncPlatformLayer | DestroyPlatformLayer
     };
 
-    void syncPlatformLayer();
     void destroyPlatformLayerIfNeeded();
     void createPlatformLayerIfNeeded();
 #endif
+    void syncPlatformLayer();
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    void platformLayerWillBeDestroyed();
+    void setPlatformLayerNeedsDisplay();
+#endif
 
     virtual void setDebugBorder(const Color&, float width) override;
 
@@ -223,6 +231,9 @@
     bool m_isValidPlatformLayer : 1;
     unsigned m_pendingPlatformLayerOperation : 3;
 #endif
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    bool m_shouldSyncPlatformLayer : 1;
+#endif
 
     CoordinatedGraphicsLayerClient* m_coordinator;
     std::unique_ptr<TiledBackingStore> m_mainBackingStore;

Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsState.h (193629 => 193630)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsState.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsState.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -44,6 +44,10 @@
 #include "GraphicsSurfaceToken.h"
 #endif
 
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include "TextureMapperPlatformLayerProxy.h"
+#endif
+
 namespace WebCore {
 
 class CoordinatedSurface;
@@ -130,6 +134,9 @@
 #if USE(GRAPHICS_SURFACE)
         , platformLayerFrontBuffer(0)
 #endif
+#if USE(COORDINATED_GRAPHICS_THREADED)
+        , platformLayerProxy(0)
+#endif
     {
     }
 
@@ -164,6 +171,10 @@
     GraphicsSurface::Flags platformLayerSurfaceFlags;
 #endif
 
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    RefPtr<TextureMapperPlatformLayerProxy> platformLayerProxy;
+#endif
+
     IntSize committedScrollOffset;
 
     bool hasPendingChanges() const

Modified: trunk/Source/WebKit2/ChangeLog (193629 => 193630)


--- trunk/Source/WebKit2/ChangeLog	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebKit2/ChangeLog	2015-12-07 17:15:56 UTC (rev 193630)
@@ -1,3 +1,21 @@
+2015-12-07  Gwang Yoon Hwang  <y...@igalia.com>
+
+        [ThreadedCompositor] Add support for PlatformLayer.
+        https://bugs.webkit.org/show_bug.cgi?id=143299
+
+        Reviewed by Žan Doberšek.
+
+        * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
+        (WebKit::CoordinatedGraphicsScene::paintToCurrentGLContext):
+        Swap pending buffers of TextureMapperPlatformLayerProxies before painting contents.
+        (WebKit::CoordinatedGraphicsScene::syncPlatformLayerIfNeeded):
+        In threaded compositor, CoordinatedGraphicsScence only cares about creation and deletion
+        of platform layers.
+
+        (WebKit::CoordinatedGraphicsScene::onNewBufferAvailable):
+        Whenever new buffer comes via TextureMapperPlatformLayerProxy, CoordinatedGraphicsScene will
+        update the scene if it is needed.
+
 2015-12-07  Mario Sanchez Prada  <ma...@endlessm.com>
 
         [GTK] Allow applications to force Accelerated Compositing mode

Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp (193629 => 193630)


--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp	2015-12-07 17:15:56 UTC (rev 193630)
@@ -83,6 +83,11 @@
     if (!currentRootLayer)
         return;
 
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    for (auto& proxy : m_platformLayerProxies.values())
+        proxy->swapBuffer();
+#endif
+
     currentRootLayer->setTextureMapper(m_textureMapper.get());
     currentRootLayer->applyAnimationsRecursively();
     m_textureMapper->beginPainting(PaintFlags);
@@ -164,20 +169,9 @@
         fixedLayer->setScrollPositionDeltaIfNeeded(delta);
 }
 
-#if USE(GRAPHICS_SURFACE)
-void CoordinatedGraphicsScene::createPlatformLayerIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
-{
-    if (!state.platformLayerToken.isValid())
-        return;
-
-    RefPtr<TextureMapperSurfaceBackingStore> platformLayerBackingStore(TextureMapperSurfaceBackingStore::create());
-    m_surfaceBackingStores.set(layer, platformLayerBackingStore);
-    platformLayerBackingStore->setGraphicsSurface(GraphicsSurface::create(state.platformLayerSize, state.platformLayerSurfaceFlags, state.platformLayerToken));
-    layer->setContentsLayer(platformLayerBackingStore.get());
-}
-
 void CoordinatedGraphicsScene::syncPlatformLayerIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
 {
+#if USE(GRAPHICS_SURFACE)
     ASSERT(m_textureMapper);
 
     if (state.platformLayerChanged) {
@@ -191,8 +185,43 @@
         RefPtr<TextureMapperSurfaceBackingStore> platformLayerBackingStore = it->value;
         platformLayerBackingStore->swapBuffersIfNeeded(state.platformLayerFrontBuffer);
     }
+#elif USE(COORDINATED_GRAPHICS_THREADED)
+    if (!state.platformLayerChanged)
+        return;
+
+    if (state.platformLayerProxy) {
+        m_platformLayerProxies.set(layer, state.platformLayerProxy);
+        state.platformLayerProxy->activateOnCompositingThread(this, layer);
+    } else
+        m_platformLayerProxies.remove(layer);
+#else
+    UNUSED_PARAM(layer);
+    UNUSED_PARAM(state);
+#endif
 }
 
+#if USE(COORDINATED_GRAPHICS_THREADED)
+void CoordinatedGraphicsScene::onNewBufferAvailable()
+{
+    RefPtr<CoordinatedGraphicsScene> protector(this);
+    dispatchOnClientRunLoop([=] {
+        protector->updateViewport();
+    });
+}
+#endif
+
+#if USE(GRAPHICS_SURFACE)
+void CoordinatedGraphicsScene::createPlatformLayerIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
+{
+    if (!state.platformLayerToken.isValid())
+        return;
+
+    RefPtr<TextureMapperSurfaceBackingStore> platformLayerBackingStore(TextureMapperSurfaceBackingStore::create());
+    m_surfaceBackingStores.set(layer, platformLayerBackingStore);
+    platformLayerBackingStore->setGraphicsSurface(GraphicsSurface::create(state.platformLayerSize, state.platformLayerSurfaceFlags, state.platformLayerToken));
+    layer->setContentsLayer(platformLayerBackingStore.get());
+}
+
 void CoordinatedGraphicsScene::destroyPlatformLayerIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
 {
     if (state.platformLayerToken.isValid())
@@ -313,9 +342,7 @@
     updateTilesIfNeeded(layer, layerState);
     setLayerFiltersIfNeeded(layer, layerState);
     setLayerAnimationsIfNeeded(layer, layerState);
-#if USE(GRAPHICS_SURFACE)
     syncPlatformLayerIfNeeded(layer, layerState);
-#endif
     setLayerRepaintCountIfNeeded(layer, layerState);
 }
 
@@ -354,6 +381,10 @@
 #if USE(GRAPHICS_SURFACE)
     m_surfaceBackingStores.remove(layer.get());
 #endif
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    if (auto platformLayerProxy = m_platformLayerProxies.take(layer.get()))
+        platformLayerProxy->invalidate();
+#endif
 }
 
 void CoordinatedGraphicsScene::setRootLayerID(CoordinatedLayerID layerID)
@@ -632,6 +663,9 @@
 #if USE(GRAPHICS_SURFACE)
     m_surfaceBackingStores.clear();
 #endif
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    m_platformLayerProxies.clear();
+#endif
     m_surfaces.clear();
 
     m_rootLayer = nullptr;

Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h (193629 => 193630)


--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h	2015-12-07 17:12:18 UTC (rev 193629)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h	2015-12-07 17:15:56 UTC (rev 193630)
@@ -45,6 +45,10 @@
 #include <WebCore/TextureMapperSurfaceBackingStore.h>
 #endif
 
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include <WebCore/TextureMapperPlatformLayerProxy.h>
+#endif
+
 namespace WebKit {
 
 class CoordinatedBackingStore;
@@ -58,7 +62,11 @@
     virtual void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) = 0;
 };
 
-class CoordinatedGraphicsScene : public ThreadSafeRefCounted<CoordinatedGraphicsScene>, public WebCore::TextureMapperLayer::ScrollingClient {
+class CoordinatedGraphicsScene : public ThreadSafeRefCounted<CoordinatedGraphicsScene>, public WebCore::TextureMapperLayer::ScrollingClient
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    , public WebCore::TextureMapperPlatformLayerProxy::Compositor
+#endif
+{
 public:
     explicit CoordinatedGraphicsScene(CoordinatedGraphicsSceneClient*);
     virtual ~CoordinatedGraphicsScene();
@@ -94,9 +102,9 @@
     void removeTilesIfNeeded(WebCore::TextureMapperLayer*, const WebCore::CoordinatedGraphicsLayerState&);
     void setLayerFiltersIfNeeded(WebCore::TextureMapperLayer*, const WebCore::CoordinatedGraphicsLayerState&);
     void setLayerAnimationsIfNeeded(WebCore::TextureMapperLayer*, const WebCore::CoordinatedGraphicsLayerState&);
+    void syncPlatformLayerIfNeeded(WebCore::TextureMapperLayer*, const WebCore::CoordinatedGraphicsLayerState&);
 #if USE(GRAPHICS_SURFACE)
     void createPlatformLayerIfNeeded(WebCore::TextureMapperLayer*, const WebCore::CoordinatedGraphicsLayerState&);
-    void syncPlatformLayerIfNeeded(WebCore::TextureMapperLayer*, const WebCore::CoordinatedGraphicsLayerState&);
     void destroyPlatformLayerIfNeeded(WebCore::TextureMapperLayer*, const WebCore::CoordinatedGraphicsLayerState&);
 #endif
     void setLayerRepaintCountIfNeeded(WebCore::TextureMapperLayer*, const WebCore::CoordinatedGraphicsLayerState&);
@@ -144,6 +152,10 @@
 
     void dispatchCommitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
 
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    virtual void onNewBufferAvailable() override;
+#endif
+
     // Render queue can be accessed ony from main thread or updatePaintNode call stack!
     Vector<std::function<void()>> m_renderQueue;
     Lock m_renderQueueMutex;
@@ -164,6 +176,11 @@
     SurfaceBackingStoreMap m_surfaceBackingStores;
 #endif
 
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    typedef HashMap<WebCore::TextureMapperLayer*, RefPtr<WebCore::TextureMapperPlatformLayerProxy>> PlatformLayerProxyMap;
+    PlatformLayerProxyMap m_platformLayerProxies;
+#endif
+
     typedef HashMap<uint32_t /* atlasID */, RefPtr<WebCore::CoordinatedSurface>> SurfaceMap;
     SurfaceMap m_surfaces;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to