2 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3 * Copyright (C) 2013 Company 100, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef CompositingCoordinator_h
28 #define CompositingCoordinator_h
30 #if USE(COORDINATED_GRAPHICS)
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>
46 class GraphicsContext;
53 class CompositingCoordinator final : public WebCore::GraphicsLayerClient
54 , public WebCore::CoordinatedGraphicsLayerClient
55 , public WebCore::GraphicsLayerFactory {
56 WTF_MAKE_NONCOPYABLE(CompositingCoordinator);
60 virtual void didFlushRootLayer(const WebCore::FloatRect& visibleContentRect) = 0;
61 virtual void notifyFlushRequired() = 0;
62 virtual void commitSceneState(const WebCore::CoordinatedGraphicsState&) = 0;
65 CompositingCoordinator(WebCore::Page*, CompositingCoordinator::Client&);
66 virtual ~CompositingCoordinator();
70 void setRootCompositingLayer(WebCore::GraphicsLayer*);
71 void setViewOverlayRootLayer(WebCore::GraphicsLayer*);
72 void sizeDidChange(const WebCore::IntSize&);
73 void deviceOrPageScaleFactorChanged();
75 void setVisibleContentsRect(const WebCore::FloatRect&);
76 void renderNextFrame();
78 void createRootLayer(const WebCore::IntSize&);
79 WebCore::GraphicsLayer* rootLayer() const { return m_rootLayer.get(); }
80 WebCore::GraphicsLayer* rootCompositingLayer() const { return m_rootCompositingLayer; }
82 void forceFrameSync() { m_shouldSyncFrame = true; }
84 bool flushPendingLayerChanges();
85 WebCore::CoordinatedGraphicsState& state() { return m_state; }
87 void syncDisplayState();
89 double nextAnimationServiceTime() const;
92 // GraphicsLayerClient
93 void notifyFlushRequired(const WebCore::GraphicsLayer*) override;
94 float deviceScaleFactor() const override;
95 float pageScaleFactor() const override;
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;
105 // GraphicsLayerFactory
106 std::unique_ptr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;
108 void initializeRootCompositingLayerIfNeeded();
110 void purgeBackingStores();
112 double timestamp() const;
114 WebCore::Page* m_page;
115 CompositingCoordinator::Client& m_client;
117 std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
118 WebCore::GraphicsLayer* m_rootCompositingLayer { nullptr };
119 WebCore::GraphicsLayer* m_overlayCompositingLayer { nullptr };
122 RefPtr<Nicosia::Scene> scene;
123 Nicosia::Scene::State state;
125 WebCore::CoordinatedGraphicsState m_state;
127 HashMap<Nicosia::PlatformLayer::LayerID, WebCore::CoordinatedGraphicsLayer*> m_registeredLayers;
129 std::unique_ptr<Nicosia::PaintingEngine> m_paintingEngine;
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 };
138 WebCore::FloatRect m_visibleContentsRect;
140 double m_lastAnimationServiceTime { 0 };
145 #endif // namespace WebKit
147 #endif // CompositingCoordinator_h