| Differences between
and this patch
- a/Source/WebCore/ChangeLog +69 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2013-03-13  Gwang Yoon Hwang  <ryumiel@company100.net>
2
3
        Coordinated Graphics: Separate CoordinatedLayerTreeHost into CoordinatedLayerTreeHost and CompositingCoordinator
4
        https://bugs.webkit.org/show_bug.cgi?id=104360
5
6
        Reviewed by Noam Rosenthal.
7
8
        The CoordinatedLayerTreeHost has too many responsibilities. It
9
        implements LayerTreeHost, GraphicsLayerClient,
10
        CoordinatedGraphicsLayerClient, CoordinatedImageBacking::Client,
11
        UpdateAtlas::Client, GraphicsLayerFactory and
12
        WebCustomFilterProgramProxyClient.
13
14
        This refactoring reduces the responsibilities of CoordinatedLayerTreeHost.
15
16
        This patch introduces a new class called CompositingCoordinator, which
17
        takes the responsibility of managing compositing resources in
18
        WebProcess.
19
20
        CoordinatedLayerTreeHost is responsible only for the scheduling and
21
        IPC-specific stuff, which are relevant only for WebKit2.
22
23
        No new tests, covered by existing tests.
24
25
        * CMakeLists.txt:
26
        * Target.pri:
27
        * platform/graphics/texmap/coordinated/CompositingCoordinator.cpp: Added.
28
        (WebCore::CompositingCoordinator::create):
29
        (WebCore::CompositingCoordinator::~CompositingCoordinator):
30
        (WebCore::CompositingCoordinator::CompositingCoordinator):
31
        (WebCore::CompositingCoordinator::setRootCompositingLayer):
32
        (WebCore::CompositingCoordinator::sizeDidChange):
33
        (WebCore::CompositingCoordinator::flushPendingLayerChanges):
34
        (WebCore::CompositingCoordinator::syncDisplayState):
35
        (WebCore::CompositingCoordinator::nextAnimationServiceTime):
36
        (WebCore::CompositingCoordinator::clearPendingStateChanges):
37
        (WebCore::CompositingCoordinator::initializeRootCompositingLayerIfNeeded):
38
        (WebCore::CompositingCoordinator::createRootLayer):
39
        (WebCore::CompositingCoordinator::syncLayerState):
40
        (WebCore::CompositingCoordinator::createImageBackingIfNeeded):
41
        (WebCore::CompositingCoordinator::createImageBacking):
42
        (WebCore::CompositingCoordinator::updateImageBacking):
43
        (WebCore::CompositingCoordinator::clearImageBackingContents):
44
        (WebCore::CompositingCoordinator::removeImageBacking):
45
        (WebCore::CompositingCoordinator::flushPendingImageBackingChanges):
46
        (WebCore::CompositingCoordinator::notifyAnimationStarted):
47
        (WebCore::CompositingCoordinator::notifyFlushRequired):
48
        (WebCore::CompositingCoordinator::paintContents):
49
        (WebCore::CompositingCoordinator::createGraphicsLayer):
50
        (WebCore::CompositingCoordinator::deviceScaleFactor):
51
        (WebCore::CompositingCoordinator::pageScaleFactor):
52
        (WebCore::CompositingCoordinator::createUpdateAtlas):
53
        (WebCore::CompositingCoordinator::removeUpdateAtlas):
54
        (WebCore::CompositingCoordinator::visibleContentsRect):
55
        (WebCore::CompositingCoordinator::mainContentsLayer):
56
        (WebCore::CompositingCoordinator::setVisibleContentsRect):
57
        (WebCore::CompositingCoordinator::deviceOrPageScaleFactorChanged):
58
        (WebCore::CompositingCoordinator::detachLayer):
59
        (WebCore::CompositingCoordinator::commitScrollOffset):
60
        (WebCore::CompositingCoordinator::renderNextFrame):
61
        (WebCore::CompositingCoordinator::purgeBackingStores):
62
        (WebCore::CompositingCoordinator::paintToSurface):
63
        (WebCore::CompositingCoordinator::scheduleReleaseInactiveAtlases):
64
        (WebCore::CompositingCoordinator::releaseInactiveAtlasesTimerFired):
65
        * platform/graphics/texmap/coordinated/CompositingCoordinator.h: Added.
66
        (WebCore::CompositingCoordinator::clearRootLayer):
67
        (WebCore::CompositingCoordinator::rootLayer):
68
        (WebCore::CompositingCoordinator::state):
69
1
2013-06-26  Roger Fong  <roger_fong@apple.com>
70
2013-06-26  Roger Fong  <roger_fong@apple.com>
2
71
3
        Add an accessibility delegate interface to AppleWin port.
72
        Add an accessibility delegate interface to AppleWin port.
- a/Source/WebKit2/ChangeLog +50 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2013-03-13  Gwang Yoon Hwang  <ryumiel@company100.net>
2
3
        Coordinated Graphics: Separate CoordinatedLayerTreeHost into CoordinatedLayerTreeHost and CompositingCoordinator
4
        https://bugs.webkit.org/show_bug.cgi?id=104360
5
6
        Reviewed by Noam Rosenthal.
7
8
        The CoordinatedLayerTreeHost has too many responsibilities. It
9
        implements LayerTreeHost, GraphicsLayerClient,
10
        CoordinatedGraphicsLayerClient, CoordinatedImageBacking::Client,
11
        UpdateAtlas::Client, GraphicsLayerFactory and
12
        WebCustomFilterProgramProxyClient.
13
14
        This refactoring reduces the responsibilities of CoordinatedLayerTreeHost.
15
16
        This patch introduces a new class called CompositingCoordinator, which
17
        takes the responsibility of managing compositing resources in
18
        WebProcess.
19
20
        CoordinatedLayerTreeHost is responsible only for the scheduling and
21
        IPC-specific stuff, which are relevant only for WebKit2.
22
23
        No new tests, covered by existing tests.
24
25
        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
26
        (WebKit::CoordinatedLayerTreeHost::~CoordinatedLayerTreeHost):
27
        (WebKit::CoordinatedLayerTreeHost::CoordinatedLayerTreeHost):
28
        (WebKit::CoordinatedLayerTreeHost::setRootCompositingLayer):
29
        (WebKit::CoordinatedLayerTreeHost::invalidate):
30
        (WebKit::CoordinatedLayerTreeHost::forceRepaint):
31
        (WebKit::CoordinatedLayerTreeHost::sizeDidChange):
32
        (WebKit::CoordinatedLayerTreeHost::setVisibleContentsRect):
33
        (WebKit::CoordinatedLayerTreeHost::renderNextFrame):
34
        (WebKit::CoordinatedLayerTreeHost::purgeBackingStores):
35
        (WebKit::CoordinatedLayerTreeHost::willSyncLayerState):
36
        (WebKit::CoordinatedLayerTreeHost::prepareCustomFilterProxiesForAnimations):
37
        (WebKit::CoordinatedLayerTreeHost::checkCustomFilterProgramProxies):
38
        (WebKit::CoordinatedLayerTreeHost::removeCustomFilterProgramProxy):
39
        (WebKit::CoordinatedLayerTreeHost::didFlushRootLayer):
40
        (WebKit::CoordinatedLayerTreeHost::performScheduledLayerFlush):
41
        (WebKit::CoordinatedLayerTreeHost::createPageOverlayLayer):
42
        (WebKit::CoordinatedLayerTreeHost::paintLayerContents):
43
        (WebKit::CoordinatedLayerTreeHost::commitSceneState):
44
        (WebKit::CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged):
45
        (WebKit::CoordinatedLayerTreeHost::graphicsLayerFactory):
46
        (WebKit::CoordinatedLayerTreeHost::scheduleAnimation):
47
        (WebKit::CoordinatedLayerTreeHost::commitScrollOffset):
48
        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
49
        * WebProcess/WebPage/LayerTreeHost.h:
50
1
2013-06-26  Simon Cooper  <scooper@apple.com>
51
2013-06-26  Simon Cooper  <scooper@apple.com>
2
52
3
        QuickTime plug-in cannot update com.apple.quicktime.plugin.preferences.plist file
53
        QuickTime plug-in cannot update com.apple.quicktime.plugin.preferences.plist file
