summaryrefslogtreecommitdiffstats
path: root/patches/chromium/third_party/WebKit/0006-Use-compositor-for-page-popups.patch
blob: 3b260a8dc44bcb18fa25545865c28a624e85389b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "jbauman@chromium.org" <jbauman@chromium.org>
Date: Fri, 21 Feb 2014 00:46:34 +0000
Subject: 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 <jocelyn.turcotte@digia.com>
---
 Source/web/WebPagePopupImpl.cpp | 87 +++++++++++++++++++++++++++++++++++++++++
 Source/web/WebPagePopupImpl.h   | 13 ++++++
 2 files changed, 100 insertions(+)

diff --git a/Source/web/WebPagePopupImpl.cpp b/Source/web/WebPagePopupImpl.cpp
index b129dc6..cadbc14 100644
--- a/Source/web/WebPagePopupImpl.cpp
+++ b/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/Source/web/WebPagePopupImpl.h b/Source/web/WebPagePopupImpl.h
index 660c47f..050f3ae 100644
--- a/Source/web/WebPagePopupImpl.h
+++ b/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;
 };