Add a layout mode for computing fixed layout size from a minimum size
[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 #ifndef RemoteLayerTreeDrawingArea_h
27 #define RemoteLayerTreeDrawingArea_h
28
29 #include "DrawingArea.h"
30 #include "GraphicsLayerCARemote.h"
31 #include "RemoteLayerTreeTransaction.h"
32 #include <WebCore/GraphicsLayerClient.h>
33 #include <WebCore/Timer.h>
34 #include <atomic>
35 #include <dispatch/dispatch.h>
36 #include <wtf/HashMap.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 private:
60     // DrawingArea
61     virtual void setNeedsDisplay() override;
62     virtual void setNeedsDisplayInRect(const WebCore::IntRect&) override;
63     virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) override;
64     virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition, bool flushSynchronously) override;
65
66     virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() override;
67     virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
68     virtual void scheduleCompositingLayerFlush() override;
69     virtual void scheduleCompositingLayerFlushImmediately() override;
70     virtual void attachViewOverlayGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*) override;
71
72     virtual void addTransactionCallbackID(uint64_t callbackID) override;
73
74     virtual RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) override;
75     void willDestroyDisplayRefreshMonitor(WebCore::DisplayRefreshMonitor*);
76
77     virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) override;
78
79     virtual void updatePreferences(const WebPreferencesStore&) override;
80
81     virtual bool supportsAsyncScrolling() override { return true; }
82
83     virtual void setLayerTreeStateIsFrozen(bool) override;
84
85     virtual void forceRepaint() override;
86     virtual bool forceRepaintAsync(uint64_t) override { return false; }
87
88     virtual void setExposedRect(const WebCore::FloatRect&) override;
89     virtual WebCore::FloatRect exposedRect() const override { return m_scrolledExposedRect; }
90
91     virtual void acceleratedAnimationDidStart(uint64_t layerID, const String& key, double startTime) override;
92     virtual void acceleratedAnimationDidEnd(uint64_t layerID, const String& key) override;
93
94 #if PLATFORM(IOS)
95     virtual void setExposedContentRect(const WebCore::FloatRect&) override;
96 #endif
97
98     virtual void didUpdate() override;
99
100 #if PLATFORM(IOS)
101     virtual void setDeviceScaleFactor(float) override;
102 #endif
103
104     virtual void mainFrameContentSizeChanged(const WebCore::IntSize&) override;
105
106     virtual void viewStateDidChange(WebCore::ViewState::Flags changed, bool wantsDidUpdateViewState, const Vector<uint64_t>& callbackIDs) override;
107
108     virtual bool adjustLayerFlushThrottling(WebCore::LayerFlushThrottleState::Flags) override;
109
110     void updateScrolledExposedRect();
111     void updateRootLayers();
112
113     void layerFlushTimerFired();
114     void flushLayers();
115
116     WebCore::TiledBacking* mainFrameTiledBacking() const;
117
118     uint64_t takeNextTransactionID() { return ++m_currentTransactionID; }
119
120     virtual bool markLayersVolatileImmediatelyIfPossible() override;
121
122     class BackingStoreFlusher : public ThreadSafeRefCounted<BackingStoreFlusher> {
123     public:
124         static PassRefPtr<BackingStoreFlusher> create(IPC::Connection*, std::unique_ptr<IPC::MessageEncoder>, Vector<RetainPtr<CGContextRef>>);
125
126         void flush();
127         bool hasFlushed() const { return m_hasFlushed; }
128
129     private:
130         BackingStoreFlusher(IPC::Connection*, std::unique_ptr<IPC::MessageEncoder>, Vector<RetainPtr<CGContextRef>>);
131
132         RefPtr<IPC::Connection> m_connection;
133         std::unique_ptr<IPC::MessageEncoder> m_commitEncoder;
134         Vector<RetainPtr<CGContextRef>> m_contextsToFlush;
135
136         std::atomic<bool> m_hasFlushed;
137     };
138
139     std::unique_ptr<RemoteLayerTreeContext> m_remoteLayerTreeContext;
140     std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
141
142     WebCore::IntSize m_viewSize;
143
144     WebCore::FloatRect m_exposedRect;
145     WebCore::FloatRect m_scrolledExposedRect;
146
147     WebCore::Timer m_layerFlushTimer;
148     bool m_isFlushingSuspended;
149     bool m_hasDeferredFlush;
150     bool m_isThrottlingLayerFlushes;
151     bool m_isLayerFlushThrottlingTemporarilyDisabledForInteraction;
152     bool m_isInitialThrottledLayerFlush;
153
154     bool m_waitingForBackingStoreSwap;
155     bool m_hadFlushDeferredWhileWaitingForBackingStoreSwap;
156
157     dispatch_queue_t m_commitQueue;
158     RefPtr<BackingStoreFlusher> m_pendingBackingStoreFlusher;
159
160     HashSet<RemoteLayerTreeDisplayRefreshMonitor*> m_displayRefreshMonitors;
161     HashSet<RemoteLayerTreeDisplayRefreshMonitor*>* m_displayRefreshMonitorsToNotify;
162
163     uint64_t m_currentTransactionID;
164     Vector<RemoteLayerTreeTransaction::TransactionCallbackID> m_pendingCallbackIDs;
165
166     WebCore::GraphicsLayer* m_contentLayer;
167     WebCore::GraphicsLayer* m_viewOverlayRootLayer;
168 };
169
170 } // namespace WebKit
171
172 SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(RemoteLayerTreeDrawingArea, DrawingAreaTypeRemoteLayerTree)
173
174 #endif // RemoteLayerTreeDrawingArea_h