- a/Source/WebCore/CMakeLists.txt +1 lines
Lines 1978-1983 set(WebCore_SOURCES a/Source/WebCore/CMakeLists.txt_sec1
1978
    platform/graphics/filters/SpotLightSource.cpp
1978
    platform/graphics/filters/SpotLightSource.cpp
1979
1979
1980
    platform/graphics/texmap/coordinated/AreaAllocator.cpp
1980
    platform/graphics/texmap/coordinated/AreaAllocator.cpp
1981
    platform/graphics/texmap/coordinated/CompositingCoordinator.cpp
1981
    platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp
1982
    platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp
1982
    platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp
1983
    platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp
1983
    platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp
1984
    platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp
- a/Source/WebCore/Target.pri +2 lines
Lines 4089-4094 use?(3D_GRAPHICS) { a/Source/WebCore/Target.pri_sec1
4089
        platform/graphics/texmap/TextureMapperGL.h \
4089
        platform/graphics/texmap/TextureMapperGL.h \
4090
        platform/graphics/texmap/TextureMapperShaderProgram.h \
4090
        platform/graphics/texmap/TextureMapperShaderProgram.h \
4091
        platform/graphics/texmap/coordinated/AreaAllocator.h \
4091
        platform/graphics/texmap/coordinated/AreaAllocator.h \
4092
        platform/graphics/texmap/coordinated/CompositingCoordinator.h \
4092
        platform/graphics/texmap/coordinated/CoordinatedBackingStore.h \
4093
        platform/graphics/texmap/coordinated/CoordinatedBackingStore.h \
4093
        platform/graphics/texmap/coordinated/CoordinatedCustomFilterOperation.h \
4094
        platform/graphics/texmap/coordinated/CoordinatedCustomFilterOperation.h \
4094
        platform/graphics/texmap/coordinated/CoordinatedCustomFilterProgram.h \
4095
        platform/graphics/texmap/coordinated/CoordinatedCustomFilterProgram.h \
Lines 4124-4129 use?(3D_GRAPHICS) { a/Source/WebCore/Target.pri_sec2
4124
        platform/graphics/texmap/TextureMapperGL.cpp \
4125
        platform/graphics/texmap/TextureMapperGL.cpp \
4125
        platform/graphics/texmap/TextureMapperShaderProgram.cpp \
4126
        platform/graphics/texmap/TextureMapperShaderProgram.cpp \
4126
        platform/graphics/texmap/coordinated/AreaAllocator.cpp \
4127
        platform/graphics/texmap/coordinated/AreaAllocator.cpp \
4128
        platform/graphics/texmap/coordinated/CompositingCoordinator.cpp \
4127
        platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp \
4129
        platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp \
4128
        platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp \
4130
        platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp \
4129
        platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp \
4131
        platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp \
- a/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp +434 lines
Line 0 a/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp_sec1
1
/*
2
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
3
 * Copyright (C) 2013 Company 100, Inc. All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#include "config.h"
28
29
#if USE(COORDINATED_GRAPHICS)
30
#include "CompositingCoordinator.h"
31
32
#include "Frame.h"
33
#include "FrameView.h"
34
#include "GraphicsContext.h"
35
#include "InspectorController.h"
36
#include "Page.h"
37
#include "Settings.h"
38
#include <wtf/CurrentTime.h>
39
#include <wtf/TemporaryChange.h>
40
41
namespace WebCore {
42
43
PassOwnPtr<CompositingCoordinator> CompositingCoordinator::create(Page* page, CompositingCoordinator::Client* client)
44
{
45
    return adoptPtr(new CompositingCoordinator(page, client));
46
}
47
48
CompositingCoordinator::~CompositingCoordinator()
49
{
50
    purgeBackingStores();
51
52
    LayerMap::iterator end = m_registeredLayers.end();
53
    for (LayerMap::iterator it = m_registeredLayers.begin(); it != end; ++it)
54
        it->value->setCoordinator(0);
55
}
56
57
CompositingCoordinator::CompositingCoordinator(Page* page, CompositingCoordinator::Client* client)
58
    : m_page(page)
59
    , m_client(client)
60
    , m_rootCompositingLayer(0)
61
    , m_isPurging(false)
62
    , m_isFlushingLayerChanges(false)
63
    , m_shouldSyncFrame(false)
64
    , m_didInitializeRootCompositingLayer(false)
65
    , m_releaseInactiveAtlasesTimer(this, &CompositingCoordinator::releaseInactiveAtlasesTimerFired)
66
#if ENABLE(REQUEST_ANIMATION_FRAME)
67
    , m_lastAnimationServiceTime(0)
68
#endif
69
{
70
    m_page->settings()->setApplyDeviceScaleFactorInCompositor(true);
71
72
    // This is a temporary way to enable this only in the GL case, until TextureMapperImageBuffer is removed.
73
    // See https://bugs.webkit.org/show_bug.cgi?id=114869
74
    CoordinatedGraphicsLayer::setShouldSupportContentsTiling(true);
75
}
76
77
void CompositingCoordinator::setRootCompositingLayer(GraphicsLayer* layer)
78
{
79
    if (m_rootCompositingLayer)
80
        m_rootCompositingLayer->removeFromParent();
81
82
    m_rootCompositingLayer = layer;
83
    if (m_rootCompositingLayer)
84
        m_rootLayer->addChildAtIndex(m_rootCompositingLayer, 0);
85
}
86
87
void CompositingCoordinator::sizeDidChange(const IntSize& newSize)
88
{
89
    m_rootLayer->setSize(newSize);
90
    m_client->notifyFlushRequired();
91
}
92
93
bool CompositingCoordinator::flushPendingLayerChanges()
94
{
95
    TemporaryChange<bool> protector(m_isFlushingLayerChanges, true);
96
97
    initializeRootCompositingLayerIfNeeded();
98
99
    m_rootLayer->flushCompositingStateForThisLayerOnly();
100
    m_client->didFlushRootLayer();
101
102
    bool didSync = m_page->mainFrame()->view()->flushCompositingStateIncludingSubframes();
103
104
    toCoordinatedGraphicsLayer(m_rootLayer.get())->updateContentBuffersIncludingSubLayers();
105
    toCoordinatedGraphicsLayer(m_rootLayer.get())->syncPendingStateChangesIncludingSubLayers();
106
107
    flushPendingImageBackingChanges();
108
109
    if (m_shouldSyncFrame) {
110
        didSync = true;
111
112
        if (m_rootCompositingLayer) {
113
            m_state.contentsSize = roundedIntSize(m_rootCompositingLayer->size());
114
            if (CoordinatedGraphicsLayer* contentsLayer = mainContentsLayer())
115
                m_state.coveredRect = contentsLayer->coverRect();
116
        }
117
        m_state.scrollPosition = m_visibleContentsRect.location();
118
119
        m_client->commitSceneState(m_state);
120
121
        clearPendingStateChanges();
122
        m_shouldSyncFrame = false;
123
    }
124
125
    return didSync;
126
}
127
128
void CompositingCoordinator::syncDisplayState()
129
{
130
#if ENABLE(INSPECTOR)
131
    m_page->inspectorController()->didBeginFrame();
132
#endif
133
134
#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
135
    // Make sure that any previously registered animation callbacks are being executed before we flush the layers.
136
    m_lastAnimationServiceTime = WTF::monotonicallyIncreasingTime();
137
    m_page->mainFrame()->view()->serviceScriptedAnimations(m_lastAnimationServiceTime);
138
#endif
139
    m_page->mainFrame()->view()->updateLayoutAndStyleIfNeededRecursive();
140
}
141
142
#if ENABLE(REQUEST_ANIMATION_FRAME)
143
double CompositingCoordinator::nextAnimationServiceTime() const
144
{
145
    // According to the requestAnimationFrame spec, rAF callbacks should not be faster than 60FPS.
146
    static const double MinimalTimeoutForAnimations = 1. / 60.;
147
    return std::max<double>(0., MinimalTimeoutForAnimations - WTF::monotonicallyIncreasingTime() + m_lastAnimationServiceTime);
148
}
149
#endif
150
151
void CompositingCoordinator::clearPendingStateChanges()
152
{
153
    m_state.layersToCreate.clear();
154
    m_state.layersToUpdate.clear();
155
    m_state.layersToRemove.clear();
156
157
    m_state.imagesToCreate.clear();
158
    m_state.imagesToRemove.clear();
159
    m_state.imagesToUpdate.clear();
160
    m_state.imagesToClear.clear();
161
162
    m_state.updateAtlasesToCreate.clear();
163
    m_state.updateAtlasesToRemove.clear();
164
165
#if ENABLE(CSS_SHADERS)
166
    m_state.customFiltersToCreate.clear();
167
    m_state.customFiltersToRemove.clear();
168
#endif
169
}
170
171
void CompositingCoordinator::initializeRootCompositingLayerIfNeeded()
172
{
173
    if (m_didInitializeRootCompositingLayer)
174
        return;
175
176
    m_state.rootCompositingLayer = toCoordinatedGraphicsLayer(m_rootLayer.get())->id();
177
    m_didInitializeRootCompositingLayer = true;
178
    m_shouldSyncFrame = true;
179
}
180
181
void CompositingCoordinator::createRootLayer(const IntSize& size)
182
{
183
    ASSERT(!m_rootLayer);
184
    // Create a root layer.
185
    m_rootLayer = GraphicsLayer::create(this, this);
186
#ifndef NDEBUG
187
    m_rootLayer->setName("CompositingCoordinator root layer");
188
#endif
189
    m_rootLayer->setDrawsContent(false);
190
    m_rootLayer->setSize(size);
191
}
192
193
void CompositingCoordinator::syncLayerState(CoordinatedLayerID id, CoordinatedGraphicsLayerState& state)
194
{
195
    m_shouldSyncFrame = true;
196
    m_client->willSyncLayerState(state);
197
    m_state.layersToUpdate.append(std::make_pair(id, state));
198
}
199
200
PassRefPtr<CoordinatedImageBacking> CompositingCoordinator::createImageBackingIfNeeded(Image* image)
201
{
202
    CoordinatedImageBackingID imageID = CoordinatedImageBacking::getCoordinatedImageBackingID(image);
203
    ImageBackingMap::iterator it = m_imageBackings.find(imageID);
204
    RefPtr<CoordinatedImageBacking> imageBacking;
205
    if (it == m_imageBackings.end()) {
206
        imageBacking = CoordinatedImageBacking::create(this, image);
207
        m_imageBackings.add(imageID, imageBacking);
208
    } else
209
        imageBacking = it->value;
210
211
    return imageBacking;
212
}
213
214
void CompositingCoordinator::createImageBacking(CoordinatedImageBackingID imageID)
215
{
216
    m_state.imagesToCreate.append(imageID);
217
}
218
219
void CompositingCoordinator::updateImageBacking(CoordinatedImageBackingID imageID, PassRefPtr<CoordinatedSurface> coordinatedSurface)
220
{
221
    m_shouldSyncFrame = true;
222
    m_state.imagesToUpdate.append(std::make_pair(imageID, coordinatedSurface));
223
}
224
225
void CompositingCoordinator::clearImageBackingContents(CoordinatedImageBackingID imageID)
226
{
227
    m_shouldSyncFrame = true;
228
    m_state.imagesToClear.append(imageID);
229
}
230
231
void CompositingCoordinator::removeImageBacking(CoordinatedImageBackingID imageID)
232
{
233
    if (m_isPurging)
234
        return;
235
236
    ASSERT(m_imageBackings.contains(imageID));
237
    m_imageBackings.remove(imageID);
238
239
    m_state.imagesToRemove.append(imageID);
240
}
241
242
void CompositingCoordinator::flushPendingImageBackingChanges()
243
{
244
    ImageBackingMap::iterator end = m_imageBackings.end();
245
    for (ImageBackingMap::iterator iter = m_imageBackings.begin(); iter != end; ++iter)
246
        iter->value->update();
247
}
248
249
void CompositingCoordinator::notifyAnimationStarted(const GraphicsLayer*, double /* time */)
250
{
251
}
252
253
void CompositingCoordinator::notifyFlushRequired(const GraphicsLayer*)
254
{
255
    m_client->notifyFlushRequired();
256
}
257
258
259
void CompositingCoordinator::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const IntRect& clipRect)
260
{
261
    m_client->paintLayerContents(graphicsLayer, graphicsContext, clipRect);
262
}
263
264
PassOwnPtr<GraphicsLayer> CompositingCoordinator::createGraphicsLayer(GraphicsLayerClient* client)
265
{
266
    CoordinatedGraphicsLayer* layer = new CoordinatedGraphicsLayer(client);
267
    layer->setCoordinator(this);
268
    m_registeredLayers.add(layer->id(), layer);
269
    m_state.layersToCreate.append(layer->id());
270
    layer->setNeedsVisibleRectAdjustment();
271
    m_client->notifyFlushRequired();
272
    return adoptPtr(layer);
273
}
274
275
float CompositingCoordinator::deviceScaleFactor() const
276
{
277
    return m_page->deviceScaleFactor();
278
}
279
280
float CompositingCoordinator::pageScaleFactor() const
281
{
282
    return m_page->pageScaleFactor();
283
}
284
285
void CompositingCoordinator::createUpdateAtlas(uint32_t atlasID, PassRefPtr<CoordinatedSurface> coordinatedSurface)
286
{
287
    m_state.updateAtlasesToCreate.append(std::make_pair(atlasID, coordinatedSurface));
288
}
289
290
void CompositingCoordinator::removeUpdateAtlas(uint32_t atlasID)
291
{
292
    if (m_isPurging)
293
        return;
294
    m_state.updateAtlasesToRemove.append(atlasID);
295
}
296
297
FloatRect CompositingCoordinator::visibleContentsRect() const
298
{
299
    return m_visibleContentsRect;
300
}
301
302
CoordinatedGraphicsLayer* CompositingCoordinator::mainContentsLayer()
303
{
304
    if (!m_rootCompositingLayer)
305
        return 0;
306
307
    return toCoordinatedGraphicsLayer(m_rootCompositingLayer)->findFirstDescendantWithContentsRecursively();
308
}
309
310
void CompositingCoordinator::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
311
{
312
    // A zero trajectoryVector indicates that tiles all around the viewport are requested.
313
    if (CoordinatedGraphicsLayer* contentsLayer = mainContentsLayer())
314
        contentsLayer->setVisibleContentRectTrajectoryVector(trajectoryVector);
315
316
    bool contentsRectDidChange = rect != m_visibleContentsRect;
317
    if (contentsRectDidChange) {
318
        m_visibleContentsRect = rect;
319
320
        LayerMap::iterator end = m_registeredLayers.end();
321
        for (LayerMap::iterator it = m_registeredLayers.begin(); it != end; ++it)
322
            it->value->setNeedsVisibleRectAdjustment();
323
    }
324
325
    FrameView* view = m_page->mainFrame()->view();
326
    if (view->useFixedLayout()) {
327
        // Round the rect instead of enclosing it to make sure that its size stays
328
        // the same while panning. This can have nasty effects on layout.
329
        view->setFixedVisibleContentRect(roundedIntRect(rect));
330
    }
331
}
332
333
void CompositingCoordinator::deviceOrPageScaleFactorChanged()
334
{
335
    m_rootLayer->deviceOrPageScaleFactorChanged();
336
}
337
338
void CompositingCoordinator::detachLayer(CoordinatedGraphicsLayer* layer)
339
{
340
    if (m_isPurging)
341
        return;
342
343
    m_registeredLayers.remove(layer->id());
344
345
    size_t index = m_state.layersToCreate.find(layer->id());
346
    if (index != notFound) {
347
        m_state.layersToCreate.remove(index);
348
        return;
349
    }
350
351
    m_state.layersToRemove.append(layer->id());
352
    m_client->notifyFlushRequired();
353
}
354
355
void CompositingCoordinator::commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset)
356
{
357
    LayerMap::iterator i = m_registeredLayers.find(layerID);
358
    if (i == m_registeredLayers.end())
359
        return;
360
361
    i->value->commitScrollOffset(offset);
362
}
363
364
void CompositingCoordinator::renderNextFrame()
365
{
366
    for (unsigned i = 0; i < m_updateAtlases.size(); ++i)
367
        m_updateAtlases[i]->didSwapBuffers();
368
}
369
370
void CompositingCoordinator::purgeBackingStores()
371
{
372
    TemporaryChange<bool> purgingToggle(m_isPurging, true);
373
374
    LayerMap::iterator end = m_registeredLayers.end();
375
    for (LayerMap::iterator it = m_registeredLayers.begin(); it != end; ++it)
376
        it->value->purgeBackingStores();
377
378
    m_imageBackings.clear();
379
    m_updateAtlases.clear();
380
}
381
382
bool CompositingCoordinator::paintToSurface(const IntSize& size, CoordinatedSurface::Flags flags, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client* client)
383
{
384
    for (unsigned i = 0; i < m_updateAtlases.size(); ++i) {
385
        UpdateAtlas* atlas = m_updateAtlases[i].get();
386
        if (atlas->supportsAlpha() == (flags & CoordinatedSurface::SupportsAlpha)) {
387
            // This will be false if there is no available buffer space.
388
            if (atlas->paintOnAvailableBuffer(size, atlasID, offset, client))
389
                return true;
390
        }
391
    }
392
393
    static const int ScratchBufferDimension = 1024; // Should be a power of two.
394
    m_updateAtlases.append(adoptPtr(new UpdateAtlas(this, ScratchBufferDimension, flags)));
395
    scheduleReleaseInactiveAtlases();
396
    return m_updateAtlases.last()->paintOnAvailableBuffer(size, atlasID, offset, client);
397
}
398
399
const double ReleaseInactiveAtlasesTimerInterval = 0.5;
400
401
void CompositingCoordinator::scheduleReleaseInactiveAtlases()
402
{
403
    if (!m_releaseInactiveAtlasesTimer.isActive())
404
        m_releaseInactiveAtlasesTimer.startRepeating(ReleaseInactiveAtlasesTimerInterval);
405
}
406
407
void CompositingCoordinator::releaseInactiveAtlasesTimerFired(Timer<CompositingCoordinator>*)
408
{
409
    // We always want to keep one atlas for non-composited content.
410
    OwnPtr<UpdateAtlas> atlasToKeepAnyway;
411
    bool foundActiveAtlasForNonCompositedContent = false;
412
    for (int i = m_updateAtlases.size() - 1;  i >= 0; --i) {
413
        UpdateAtlas* atlas = m_updateAtlases[i].get();
414
        if (!atlas->isInUse())
415
            atlas->addTimeInactive(ReleaseInactiveAtlasesTimerInterval);
416
        bool usableForNonCompositedContent = !atlas->supportsAlpha();
417
        if (atlas->isInactive()) {
418
            if (!foundActiveAtlasForNonCompositedContent && !atlasToKeepAnyway && usableForNonCompositedContent)
419
                atlasToKeepAnyway = m_updateAtlases[i].release();
420
            m_updateAtlases.remove(i);
421
        } else if (usableForNonCompositedContent)
422
            foundActiveAtlasForNonCompositedContent = true;
423
    }
424
425
    if (!foundActiveAtlasForNonCompositedContent && atlasToKeepAnyway)
426
        m_updateAtlases.append(atlasToKeepAnyway.release());
427
428
    if (m_updateAtlases.size() <= 1)
429
        m_releaseInactiveAtlasesTimer.stop();
430
}
431
432
} // namespace WebCore
433
434
#endif // USE(COORDINATED_GRAPHICS)
- a/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h +168 lines
Line 0 a/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h_sec1
1
/*
2
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3
 * Copyright (C) 2013 Company 100, Inc. All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#ifndef CompositingCoordinator_h
28
#define CompositingCoordinator_h
29
30
#if USE(COORDINATED_GRAPHICS)
31
32
#include "CoordinatedGraphicsLayer.h"
33
#include "CoordinatedGraphicsState.h"
34
#include "CoordinatedImageBacking.h"
35
#include "FloatPoint.h"
36
#include "GraphicsLayerClient.h"
37
#include "GraphicsLayerFactory.h"
38
#include "IntRect.h"
39
#include "Timer.h"
40
#include "UpdateAtlas.h"
41
#include <wtf/OwnPtr.h>
42
43
#if ENABLE(CSS_SHADERS)
44
#include "FilterOperations.h"
45
#endif
46
47
namespace WebCore {
48
49
class Page;
50
class GraphicsContext;
51
class GraphicsLayer;
52
class CoordinatedSurface;
53
54
class CompositingCoordinator : public GraphicsLayerClient
55
    , public CoordinatedGraphicsLayerClient
56
    , public CoordinatedImageBacking::Client
57
    , public UpdateAtlas::Client
58
    , public GraphicsLayerFactory {
59
    WTF_MAKE_NONCOPYABLE(CompositingCoordinator); WTF_MAKE_FAST_ALLOCATED;
60
public:
61
    class Client {
62
    public:
63
        virtual void didFlushRootLayer() = 0;
64
        virtual void willSyncLayerState(CoordinatedGraphicsLayerState&) = 0;
65
        virtual void notifyFlushRequired() = 0;
66
        virtual void commitSceneState(CoordinatedGraphicsState&) = 0;
67
        virtual void paintLayerContents(const GraphicsLayer*, GraphicsContext&, const IntRect& clipRect) = 0;
68
    };
69
70
    static PassOwnPtr<CompositingCoordinator> create(Page*, CompositingCoordinator::Client*);
71
    virtual ~CompositingCoordinator();
72
73
    void setRootCompositingLayer(GraphicsLayer*);
74
    void sizeDidChange(const IntSize& newSize);
75
    void deviceOrPageScaleFactorChanged();
76
77
    void setVisibleContentsRect(const FloatRect&, const FloatPoint&);
78
    void renderNextFrame();
79
    void purgeBackingStores();
80
    void commitScrollOffset(uint32_t layerID, const IntSize& offset);
81
82
    void createRootLayer(const IntSize&);
83
    void clearRootLayer() { m_rootLayer = nullptr; }
84
    GraphicsLayer* rootLayer() const { return m_rootLayer.get(); }
85
    CoordinatedGraphicsLayer* mainContentsLayer();
86
87
    bool flushPendingLayerChanges();
88
    CoordinatedGraphicsState& state() { return m_state; }
89
90
    void syncDisplayState();
91
92
#if ENABLE(REQUEST_ANIMATION_FRAME)
93
    double nextAnimationServiceTime() const;
94
#endif
95
96
private:
97
    CompositingCoordinator(Page*, CompositingCoordinator::Client*);
98
99
    // GraphicsLayerClient
100
    virtual void notifyAnimationStarted(const GraphicsLayer*, double time) OVERRIDE;
101
    virtual void notifyFlushRequired(const GraphicsLayer*) OVERRIDE;
102
    virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& clipRect) OVERRIDE;
103
    virtual float deviceScaleFactor() const OVERRIDE;
104
    virtual float pageScaleFactor() const OVERRIDE;
105
106
    // CoordinatedImageBacking::Client
107
    virtual void createImageBacking(CoordinatedImageBackingID) OVERRIDE;
108
    virtual void updateImageBacking(CoordinatedImageBackingID, PassRefPtr<CoordinatedSurface>) OVERRIDE;
109
    virtual void clearImageBackingContents(CoordinatedImageBackingID) OVERRIDE;
110
    virtual void removeImageBacking(CoordinatedImageBackingID) OVERRIDE;
111
112
    // CoordinatedGraphicsLayerClient
113
    virtual bool isFlushingLayerChanges() const OVERRIDE { return m_isFlushingLayerChanges; }
114
    virtual FloatRect visibleContentsRect() const OVERRIDE;
115
    virtual PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(Image*) OVERRIDE;
116
    virtual void detachLayer(CoordinatedGraphicsLayer*) OVERRIDE;
117
    virtual bool paintToSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags, uint32_t& /* atlasID */, WebCore::IntPoint&, WebCore::CoordinatedSurface::Client*) OVERRIDE;
