/src/mozilla-central/gfx/layers/ipc/CompositorBridgeParent.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_layers_CompositorBridgeParent_h |
8 | | #define mozilla_layers_CompositorBridgeParent_h |
9 | | |
10 | | // Enable this pref to turn on compositor performance warning. |
11 | | // This will print warnings if the compositor isn't meeting |
12 | | // its responsiveness objectives: |
13 | | // 1) Compose a frame within 15ms of receiving a ScheduleCompositeCall |
14 | | // 2) Unless a frame was composited within the throttle threshold in |
15 | | // which the deadline will be 15ms + throttle threshold |
16 | | //#define COMPOSITOR_PERFORMANCE_WARNING |
17 | | |
18 | | #include <stdint.h> // for uint64_t |
19 | | #include "Layers.h" // for Layer |
20 | | #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 |
21 | | #include "mozilla/Attributes.h" // for override |
22 | | #include "mozilla/Maybe.h" |
23 | | #include "mozilla/Monitor.h" // for Monitor |
24 | | #include "mozilla/RefPtr.h" // for RefPtr |
25 | | #include "mozilla/TimeStamp.h" // for TimeStamp |
26 | | #include "mozilla/dom/ipc/IdType.h" |
27 | | #include "mozilla/gfx/Point.h" // for IntSize |
28 | | #include "mozilla/ipc/ProtocolUtils.h" |
29 | | #include "mozilla/ipc/SharedMemory.h" |
30 | | #include "mozilla/layers/CompositorController.h" |
31 | | #include "mozilla/layers/CompositorOptions.h" |
32 | | #include "mozilla/layers/CompositorVsyncSchedulerOwner.h" |
33 | | #include "mozilla/layers/GeckoContentController.h" |
34 | | #include "mozilla/layers/ISurfaceAllocator.h" // for ShmemAllocator |
35 | | #include "mozilla/layers/LayersMessages.h" // for TargetConfig |
36 | | #include "mozilla/layers/MetricsSharingController.h" |
37 | | #include "mozilla/layers/PCompositorBridgeParent.h" |
38 | | #include "mozilla/layers/APZTestData.h" |
39 | | #include "mozilla/webrender/WebRenderTypes.h" |
40 | | #include "mozilla/widget/CompositorWidget.h" |
41 | | #include "nsISupportsImpl.h" |
42 | | #include "ThreadSafeRefcountingWithMainThreadDestruction.h" |
43 | | #include "mozilla/layers/UiCompositorControllerParent.h" |
44 | | |
45 | | class MessageLoop; |
46 | | class nsIWidget; |
47 | | |
48 | | namespace mozilla { |
49 | | |
50 | | class CancelableRunnable; |
51 | | |
52 | | namespace gfx { |
53 | | class DrawTarget; |
54 | | class GPUProcessManager; |
55 | | class GPUParent; |
56 | | } // namespace gfx |
57 | | |
58 | | namespace ipc { |
59 | | class Shmem; |
60 | | } // namespace ipc |
61 | | |
62 | | namespace layers { |
63 | | |
64 | | class APZCTreeManager; |
65 | | class APZCTreeManagerParent; |
66 | | class APZSampler; |
67 | | class APZUpdater; |
68 | | class AsyncCompositionManager; |
69 | | class AsyncImagePipelineManager; |
70 | | class Compositor; |
71 | | class CompositorAnimationStorage; |
72 | | class CompositorBridgeParent; |
73 | | class CompositorManagerParent; |
74 | | class CompositorVsyncScheduler; |
75 | | class HostLayerManager; |
76 | | class IAPZCTreeManager; |
77 | | class LayerTransactionParent; |
78 | | class PAPZParent; |
79 | | class CrossProcessCompositorBridgeParent; |
80 | | class CompositorThreadHolder; |
81 | | class InProcessCompositorSession; |
82 | | class WebRenderBridgeParent; |
83 | | |
84 | | struct ScopedLayerTreeRegistration |
85 | | { |
86 | | ScopedLayerTreeRegistration(APZCTreeManager* aApzctm, |
87 | | LayersId aLayersId, |
88 | | Layer* aRoot, |
89 | | GeckoContentController* aController); |
90 | | ~ScopedLayerTreeRegistration(); |
91 | | |
92 | | private: |
93 | | LayersId mLayersId; |
94 | | }; |
95 | | |
96 | | class CompositorBridgeParentBase : public PCompositorBridgeParent, |
97 | | public HostIPCAllocator, |
98 | | public ShmemAllocator, |
99 | | public MetricsSharingController |
100 | | { |
101 | | public: |
102 | | explicit CompositorBridgeParentBase(CompositorManagerParent* aManager); |
103 | | |
104 | | virtual void ShadowLayersUpdated(LayerTransactionParent* aLayerTree, |
105 | | const TransactionInfo& aInfo, |
106 | | bool aHitTestUpdate) = 0; |
107 | | |
108 | 0 | virtual AsyncCompositionManager* GetCompositionManager(LayerTransactionParent* aLayerTree) { return nullptr; } |
109 | | |
110 | 0 | virtual void NotifyClearCachedResources(LayerTransactionParent* aLayerTree) { } |
111 | | |
112 | 0 | virtual void ScheduleComposite(LayerTransactionParent* aLayerTree) { } |
113 | | virtual bool SetTestSampleTime(const LayersId& aId, |
114 | 0 | const TimeStamp& aTime) { return true; } |
115 | 0 | virtual void LeaveTestMode(const LayersId& aId) { } |
116 | | enum class TransformsToSkip : uint8_t { NoneOfThem = 0, APZ = 1 }; |
117 | | virtual void ApplyAsyncProperties(LayerTransactionParent* aLayerTree, |
118 | | TransformsToSkip aSkip) = 0; |
119 | | virtual void SetTestAsyncScrollOffset(const LayersId& aLayersId, |
120 | | const FrameMetrics::ViewID& aScrollId, |
121 | | const CSSPoint& aPoint) = 0; |
122 | | virtual void SetTestAsyncZoom(const LayersId& aLayersId, |
123 | | const FrameMetrics::ViewID& aScrollId, |
124 | | const LayerToParentLayerScale& aZoom) = 0; |
125 | | virtual void FlushApzRepaints(const LayersId& aLayersId) = 0; |
126 | | virtual void GetAPZTestData(const LayersId& aLayersId, |
127 | 0 | APZTestData* aOutData) { } |
128 | | virtual void SetConfirmedTargetAPZC(const LayersId& aLayersId, |
129 | | const uint64_t& aInputBlockId, |
130 | | const nsTArray<ScrollableLayerGuid>& aTargets) = 0; |
131 | 0 | virtual void UpdatePaintTime(LayerTransactionParent* aLayerTree, const TimeDuration& aPaintTime) {} |
132 | | |
133 | 0 | ShmemAllocator* AsShmemAllocator() override { return this; } |
134 | | |
135 | 0 | CompositorBridgeParentBase* AsCompositorBridgeParentBase() override { return this; } |
136 | | |
137 | 0 | mozilla::ipc::IPCResult RecvSyncWithCompositor() override { return IPC_OK(); } |
138 | | |
139 | 0 | mozilla::ipc::IPCResult Recv__delete__() override { return IPC_OK(); } |
140 | | |
141 | | virtual void ObserveLayersUpdate(LayersId aLayersId, LayersObserverEpoch aEpoch, bool aActive) = 0; |
142 | | |
143 | | virtual void DidComposite(LayersId aId, TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd) = 0; |
144 | | |
145 | | // HostIPCAllocator |
146 | | base::ProcessId GetChildProcessId() override; |
147 | | void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override; |
148 | | void SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage) override; |
149 | | |
150 | | // ShmemAllocator |
151 | | bool AllocShmem(size_t aSize, |
152 | | mozilla::ipc::SharedMemory::SharedMemoryType aType, |
153 | | mozilla::ipc::Shmem* aShmem) override; |
154 | | bool AllocUnsafeShmem(size_t aSize, |
155 | | mozilla::ipc::SharedMemory::SharedMemoryType aType, |
156 | | mozilla::ipc::Shmem* aShmem) override; |
157 | | void DeallocShmem(mozilla::ipc::Shmem& aShmem) override; |
158 | | |
159 | | // MetricsSharingController |
160 | 0 | NS_IMETHOD_(MozExternalRefCountType) AddRef() override { return HostIPCAllocator::AddRef(); } |
161 | 0 | NS_IMETHOD_(MozExternalRefCountType) Release() override { return HostIPCAllocator::Release(); } |
162 | | base::ProcessId RemotePid() override; |
163 | | bool StartSharingMetrics(mozilla::ipc::SharedMemoryBasic::Handle aHandle, |
164 | | CrossProcessMutexHandle aMutexHandle, |
165 | | LayersId aLayersId, |
166 | | uint32_t aApzcId) override; |
167 | | bool StopSharingMetrics(FrameMetrics::ViewID aScrollId, |
168 | | uint32_t aApzcId) override; |
169 | | |
170 | 0 | virtual bool IsRemote() const { |
171 | 0 | return false; |
172 | 0 | } |
173 | | |
174 | 0 | virtual void ForceComposeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr) { |
175 | 0 | MOZ_CRASH(); |
176 | 0 | } |
177 | | |
178 | 0 | virtual void NotifyMemoryPressure() {} |
179 | 0 | virtual void AccumulateMemoryReport(wr::MemoryReport*) {} |
180 | | |
181 | | protected: |
182 | | ~CompositorBridgeParentBase() override; |
183 | | |
184 | | bool mCanSend; |
185 | | |
186 | | private: |
187 | | RefPtr<CompositorManagerParent> mCompositorManager; |
188 | | }; |
189 | | |
190 | | MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CompositorBridgeParentBase::TransformsToSkip) |
191 | | |
192 | | class CompositorBridgeParent final : public CompositorBridgeParentBase |
193 | | , public CompositorController |
194 | | , public CompositorVsyncSchedulerOwner |
195 | | { |
196 | | friend class CompositorThreadHolder; |
197 | | friend class InProcessCompositorSession; |
198 | | friend class gfx::GPUProcessManager; |
199 | | friend class gfx::GPUParent; |
200 | | |
201 | | public: |
202 | 0 | NS_IMETHOD_(MozExternalRefCountType) AddRef() override { return CompositorBridgeParentBase::AddRef(); } |
203 | 0 | NS_IMETHOD_(MozExternalRefCountType) Release() override { return CompositorBridgeParentBase::Release(); } |
204 | | |
205 | | explicit CompositorBridgeParent(CompositorManagerParent* aManager, |
206 | | CSSToLayoutDeviceScale aScale, |
207 | | const TimeDuration& aVsyncRate, |
208 | | const CompositorOptions& aOptions, |
209 | | bool aUseExternalSurfaceSize, |
210 | | const gfx::IntSize& aSurfaceSize); |
211 | | |
212 | | void InitSameProcess(widget::CompositorWidget* aWidget, const LayersId& aLayerTreeId); |
213 | | |
214 | | mozilla::ipc::IPCResult RecvInitialize(const LayersId& aRootLayerTreeId) override; |
215 | | mozilla::ipc::IPCResult RecvGetFrameUniformity(FrameUniformityData* aOutData) override; |
216 | | mozilla::ipc::IPCResult RecvWillClose() override; |
217 | | mozilla::ipc::IPCResult RecvPause() override; |
218 | | mozilla::ipc::IPCResult RecvResume() override; |
219 | | mozilla::ipc::IPCResult RecvNotifyChildCreated(const LayersId& child, CompositorOptions* aOptions) override; |
220 | | mozilla::ipc::IPCResult RecvMapAndNotifyChildCreated(const LayersId& child, const base::ProcessId& pid, CompositorOptions* aOptions) override; |
221 | | mozilla::ipc::IPCResult RecvNotifyChildRecreated(const LayersId& child, CompositorOptions* aOptions) override; |
222 | | mozilla::ipc::IPCResult RecvAdoptChild(const LayersId& child) override; |
223 | | mozilla::ipc::IPCResult RecvMakeSnapshot(const SurfaceDescriptor& aInSnapshot, |
224 | | const gfx::IntRect& aRect) override; |
225 | | mozilla::ipc::IPCResult RecvFlushRendering() override; |
226 | | mozilla::ipc::IPCResult RecvFlushRenderingAsync() override; |
227 | | mozilla::ipc::IPCResult RecvWaitOnTransactionProcessed() override; |
228 | | mozilla::ipc::IPCResult RecvForcePresent() override; |
229 | | |
230 | | mozilla::ipc::IPCResult RecvNotifyRegionInvalidated(const nsIntRegion& aRegion) override; |
231 | | mozilla::ipc::IPCResult RecvStartFrameTimeRecording(const int32_t& aBufferSize, uint32_t* aOutStartIndex) override; |
232 | | mozilla::ipc::IPCResult RecvStopFrameTimeRecording(const uint32_t& aStartIndex, InfallibleTArray<float>* intervals) override; |
233 | | |
234 | 0 | mozilla::ipc::IPCResult RecvCheckContentOnlyTDR(const uint32_t& sequenceNum, bool* isContentOnlyTDR) override { return IPC_OK(); } |
235 | | |
236 | | // Unused for chrome <-> compositor communication (which this class does). |
237 | | // @see CrossProcessCompositorBridgeParent::RecvRequestNotifyAfterRemotePaint |
238 | 0 | mozilla::ipc::IPCResult RecvRequestNotifyAfterRemotePaint() override { return IPC_OK(); }; |
239 | | |
240 | | mozilla::ipc::IPCResult RecvAllPluginsCaptured() override; |
241 | | |
242 | | virtual void NotifyMemoryPressure() override; |
243 | | virtual void AccumulateMemoryReport(wr::MemoryReport*) override; |
244 | | |
245 | | void ActorDestroy(ActorDestroyReason why) override; |
246 | | |
247 | | void ShadowLayersUpdated(LayerTransactionParent* aLayerTree, |
248 | | const TransactionInfo& aInfo, |
249 | | bool aHitTestUpdate) override; |
250 | | void ScheduleComposite(LayerTransactionParent* aLayerTree) override; |
251 | | bool SetTestSampleTime(const LayersId& aId, |
252 | | const TimeStamp& aTime) override; |
253 | | void LeaveTestMode(const LayersId& aId) override; |
254 | | void ApplyAsyncProperties(LayerTransactionParent* aLayerTree, |
255 | | TransformsToSkip aSkip) override; |
256 | | CompositorAnimationStorage* GetAnimationStorage(); |
257 | | void SetTestAsyncScrollOffset(const LayersId& aLayersId, |
258 | | const FrameMetrics::ViewID& aScrollId, |
259 | | const CSSPoint& aPoint) override; |
260 | | void SetTestAsyncZoom(const LayersId& aLayersId, |
261 | | const FrameMetrics::ViewID& aScrollId, |
262 | | const LayerToParentLayerScale& aZoom) override; |
263 | | void FlushApzRepaints(const LayersId& aLayersId) override; |
264 | | void GetAPZTestData(const LayersId& aLayersId, |
265 | | APZTestData* aOutData) override; |
266 | | void SetConfirmedTargetAPZC(const LayersId& aLayersId, |
267 | | const uint64_t& aInputBlockId, |
268 | | const nsTArray<ScrollableLayerGuid>& aTargets) override; |
269 | 0 | AsyncCompositionManager* GetCompositionManager(LayerTransactionParent* aLayerTree) override { return mCompositionManager; } |
270 | | |
271 | | PTextureParent* AllocPTextureParent(const SurfaceDescriptor& aSharedData, |
272 | | const ReadLockDescriptor& aReadLock, |
273 | | const LayersBackend& aLayersBackend, |
274 | | const TextureFlags& aFlags, |
275 | | const LayersId& aId, |
276 | | const uint64_t& aSerial, |
277 | | const wr::MaybeExternalImageId& aExternalImageId) override; |
278 | | bool DeallocPTextureParent(PTextureParent* actor) override; |
279 | | |
280 | | bool IsSameProcess() const override; |
281 | | |
282 | | void NotifyWebRenderError(wr::WebRenderError aError); |
283 | | void NotifyWebRenderContextPurge(); |
284 | | void NotifyPipelineRendered(const wr::PipelineId& aPipelineId, |
285 | | const wr::Epoch& aEpoch, |
286 | | TimeStamp& aCompositeStart, |
287 | | TimeStamp& aCompositeEnd); |
288 | | RefPtr<AsyncImagePipelineManager> GetAsyncImagePipelineManager() const; |
289 | | |
290 | | PCompositorWidgetParent* AllocPCompositorWidgetParent(const CompositorWidgetInitData& aInitData) override; |
291 | | bool DeallocPCompositorWidgetParent(PCompositorWidgetParent* aActor) override; |
292 | | |
293 | 0 | void ObserveLayersUpdate(LayersId aLayersId, LayersObserverEpoch aEpoch, bool aActive) override { } |
294 | | |
295 | | /** |
296 | | * This forces the is-first-paint flag to true. This is intended to |
297 | | * be called by the widget code when it loses its viewport information |
298 | | * (or for whatever reason wants to refresh the viewport information). |
299 | | * The information refresh happens because the compositor will call |
300 | | * SetFirstPaintViewport on the next frame of composition. |
301 | | */ |
302 | | void ForceIsFirstPaint(); |
303 | | |
304 | | static void SetShadowProperties(Layer* aLayer); |
305 | | |
306 | | void NotifyChildCreated(LayersId aChild); |
307 | | |
308 | | void AsyncRender(); |
309 | | |
310 | | // Can be called from any thread |
311 | | void ScheduleRenderOnCompositorThread() override; |
312 | | void SchedulePauseOnCompositorThread(); |
313 | | void InvalidateOnCompositorThread(); |
314 | | /** |
315 | | * Returns true if a surface was obtained and the resume succeeded; false |
316 | | * otherwise. |
317 | | */ |
318 | | bool ScheduleResumeOnCompositorThread(); |
319 | | bool ScheduleResumeOnCompositorThread(int width, int height); |
320 | | |
321 | | void ScheduleComposition(); |
322 | | void NotifyShadowTreeTransaction(LayersId aId, bool aIsFirstPaint, |
323 | | const FocusTarget& aFocusTarget, |
324 | | bool aScheduleComposite, uint32_t aPaintSequenceNumber, |
325 | | bool aIsRepeatTransaction, bool aHitTestUpdate); |
326 | | |
327 | | void UpdatePaintTime(LayerTransactionParent* aLayerTree, |
328 | | const TimeDuration& aPaintTime) override; |
329 | | |
330 | | /** |
331 | | * Check rotation info and schedule a rendering task if needed. |
332 | | * Only can be called from compositor thread. |
333 | | */ |
334 | | void ScheduleRotationOnCompositorThread(const TargetConfig& aTargetConfig, bool aIsFirstPaint); |
335 | | |
336 | | /** |
337 | | * Returns the unique layer tree identifier that corresponds to the root |
338 | | * tree of this compositor. |
339 | | */ |
340 | | LayersId RootLayerTreeId(); |
341 | | |
342 | | /** |
343 | | * Notify local and remote layer trees connected to this compositor that |
344 | | * the compositor's local device is being reset. All layers must be |
345 | | * invalidated to clear any cached TextureSources. |
346 | | * |
347 | | * This must be called on the compositor thread. |
348 | | */ |
349 | | void InvalidateRemoteLayers(); |
350 | | |
351 | | /** |
352 | | * Returns a pointer to the CompositorBridgeParent corresponding to the given ID. |
353 | | */ |
354 | | static CompositorBridgeParent* GetCompositorBridgeParent(uint64_t id); |
355 | | |
356 | | /** |
357 | | * Notify the compositor for the given layer tree that vsync has occurred. |
358 | | */ |
359 | | static void NotifyVsync(const TimeStamp& aTimeStamp, const LayersId& aLayersId); |
360 | | |
361 | | /** |
362 | | * Set aController as the pan/zoom callback for the subtree referred |
363 | | * to by aLayersId. |
364 | | * |
365 | | * Must run on content main thread. |
366 | | */ |
367 | | static void SetControllerForLayerTree(LayersId aLayersId, |
368 | | GeckoContentController* aController); |
369 | | |
370 | | struct LayerTreeState { |
371 | | LayerTreeState(); |
372 | | ~LayerTreeState(); |
373 | | RefPtr<Layer> mRoot; |
374 | | RefPtr<GeckoContentController> mController; |
375 | | APZCTreeManagerParent* mApzcTreeManagerParent; |
376 | | RefPtr<CompositorBridgeParent> mParent; |
377 | | HostLayerManager* mLayerManager; |
378 | | RefPtr<WebRenderBridgeParent> mWrBridge; |
379 | | // Pointer to the CrossProcessCompositorBridgeParent. Used by APZCs to share |
380 | | // their FrameMetrics with the corresponding child process that holds |
381 | | // the PCompositorBridgeChild |
382 | | CrossProcessCompositorBridgeParent* mCrossProcessParent; |
383 | | TargetConfig mTargetConfig; |
384 | | LayerTransactionParent* mLayerTree; |
385 | | nsTArray<PluginWindowData> mPluginData; |
386 | | bool mUpdatedPluginDataAvailable; |
387 | | |
388 | | CompositorController* GetCompositorController() const; |
389 | | MetricsSharingController* CrossProcessSharingController() const; |
390 | | MetricsSharingController* InProcessSharingController() const; |
391 | | RefPtr<UiCompositorControllerParent> mUiControllerParent; |
392 | | }; |
393 | | |
394 | | /** |
395 | | * Lookup the indirect shadow tree for |aId| and return it if it |
396 | | * exists. Otherwise null is returned. This must only be called on |
397 | | * the compositor thread. |
398 | | */ |
399 | | static LayerTreeState* GetIndirectShadowTree(LayersId aId); |
400 | | |
401 | | /** |
402 | | * Lookup the indirect shadow tree for |aId|, call the function object and |
403 | | * return true if found. If not found, return false. |
404 | | */ |
405 | | static bool CallWithIndirectShadowTree( |
406 | | LayersId aId, |
407 | | const std::function<void(LayerTreeState&)>& aFunc); |
408 | | |
409 | | /** |
410 | | * Given the layers id for a content process, get the APZCTreeManagerParent |
411 | | * for the corresponding *root* layers id. That is, the APZCTreeManagerParent, |
412 | | * if one is found, will always be connected to the parent process rather |
413 | | * than a content process. Note that unless the compositor process is |
414 | | * separated this is expected to return null, because if the compositor is |
415 | | * living in the gecko parent process then there is no APZCTreeManagerParent |
416 | | * for the parent process. |
417 | | */ |
418 | | static APZCTreeManagerParent* GetApzcTreeManagerParentForRoot( |
419 | | LayersId aContentLayersId); |
420 | | /** |
421 | | * Same as the GetApzcTreeManagerParentForRoot function, but returns |
422 | | * the GeckoContentController for the parent process. |
423 | | */ |
424 | | static GeckoContentController* GetGeckoContentControllerForRoot( |
425 | | LayersId aContentLayersId); |
426 | | |
427 | | #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK) |
428 | | /** |
429 | | * Calculates and requests the main thread update plugin positioning, clip, |
430 | | * and visibility via ipc. |
431 | | */ |
432 | | bool UpdatePluginWindowState(LayersId aId); |
433 | | |
434 | | /** |
435 | | * Plugin visibility helpers for the apz (main thread) and compositor |
436 | | * thread. |
437 | | */ |
438 | | void ScheduleShowAllPluginWindows() override; |
439 | | void ScheduleHideAllPluginWindows() override; |
440 | | void ShowAllPluginWindows(); |
441 | | void HideAllPluginWindows(); |
442 | | #else |
443 | | void ScheduleShowAllPluginWindows() override {} |
444 | | void ScheduleHideAllPluginWindows() override {} |
445 | | #endif |
446 | | |
447 | | /** |
448 | | * Main thread response for a plugin visibility request made by the |
449 | | * compositor thread. |
450 | | */ |
451 | | mozilla::ipc::IPCResult RecvRemotePluginsReady() override; |
452 | | |
453 | | /** |
454 | | * Used by the profiler to denote when a vsync occured |
455 | | */ |
456 | | static void PostInsertVsyncProfilerMarker(mozilla::TimeStamp aVsyncTimestamp); |
457 | | |
458 | 0 | widget::CompositorWidget* GetWidget() { return mWidget; } |
459 | | |
460 | | virtual void ForceComposeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr) override; |
461 | | |
462 | | PAPZCTreeManagerParent* AllocPAPZCTreeManagerParent(const LayersId& aLayersId) override; |
463 | | bool DeallocPAPZCTreeManagerParent(PAPZCTreeManagerParent* aActor) override; |
464 | | |
465 | | // Helper method so that we don't have to expose mApzcTreeManager to |
466 | | // CrossProcessCompositorBridgeParent. |
467 | | void AllocateAPZCTreeManagerParent(const MonitorAutoLock& aProofOfLayerTreeStateLock, |
468 | | const LayersId& aLayersId, |
469 | | LayerTreeState& aLayerTreeStateToUpdate); |
470 | | |
471 | | PAPZParent* AllocPAPZParent(const LayersId& aLayersId) override; |
472 | | bool DeallocPAPZParent(PAPZParent* aActor) override; |
473 | | |
474 | | #if defined(MOZ_WIDGET_ANDROID) |
475 | | AndroidDynamicToolbarAnimator* GetAndroidDynamicToolbarAnimator(); |
476 | | #endif |
477 | | RefPtr<APZSampler> GetAPZSampler(); |
478 | | RefPtr<APZUpdater> GetAPZUpdater(); |
479 | | |
480 | 0 | CompositorOptions GetOptions() const { |
481 | 0 | return mOptions; |
482 | 0 | } |
483 | | |
484 | | TimeDuration GetVsyncInterval() const { |
485 | | // the variable is called "rate" but really it's an interval |
486 | | return mVsyncRate; |
487 | | } |
488 | | |
489 | | PWebRenderBridgeParent* AllocPWebRenderBridgeParent(const wr::PipelineId& aPipelineId, |
490 | | const LayoutDeviceIntSize& aSize, |
491 | | TextureFactoryIdentifier* aTextureFactoryIdentifier, |
492 | | wr::IdNamespace* aIdNamespace) override; |
493 | | bool DeallocPWebRenderBridgeParent(PWebRenderBridgeParent* aActor) override; |
494 | | RefPtr<WebRenderBridgeParent> GetWebRenderBridgeParent() const; |
495 | | Maybe<TimeStamp> GetTestingTimeStamp() const; |
496 | | |
497 | | static CompositorBridgeParent* GetCompositorBridgeParentFromLayersId(const LayersId& aLayersId); |
498 | | static RefPtr<CompositorBridgeParent> GetCompositorBridgeParentFromWindowId(const wr::WindowId& aWindowId); |
499 | | |
500 | | /** |
501 | | * This returns a reference to the IAPZCTreeManager "controller subinterface" |
502 | | * to which pan/zoom-related events can be sent. The controller subinterface |
503 | | * doesn't expose any sampler-thread APZCTreeManager methods. |
504 | | */ |
505 | | static already_AddRefed<IAPZCTreeManager> GetAPZCTreeManager(LayersId aLayersId); |
506 | | |
507 | | #if defined(MOZ_WIDGET_ANDROID) |
508 | | gfx::IntSize GetEGLSurfaceSize() { |
509 | | return mEGLSurfaceSize; |
510 | | } |
511 | | #endif // defined(MOZ_WIDGET_ANDROID) |
512 | | |
513 | | WebRenderBridgeParent* GetWrBridge() { return mWrBridge; } |
514 | | |
515 | | private: |
516 | | |
517 | | void Initialize(); |
518 | | |
519 | | /** |
520 | | * Called during destruction in order to release resources as early as possible. |
521 | | */ |
522 | | void StopAndClearResources(); |
523 | | |
524 | | /** |
525 | | * Release compositor-thread resources referred to by |aID|. |
526 | | * |
527 | | * Must run on the content main thread. |
528 | | */ |
529 | | static void DeallocateLayerTreeId(LayersId aId); |
530 | | |
531 | | protected: |
532 | | // Protected destructor, to discourage deletion outside of Release(): |
533 | | virtual ~CompositorBridgeParent(); |
534 | | |
535 | | void DeferredDestroy(); |
536 | | |
537 | | PLayerTransactionParent* AllocPLayerTransactionParent( |
538 | | const nsTArray<LayersBackend>& aBackendHints, |
539 | | const LayersId& aId) override; |
540 | | bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) override; |
541 | | virtual void ScheduleTask(already_AddRefed<CancelableRunnable>, int); |
542 | | |
543 | | void SetEGLSurfaceSize(int width, int height); |
544 | | |
545 | | void InitializeLayerManager(const nsTArray<LayersBackend>& aBackendHints); |
546 | | |
547 | | public: |
548 | | void PauseComposition(); |
549 | | void ResumeComposition(); |
550 | | void ResumeCompositionAndResize(int width, int height); |
551 | | void Invalidate(); |
552 | | |
553 | | protected: |
554 | | void ForceComposition(); |
555 | | void CancelCurrentCompositeTask(); |
556 | | |
557 | | // CompositorVsyncSchedulerOwner |
558 | | bool IsPendingComposite() override; |
559 | | void FinishPendingComposite() override; |
560 | | void CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr) override; |
561 | | |
562 | | bool InitializeAdvancedLayers(const nsTArray<LayersBackend>& aBackendHints, |
563 | | TextureFactoryIdentifier* aOutIdentifier); |
564 | | RefPtr<Compositor> NewCompositor(const nsTArray<LayersBackend>& aBackendHints); |
565 | | |
566 | | /** |
567 | | * Add a compositor to the global compositor map. |
568 | | */ |
569 | | static void AddCompositor(CompositorBridgeParent* compositor, uint64_t* id); |
570 | | /** |
571 | | * Remove a compositor from the global compositor map. |
572 | | */ |
573 | | static CompositorBridgeParent* RemoveCompositor(uint64_t id); |
574 | | |
575 | | /** |
576 | | * Creates the global compositor map. |
577 | | */ |
578 | | static void Setup(); |
579 | | |
580 | | /** |
581 | | * Remaning cleanups after the compositore thread is gone. |
582 | | */ |
583 | | static void FinishShutdown(); |
584 | | |
585 | | /** |
586 | | * Return true if current state allows compositing, that is |
587 | | * finishing a layers transaction. |
588 | | */ |
589 | | bool CanComposite(); |
590 | | |
591 | | void DidComposite(LayersId aId, TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd) override; |
592 | | void DidComposite(TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd); |
593 | | |
594 | | void NotifyDidComposite(TransactionId aTransactionId, TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd); |
595 | | |
596 | | // The indirect layer tree lock must be held before calling this function. |
597 | | // Callback should take (LayerTreeState* aState, const LayersId& aLayersId) |
598 | | template <typename Lambda> |
599 | | inline void ForEachIndirectLayerTree(const Lambda& aCallback); |
600 | | |
601 | | RefPtr<HostLayerManager> mLayerManager; |
602 | | RefPtr<Compositor> mCompositor; |
603 | | RefPtr<AsyncCompositionManager> mCompositionManager; |
604 | | RefPtr<AsyncImagePipelineManager> mAsyncImageManager; |
605 | | RefPtr<WebRenderBridgeParent> mWrBridge; |
606 | | widget::CompositorWidget* mWidget; |
607 | | Maybe<TimeStamp> mTestTime; |
608 | | CSSToLayoutDeviceScale mScale; |
609 | | TimeDuration mVsyncRate; |
610 | | |
611 | | TransactionId mPendingTransaction; |
612 | | TimeStamp mRefreshStartTime; |
613 | | TimeStamp mTxnStartTime; |
614 | | TimeStamp mFwdTime; |
615 | | |
616 | | bool mPaused; |
617 | | |
618 | | bool mUseExternalSurfaceSize; |
619 | | gfx::IntSize mEGLSurfaceSize; |
620 | | |
621 | | CompositorOptions mOptions; |
622 | | |
623 | | mozilla::Monitor mPauseCompositionMonitor; |
624 | | mozilla::Monitor mResumeCompositionMonitor; |
625 | | |
626 | | uint64_t mCompositorBridgeID; |
627 | | LayersId mRootLayerTreeID; |
628 | | |
629 | | bool mOverrideComposeReadiness; |
630 | | RefPtr<CancelableRunnable> mForceCompositionTask; |
631 | | |
632 | | RefPtr<APZCTreeManager> mApzcTreeManager; |
633 | | RefPtr<APZSampler> mApzSampler; |
634 | | RefPtr<APZUpdater> mApzUpdater; |
635 | | |
636 | | RefPtr<CompositorVsyncScheduler> mCompositorScheduler; |
637 | | // This makes sure the compositorParent is not destroyed before receiving |
638 | | // confirmation that the channel is closed. |
639 | | // mSelfRef is cleared in DeferredDestroy which is scheduled by ActorDestroy. |
640 | | RefPtr<CompositorBridgeParent> mSelfRef; |
641 | | RefPtr<CompositorAnimationStorage> mAnimationStorage; |
642 | | |
643 | | TimeDuration mPaintTime; |
644 | | |
645 | | #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK) |
646 | | // cached plugin data used to reduce the number of updates we request. |
647 | | LayersId mLastPluginUpdateLayerTreeId; |
648 | | nsIntPoint mPluginsLayerOffset; |
649 | | nsIntRegion mPluginsLayerVisibleRegion; |
650 | | nsTArray<PluginWindowData> mCachedPluginData; |
651 | | // Time until which we will block composition to wait for plugin updates. |
652 | | TimeStamp mWaitForPluginsUntil; |
653 | | // Indicates that we have actually blocked a composition waiting for plugins. |
654 | | bool mHaveBlockedForPlugins = false; |
655 | | // indicates if plugin window visibility and metric updates are currently |
656 | | // being defered due to a scroll operation. |
657 | | bool mDeferPluginWindows; |
658 | | // indicates if the plugin windows were hidden, and need to be made |
659 | | // visible again even if their geometry has not changed. |
660 | | bool mPluginWindowsHidden; |
661 | | #endif |
662 | | |
663 | | DISALLOW_EVIL_CONSTRUCTORS(CompositorBridgeParent); |
664 | | }; |
665 | | |
666 | | } // namespace layers |
667 | | } // namespace mozilla |
668 | | |
669 | | #endif // mozilla_layers_CompositorBridgeParent_h |