1 | /* |
2 | * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 | * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). |
4 | * Copyright (C) 2016-2019 Igalia S.L. |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
17 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
18 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
19 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | * THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #pragma once |
29 | |
30 | #include "BackingStore.h" |
31 | #include "DrawingAreaProxy.h" |
32 | #include "LayerTreeContext.h" |
33 | #include <wtf/RunLoop.h> |
34 | |
35 | namespace WebCore { |
36 | class Region; |
37 | } |
38 | |
39 | namespace WebKit { |
40 | |
41 | class DrawingAreaProxyCoordinatedGraphics final : public DrawingAreaProxy { |
42 | public: |
43 | DrawingAreaProxyCoordinatedGraphics(WebPageProxy&, WebProcessProxy&); |
44 | virtual ~DrawingAreaProxyCoordinatedGraphics(); |
45 | |
46 | #if !PLATFORM(WPE) |
47 | void paint(BackingStore::PlatformGraphicsContext, const WebCore::IntRect&, WebCore::Region& unpaintedRegion); |
48 | #endif |
49 | |
50 | bool isInAcceleratedCompositingMode() const { return !m_layerTreeContext.isEmpty(); } |
51 | |
52 | #if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW) |
53 | void setNativeSurfaceHandleForCompositing(uint64_t); |
54 | void destroyNativeSurfaceHandleForCompositing(); |
55 | #endif |
56 | |
57 | private: |
58 | // DrawingAreaProxy |
59 | void sizeDidChange() override; |
60 | void deviceScaleFactorDidChange() override; |
61 | void waitForBackingStoreUpdateOnNextPaint() override; |
62 | void setBackingStoreIsDiscardable(bool) override; |
63 | |
64 | // IPC message handlers |
65 | void update(uint64_t backingStoreStateID, const UpdateInfo&) override; |
66 | void didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo&, const LayerTreeContext&) override; |
67 | void enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&) override; |
68 | void exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo&) override; |
69 | void updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&) override; |
70 | |
71 | #if !PLATFORM(WPE) |
72 | void incorporateUpdate(const UpdateInfo&); |
73 | #endif |
74 | |
75 | bool alwaysUseCompositing() const; |
76 | void enterAcceleratedCompositingMode(const LayerTreeContext&); |
77 | void exitAcceleratedCompositingMode(); |
78 | void updateAcceleratedCompositingMode(const LayerTreeContext&); |
79 | |
80 | enum RespondImmediatelyOrNot { DoNotRespondImmediately, RespondImmediately }; |
81 | void backingStoreStateDidChange(RespondImmediatelyOrNot); |
82 | void sendUpdateBackingStoreState(RespondImmediatelyOrNot); |
83 | void waitForAndDispatchDidUpdateBackingStoreState(); |
84 | |
85 | #if !PLATFORM(WPE) |
86 | void discardBackingStoreSoon(); |
87 | void discardBackingStore(); |
88 | #endif |
89 | |
90 | void dispatchAfterEnsuringDrawing(WTF::Function<void(CallbackBase::Error)>&&) override; |
91 | |
92 | class DrawingMonitor { |
93 | WTF_MAKE_NONCOPYABLE(DrawingMonitor); WTF_MAKE_FAST_ALLOCATED; |
94 | public: |
95 | DrawingMonitor(WebPageProxy&); |
96 | ~DrawingMonitor(); |
97 | |
98 | void start(WTF::Function<void(CallbackBase::Error)>&&); |
99 | |
100 | private: |
101 | static int webViewDrawCallback(DrawingMonitor*); |
102 | |
103 | void stop(); |
104 | void didDraw(); |
105 | |
106 | MonotonicTime m_startTime; |
107 | WTF::Function<void(CallbackBase::Error)> m_callback; |
108 | RunLoop::Timer<DrawingMonitor> m_timer; |
109 | #if PLATFORM(GTK) |
110 | WebPageProxy& m_webPage; |
111 | #endif |
112 | }; |
113 | |
114 | // The state ID corresponding to our current backing store. Updated whenever we allocate |
115 | // a new backing store. Any messages received that correspond to an earlier state are ignored, |
116 | // as they don't apply to our current backing store. |
117 | uint64_t m_currentBackingStoreStateID { 0 }; |
118 | |
119 | // The next backing store state ID we will request the web process update to. Incremented |
120 | // whenever our state changes in a way that will require a new backing store to be allocated. |
121 | uint64_t m_nextBackingStoreStateID { 0 }; |
122 | |
123 | // The current layer tree context. |
124 | LayerTreeContext m_layerTreeContext; |
125 | |
126 | // Whether we've sent a UpdateBackingStoreState message and are now waiting for a DidUpdateBackingStoreState message. |
127 | // Used to throttle UpdateBackingStoreState messages so we don't send them faster than the Web process can handle. |
128 | bool m_isWaitingForDidUpdateBackingStoreState { false }; |
129 | |
130 | // For a new Drawing Area don't draw anything until the WebProcess has sent over the first content. |
131 | bool m_hasReceivedFirstUpdate { false }; |
132 | |
133 | #if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW) |
134 | uint64_t m_pendingNativeSurfaceHandleForCompositing { 0 }; |
135 | #endif |
136 | |
137 | #if !PLATFORM(WPE) |
138 | bool m_isBackingStoreDiscardable { true }; |
139 | std::unique_ptr<BackingStore> m_backingStore; |
140 | RunLoop::Timer<DrawingAreaProxyCoordinatedGraphics> m_discardBackingStoreTimer; |
141 | #endif |
142 | std::unique_ptr<DrawingMonitor> m_drawingMonitor; |
143 | }; |
144 | |
145 | } // namespace WebKit |
146 | |