118
    virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) OVERRIDE;
119
120
    // UpdateAtlas::Client
121
    virtual void createUpdateAtlas(uint32_t atlasID, PassRefPtr<CoordinatedSurface>) OVERRIDE;
122
    virtual void removeUpdateAtlas(uint32_t atlasID) OVERRIDE;
123
124
    // GraphicsLayerFactory
125
    virtual PassOwnPtr<GraphicsLayer> createGraphicsLayer(GraphicsLayerClient*) OVERRIDE;
126
127
    void initializeRootCompositingLayerIfNeeded();
128
    void flushPendingImageBackingChanges();
129
    void clearPendingStateChanges();
130
131
    void scheduleReleaseInactiveAtlases();
132
133
    void releaseInactiveAtlasesTimerFired(Timer<CompositingCoordinator>*);
134
135
    Page* m_page;
136
    CompositingCoordinator::Client* m_client;
137
138
    OwnPtr<GraphicsLayer> m_rootLayer;
139
    GraphicsLayer* m_rootCompositingLayer;
140
141
    CoordinatedGraphicsState m_state;
142
143
    typedef HashMap<CoordinatedLayerID, CoordinatedGraphicsLayer*> LayerMap;
144
    LayerMap m_registeredLayers;
145
    typedef HashMap<CoordinatedImageBackingID, RefPtr<CoordinatedImageBacking> > ImageBackingMap;
