From a674cb3f8da072db2795806ec2df63a451430a49 Mon Sep 17 00:00:00 2001 From: "jbauman@chromium.org" Date: Fri, 21 Feb 2014 00:46:34 +0000 Subject: [Backport] Use compositor for page popups. This is essentially the last user of the legacy 2d path. BUG=271140 Review URL: https://codereview.chromium.org/171343003 Change-Id: I64911d0d83b9d1d4782dff9b09db1bbcc439da24 git-svn-id: svn://svn.chromium.org/blink/trunk@167552 bbb929c8-8fbe-4397-9dbb-9b2b20218538 Reviewed-by: Jocelyn Turcotte --- .../WebKit/Source/web/WebPagePopupImpl.cpp | 87 ++++++++++++++++++++++ .../WebKit/Source/web/WebPagePopupImpl.h | 13 ++++ 2 files changed, 100 insertions(+) diff --git a/chromium/third_party/WebKit/Source/web/WebPagePopupImpl.cpp b/chromium/third_party/WebKit/Source/web/WebPagePopupImpl.cpp index b129dc6e10e..cadbc144e41 100644 --- a/chromium/third_party/WebKit/Source/web/WebPagePopupImpl.cpp +++ b/chromium/third_party/WebKit/Source/web/WebPagePopupImpl.cpp @@ -138,6 +138,16 @@ private: m_popup->widgetClient()->hasTouchEventHandlers(needsTouchEvents); } + virtual GraphicsLayerFactory* graphicsLayerFactory() const OVERRIDE + { + return m_popup->m_webView->graphicsLayerFactory(); + } + + virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer* graphicsLayer) OVERRIDE + { + m_popup->setRootGraphicsLayer(graphicsLayer); + } + WebPagePopupImpl* m_popup; }; @@ -157,6 +167,10 @@ bool PagePopupFeaturesClient::isEnabled(Document*, ContextFeatures::FeatureType WebPagePopupImpl::WebPagePopupImpl(WebWidgetClient* client) : m_widgetClient(client) , m_closing(false) + , m_layerTreeView(0) + , m_rootLayer(0) + , m_rootGraphicsLayer(0) + , m_isAcceleratedCompositingActive(false) { ASSERT(client); } @@ -224,6 +238,49 @@ void WebPagePopupImpl::destroyPage() m_page.clear(); } +void WebPagePopupImpl::setRootGraphicsLayer(GraphicsLayer* layer) +{ + m_rootGraphicsLayer = layer; + m_rootLayer = layer ? layer->platformLayer() : 0; + + setIsAcceleratedCompositingActive(layer); + if (m_layerTreeView) { + if (m_rootLayer) { + m_layerTreeView->setRootLayer(*m_rootLayer); + } else { + m_layerTreeView->clearRootLayer(); + } + } +} + +void WebPagePopupImpl::setIsAcceleratedCompositingActive(bool enter) +{ + if (m_isAcceleratedCompositingActive == enter) + return; + + if (!enter) { + m_isAcceleratedCompositingActive = false; + m_widgetClient->didDeactivateCompositor(); + } else if (m_layerTreeView) { + m_isAcceleratedCompositingActive = true; + m_widgetClient->didActivateCompositor(0); + } else { + TRACE_EVENT0("webkit", "WebPagePopupImpl::setIsAcceleratedCompositingActive(true)"); + + m_widgetClient->initializeLayerTreeView(); + m_layerTreeView = m_widgetClient->layerTreeView(); + if (m_layerTreeView) { + m_layerTreeView->setVisible(true); + m_widgetClient->didActivateCompositor(0); + m_isAcceleratedCompositingActive = true; + m_layerTreeView->setDeviceScaleFactor(m_widgetClient->deviceScaleFactor()); + } else { + m_isAcceleratedCompositingActive = false; + m_widgetClient->didDeactivateCompositor(); + } + } +} + WebSize WebPagePopupImpl::size() { return m_popupClient->contentSize(); @@ -234,6 +291,36 @@ void WebPagePopupImpl::animate(double) PageWidgetDelegate::animate(m_page.get(), monotonicallyIncreasingTime()); } +void WebPagePopupImpl::enterForceCompositingMode(bool enter) +{ + if (m_page->settings().forceCompositingMode() == enter) + return; + + TRACE_EVENT1("webkit", "WebPagePopupImpl::enterForceCompositingMode", "enter", enter); + m_page->settings().setForceCompositingMode(enter); + if (enter) { + if (!m_page) + return; + Frame* mainFrame = m_page->mainFrame(); + if (!mainFrame) + return; + mainFrame->view()->updateCompositingLayersAfterStyleChange(); + } +} + +void WebPagePopupImpl::didExitCompositingMode() +{ + setIsAcceleratedCompositingActive(false); + m_widgetClient->didInvalidateRect(IntRect(0, 0, size().width, size().height)); + m_page->mainFrame()->document()->setNeedsStyleRecalc(SubtreeStyleChange); +} + +void WebPagePopupImpl::willCloseLayerTreeView() +{ + setIsAcceleratedCompositingActive(false); + m_layerTreeView = 0; +} + void WebPagePopupImpl::layout() { PageWidgetDelegate::layout(m_page.get()); diff --git a/chromium/third_party/WebKit/Source/web/WebPagePopupImpl.h b/chromium/third_party/WebKit/Source/web/WebPagePopupImpl.h index 660c47f75ff..050f3aeb373 100644 --- a/chromium/third_party/WebKit/Source/web/WebPagePopupImpl.h +++ b/chromium/third_party/WebKit/Source/web/WebPagePopupImpl.h @@ -38,6 +38,7 @@ #include "wtf/RefCounted.h" namespace WebCore { +class GraphicsLayer; class Page; class PagePopupClient; class PlatformKeyboardEvent; @@ -46,6 +47,8 @@ class PlatformKeyboardEvent; namespace blink { class PagePopupChromeClient; +class WebLayerTreeView; +class WebLayer; class WebViewImpl; class WebPagePopupImpl : public WebPagePopup, @@ -68,6 +71,9 @@ private: virtual WebSize size() OVERRIDE; virtual void animate(double) OVERRIDE; virtual void layout() OVERRIDE; + virtual void enterForceCompositingMode(bool enter) OVERRIDE; + virtual void didExitCompositingMode() OVERRIDE; + virtual void willCloseLayerTreeView() OVERRIDE; virtual void paint(WebCanvas*, const WebRect&, PaintOptions = ReadbackFromCompositorIfAvailable) OVERRIDE; virtual void resize(const WebSize&) OVERRIDE; virtual void close() OVERRIDE; @@ -83,6 +89,8 @@ private: explicit WebPagePopupImpl(WebWidgetClient*); bool initializePage(); void destroyPage(); + void setRootGraphicsLayer(WebCore::GraphicsLayer*); + void setIsAcceleratedCompositingActive(bool enter); WebWidgetClient* m_widgetClient; WebRect m_windowRectInScreen; @@ -92,6 +100,11 @@ private: WebCore::PagePopupClient* m_popupClient; bool m_closing; + WebLayerTreeView* m_layerTreeView; + WebLayer* m_rootLayer; + WebCore::GraphicsLayer* m_rootGraphicsLayer; + bool m_isAcceleratedCompositingActive; + friend class WebPagePopup; friend class PagePopupChromeClient; }; -- cgit v1.2.1