| Differences between
and this patch
- a/Source/WebKit2/ChangeLog +175 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2012-12-07  Gwang Yoon Hwang  <ryumiel@company100.net>
2
3
        Coordinated Graphics: Separeate LayerTreeCoordinator into LayerTreeCoordinator and CompositingCoordinator
4
        https://bugs.webkit.org/show_bug.cgi?id=104360
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        The LayerTreeCoordinator has too many responsibilities. It implements
9
        LayerTreeHost, GraphicsLayerClient, CoordinatedGraphicsLayerClient,
10
        CoordinatedImageBacking::Coordinator, UpdateAtlasClient,
11
        GraphicsLayerFactory and WebCustomFilterProgramProxyClient.
12
13
        This refactoring reduces the responsibilities of LayerTreeCoordinator.
14
15
        By creates a new class called CompositingCoordinator, which takes the
16
        responsibility of scheduling compositing task in WebProcess,
17
        LayerTreeCoordinator acts like simple LayerTreeHost.
18
19
        By extracting interfaces dealing with LayerTreeCoordinatorProxy to
20
        CompositingCoordinatorMessageClient, CompositingCoordinator is decoupled
21
        from IPC handling.
22
23
        WebCompositingCoordinatorMessageClient implements IPC handling for
24
        CompositingCoordinator and LayerTreeCoordinator.
25
        WebCustomFilterProgramProxyClient is stands for IPC handling, so
26
        WebCompositingCoordiantorMessageClient implements this interface, too.
27
28
        No new tests because no change in behavior.
29
30
        * CMakeLists.txt:
31
        * Target.pri:
32
        * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp:
33
        Added. It takes responsibiliy for scheduling compositing tasks and
34
        managing resources.
35
        (WebKit):
36
        (WebKit::CompositingCoordinator::create):
37
        (WebKit::CompositingCoordinator::~CompositingCoordinator):
38
        (WebKit::CompositingCoordinator::CompositingCoordinator):
39
        (WebKit::CompositingCoordinator::setLayerFlushSchedulingEnabled):
40
        (WebKit::CompositingCoordinator::scheduleLayerFlush):
41
        (WebKit::CompositingCoordinator::cancelPendingLayerFlush):
42
        (WebKit::CompositingCoordinator::setRootCompositingLayer):
43
        (WebKit::CompositingCoordinator::invalidate):
44
        (WebKit::CompositingCoordinator::setNeedsDisplayInRect):
45
        (WebKit::CompositingCoordinator::forceRepaint):
46
        (WebKit::CompositingCoordinator::sizeDidChange):
47
        (WebKit::CompositingCoordinator::flushPendingLayerChanges):
48
        (WebKit::CompositingCoordinator::syncLayerState):
49
        (WebKit::CompositingCoordinator::syncLayerChildren):
50
        (WebKit::CompositingCoordinator::createCanvas):
51
        (WebKit::CompositingCoordinator::syncCanvas):
52
        (WebKit::CompositingCoordinator::destroyCanvas):
53
        (WebKit::CompositingCoordinator::syncLayerFilters):
54
        (WebKit::CompositingCoordinator::detachLayer):
55
        (WebKit::updateOffsetFromViewportForSelf):
56
        (WebKit::updateOffsetFromViewportForLayer):
57
        (WebKit::CompositingCoordinator::syncFixedLayers):
58
        (WebKit::CompositingCoordinator::lockAnimations):
59
        (WebKit::CompositingCoordinator::unlockAnimations):
60
        (WebKit::CompositingCoordinator::performScheduledLayerFlush):
61
        (WebKit::CompositingCoordinator::syncDisplayState):
62
        (WebKit::CompositingCoordinator::layerFlushTimerFired):
63
        (WebKit::CompositingCoordinator::createPageOverlayLayer):
64
        (WebKit::CompositingCoordinator::destroyPageOverlayLayer):
65
        (WebKit::CompositingCoordinator::setPageOverlayNeedsDisplay):
66
        (WebKit::CompositingCoordinator::setPageOverlayOpacity):
67
        (WebKit::CompositingCoordinator::createImageBackingIfNeeded):
68
        (WebKit::CompositingCoordinator::createImageBacking):
69
        (WebKit::CompositingCoordinator::updateImageBacking):
70
        (WebKit::CompositingCoordinator::clearImageBackingContents):
71
        (WebKit::CompositingCoordinator::removeImageBacking):
72
        (WebKit::CompositingCoordinator::flushPendingImageBackingChanges):
73
        (WebKit::CompositingCoordinator::notifyAnimationStarted):
74
        (WebKit::CompositingCoordinator::notifyFlushRequired):
75
        (WebKit::CompositingCoordinator::paintContents):
76
        (WebKit::CompositingCoordinator::createGraphicsLayer):
77
        (WebKit::CompositingCoordinator::createTile):
78
        (WebKit::CompositingCoordinator::updateTile):
79
        (WebKit::CompositingCoordinator::removeTile):
80
        (WebKit::CompositingCoordinator::createUpdateAtlas):
81
        (WebKit::CompositingCoordinator::removeUpdateAtlas):
82
        (WebKit::CompositingCoordinator::visibleContentsRect):
83
        (WebKit::CompositingCoordinator::setLayerAnimations):
84
        (WebKit::CompositingCoordinator::setVisibleContentsRect):
85
        (WebKit::CompositingCoordinator::renderNextFrame):
86
        (WebKit::CompositingCoordinator::layerTreeTileUpdatesAllowed):
87
        (WebKit::CompositingCoordinator::purgeBackingStores):
88
        (WebKit::CompositingCoordinator::beginContentUpdate):
89
        (WebKit::CompositingCoordinator::scheduleReleaseInactiveAtlases):
90
        (WebKit::CompositingCoordinator::releaseInactiveAtlasesTimerFired):
91
        * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h:
92
        Added.
93
        (WebCore):
94
        (WebKit):
95
        (CompositingCoordinator):
96
        (WebKit::CompositingCoordinator::pauseRendering):
97
        (WebKit::CompositingCoordinator::resumeRendering):
98
        (WebKit::CompositingCoordinator::rootGraphicsLayer):
99
        * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinatorClient.h: Added.
100
        (WebKit):
101
        (CompositingCoordinatorMessageClient):
102
        This interface provides a way to send messages to renderer.
103
        (CompositingCoordinatorClient):
104
        This interface provides a way to use LayerTreeCoordinator from
105
        Compositing Coordinator.
106
        (WebKit::CompositingCoordinatorClient::~CompositingCoordinatorClient):
107
        * WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp:
108
        (WebKit::LayerTreeCoordinator::~LayerTreeCoordinator):
109
        (WebKit::LayerTreeCoordinator::LayerTreeCoordinator):
110
        (WebKit::LayerTreeCoordinator::setLayerFlushSchedulingEnabled):
111
        (WebKit::LayerTreeCoordinator::scheduleLayerFlush):
112
        (WebKit::LayerTreeCoordinator::setRootCompositingLayer):
113
        (WebKit::LayerTreeCoordinator::invalidate):
114
        (WebKit::LayerTreeCoordinator::setNonCompositedContentsNeedDisplay):
115
        (WebKit::LayerTreeCoordinator::forceRepaint):
116
        (WebKit::LayerTreeCoordinator::sizeDidChange):
117
        (WebKit::LayerTreeCoordinator::didInstallPageOverlay):
118
        (WebKit::LayerTreeCoordinator::didUninstallPageOverlay):
119
        (WebKit::LayerTreeCoordinator::setPageOverlayNeedsDisplay):
120
        (WebKit::LayerTreeCoordinator::setPageOverlayOpacity):
121
        (WebKit::LayerTreeCoordinator::pauseRendering):
122
        (WebKit::LayerTreeCoordinator::resumeRendering):
123
        (WebKit::LayerTreeCoordinator::viewSize):
124
        (WebKit::LayerTreeCoordinator::layoutIfNeeded):
125
        (WebKit::LayerTreeCoordinator::isOpaqueContents):
126
        (WebKit::LayerTreeCoordinator::didPerformScheduledLayerFlush):
127
        (WebKit::LayerTreeCoordinator::paintContents):
128
        (WebKit::LayerTreeCoordinator::paintOverlayContents):
129
        (WebKit::LayerTreeCoordinator::setVisibleContentsRect):
130
        (WebKit::LayerTreeCoordinator::graphicsLayerFactory):
131
        (WebKit::LayerTreeCoordinator::scheduleAnimation):
132
        (WebKit::LayerTreeCoordinator::renderNextFrame):
133
        (WebKit::LayerTreeCoordinator::purgeBackingStores):
134
        (WebKit::LayerTreeCoordinator::setBackgroundColor):
135
        * WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h:
136
        (WebCore):
137
        (LayerTreeCoordinator):
138
        * WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.cpp:
139
        Added. Manages sends actual IPC messages and manages
140
        WebCustomFilterProgram
141
        (WebKit):
142
        (WebKit::WebCompositingCoordinatorMessageClient::create):
143
        (WebKit::WebCompositingCoordinatorMessageClient::~WebCompositingCoordinatorMessageClient):
144
        (WebKit::WebCompositingCoordinatorMessageClient::WebCompositingCoordinatorMessageClient):
145
        (WebKit::WebCompositingCoordinatorMessageClient::setRootCompositingLayer):
146
        (WebKit::WebCompositingCoordinatorMessageClient::setCompositingLayerState):
147
        (WebKit::WebCompositingCoordinatorMessageClient::setCompositingLayerChildren):
148
        (WebKit::WebCompositingCoordinatorMessageClient::setCompositingLayerFilters):
149
        (WebKit::WebCompositingCoordinatorMessageClient::deleteCompositingLayer):
150
        (WebKit::WebCompositingCoordinatorMessageClient::createTileForLayer):
151
        (WebKit::WebCompositingCoordinatorMessageClient::updateTileForLayer):
152
        (WebKit::WebCompositingCoordinatorMessageClient::removeTileForLayer):
153
        (WebKit::WebCompositingCoordinatorMessageClient::createUpdateAtlas):
154
        (WebKit::WebCompositingCoordinatorMessageClient::removeUpdateAtlas):
155
        (WebKit::WebCompositingCoordinatorMessageClient::createImageBacking):
156
        (WebKit::WebCompositingCoordinatorMessageClient::updateImageBacking):
157
        (WebKit::WebCompositingCoordinatorMessageClient::clearImageBackingContents):
158
        (WebKit::WebCompositingCoordinatorMessageClient::removeImageBacking):
159
        (WebKit::WebCompositingCoordinatorMessageClient::didRenderFrame):
160
        (WebKit::WebCompositingCoordinatorMessageClient::didChangeScrollPosition):
161
        (WebKit::WebCompositingCoordinatorMessageClient::createCanvas):
162
        (WebKit::WebCompositingCoordinatorMessageClient::syncCanvas):
163
        (WebKit::WebCompositingCoordinatorMessageClient::destroyCanvas):
164
        (WebKit::WebCompositingCoordinatorMessageClient::setLayerAnimations):
165
        (WebKit::WebCompositingCoordinatorMessageClient::setAnimationsLocked):
166
        (WebKit::WebCompositingCoordinatorMessageClient::setBackgroundColor):
167
        (WebKit::WebCompositingCoordinatorMessageClient::requestAnimationFrame):
168
        (WebKit::WebCompositingCoordinatorMessageClient::invokeForceRepaintAsyncCallback):
169
        (WebKit::WebCompositingCoordinatorMessageClient::checkCustomFilterProgramProxies):
170
        (WebKit::WebCompositingCoordinatorMessageClient::removeCustomFilterProgramProxy):
171
        (WebKit::WebCompositingCoordinatorMessageClient::disconnectCustomFilterPrograms):
172
        * WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.h: Added.
173
        (WebKit):
174
        (WebCompositingCoordinatorMessageClient):
175
1
2012-12-06  Rick Byers  <rbyers@chromium.org>
176
2012-12-06  Rick Byers  <rbyers@chromium.org>
2
177
3
        CSS cursor property should support webkit-image-set
178
        CSS cursor property should support webkit-image-set