146
    ImageBackingMap m_imageBackings;
147
    Vector<OwnPtr<UpdateAtlas> > m_updateAtlases;
148
149
    // We don't send the messages related to releasing resources to renderer during purging, because renderer already had removed all resources.
150
    bool m_isPurging;
151
    bool m_isFlushingLayerChanges;
152
153
    FloatRect m_visibleContentsRect;
154
155
    bool m_shouldSyncFrame;
156
    bool m_didInitializeRootCompositingLayer;
157
    Timer<CompositingCoordinator> m_releaseInactiveAtlasesTimer;
158
159
#if ENABLE(REQUEST_ANIMATION_FRAME)
160
    double m_lastAnimationServiceTime;
161
#endif
162
};
163
164
}
165
166
#endif
167
168
#endif // CompositingCoordinator_h
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp -384 / +62 lines
Lines 40-57 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec1
40
#include "WebPageProxyMessages.h"
40
#include "WebPageProxyMessages.h"
41
#include <WebCore/Frame.h>
41
#include <WebCore/Frame.h>
42
#include <WebCore/FrameView.h>
42
#include <WebCore/FrameView.h>
43
#include <WebCore/GraphicsSurface.h>
44
#include <WebCore/InspectorController.h>
45
#include <WebCore/Page.h>
46
#include <WebCore/RenderLayer.h>
47
#include <WebCore/RenderLayerBacking.h>
48
#include <WebCore/RenderLayerCompositor.h>
49
#include <WebCore/RenderView.h>
50
#include <WebCore/Settings.h>
43
#include <WebCore/Settings.h>
51
#include <WebCore/SurfaceUpdateInfo.h>
52
#include <WebCore/TextureMapperPlatformLayer.h>
53
#include <wtf/CurrentTime.h>
44
#include <wtf/CurrentTime.h>
54
#include <wtf/TemporaryChange.h>
55
45
56
#if ENABLE(CSS_SHADERS)
46
#if ENABLE(CSS_SHADERS)
57
#include "CustomFilterValidatedProgram.h"
47
#include "CustomFilterValidatedProgram.h"
Lines 72-122 CoordinatedLayerTreeHost::~CoordinatedLayerTreeHost() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec2
72
#if ENABLE(CSS_SHADERS)
62
#if ENABLE(CSS_SHADERS)
73
    disconnectCustomFilterPrograms();
63
    disconnectCustomFilterPrograms();
74
#endif
64
#endif
75
    purgeBackingStores();
76
77
    LayerMap::iterator end = m_registeredLayers.end();
78
    for (LayerMap::iterator it = m_registeredLayers.begin(); it != end; ++it)
79
        it->value->setCoordinator(0);
80
}
65
}
81
66
82
CoordinatedLayerTreeHost::CoordinatedLayerTreeHost(WebPage* webPage)
67
CoordinatedLayerTreeHost::CoordinatedLayerTreeHost(WebPage* webPage)
83
    : LayerTreeHost(webPage)
68
    : LayerTreeHost(webPage)
84
    , m_rootCompositingLayer(0)
85
    , m_notifyAfterScheduledLayerFlush(false)
69
    , m_notifyAfterScheduledLayerFlush(false)
86
    , m_isValid(true)
70
    , m_isValid(true)
87
    , m_isPurging(false)
88
    , m_isFlushingLayerChanges(false)
89
    , m_waitingForUIProcess(true)
90
    , m_isSuspended(false)
71
    , m_isSuspended(false)
91
    , m_shouldSyncFrame(false)
72
    , m_isWaitingForRenderer(true)
92
    , m_didInitializeRootCompositingLayer(false)
93
    , m_layerFlushTimer(this, &CoordinatedLayerTreeHost::layerFlushTimerFired)
73
    , m_layerFlushTimer(this, &CoordinatedLayerTreeHost::layerFlushTimerFired)
94
    , m_releaseInactiveAtlasesTimer(this, &CoordinatedLayerTreeHost::releaseInactiveAtlasesTimerFired)
95
    , m_layerFlushSchedulingEnabled(true)
74
    , m_layerFlushSchedulingEnabled(true)
96
    , m_forceRepaintAsyncCallbackID(0)
75
    , m_forceRepaintAsyncCallbackID(0)
97
    , m_animationsLocked(false)
98
#if ENABLE(REQUEST_ANIMATION_FRAME)
99
    , m_lastAnimationServiceTime(0)
