[WinCairo] Accelerated compositing is not implemented.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Oct 2014 19:50:09 +0000 (19:50 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Oct 2014 19:50:09 +0000 (19:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137345

Patch by peavo@outlook.com <peavo@outlook.com> on 2014-10-17
Reviewed by Brent Fulgham.

This patch is based on GTK, and the texture mapper graphics layer type.

Source/WebCore:

* WebCore.vcxproj/copyForwardingHeaders.cmd: Copy texmap headers.
* platform/graphics/texmap/GraphicsLayerTextureMapper.cpp: Added method and flag indicating whether animation has started.
(WebCore::GraphicsLayerTextureMapper::GraphicsLayerTextureMapper):
(WebCore::GraphicsLayerTextureMapper::addAnimation):
* platform/graphics/texmap/GraphicsLayerTextureMapper.h: Ditto.
(WebCore::GraphicsLayerTextureMapper::startedAnimation):
* platform/graphics/texmap/TextureMapperShaderProgram.cpp: Use same precision for uniform in vertex shader as in fragment shader.
Otherwise glLinkProgram() will fail, and nothing will be rendered.

Source/WebKit:

* WebKit.vcxproj/WebKit/WebKit.vcxproj: Added new accelerated compositing source files.
* WebKit.vcxproj/WebKit/WebKit.vcxproj.filters: Ditto.

Source/WebKit/win:

* WebCoreSupport/AcceleratedCompositingContext.cpp: Added.
(WebKit::AcceleratedCompositingContext::AcceleratedCompositingContext):
(WebKit::getWebViewSize):
(WebKit::AcceleratedCompositingContext::initialize):
(WebKit::AcceleratedCompositingContext::~AcceleratedCompositingContext):
(WebKit::AcceleratedCompositingContext::stopAnyPendingLayerFlush):
(WebKit::AcceleratedCompositingContext::enabled):
(WebKit::AcceleratedCompositingContext::prepareForRendering):
(WebKit::AcceleratedCompositingContext::startedAnimation):
(WebKit::AcceleratedCompositingContext::compositeLayersToContext):
(WebKit::AcceleratedCompositingContext::setRootCompositingLayer):
(WebKit::AcceleratedCompositingContext::setNonCompositedContentsNeedDisplay):
(WebKit::AcceleratedCompositingContext::setNeedsDisplayInRect):
(WebKit::AcceleratedCompositingContext::resizeRootLayer):
(WebKit::AcceleratedCompositingContext::scrollNonCompositedContents):
(WebKit::AcceleratedCompositingContext::scheduleLayerFlush):
(WebKit::AcceleratedCompositingContext::flushPendingLayerChanges):
(WebKit::AcceleratedCompositingContext::flushPendingLayerChangesSoon):
(WebKit::AcceleratedCompositingContext::flushAndRenderLayers):
(WebKit::AcceleratedCompositingContext::layerFlushTimerFired):
(WebKit::AcceleratedCompositingContext::notifyAnimationStarted):
(WebKit::AcceleratedCompositingContext::notifyFlushRequired):
(WebKit::AcceleratedCompositingContext::paintContents):
* WebCoreSupport/AcceleratedCompositingContext.h: Added.
(WebKit::AcceleratedCompositingContext::LayerFlushTimer::LayerFlushTimer):
(WebKit::AcceleratedCompositingContext::LayerFlushTimer::fired):
* WebView.cpp:
(WebView::WebView):
(WebView::addToDirtyRegion):
(WebView::scrollBackingStore):
(WebView::sizeChanged):
(WebView::paint):
(WebView::setRootChildLayer):
(WebView::flushPendingGraphicsLayerChangesSoon):
(WebView::setAcceleratedCompositing):
* WebView.h:

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.vcxproj/copyForwardingHeaders.cmd
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h
Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebKit.vcxproj/WebKit/WebKit.vcxproj
Source/WebKit/WebKit.vcxproj/WebKit/WebKit.vcxproj.filters
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/AcceleratedCompositingContext.cpp [new file with mode: 0644]
Source/WebKit/win/WebCoreSupport/AcceleratedCompositingContext.h [new file with mode: 0644]
Source/WebKit/win/WebView.cpp
Source/WebKit/win/WebView.h

index 13495a1..ef7542f 100644 (file)
@@ -1,3 +1,21 @@
+2014-10-17  peavo@outlook.com  <peavo@outlook.com>
+
+        [WinCairo] Accelerated compositing is not implemented.
+        https://bugs.webkit.org/show_bug.cgi?id=137345
+
+        Reviewed by Brent Fulgham.
+
+        This patch is based on GTK, and the texture mapper graphics layer type.
+
+        * WebCore.vcxproj/copyForwardingHeaders.cmd: Copy texmap headers.
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp: Added method and flag indicating whether animation has started.
+        (WebCore::GraphicsLayerTextureMapper::GraphicsLayerTextureMapper):
+        (WebCore::GraphicsLayerTextureMapper::addAnimation):
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.h: Ditto.
+        (WebCore::GraphicsLayerTextureMapper::startedAnimation):
+        * platform/graphics/texmap/TextureMapperShaderProgram.cpp: Use same precision for uniform in vertex shader as in fragment shader.
+        Otherwise glLinkProgram() will fail, and nothing will be rendered.
+
 2014-10-17  Alexey Proskuryakov  <ap@apple.com>
 
         [iOS] Crash when load is canceled while waiting for the user to type HTTP authentication credentials
index fbf69f1..6d7e9d0 100644 (file)
@@ -58,6 +58,8 @@ xcopy /y /d "%ProjectDir%..\platform\graphics\gstreamer\*.h" "%CONFIGURATIONBUIL
 xcopy /y /d "%ProjectDir%..\platform\graphics\win\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\graphics\win\%1\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\graphics\opentype\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
+xcopy /y /d "%ProjectDir%..\platform\graphics\opengl\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
+xcopy /y /d "%ProjectDir%..\platform\graphics\texmap\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\mock\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\text\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\text\icu\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
index 4b801e8..cee5d26 100644 (file)
@@ -54,6 +54,7 @@ GraphicsLayerTextureMapper::GraphicsLayerTextureMapper(GraphicsLayerClient& clie
     , m_contentsLayer(0)
     , m_animationStartTime(0)
     , m_isScrollable(false)
+    , m_startedAnimation(false)
 {
 }
 
@@ -591,6 +592,7 @@ bool GraphicsLayerTextureMapper::addAnimation(const KeyframeValueList& valueList
         m_animationStartTime = currentTime - timeOffset;
     notifyChange(AnimationChange);
     notifyChange(AnimationStarted);
+    m_startedAnimation = true;
     return true;
 }
 
index 7a82b7d..900f920 100644 (file)
@@ -100,6 +100,8 @@ public:
     float debugBorderWidth() const { return m_debugBorderWidth; }
     void setRepaintCount(int);
 
+    bool startedAnimation() const { return m_startedAnimation; }
+
 private:
     virtual void willBeDestroyed();
 
@@ -177,6 +179,7 @@ private:
 
     IntSize m_committedScrollOffset;
     bool m_isScrollable;
+    bool m_startedAnimation;
 };
 
 inline static GraphicsLayerTextureMapper* toGraphicsLayerTextureMapper(GraphicsLayer* layer)
index 7247502..58bc651 100644 (file)
@@ -208,6 +208,8 @@ static const char* fragmentTemplate =
     ANTIALIASING_TEX_COORD_DIRECTIVE
     BLUR_CONSTANTS
     STRINGIFY(
+        precision highp float;
+        uniform mat4 u_textureSpaceMatrix;
         precision mediump float;
         uniform SamplerType s_sampler;
         uniform sampler2D s_contentTexture;
@@ -220,7 +222,6 @@ static const char* fragmentTemplate =
         uniform vec2 u_shadowOffset;
         uniform vec4 u_color;
         uniform float u_gaussianKernel[GAUSSIAN_KERNEL_HALF_WIDTH];
-        uniform mat4 u_textureSpaceMatrix;
 
         void noop(inout vec4 dummyParameter) { }
         void noop(inout vec4 dummyParameter, vec2 texCoord) { }
index e6b99df..748e13e 100644 (file)
@@ -1,3 +1,15 @@
+2014-10-17  peavo@outlook.com  <peavo@outlook.com>
+
+        [WinCairo] Accelerated compositing is not implemented.
+        https://bugs.webkit.org/show_bug.cgi?id=137345
+
+        Reviewed by Brent Fulgham.
+
+        This patch is based on GTK, and the texture mapper graphics layer type.
+
+        * WebKit.vcxproj/WebKit/WebKit.vcxproj: Added new accelerated compositing source files.
+        * WebKit.vcxproj/WebKit/WebKit.vcxproj.filters: Ditto.
+
 2014-10-16  Tim Horton  <timothy_horton@apple.com>
 
         Implement selection services menu for Legacy WebKit
index b71c983..be61ed3 100644 (file)
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
     </ClCompile>
     <ClCompile Include="..\..\win\WebCoreStatistics.cpp" />
+    <ClCompile Include="..\..\win\WebCoreSupport\AcceleratedCompositingContext.cpp" />
     <ClCompile Include="..\..\win\WebCoreSupport\EmbeddedWidget.cpp" />
     <ClCompile Include="..\..\win\WebCoreSupport\WebChromeClient.cpp" />
     <ClCompile Include="..\..\win\WebCoreSupport\WebContextMenuClient.cpp" />
     <ClInclude Include="..\..\win\WebCachedFramePlatformData.h" />
     <ClInclude Include="..\..\win\WebCookieManager.h" />
     <ClInclude Include="..\..\win\WebCoreStatistics.h" />
+    <ClInclude Include="..\..\win\WebCoreSupport\AcceleratedCompositingContext.h" />
     <ClInclude Include="..\..\win\WebCoreSupport\EmbeddedWidget.h" />
     <ClInclude Include="..\..\win\WebCoreSupport\WebChromeClient.h" />
     <ClInclude Include="..\..\win\WebCoreSupport\WebContextMenuClient.h" />
index 83963f2..f9257b6 100644 (file)
     <ClCompile Include="..\..\win\AccessibleTextImpl.cpp">
       <Filter>Sources</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\win\WebCoreSupport\AcceleratedCompositingContext.cpp">
+      <Filter>WebCoreSupport</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\win\WebCoreSupport\EmbeddedWidget.h">
     <ClInclude Include="..\..\win\AccessibleTextImpl.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\win\WebCoreSupport\AcceleratedCompositingContext.h">
+      <Filter>WebCoreSupport</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="WebKitPostBuild.cmd" />
index 3e1c870..95bd21c 100644 (file)
@@ -1,3 +1,49 @@
+2014-10-17  peavo@outlook.com  <peavo@outlook.com>
+
+        [WinCairo] Accelerated compositing is not implemented.
+        https://bugs.webkit.org/show_bug.cgi?id=137345
+
+        Reviewed by Brent Fulgham.
+
+        This patch is based on GTK, and the texture mapper graphics layer type.
+
+        * WebCoreSupport/AcceleratedCompositingContext.cpp: Added.
+        (WebKit::AcceleratedCompositingContext::AcceleratedCompositingContext):
+        (WebKit::getWebViewSize):
+        (WebKit::AcceleratedCompositingContext::initialize):
+        (WebKit::AcceleratedCompositingContext::~AcceleratedCompositingContext):
+        (WebKit::AcceleratedCompositingContext::stopAnyPendingLayerFlush):
+        (WebKit::AcceleratedCompositingContext::enabled):
+        (WebKit::AcceleratedCompositingContext::prepareForRendering):
+        (WebKit::AcceleratedCompositingContext::startedAnimation):
+        (WebKit::AcceleratedCompositingContext::compositeLayersToContext):
+        (WebKit::AcceleratedCompositingContext::setRootCompositingLayer):
+        (WebKit::AcceleratedCompositingContext::setNonCompositedContentsNeedDisplay):
+        (WebKit::AcceleratedCompositingContext::setNeedsDisplayInRect):
+        (WebKit::AcceleratedCompositingContext::resizeRootLayer):
+        (WebKit::AcceleratedCompositingContext::scrollNonCompositedContents):
+        (WebKit::AcceleratedCompositingContext::scheduleLayerFlush):
+        (WebKit::AcceleratedCompositingContext::flushPendingLayerChanges):
+        (WebKit::AcceleratedCompositingContext::flushPendingLayerChangesSoon):
+        (WebKit::AcceleratedCompositingContext::flushAndRenderLayers):
+        (WebKit::AcceleratedCompositingContext::layerFlushTimerFired):
+        (WebKit::AcceleratedCompositingContext::notifyAnimationStarted):
+        (WebKit::AcceleratedCompositingContext::notifyFlushRequired):
+        (WebKit::AcceleratedCompositingContext::paintContents):
+        * WebCoreSupport/AcceleratedCompositingContext.h: Added.
+        (WebKit::AcceleratedCompositingContext::LayerFlushTimer::LayerFlushTimer):
+        (WebKit::AcceleratedCompositingContext::LayerFlushTimer::fired):
+        * WebView.cpp:
+        (WebView::WebView):
+        (WebView::addToDirtyRegion):
+        (WebView::scrollBackingStore):
+        (WebView::sizeChanged):
+        (WebView::paint):
+        (WebView::setRootChildLayer):
+        (WebView::flushPendingGraphicsLayerChangesSoon):
+        (WebView::setAcceleratedCompositing):
+        * WebView.h:
+
 2014-10-16  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r174754.
diff --git a/Source/WebKit/win/WebCoreSupport/AcceleratedCompositingContext.cpp b/Source/WebKit/win/WebCoreSupport/AcceleratedCompositingContext.cpp
new file mode 100644 (file)
index 0000000..81129ae
--- /dev/null
@@ -0,0 +1,328 @@
+/*
+ * Copyright (C) 2014 Apple, Inc.
+ *
+ * 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 "AcceleratedCompositingContext.h"
+
+#if USE(TEXTURE_MAPPER_GL)
+
+#include "WebView.h"
+
+#include <WebCore/Document.h>
+#include <WebCore/Frame.h>
+#include <WebCore/FrameView.h>
+#include <WebCore/GraphicsLayerTextureMapper.h>
+#include <WebCore/MainFrame.h>
+#include <WebCore/Page.h>
+#include <WebCore/Settings.h>
+#include <WebCore/TemporaryOpenGLSetting.h>
+#include <WebCore/TextureMapperGL.h>
+#include <WebCore/TextureMapperLayer.h>
+
+#if USE(OPENGL_ES_2)
+#include <GLES2/gl2.h>
+#else
+#include <GL/gl.h>
+#endif
+
+using namespace WebCore;
+
+AcceleratedCompositingContext::AcceleratedCompositingContext(WebView& webView)
+    : m_webView(webView)
+    , m_layerFlushTimer(*this)
+    , m_context(nullptr)
+    , m_window(0)
+{
+}
+
+static IntSize getWebViewSize(WebView& webView)
+{
+    RECT r;
+    webView.frameRect(&r);
+    return IntSize(r.right - r.left, r.bottom - r.top);
+}
+
+void AcceleratedCompositingContext::initialize()
+{
+    if (m_rootLayer)
+        return;
+
+    IntSize pageSize = getWebViewSize(m_webView);
+
+    m_window = m_webView.viewWindow();
+
+    if (!m_window)
+        return;
+
+    m_rootLayer = GraphicsLayer::create(nullptr, *this);
+    m_rootLayer->setDrawsContent(false);
+    m_rootLayer->setSize(pageSize);
+
+    // The non-composited contents are a child of the root layer.
+    m_nonCompositedContentLayer = GraphicsLayer::create(nullptr, *this);
+    m_nonCompositedContentLayer->setDrawsContent(true);
+    m_nonCompositedContentLayer->setContentsOpaque(!m_webView.transparent());
+    m_nonCompositedContentLayer->setSize(pageSize);
+    if (core(&m_webView)->settings().acceleratedDrawingEnabled())
+        m_nonCompositedContentLayer->setAcceleratesDrawing(true);
+
+#ifndef NDEBUG
+    m_rootLayer->setName("Root layer");
+    m_nonCompositedContentLayer->setName("Non-composited content");
+#endif
+
+    m_rootLayer->addChild(m_nonCompositedContentLayer.get());
+    m_nonCompositedContentLayer->setNeedsDisplay();
+
+    // The creation of the TextureMapper needs an active OpenGL context.
+    if (!m_context)
+        m_context = GLContext::createContextForWindow(m_window, GLContext::sharingContext());
+
+    m_context->makeContextCurrent();
+
+    m_textureMapper = TextureMapperGL::create(TextureMapper::OpenGLMode);
+    static_cast<TextureMapperGL*>(m_textureMapper.get())->setEnableEdgeDistanceAntialiasing(true);
+    toTextureMapperLayer(m_rootLayer.get())->setTextureMapper(m_textureMapper.get());
+
+    scheduleLayerFlush();
+}
+
+AcceleratedCompositingContext::~AcceleratedCompositingContext()
+{
+    stopAnyPendingLayerFlush();
+}
+
+void AcceleratedCompositingContext::stopAnyPendingLayerFlush()
+{
+    m_layerFlushTimer.stop();
+}
+
+bool AcceleratedCompositingContext::enabled()
+{
+    return m_window && m_rootLayer && m_textureMapper;
+}
+
+bool AcceleratedCompositingContext::prepareForRendering()
+{
+    if (!enabled())
+        return false;
+
+    if (!m_context)
+        return false;
+
+    if (!m_context->makeContextCurrent())
+        return false;
+
+    return true;
+}
+
+bool AcceleratedCompositingContext::startedAnimation(WebCore::GraphicsLayer* layer)
+{
+    if (!layer)
+        return false;
+
+    if (toGraphicsLayerTextureMapper(layer)->startedAnimation())
+        return true;
+
+    for (auto childLayer : layer->children()) {
+        if (startedAnimation(childLayer))
+            return true;
+    }
+
+    return false;
+}
+
+void AcceleratedCompositingContext::compositeLayersToContext(CompositePurpose purpose)
+{
+    if (!prepareForRendering())
+        return;
+
+    RECT r;
+    if (!::GetClientRect(m_window, &r))
+        return;
+    IntSize windowSize(r.right, r.bottom);
+    glViewport(0, 0, windowSize.width(), windowSize.height());
+
+    if (purpose == ForResize) {
+        TemporaryOpenGLSetting scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
+        glClearColor(1, 1, 1, 0);
+        glClear(GL_COLOR_BUFFER_BIT);
+    }
+
+    m_textureMapper->beginPainting();
+    toTextureMapperLayer(m_rootLayer.get())->paint();
+    m_fpsCounter.updateFPSAndDisplay(m_textureMapper.get());
+    m_textureMapper->endPainting();
+
+    m_context->swapBuffers();
+}
+
+void AcceleratedCompositingContext::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
+{
+    prepareForRendering();
+
+    if (!graphicsLayer) {
+        stopAnyPendingLayerFlush();
+        m_rootLayer = nullptr;
+        m_nonCompositedContentLayer = nullptr;
+        m_textureMapper = nullptr;
+        return;
+    }
+
+    // Add the accelerated layer tree hierarchy.
+    initialize();
+    if (!m_window)
+        return;
+
+    m_nonCompositedContentLayer->removeAllChildren();
+    m_nonCompositedContentLayer->addChild(graphicsLayer);
+
+    stopAnyPendingLayerFlush();
+
+    scheduleLayerFlush();
+}
+
+void AcceleratedCompositingContext::setNonCompositedContentsNeedDisplay(const IntRect& rect)
+{
+    if (!m_rootLayer)
+        return;
+    if (rect.isEmpty()) {
+        m_rootLayer->setNeedsDisplay();
+        return;
+    }
+    m_nonCompositedContentLayer->setNeedsDisplayInRect(rect);
+    scheduleLayerFlush();
+}
+
+void AcceleratedCompositingContext::setNeedsDisplayInRect(const IntRect& rect)
+{
+    if (!m_rootLayer)
+        return;
+    if (rect.isEmpty()) {
+        m_rootLayer->setNeedsDisplay();
+        return;
+    }
+    m_rootLayer->setNeedsDisplayInRect(rect);
+    scheduleLayerFlush();
+}
+
+void AcceleratedCompositingContext::resizeRootLayer(const IntSize& newSize)
+{
+    if (!enabled())
+        return;
+
+    if (m_rootLayer->size() == newSize)
+        return;
+
+    m_rootLayer->setSize(newSize);
+
+    // If the newSize exposes new areas of the non-composited content a setNeedsDisplay is needed
+    // for those newly exposed areas.
+    FloatSize oldSize = m_nonCompositedContentLayer->size();
+    m_nonCompositedContentLayer->setSize(newSize);
+
+    if (newSize.width() > oldSize.width()) {
+        float height = std::min(static_cast<float>(newSize.height()), oldSize.height());
+        m_nonCompositedContentLayer->setNeedsDisplayInRect(FloatRect(oldSize.width(), 0, newSize.width() - oldSize.width(), height));
+    }
+
+    if (newSize.height() > oldSize.height())
+        m_nonCompositedContentLayer->setNeedsDisplayInRect(FloatRect(0, oldSize.height(), newSize.width(), newSize.height() - oldSize.height()));
+
+    m_nonCompositedContentLayer->setNeedsDisplayInRect(IntRect(IntPoint(), newSize));
+    compositeLayersToContext(ForResize);
+    scheduleLayerFlush();
+}
+
+void AcceleratedCompositingContext::scrollNonCompositedContents(const IntRect& scrollRect, const IntSize& /* scrollOffset */)
+{
+    m_nonCompositedContentLayer->setNeedsDisplay();
+    scheduleLayerFlush();
+}
+
+void AcceleratedCompositingContext::scheduleLayerFlush()
+{
+    if (!enabled())
+        return;
+
+    if (m_layerFlushTimer.isActive())
+        return;
+
+    m_layerFlushTimer.startOneShot(0);
+}
+
+bool AcceleratedCompositingContext::flushPendingLayerChanges()
+{
+    m_rootLayer->flushCompositingStateForThisLayerOnly();
+    m_nonCompositedContentLayer->flushCompositingStateForThisLayerOnly();
+    return core(&m_webView)->mainFrame().view()->flushCompositingStateIncludingSubframes();
+}
+
+bool AcceleratedCompositingContext::flushPendingLayerChangesSoon()
+{
+    scheduleLayerFlush();
+    return true;
+}
+
+void AcceleratedCompositingContext::flushAndRenderLayers()
+{
+    if (!enabled())
+        return;
+
+    Frame& frame = core(&m_webView)->mainFrame();
+    if (!frame.contentRenderer() || !frame.view())
+        return;
+    frame.view()->updateLayoutAndStyleIfNeededRecursive();
+
+    if (!enabled())
+        return;
+
+    if (m_context && !m_context->makeContextCurrent())
+        return;
+
+    if (!flushPendingLayerChanges())
+        return;
+
+    compositeLayersToContext();
+}
+
+void AcceleratedCompositingContext::layerFlushTimerFired()
+{
+    flushAndRenderLayers();
+
+    // In case an animation is running, we should flush again soon.
+    if (startedAnimation(m_rootLayer.get()))
+        scheduleLayerFlush();
+}
+
+void AcceleratedCompositingContext::paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase, const FloatRect& rectToPaint)
+{
+    context.save();
+    context.clip(rectToPaint);
+    core(&m_webView)->mainFrame().view()->paint(&context, enclosingIntRect(rectToPaint));
+    context.restore();
+}
+
+#endif // USE(TEXTURE_MAPPER_GL)
diff --git a/Source/WebKit/win/WebCoreSupport/AcceleratedCompositingContext.h b/Source/WebKit/win/WebCoreSupport/AcceleratedCompositingContext.h
new file mode 100644 (file)
index 0000000..9eba23f
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2014 Apple, Inc.
+ *
+ * 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 AcceleratedCompositingContext_h
+#define AcceleratedCompositingContext_h
+
+#if USE(TEXTURE_MAPPER_GL)
+
+#include <WebCore/FloatRect.h>
+#include <WebCore/GLContext.h>
+#include <WebCore/GraphicsLayer.h>
+#include <WebCore/GraphicsLayerClient.h>
+#include <WebCore/IntRect.h>
+#include <WebCore/IntSize.h>
+#include <WebCore/TextureMapperFPSCounter.h>
+#include <WebCore/Timer.h>
+#include <wtf/PassOwnPtr.h>
+
+class WebView;
+
+class AcceleratedCompositingContext : public WebCore::GraphicsLayerClient {
+    WTF_MAKE_NONCOPYABLE(AcceleratedCompositingContext);
+public:
+    explicit AcceleratedCompositingContext(WebView&);
+    virtual ~AcceleratedCompositingContext();
+
+    void setRootCompositingLayer(WebCore::GraphicsLayer*);
+    void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&);
+    void setNeedsDisplayInRect(const WebCore::IntRect&);
+    void scheduleLayerFlush();
+    void resizeRootLayer(const WebCore::IntSize&);
+    bool enabled();
+
+    // GraphicsLayerClient
+    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::FloatRect& rectToPaint);
+
+    void initialize();
+
+    enum CompositePurpose { ForResize, NotForResize };
+    void compositeLayersToContext(CompositePurpose = NotForResize);
+
+    void flushAndRenderLayers();
+    bool flushPendingLayerChanges();
+    bool flushPendingLayerChangesSoon();
+    void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
+
+private:
+    WebView& m_webView;
+    OwnPtr<WebCore::GLContext> m_context;
+    HWND m_window;
+    std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
+    std::unique_ptr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
+    std::unique_ptr<WebCore::TextureMapper> m_textureMapper;
+    WebCore::TextureMapperFPSCounter m_fpsCounter;
+
+    class LayerFlushTimer : public WebCore::TimerBase {
+    public:
+        LayerFlushTimer(AcceleratedCompositingContext& context)
+            : m_context(context)
+        {
+        }
+
+    private:
+        virtual void fired()
+        {
+            m_context.layerFlushTimerFired();
+        }
+
+        AcceleratedCompositingContext& m_context;
+    } m_layerFlushTimer;
+
+    void layerFlushTimerFired();
+    void stopAnyPendingLayerFlush();
+    bool prepareForRendering();
+    bool startedAnimation(WebCore::GraphicsLayer*);
+};
+
+#endif // TEXTURE_MAPPER_GL
+
+#endif // AcceleratedCompositingContext_h
index cce5109..f783277 100644 (file)
 #if USE(CA)
 #include <WebCore/CACFLayerTreeHost.h>
 #include <WebCore/PlatformCALayer.h>