- a/Source/WebKit2/CMakeLists.txt +2 lines
Lines 495-505 set(WebKit2_SOURCES a/Source/WebKit2/CMakeLists.txt_sec1
495
    WebProcess/WebPage/WebUndoStep.cpp
495
    WebProcess/WebPage/WebUndoStep.cpp
496
496
497
    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp
497
    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp
498
    WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
498
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedImageBacking.cpp
499
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedImageBacking.cpp
499
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp
500
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp
500
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.cpp
501
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.cpp
501
    WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp
502
    WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp
502
    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp
503
    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp
504
    WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.cpp
503
)
505
)
504
506
505
set(WebKit2_MESSAGES_IN_FILES
507
set(WebKit2_MESSAGES_IN_FILES
- a/Source/WebKit2/Target.pri +5 lines
Lines 369-379 HEADERS += \ a/Source/WebKit2/Target.pri_sec1
369
    WebProcess/WebPage/EventDispatcher.h \
369
    WebProcess/WebPage/EventDispatcher.h \
370
    WebProcess/WebPage/FindController.h \
370
    WebProcess/WebPage/FindController.h \
371
    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h \
371
    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h \
372
    WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h \
373
    WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinatorClient.h \
372
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h \
374
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h \
373
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedImageBacking.h \
375
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedImageBacking.h \
374
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.h \
376
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.h \
375
    WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h \
377
    WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h \
376
    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h \
378
    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h \
379
    WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.h \
377
    WebProcess/WebPage/TapHighlightController.h \
380
    WebProcess/WebPage/TapHighlightController.h \
378
    WebProcess/WebPage/PageOverlay.h \
381
    WebProcess/WebPage/PageOverlay.h \
379
    WebProcess/WebPage/WebContextMenu.h \
382
    WebProcess/WebPage/WebContextMenu.h \
Lines 753-763 SOURCES += \ a/Source/WebKit2/Target.pri_sec2
753
    WebProcess/WebPage/EventDispatcher.cpp \
756
    WebProcess/WebPage/EventDispatcher.cpp \
754
    WebProcess/WebPage/FindController.cpp \
757
    WebProcess/WebPage/FindController.cpp \
755
    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp \
758
    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp \
759
    WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp \
756
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp \
760
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp \
757
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedImageBacking.cpp \
761
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedImageBacking.cpp \
758
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.cpp \
762
    WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.cpp \
759
    WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp \
763
    WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp \
760
    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp \
764
    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp \
765
    WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.cpp \
761
    WebProcess/WebPage/TapHighlightController.cpp \
766
    WebProcess/WebPage/TapHighlightController.cpp \
762
    WebProcess/WebPage/LayerTreeHost.cpp \
767
    WebProcess/WebPage/LayerTreeHost.cpp \
763
    WebProcess/WebPage/PageOverlay.cpp \
768
    WebProcess/WebPage/PageOverlay.cpp \
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp +677 lines
Line 0 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp_sec1
1
/*
2
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
3
 * Copyright (C) 2012 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 "CoordinatedLayerInfo.h"
33
#include "SurfaceUpdateInfo.h"
34
#include <WebCore/Frame.h>
35
#include <WebCore/FrameView.h>
36
#include <WebCore/GraphicsSurface.h>
37
#include <WebCore/Page.h>
38
#include <WebCore/RenderLayer.h>
39
#include <WebCore/RenderLayerBacking.h>
40
#include <WebCore/RenderLayerCompositor.h>
41
#include <WebCore/RenderView.h>
42
#include <WebCore/Settings.h>
43
#include <WebCore/TextureMapperPlatformLayer.h>
44
#include <wtf/TemporaryChange.h>
45
46
#if ENABLE(CSS_SHADERS)
47
#include "CustomFilterValidatedProgram.h"
48
#include "ValidatedCustomFilterOperation.h"
49
#endif
50
51
using namespace WebCore;
52
53
namespace WebKit {
54
55
PassOwnPtr<CompositingCoordinator> CompositingCoordinator::create(Page* page, CompositingCoordinatorClient* client, CompositingCoordinatorMessageClient* messageClient)
56
{
57
    return adoptPtr(new CompositingCoordinator(page, client, messageClient));
58
}
59
60
CompositingCoordinator::~CompositingCoordinator()
61
{
62
    // Prevent setCoordinatedGraphicsLayerClient(0) -> detachLayer() from modifying the set while we iterate it.
63
    HashSet<CoordinatedGraphicsLayer*> registeredLayers;
64
    registeredLayers.swap(m_registeredLayers);
65
66
    HashSet<CoordinatedGraphicsLayer*>::iterator end = registeredLayers.end();
67
    for (HashSet<CoordinatedGraphicsLayer*>::iterator it = registeredLayers.begin(); it != end; ++it)
68
        (*it)->setCoordinator(0);
69
}
70
71
CompositingCoordinator::CompositingCoordinator(Page* page, CompositingCoordinatorClient* client, CompositingCoordinatorMessageClient* messageClient)
72
    : m_page(page)
73
    , m_client(client)
74
    , m_messageClient(messageClient)
75
    , m_isValid(true)
76
    , m_isPurging(false)
77
    , m_waitingForRenderer(true)
78
    , m_isSuspended(false)
79
    , m_contentsScale(1)
80
    , m_shouldSendScrollPositionUpdate(true)
81
    , m_shouldSyncFrame(false)
82
    , m_shouldSyncRootLayer(true)
83
    , m_layerFlushTimer(this, &CompositingCoordinator::layerFlushTimerFired)
84
    , m_releaseInactiveAtlasesTimer(this, &CompositingCoordinator::releaseInactiveAtlasesTimerFired)
85
    , m_layerFlushSchedulingEnabled(true)
86
    , m_forceRepaintAsyncCallbackID(0)
87
    , m_animationsLocked(false)
88
{
89
    // Create a root layer.
90
    m_rootLayer = GraphicsLayer::create(this, this);
91
    CoordinatedGraphicsLayer* coordinatedRootLayer = toCoordinatedGraphicsLayer(m_rootLayer.get());
92
    coordinatedRootLayer->setRootLayer(true);
93
#ifndef NDEBUG
94
    m_rootLayer->setName("CompositingCoordinator root layer");
95
#endif
96
    m_rootLayer->setDrawsContent(false);
97
98
    IntSize viewSize(m_client->viewSize());
99
    m_rootLayer->setSize(viewSize);
100
101
    m_nonCompositedContentLayer = GraphicsLayer::create(this, this);
102
#ifndef NDEBUG
103
    m_nonCompositedContentLayer->setName("CompositingCoordinator non-composited content");
104
#endif
105
    m_nonCompositedContentLayer->setDrawsContent(true);
106
    m_nonCompositedContentLayer->setSize(viewSize);
107
108
    m_rootLayer->addChild(m_nonCompositedContentLayer.get());
109
110
    scheduleLayerFlush();
111
}
112
113
void CompositingCoordinator::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
114
{
115
    if (m_layerFlushSchedulingEnabled == layerFlushingEnabled)
116
        return;
117
118
    m_layerFlushSchedulingEnabled = layerFlushingEnabled;
119
120
    if (m_layerFlushSchedulingEnabled) {
121
        scheduleLayerFlush();
122
        return;
123
    }
124
125
    cancelPendingLayerFlush();
126
}
127
128
void CompositingCoordinator::scheduleLayerFlush()
129
{
130
    if (!m_layerFlushSchedulingEnabled)
131
        return;
132
133
    if (!m_layerFlushTimer.isActive())
134
        m_layerFlushTimer.startOneShot(0);
135
}
136
137
void CompositingCoordinator::cancelPendingLayerFlush()
138
{
139
    m_layerFlushTimer.stop();
140
}
141
142
void CompositingCoordinator::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
143
{
144
    m_nonCompositedContentLayer->removeAllChildren();
145
    m_nonCompositedContentLayer->setContentsOpaque(m_client->isOpaqueContents());
146
147
    // Add the accelerated layer tree hierarchy.
148
    if (graphicsLayer)
149
        m_nonCompositedContentLayer->addChild(graphicsLayer);
150
}
151
152
void CompositingCoordinator::invalidate()
153
{
154
    cancelPendingLayerFlush();
155
156
    ASSERT(m_isValid);
157
    m_rootLayer = nullptr;
158
    m_isValid = false;
159
}
160
161
void CompositingCoordinator::setNeedsDisplayInRect(const IntRect& rect)
162
{
163
    m_nonCompositedContentLayer->setNeedsDisplayInRect(rect);
164
165
    if (m_pageOverlayLayer)
166
        m_pageOverlayLayer->setNeedsDisplayInRect(rect);
167
168
    scheduleLayerFlush();
169
}
170
171
void CompositingCoordinator::forceRepaint()
172
{
173
    // This is necessary for running layout tests. Since in this case we are not waiting for a renderer to reply nicely.
174
    // Instead we are just triggering forceRepaint. But we still want to have the scripted animation callbacks being executed.
175
    syncDisplayState();
176
177
    // We need to schedule another flush, otherwise the forced paint might cancel a later expected flush.
178
    // This is aligned with LayerTreeHostCA.
179
    scheduleLayerFlush();
180
    flushPendingLayerChanges();
181
}
182
183
void CompositingCoordinator::sizeDidChange(const IntSize& newSize)
184
{
185
    if (m_rootLayer->size() == newSize)
186
        return;
187
188
    m_rootLayer->setSize(newSize);
189
190
    // If the newSize exposes new areas of the non-composited content a setNeedsDisplay is needed
191
    // for those newly exposed areas.
192
    FloatSize oldSize = m_nonCompositedContentLayer->size();
193
    m_nonCompositedContentLayer->setSize(newSize);
194
195
    if (newSize.width() > oldSize.width()) {
196
        float height = std::min(static_cast<float>(newSize.height()), oldSize.height());
197
        m_nonCompositedContentLayer->setNeedsDisplayInRect(FloatRect(oldSize.width(), 0, newSize.width() - oldSize.width(), height));
198
    }
199
200
    if (newSize.height() > oldSize.height())
201
        m_nonCompositedContentLayer->setNeedsDisplayInRect(FloatRect(0, oldSize.height(), newSize.width(), newSize.height() - oldSize.height()));
202
203
    if (m_pageOverlayLayer)
204
        m_pageOverlayLayer->setSize(newSize);
205
206
    scheduleLayerFlush();
207
}
208
209
bool CompositingCoordinator::flushPendingLayerChanges()
210
{
211
    if (m_waitingForRenderer)
212
        return false;
213
214
    for (size_t i = 0; i < m_detachedLayers.size(); ++i)
215
        m_messageClient->deleteCompositingLayer(m_detachedLayers[i]);
216
    m_detachedLayers.clear();
217
218
    m_rootLayer->flushCompositingStateForThisLayerOnly();
219
    m_nonCompositedContentLayer->flushCompositingStateForThisLayerOnly();
220
221
    if (m_pageOverlayLayer)
222
        m_pageOverlayLayer->flushCompositingStateForThisLayerOnly();
223
224
    bool didSync = m_page->mainFrame()->view()->flushCompositingStateIncludingSubframes();
225
226
    flushPendingImageBackingChanges();
227
228
    if (m_shouldSyncRootLayer) {
229
        m_messageClient->setRootCompositingLayer(toCoordinatedGraphicsLayer(m_rootLayer.get())->id());
230
        m_shouldSyncRootLayer = false;
231
        m_shouldSyncFrame = true;
232
    }
233
234
    if (m_shouldSyncFrame) {
235
        didSync = true;
236
237
        IntSize contentsSize = roundedIntSize(m_nonCompositedContentLayer->size());
238
        IntRect coveredRect = toCoordinatedGraphicsLayer(m_nonCompositedContentLayer.get())->coverRect();
239
        m_messageClient->didRenderFrame(contentsSize, coveredRect);
240
        m_waitingForRenderer = true;
241
        m_shouldSyncFrame = false;
242
    } else
243
        unlockAnimations();
244
245
    return didSync;
246
}
247
248
void CompositingCoordinator::syncLayerState(CoordinatedLayerID id, const CoordinatedLayerInfo& info)
249
{
250
    if (m_shouldSendScrollPositionUpdate) {
251
        m_messageClient->didChangeScrollPosition(m_visibleContentsRect.location());
252
        m_shouldSendScrollPositionUpdate = false;
253
    }
254
255
    m_shouldSyncFrame = true;
256
    m_messageClient->setCompositingLayerState(id, info);
257
}
258
259
void CompositingCoordinator::syncLayerChildren(CoordinatedLayerID id, const Vector<CoordinatedLayerID>& children)
260
{
261
    m_shouldSyncFrame = true;
262
    m_messageClient->setCompositingLayerChildren(id, children);
263
}
264
265
#if USE(GRAPHICS_SURFACE)
266
void CompositingCoordinator::createCanvas(CoordinatedLayerID id, PlatformLayer* canvasPlatformLayer)
267
{
268
    m_shouldSyncFrame = true;
269
    GraphicsSurfaceToken token = canvasPlatformLayer->graphicsSurfaceToken();
270
    IntSize canvasSize = canvasPlatformLayer->platformLayerSize();
271
    m_messageClient->createCanvas(id, canvasSize, token);
272
}
273
274
void CompositingCoordinator::syncCanvas(CoordinatedLayerID id, PlatformLayer* canvasPlatformLayer)
275
{
276
    m_shouldSyncFrame = true;
277
    uint32_t frontBuffer = canvasPlatformLayer->copyToGraphicsSurface();
278
    m_messageClient->syncCanvas(id, frontBuffer);
279
}
280
281
void CompositingCoordinator::destroyCanvas(CoordinatedLayerID id)
282
{
283
    if (m_isPurging)
284
        return;
285
286
    m_shouldSyncFrame = true;
287
    m_messageClient->destroyCanvas(id);
288
}
289
#endif
290
291
#if ENABLE(CSS_FILTERS)
292
void CompositingCoordinator::syncLayerFilters(CoordinatedLayerID id, const FilterOperations& filters)
293
{
294
    m_shouldSyncFrame = true;
295
    m_messageClient->setCompositingLayerFilters(id, filters);
296
}
297
#endif
298
299
void CompositingCoordinator::detachLayer(CoordinatedGraphicsLayer* layer)
300
{
301
    m_registeredLayers.remove(layer);
302
    m_shouldSyncFrame = true;
303
    m_detachedLayers.append(layer->id());
304
    scheduleLayerFlush();
305
}
306
307
static void updateOffsetFromViewportForSelf(RenderLayer* renderLayer)
308
{
309
    // These conditions must match the conditions in RenderLayerCompositor::requiresCompositingForPosition.
310
    RenderLayerBacking* backing = renderLayer->backing();
311
    if (!backing)
312
        return;
313
314
    RenderStyle* style = renderLayer->renderer()->style();
315
    if (!style)
316
        return;
317
318
    if (!renderLayer->renderer()->isOutOfFlowPositioned() || renderLayer->renderer()->style()->position() != FixedPosition)
319
        return;
320
321
    if (!renderLayer->renderer()->container()->isRenderView())
322
        return;
323
324
    if (!renderLayer->isStackingContext())
325
        return;
326
327
    CoordinatedGraphicsLayer* graphicsLayer = toCoordinatedGraphicsLayer(backing->graphicsLayer());
328
    graphicsLayer->setFixedToViewport(true);
329
}
330
331
static void updateOffsetFromViewportForLayer(RenderLayer* renderLayer)
332
{
333
    updateOffsetFromViewportForSelf(renderLayer);
334
335
    if (renderLayer->firstChild())
336
        updateOffsetFromViewportForLayer(renderLayer->firstChild());
337
    if (renderLayer->nextSibling())
338
        updateOffsetFromViewportForLayer(renderLayer->nextSibling());
339
}
340
341
void CompositingCoordinator::syncFixedLayers()
342
{
343
    if (!m_page->settings() || !m_page->settings()->acceleratedCompositingForFixedPositionEnabled())
344
        return;
345
346
    if (!m_page->mainFrame()->view()->hasViewportConstrainedObjects())
347
        return;
348
349
    RenderLayer* rootRenderLayer = m_page->mainFrame()->contentRenderer()->compositor()->rootRenderLayer();
350
    ASSERT(rootRenderLayer);
351
    if (rootRenderLayer->firstChild())
352
        updateOffsetFromViewportForLayer(rootRenderLayer->firstChild());
353
}
354
355
void CompositingCoordinator::lockAnimations()
356
{
357
    m_animationsLocked = true;
358
    m_messageClient->setAnimationsLocked(true);
359
}
360
361
void CompositingCoordinator::unlockAnimations()
362
{
363
    if (!m_animationsLocked)
364
        return;
365
366
    m_animationsLocked = false;
367
    m_messageClient->setAnimationsLocked(false);
368
}
369
370
void CompositingCoordinator::performScheduledLayerFlush()
371
{
372
    if (m_isSuspended || m_waitingForRenderer)
373
        return;
374
375
    // We lock the animations while performing layout, to avoid flickers caused by animations continuing in the renderer while
376
    // the web process layout wants to cancel them.
377
    lockAnimations();
378
    syncDisplayState();
379
380
    // We can unlock the animations before flushing if there are no visible changes, for example if there are content updates
381
    // in a layer with opacity 0.
382
    bool canUnlockBeforeFlush = !m_isValid || !toCoordinatedGraphicsLayer(m_rootLayer.get())->hasPendingVisibleChanges();
383
    if (canUnlockBeforeFlush)
384
        unlockAnimations();
385
386
    if (!m_isValid)
387
        return;
388
389
    bool didSync = flushPendingLayerChanges();
390
    m_client->didPerformScheduledLayerFlush(didSync);
391
}
392
393
void CompositingCoordinator::syncDisplayState()
394
{
395
#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
396
    // Make sure that any previously registered animation callbacks are being executed before we flush the layers.
397
    m_page->mainFrame()->view()->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(currentTime()));
398
#endif
399
400
    m_client->layoutIfNeeded();
401
}
402
403
void CompositingCoordinator::layerFlushTimerFired(Timer<CompositingCoordinator>*)
404
{
405
    performScheduledLayerFlush();
406
}
407
408
void CompositingCoordinator::createPageOverlayLayer()
409
{
410
    ASSERT(!m_pageOverlayLayer);
411
412
    m_pageOverlayLayer = GraphicsLayer::create(this, this);
413
#ifndef NDEBUG
414
    m_pageOverlayLayer->setName("CompositingCoordinator page overlay content");
415
#endif
416
417
    m_pageOverlayLayer->setDrawsContent(true);
418
    m_pageOverlayLayer->setSize(m_client->viewSize());
419
420
    m_rootLayer->addChild(m_pageOverlayLayer.get());
421
422
    scheduleLayerFlush();
423
}
424
425
void CompositingCoordinator::destroyPageOverlayLayer()
426
{
427
    ASSERT(m_pageOverlayLayer);
428
    m_pageOverlayLayer->removeFromParent();
429
    m_pageOverlayLayer = nullptr;
430
431
    scheduleLayerFlush();
432
}
433
434
void CompositingCoordinator::setPageOverlayNeedsDisplay(const WebCore::IntRect& rect)
435
{
436
    ASSERT(m_pageOverlayLayer);
437
    m_pageOverlayLayer->setNeedsDisplayInRect(rect);
438
    scheduleLayerFlush();
439
}
440
441
void CompositingCoordinator::setPageOverlayOpacity(float value)
442
{
443
    ASSERT(m_pageOverlayLayer);
444
    m_pageOverlayLayer->setOpacity(value);
445
    scheduleLayerFlush();
446
}
447
448
PassRefPtr<CoordinatedImageBacking> CompositingCoordinator::createImageBackingIfNeeded(Image* image)
449
{
450
    CoordinatedImageBackingID imageID = CoordinatedImageBacking::getCoordinatedImageBackingID(image);
451
    ImageBackingMap::iterator it = m_imageBackings.find(imageID);
452
    RefPtr<CoordinatedImageBacking> imageBacking;
453
    if (it == m_imageBackings.end()) {
454
        imageBacking = CoordinatedImageBacking::create(this, image);
455
        m_imageBackings.add(imageID, imageBacking);
456
    } else
457
        imageBacking = it->value;
458
459
    return imageBacking;
460
}
461
462
void CompositingCoordinator::createImageBacking(CoordinatedImageBackingID imageID)
463
{
464
    m_shouldSyncFrame = true;
465
    m_messageClient->createImageBacking(imageID);
466
}
467
468
void CompositingCoordinator::updateImageBacking(CoordinatedImageBackingID imageID, const ShareableSurface::Handle& handle)
469
{
470
    m_shouldSyncFrame = true;
471
    m_messageClient->updateImageBacking(imageID, handle);
472
}
473
474
void CompositingCoordinator::clearImageBackingContents(CoordinatedImageBackingID imageID)
475
{
476
    m_shouldSyncFrame = true;
477
    m_messageClient->clearImageBackingContents(imageID);
478
}
479
480
void CompositingCoordinator::removeImageBacking(CoordinatedImageBackingID imageID)
481
{
482
    if (m_isPurging)
483
        return;
484
485
    ASSERT(m_imageBackings.contains(imageID));
486
    m_shouldSyncFrame = true;
487
    m_imageBackings.remove(imageID);
488
    m_messageClient->removeImageBacking(imageID);
489
}
490
491
void CompositingCoordinator::flushPendingImageBackingChanges()
492
{
493
    ImageBackingMap::iterator end = m_imageBackings.end();
494
    for (ImageBackingMap::iterator iter = m_imageBackings.begin(); iter != end; ++iter)
495
        iter->value->update();
496
}
497
498
void CompositingCoordinator::notifyAnimationStarted(const GraphicsLayer*, double /* time */)
499
{
500
}
501
502
void CompositingCoordinator::notifyFlushRequired(const GraphicsLayer*)
503
{
504
}
505
506
void CompositingCoordinator::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase phase, const IntRect& clipRect)
507
{
508
    bool isNonCompositingContent = (graphicsLayer == m_nonCompositedContentLayer);
509
    bool isPageOverlay = (graphicsLayer == m_pageOverlayLayer);
510
511
    if (isNonCompositingContent)
512
        m_client->paintContents(graphicsContext, clipRect);
513
    else if (isPageOverlay)
514
        m_client->paintOverlayContents(graphicsContext, clipRect);
515
}
516
517
PassOwnPtr<GraphicsLayer> CompositingCoordinator::createGraphicsLayer(GraphicsLayerClient* client)
518
{
519
    CoordinatedGraphicsLayer* layer = new CoordinatedGraphicsLayer(client);
520
    layer->setCoordinator(this);
521
    m_registeredLayers.add(layer);
522
    layer->setContentsScale(m_contentsScale);
523
    layer->adjustVisibleRect();
524
    return adoptPtr(layer);
525
}
526
527
void CompositingCoordinator::createTile(CoordinatedLayerID layerID, uint32_t tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& tileRect)
528
{
529
    m_shouldSyncFrame = true;
530
    m_messageClient->createTileForLayer(layerID, tileID, tileRect, updateInfo);
531
}
532
533
void CompositingCoordinator::updateTile(CoordinatedLayerID layerID, uint32_t tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& tileRect)
534
{
535
    m_shouldSyncFrame = true;
536
    m_messageClient->updateTileForLayer(layerID, tileID, tileRect, updateInfo);
537
}
538
539
void CompositingCoordinator::removeTile(CoordinatedLayerID layerID, uint32_t tileID)
540
{
541
    if (m_isPurging)
542
        return;
543
    m_shouldSyncFrame = true;
544
    m_messageClient->removeTileForLayer(layerID, tileID);
545
}
546
547
void CompositingCoordinator::createUpdateAtlas(int atlasID, const ShareableSurface::Handle& handle)
548
{
549
    m_messageClient->createUpdateAtlas(atlasID, handle);
550
}
551
552
void CompositingCoordinator::removeUpdateAtlas(int atlasID)
553
{
554
    if (m_isPurging)
555
        return;
556
    m_messageClient->removeUpdateAtlas(atlasID);
557
}
558
559
IntRect CompositingCoordinator::visibleContentsRect() const
560
{
561
    return m_visibleContentsRect;
562
}
563
564
void CompositingCoordinator::setLayerAnimations(CoordinatedLayerID layerID, const GraphicsLayerAnimations& animations)
565
{
566
    m_shouldSyncFrame = true;
567
    GraphicsLayerAnimations activeAnimations = animations.getActiveAnimations();
568
    m_messageClient->setLayerAnimations(layerID, activeAnimations);
569
}
570
571
void CompositingCoordinator::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector)
572
{
573
    bool contentsRectDidChange = rect != m_visibleContentsRect;
574
    bool contentsScaleDidChange = scale != m_contentsScale;
575
576
    // A zero trajectoryVector indicates that tiles all around the viewport are requested.
577
    toCoordinatedGraphicsLayer(m_nonCompositedContentLayer.get())->setVisibleContentRectTrajectoryVector(trajectoryVector);
578
579
    if (contentsRectDidChange || contentsScaleDidChange) {
580
        m_visibleContentsRect = rect;
581
        m_contentsScale = scale;
582
583
        HashSet<CoordinatedGraphicsLayer*>::iterator end = m_registeredLayers.end();
584
        for (HashSet<CoordinatedGraphicsLayer*>::iterator it = m_registeredLayers.begin(); it != end; ++it) {
585
            if (contentsScaleDidChange)
586
                (*it)->setContentsScale(scale);
587
            if (contentsRectDidChange)
588
                (*it)->adjustVisibleRect();
589
        }
590
    }
591
592
    if (contentsRectDidChange)
593
        m_shouldSendScrollPositionUpdate = true;
594
595
    scheduleLayerFlush();
596
}
597
598
void CompositingCoordinator::renderNextFrame()
599
{
600
    m_waitingForRenderer = false;
601
    scheduleLayerFlush();
602
    for (unsigned i = 0; i < m_updateAtlases.size(); ++i)
603
        m_updateAtlases[i]->didSwapBuffers();
604
}
605
606
bool CompositingCoordinator::layerTreeTileUpdatesAllowed() const
607
{
608
    return !m_isSuspended && !m_waitingForRenderer;
609
}
610
611
void CompositingCoordinator::purgeBackingStores()
612
{
613
    TemporaryChange<bool> purgingToggle(m_isPurging, true);
614
615
    HashSet<CoordinatedGraphicsLayer*>::iterator end = m_registeredLayers.end();
616
    for (HashSet<CoordinatedGraphicsLayer*>::iterator it = m_registeredLayers.begin(); it != end; ++it)
617
        (*it)->purgeBackingStores();
618
619
    m_imageBackings.clear();
620
    m_updateAtlases.clear();
621
}
622
623
PassOwnPtr<GraphicsContext> CompositingCoordinator::beginContentUpdate(const WebCore::IntSize& size, ShareableBitmap::Flags flags, int& atlasID, WebCore::IntPoint& offset)
624
{
625
    OwnPtr<GraphicsContext> graphicsContext;
626
    for (unsigned i = 0; i < m_updateAtlases.size(); ++i) {
627
        UpdateAtlas* atlas = m_updateAtlases[i].get();
628
        if (atlas->flags() == flags) {
629
            // This will return null if there is no available buffer space.
630
            graphicsContext = atlas->beginPaintingOnAvailableBuffer(atlasID, size, offset);
631
            if (graphicsContext)
632
                return graphicsContext.release();
633
        }
634
    }
635
636
    static const int ScratchBufferDimension = 1024; // Should be a power of two.
637
    m_updateAtlases.append(adoptPtr(new UpdateAtlas(this, ScratchBufferDimension, flags)));
638
    scheduleReleaseInactiveAtlases();
639
    return m_updateAtlases.last()->beginPaintingOnAvailableBuffer(atlasID, size, offset);
640
}
641
642
const double ReleaseInactiveAtlasesTimerInterval = 0.5;
643
644
void CompositingCoordinator::scheduleReleaseInactiveAtlases()
645
{
646
    if (!m_releaseInactiveAtlasesTimer.isActive())
647
        m_releaseInactiveAtlasesTimer.startRepeating(ReleaseInactiveAtlasesTimerInterval);
648
}
649
650
void CompositingCoordinator::releaseInactiveAtlasesTimerFired(Timer<CompositingCoordinator>*)
651
{
652
    // We always want to keep one atlas for non-composited content.
653
    OwnPtr<UpdateAtlas> atlasToKeepAnyway;
654
    bool foundActiveAtlasForNonCompositedContent = false;
655
    for (int i = m_updateAtlases.size() - 1;  i >= 0; --i) {
656
        UpdateAtlas* atlas = m_updateAtlases[i].get();
657
        if (!atlas->isInUse())
658
            atlas->addTimeInactive(ReleaseInactiveAtlasesTimerInterval);
659
        bool usableForNonCompositedContent = atlas->flags() == ShareableBitmap::NoFlags;
660
        if (atlas->isInactive()) {
661
            if (!foundActiveAtlasForNonCompositedContent && !atlasToKeepAnyway && usableForNonCompositedContent)
662
                atlasToKeepAnyway = m_updateAtlases[i].release();
663
            m_updateAtlases.remove(i);
664
        } else if (usableForNonCompositedContent)
665
            foundActiveAtlasForNonCompositedContent = true;
666
    }
667
668
    if (!foundActiveAtlasForNonCompositedContent && atlasToKeepAnyway)
669
        m_updateAtlases.append(atlasToKeepAnyway.release());
670
671
    if (m_updateAtlases.size() <= 1)
672
        m_releaseInactiveAtlasesTimer.stop();
673
}
674
675
} // namespace WebKit
676
677
#endif // USE(COORDINATED_GRAPHICS)
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h +192 lines
Line 0 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h_sec1
1
/*
2
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3
 * Copyright (C) 2012 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 "CompositingCoordinatorClient.h"
33
#include "CoordinatedGraphicsLayer.h"
34
#include "CoordinatedImageBacking.h"
35
#include "UpdateAtlas.h"
36
#include <WebCore/FloatPoint.h>
37
#include <WebCore/GraphicsLayerClient.h>
38
#include <WebCore/GraphicsLayerFactory.h>
39
#include <WebCore/IntRect.h>
40
#include <WebCore/Timer.h>
41
#include <wtf/OwnPtr.h>
42
43
#if ENABLE(CSS_SHADERS)
44
#include <WebCore/FilterOperations.h>
45
#endif
46
47
namespace WebCore {
48
class Page;
49
}
50
51
namespace WebKit {
52
53
class CompositingCoordinator : public WebCore::GraphicsLayerClient
54
    , public CoordinatedGraphicsLayerClient
55
    , public CoordinatedImageBacking::Coordinator
56
    , public UpdateAtlasClient
57
    , public WebCore::GraphicsLayerFactory {
58
    WTF_MAKE_NONCOPYABLE(CompositingCoordinator); WTF_MAKE_FAST_ALLOCATED;
59
public:
60
    static PassOwnPtr<CompositingCoordinator> create(WebCore::Page*, CompositingCoordinatorClient*, CompositingCoordinatorMessageClient*);
61
    virtual ~CompositingCoordinator();
62
63
    virtual void scheduleLayerFlush();
64
    virtual void setLayerFlushSchedulingEnabled(bool);
65
    virtual void setRootCompositingLayer(WebCore::GraphicsLayer*);
66
    virtual void invalidate();
67
68
    virtual void setNeedsDisplayInRect(const WebCore::IntRect&);
69
70
    virtual void sizeDidChange(const WebCore::IntSize& newSize);
71
72
    void createPageOverlayLayer();
73
    void destroyPageOverlayLayer();
74
    void setPageOverlayNeedsDisplay(const WebCore::IntRect&);
75
    void setPageOverlayOpacity(float);
76
77
    virtual void pauseRendering() { m_isSuspended = true; }
78
    virtual void resumeRendering() { m_isSuspended = false; scheduleLayerFlush(); }
79
80
    virtual void forceRepaint();
81
82
    virtual void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint&);
83
84
    // CoordinatedGraphicsLayerClient :: CoordinatedTileClient
85
    virtual void createTile(CoordinatedLayerID, uint32_t tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&);
86
    virtual void updateTile(CoordinatedLayerID, uint32_t tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&);
87
    virtual void removeTile(CoordinatedLayerID, uint32_t tileID);
88
89
    // CoordinatedGraphicsLayerClient
90
    virtual WebCore::IntRect visibleContentsRect() const;
91
    virtual bool layerTreeTileUpdatesAllowed() const;
92
    virtual PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(WebCore::Image*) OVERRIDE;
93
    virtual void syncLayerState(CoordinatedLayerID, const CoordinatedLayerInfo&);
94
    virtual void syncLayerChildren(CoordinatedLayerID, const Vector<CoordinatedLayerID>&);
95
#if ENABLE(CSS_FILTERS)
96
    virtual void syncLayerFilters(CoordinatedLayerID, const WebCore::FilterOperations&);
97
#endif
98
#if USE(GRAPHICS_SURFACE)
99
    virtual void createCanvas(CoordinatedLayerID, WebCore::PlatformLayer*) OVERRIDE;
100
    virtual void syncCanvas(CoordinatedLayerID, WebCore::PlatformLayer*) OVERRIDE;
101
    virtual void destroyCanvas(CoordinatedLayerID) OVERRIDE;
102
#endif
103
    virtual void setLayerAnimations(CoordinatedLayerID, const WebCore::GraphicsLayerAnimations&);
104
105
    virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*);
106
    virtual void syncFixedLayers();
107
    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, int& atlasID, WebCore::IntPoint&);
108
109
    // UpdateAtlasClient
110
    virtual void createUpdateAtlas(int atlasID, const ShareableSurface::Handle&);
111
    virtual void removeUpdateAtlas(int atlasID);
112
113
    void renderNextFrame();
114
    void purgeBackingStores();
115
116
    WebCore::GraphicsLayer* rootGraphicsLayer() const { return m_rootLayer.get(); }
117
118
private:
119
    CompositingCoordinator(WebCore::Page*, CompositingCoordinatorClient*, CompositingCoordinatorMessageClient*);
120
121
    // GraphicsLayerClient
122
    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
123
    virtual void notifyFlushRequired(const WebCore::GraphicsLayer*);
124
    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect);
125
126
    // CoordinatedImageBacking::Coordinator
127
    virtual void createImageBacking(CoordinatedImageBackingID) OVERRIDE;
128
    virtual void updateImageBacking(CoordinatedImageBackingID, const ShareableSurface::Handle&) OVERRIDE;
129
    virtual void clearImageBackingContents(CoordinatedImageBackingID) OVERRIDE;
130
    virtual void removeImageBacking(CoordinatedImageBackingID) OVERRIDE;
131
132
    void flushPendingImageBackingChanges();
133
134
    // GraphicsLayerFactory
135
    virtual PassOwnPtr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayerClient*) OVERRIDE;
136
137
    // CompositingCoordinator
138
    bool flushPendingLayerChanges();
139
    void cancelPendingLayerFlush();
140
    void performScheduledLayerFlush();
141
    void syncDisplayState();
142
    void lockAnimations();
143
    void unlockAnimations();
144
145
    void layerFlushTimerFired(WebCore::Timer<CompositingCoordinator>*);
146
147
    void scheduleReleaseInactiveAtlases();
148
149
    void releaseInactiveAtlasesTimerFired(WebCore::Timer<CompositingCoordinator>*);
150
151
    WebCore::Page* m_page;
152
    CompositingCoordinatorClient* m_client;
153
    CompositingCoordinatorMessageClient* m_messageClient;
154
155
    OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
156
157
    // The layer which contains all non-composited content.
158
    OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
159
160
    // The page overlay layer. Will be null if there's no page overlay.
161
    OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer;
162
163
    HashSet<WebCore::CoordinatedGraphicsLayer*> m_registeredLayers;
164
    Vector<CoordinatedLayerID> m_detachedLayers;
165
    typedef HashMap<CoordinatedImageBackingID, RefPtr<CoordinatedImageBacking> > ImageBackingMap;
166
    ImageBackingMap m_imageBackings;
167
    Vector<OwnPtr<UpdateAtlas> > m_updateAtlases;
168
169
    bool m_isValid;
170
    // We don't send the messages related to releasing resources to renderer during purging, because renderer already had removed all resources.
171
    bool m_isPurging;
172
173
    bool m_waitingForRenderer;
174
    bool m_isSuspended;
175
    WebCore::IntRect m_visibleContentsRect;
176
    float m_contentsScale;
177
    bool m_shouldSendScrollPositionUpdate;
178
179
    bool m_shouldSyncFrame;
180
    bool m_shouldSyncRootLayer;
181
    WebCore::Timer<CompositingCoordinator> m_layerFlushTimer;
182
    WebCore::Timer<CompositingCoordinator> m_releaseInactiveAtlasesTimer;
183
    bool m_layerFlushSchedulingEnabled;
184
    uint64_t m_forceRepaintAsyncCallbackID;
185
    bool m_animationsLocked;
186
};
187
188
}
189
190
#endif
191
192
#endif // CompositingCoordinator_h
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinatorClient.h +100 lines
Line 0 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinatorClient.h_sec1
1
/*
2
 * Copyright (C) 2012 Company 100, Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#ifndef CompositingCoordinatorClient_h
27
#define CompositingCoordinatorClient_h
28
29
#if USE(COORDINATED_GRAPHICS)
30
31
#include "CoordinatedLayerInfo.h"
32
#include "ShareableSurface.h"
33
#include "SurfaceUpdateInfo.h"
34
#include <WebCore/GraphicsLayerAnimation.h>
35
#include <WebCore/IntRect.h>
36
#include <WebCore/IntSize.h>
37
#include <wtf/RefCounted.h>
38
39
#if USE(GRAPHICS_SURFACE)
40
#include <WebCore/GraphicsSurfaceToken.h>
41
#endif
42
43
#if ENABLE(CSS_FILTERS)
44
#include <WebCore/FilterOperation.h>
45
#endif
46
47
namespace WebKit {
48
49
class CompositingCoordinatorMessageClient {
50
public:
51
    virtual void setRootCompositingLayer(CoordinatedLayerID) = 0;
52
    virtual void setCompositingLayerState(CoordinatedLayerID, const CoordinatedLayerInfo&) = 0;
53
    virtual void setCompositingLayerChildren(CoordinatedLayerID, const Vector<CoordinatedLayerID>&) = 0;
54
#if ENABLE(CSS_FILTERS)
55
    virtual void setCompositingLayerFilters(CoordinatedLayerID, const WebCore::FilterOperations&) = 0;
56
#endif
57
    virtual void deleteCompositingLayer(CoordinatedLayerID) = 0;
58
59
    virtual void createTileForLayer(CoordinatedLayerID, uint32_t tileID, const WebCore::IntRect&, const SurfaceUpdateInfo&) = 0;
60
    virtual void updateTileForLayer(CoordinatedLayerID, uint32_t tileID, const WebCore::IntRect&, const SurfaceUpdateInfo&) = 0;
61
    virtual void removeTileForLayer(CoordinatedLayerID, uint32_t tileID) = 0;
62
63
    virtual void createUpdateAtlas(int atlasID, const ShareableSurface::Handle&) = 0;
64
    virtual void removeUpdateAtlas(int atlasID) = 0;
65
66
    virtual void createImageBacking(CoordinatedImageBackingID) = 0;
67
    virtual void updateImageBacking(CoordinatedImageBackingID, const ShareableSurface::Handle&) = 0;
68
    virtual void clearImageBackingContents(CoordinatedImageBackingID) = 0;
69
    virtual void removeImageBacking(CoordinatedImageBackingID) = 0;
70
71
    virtual void didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect) = 0;
72
    virtual void didChangeScrollPosition(const WebCore::IntPoint& position) = 0;
73
74
#if USE(GRAPHICS_SURFACE)
75
    virtual void createCanvas(CoordinatedLayerID, const WebCore::IntSize&, const WebCore::GraphicsSurfaceToken&) = 0;
76
    virtual void syncCanvas(CoordinatedLayerID, uint32_t frontBuffer) = 0;
77
    virtual void destroyCanvas(CoordinatedLayerID) = 0;
78
#endif
79
80
    virtual void setLayerAnimations(CoordinatedLayerID, const WebCore::GraphicsLayerAnimations&) = 0;
81
    virtual void setAnimationsLocked(bool) = 0;
82
};
83
84
class CompositingCoordinatorClient {
85
public:
86
    virtual const WebCore::IntSize& viewSize() const = 0;
87
88
    virtual void didPerformScheduledLayerFlush(bool didSync) = 0;
89
    virtual void layoutIfNeeded() = 0;
90
91
    virtual bool isOpaqueContents() = 0;
92
93
    virtual void paintContents(WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) = 0;
94
    virtual void paintOverlayContents(WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) = 0;
95
};
96
97
}
98
#endif
99
100
#endif // CompositingCoordinatorClient_h
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp -633 / +45 lines
Lines 1-6 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2011 Apple Inc. All rights reserved.
2
 * Copyright (C) 2011 Apple Inc. All rights reserved.
3
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
3
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4
 * Copyright (C) 2012 Company 100, Inc. All rights reserved.
4
 *
5
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
Lines 29-60 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp_sec2
29
#if USE(COORDINATED_GRAPHICS)
30
#if USE(COORDINATED_GRAPHICS)
30
#include "LayerTreeCoordinator.h"
31
#include "LayerTreeCoordinator.h"
31
32
32
#include "CoordinatedGraphicsArgumentCoders.h"
33
#include "CoordinatedGraphicsLayer.h"
33
#include "CoordinatedGraphicsLayer.h"
34
#include "DrawingAreaImpl.h"
34
#include "DrawingAreaImpl.h"
35
#include "GraphicsContext.h"
35
#include "GraphicsContext.h"
36
#include "LayerTreeCoordinatorProxyMessages.h"
37
#include "MessageID.h"
38
#include "SurfaceUpdateInfo.h"
39
#include "WebCoreArgumentCoders.h"
40
#include "WebPage.h"
36
#include "WebPage.h"
41
#include "WebPageProxyMessages.h"
42
#include <WebCore/Frame.h>
43
#include <WebCore/FrameView.h>
44
#include <WebCore/GraphicsSurface.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>
51
#include <WebCore/TextureMapperPlatformLayer.h>
52
#include <wtf/TemporaryChange.h>
53
54
#if ENABLE(CSS_SHADERS)
55
#include "CustomFilterValidatedProgram.h"
56
#include "ValidatedCustomFilterOperation.h"
57
#endif
58
37
59
using namespace WebCore;
38
using namespace WebCore;
60
39
Lines 67-155 PassRefPtr<LayerTreeCoordinator> LayerTreeCoordinator::create(WebPage* webPage) a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp_sec3
67
46
68
LayerTreeCoordinator::~LayerTreeCoordinator()
47
LayerTreeCoordinator::~LayerTreeCoordinator()
69
{
48
{
70
#if ENABLE(CSS_SHADERS)
71
    disconnectCustomFilterPrograms();
72
#endif
73
74
    // Prevent setCoordinatedGraphicsLayerClient(0) -> detachLayer() from modifying the set while we iterate it.
75
    HashSet<WebCore::CoordinatedGraphicsLayer*> registeredLayers;
76
    registeredLayers.swap(m_registeredLayers);
77
78
    HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator end = registeredLayers.end();
79
    for (HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator it = registeredLayers.begin(); it != end; ++it)
80
        (*it)->setCoordinator(0);
81
}
49
}
82
50
83
LayerTreeCoordinator::LayerTreeCoordinator(WebPage* webPage)
51
LayerTreeCoordinator::LayerTreeCoordinator(WebPage* webPage)
84
    : LayerTreeHost(webPage)
52
    : LayerTreeHost(webPage)
85
    , m_notifyAfterScheduledLayerFlush(false)
53
    , m_notifyAfterScheduledLayerFlush(false)
86
    , m_isValid(true)
87
    , m_isPurging(false)
88
    , m_waitingForUIProcess(true)
89
    , m_isSuspended(false)
90
    , m_contentsScale(1)
91
    , m_shouldSendScrollPositionUpdate(true)
92
    , m_shouldSyncFrame(false)
93
    , m_shouldSyncRootLayer(true)
94
    , m_layerFlushTimer(this, &LayerTreeCoordinator::layerFlushTimerFired)
95
    , m_releaseInactiveAtlasesTimer(this, &LayerTreeCoordinator::releaseInactiveAtlasesTimerFired)
96
    , m_layerFlushSchedulingEnabled(true)
97
    , m_forceRepaintAsyncCallbackID(0)
54
    , m_forceRepaintAsyncCallbackID(0)
98
    , m_animationsLocked(false)
55
{
99
{
56
    m_compositingCoordinatorMessageClient = WebCompositingCoordinatorMessageClient::create(m_webPage);
100
    // Create a root layer.
57
    m_compositingCoordinator = CompositingCoordinator::create(m_webPage->corePage(), this, m_compositingCoordinatorMessageClient.get());
101
    m_rootLayer = GraphicsLayer::create(this, this);
102
    CoordinatedGraphicsLayer* coordinatedRootLayer = toCoordinatedGraphicsLayer(m_rootLayer.get());
103
    coordinatedRootLayer->setRootLayer(true);
104
#ifndef NDEBUG
105
    m_rootLayer->setName("LayerTreeCoordinator root layer");
106
#endif
107
    m_rootLayer->setDrawsContent(false);
108
    m_rootLayer->setSize(m_webPage->size());
109
    m_layerTreeContext.coordinatedLayerID = toCoordinatedGraphicsLayer(coordinatedRootLayer)->id();
110
111
    m_nonCompositedContentLayer = GraphicsLayer::create(this, this);
112
#ifndef NDEBUG
113
    m_nonCompositedContentLayer->setName("LayerTreeCoordinator non-composited content");
114
#endif
115
    m_nonCompositedContentLayer->setDrawsContent(true);
116
    m_nonCompositedContentLayer->setSize(m_webPage->size());
117
58
118
    m_rootLayer->addChild(m_nonCompositedContentLayer.get());
59
    CoordinatedGraphicsLayer* rootLayer = toCoordinatedGraphicsLayer(m_compositingCoordinator->rootGraphicsLayer());
60
    m_layerTreeContext.coordinatedLayerID = rootLayer->id();
119
61
120
    if (m_webPage->hasPageOverlay())
62
    if (m_webPage->hasPageOverlay())
121
        createPageOverlayLayer();
63
        m_compositingCoordinator->createPageOverlayLayer();
122
64
123
    scheduleLayerFlush();
65
    scheduleLayerFlush();
124
}
66
}
125
67
126
void LayerTreeCoordinator::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
68
void LayerTreeCoordinator::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
127
{
69
{
128
    if (m_layerFlushSchedulingEnabled == layerFlushingEnabled)
70
    m_compositingCoordinator->setLayerFlushSchedulingEnabled(layerFlushingEnabled);
129
        return;
130
131
    m_layerFlushSchedulingEnabled = layerFlushingEnabled;
132
133
    if (m_layerFlushSchedulingEnabled) {
134
        scheduleLayerFlush();
135
        return;
136
    }
137
138
    cancelPendingLayerFlush();
139
}
71
}
140
72
141
void LayerTreeCoordinator::scheduleLayerFlush()
73
void LayerTreeCoordinator::scheduleLayerFlush()
142
{
74
{
143
    if (!m_layerFlushSchedulingEnabled)
75
    m_compositingCoordinator->scheduleLayerFlush();
144
        return;
145
146
    if (!m_layerFlushTimer.isActive())
147
        m_layerFlushTimer.startOneShot(0);
148
}
149
150
void LayerTreeCoordinator::cancelPendingLayerFlush()
151
{
152
    m_layerFlushTimer.stop();
153
}
76
}
154
77
155
void LayerTreeCoordinator::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush)
78
void LayerTreeCoordinator::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush)
Lines 159-188 void LayerTreeCoordinator::setShouldNotifyAfterNextScheduledLayerFlush(bool noti a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp_sec4
159
82
160
void LayerTreeCoordinator::setRootCompositingLayer(WebCore::GraphicsLayer* graphicsLayer)
83
void LayerTreeCoordinator::setRootCompositingLayer(WebCore::GraphicsLayer* graphicsLayer)
161
{
84
{
162
    m_nonCompositedContentLayer->removeAllChildren();
85
    m_compositingCoordinator->setRootCompositingLayer(graphicsLayer);
163
    m_nonCompositedContentLayer->setContentsOpaque(m_webPage->drawsBackground() && !m_webPage->drawsTransparentBackground());
164
165
    // Add the accelerated layer tree hierarchy.
166
    if (graphicsLayer)
167
        m_nonCompositedContentLayer->addChild(graphicsLayer);
168
}
86
}
169
87
170
void LayerTreeCoordinator::invalidate()
88
void LayerTreeCoordinator::invalidate()
171
{
89
{
172
    cancelPendingLayerFlush();
90
    m_compositingCoordinator->invalidate();
173
174
    ASSERT(m_isValid);
175
    m_rootLayer = nullptr;
176
    m_isValid = false;
177
}
91
}
178
92
179
void LayerTreeCoordinator::setNonCompositedContentsNeedDisplay(const WebCore::IntRect& rect)
93
void LayerTreeCoordinator::setNonCompositedContentsNeedDisplay(const WebCore::IntRect& rect)
180
{
94
{
181
    m_nonCompositedContentLayer->setNeedsDisplayInRect(rect);
95
    m_compositingCoordinator->setNeedsDisplayInRect(rect);
182
    if (m_pageOverlayLayer)
183
        m_pageOverlayLayer->setNeedsDisplayInRect(rect);
184
185
    scheduleLayerFlush();
186
}
96
}
187
97
188
void LayerTreeCoordinator::scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& /* scrollOffset */)
98
void LayerTreeCoordinator::scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& /* scrollOffset */)
Lines 192-205 void LayerTreeCoordinator::scrollNonCompositedContents(const WebCore::IntRect& s a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp_sec5
192
102
193
void LayerTreeCoordinator::forceRepaint()
103
void LayerTreeCoordinator::forceRepaint()
194
{
104
{
195
    // This is necessary for running layout tests. Since in this case we are not waiting for a UIProcess to reply nicely.
105
    m_compositingCoordinator->forceRepaint();
196
    // Instead we are just triggering forceRepaint. But we still want to have the scripted animation callbacks being executed.
197
    syncDisplayState();
198
199
    // We need to schedule another flush, otherwise the forced paint might cancel a later expected flush.
200
    // This is aligned with LayerTreeHostCA.
201
    scheduleLayerFlush();
202
    flushPendingLayerChanges();
203
}
106
}
204
107
205
bool LayerTreeCoordinator::forceRepaintAsync(uint64_t callbackID)
108
bool LayerTreeCoordinator::forceRepaintAsync(uint64_t callbackID)
Lines 213-637 bool LayerTreeCoordinator::forceRepaintAsync(uint64_t callbackID) a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp_sec6
213
116
214
void LayerTreeCoordinator::sizeDidChange(const WebCore::IntSize& newSize)
117
void LayerTreeCoordinator::sizeDidChange(const WebCore::IntSize& newSize)
215
{
118
{
216
    if (m_rootLayer->size() == newSize)
119
    m_compositingCoordinator->sizeDidChange(newSize);
217
        return;
218
219
    m_rootLayer->setSize(newSize);
220
221
    // If the newSize exposes new areas of the non-composited content a setNeedsDisplay is needed
222
    // for those newly exposed areas.
223
    FloatSize oldSize = m_nonCompositedContentLayer->size();
224
    m_nonCompositedContentLayer->setSize(newSize);
225
226
    if (newSize.width() > oldSize.width()) {
227
        float height = std::min(static_cast<float>(newSize.height()), oldSize.height());
228
        m_nonCompositedContentLayer->setNeedsDisplayInRect(FloatRect(oldSize.width(), 0, newSize.width() - oldSize.width(), height));
229
    }
230
231
    if (newSize.height() > oldSize.height())
232
        m_nonCompositedContentLayer->setNeedsDisplayInRect(FloatRect(0, oldSize.height(), newSize.width(), newSize.height() - oldSize.height()));
233
234
    if (m_pageOverlayLayer)
235
        m_pageOverlayLayer->setSize(newSize);
236
237
    scheduleLayerFlush();
238
}
120
}
239
121
240
void LayerTreeCoordinator::didInstallPageOverlay()
122
void LayerTreeCoordinator::didInstallPageOverlay()
241
{
123
{
242
    createPageOverlayLayer();
124
    m_compositingCoordinator->createPageOverlayLayer();
243
    scheduleLayerFlush();
244
}
125
}
245
126
246
void LayerTreeCoordinator::didUninstallPageOverlay()
127
void LayerTreeCoordinator::didUninstallPageOverlay()
247
{
128
{
248
    destroyPageOverlayLayer();
129
    m_compositingCoordinator->destroyPageOverlayLayer();
249
    scheduleLayerFlush();
250
}
130
}
251
131
252
void LayerTreeCoordinator::setPageOverlayNeedsDisplay(const WebCore::IntRect& rect)
132
void LayerTreeCoordinator::setPageOverlayNeedsDisplay(const WebCore::IntRect& rect)
253
{
133
{
254
    ASSERT(m_pageOverlayLayer);
134
    m_compositingCoordinator->setPageOverlayNeedsDisplay(rect);
255
    m_pageOverlayLayer->setNeedsDisplayInRect(rect);
256
    scheduleLayerFlush();
257
}
135
}
258
136
259
void LayerTreeCoordinator::setPageOverlayOpacity(float value)
137
void LayerTreeCoordinator::setPageOverlayOpacity(float value)
260
{
138
{
261
    ASSERT(m_pageOverlayLayer);
139
    m_compositingCoordinator->setPageOverlayOpacity(value);
262
    m_pageOverlayLayer->setOpacity(value);
263
    scheduleLayerFlush();
264
}
140
}
265
141
266
bool LayerTreeCoordinator::flushPendingLayerChanges()
142
void LayerTreeCoordinator::pauseRendering()
267
{
143
{
268
    if (m_waitingForUIProcess)
144
    m_compositingCoordinator->pauseRendering();
269
        return false;
270
271
    m_rootLayer->flushCompositingStateForThisLayerOnly();
272
    m_nonCompositedContentLayer->flushCompositingStateForThisLayerOnly();
273
    if (m_pageOverlayLayer)
274
        m_pageOverlayLayer->flushCompositingStateForThisLayerOnly();
275
276
    bool didSync = m_webPage->corePage()->mainFrame()->view()->flushCompositingStateIncludingSubframes();
277
278
    flushPendingImageBackingChanges();
279
280
    if (m_shouldSyncRootLayer) {
281
        m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetRootCompositingLayer(toCoordinatedGraphicsLayer(m_rootLayer.get())->id()));
282
        m_shouldSyncRootLayer = false;
283
        m_shouldSyncFrame = true;
284
    }
285
286
    for (size_t i = 0; i < m_detachedLayers.size(); ++i)
287
        m_webPage->send(Messages::LayerTreeCoordinatorProxy::DeleteCompositingLayer(m_detachedLayers[i]));
288
    m_detachedLayers.clear();
289
290
    if (m_shouldSyncFrame) {
291
        didSync = true;
292
293
        IntSize contentsSize = roundedIntSize(m_nonCompositedContentLayer->size());
294
        IntRect coveredRect = toCoordinatedGraphicsLayer(m_nonCompositedContentLayer.get())->coverRect();
295
        m_webPage->send(Messages::LayerTreeCoordinatorProxy::DidRenderFrame(contentsSize, coveredRect));
296
        m_waitingForUIProcess = true;
297
        m_shouldSyncFrame = false;
298
    } else
299
        unlockAnimations();
300
301
    if (m_forceRepaintAsyncCallbackID) {
302
        m_webPage->send(Messages::WebPageProxy::VoidCallback(m_forceRepaintAsyncCallbackID));
303
        m_forceRepaintAsyncCallbackID = 0;
304
    }
305
306
    return didSync;
307
}
308
309
void LayerTreeCoordinator::syncLayerState(CoordinatedLayerID id, const CoordinatedLayerInfo& info)
310
{
311
    if (m_shouldSendScrollPositionUpdate) {
312
        m_webPage->send(Messages::LayerTreeCoordinatorProxy::DidChangeScrollPosition(m_visibleContentsRect.location()));
313
        m_shouldSendScrollPositionUpdate = false;
314
    }
315
316
    m_shouldSyncFrame = true;
317
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetCompositingLayerState(id, info));
318
}
145
}
319
146
320
void LayerTreeCoordinator::syncLayerChildren(CoordinatedLayerID id, const Vector<CoordinatedLayerID>& children)
147
void LayerTreeCoordinator::resumeRendering()
321
{
148
{
322
    m_shouldSyncFrame = true;
149
    m_compositingCoordinator->resumeRendering();
323
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetCompositingLayerChildren(id, children));
324
}
150
}
325
151
326
#if USE(GRAPHICS_SURFACE)
152
const IntSize& LayerTreeCoordinator::viewSize() const
327
void LayerTreeCoordinator::createCanvas(CoordinatedLayerID id, PlatformLayer* canvasPlatformLayer)
328
{
153
{
329
    m_shouldSyncFrame = true;
154
    return m_webPage->size();
330
    GraphicsSurfaceToken token = canvasPlatformLayer->graphicsSurfaceToken();
331
    IntSize canvasSize = canvasPlatformLayer->platformLayerSize();
332
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateCanvas(id, canvasSize, token));
333
}
155
}
334
156
335
void LayerTreeCoordinator::syncCanvas(CoordinatedLayerID id, PlatformLayer* canvasPlatformLayer)
157
void LayerTreeCoordinator::layoutIfNeeded()
336
{
158
{
337
    m_shouldSyncFrame = true;
159
    m_webPage->layoutIfNeeded();
338
    uint32_t frontBuffer = canvasPlatformLayer->copyToGraphicsSurface();
339
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SyncCanvas(id, frontBuffer));
340
}
160
}
341
161
342
void LayerTreeCoordinator::destroyCanvas(CoordinatedLayerID id)
162
bool LayerTreeCoordinator::isOpaqueContents()
343
{
163
{
344
    if (m_isPurging)
164
    return m_webPage->drawsBackground() && !m_webPage->drawsTransparentBackground();
345
        return;
346
347
    m_shouldSyncFrame = true;
348
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::DestroyCanvas(id));
349
}
165
}
350
#endif
351
166
352
#if ENABLE(CSS_FILTERS)
167
void LayerTreeCoordinator::didPerformScheduledLayerFlush(bool didSync)
353
void LayerTreeCoordinator::syncLayerFilters(CoordinatedLayerID id, const FilterOperations& filters)
354
{
168
{
355
    m_shouldSyncFrame = true;
169
    if (m_forceRepaintAsyncCallbackID) {
356
#if ENABLE(CSS_SHADERS)
170
        m_compositingCoordinatorMessageClient->invokeForceRepaintAsyncCallback(m_forceRepaintAsyncCallbackID);
357
    checkCustomFilterProgramProxies(filters);
171
        m_forceRepaintAsyncCallbackID = 0;
358
#endif
359
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetCompositingLayerFilters(id, filters));
360
}
361
#endif
362
363
#if ENABLE(CSS_SHADERS)
364
void LayerTreeCoordinator::checkCustomFilterProgramProxies(const FilterOperations& filters)
365
{
366
    // We need to create the WebCustomFilterProgramProxy objects before we get to serialize the
367
    // custom filters to the other process. That's because WebCustomFilterProgramProxy needs
368
    // to link back to the coordinator, so that we can send a message to the UI process when 
369
    // the program is not needed anymore.
370
    // Note that the serialization will only happen at a later time in ArgumentCoder<WebCore::FilterOperations>::encode.
371
    // At that point the program will only be serialized once. All the other times it will only use the ID of the program.
372
    for (size_t i = 0; i < filters.size(); ++i) {
373
        const FilterOperation* operation = filters.at(i);
374
        if (operation->getOperationType() != FilterOperation::VALIDATED_CUSTOM)
375
            continue;
376
        const ValidatedCustomFilterOperation* customOperation = static_cast<const ValidatedCustomFilterOperation*>(operation);
377
        ASSERT(customOperation->validatedProgram()->isInitialized());
378
        TextureMapperPlatformCompiledProgram* program = customOperation->validatedProgram()->platformCompiledProgram();
379
        
380
        RefPtr<WebCustomFilterProgramProxy> customFilterProgramProxy;
381
        if (program->client())
382
            customFilterProgramProxy = static_cast<WebCustomFilterProgramProxy*>(program->client());
383
        else {
384
            customFilterProgramProxy = WebCustomFilterProgramProxy::create();
385
            program->setClient(customFilterProgramProxy);
386
        }
387
        
388
        if (!customFilterProgramProxy->client()) {
389
            customFilterProgramProxy->setClient(this);
390
            m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateCustomFilterProgram(customFilterProgramProxy->id(), customOperation->validatedProgram()->validatedProgramInfo()));
391
        } else {
392
            // If the client was not disconnected then this coordinator must be the client for it.
393
            ASSERT(customFilterProgramProxy->client() == this);
394
        }
395
    }
172
    }