100
#endif
101
{
76
{
102
    m_webPage->corePage()->settings()->setApplyDeviceScaleFactorInCompositor(true);
77
    m_coordinator = CompositingCoordinator::create(webPage->corePage(), this);
103
78
104
    // Create a root layer.
79
    m_coordinator->createRootLayer(webPage->size());
105
    m_rootLayer = GraphicsLayer::create(this, this);
80
    m_layerTreeContext.coordinatedLayerID = toCoordinatedGraphicsLayer(m_coordinator->rootLayer())->id();
106
#ifndef NDEBUG
107
    m_rootLayer->setName("CoordinatedLayerTreeHost root layer");
108
#endif
109
    m_rootLayer->setDrawsContent(false);
110
    m_rootLayer->setSize(m_webPage->size());
111
    m_layerTreeContext.coordinatedLayerID = toCoordinatedGraphicsLayer(m_rootLayer.get())->id();
112
81
113
    CoordinatedSurface::setFactory(createCoordinatedSurface);
82
    CoordinatedSurface::setFactory(createCoordinatedSurface);
114
83
115
    // This is a temporary way to enable this only in the GL case, until TextureMapperImageBuffer is removed.
84
    if (webPage->hasPageOverlay())
116
    // See https://bugs.webkit.org/show_bug.cgi?id=114869
117
    CoordinatedGraphicsLayer::setShouldSupportContentsTiling(true);
118
119
    if (m_webPage->hasPageOverlay())
120
        createPageOverlayLayer();
85
        createPageOverlayLayer();
121
86
122
    scheduleLayerFlush();
87
    scheduleLayerFlush();
Lines 158-169 void CoordinatedLayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush(bool a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec3
158
123
159
void CoordinatedLayerTreeHost::setRootCompositingLayer(WebCore::GraphicsLayer* graphicsLayer)
124
void CoordinatedLayerTreeHost::setRootCompositingLayer(WebCore::GraphicsLayer* graphicsLayer)
160
{
125
{
161
    if (m_rootCompositingLayer)
126
    m_coordinator->setRootCompositingLayer(graphicsLayer);
162
        m_rootCompositingLayer->removeFromParent();
163
164
    m_rootCompositingLayer = graphicsLayer;
165
    if (m_rootCompositingLayer)
166
        m_rootLayer->addChildAtIndex(m_rootCompositingLayer, 0);
167
}
127
}
168
128
169
void CoordinatedLayerTreeHost::invalidate()
129
void CoordinatedLayerTreeHost::invalidate()
Lines 171-177 void CoordinatedLayerTreeHost::invalidate() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec4
171
    cancelPendingLayerFlush();
131
    cancelPendingLayerFlush();
172
132
173
    ASSERT(m_isValid);
133
    ASSERT(m_isValid);
174
    m_rootLayer = nullptr;
134
    m_coordinator->clearRootLayer();
175
    m_isValid = false;
135
    m_isValid = false;
176
}
136
}
177
137
Lines 179-190 void CoordinatedLayerTreeHost::forceRepaint() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec5
179
{
139
{
180
    // This is necessary for running layout tests. Since in this case we are not waiting for a UIProcess to reply nicely.
140
    // This is necessary for running layout tests. Since in this case we are not waiting for a UIProcess to reply nicely.
181
    // Instead we are just triggering forceRepaint. But we still want to have the scripted animation callbacks being executed.
141
    // Instead we are just triggering forceRepaint. But we still want to have the scripted animation callbacks being executed.
182
    syncDisplayState();
142
    m_coordinator->syncDisplayState();
183
143
184
    // We need to schedule another flush, otherwise the forced paint might cancel a later expected flush.
144
    // We need to schedule another flush, otherwise the forced paint might cancel a later expected flush.
185
    // This is aligned with LayerTreeHostCA.
145
    // This is aligned with LayerTreeHostCA.
186
    scheduleLayerFlush();
146
    scheduleLayerFlush();
187
    flushPendingLayerChanges();
147
    m_coordinator->flushPendingLayerChanges();
188
}
148
}
189
149
190
bool CoordinatedLayerTreeHost::forceRepaintAsync(uint64_t callbackID)
150
bool CoordinatedLayerTreeHost::forceRepaintAsync(uint64_t callbackID)
Lines 198-204 bool CoordinatedLayerTreeHost::forceRepaintAsync(uint64_t callbackID) a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec6
198
158
199
void CoordinatedLayerTreeHost::sizeDidChange(const WebCore::IntSize& newSize)
159
void CoordinatedLayerTreeHost::sizeDidChange(const WebCore::IntSize& newSize)
200
{
160
{
201
    m_rootLayer->setSize(newSize);
161
    m_coordinator->sizeDidChange(newSize);
202
    scheduleLayerFlush();
162
    scheduleLayerFlush();
203
}
163
}
204
164
Lines 233-343 void CoordinatedLayerTreeHost::setPageOverlayOpacity(PageOverlay*, float value) a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec7
233
    scheduleLayerFlush();
193
    scheduleLayerFlush();
234
}
194
}
235
195
236
bool CoordinatedLayerTreeHost::flushPendingLayerChanges()
196
void CoordinatedLayerTreeHost::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
237
{
197
{
238
    if (m_waitingForUIProcess)
198
    m_coordinator->setVisibleContentsRect(rect, trajectoryVector);
239
        return false;
199
    scheduleLayerFlush();
240
241
    TemporaryChange<bool> protector(m_isFlushingLayerChanges, true);
242
243
    initializeRootCompositingLayerIfNeeded();
244
245
    m_rootLayer->flushCompositingStateForThisLayerOnly();
246
    if (m_pageOverlayLayer)
247
        m_pageOverlayLayer->flushCompositingStateForThisLayerOnly();
248
249
    bool didSync = m_webPage->corePage()->mainFrame()->view()->flushCompositingStateIncludingSubframes();
250
251
    toCoordinatedGraphicsLayer(m_rootLayer.get())->updateContentBuffersIncludingSubLayers();
252
    toCoordinatedGraphicsLayer(m_rootLayer.get())->syncPendingStateChangesIncludingSubLayers();
253
254
    flushPendingImageBackingChanges();
255
256
    if (m_shouldSyncFrame) {
257
        didSync = true;
258
259
        if (m_rootCompositingLayer) {
260
            m_state.contentsSize = roundedIntSize(m_rootCompositingLayer->size());
261
            if (CoordinatedGraphicsLayer* contentsLayer = mainContentsLayer())
262
                m_state.coveredRect = contentsLayer->coverRect();
263
        }
264
265
        m_state.scrollPosition = m_visibleContentsRect.location();
266
267
        m_webPage->send(Messages::CoordinatedLayerTreeHostProxy::CommitCoordinatedGraphicsState(m_state));
268
269
        clearPendingStateChanges();
270
        m_waitingForUIProcess = true;
271
        m_shouldSyncFrame = false;
272
    }
273
274
    if (m_forceRepaintAsyncCallbackID) {
275
        m_webPage->send(Messages::WebPageProxy::VoidCallback(m_forceRepaintAsyncCallbackID));
276
        m_forceRepaintAsyncCallbackID = 0;
277
    }
278
279
    return didSync;
280
}
200
}
281
201
282
void CoordinatedLayerTreeHost::clearPendingStateChanges()
202
void CoordinatedLayerTreeHost::renderNextFrame()
283
{
203
{
284
    m_state.layersToCreate.clear();
204
    m_coordinator->renderNextFrame();
285
    m_state.layersToUpdate.clear();
205
    m_isWaitingForRenderer = false;
286
    m_state.layersToRemove.clear();
206
    scheduleLayerFlush();
287
288
    m_state.imagesToCreate.clear();
289
    m_state.imagesToRemove.clear();
290
    m_state.imagesToUpdate.clear();
291
    m_state.imagesToClear.clear();
292
293
    m_state.updateAtlasesToCreate.clear();
294
    m_state.updateAtlasesToRemove.clear();
295
296
#if ENABLE(CSS_SHADERS)
297
    m_state.customFiltersToCreate.clear();
298
    m_state.customFiltersToRemove.clear();
299
#endif
300
}
207
}
301
208
302
void CoordinatedLayerTreeHost::initializeRootCompositingLayerIfNeeded()
209
void CoordinatedLayerTreeHost::purgeBackingStores()
303
{
210
{
304
    if (m_didInitializeRootCompositingLayer)
211
    m_coordinator->purgeBackingStores();
305
        return;
306
307
    m_state.rootCompositingLayer = toCoordinatedGraphicsLayer(m_rootLayer.get())->id();
308
    m_didInitializeRootCompositingLayer = true;
309
    m_shouldSyncFrame = true;
310
}
212
}
311
213
312
void CoordinatedLayerTreeHost::syncLayerState(CoordinatedLayerID id, CoordinatedGraphicsLayerState& state)
214
void CoordinatedLayerTreeHost::willSyncLayerState(CoordinatedGraphicsLayerState& state)
313
{
215
{
314
    m_shouldSyncFrame = true;
315
316
#if ENABLE(CSS_SHADERS)
216
#if ENABLE(CSS_SHADERS)
317
    prepareCustomFilterProxiesIfNeeded(state);
217
    if (state.animationsChanged)
318
#endif
218
        prepareCustomFilterProxiesForAnimations(state.animations);
319
219
320
    m_state.layersToUpdate.append(std::make_pair(id, state));
220
    if (state.filtersChanged)
221
        checkCustomFilterProgramProxies(state.filters);
222
#else
223
    UNUSED_PARAM(state);
224
#endif
321
}
225
}
322
226
323
#if ENABLE(CSS_SHADERS)
227
#if ENABLE(CSS_SHADERS)
324
void CoordinatedLayerTreeHost::prepareCustomFilterProxiesIfNeeded(CoordinatedGraphicsLayerState& state)
228
void CoordinatedLayerTreeHost::prepareCustomFilterProxiesForAnimations(GraphicsLayerAnimations& activeAnimations)
325
{
229
{
326
    if (state.animationsChanged) {
230
    for (size_t i = 0; i < activeAnimations.animations().size(); ++i) {
327
        GraphicsLayerAnimations& activeAnimations = state.animations;
231
        const KeyframeValueList& keyframes = activeAnimations.animations().at(i).keyframes();
328
        for (size_t i = 0; i < activeAnimations.animations().size(); ++i) {
232
        if (keyframes.property() != AnimatedPropertyWebkitFilter)
329
            const KeyframeValueList& keyframes = activeAnimations.animations().at(i).keyframes();
233
            continue;
330
            if (keyframes.property() != AnimatedPropertyWebkitFilter)
234
        for (size_t j = 0; j < keyframes.size(); ++j) {
331
                continue;
235
            const FilterAnimationValue& filterValue = static_cast<const FilterAnimationValue&>(keyframes.at(j));
332
            for (size_t j = 0; j < keyframes.size(); ++j) {
236
            checkCustomFilterProgramProxies(filterValue.value());
333
                const FilterAnimationValue& filterValue = static_cast<const FilterAnimationValue&>(keyframes.at(j));
334
                checkCustomFilterProgramProxies(filterValue.value());
335
            }
336
        }
237
        }
337
    }
238
    }
338
339
    if (state.filtersChanged)
340
        checkCustomFilterProgramProxies(state.filters);
341
}
239
}
342
240
343
void CoordinatedLayerTreeHost::checkCustomFilterProgramProxies(const FilterOperations& filters)
241
void CoordinatedLayerTreeHost::checkCustomFilterProgramProxies(const FilterOperations& filters)
Lines 367-373 void CoordinatedLayerTreeHost::checkCustomFilterProgramProxies(const FilterOpera a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec8
367
        if (!customFilterProgramProxy->client()) {
265
        if (!customFilterProgramProxy->client()) {
368
            customFilterProgramProxy->setClient(this);
266
            customFilterProgramProxy->setClient(this);
369
            m_customFilterPrograms.add(customFilterProgramProxy.get());
267
            m_customFilterPrograms.add(customFilterProgramProxy.get());
370
            m_state.customFiltersToCreate.append(std::make_pair(customFilterProgramProxy->id(), customOperation->validatedProgram()->validatedProgramInfo()));
268
            m_coordinator->state().customFiltersToCreate.append(std::make_pair(customFilterProgramProxy->id(), customOperation->validatedProgram()->validatedProgramInfo()));
371
        } else {
269
        } else {
372
            // If the client was not disconnected then this coordinator must be the client for it.
270
            // If the client was not disconnected then this coordinator must be the client for it.
373
            ASSERT(customFilterProgramProxy->client() == this);
271
            ASSERT(customFilterProgramProxy->client() == this);
Lines 380-386 void CoordinatedLayerTreeHost::removeCustomFilterProgramProxy(WebCustomFilterPro a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec9
380
    // At this time the shader is not needed anymore, so we remove it from our set and
278
    // At this time the shader is not needed anymore, so we remove it from our set and
381
    // send a message to the other process to delete it.
279
    // send a message to the other process to delete it.
382
    m_customFilterPrograms.remove(customFilterProgramProxy);
280
    m_customFilterPrograms.remove(customFilterProgramProxy);
383
    m_state.customFiltersToRemove.append(customFilterProgramProxy->id());
281
    m_coordinator->state().customFiltersToRemove.append(customFilterProgramProxy->id());
384
}
282
}
385
283
386
void CoordinatedLayerTreeHost::disconnectCustomFilterPrograms()
284
void CoordinatedLayerTreeHost::disconnectCustomFilterPrograms()
Lines 392-443 void CoordinatedLayerTreeHost::disconnectCustomFilterPrograms() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec10
392
}
290
}
393
#endif // ENABLE(CSS_SHADERS)
291
#endif // ENABLE(CSS_SHADERS)
394
292
395
void CoordinatedLayerTreeHost::detachLayer(CoordinatedGraphicsLayer* layer)
293
void CoordinatedLayerTreeHost::didFlushRootLayer()
396
{
294
{
397
    m_registeredLayers.remove(layer->id());
295
    if (m_pageOverlayLayer)
398
296
        m_pageOverlayLayer->flushCompositingStateForThisLayerOnly();
399
    size_t index = m_state.layersToCreate.find(layer->id());
400
    if (index != notFound) {
401
        m_state.layersToCreate.remove(index);
402
        return;
403
    }
404
405
    m_state.layersToRemove.append(layer->id());
406
    scheduleLayerFlush();
407
}
297
}
408
298
409
void CoordinatedLayerTreeHost::performScheduledLayerFlush()
299
void CoordinatedLayerTreeHost::performScheduledLayerFlush()
410
{
300
{
411
    if (m_isSuspended || m_waitingForUIProcess)
301
    if (m_isSuspended || m_isWaitingForRenderer)
412
        return;
302
        return;
413
303
414
    syncDisplayState();
304
    m_coordinator->syncDisplayState();
415
305
416
    if (!m_isValid)
306
    if (!m_isValid)
417
        return;
307
        return;
418
308
419
    if (flushPendingLayerChanges())
309
    bool didSync = m_coordinator->flushPendingLayerChanges();
420
        didPerformScheduledLayerFlush();
421
}
422
423
void CoordinatedLayerTreeHost::syncDisplayState()
424
{
425
#if ENABLE(INSPECTOR)
426
    m_webPage->corePage()->inspectorController()->didBeginFrame();
427
#endif
428
429
#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
430
    // Make sure that any previously registered animation callbacks are being executed before we flush the layers.
431
    m_lastAnimationServiceTime = WTF::monotonicallyIncreasingTime();
432
    m_webPage->corePage()->mainFrame()->view()->serviceScriptedAnimations(m_lastAnimationServiceTime);
433
#endif
434
310
435
    m_webPage->layoutIfNeeded();
311
    if (m_forceRepaintAsyncCallbackID) {
436
}
312
        m_webPage->send(Messages::WebPageProxy::VoidCallback(m_forceRepaintAsyncCallbackID));
313
        m_forceRepaintAsyncCallbackID = 0;
314
    }
437
315
438
void CoordinatedLayerTreeHost::didPerformScheduledLayerFlush()
316
    if (m_notifyAfterScheduledLayerFlush && didSync) {
439
{
440
    if (m_notifyAfterScheduledLayerFlush) {
441
        static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
317
        static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
442
        m_notifyAfterScheduledLayerFlush = false;
318
        m_notifyAfterScheduledLayerFlush = false;
443
    }
319
    }
Lines 452-466 void CoordinatedLayerTreeHost::createPageOverlayLayer() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec11
452
{
328
{
453
    ASSERT(!m_pageOverlayLayer);
329
    ASSERT(!m_pageOverlayLayer);
454
330
455
    m_pageOverlayLayer = GraphicsLayer::create(this, this);
331
    m_pageOverlayLayer = GraphicsLayer::create(graphicsLayerFactory(), m_coordinator.get());
456
#ifndef NDEBUG
332
#ifndef NDEBUG
457
    m_pageOverlayLayer->setName("CoordinatedLayerTreeHost page overlay content");
333
    m_pageOverlayLayer->setName("CompositingCoordinator page overlay content");
458
#endif
334
#endif
459
335
460
    m_pageOverlayLayer->setDrawsContent(true);
336
    m_pageOverlayLayer->setDrawsContent(true);
461
    m_pageOverlayLayer->setSize(m_webPage->size());
337
    m_pageOverlayLayer->setSize(m_coordinator->rootLayer()->size());
462
338
463
    m_rootLayer->addChild(m_pageOverlayLayer.get());
339
    m_coordinator->rootLayer()->addChild(m_pageOverlayLayer.get());
464
}
340
}
465
341
466
void CoordinatedLayerTreeHost::destroyPageOverlayLayer()
342
void CoordinatedLayerTreeHost::destroyPageOverlayLayer()
Lines 470-534 void CoordinatedLayerTreeHost::destroyPageOverlayLayer() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec12
470
    m_pageOverlayLayer = nullptr;
346
    m_pageOverlayLayer = nullptr;
471
}
347
}
472
348
473
PassRefPtr<CoordinatedImageBacking> CoordinatedLayerTreeHost::createImageBackingIfNeeded(Image* image)
349
void CoordinatedLayerTreeHost::paintLayerContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, const IntRect& clipRect)
474
{
475
    CoordinatedImageBackingID imageID = CoordinatedImageBacking::getCoordinatedImageBackingID(image);
476
    ImageBackingMap::iterator it = m_imageBackings.find(imageID);
477
    RefPtr<CoordinatedImageBacking> imageBacking;
478
    if (it == m_imageBackings.end()) {
479
        imageBacking = CoordinatedImageBacking::create(this, image);
480
        m_imageBackings.add(imageID, imageBacking);
481
    } else
482
        imageBacking = it->value;
483
484
    return imageBacking;
485
}
486
487
void CoordinatedLayerTreeHost::createImageBacking(CoordinatedImageBackingID imageID)
488
{
489
    m_state.imagesToCreate.append(imageID);
490
}
491
492
void CoordinatedLayerTreeHost::updateImageBacking(CoordinatedImageBackingID imageID, PassRefPtr<CoordinatedSurface> coordinatedSurface)
493
{
494
    m_shouldSyncFrame = true;
495
    m_state.imagesToUpdate.append(std::make_pair(imageID, coordinatedSurface));
496
}
497
498
void CoordinatedLayerTreeHost::clearImageBackingContents(CoordinatedImageBackingID imageID)
499
{
500
    m_shouldSyncFrame = true;
501
    m_state.imagesToClear.append(imageID);
502
}
503
504
void CoordinatedLayerTreeHost::removeImageBacking(CoordinatedImageBackingID imageID)
505
{
506
    if (m_isPurging)
507
        return;
508
509
    ASSERT(m_imageBackings.contains(imageID));
510
    m_imageBackings.remove(imageID);
511
512
    m_state.imagesToRemove.append(imageID);
513
}
514
515
void CoordinatedLayerTreeHost::flushPendingImageBackingChanges()
516
{
517
    ImageBackingMap::iterator end = m_imageBackings.end();
518
    for (ImageBackingMap::iterator iter = m_imageBackings.begin(); iter != end; ++iter)
519
        iter->value->update();
520
}
521
522
void CoordinatedLayerTreeHost::notifyAnimationStarted(const WebCore::GraphicsLayer*, double /* time */)
523
{
524
}
525
526
void CoordinatedLayerTreeHost::notifyFlushRequired(const WebCore::GraphicsLayer*)
527
{
528
    scheduleLayerFlush();
529
}
530
531
void CoordinatedLayerTreeHost::paintContents(const WebCore::GraphicsLayer* graphicsLayer, WebCore::GraphicsContext& graphicsContext, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect)
532
{
350
{
533
    if (graphicsLayer == m_pageOverlayLayer) {
351
    if (graphicsLayer == m_pageOverlayLayer) {
534
        // Overlays contain transparent contents and won't clear the context as part of their rendering, so we do it here.
352
        // Overlays contain transparent contents and won't clear the context as part of their rendering, so we do it here.
Lines 538-552 void CoordinatedLayerTreeHost::paintContents(const WebCore::GraphicsLayer* graph a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec13
538
    }
356
    }
539
}
357
}
540
358
541
PassOwnPtr<GraphicsLayer> CoordinatedLayerTreeHost::createGraphicsLayer(GraphicsLayerClient* client)
359
void CoordinatedLayerTreeHost::commitSceneState(WebCore::CoordinatedGraphicsState& state)
542
{
360
{
543
    CoordinatedGraphicsLayer* layer = new CoordinatedGraphicsLayer(client);
361
    m_webPage->send(Messages::CoordinatedLayerTreeHostProxy::CommitCoordinatedGraphicsState(state));
544
    layer->setCoordinator(this);
362
    m_isWaitingForRenderer = true;
545
    m_registeredLayers.add(layer->id(), layer);
546
    m_state.layersToCreate.append(layer->id());
547
    layer->setNeedsVisibleRectAdjustment();
548
    scheduleLayerFlush();
549
    return adoptPtr(layer);
550
}
363
}
551
364
552
PassRefPtr<CoordinatedSurface> CoordinatedLayerTreeHost::createCoordinatedSurface(const IntSize& size, CoordinatedSurface::Flags flags)
365
PassRefPtr<CoordinatedSurface> CoordinatedLayerTreeHost::createCoordinatedSurface(const IntSize& size, CoordinatedSurface::Flags flags)
Lines 554-626 PassRefPtr<CoordinatedSurface> CoordinatedLayerTreeHost::createCoordinatedSurfac a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec14
554
    return WebCoordinatedSurface::create(size, flags);
367
    return WebCoordinatedSurface::create(size, flags);
555
}
368
}
556
369
557
float CoordinatedLayerTreeHost::deviceScaleFactor() const
558
{
559
    return m_webPage->deviceScaleFactor();
560
}
561
562
float CoordinatedLayerTreeHost::pageScaleFactor() const
563
{
564
    return m_webPage->pageScaleFactor();
565
}
566
567
bool LayerTreeHost::supportsAcceleratedCompositing()
370
bool LayerTreeHost::supportsAcceleratedCompositing()
568
{
371
{
569
    return true;
372
    return true;
570
}
373
}
571
374
572
void CoordinatedLayerTreeHost::createUpdateAtlas(uint32_t atlasID, PassRefPtr<CoordinatedSurface> coordinatedSurface)
573
{
574
    m_state.updateAtlasesToCreate.append(std::make_pair(atlasID, coordinatedSurface));
575
}
576
577
void CoordinatedLayerTreeHost::removeUpdateAtlas(uint32_t atlasID)
578
{
579
    if (m_isPurging)
580
        return;
581
    m_state.updateAtlasesToRemove.append(atlasID);
582
}
583
584
WebCore::FloatRect CoordinatedLayerTreeHost::visibleContentsRect() const
585
{
586
    return m_visibleContentsRect;
587
}
588
589
CoordinatedGraphicsLayer* CoordinatedLayerTreeHost::mainContentsLayer()
590
{
591
    if (!m_rootCompositingLayer)
592
        return 0;
593
594
    return toCoordinatedGraphicsLayer(m_rootCompositingLayer)->findFirstDescendantWithContentsRecursively();
595
}
596
597
void CoordinatedLayerTreeHost::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
598
{
599
    // A zero trajectoryVector indicates that tiles all around the viewport are requested.
600
    if (CoordinatedGraphicsLayer* contentsLayer = mainContentsLayer())
601
        contentsLayer->setVisibleContentRectTrajectoryVector(trajectoryVector);
602
603
    bool contentsRectDidChange = rect != m_visibleContentsRect;
604
    if (contentsRectDidChange) {
605
        m_visibleContentsRect = rect;
606
607
        LayerMap::iterator end = m_registeredLayers.end();
608
        for (LayerMap::iterator it = m_registeredLayers.begin(); it != end; ++it) {
609
            it->value->setNeedsVisibleRectAdjustment();
610
        }
611
    }
612
613
    scheduleLayerFlush();
614
    if (m_webPage->useFixedLayout()) {
615
        // Round the rect instead of enclosing it to make sure that its size stays
616
        // the same while panning. This can have nasty effects on layout.
617
        m_webPage->setFixedVisibleContentRect(roundedIntRect(rect));
618
    }
619
}
620
621
void CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged()
375
void CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged()
622
{
376
{
623
    m_rootLayer->deviceOrPageScaleFactorChanged();
377
    m_coordinator->deviceOrPageScaleFactorChanged();
624
    if (m_pageOverlayLayer)
378
    if (m_pageOverlayLayer)
625
        m_pageOverlayLayer->deviceOrPageScaleFactorChanged();
379
        m_pageOverlayLayer->deviceOrPageScaleFactorChanged();
626
}
380
}
Lines 631-725 void CoordinatedLayerTreeHost::pageBackgroundTransparencyChanged() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec15
631
385
632
GraphicsLayerFactory* CoordinatedLayerTreeHost::graphicsLayerFactory()
386
GraphicsLayerFactory* CoordinatedLayerTreeHost::graphicsLayerFactory()
633
{
387
{
634
    return this;
388
    return m_coordinator.get();
635
}
389
}
636
390
637
#if ENABLE(REQUEST_ANIMATION_FRAME)
391
#if ENABLE(REQUEST_ANIMATION_FRAME)
638
void CoordinatedLayerTreeHost::scheduleAnimation()
392
void CoordinatedLayerTreeHost::scheduleAnimation()
639
{
393
{
640
    if (m_waitingForUIProcess)
394
    if (m_isWaitingForRenderer)
641
        return;
395
        return;
642
396
643
    if (m_layerFlushTimer.isActive())
397
    if (m_layerFlushTimer.isActive())
644
        return;
398
        return;
645
399
646
    // According to the requestAnimationFrame spec, rAF callbacks should not be faster than 60FPS.
400
    m_layerFlushTimer.startOneShot(m_coordinator->nextAnimationServiceTime());
647
    static const double MinimalTimeoutForAnimations = 1. / 60.;
648
    m_layerFlushTimer.startOneShot(std::max<double>(0., MinimalTimeoutForAnimations - WTF::monotonicallyIncreasingTime() + m_lastAnimationServiceTime));
649
    scheduleLayerFlush();
401
    scheduleLayerFlush();
650
}
402
}
651
#endif
403
#endif
652
404
653
void CoordinatedLayerTreeHost::renderNextFrame()
654
{
655
    m_waitingForUIProcess = false;
656
    scheduleLayerFlush();
657
    for (unsigned i = 0; i < m_updateAtlases.size(); ++i)
658
        m_updateAtlases[i]->didSwapBuffers();
659
}
660
661
void CoordinatedLayerTreeHost::purgeBackingStores()
662
{
663
    TemporaryChange<bool> purgingToggle(m_isPurging, true);
664
665
    LayerMap::iterator end = m_registeredLayers.end();
666
    for (LayerMap::iterator it = m_registeredLayers.begin(); it != end; ++it)
667
        it->value->purgeBackingStores();
668
669
    m_imageBackings.clear();
670
    m_updateAtlases.clear();
671
}
672
673
bool CoordinatedLayerTreeHost::paintToSurface(const IntSize& size, CoordinatedSurface::Flags flags, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client* client)
674
{
675
    for (unsigned i = 0; i < m_updateAtlases.size(); ++i) {
676
        UpdateAtlas* atlas = m_updateAtlases[i].get();
677
        if (atlas->supportsAlpha() == (flags & CoordinatedSurface::SupportsAlpha)) {
678
            // This will false if there is no available buffer space.
679
            if (atlas->paintOnAvailableBuffer(size, atlasID, offset, client))
680
                return true;
681
        }
682
    }
683
684
    static const int ScratchBufferDimension = 1024; // Should be a power of two.
685
    m_updateAtlases.append(adoptPtr(new UpdateAtlas(this, ScratchBufferDimension, flags)));
686
    scheduleReleaseInactiveAtlases();
687
    return m_updateAtlases.last()->paintOnAvailableBuffer(size, atlasID, offset, client);
688
}
689
690
const double ReleaseInactiveAtlasesTimerInterval = 0.5;
691
692
void CoordinatedLayerTreeHost::scheduleReleaseInactiveAtlases()
693
{
694
    if (!m_releaseInactiveAtlasesTimer.isActive())
695
        m_releaseInactiveAtlasesTimer.startRepeating(ReleaseInactiveAtlasesTimerInterval);
696
}
697
698
void CoordinatedLayerTreeHost::releaseInactiveAtlasesTimerFired(Timer<CoordinatedLayerTreeHost>*)
699
{
700
    // We always want to keep one atlas for non-composited content.
701
    OwnPtr<UpdateAtlas> atlasToKeepAnyway;
702
    bool foundActiveAtlasForNonCompositedContent = false;
703
    for (int i = m_updateAtlases.size() - 1;  i >= 0; --i) {
704
        UpdateAtlas* atlas = m_updateAtlases[i].get();
705
        if (!atlas->isInUse())
706
            atlas->addTimeInactive(ReleaseInactiveAtlasesTimerInterval);
707
        bool usableForNonCompositedContent = !atlas->supportsAlpha();
708
        if (atlas->isInactive()) {
709
            if (!foundActiveAtlasForNonCompositedContent && !atlasToKeepAnyway && usableForNonCompositedContent)
710
                atlasToKeepAnyway = m_updateAtlases[i].release();
711
            m_updateAtlases.remove(i);
712
        } else if (usableForNonCompositedContent)
713
            foundActiveAtlasForNonCompositedContent = true;
714
    }
715
716
    if (!foundActiveAtlasForNonCompositedContent && atlasToKeepAnyway)
717
        m_updateAtlases.append(atlasToKeepAnyway.release());
718
719
    if (m_updateAtlases.size() <= 1)
720
        m_releaseInactiveAtlasesTimer.stop();
721
}
722
723
void CoordinatedLayerTreeHost::setBackgroundColor(const WebCore::Color& color)
405
void CoordinatedLayerTreeHost::setBackgroundColor(const WebCore::Color& color)
724
{
406
{
725
    m_webPage->send(Messages::CoordinatedLayerTreeHostProxy::SetBackgroundColor(color));
407
    m_webPage->send(Messages::CoordinatedLayerTreeHostProxy::SetBackgroundColor(color));
Lines 727-737 void CoordinatedLayerTreeHost::setBackgroundColor(const WebCore::Color& color) a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp_sec16
727
409
728
void CoordinatedLayerTreeHost::commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset)
410
void CoordinatedLayerTreeHost::commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset)
729
{
411
{
730
    LayerMap::iterator i = m_registeredLayers.find(layerID);
412
    m_coordinator->commitScrollOffset(layerID, offset);
731
    if (i == m_registeredLayers.end())
732
        return;
733
734
    i->value->commitScrollOffset(offset);
735
}
413
}
736
414
737
} // namespace WebKit
415
} // namespace WebKit
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h -79 / +17 lines
Lines 25-37 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h_sec1
25
25
26
#include "LayerTreeContext.h"
26
#include "LayerTreeContext.h"
27
#include "LayerTreeHost.h"
27
#include "LayerTreeHost.h"
28
#include "Timer.h"
28
#include <WebCore/CompositingCoordinator.h>
29
#include <WebCore/CoordinatedGraphicsLayer.h>
30
#include <WebCore/CoordinatedGraphicsState.h>
31
#include <WebCore/CoordinatedImageBacking.h>
32
#include <WebCore/GraphicsLayerClient.h>
33
#include <WebCore/GraphicsLayerFactory.h>
29
#include <WebCore/GraphicsLayerFactory.h>
34
#include <WebCore/UpdateAtlas.h>
35
#include <wtf/OwnPtr.h>
30
#include <wtf/OwnPtr.h>
36
31
37
#if ENABLE(CSS_SHADERS)
32
#if ENABLE(CSS_SHADERS)
Lines 46-56 namespace WebKit { a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h_sec2
46
41
47
class WebPage;
42
class WebPage;
48
43
49
class CoordinatedLayerTreeHost : public LayerTreeHost, WebCore::GraphicsLayerClient
44
class CoordinatedLayerTreeHost : public LayerTreeHost, public WebCore::CompositingCoordinator::Client
50
    , public WebCore::CoordinatedGraphicsLayerClient
51
    , public WebCore::CoordinatedImageBacking::Client
52
    , public WebCore::UpdateAtlas::Client
53
    , public WebCore::GraphicsLayerFactory
54
#if ENABLE(CSS_SHADERS)
45
#if ENABLE(CSS_SHADERS)
55
    , WebCustomFilterProgramProxyClient
46
    , WebCustomFilterProgramProxyClient
56
#endif
47
#endif
Lines 84-92 public: a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h_sec3
84
    virtual void deviceOrPageScaleFactorChanged() OVERRIDE;
75
    virtual void deviceOrPageScaleFactorChanged() OVERRIDE;
85
    virtual void pageBackgroundTransparencyChanged() OVERRIDE;
76
    virtual void pageBackgroundTransparencyChanged() OVERRIDE;
86
77
87
    virtual void renderNextFrame();
88
    virtual void purgeBackingStores();
89
    virtual void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
90
    virtual void didReceiveCoordinatedLayerTreeHostMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
78
    virtual void didReceiveCoordinatedLayerTreeHostMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
91
    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() OVERRIDE;
79
    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() OVERRIDE;
92
    WebCore::CoordinatedGraphicsLayer* mainContentsLayer();
80
    WebCore::CoordinatedGraphicsLayer* mainContentsLayer();
Lines 98-157 public: a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h_sec4
98
86
99
    static PassRefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
87
    static PassRefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
100
88
101
    void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
102
103
protected:
89
protected:
104
    explicit CoordinatedLayerTreeHost(WebPage*);
90
    explicit CoordinatedLayerTreeHost(WebPage*);
105
91
106
private:
92
private:
107
    // GraphicsLayerClient
108
    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
109
    virtual void notifyFlushRequired(const WebCore::GraphicsLayer*);
110
    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect);
