[WinCairo][WK2] Use GraphicsLayerTextureMapper for Accelerated Compositing mode
authorHironori.Fujii@sony.com <Hironori.Fujii@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 May 2020 20:30:55 +0000 (20:30 +0000)
committerHironori.Fujii@sony.com <Hironori.Fujii@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 May 2020 20:30:55 +0000 (20:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211883

Reviewed by Don Olmstead.

.:

* Source/cmake/OptionsWinCairo.cmake: Added a new build option
USE_GRAPHICS_LAYER_TEXTURE_MAPPER, and set ON as the default.

Source/WebKit:

GraphicsLayerTextureMapper is a simple GraphicsLayer
implementation using TextureMapper which is used for WinCairo WebKit1.

Add a new LayerTreeHost implementation for
GraphicsLayerTextureMapper by copying WinCairo WebKit1's
AcceleratedCompositingContext.

Windows WebKitTestRunner can't capture the window content for
pixel dump tests yet.

* PlatformWin.cmake:
* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
* UIProcess/win/WebView.cpp:
(WebKit::WebView::WebView):
* WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
(WebKit::DrawingAreaCoordinatedGraphics::setNeedsDisplayInRect):
(WebKit::DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingMode):
* WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.h:
* WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.cpp: Added.
(WebKit::LayerTreeHost::prepareForRendering):
(WebKit::LayerTreeHost::compositeLayersToContext):
(WebKit::LayerTreeHost::flushPendingLayerChanges):
(WebKit::LayerTreeHost::layerFlushTimerFired):
(WebKit::LayerTreeHost::LayerTreeHost):
(WebKit::LayerTreeHost::setLayerFlushSchedulingEnabled):
(WebKit::LayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush):
(WebKit::LayerTreeHost::scheduleLayerFlush):
(WebKit::LayerTreeHost::cancelPendingLayerFlush):
(WebKit::LayerTreeHost::setRootCompositingLayer):
(WebKit::LayerTreeHost::setViewOverlayRootLayer):
(WebKit::LayerTreeHost::setNonCompositedContentsNeedDisplay):
(WebKit::LayerTreeHost::scrollNonCompositedContents):
(WebKit::LayerTreeHost::flushAndRenderLayers):
(WebKit::LayerTreeHost::forceRepaint):
(WebKit::LayerTreeHost::forceRepaintAsync):
(WebKit::LayerTreeHost::sizeDidChange):
(WebKit::LayerTreeHost::pauseRendering):
(WebKit::LayerTreeHost::resumeRendering):
(WebKit::LayerTreeHost::graphicsLayerFactory):
(WebKit::LayerTreeHost::contentsSizeChanged):
(WebKit::LayerTreeHost::didChangeViewportAttributes):
(WebKit::LayerTreeHost::setIsDiscardable):
(WebKit::LayerTreeHost::deviceOrPageScaleFactorChanged):
(WebKit::LayerTreeHost::createDisplayRefreshMonitor):
(WebKit::LayerTreeHost::window):
(WebKit::LayerTreeHost::enabled):
(WebKit::LayerTreeHost::paintContents):
(WebKit::LayerTreeHost::deviceScaleFactor const):
(WebKit::LayerTreeHost::applyDeviceScaleFactor):
* WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.h: Added.
(WebKit::LayerTreeHost::layerTreeContext const):
(WebKit::LayerTreeHost::displayID const):
* WebProcess/WebPage/WebPage.cpp:
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::nativeWindowHandle):
* WebProcess/win/WebProcessMainWin.cpp:

Tools:

* MiniBrowser/win/WebKitBrowserWindow.cpp:
(WebKitBrowserWindow::setPreference): Call WKPreferencesSet* for
menu items IDM_ACC_COMPOSITING, IDM_COMPOSITING_BORDERS and
IDM_DEBUG_INFO_LAYER.

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