396
}
397
398
void LayerTreeCoordinator::removeCustomFilterProgramProxy(WebCustomFilterProgramProxy* customFilterProgramProxy)
399
{
400
    // At this time the shader is not needed anymore, so we remove it from our set and 
401
    // send a message to the other process to delete it.
402
    m_customFilterPrograms.remove(customFilterProgramProxy);
403
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveCustomFilterProgram(customFilterProgramProxy->id()));
404
}
405
406
void LayerTreeCoordinator::disconnectCustomFilterPrograms()
407
{
408
    // Make sure that WebCore will not call into this coordinator anymore.
409
    HashSet<WebCustomFilterProgramProxy*>::iterator iter = m_customFilterPrograms.begin();
410
    for (; iter != m_customFilterPrograms.end(); ++iter)
411
        (*iter)->setClient(0);
412
}
413
#endif
414
415
void LayerTreeCoordinator::detachLayer(CoordinatedGraphicsLayer* layer)
416
{
417
    m_registeredLayers.remove(layer);
418
    m_shouldSyncFrame = true;
419
    m_detachedLayers.append(layer->id());
420
    scheduleLayerFlush();
421
}
422
423
static void updateOffsetFromViewportForSelf(RenderLayer* renderLayer)
424
{
425
    // These conditions must match the conditions in RenderLayerCompositor::requiresCompositingForPosition.
426
    RenderLayerBacking* backing = renderLayer->backing();
427
    if (!backing)
428
        return;
429
430
    RenderStyle* style = renderLayer->renderer()->style();
431
    if (!style)
432
        return;
433
434
    if (!renderLayer->renderer()->isOutOfFlowPositioned() || renderLayer->renderer()->style()->position() != FixedPosition)
435
        return;
436
437
    if (!renderLayer->renderer()->container()->isRenderView())
438
        return;
439
440
    if (!renderLayer->isStackingContext())
441
        return;
442
443
    CoordinatedGraphicsLayer* graphicsLayer = toCoordinatedGraphicsLayer(backing->graphicsLayer());
444
    graphicsLayer->setFixedToViewport(true);
445
}
446
447
static void updateOffsetFromViewportForLayer(RenderLayer* renderLayer)
448
{
449
    updateOffsetFromViewportForSelf(renderLayer);
450
451
    if (renderLayer->firstChild())
452
        updateOffsetFromViewportForLayer(renderLayer->firstChild());
453
    if (renderLayer->nextSibling())
454
        updateOffsetFromViewportForLayer(renderLayer->nextSibling());
455
}
456
457
void LayerTreeCoordinator::syncFixedLayers()
458
{
459
    if (!m_webPage->corePage()->settings() || !m_webPage->corePage()->settings()->acceleratedCompositingForFixedPositionEnabled())
460
        return;
461
462
    if (!m_webPage->mainFrame()->view()->hasViewportConstrainedObjects())
463
        return;
464
465
    RenderLayer* rootRenderLayer = m_webPage->mainFrame()->contentRenderer()->compositor()->rootRenderLayer();
466
    ASSERT(rootRenderLayer);
467
    if (rootRenderLayer->firstChild())
468
        updateOffsetFromViewportForLayer(rootRenderLayer->firstChild());
469
}
470
471
void LayerTreeCoordinator::lockAnimations()
472
{
473
    m_animationsLocked = true;
474
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetAnimationsLocked(true));
475
}
476
477
void LayerTreeCoordinator::unlockAnimations()
478
{
479
    if (!m_animationsLocked)
480
        return;
481
482
    m_animationsLocked = false;
483
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetAnimationsLocked(false));
484
}
485
486
void LayerTreeCoordinator::performScheduledLayerFlush()
487
{
488
    if (m_isSuspended || m_waitingForUIProcess)
489
        return;
490
491
    // We lock the animations while performing layout, to avoid flickers caused by animations continuing in the UI process while
492
    // the web process layout wants to cancel them.
493
    lockAnimations();
494
    syncDisplayState();
495
496
    // We can unlock the animations before flushing if there are no visible changes, for example if there are content updates
497
    // in a layer with opacity 0.
498
    bool canUnlockBeforeFlush = !m_isValid || !toCoordinatedGraphicsLayer(m_rootLayer.get())->hasPendingVisibleChanges();
499
    if (canUnlockBeforeFlush)
500
        unlockAnimations();
501
502
    if (!m_isValid)
503
        return;
504
173
505
    if (flushPendingLayerChanges())
174
    if (didSync && m_notifyAfterScheduledLayerFlush) {
506
        didPerformScheduledLayerFlush();
507
}
508
509
void LayerTreeCoordinator::syncDisplayState()
510
{
511
#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
512
    // Make sure that any previously registered animation callbacks are being executed before we flush the layers.
513
    m_webPage->corePage()->mainFrame()->view()->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(currentTime()));
514
#endif
515
516
    m_webPage->layoutIfNeeded();
517
}
518
519
void LayerTreeCoordinator::didPerformScheduledLayerFlush()
520
{
521
    if (m_notifyAfterScheduledLayerFlush) {
522
        static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
175
        static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
523
        m_notifyAfterScheduledLayerFlush = false;
176
        m_notifyAfterScheduledLayerFlush = false;
524
    }
177
    }