111
    virtual float deviceScaleFactor() const OVERRIDE;
112
    virtual float pageScaleFactor() const OVERRIDE;
113
114
    // CoordinatedImageBacking::Client
115
    virtual void createImageBacking(WebCore::CoordinatedImageBackingID) OVERRIDE;
116
    virtual void updateImageBacking(WebCore::CoordinatedImageBackingID, PassRefPtr<WebCore::CoordinatedSurface>) OVERRIDE;
117
    virtual void clearImageBackingContents(WebCore::CoordinatedImageBackingID) OVERRIDE;
118
    virtual void removeImageBacking(WebCore::CoordinatedImageBackingID) OVERRIDE;
119
120
    void flushPendingImageBackingChanges();
121
122
    // CoordinatedGraphicsLayerClient
123
    virtual bool isFlushingLayerChanges() const OVERRIDE { return m_isFlushingLayerChanges; }
124
    virtual WebCore::FloatRect visibleContentsRect() const;
125
    virtual PassRefPtr<WebCore::CoordinatedImageBacking> createImageBackingIfNeeded(WebCore::Image*) OVERRIDE;
126
    virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*);
127
    virtual bool paintToSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags, uint32_t& /* atlasID */, WebCore::IntPoint&, WebCore::CoordinatedSurface::Client*) OVERRIDE;
