Media queries and platform screen modernization and streamlining
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / mac / RemoteLayerTreeDrawingArea.h
1 /*
2  * Copyright (C) 2012-2014 Apple 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 #pragma once
27
28 #include "DrawingArea.h"
29 #include "GraphicsLayerCARemote.h"
30 #include "RemoteLayerTreeTransaction.h"
31 #include <WebCore/GraphicsLayerClient.h>
32 #include <WebCore/Timer.h>
33 #include <atomic>
34 #include <dispatch/dispatch.h>
35 #include <wtf/HashMap.h>
36 #include <wtf/WeakPtr.h>
37
38 namespace WebCore {
39 class PlatformCALayer;
40 }
41
42 namespace IPC {
43 class MessageEncoder;
44 }
45
46 namespace WebKit {
47
48 class RemoteLayerTreeContext;
49 class RemoteLayerTreeDisplayRefreshMonitor;
50
51 class RemoteLayerTreeDrawingArea : public DrawingArea, public WebCore::GraphicsLayerClient {
52     friend class RemoteLayerTreeDisplayRefreshMonitor;
53 public:
54     RemoteLayerTreeDrawingArea(WebPage&, const WebPageCreationParameters&);
55     virtual ~RemoteLayerTreeDrawingArea();
56
57     uint64_t nextTransactionID() const { return m_currentTransactionID + 1; }
58
59     WeakPtr<RemoteLayerTreeDrawingArea> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
60     
61 private:
62     // DrawingArea
63     void setNeedsDisplay() override;
64     void setNeedsDisplayInRect(const WebCore::IntRect&) override;
65     void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) override;
66     void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition, bool flushSynchronously, const WebCore::MachSendRight& fencePort) override;
67
68     WebCore::GraphicsLayerFactory* graphicsLayerFactory() override;
69     void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
70     void scheduleCompositingLayerFlush() override;
71     void scheduleCompositingLayerFlushImmediately() override;
72     void attachViewOverlayGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*) override;
73
74     void addTransactionCallbackID(uint64_t callbackID) override;
75
76     RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) override;
77     void willDestroyDisplayRefreshMonitor(WebCore::DisplayRefreshMonitor*);
78
79     bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) override;
80
81     void updatePreferences(const WebPreferencesStore&) override;
82
83     bool supportsAsyncScrolling() override { return true; }
84
85     void setLayerTreeStateIsFrozen(bool) override;
86
87     void forceRepaint() override;
88     bool forceRepaintAsync(uint64_t) override { return false; }
89
90     void setViewExposedRect(Optional<WebCore::FloatRect>) override;
91     Optional<WebCore::FloatRect> viewExposedRect() const override { return m_scrolledViewExposedRect; }
92
93     void acceleratedAnimationDidStart(uint64_t layerID, const String& key, double startTime) override;
94     void acceleratedAnimationDidEnd(uint64_t layerID, const String& key) override;
95
96 #if PLATFORM(IOS)
97     WebCore::FloatRect exposedContentRect() const override;
98     void setExposedContentRect(const WebCore::FloatRect&) override;
99 #endif
100
101     void didUpdate() override;
102
103 #if PLATFORM(IOS)
104     void setDeviceScaleFactor(float) override;
105 #endif
106
107     void mainFrameContentSizeChanged(const WebCore::IntSize&) override;
108
109     void viewStateDidChange(WebCore::ViewState::Flags changed, bool wantsDidUpdateViewState, const Vector<uint64_t>& callbackIDs) override;
110
111     bool adjustLayerFlushThrottling(WebCore::LayerFlushThrottleState::Flags) override;
112
113     bool dispatchDidLayout(WebCore::LayoutMilestones) override;
114
115     void updateScrolledExposedRect();
116     void updateRootLayers();
117
118     void flushLayers();
119
120     WebCore::TiledBacking* mainFrameTiledBacking() const;
121
122     uint64_t takeNextTransactionID() { return ++m_currentTransactionID; }
123
124     bool markLayersVolatileImmediatelyIfPossible() override;
125
126     class BackingStoreFlusher : public ThreadSafeRefCounted<BackingStoreFlusher> {
127     public:
128         static Ref<BackingStoreFlusher> create(IPC::Connection*, std::unique_ptr<IPC::MessageEncoder>, Vector<RetainPtr<CGContextRef>>);
129
130         void flush();
131         bool hasFlushed() const { return m_hasFlushed; }
132
133     private:
134         BackingStoreFlusher(IPC::Connection*, std::unique_ptr<IPC::MessageEncoder>, Vector<RetainPtr<CGContextRef>>);
135
136         RefPtr<IPC::Connection> m_connection;
137         std::unique_ptr<IPC::MessageEncoder> m_commitEncoder;
138         Vector<RetainPtr<CGContextRef>> m_contextsToFlush;
139
140         std::atomic<bool> m_hasFlushed;
141     };
142
143     std::unique_ptr<RemoteLayerTreeContext> m_remoteLayerTreeContext;
144     std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
145
146     WebCore::IntSize m_viewSize;
147
148     Optional<WebCore::FloatRect> m_viewExposedRect;
149     Optional<WebCore::FloatRect> m_scrolledViewExposedRect;
150
151     WebCore::Timer m_layerFlushTimer;
152     bool m_isFlushingSuspended;
153     bool m_hasDeferredFlush;
154     bool m_isThrottlingLayerFlushes;
155     bool m_isLayerFlushThrottlingTemporarilyDisabledForInteraction;
156     bool m_isInitialThrottledLayerFlush;
157
158     bool m_waitingForBackingStoreSwap;
159     bool m_hadFlushDeferredWhileWaitingForBackingStoreSwap;
160
161     dispatch_queue_t m_commitQueue;
162     RefPtr<BackingStoreFlusher> m_pendingBackingStoreFlusher;
163
164     HashSet<RemoteLayerTreeDisplayRefreshMonitor*> m_displayRefreshMonitors;
165     HashSet<RemoteLayerTreeDisplayRefreshMonitor*>* m_displayRefreshMonitorsToNotify;
166
167     uint64_t m_currentTransactionID;
168     Vector<RemoteLayerTreeTransaction::TransactionCallbackID> m_pendingCallbackIDs;
169
170     WebCore::LayoutMilestones m_pendingNewlyReachedLayoutMilestones;
171
172     WebCore::GraphicsLayer* m_contentLayer;
173     WebCore::GraphicsLayer* m_viewOverlayRootLayer;
174     
175     WeakPtrFactory<RemoteLayerTreeDrawingArea> m_weakPtrFactory;
176 };
177
178 } // namespace WebKit
179
180 SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(RemoteLayerTreeDrawingArea, DrawingAreaTypeRemoteLayerTree)