525
}
178
}
526
179
527
void LayerTreeCoordinator::layerFlushTimerFired(Timer<LayerTreeCoordinator>*)
180
void LayerTreeCoordinator::paintContents(WebCore::GraphicsContext& graphicsContext, const IntRect& clipRect)
528
{
529
    performScheduledLayerFlush();
530
}
531
532
void LayerTreeCoordinator::createPageOverlayLayer()
533
{
534
    ASSERT(!m_pageOverlayLayer);
535
536
    m_pageOverlayLayer = GraphicsLayer::create(this, this);
537
#ifndef NDEBUG
538
    m_pageOverlayLayer->setName("LayerTreeCoordinator page overlay content");
539
#endif
540
541
    m_pageOverlayLayer->setDrawsContent(true);
542
    m_pageOverlayLayer->setSize(m_webPage->size());
543
544
    m_rootLayer->addChild(m_pageOverlayLayer.get());
545
}
546
547
void LayerTreeCoordinator::destroyPageOverlayLayer()
548
{
549
    ASSERT(m_pageOverlayLayer);
550
    m_pageOverlayLayer->removeFromParent();
551
    m_pageOverlayLayer = nullptr;
552
}
553
554
PassRefPtr<CoordinatedImageBacking> LayerTreeCoordinator::createImageBackingIfNeeded(Image* image)
555
{
556
    CoordinatedImageBackingID imageID = CoordinatedImageBacking::getCoordinatedImageBackingID(image);
557
    ImageBackingMap::iterator it = m_imageBackings.find(imageID);
558
    RefPtr<CoordinatedImageBacking> imageBacking;
559
    if (it == m_imageBackings.end()) {
560
        imageBacking = CoordinatedImageBacking::create(this, image);
561
        m_imageBackings.add(imageID, imageBacking);
562
    } else
563
        imageBacking = it->value;
564
565
    return imageBacking;
566
}
567
568
void LayerTreeCoordinator::createImageBacking(CoordinatedImageBackingID imageID)
569
{
181
{
570
    m_shouldSyncFrame = true;
182
    m_webPage->drawRect(graphicsContext, clipRect);
571
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateImageBacking(imageID));
572
}
573
574
void LayerTreeCoordinator::updateImageBacking(CoordinatedImageBackingID imageID, const ShareableSurface::Handle& handle)
575
{
576
    m_shouldSyncFrame = true;
577
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::UpdateImageBacking(imageID, handle));
578
}
579
580
void LayerTreeCoordinator::clearImageBackingContents(CoordinatedImageBackingID imageID)
581
{
582
    m_shouldSyncFrame = true;
583
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::ClearImageBackingContents(imageID));
584
}
585
586
void LayerTreeCoordinator::removeImageBacking(CoordinatedImageBackingID imageID)
587
{
588
    if (m_isPurging)
589
        return;
590
591
    ASSERT(m_imageBackings.contains(imageID));
592
    m_shouldSyncFrame = true;
593
    m_imageBackings.remove(imageID);
594
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveImageBacking(imageID));
595
}
596
597
void LayerTreeCoordinator::flushPendingImageBackingChanges()
598
{
599
    ImageBackingMap::iterator end = m_imageBackings.end();
600
    for (ImageBackingMap::iterator iter = m_imageBackings.begin(); iter != end; ++iter)
601
        iter->value->update();
602
}
603
604
void LayerTreeCoordinator::notifyAnimationStarted(const WebCore::GraphicsLayer*, double /* time */)
605
{
606
}
607
608
void LayerTreeCoordinator::notifyFlushRequired(const WebCore::GraphicsLayer*)
609
{
610
}
611
612
void LayerTreeCoordinator::paintContents(const WebCore::GraphicsLayer* graphicsLayer, WebCore::GraphicsContext& graphicsContext, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect)
613
{
614
    if (graphicsLayer == m_nonCompositedContentLayer) {
615
        m_webPage->drawRect(graphicsContext, clipRect);
616
        return;
617
    }
618
619
    if (graphicsLayer == m_pageOverlayLayer) {
620
        // Overlays contain transparent contents and won't clear the context as part of their rendering, so we do it here.
621
        graphicsContext.clearRect(clipRect);
622
        m_webPage->drawPageOverlay(graphicsContext, clipRect);
623
        return;
624
    }
625
}
183
}
626
184
627
PassOwnPtr<GraphicsLayer> LayerTreeCoordinator::createGraphicsLayer(GraphicsLayerClient* client)
185
void LayerTreeCoordinator::paintOverlayContents(WebCore::GraphicsContext& graphicsContext, const IntRect& clipRect)
628
{
186
{
629
    CoordinatedGraphicsLayer* layer = new CoordinatedGraphicsLayer(client);
187
    // Overlays contain transparent contents and won't clear the context as part of their rendering, so we do it here.
630
    layer->setCoordinator(this);
188
    graphicsContext.clearRect(clipRect);
631
    m_registeredLayers.add(layer);
189
    m_webPage->drawPageOverlay(graphicsContext, clipRect);
632
    layer->setContentsScale(m_contentsScale);
633
    layer->adjustVisibleRect();
634
    return adoptPtr(layer);
635
}
190
}
636
191
637
bool LayerTreeHost::supportsAcceleratedCompositing()
192
bool LayerTreeHost::supportsAcceleratedCompositing()
Lines 639-737 bool LayerTreeHost::supportsAcceleratedCompositing() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp_sec7
639
    return true;