17 files changed:
ChangeLog
Source/WebKit/ChangeLog
Source/WebKit/PlatformWin.cmake
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/win/WebView.cpp
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.h
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.cpp [new file with mode: 0644]
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.h [new file with mode: 0644]
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/win/WebProcessMainWin.cpp
Source/cmake/OptionsWinCairo.cmake
Tools/ChangeLog
Tools/MiniBrowser/win/WebKitBrowserWindow.cpp

index 49060f1..4fc10d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-05-26  Fujii Hironori  <Hironori.Fujii@sony.com>
+
+        [WinCairo][WK2] Use GraphicsLayerTextureMapper for Accelerated Compositing mode
+        https://bugs.webkit.org/show_bug.cgi?id=211883
+
+        Reviewed by Don Olmstead.
+
+        * Source/cmake/OptionsWinCairo.cmake: Added a new build option
+        USE_GRAPHICS_LAYER_TEXTURE_MAPPER, and set ON as the default.
+
 2020-05-26  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake] Add static analyzers
index 82e56e7..bf6e87e 100644 (file)
@@ -1,3 +1,72 @@
+2020-05-26  Fujii Hironori  <Hironori.Fujii@sony.com>
+
+        [WinCairo][WK2] Use GraphicsLayerTextureMapper for Accelerated Compositing mode
+        https://bugs.webkit.org/show_bug.cgi?id=211883
+
+        Reviewed by Don Olmstead.
+
+        GraphicsLayerTextureMapper is a simple GraphicsLayer
+        implementation using TextureMapper which is used for WinCairo WebKit1.
+
+        Add a new LayerTreeHost implementation for
+        GraphicsLayerTextureMapper by copying WinCairo WebKit1's
+        AcceleratedCompositingContext.
+
+        Windows WebKitTestRunner can't capture the window content for
+        pixel dump tests yet.
+
+        * PlatformWin.cmake:
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters):
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::WebView):
+        * WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
+        (WebKit::DrawingAreaCoordinatedGraphics::setNeedsDisplayInRect):
+        (WebKit::DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingMode):
+        * WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.h:
+        * WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.cpp: Added.
+        (WebKit::LayerTreeHost::prepareForRendering):
+        (WebKit::LayerTreeHost::compositeLayersToContext):
+        (WebKit::LayerTreeHost::flushPendingLayerChanges):
+        (WebKit::LayerTreeHost::layerFlushTimerFired):
+        (WebKit::LayerTreeHost::LayerTreeHost):
+        (WebKit::LayerTreeHost::setLayerFlushSchedulingEnabled):
+        (WebKit::LayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush):
+        (WebKit::LayerTreeHost::scheduleLayerFlush):
+        (WebKit::LayerTreeHost::cancelPendingLayerFlush):
+        (WebKit::LayerTreeHost::setRootCompositingLayer):
+        (WebKit::LayerTreeHost::setViewOverlayRootLayer):
+        (WebKit::LayerTreeHost::setNonCompositedContentsNeedDisplay):
+        (WebKit::LayerTreeHost::scrollNonCompositedContents):
+        (WebKit::LayerTreeHost::flushAndRenderLayers):
+        (WebKit::LayerTreeHost::forceRepaint):
+        (WebKit::LayerTreeHost::forceRepaintAsync):
+        (WebKit::LayerTreeHost::sizeDidChange):
+        (WebKit::LayerTreeHost::pauseRendering):
+        (WebKit::LayerTreeHost::resumeRendering):
+        (WebKit::LayerTreeHost::graphicsLayerFactory):
+        (WebKit::LayerTreeHost::contentsSizeChanged):
+        (WebKit::LayerTreeHost::didChangeViewportAttributes):
+        (WebKit::LayerTreeHost::setIsDiscardable):
+        (WebKit::LayerTreeHost::deviceOrPageScaleFactorChanged):
+        (WebKit::LayerTreeHost::createDisplayRefreshMonitor):
+        (WebKit::LayerTreeHost::window):
+        (WebKit::LayerTreeHost::enabled):
+        (WebKit::LayerTreeHost::paintContents):
+        (WebKit::LayerTreeHost::deviceScaleFactor const):
+        (WebKit::LayerTreeHost::applyDeviceScaleFactor):
+        * WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.h: Added.
+        (WebKit::LayerTreeHost::layerTreeContext const):
+        (WebKit::LayerTreeHost::displayID const):
+        * WebProcess/WebPage/WebPage.cpp:
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::nativeWindowHandle):
+        * WebProcess/win/WebProcessMainWin.cpp:
+
 2020-05-25  Darin Adler  <darin@apple.com>
 
         Eliminate Color constructors that take strings, moving color parsing entirely into the CSS parser
