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