+#elif USE(TEXTURE_MAPPER_GL)
+#include "AcceleratedCompositingContext.h"
 #endif
 
 #if ENABLE(FULLSCREEN_API)
@@ -409,6 +411,9 @@ WebView::WebView()
     , m_lastSetCursor(0)
     , m_usesLayeredWindow(false)
     , m_needsDisplay(false)
+#if USE(TEXTURE_MAPPER_GL)
+    , m_acceleratedCompositingContext(nullptr)
+#endif
 {
     JSC::initializeThreading();
     WTF::initializeMainThread();
@@ -860,7 +865,11 @@ void WebView::addToDirtyRegion(const IntRect& dirtyRect)
     // http://webkit.org/b/29350.
 
     if (isAcceleratedCompositing()) {
+#if USE(CA)
         m_backingLayer->setNeedsDisplayInRect(dirtyRect);
+#elif USE(TEXTURE_MAPPER_GL)
+        m_acceleratedCompositingContext->setNeedsDisplayInRect(dirtyRect);
+#endif
         return;
     }
 
@@ -895,7 +904,11 @@ void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const Int
     if (isAcceleratedCompositing()) {
         // FIXME: We should be doing something smarter here, like moving tiles around and painting
         // any newly-exposed tiles. <http://webkit.org/b/52714>
+#if USE(CA)
         m_backingLayer->setNeedsDisplayInRect(scrollViewRect);
+#elif USE(TEXTURE_MAPPER_GL)
+        m_acceleratedCompositingContext->scrollNonCompositedContents(scrollViewRect, IntSize(dx, dy));
+#endif
         return;
     }
 
@@ -952,10 +965,14 @@ void WebView::sizeChanged(const IntSize& newSize)
 #if USE(CA)
     if (m_layerTreeHost)
         m_layerTreeHost->resize();
+
     if (m_backingLayer) {
         m_backingLayer->setSize(newSize);
         m_backingLayer->setNeedsDisplay();
     }
+#elif USE(TEXTURE_MAPPER_GL)
+    if (m_acceleratedCompositingContext)
+        m_acceleratedCompositingContext->resizeRootLayer(newSize);
 #endif
 }
 
