1 | /* |
2 | * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) |
3 | * Copyright (C) 2013 Company 100, Inc. All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
24 | * THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #ifndef CompositingCoordinator_h |
28 | #define CompositingCoordinator_h |
29 | |
30 | #if USE(COORDINATED_GRAPHICS) |
31 | |
32 | #include <WebCore/CoordinatedGraphicsLayer.h> |
33 | #include <WebCore/CoordinatedGraphicsState.h> |
34 | #include <WebCore/FloatPoint.h> |
35 | #include <WebCore/GraphicsLayerClient.h> |
36 | #include <WebCore/GraphicsLayerFactory.h> |
37 | #include <WebCore/IntRect.h> |
38 | #include <WebCore/NicosiaBuffer.h> |
39 | #include <WebCore/NicosiaPlatformLayer.h> |
40 | |
41 | namespace Nicosia { |
42 | class PaintingEngine; |
43 | } |
44 | |
45 | namespace WebCore { |
46 | class GraphicsContext; |
47 | class GraphicsLayer; |
48 | class Page; |
49 | } |
50 | |
51 | namespace WebKit { |
52 | |
53 | class CompositingCoordinator final : public WebCore::GraphicsLayerClient |
54 | , public WebCore::CoordinatedGraphicsLayerClient |
55 | , public WebCore::GraphicsLayerFactory { |
56 | WTF_MAKE_NONCOPYABLE(CompositingCoordinator); |
57 | public: |
58 | class Client { |
59 | public: |
60 | virtual void didFlushRootLayer(const WebCore::FloatRect& visibleContentRect) = 0; |
61 | virtual void notifyFlushRequired() = 0; |
62 | virtual void commitSceneState(const WebCore::CoordinatedGraphicsState&) = 0; |
63 | }; |
64 | |
65 | CompositingCoordinator(WebCore::Page*, CompositingCoordinator::Client&); |
66 | virtual ~CompositingCoordinator(); |
67 | |
68 | void invalidate(); |
69 | |
70 | void setRootCompositingLayer(WebCore::GraphicsLayer*); |
71 | void setViewOverlayRootLayer(WebCore::GraphicsLayer*); |
72 | void sizeDidChange(const WebCore::IntSize&); |
73 | void deviceOrPageScaleFactorChanged(); |
74 | |
75 | void setVisibleContentsRect(const WebCore::FloatRect&); |
76 | void renderNextFrame(); |
77 | |
78 | void createRootLayer(const WebCore::IntSize&); |
79 | WebCore::GraphicsLayer* rootLayer() const { return m_rootLayer.get(); } |
80 | WebCore::GraphicsLayer* rootCompositingLayer() const { return m_rootCompositingLayer; } |
81 | |
82 | void forceFrameSync() { m_shouldSyncFrame = true; } |
83 | |
84 | bool flushPendingLayerChanges(); |
85 | WebCore::CoordinatedGraphicsState& state() { return m_state; } |
86 | |
87 | void syncDisplayState(); |
88 | |
89 | double nextAnimationServiceTime() const; |
90 | |
91 | private: |
92 | // GraphicsLayerClient |
93 | void notifyFlushRequired(const WebCore::GraphicsLayer*) override; |
94 | float deviceScaleFactor() const override; |
95 | float pageScaleFactor() const override; |
96 | |
97 | // CoordinatedGraphicsLayerClient |
98 | bool isFlushingLayerChanges() const override { return m_isFlushingLayerChanges; } |
99 | WebCore::FloatRect visibleContentsRect() const override; |
100 | void detachLayer(WebCore::CoordinatedGraphicsLayer*) override; |
101 | void attachLayer(WebCore::CoordinatedGraphicsLayer*) override; |
102 | Nicosia::PaintingEngine& paintingEngine() override; |
103 | void syncLayerState() override; |
104 | |
105 | // GraphicsLayerFactory |
106 | Ref<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override; |
107 | |
108 | void initializeRootCompositingLayerIfNeeded(); |
109 | |
110 | void purgeBackingStores(); |
111 | |
112 | double timestamp() const; |
113 | |
114 | WebCore::Page* m_page; |
115 | CompositingCoordinator::Client& m_client; |
116 | |
117 | RefPtr<WebCore::GraphicsLayer> m_rootLayer; |
118 | WebCore::GraphicsLayer* m_rootCompositingLayer { nullptr }; |
119 | WebCore::GraphicsLayer* m_overlayCompositingLayer { nullptr }; |
120 | |
121 | struct { |
122 | RefPtr<Nicosia::Scene> scene; |
123 | Nicosia::Scene::State state; |
124 | } m_nicosia; |
125 | WebCore::CoordinatedGraphicsState m_state; |
126 | |
127 | HashMap<Nicosia::PlatformLayer::LayerID, WebCore::CoordinatedGraphicsLayer*> m_registeredLayers; |
128 | |
129 | std::unique_ptr<Nicosia::PaintingEngine> m_paintingEngine; |
130 | |
131 | // We don't send the messages related to releasing resources to renderer during purging, because renderer already had removed all resources. |
132 | bool m_isDestructing { false }; |
133 | bool m_isPurging { false }; |
134 | bool m_isFlushingLayerChanges { false }; |
135 | bool m_shouldSyncFrame { false }; |
136 | bool m_didInitializeRootCompositingLayer { false }; |
137 | |
138 | WebCore::FloatRect m_visibleContentsRect; |
139 | |
140 | double m_lastAnimationServiceTime { 0 }; |
141 | }; |
142 | |
143 | } |
144 | |
145 | #endif // namespace WebKit |
146 | |
147 | #endif // CompositingCoordinator_h |
148 | |