128
    virtual void syncLayerState(WebCore::CoordinatedLayerID, WebCore::CoordinatedGraphicsLayerState&);
129
130
    // UpdateAtlas::Client
131
    virtual void createUpdateAtlas(uint32_t atlasID, PassRefPtr<WebCore::CoordinatedSurface>) OVERRIDE;
132
    virtual void removeUpdateAtlas(uint32_t atlasID) OVERRIDE;
133
134
    // GraphicsLayerFactory
135
    virtual PassOwnPtr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayerClient*) OVERRIDE;
136
137
    // CoordinatedLayerTreeHost
93
    // CoordinatedLayerTreeHost
138
    void initializeRootCompositingLayerIfNeeded();
139
    void createPageOverlayLayer();
94
    void createPageOverlayLayer();
140
    void destroyPageOverlayLayer();
95
    void destroyPageOverlayLayer();
141
    bool flushPendingLayerChanges();
142
    void clearPendingStateChanges();
143
    void cancelPendingLayerFlush();
96
    void cancelPendingLayerFlush();
144
    void performScheduledLayerFlush();
97
    void performScheduledLayerFlush();
145
    void didPerformScheduledLayerFlush();
98
    void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
146
    void syncDisplayState();
99
    void renderNextFrame();
147
    void layerFlushTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*);