index a94c7e1..3b94f4d 100644 (file)
@@ -81,7 +81,7 @@ list(APPEND WebKit_SOURCES
 
     WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
     WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp
-    WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.cpp
+    WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.cpp
 
     WebProcess/WebPage/win/WebPageWin.cpp
 
index 8389265..a38ed40 100644 (file)
@@ -116,6 +116,9 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
 #if USE(WPE_RENDERER)
     encoder << hostFileDescriptor;
 #endif
+#if PLATFORM(WIN)
+    encoder << nativeWindowHandle;
+#endif
     encoder << appleMailPaginationQuirkEnabled;
     encoder << appleMailLinesClampEnabled;
     encoder << shouldScaleViewToFitDocument;
@@ -358,6 +361,11 @@ Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decod
         return WTF::nullopt;
 #endif
 
+#if PLATFORM(WIN)
+    if (!decoder.decode(parameters.nativeWindowHandle))
+        return WTF::nullopt;
+#endif
+
     if (!decoder.decode(parameters.appleMailPaginationQuirkEnabled))
         return WTF::nullopt;
 
index 8a982a4..fd23edf 100644 (file)
@@ -177,6 +177,9 @@ struct WebPageCreationParameters {
 #if USE(WPE_RENDERER)
     IPC::Attachment hostFileDescriptor;
 #endif
+#if PLATFORM(WIN)
+    uint64_t nativeWindowHandle;
+#endif
     bool appleMailPaginationQuirkEnabled;
     bool appleMailLinesClampEnabled;
     bool shouldScaleViewToFitDocument;
index 187e489..718334f 100644 (file)
@@ -7814,6 +7814,10 @@ WebPageCreationParameters WebPageProxy::creationParameters(WebProcessProxy& proc
     parameters.hostFileDescriptor = pageClient().hostFileDescriptor();
 #endif
 
+#if PLATFORM(WIN)
+    parameters.nativeWindowHandle = reinterpret_cast<uint64_t>(viewWidget());
+#endif
+
     for (auto& iterator : m_urlSchemeHandlersByScheme)
         parameters.urlSchemeHandlers.set(iterator.key, iterator.value->identifier());
 
index 4a96b5e..27686d7 100644 (file)
@@ -237,16 +237,6 @@ WebView::WebView(RECT rect, const API::PageConfiguration& configuration, HWND pa
     ASSERT(m_isVisible == static_cast<bool>(::GetWindowLong(m_window, GWL_STYLE) & WS_VISIBLE));
 
     auto pageConfiguration = configuration.copy();
-    auto* preferences = pageConfiguration->preferences();
-    if (!preferences && pageConfiguration->pageGroup()) {
-        preferences = &pageConfiguration->pageGroup()->preferences();
-        pageConfiguration->setPreferences(preferences);
-    }
-    if (preferences) {
-        // Disable accelerated compositing until it is supported.
-        preferences->setAcceleratedCompositingEnabled(false);
-    }
-
     WebProcessPool* processPool = pageConfiguration->processPool();
     m_page = processPool->createWebPage(*m_pageClient, WTFMove(pageConfiguration));
     m_page->initializeWebPage();
index f5f24bc..564126e 100644 (file)
@@ -95,6 +95,9 @@ void DrawingAreaCoordinatedGraphics::setNeedsDisplayInRect(const IntRect& rect)
 {
     if (m_layerTreeHost) {
         ASSERT(m_dirtyRegion.isEmpty());
+#if USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
+        m_layerTreeHost->setNonCompositedContentsNeedDisplay(rect);
+#endif
         return;
     }
 
@@ -588,7 +591,7 @@ void DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingMode(GraphicsLay
         if (!m_layerTreeStateIsFrozen)
             m_layerTreeHost->setLayerFlushSchedulingEnabled(true);
     } else {
-#if USE(COORDINATED_GRAPHICS)
+#if USE(COORDINATED_GRAPHICS) || USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
         m_layerTreeHost = makeUnique<LayerTreeHost>(m_webPage);
         changeWindowScreen();
 #else
index 4a5e21a..34d7210 100644 (file)
 #include <wtf/OptionSet.h>
 #include <wtf/RunLoop.h>
 
-#if USE(COORDINATED_GRAPHICS)
-#endif
+#if USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
+
+#include "LayerTreeHostTextureMapper.h"
+
+#else // USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
 
 namespace WebCore {
 class IntRect;
@@ -223,3 +226,5 @@ inline RefPtr<WebCore::DisplayRefreshMonitor> LayerTreeHost::createDisplayRefres
 #endif
 
 } // namespace WebKit
+
+#endif // USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
diff --git a/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.cpp b/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.cpp
new file mode 100644 (file)
index 0000000..92a0c39
--- /dev/null
@@ -0,0 +1,300 @@
+/*
+ * Copyright (C) 2014 Apple, Inc.
+ * Copyright (C) 2020 Sony Interactive Entertainment 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 "LayerTreeHostTextureMapper.h"
+
+#if USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
+
+#include "WebPage.h"
+#include <GLES2/gl2.h>
+#include <WebCore/Document.h>
+#include <WebCore/Frame.h>
+#include <WebCore/FrameView.h>
+#include <WebCore/GraphicsLayerTextureMapper.h>
+#include <WebCore/Page.h>
+#include <WebCore/Settings.h>
+#include <WebCore/TemporaryOpenGLSetting.h>
+#include <WebCore/TextureMapperGL.h>
+#include <WebCore/TextureMapperLayer.h>
+
+namespace WebKit {
+using namespace WebCore;
+
+bool LayerTreeHost::prepareForRendering()
+{
+    if (!enabled())
+        return false;
+
+    if (!m_context)
+        return false;
+
+    if (!m_context->makeContextCurrent())
+        return false;
+
+    return true;
+}
+
+void LayerTreeHost::compositeLayersToContext()
+{
+    if (!prepareForRendering())
+        return;
+
+    IntSize windowSize = expandedIntSize(m_rootLayer->size());
+    glViewport(0, 0, windowSize.width(), windowSize.height());
+
+    m_textureMapper->beginPainting();
+    downcast<GraphicsLayerTextureMapper>(*m_rootLayer).layer().paint();
+    m_fpsCounter.updateFPSAndDisplay(*m_textureMapper);
+    m_textureMapper->endPainting();
+
+    m_context->swapBuffers();
+}
+
+bool LayerTreeHost::flushPendingLayerChanges()
+{
+    FrameView* frameView = m_webPage.corePage()->mainFrame().view();
+    m_rootLayer->flushCompositingStateForThisLayerOnly();
+    if (!frameView->flushCompositingStateIncludingSubframes())
+        return false;
+
+    if (m_overlayCompositingLayer)
+        m_overlayCompositingLayer->flushCompositingState(FloatRect(FloatPoint(), m_rootLayer->size()));
+
+    downcast<GraphicsLayerTextureMapper>(*m_rootLayer).updateBackingStoreIncludingSubLayers();
+    return true;
+}
+
+void LayerTreeHost::layerFlushTimerFired()
+{
+    flushAndRenderLayers();
+
+    if (!enabled())
+        return;
+
+    // In case an animation is running, we should flush again soon.
+    if (downcast<GraphicsLayerTextureMapper>(m_rootLayer.get())->layer().descendantsOrSelfHaveRunningAnimations())
+        m_webPage.corePage()->scheduleTimedRenderingUpdate();
+}
+
+LayerTreeHost::LayerTreeHost(WebPage& webPage)
+    : m_webPage(webPage)
+    , m_layerFlushTimer(*this, &LayerTreeHost::layerFlushTimerFired)
+{
+    m_rootLayer = GraphicsLayer::create(nullptr, *this);
+    m_rootLayer->setDrawsContent(true);
+    m_rootLayer->setContentsOpaque(true);
+    m_rootLayer->setSize(m_webPage.size());
+    m_rootLayer->setNeedsDisplay();
+#ifndef NDEBUG
+    m_rootLayer->setName("Root layer");
+#endif
+    applyDeviceScaleFactor();
+
+    // The creation of the TextureMapper needs an active OpenGL context.
+    m_context = GLContext::createContextForWindow(window());
+
+    if (!m_context)
+        return;
+
+    m_context->makeContextCurrent();
+
+    m_textureMapper = TextureMapperGL::create();
+    downcast<GraphicsLayerTextureMapper>(*m_rootLayer).layer().setTextureMapper(m_textureMapper.get());
+}
+
+void LayerTreeHost::setLayerFlushSchedulingEnabled(bool)
+{
+}
+
+void LayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush(bool)
+{
+}
+
+void LayerTreeHost::scheduleLayerFlush()
+{
+    if (!enabled())
+        return;
+
+    if (m_layerFlushTimer.isActive())
+        return;
+
+    m_layerFlushTimer.startOneShot(0_s);
+}
+
+void LayerTreeHost::cancelPendingLayerFlush()
+{
+    m_layerFlushTimer.stop();
+}
+
+void LayerTreeHost::setRootCompositingLayer(WebCore::GraphicsLayer* graphicsLayer)
+{
+    if (m_rootCompositingLayer == graphicsLayer)
+        return;
+
+    m_rootCompositingLayer = graphicsLayer;
+    m_rootLayer->removeAllChildren();
+    if (m_overlayCompositingLayer)
+        m_rootLayer->addChild(*m_overlayCompositingLayer);
+    if (m_rootCompositingLayer)
+        m_rootLayer->addChild(*m_rootCompositingLayer);
+}
+
+void LayerTreeHost::setViewOverlayRootLayer(WebCore::GraphicsLayer* graphicsLayer)
+{
+    if (m_overlayCompositingLayer == graphicsLayer)
+        return;
+
+    m_overlayCompositingLayer = graphicsLayer;
+    m_rootLayer->removeAllChildren();
+    if (m_overlayCompositingLayer)
+        m_rootLayer->addChild(*m_overlayCompositingLayer);
+    if (m_rootCompositingLayer)
+        m_rootLayer->addChild(*m_rootCompositingLayer);
+}
+
+void LayerTreeHost::setNonCompositedContentsNeedDisplay(const WebCore::IntRect& rect)
+{
+    if (!enabled())
+        return;
+    m_rootLayer->setNeedsDisplayInRect(rect);
+    scheduleLayerFlush();
+}
+
+void LayerTreeHost::scrollNonCompositedContents(const WebCore::IntRect& scrollRect)
+{
+    setNonCompositedContentsNeedDisplay(scrollRect);
+}
+
+void LayerTreeHost::flushAndRenderLayers()
+{
+    if (!enabled())
+        return;
+
+    m_webPage.corePage()->updateRendering();
+
+    if (!flushPendingLayerChanges())
+        return;
+
+    compositeLayersToContext();
+}
+
+void LayerTreeHost::forceRepaint()
+{
+    flushAndRenderLayers();
+}
+
+bool LayerTreeHost::forceRepaintAsync(CallbackID)
+{
+    return false;
+}
+
+void LayerTreeHost::sizeDidChange(const WebCore::IntSize& newSize)
+{
+    if (!enabled())
+        return;
+
+    if (m_rootLayer->size() == newSize)
+        return;
+    m_rootLayer->setSize(newSize);
+    applyDeviceScaleFactor();
+
+    scheduleLayerFlush();
+}
+
+void LayerTreeHost::pauseRendering()
+{
+}
+
+void LayerTreeHost::resumeRendering()
+{
+}
+
+WebCore::GraphicsLayerFactory* LayerTreeHost::graphicsLayerFactory()
+{
+    return nullptr;
+}
+
+void LayerTreeHost::contentsSizeChanged(const WebCore::IntSize&)
+{
+}
+
+void LayerTreeHost::didChangeViewportAttributes(WebCore::ViewportAttributes&&)
+{
+}
+
+void LayerTreeHost::setIsDiscardable(bool)
+{
+}
+
+void LayerTreeHost::deviceOrPageScaleFactorChanged()
+{
+}
+
+RefPtr<WebCore::DisplayRefreshMonitor> LayerTreeHost::createDisplayRefreshMonitor(WebCore::PlatformDisplayID)
+{
+    return nullptr;
+}
+
+HWND LayerTreeHost::window()
+{
+    return reinterpret_cast<HWND>(m_webPage.nativeWindowHandle());
+}
+
+bool LayerTreeHost::enabled()
+{
+    return window() && m_rootCompositingLayer;
+}
+
+void LayerTreeHost::paintContents(const GraphicsLayer*, GraphicsContext& context, const FloatRect& rectToPaint, GraphicsLayerPaintBehavior)
+{
+    context.save();
+    context.clip(rectToPaint);
+    m_webPage.corePage()->mainFrame().view()->paint(context, enclosingIntRect(rectToPaint));
+    context.restore();
+}
+
+float LayerTreeHost::deviceScaleFactor() const
+{
+    return m_webPage.corePage()->deviceScaleFactor();
+}
+
+void LayerTreeHost::applyDeviceScaleFactor()
+{
+    const FloatSize& size = m_rootLayer->size();
+
+    TransformationMatrix m;
+    m.scale(deviceScaleFactor());
+    // Center view
+    double tx = (size.width() - size.width() / deviceScaleFactor()) / 2.0;
+    double ty = (size.height() - size.height() / deviceScaleFactor()) / 2.0;
+    m.translate(tx, ty);
+    m_rootLayer->setTransform(m);
+}
+
+} // namespace WebKit
+
+#endif // USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
diff --git a/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.h b/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHostTextureMapper.h
new file mode 100644 (file)
index 0000000..cb98b8b
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2014 Apple, Inc.
+ * Copyright (C) 2020 Sony Interactive Entertainment 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.
+ */
+
+#pragma once
+
+#if USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
+
+#include "CallbackID.h"
+#include "LayerTreeContext.h"
+#include <WebCore/DisplayRefreshMonitor.h>
+#include <WebCore/GLContext.h>
+#include <WebCore/GraphicsLayerClient.h>
+#include <WebCore/PlatformScreen.h>
+#include <WebCore/TextureMapperFPSCounter.h>
+#include <WebCore/Timer.h>
+#include <wtf/Forward.h>
+
+namespace WebCore {
+class GraphicsLayer;
+class GraphicsLayerFactory;
+class IntRect;
+class IntSize;
+class Page;
+struct ViewportAttributes;
+}
+
+namespace WebKit {
+
+class WebPage;
+
+class LayerTreeHost : public WebCore::GraphicsLayerClient {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    explicit LayerTreeHost(WebPage&);
+
+    const LayerTreeContext& layerTreeContext() const { return m_layerTreeContext; }
+    void setLayerFlushSchedulingEnabled(bool);
+    void setShouldNotifyAfterNextScheduledLayerFlush(bool);
+    void scheduleLayerFlush();
+    void cancelPendingLayerFlush();
+    void setRootCompositingLayer(WebCore::GraphicsLayer*);
+    void setViewOverlayRootLayer(WebCore::GraphicsLayer*);
+    void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&);
+    void scrollNonCompositedContents(const WebCore::IntRect&);
+    void forceRepaint();
+    bool forceRepaintAsync(CallbackID);
+    void sizeDidChange(const WebCore::IntSize& newSize);
+    void pauseRendering();
+    void resumeRendering();
+    WebCore::GraphicsLayerFactory* graphicsLayerFactory();
+    void contentsSizeChanged(const WebCore::IntSize&);
+    void didChangeViewportAttributes(WebCore::ViewportAttributes&&);
+    void setIsDiscardable(bool);
+    void deviceOrPageScaleFactorChanged();
+    RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID);
+    WebCore::PlatformDisplayID displayID() const { return m_displayID; }
+
+private:
+    // GraphicsLayerClient
+    void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::FloatRect& rectToPaint, WebCore::GraphicsLayerPaintBehavior) override;
+    float deviceScaleFactor() const override;
+
+    void initialize();
+    HWND window();
+    bool enabled();
+    void compositeLayersToContext();
+    void flushAndRenderLayers();
+    bool flushPendingLayerChanges();
+    void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
+    void layerFlushTimerFired();
+    bool prepareForRendering();
+    void applyDeviceScaleFactor();
+
+    WebPage& m_webPage;
+    std::unique_ptr<WebCore::GLContext> m_context;
+    LayerTreeContext m_layerTreeContext;
+    WebCore::PlatformDisplayID m_displayID;
+    RefPtr<WebCore::GraphicsLayer> m_rootLayer;
+    WebCore::GraphicsLayer* m_rootCompositingLayer { nullptr };
+    WebCore::GraphicsLayer* m_overlayCompositingLayer { nullptr };
+    std::unique_ptr<WebCore::TextureMapper> m_textureMapper;
+    WebCore::TextureMapperFPSCounter m_fpsCounter;
+    WebCore::Timer m_layerFlushTimer;
+};
+
+} // namespace WebKit
+
+#endif // USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
index 494c86b..c78977a 100644 (file)
@@ -428,6 +428,9 @@ WebPage::WebPage(PageIdentifier pageID, WebPageCreationParameters&& parameters)
 #elif ENABLE(ACCESSIBILITY) && PLATFORM(GTK)
     , m_accessibilityObject(nullptr)
 #endif
+#if PLATFORM(WIN)
+    , m_nativeWindowHandle(parameters.nativeWindowHandle)
+#endif
     , m_setCanStartMediaTimer(RunLoop::main(), this, &WebPage::setCanStartMediaTimerFired)
 #if ENABLE(CONTEXT_MENUS)
     , m_contextMenuClient(makeUnique<API::InjectedBundle::PageContextMenuClient>())
index fdcee1f..3c984ce 100644 (file)
@@ -1335,6 +1335,10 @@ public:
     void removeMediaUsageManagerSession(WebCore::MediaSessionIdentifier);
 #endif
 
+#if PLATFORM(WIN)
+    uint64_t nativeWindowHandle() { return m_nativeWindowHandle; }
+#endif
+
 private:
     WebPage(WebCore::PageIdentifier, WebPageCreationParameters&&);
 
@@ -1829,6 +1833,10 @@ private:
     GRefPtr<AtkObject> m_accessibilityObject;
 #endif
 
+#if PLATFORM(WIN)
+    uint64_t m_nativeWindowHandle { 0 };
+#endif
+
 #if !PLATFORM(IOS_FAMILY)
     RefPtr<PageBanner> m_headerBanner;
     RefPtr<PageBanner> m_footerBanner;
index f0ea5c5..89bc159 100644 (file)
 #include "AuxiliaryProcessMain.h"
 #include "WebProcess.h"
 #include <Objbase.h>
+#include <wtf/win/SoftLinking.h>
+
+SOFT_LINK_LIBRARY(user32);
+SOFT_LINK_OPTIONAL(user32, SetProcessDpiAwarenessContext, BOOL, STDAPICALLTYPE, (DPI_AWARENESS_CONTEXT));
 
 namespace WebKit {
 using namespace WebCore;
@@ -37,6 +41,10 @@ class WebProcessMainWin final : public AuxiliaryProcessMainBase {
 public:
     bool platformInitialize() override
     {
+        if (SetProcessDpiAwarenessContextPtr())
+            SetProcessDpiAwarenessContextPtr()(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
+        else
+            SetProcessDPIAware();
         return true;
     }
 };
index 35edf85..113170c 100644 (file)
@@ -39,6 +39,7 @@ set(USE_ANGLE_EGL ON)
 SET_AND_EXPOSE_TO_BUILD(USE_CAIRO ON)
 SET_AND_EXPOSE_TO_BUILD(USE_CF ON)
 SET_AND_EXPOSE_TO_BUILD(USE_CURL ON)
+SET_AND_EXPOSE_TO_BUILD(USE_GRAPHICS_LAYER_TEXTURE_MAPPER ON)
 SET_AND_EXPOSE_TO_BUILD(USE_EGL ON)
 SET_AND_EXPOSE_TO_BUILD(USE_OPENGL_ES ON)
 SET_AND_EXPOSE_TO_BUILD(HAVE_OPENGL_ES_3 ON)
index ae3712f..a9c4691 100644 (file)
@@ -1,3 +1,15 @@
+2020-05-26  Fujii Hironori  <Hironori.Fujii@sony.com>
+
+        [WinCairo][WK2] Use GraphicsLayerTextureMapper for Accelerated Compositing mode
+        https://bugs.webkit.org/show_bug.cgi?id=211883
+
+        Reviewed by Don Olmstead.
+
+        * MiniBrowser/win/WebKitBrowserWindow.cpp:
+        (WebKitBrowserWindow::setPreference): Call WKPreferencesSet* for
+        menu items IDM_ACC_COMPOSITING, IDM_COMPOSITING_BORDERS and
+        IDM_DEBUG_INFO_LAYER.
+
 2020-05-26  Sam Weinig  <weinig@apple.com>
 
         Extended Color Cleanup: Remove red()/green()/blue() accessors from ExtendedColor in preperation for supporting non-RGB based ColorSpaces
index 1e4fb27..9245dfc 100644 (file)
@@ -33,6 +33,7 @@
 #include <WebKit/WKCertificateInfoCurl.h>
 #include <WebKit/WKCredential.h>
 #include <WebKit/WKInspector.h>
+#include <WebKit/WKPreferencesRefPrivate.h>
 #include <WebKit/WKProtectionSpace.h>
 #include <WebKit/WKProtectionSpaceCurl.h>
 #include <WebKit/WKWebsiteDataStoreRef.h>
@@ -225,6 +226,16 @@ void WebKitBrowserWindow::setPreference(UINT menuID, bool enable)
     auto pgroup = WKPageGetPageGroup(page);
     auto pref = WKPageGroupGetPreferences(pgroup);
     switch (menuID) {
+    case IDM_ACC_COMPOSITING:
+        WKPreferencesSetAcceleratedCompositingEnabled(pref, enable);
+        break;
+    case IDM_COMPOSITING_BORDERS:
+        WKPreferencesSetCompositingBordersVisible(pref, enable);
+        WKPreferencesSetCompositingRepaintCountersVisible(pref, enable);
+        break;
+    case IDM_DEBUG_INFO_LAYER:
+        WKPreferencesSetTiledScrollingIndicatorVisible(pref, enable);
+        break;
     case IDM_DISABLE_IMAGES:
         WKPreferencesSetLoadsImagesAutomatically(pref, !enable);
         break;