[Coordinated Graphics] Move CompositingCoordinator from platform to WebKit2 layer
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / CoordinatedGraphics / CoordinatedLayerTreeHost.h
1 /*
2     Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3     Copyright (C) 2013 Company 100, Inc.
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18     Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef CoordinatedLayerTreeHost_h
22 #define CoordinatedLayerTreeHost_h
23
24 #if USE(COORDINATED_GRAPHICS)
25
26 #include "CompositingCoordinator.h"
27 #include "LayerTreeHost.h"
28 #include <wtf/RunLoop.h>
29
30 namespace WebCore {
31 class CoordinatedSurface;
32 class GraphicsLayerFactory;
33 }
34
35 namespace WebKit {
36
37 class WebPage;
38
39 class CoordinatedLayerTreeHost : public LayerTreeHost, public CompositingCoordinator::Client
40 {
41 public:
42     static Ref<CoordinatedLayerTreeHost> create(WebPage&);
43     virtual ~CoordinatedLayerTreeHost();
44
45 protected:
46     explicit CoordinatedLayerTreeHost(WebPage&);
47
48     void scheduleLayerFlush() override;
49     void cancelPendingLayerFlush() override;
50     void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
51     void invalidate() override;
52
53     void forceRepaint() override;
54     bool forceRepaintAsync(uint64_t callbackID) override;
55     void sizeDidChange(const WebCore::IntSize& newSize) override;
56
57     void deviceOrPageScaleFactorChanged() override;
58     void pageBackgroundTransparencyChanged() override;
59
60     void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
61     void renderNextFrame();
62     void purgeBackingStores();
63     void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
64
65     WebCore::GraphicsLayerFactory* graphicsLayerFactory() override;
66
67 #if ENABLE(REQUEST_ANIMATION_FRAME)
68     void scheduleAnimation() override;
69 #endif
70
71     void setViewOverlayRootLayer(WebCore::GraphicsLayer*) override;
72
73     // CompositingCoordinator::Client
74     void didFlushRootLayer(const WebCore::FloatRect& visibleContentRect) override;
75     void notifyFlushRequired() override { scheduleLayerFlush(); };
76     void commitSceneState(const WebCore::CoordinatedGraphicsState&) override;
77     void paintLayerContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) override;
78
79 private:
80     void layerFlushTimerFired();
81
82 #if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
83     void didReceiveCoordinatedLayerTreeHostMessage(IPC::Connection&, IPC::MessageDecoder&) override;
84 #endif
85
86     static RefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
87
88     std::unique_ptr<CompositingCoordinator> m_coordinator;
89     bool m_isWaitingForRenderer { true };
90     uint64_t m_forceRepaintAsyncCallbackID { 0 };
91     RunLoop::Timer<CoordinatedLayerTreeHost> m_layerFlushTimer;
92 };
93
94 } // namespace WebKit
95
96 #endif // USE(COORDINATED_GRAPHICS)
97
98 #endif // CoordinatedLayerTreeHost_h