@@ -1084,18 +1101,22 @@ void WebView::paint(HDC dc, LPARAM options)
 {
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 
-#if USE(CA)
     if (isAcceleratedCompositing() && !usesLayeredWindow()) {
+#if USE(CA)
         m_layerTreeHost->flushPendingLayerChangesNow();
+#elif USE(TEXTURE_MAPPER_GL)
+        m_acceleratedCompositingContext->flushAndRenderLayers();
+#endif
         // Flushing might have taken us out of compositing mode.
         if (isAcceleratedCompositing()) {
+#if USE(CA)
             // FIXME: We need to paint into dc (if provided). <http://webkit.org/b/52578>
             m_layerTreeHost->paint();
+#endif
             ::ValidateRect(m_viewWindow, 0);
             return;
         }
     }
-#endif
 
     Frame* coreFrame = core(m_mainFrame);
     if (!coreFrame)
@@ -2393,8 +2414,10 @@ LRESULT CALLBACK WebView::WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam,
                 RECT windowRect;
                 ::GetClientRect(hWnd, &windowRect);
                 ::InvalidateRect(hWnd, &windowRect, false);
+#if USE(CA)
                 if (webView->isAcceleratedCompositing())
                     webView->m_backingLayer->setNeedsDisplay();
+#endif
            }
             break;
         case WM_MOUSEACTIVATE:
@@ -6551,9 +6574,15 @@ void WebView::downloadURL(const URL& url)
 void WebView::setRootChildLayer(GraphicsLayer* layer)
 {
     setAcceleratedCompositing(layer ? true : false);
+#if USE(CA)
     if (!m_backingLayer)
         return;
     m_backingLayer->addChild(layer);
+#elif USE(TEXTURE_MAPPER_GL)
+    if (!m_acceleratedCompositingContext)
+        return;
+    m_acceleratedCompositingContext->setRootCompositingLayer(layer);
+#endif
 }
 
 void WebView::flushPendingGraphicsLayerChangesSoon()
@@ -6562,13 +6591,20 @@ void WebView::flushPendingGraphicsLayerChangesSoon()
     if (!m_layerTreeHost)
         return;
     m_layerTreeHost->flushPendingGraphicsLayerChangesSoon();
+#elif USE(TEXTURE_MAPPER_GL)
+    if (!m_acceleratedCompositingContext)
+        return;
+    m_acceleratedCompositingContext->flushPendingLayerChangesSoon();
 #endif
 }
 
 void WebView::setAcceleratedCompositing(bool accelerated)
 {
+    if (m_isAcceleratedCompositing == accelerated)
+        return;
+
 #if USE(CA)
-    if (m_isAcceleratedCompositing == accelerated || !CACFLayerTreeHost::acceleratedCompositingAvailable())
+    if (!CACFLayerTreeHost::acceleratedCompositingAvailable())
         return;
 
     if (accelerated) {
@@ -6608,6 +6644,10 @@ void WebView::setAcceleratedCompositing(bool accelerated)
         m_backingLayer = nullptr;
         m_isAcceleratedCompositing = false;
     }
+#elif USE(TEXTURE_MAPPER_GL)
+    if (accelerated && !m_acceleratedCompositingContext)
+        m_acceleratedCompositingContext = std::make_unique<AcceleratedCompositingContext>(*this);
+    m_isAcceleratedCompositing = accelerated;
 #endif
 }
 