194
    return true;
640
}
195
}
641
196
642
void LayerTreeCoordinator::createTile(CoordinatedLayerID layerID, uint32_t tileID, const SurfaceUpdateInfo& updateInfo, const WebCore::IntRect& tileRect)
643
{
644
    m_shouldSyncFrame = true;
645
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateTileForLayer(layerID, tileID, tileRect, updateInfo));
646
}
647
648
void LayerTreeCoordinator::updateTile(CoordinatedLayerID layerID, uint32_t tileID, const SurfaceUpdateInfo& updateInfo, const WebCore::IntRect& tileRect)
649
{
650
    m_shouldSyncFrame = true;
651
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::UpdateTileForLayer(layerID, tileID, tileRect, updateInfo));
652
}
653
654
void LayerTreeCoordinator::removeTile(CoordinatedLayerID layerID, uint32_t tileID)
655
{
656
    if (m_isPurging)
657
        return;
658
    m_shouldSyncFrame = true;
659
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveTileForLayer(layerID, tileID));
660
}
661
662
void LayerTreeCoordinator::createUpdateAtlas(int atlasID, const ShareableSurface::Handle& handle)
663
{
664
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateUpdateAtlas(atlasID, handle));
665
}
666
667
void LayerTreeCoordinator::removeUpdateAtlas(int atlasID)
668
{
669
    if (m_isPurging)
670
        return;
671
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveUpdateAtlas(atlasID));
672
}
673
674
WebCore::IntRect LayerTreeCoordinator::visibleContentsRect() const
675
{
676
    return m_visibleContentsRect;
677
}
678
679
680
void LayerTreeCoordinator::setLayerAnimations(CoordinatedLayerID layerID, const GraphicsLayerAnimations& animations)
681
{
682
    m_shouldSyncFrame = true;
683
    GraphicsLayerAnimations activeAnimations = animations.getActiveAnimations();
684
#if ENABLE(CSS_SHADERS)
685
    for (size_t i = 0; i < activeAnimations.animations().size(); ++i) {
686
        const KeyframeValueList& keyframes = animations.animations().at(i).keyframes();
687
        if (keyframes.property() != AnimatedPropertyWebkitFilter)
688
            continue;
689
        for (size_t j = 0; j < keyframes.size(); ++j) {
690
            const FilterAnimationValue* filterValue = static_cast<const FilterAnimationValue*>(keyframes.at(i));
691
            checkCustomFilterProgramProxies(*filterValue->value());
692
        }
693
    }
694
#endif
695
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetLayerAnimations(layerID, activeAnimations));
696
}
697
698
void LayerTreeCoordinator::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector)
197
void LayerTreeCoordinator::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector)
699
{
198
{
700
    bool contentsRectDidChange = rect != m_visibleContentsRect;
199
    m_compositingCoordinator->setVisibleContentsRect(rect, scale, trajectoryVector);
701
    bool contentsScaleDidChange = scale != m_contentsScale;
702
703
    // A zero trajectoryVector indicates that tiles all around the viewport are requested.
704
    toCoordinatedGraphicsLayer(m_nonCompositedContentLayer.get())->setVisibleContentRectTrajectoryVector(trajectoryVector);
705
200
706
    if (contentsRectDidChange || contentsScaleDidChange) {
707
        m_visibleContentsRect = rect;
708
        m_contentsScale = scale;
709
710
        HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator end = m_registeredLayers.end();
711
        for (HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator it = m_registeredLayers.begin(); it != end; ++it) {
712
            if (contentsScaleDidChange)
713
                (*it)->setContentsScale(scale);
714
            if (contentsRectDidChange)
715
                (*it)->adjustVisibleRect();
716
        }
717
    }
718
719
    scheduleLayerFlush();
720
    if (m_webPage->useFixedLayout())
201
    if (m_webPage->useFixedLayout())
721
        m_webPage->setFixedVisibleContentRect(rect);
202
        m_webPage->setFixedVisibleContentRect(rect);
722
    if (contentsRectDidChange)
723
        m_shouldSendScrollPositionUpdate = true;
724
}
203
}
725
204
726
GraphicsLayerFactory* LayerTreeCoordinator::graphicsLayerFactory()
205
GraphicsLayerFactory* LayerTreeCoordinator::graphicsLayerFactory()
727
{
206
{
728
    return this;
207
    return m_compositingCoordinator.get();
729
}
208
}
730
209
731
#if ENABLE(REQUEST_ANIMATION_FRAME)
210
#if ENABLE(REQUEST_ANIMATION_FRAME)
732
void LayerTreeCoordinator::scheduleAnimation()
211
void LayerTreeCoordinator::scheduleAnimation()
733
{
212
{
734
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RequestAnimationFrame());
213
    m_compositingCoordinatorMessageClient->requestAnimationFrame();
735
}
214
}
736
215
737
void LayerTreeCoordinator::animationFrameReady()
216
void LayerTreeCoordinator::animationFrameReady()
Lines 742-825 void LayerTreeCoordinator::animationFrameReady() a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp_sec8
742
221
743
void LayerTreeCoordinator::renderNextFrame()
222
void LayerTreeCoordinator::renderNextFrame()
744
{
223
{
745
    m_waitingForUIProcess = false;
224
    m_compositingCoordinator->renderNextFrame();
746
    scheduleLayerFlush();
747
    for (unsigned i = 0; i < m_updateAtlases.size(); ++i)
748
        m_updateAtlases[i]->didSwapBuffers();
749
}
750
751
bool LayerTreeCoordinator::layerTreeTileUpdatesAllowed() const
752
{
753
    return !m_isSuspended && !m_waitingForUIProcess;
754
}
225
}
755
226
756
void LayerTreeCoordinator::purgeBackingStores()
227
void LayerTreeCoordinator::purgeBackingStores()
757
{
228
{
758
    TemporaryChange<bool> purgingToggle(m_isPurging, true);
229
    m_compositingCoordinator->purgeBackingStores();
759
760
    HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator end = m_registeredLayers.end();
761
    for (HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator it = m_registeredLayers.begin(); it != end; ++it)
762
        (*it)->purgeBackingStores();
763
764
    m_imageBackings.clear();
765
    m_updateAtlases.clear();
766
}
767
768
PassOwnPtr<WebCore::GraphicsContext> LayerTreeCoordinator::beginContentUpdate(const WebCore::IntSize& size, ShareableBitmap::Flags flags, int& atlasID, WebCore::IntPoint& offset)
769
{
770
    OwnPtr<WebCore::GraphicsContext> graphicsContext;
771
    for (unsigned i = 0; i < m_updateAtlases.size(); ++i) {
772
        UpdateAtlas* atlas = m_updateAtlases[i].get();
773
        if (atlas->flags() == flags) {
774
            // This will return null if there is no available buffer space.
775
            graphicsContext = atlas->beginPaintingOnAvailableBuffer(atlasID, size, offset);
776
            if (graphicsContext)
777
                return graphicsContext.release();
778
        }
779
    }
780
781
    static const int ScratchBufferDimension = 1024; // Should be a power of two.
782
    m_updateAtlases.append(adoptPtr(new UpdateAtlas(this, ScratchBufferDimension, flags)));
783
    scheduleReleaseInactiveAtlases();
784
    return m_updateAtlases.last()->beginPaintingOnAvailableBuffer(atlasID, size, offset);
785
}
786
787
const double ReleaseInactiveAtlasesTimerInterval = 0.5;
788
789
void LayerTreeCoordinator::scheduleReleaseInactiveAtlases()
790
{
791
    if (!m_releaseInactiveAtlasesTimer.isActive())
792
        m_releaseInactiveAtlasesTimer.startRepeating(ReleaseInactiveAtlasesTimerInterval);
793
}
794
795
void LayerTreeCoordinator::releaseInactiveAtlasesTimerFired(Timer<LayerTreeCoordinator>*)
796
{
797
    // We always want to keep one atlas for non-composited content.
798
    OwnPtr<UpdateAtlas> atlasToKeepAnyway;
799
    bool foundActiveAtlasForNonCompositedContent = false;
800
    for (int i = m_updateAtlases.size() - 1;  i >= 0; --i) {
801
        UpdateAtlas* atlas = m_updateAtlases[i].get();
802
        if (!atlas->isInUse())
803
            atlas->addTimeInactive(ReleaseInactiveAtlasesTimerInterval);
804
        bool usableForNonCompositedContent = atlas->flags() == ShareableBitmap::NoFlags;
805
        if (atlas->isInactive()) {
806
            if (!foundActiveAtlasForNonCompositedContent && !atlasToKeepAnyway && usableForNonCompositedContent)
807
                atlasToKeepAnyway = m_updateAtlases[i].release();
808
            m_updateAtlases.remove(i);
809
        } else if (usableForNonCompositedContent)
810
            foundActiveAtlasForNonCompositedContent = true;
811
    }
812
813
    if (!foundActiveAtlasForNonCompositedContent && atlasToKeepAnyway)
814
        m_updateAtlases.append(atlasToKeepAnyway.release());
815
816
    if (m_updateAtlases.size() <= 1)
817
        m_releaseInactiveAtlasesTimer.stop();
818
}
230
}
819
231
820
void LayerTreeCoordinator::setBackgroundColor(const WebCore::Color& color)
232
void LayerTreeCoordinator::setBackgroundColor(const WebCore::Color& color)
821
{
233
{
822
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetBackgroundColor(color));
234
    m_compositingCoordinatorMessageClient->setBackgroundColor(color);
823
}
235
}
824
236
825
} // namespace WebKit
237
} // namespace WebKit
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h -119 / +21 lines
Lines 1-5 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h_sec1
1
/*
1
/*
2
    Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
2
    Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3
    Copyright (C) 2012 Company 100, Inc. All rights reserved.
3
4
4
    This library is free software; you can redistribute it and/or
5
    This library is free software; you can redistribute it and/or
5
    modify it under the terms of the GNU Library General Public
6
    modify it under the terms of the GNU Library General Public
Lines 22-59 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h_sec2
22
23
23
#if USE(COORDINATED_GRAPHICS)
24
#if USE(COORDINATED_GRAPHICS)
24
25
25
#include "CoordinatedGraphicsLayer.h"
26
#include "CompositingCoordinator.h"
26
#include "CoordinatedImageBacking.h"
27
#include "LayerTreeContext.h"
27
#include "LayerTreeContext.h"
28
#include "LayerTreeHost.h"
28
#include "LayerTreeHost.h"
29
#include "Timer.h"
29
#include "WebCompositingCoordinatorMessageClient.h"
30
#include "UpdateAtlas.h"
31
#include <WebCore/GraphicsLayerClient.h>
32
#include <WebCore/GraphicsLayerFactory.h>
33
#include <wtf/OwnPtr.h>
30
#include <wtf/OwnPtr.h>
31
#include <wtf/RefPtr.h>
34
32
35
#if ENABLE(CSS_SHADERS)
33
namespace WebCore {
36
#include "WebCustomFilterProgramProxy.h"
34
class GraphicsLayerFactory;
37
#endif
35
}
38
36
39
namespace WebKit {
37
namespace WebKit {
40
38
41
class UpdateInfo;
39
class UpdateInfo;
42
class WebPage;
40
class WebPage;
43
41
44
class LayerTreeCoordinator : public LayerTreeHost, WebCore::GraphicsLayerClient
42
class LayerTreeCoordinator : public LayerTreeHost, public CompositingCoordinatorClient {
45
    , public CoordinatedGraphicsLayerClient
46
    , public CoordinatedImageBacking::Coordinator
47
    , public UpdateAtlasClient
48
    , public WebCore::GraphicsLayerFactory
49
#if ENABLE(CSS_SHADERS)
50
    , WebCustomFilterProgramProxyClient
51
#endif
52
{
53
public:
43
public:
54
    static PassRefPtr<LayerTreeCoordinator> create(WebPage*);
44
    static PassRefPtr<LayerTreeCoordinator> create(WebPage*);
55
    virtual ~LayerTreeCoordinator();
45
    virtual ~LayerTreeCoordinator();
56
46
47
    // Reimplementations from LayerTreeHost
57
    virtual const LayerTreeContext& layerTreeContext() { return m_layerTreeContext; }
48
    virtual const LayerTreeContext& layerTreeContext() { return m_layerTreeContext; }
58
    virtual void setLayerFlushSchedulingEnabled(bool);
49
    virtual void setLayerFlushSchedulingEnabled(bool);
59
    virtual void scheduleLayerFlush();
50
    virtual void scheduleLayerFlush();
Lines 73-204 public: a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h_sec3
73
    virtual void setPageOverlayOpacity(float);
64
    virtual void setPageOverlayOpacity(float);
74
    virtual bool pageOverlayShouldApplyFadeWhenPainting() const { return false; }
65
    virtual bool pageOverlayShouldApplyFadeWhenPainting() const { return false; }
75
66
76
    virtual void pauseRendering() { m_isSuspended = true; }
67
    virtual void pauseRendering();
77
    virtual void resumeRendering() { m_isSuspended = false; scheduleLayerFlush(); }
68
    virtual void resumeRendering();
78
    virtual void deviceScaleFactorDidChange() { }
69
    virtual void deviceScaleFactorDidChange() { }
79
    virtual PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(WebCore::Image*) OVERRIDE;
80
70
81
    virtual void createTile(CoordinatedLayerID, uint32_t tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&);
82
    virtual void updateTile(CoordinatedLayerID, uint32_t tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&);
83
    virtual void removeTile(CoordinatedLayerID, uint32_t tileID);
84
    virtual WebCore::IntRect visibleContentsRect() const;
85
    virtual void renderNextFrame();
71
    virtual void renderNextFrame();
86
    virtual void purgeBackingStores();
72
    virtual void purgeBackingStores();
87
    virtual bool layerTreeTileUpdatesAllowed() const;
88
    virtual void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint&);
73
    virtual void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint&);
89
    virtual void didReceiveLayerTreeCoordinatorMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
74
    virtual void didReceiveLayerTreeCoordinatorMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
90
    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() OVERRIDE;
75
    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() OVERRIDE;
91
92
    virtual void syncLayerState(CoordinatedLayerID, const CoordinatedLayerInfo&);
93
    virtual void syncLayerChildren(CoordinatedLayerID, const Vector<CoordinatedLayerID>&);
94
    virtual void setLayerAnimations(CoordinatedLayerID, const WebCore::GraphicsLayerAnimations&);
95
#if ENABLE(CSS_FILTERS)
96
    virtual void syncLayerFilters(CoordinatedLayerID, const WebCore::FilterOperations&);
97
#endif
98
#if USE(GRAPHICS_SURFACE)
99
    virtual void createCanvas(CoordinatedLayerID, WebCore::PlatformLayer*) OVERRIDE;
100
    virtual void syncCanvas(CoordinatedLayerID, WebCore::PlatformLayer*) OVERRIDE;
101
    virtual void destroyCanvas(CoordinatedLayerID) OVERRIDE;
102
#endif
103
    virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*);
104
    virtual void syncFixedLayers();
105
106
    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, int& atlasID, WebCore::IntPoint&);
107
108
    // UpdateAtlasClient
109
    virtual void createUpdateAtlas(int atlasID, const ShareableSurface::Handle&);
110
    virtual void removeUpdateAtlas(int atlasID);
111
112
#if ENABLE(REQUEST_ANIMATION_FRAME)
76
#if ENABLE(REQUEST_ANIMATION_FRAME)
113
    virtual void scheduleAnimation() OVERRIDE;
77
    virtual void scheduleAnimation() OVERRIDE;
114
#endif
78
#endif
115
    virtual void setBackgroundColor(const WebCore::Color&) OVERRIDE;
79
    virtual void setBackgroundColor(const WebCore::Color&) OVERRIDE;
116
80
81
    // Reimplementations from CompositingCoordinatorClient
82
    virtual const WebCore::IntSize& viewSize() const OVERRIDE;
83
    virtual void didPerformScheduledLayerFlush(bool didSync) OVERRIDE;
84
    virtual bool isOpaqueContents() OVERRIDE;
85
    virtual void layoutIfNeeded() OVERRIDE;
86
    virtual void paintContents(WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) OVERRIDE;
87
    virtual void paintOverlayContents(WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) OVERRIDE;
88
117
protected:
89
protected:
118
    explicit LayerTreeCoordinator(WebPage*);
90
    explicit LayerTreeCoordinator(WebPage*);
119
91
120
private:
92
private:
121
    // GraphicsLayerClient
122
    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
123
    virtual void notifyFlushRequired(const WebCore::GraphicsLayer*);
124
    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect);
125
126
    // CoordinatedImageBacking::Coordinator
127
    virtual void createImageBacking(CoordinatedImageBackingID) OVERRIDE;
128
    virtual void updateImageBacking(CoordinatedImageBackingID, const ShareableSurface::Handle&) OVERRIDE;
129
    virtual void clearImageBackingContents(CoordinatedImageBackingID) OVERRIDE;
130
    virtual void removeImageBacking(CoordinatedImageBackingID) OVERRIDE;
131
132
    void flushPendingImageBackingChanges();
133
134
    // GraphicsLayerFactory
135
    virtual PassOwnPtr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayerClient*) OVERRIDE;
136
137
    // LayerTreeCoordinator
138
    void createPageOverlayLayer();
139
    void destroyPageOverlayLayer();
140
    bool flushPendingLayerChanges();
141
    void cancelPendingLayerFlush();
142
    void performScheduledLayerFlush();
143
    void didPerformScheduledLayerFlush();
144
    void syncDisplayState();
145
    void lockAnimations();
146
    void unlockAnimations();
147
148
    void layerFlushTimerFired(WebCore::Timer<LayerTreeCoordinator>*);
149
150
    void scheduleReleaseInactiveAtlases();
151
#if ENABLE(REQUEST_ANIMATION_FRAME)
93
#if ENABLE(REQUEST_ANIMATION_FRAME)
152
    void animationFrameReady();
94
    void animationFrameReady();
153
#endif
95
#endif
154
96
155
    void releaseInactiveAtlasesTimerFired(WebCore::Timer<LayerTreeCoordinator>*);
97
    RefPtr<WebCompositingCoordinatorMessageClient> m_compositingCoordinatorMessageClient;
156
98
    OwnPtr<CompositingCoordinator> m_compositingCoordinator;
157
#if ENABLE(CSS_SHADERS)
158
    // WebCustomFilterProgramProxyClient
159
    void removeCustomFilterProgramProxy(WebCustomFilterProgramProxy*);
160
161
    void checkCustomFilterProgramProxies(const WebCore::FilterOperations&);
162
    void disconnectCustomFilterPrograms();
163
#endif
164
165
    OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
166
167
    // The layer which contains all non-composited content.
168
    OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
169
170
    // The page overlay layer. Will be null if there's no page overlay.
171
    OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer;
172
173
    HashSet<WebCore::CoordinatedGraphicsLayer*> m_registeredLayers;
174
    Vector<CoordinatedLayerID> m_detachedLayers;
175
    typedef HashMap<CoordinatedImageBackingID, RefPtr<CoordinatedImageBacking> > ImageBackingMap;
176
    ImageBackingMap m_imageBackings;
177
    Vector<OwnPtr<UpdateAtlas> > m_updateAtlases;
178
179
#if ENABLE(CSS_SHADERS)
180
    HashSet<WebCustomFilterProgramProxy*> m_customFilterPrograms;
181
#endif
182
99
183
    bool m_notifyAfterScheduledLayerFlush;
100
    bool m_notifyAfterScheduledLayerFlush;
184
    bool m_isValid;
185
    // We don't send the messages related to releasing resources to UI Process during purging, because UI Process already had removed all resources.
186
    bool m_isPurging;
187
188
    bool m_waitingForUIProcess;
189
    bool m_isSuspended;
190
    WebCore::IntRect m_visibleContentsRect;
191
    float m_contentsScale;
192
    bool m_shouldSendScrollPositionUpdate;
193
101
194
    LayerTreeContext m_layerTreeContext;
102
    LayerTreeContext m_layerTreeContext;
195
    bool m_shouldSyncFrame;
196
    bool m_shouldSyncRootLayer;
197
    WebCore::Timer<LayerTreeCoordinator> m_layerFlushTimer;
198
    WebCore::Timer<LayerTreeCoordinator> m_releaseInactiveAtlasesTimer;
199
    bool m_layerFlushSchedulingEnabled;
200
    uint64_t m_forceRepaintAsyncCallbackID;
103
    uint64_t m_forceRepaintAsyncCallbackID;
201
    bool m_animationsLocked;
202
};
104
};
203
105
204
}
106
}
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.cpp +263 lines
Line 0 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.cpp_sec1
1
/*
2
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
3
 * Copyright (C) 2012 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
31
#include "WebCompositingCoordinatorMessageClient.h"
32
33
#include "CoordinatedGraphicsArgumentCoders.h"
34
#include "LayerTreeCoordinatorProxyMessages.h"
35
#include "MessageID.h"
36
#include "SurfaceUpdateInfo.h"
37
#include "WebCoreArgumentCoders.h"
38
#include "WebPage.h"
39
#include "WebPageProxyMessages.h"
40
41
#if ENABLE(CSS_SHADERS)
42
#include "CustomFilterValidatedProgram.h"
43
#include "ValidatedCustomFilterOperation.h"
44
#endif
45
46
using namespace WebCore;
47
48
namespace WebKit {
49
50
PassRefPtr<WebCompositingCoordinatorMessageClient> WebCompositingCoordinatorMessageClient::create(WebPage* webPage)
51
{
52
    return adoptRef(new WebCompositingCoordinatorMessageClient(webPage));
53
}
54
55
WebCompositingCoordinatorMessageClient::~WebCompositingCoordinatorMessageClient()
56
{
57
#if ENABLE(CSS_SHADERS)
58
    disconnectCustomFilterPrograms();
59
#endif
60
}
61
62
WebCompositingCoordinatorMessageClient::WebCompositingCoordinatorMessageClient(WebPage* webPage)
63
    : m_webPage(webPage)
64
{
65
66
}
67
68
void WebCompositingCoordinatorMessageClient::setRootCompositingLayer(CoordinatedLayerID id)
69
{
70
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetRootCompositingLayer(id));
71
}
72
73
void WebCompositingCoordinatorMessageClient::setCompositingLayerState(CoordinatedLayerID id, const CoordinatedLayerInfo& info)
74
{
75
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetCompositingLayerState(id, info));
76
}
77
78
void WebCompositingCoordinatorMessageClient::setCompositingLayerChildren(CoordinatedLayerID id, const Vector<CoordinatedLayerID>& children)
79
{
80
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetCompositingLayerChildren(id, children));
81
}
82
83
#if ENABLE(CSS_FILTERS)
84
void WebCompositingCoordinatorMessageClient::setCompositingLayerFilters(CoordinatedLayerID id, const FilterOperations& filters)
85
{
86
#if ENABLE(CSS_SHADERS)
87
    checkCustomFilterProgramProxies(filters);
88
#endif
89
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetCompositingLayerFilters(id, filters));
90
}
91
#endif
92
93
void WebCompositingCoordinatorMessageClient::deleteCompositingLayer(CoordinatedLayerID id)
94
{
95
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::DeleteCompositingLayer(id));
96
}
97
98
void WebCompositingCoordinatorMessageClient::createTileForLayer(CoordinatedLayerID layerID, uint32_t tileID, const IntRect& tileRect, const SurfaceUpdateInfo& updateInfo)
99
{
100
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateTileForLayer(layerID, tileID, tileRect, updateInfo));
101
}
102
103
void WebCompositingCoordinatorMessageClient::updateTileForLayer(CoordinatedLayerID layerID, uint32_t tileID, const IntRect& tileRect, const SurfaceUpdateInfo& updateInfo)
104
{
105
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::UpdateTileForLayer(layerID, tileID, tileRect, updateInfo));
106
}
107
108
void WebCompositingCoordinatorMessageClient::removeTileForLayer(CoordinatedLayerID layerID, uint32_t tileID)
109
{
110
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveTileForLayer(layerID, tileID));
111
}
112
113
void WebCompositingCoordinatorMessageClient::createUpdateAtlas(int atlasID, const ShareableSurface::Handle& handle)
114
{
115
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateUpdateAtlas(atlasID, handle));
116
}
117
118
void WebCompositingCoordinatorMessageClient::removeUpdateAtlas(int atlasID)
119
{
120
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveUpdateAtlas(atlasID));
121
}
122
123
void WebCompositingCoordinatorMessageClient::createImageBacking(CoordinatedImageBackingID imageID)
124
{
125
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateImageBacking(imageID));
126
}
127
128
void WebCompositingCoordinatorMessageClient::updateImageBacking(CoordinatedImageBackingID imageID, const ShareableSurface::Handle& handle)
129
{
130
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::UpdateImageBacking(imageID, handle));
131
}
132
133
void WebCompositingCoordinatorMessageClient::clearImageBackingContents(CoordinatedImageBackingID imageID)
134
{
135
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::ClearImageBackingContents(imageID));
136
}
137
138
void WebCompositingCoordinatorMessageClient::removeImageBacking(CoordinatedImageBackingID imageID)
139
{
140
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveImageBacking(imageID));
141
}
142
143
void WebCompositingCoordinatorMessageClient::didRenderFrame(const IntSize& contentsSize, const IntRect& coveredRect)
144
{
145
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::DidRenderFrame(contentsSize, coveredRect));
146
}
147
148
void WebCompositingCoordinatorMessageClient::didChangeScrollPosition(const IntPoint& position)
149
{
150
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::DidChangeScrollPosition(position));
151
}
152
153
#if USE(GRAPHICS_SURFACE)
154
void WebCompositingCoordinatorMessageClient::createCanvas(CoordinatedLayerID id, const IntSize& canvasSize, const GraphicsSurfaceToken& token)
155
{
156
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateCanvas(id, canvasSize, token));
157
}
158
159
void WebCompositingCoordinatorMessageClient::syncCanvas(CoordinatedLayerID id, uint32_t frontBuffer)
160
{
161
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SyncCanvas(id, frontBuffer));
162
}
163
164
void WebCompositingCoordinatorMessageClient::destroyCanvas(CoordinatedLayerID id)
165
{
166
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::DestroyCanvas(id));
167
}
168
#endif
169
170
void WebCompositingCoordinatorMessageClient::setLayerAnimations(CoordinatedLayerID layerID, const GraphicsLayerAnimations& activeAnimations)
171
{
172
#if ENABLE(CSS_SHADERS)
173
    for (size_t i = 0; i < activeAnimations.animations().size(); ++i) {
174
        const KeyframeValueList& keyframes = activeAnimations.animations().at(i).keyframes();
175
        if (keyframes.property() != AnimatedPropertyWebkitFilter)
176
            continue;
177
        for (size_t j = 0; j < keyframes.size(); ++j) {
178
            const FilterAnimationValue* filterValue = static_cast<const FilterAnimationValue*>(keyframes.at(i));
179
            checkCustomFilterProgramProxies(*filterValue->value());
180
        }
181
    }
182
#endif
183
184
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetLayerAnimations(layerID, activeAnimations));
185
}
186
187
void WebCompositingCoordinatorMessageClient::setAnimationsLocked(bool isLocked)
188
{
189
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetAnimationsLocked(isLocked));
190
}
191
192
void WebCompositingCoordinatorMessageClient::setBackgroundColor(const WebCore::Color& color)
193
{
194
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetBackgroundColor(color));
195
}
196
197
#if ENABLE(REQUEST_ANIMATION_FRAME)
198
void WebCompositingCoordinatorMessageClient::requestAnimationFrame()
199
{
200
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RequestAnimationFrame());
201
}
202
#endif
203
204
void WebCompositingCoordinatorMessageClient::invokeForceRepaintAsyncCallback(uint64_t callbackID)
205
{
206
    m_webPage->send(Messages::WebPageProxy::VoidCallback(callbackID));
207
}
208
209
#if ENABLE(CSS_SHADERS)
210
void WebCompositingCoordinatorMessageClient::checkCustomFilterProgramProxies(const FilterOperations& filters)
211
{
212
    // We need to create the WebCustomFilterProgramProxy objects before we get to serialize the
213
    // custom filters to the other process. That's because WebCustomFilterProgramProxy needs
214
    // to link back to the coordinator, so that we can send a message to the UI process when
215
    // the program is not needed anymore.
216
    // Note that the serialization will only happen at a later time in ArgumentCoder<WebCore::FilterOperations>::encode.
217
    // At that point the program will only be serialized once. All the other times it will only use the ID of the program.
218
    for (size_t i = 0; i < filters.size(); ++i) {
219
        const FilterOperation* operation = filters.at(i);
220
        if (operation->getOperationType() != FilterOperation::VALIDATED_CUSTOM)
221
            continue;
222
        const ValidatedCustomFilterOperation* customOperation = static_cast<const ValidatedCustomFilterOperation*>(operation);
223
        ASSERT(customOperation->validatedProgram()->isInitialized());
224
        TextureMapperPlatformCompiledProgram* program = customOperation->validatedProgram()->platformCompiledProgram();
225
226
        RefPtr<WebCustomFilterProgramProxy> customFilterProgramProxy;
227
        if (program->client())
228
            customFilterProgramProxy = static_cast<WebCustomFilterProgramProxy*>(program->client());
229
        else {
230
            customFilterProgramProxy = WebCustomFilterProgramProxy::create();
231
            program->setClient(customFilterProgramProxy);
232
        }
233
234
        if (!customFilterProgramProxy->client()) {
235
            customFilterProgramProxy->setClient(this);
236
            m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateCustomFilterProgram(customFilterProgramProxy->id(), customOperation->validatedProgram()->validatedProgramInfo()));
237
        } else {
238
            // If the client was not disconnected then this coordinator must be the client for it.
239
            ASSERT(customFilterProgramProxy->client() == this);
240
        }
241
    }
242
}
243
244
void WebCompositingCoordinatorMessageClient::removeCustomFilterProgramProxy(WebCustomFilterProgramProxy* customFilterProgramProxy)
245
{
246
    // At this time the shader is not needed anymore, so we remove it from our set and
247
    // send a message to the other process to delete it.
248
    m_customFilterPrograms.remove(customFilterProgramProxy);
249
    m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveCustomFilterProgram(customFilterProgramProxy->id()));
250
}
251
252
void WebCompositingCoordinatorMessageClient::disconnectCustomFilterPrograms()
253
{
254
    // Make sure that WebCore will not call into this coordinator anymore.
255
    HashSet<WebCustomFilterProgramProxy*>::iterator iter = m_customFilterPrograms.begin();
256
    for (; iter != m_customFilterPrograms.end(); ++iter)
257
        (*iter)->setClient(0);
258
}
259
#endif
260
261
} // namespace WebKit
262
263
#endif // USE(COORDINATED_GRAPHICS)
- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.h +116 lines
Line 0 a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/WebCompositingCoordinatorMessageClient.h_sec1
1
/*
2
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
3
 * Copyright (C) 2012 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 WebCompositingCoordinatorMessageClient_h
28
#define WebCompositingCoordinatorMessageClient_h
29
30
#if USE(COORDINATED_GRAPHICS)
31
32
#include "CompositingCoordinatorClient.h"
33
34
#if ENABLE(CSS_SHADERS)
35
#include "WebCustomFilterProgramProxy.h"
36
#endif
37
38
namespace WebKit {
39
40
class WebPage;
41
42
class WebCompositingCoordinatorMessageClient : public RefCounted<WebCompositingCoordinatorMessageClient>
43
    , public CompositingCoordinatorMessageClient
44
#if ENABLE(CSS_SHADERS)
45
    , WebCustomFilterProgramProxyClient
46
#endif
47
{
48
    WTF_MAKE_NONCOPYABLE(WebCompositingCoordinatorMessageClient); WTF_MAKE_FAST_ALLOCATED;
49
public:
50
    static PassRefPtr<WebCompositingCoordinatorMessageClient> create(WebPage*);
51
52
    ~WebCompositingCoordinatorMessageClient();
53
54
    // CompositingCoordinatorMessageClient
55
    virtual void setRootCompositingLayer(CoordinatedLayerID) OVERRIDE;
56
    virtual void setCompositingLayerState(CoordinatedLayerID, const CoordinatedLayerInfo&) OVERRIDE;
57
    virtual void setCompositingLayerChildren(CoordinatedLayerID, const Vector<CoordinatedLayerID>&) OVERRIDE;
58
#if ENABLE(CSS_FILTERS)
59
    virtual void setCompositingLayerFilters(CoordinatedLayerID, const WebCore::FilterOperations&) OVERRIDE;
60
#endif
61
    virtual void deleteCompositingLayer(CoordinatedLayerID) OVERRIDE;
62
63
    virtual void createTileForLayer(CoordinatedLayerID, uint32_t tileID, const WebCore::IntRect&, const SurfaceUpdateInfo&) OVERRIDE;
64
    virtual void updateTileForLayer(CoordinatedLayerID, uint32_t tileID, const WebCore::IntRect&, const SurfaceUpdateInfo&) OVERRIDE;
65
    virtual void removeTileForLayer(CoordinatedLayerID, uint32_t tileID) OVERRIDE;
66
67
    virtual void createUpdateAtlas(int atlasID, const ShareableSurface::Handle&) OVERRIDE;
68
    virtual void removeUpdateAtlas(int atlasID) OVERRIDE;
69
70
    virtual void createImageBacking(CoordinatedImageBackingID) OVERRIDE;
71
    virtual void updateImageBacking(CoordinatedImageBackingID, const ShareableSurface::Handle&) OVERRIDE;
72
    virtual void clearImageBackingContents(CoordinatedImageBackingID) OVERRIDE;
73
    virtual void removeImageBacking(CoordinatedImageBackingID) OVERRIDE;
74
75
    virtual void didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect) OVERRIDE;
76
    virtual void didChangeScrollPosition(const WebCore::IntPoint& position) OVERRIDE;
77
78
#if USE(GRAPHICS_SURFACE)
79
    virtual void createCanvas(CoordinatedLayerID, const WebCore::IntSize&, const WebCore::GraphicsSurfaceToken&) OVERRIDE;
80
    virtual void syncCanvas(CoordinatedLayerID, uint32_t frontBuffer) OVERRIDE;
81
    virtual void destroyCanvas(CoordinatedLayerID) OVERRIDE;
82
#endif
83
84
    virtual void setLayerAnimations(CoordinatedLayerID, const WebCore::GraphicsLayerAnimations&) OVERRIDE;
85
    virtual void setAnimationsLocked(bool) OVERRIDE;
86
87
    void setBackgroundColor(const WebCore::Color&);
88
89
#if ENABLE(REQUEST_ANIMATION_FRAME)
90
    void requestAnimationFrame();
91
#endif
92
    void invokeForceRepaintAsyncCallback(uint64_t callbackID);
93
94
private:
95
    explicit WebCompositingCoordinatorMessageClient(WebPage*);
96
97
#if ENABLE(CSS_SHADERS)
98
    // WebCustomFilterProgramProxyClient
99
    void removeCustomFilterProgramProxy(WebCustomFilterProgramProxy*);
100
101
    void checkCustomFilterProgramProxies(const WebCore::FilterOperations& filters) OVERRIDE;
102
    void disconnectCustomFilterPrograms();
103
#endif
104
105
    WebPage* m_webPage;
106
107
#if ENABLE(CSS_SHADERS)
108
    HashSet<WebCustomFilterProgramProxy*> m_customFilterPrograms;
109
#endif
110
};
111
112
} // namespace WebKit
113
114
#endif
115
116
#endif // WebCompositingCoordinatorMessageClient_h

Return to Bug 104360