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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
* Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
*
* 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"
#if USE(COORDINATED_GRAPHICS)
#include "CoordinatedDrawingAreaProxy.h"
#include "CoordinatedLayerTreeHostProxy.h"
#include "DrawingAreaMessages.h"
#include "DrawingAreaProxyMessages.h"
#include "LayerTreeContext.h"
#include "UpdateInfo.h"
#include "WebPageGroup.h"
#include "WebPageProxy.h"
#include "WebPreferences.h"
#include "WebProcessProxy.h"
#include <WebCore/Region.h>
using namespace WebCore;
namespace WebKit {
CoordinatedDrawingAreaProxy::CoordinatedDrawingAreaProxy(WebPageProxy& webPageProxy)
: DrawingAreaProxy(DrawingAreaTypeCoordinated, webPageProxy)
, m_currentBackingStoreStateID(0)
, m_nextBackingStoreStateID(0)
, m_isWaitingForDidUpdateBackingStoreState(false)
, m_hasReceivedFirstUpdate(false)
{
// Construct the proxy early to allow messages to be sent to the web process while AC is entered there.
m_coordinatedLayerTreeHostProxy = std::make_unique<CoordinatedLayerTreeHostProxy>(this);
}
CoordinatedDrawingAreaProxy::~CoordinatedDrawingAreaProxy()
{
// Make sure to exit accelerated compositing mode.
if (isInAcceleratedCompositingMode())
exitAcceleratedCompositingMode();
}
void CoordinatedDrawingAreaProxy::updateViewport()
{
m_webPageProxy.setViewNeedsDisplay(viewportVisibleRect());
}
WebCore::IntRect CoordinatedDrawingAreaProxy::contentsRect() const
{
return IntRect(IntPoint::zero(), m_webPageProxy.viewSize());
}
void CoordinatedDrawingAreaProxy::sizeDidChange()
{
backingStoreStateDidChange(RespondImmediately);
}
void CoordinatedDrawingAreaProxy::deviceScaleFactorDidChange()
{
backingStoreStateDidChange(RespondImmediately);
}
void CoordinatedDrawingAreaProxy::visibilityDidChange()
{
// If we don't have a backing store, go ahead and mark the backing store as being changed so
// that when paint we'll actually wait for something to paint and not flash white.
if (m_layerTreeContext.isEmpty())
backingStoreStateDidChange(DoNotRespondImmediately);
}
void CoordinatedDrawingAreaProxy::waitForBackingStoreUpdateOnNextPaint()
{
m_hasReceivedFirstUpdate = true;
}
void CoordinatedDrawingAreaProxy::didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo& updateInfo, const LayerTreeContext& layerTreeContext)
{
ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_nextBackingStoreStateID);
ASSERT_ARG(backingStoreStateID, backingStoreStateID > m_currentBackingStoreStateID);
m_currentBackingStoreStateID = backingStoreStateID;
m_isWaitingForDidUpdateBackingStoreState = false;
// Stop the responsiveness timer that was started in sendUpdateBackingStoreState.
m_webPageProxy.process().responsivenessTimer().stop();
if (layerTreeContext != m_layerTreeContext) {
if (!m_layerTreeContext.isEmpty()) {
exitAcceleratedCompositingMode();
ASSERT(m_layerTreeContext.isEmpty());
}
if (!layerTreeContext.isEmpty()) {
enterAcceleratedCompositingMode(layerTreeContext);
ASSERT(layerTreeContext == m_layerTreeContext);
}
}
if (m_nextBackingStoreStateID != m_currentBackingStoreStateID)
sendUpdateBackingStoreState(RespondImmediately);
else
m_hasReceivedFirstUpdate = true;
}
void CoordinatedDrawingAreaProxy::enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext& layerTreeContext)
{
ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID);
if (backingStoreStateID < m_currentBackingStoreStateID)
return;
enterAcceleratedCompositingMode(layerTreeContext);
}
void CoordinatedDrawingAreaProxy::exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo& updateInfo)
{
ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID);
if (backingStoreStateID < m_currentBackingStoreStateID)
return;
exitAcceleratedCompositingMode();
}
void CoordinatedDrawingAreaProxy::updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext& layerTreeContext)
{
ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID);
if (backingStoreStateID < m_currentBackingStoreStateID)
return;
updateAcceleratedCompositingMode(layerTreeContext);
}
void CoordinatedDrawingAreaProxy::backingStoreStateDidChange(RespondImmediatelyOrNot respondImmediatelyOrNot)
{
++m_nextBackingStoreStateID;
sendUpdateBackingStoreState(respondImmediatelyOrNot);
}
void CoordinatedDrawingAreaProxy::sendUpdateBackingStoreState(RespondImmediatelyOrNot respondImmediatelyOrNot)
{
ASSERT(m_currentBackingStoreStateID < m_nextBackingStoreStateID);
if (!m_webPageProxy.isValid())
return;
if (m_isWaitingForDidUpdateBackingStoreState)
return;
if (m_webPageProxy.viewSize().isEmpty() && !m_webPageProxy.useFixedLayout())
return;
m_isWaitingForDidUpdateBackingStoreState = respondImmediatelyOrNot == RespondImmediately;
m_webPageProxy.process().send(Messages::DrawingArea::UpdateBackingStoreState(m_nextBackingStoreStateID, respondImmediatelyOrNot == RespondImmediately, m_webPageProxy.deviceScaleFactor(), m_size, m_scrollOffset), m_webPageProxy.pageID());
m_scrollOffset = IntSize();
if (m_isWaitingForDidUpdateBackingStoreState) {
// Start the responsiveness timer. We will stop it when we hear back from the WebProcess
// in didUpdateBackingStoreState.
m_webPageProxy.process().responsivenessTimer().start();
}
if (m_isWaitingForDidUpdateBackingStoreState && !m_layerTreeContext.isEmpty()) {
// Wait for the DidUpdateBackingStoreState message. Normally we do this in CoordinatedDrawingAreaProxy::paint, but that
// function is never called when in accelerated compositing mode.
waitForAndDispatchDidUpdateBackingStoreState();
}
}
void CoordinatedDrawingAreaProxy::waitForAndDispatchDidUpdateBackingStoreState()
{
ASSERT(m_isWaitingForDidUpdateBackingStoreState);
if (!m_webPageProxy.isValid())
return;
if (m_webPageProxy.process().state() == WebProcessProxy::State::Launching)
return;
// FIXME: waitForAndDispatchImmediately will always return the oldest DidUpdateBackingStoreState message that
// hasn't yet been processed. But it might be better to skip ahead to some other DidUpdateBackingStoreState
// message, if multiple DidUpdateBackingStoreState messages are waiting to be processed. For instance, we could
// choose the most recent one, or the one that is closest to our current size.
// The timeout, in seconds, we use when waiting for a DidUpdateBackingStoreState message when we're asked to paint.
m_webPageProxy.process().connection()->waitForAndDispatchImmediately<Messages::DrawingAreaProxy::DidUpdateBackingStoreState>(m_webPageProxy.pageID(), std::chrono::milliseconds(500));
}
void CoordinatedDrawingAreaProxy::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
{
ASSERT(!isInAcceleratedCompositingMode());
m_layerTreeContext = layerTreeContext;
m_webPageProxy.enterAcceleratedCompositingMode(layerTreeContext);
}
void CoordinatedDrawingAreaProxy::setVisibleContentsRect(const WebCore::FloatRect& visibleContentsRect, const WebCore::FloatPoint& trajectoryVector)
{
m_coordinatedLayerTreeHostProxy->setVisibleContentsRect(visibleContentsRect, trajectoryVector);
}
void CoordinatedDrawingAreaProxy::exitAcceleratedCompositingMode()
{
ASSERT(isInAcceleratedCompositingMode());
m_layerTreeContext = LayerTreeContext();
m_webPageProxy.exitAcceleratedCompositingMode();
}
void CoordinatedDrawingAreaProxy::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
{
ASSERT(isInAcceleratedCompositingMode());
m_layerTreeContext = layerTreeContext;
m_webPageProxy.updateAcceleratedCompositingMode(layerTreeContext);
}
} // namespace WebKit
#endif // USE(COORDINATED_GRAPHICS)
|