@@ -6752,14 +6792,18 @@ void WebView::flushPendingGraphicsLayerChanges()
     FrameView* view = coreFrame->view();
     if (!view)
         return;
+#if USE(CA)
     if (!m_backingLayer)
         return;
+#endif
 
     view->updateLayoutAndStyleIfNeededRecursive();
 
+#if USE(CA)
     // Updating layout might have taken us out of compositing mode.
     if (m_backingLayer)
         m_backingLayer->flushCompositingStateForThisLayerOnly();
+#endif
 
     view->flushCompositingStateIncludingSubframes();
 }
index 6aa724d..2b51f24 100644 (file)
@@ -67,6 +67,9 @@ class WebBackForwardList;
 class WebFrame;
 class WebInspector;
 class WebInspectorClient;
+#if USE(TEXTURE_MAPPER_GL)
+class AcceleratedCompositingContext;
+#endif
 
 WebView* kit(WebCore::Page*);
 WebCore::Page* core(IWebView*);
@@ -1136,8 +1139,10 @@ protected:
     void setAcceleratedCompositing(bool);
 #if USE(CA)
     RefPtr<WebCore::CACFLayerTreeHost> m_layerTreeHost;
-#endif
     std::unique_ptr<WebCore::GraphicsLayer> m_backingLayer;
+#elif USE(TEXTURE_MAPPER_GL)
+    std::unique_ptr<AcceleratedCompositingContext> m_acceleratedCompositingContext;
+#endif
     bool m_isAcceleratedCompositing;
 
     bool m_nextDisplayIsSynchronous;