100
    void purgeBackingStores();
101
    void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
148
102
149
    void scheduleReleaseInactiveAtlases();
103
    void layerFlushTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*);
150
104
151
    void releaseInactiveAtlasesTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*);
105
    // CompositingCoordinator::Client
106
    virtual void didFlushRootLayer() OVERRIDE;
107
    virtual void willSyncLayerState(WebCore::CoordinatedGraphicsLayerState&) OVERRIDE;
108
    virtual void notifyFlushRequired() OVERRIDE { scheduleLayerFlush(); };
109
    virtual void commitSceneState(WebCore::CoordinatedGraphicsState&) OVERRIDE;
110
    virtual void paintLayerContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) OVERRIDE;
152
111
153
#if ENABLE(CSS_SHADERS)
112
#if ENABLE(CSS_SHADERS)
154
    void prepareCustomFilterProxiesIfNeeded(WebCore::CoordinatedGraphicsLayerState&);
113
    void prepareCustomFilterProxiesForAnimations(WebCore::GraphicsLayerAnimations&);
155
114
156
    // WebCustomFilterProgramProxyClient
115
    // WebCustomFilterProgramProxyClient
157
    void removeCustomFilterProgramProxy(WebCustomFilterProgramProxy*);
116
    void removeCustomFilterProgramProxy(WebCustomFilterProgramProxy*);
Lines 160-206 private: a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h_sec5
160
    void disconnectCustomFilterPrograms();
119
    void disconnectCustomFilterPrograms();
161
#endif
120
#endif
162
121
163
    OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
122
    OwnPtr<WebCore::CompositingCoordinator> m_coordinator;
164
    WebCore::GraphicsLayer* m_rootCompositingLayer;
165
123
166
    // The page overlay layer. Will be null if there's no page overlay.
124
    // The page overlay layer. Will be null if there's no page overlay.
167
    OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer;
125
    OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer;
168
    RefPtr<PageOverlay> m_pageOverlay;
126
    RefPtr<PageOverlay> m_pageOverlay;
169
127
170
    WebCore::CoordinatedGraphicsState m_state;
171
172
    typedef HashMap<WebCore::CoordinatedLayerID, WebCore::CoordinatedGraphicsLayer*> LayerMap;
173
    LayerMap m_registeredLayers;
174
    typedef HashMap<WebCore::CoordinatedImageBackingID, RefPtr<WebCore::CoordinatedImageBacking> > ImageBackingMap;
175
    ImageBackingMap m_imageBackings;
176
    Vector<OwnPtr<WebCore::UpdateAtlas> > m_updateAtlases;
177
178
#if ENABLE(CSS_SHADERS)
128
#if ENABLE(CSS_SHADERS)
179
    HashSet<WebCustomFilterProgramProxy*> m_customFilterPrograms;
129
    HashSet<WebCustomFilterProgramProxy*> m_customFilterPrograms;
180
#endif
130
#endif
181
131
182
    bool m_notifyAfterScheduledLayerFlush;
132
    bool m_notifyAfterScheduledLayerFlush;
183
    bool m_isValid;
133
    bool m_isValid;
184
    // We don't send the messages related to releasing resources to UI Process during purging, because UI Process already had removed all resources.
185
    bool m_isPurging;
186
    bool m_isFlushingLayerChanges;
187
188
    bool m_waitingForUIProcess;
189
    bool m_isSuspended;
134
    bool m_isSuspended;
190
    WebCore::FloatRect m_visibleContentsRect;
135
    bool m_isWaitingForRenderer;
191
136
192
    LayerTreeContext m_layerTreeContext;
137
    LayerTreeContext m_layerTreeContext;
193
    bool m_shouldSyncFrame;
138
194
    bool m_didInitializeRootCompositingLayer;
195
    WebCore::Timer<CoordinatedLayerTreeHost> m_layerFlushTimer;
139
    WebCore::Timer<CoordinatedLayerTreeHost> m_layerFlushTimer;
196
    WebCore::Timer<CoordinatedLayerTreeHost> m_releaseInactiveAtlasesTimer;
197
    bool m_layerFlushSchedulingEnabled;
140
    bool m_layerFlushSchedulingEnabled;
198
    uint64_t m_forceRepaintAsyncCallbackID;
141
    uint64_t m_forceRepaintAsyncCallbackID;
199
    bool m_animationsLocked;
200
201
#if ENABLE(REQUEST_ANIMATION_FRAME)
202
    double m_lastAnimationServiceTime;
203
#endif
204
};
142
};
205
143
206
} // namespace WebKit
144
} // namespace WebKit
- a/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h -3 lines
Lines 87-95 public: a/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h_sec1
87
    virtual void setBackgroundColor(const WebCore::Color&) { }
87
    virtual void setBackgroundColor(const WebCore::Color&) { }
88
88
89
#if USE(COORDINATED_GRAPHICS)
89
#if USE(COORDINATED_GRAPHICS)
90
    virtual void setVisibleContentsRect(const WebCore::FloatRect&, float /* scale */, const WebCore::FloatPoint&) { }
91
    virtual void renderNextFrame() { }
92
    virtual void purgeBackingStores() { }
93
    virtual void didReceiveCoordinatedLayerTreeHostMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&) = 0;
90
    virtual void didReceiveCoordinatedLayerTreeHostMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&) = 0;
94
#endif
91
#endif
95
92

Return to Bug 104360