Line data Source code
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 0 : 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 0 : 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 ObserveLayerUpdate(LayersId aLayersId, uint64_t 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 12 : NS_IMETHOD_(MozExternalRefCountType) AddRef() override { return HostIPCAllocator::AddRef(); }
161 5 : 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 : }
173 :
174 : protected:
175 : ~CompositorBridgeParentBase() override;
176 :
177 : bool mCanSend;
178 :
179 : private:
180 : RefPtr<CompositorManagerParent> mCompositorManager;
181 : };
182 :
183 14 : MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CompositorBridgeParentBase::TransformsToSkip)
184 :
185 : class CompositorBridgeParent final : public CompositorBridgeParentBase
186 : , public CompositorController
187 : , public CompositorVsyncSchedulerOwner
188 : {
189 : friend class CompositorThreadHolder;
190 : friend class InProcessCompositorSession;
191 : friend class gfx::GPUProcessManager;
192 : friend class gfx::GPUParent;
193 :
194 : public:
195 22 : NS_IMETHOD_(MozExternalRefCountType) AddRef() override { return CompositorBridgeParentBase::AddRef(); }
196 10 : NS_IMETHOD_(MozExternalRefCountType) Release() override { return CompositorBridgeParentBase::Release(); }
197 :
198 : explicit CompositorBridgeParent(CompositorManagerParent* aManager,
199 : CSSToLayoutDeviceScale aScale,
200 : const TimeDuration& aVsyncRate,
201 : const CompositorOptions& aOptions,
202 : bool aUseExternalSurfaceSize,
203 : const gfx::IntSize& aSurfaceSize);
204 :
205 : void InitSameProcess(widget::CompositorWidget* aWidget, const LayersId& aLayerTreeId);
206 :
207 : mozilla::ipc::IPCResult RecvInitialize(const LayersId& aRootLayerTreeId) override;
208 : mozilla::ipc::IPCResult RecvGetFrameUniformity(FrameUniformityData* aOutData) override;
209 : mozilla::ipc::IPCResult RecvWillClose() override;
210 : mozilla::ipc::IPCResult RecvPause() override;
211 : mozilla::ipc::IPCResult RecvResume() override;
212 : mozilla::ipc::IPCResult RecvNotifyChildCreated(const LayersId& child, CompositorOptions* aOptions) override;
213 : mozilla::ipc::IPCResult RecvMapAndNotifyChildCreated(const LayersId& child, const base::ProcessId& pid, CompositorOptions* aOptions) override;
214 : mozilla::ipc::IPCResult RecvNotifyChildRecreated(const LayersId& child, CompositorOptions* aOptions) override;
215 : mozilla::ipc::IPCResult RecvAdoptChild(const LayersId& child) override;
216 : mozilla::ipc::IPCResult RecvMakeSnapshot(const SurfaceDescriptor& aInSnapshot,
217 : const gfx::IntRect& aRect) override;
218 : mozilla::ipc::IPCResult RecvFlushRendering() override;
219 : mozilla::ipc::IPCResult RecvFlushRenderingAsync() override;
220 : mozilla::ipc::IPCResult RecvWaitOnTransactionProcessed() override;
221 : mozilla::ipc::IPCResult RecvForcePresent() override;
222 :
223 : mozilla::ipc::IPCResult RecvNotifyRegionInvalidated(const nsIntRegion& aRegion) override;
224 : mozilla::ipc::IPCResult RecvStartFrameTimeRecording(const int32_t& aBufferSize, uint32_t* aOutStartIndex) override;
225 : mozilla::ipc::IPCResult RecvStopFrameTimeRecording(const uint32_t& aStartIndex, InfallibleTArray<float>* intervals) override;
226 :
227 0 : mozilla::ipc::IPCResult RecvCheckContentOnlyTDR(const uint32_t& sequenceNum, bool* isContentOnlyTDR) override { return IPC_OK(); }
228 :
229 : // Unused for chrome <-> compositor communication (which this class does).
230 : // @see CrossProcessCompositorBridgeParent::RecvRequestNotifyAfterRemotePaint
231 0 : mozilla::ipc::IPCResult RecvRequestNotifyAfterRemotePaint() override { return IPC_OK(); };
232 :
233 : mozilla::ipc::IPCResult RecvAllPluginsCaptured() override;
234 :
235 : void ActorDestroy(ActorDestroyReason why) override;
236 :
237 : void ShadowLayersUpdated(LayerTransactionParent* aLayerTree,
238 : const TransactionInfo& aInfo,
239 : bool aHitTestUpdate) override;
240 : void ScheduleComposite(LayerTransactionParent* aLayerTree) override;
241 : bool SetTestSampleTime(const LayersId& aId,
242 : const TimeStamp& aTime) override;
243 : void LeaveTestMode(const LayersId& aId) override;
244 : void ApplyAsyncProperties(LayerTransactionParent* aLayerTree,
245 : TransformsToSkip aSkip) override;
246 : CompositorAnimationStorage* GetAnimationStorage();
247 : void SetTestAsyncScrollOffset(const LayersId& aLayersId,
248 : const FrameMetrics::ViewID& aScrollId,
249 : const CSSPoint& aPoint) override;
250 : void SetTestAsyncZoom(const LayersId& aLayersId,
251 : const FrameMetrics::ViewID& aScrollId,
252 : const LayerToParentLayerScale& aZoom) override;
253 : void FlushApzRepaints(const LayersId& aLayersId) override;
254 : void GetAPZTestData(const LayersId& aLayersId,
255 : APZTestData* aOutData) override;
256 : void SetConfirmedTargetAPZC(const LayersId& aLayersId,
257 : const uint64_t& aInputBlockId,
258 : const nsTArray<ScrollableLayerGuid>& aTargets) override;
259 40 : AsyncCompositionManager* GetCompositionManager(LayerTransactionParent* aLayerTree) override { return mCompositionManager; }
260 :
261 : PTextureParent* AllocPTextureParent(const SurfaceDescriptor& aSharedData,
262 : const ReadLockDescriptor& aReadLock,
263 : const LayersBackend& aLayersBackend,
264 : const TextureFlags& aFlags,
265 : const LayersId& aId,
266 : const uint64_t& aSerial,
267 : const wr::MaybeExternalImageId& aExternalImageId) override;
268 : bool DeallocPTextureParent(PTextureParent* actor) override;
269 :
270 : bool IsSameProcess() const override;
271 :
272 : void NotifyWebRenderError(wr::WebRenderError aError);
273 : void NotifyPipelineRendered(const wr::PipelineId& aPipelineId,
274 : const wr::Epoch& aEpoch,
275 : TimeStamp& aCompositeStart,
276 : TimeStamp& aCompositeEnd);
277 : RefPtr<AsyncImagePipelineManager> GetAsyncImagePipelineManager() const;
278 :
279 : PCompositorWidgetParent* AllocPCompositorWidgetParent(const CompositorWidgetInitData& aInitData) override;
280 : bool DeallocPCompositorWidgetParent(PCompositorWidgetParent* aActor) override;
281 :
282 : void ObserveLayerUpdate(LayersId aLayersId, uint64_t aEpoch, bool aActive) override { }
283 :
284 : /**
285 : * This forces the is-first-paint flag to true. This is intended to
286 : * be called by the widget code when it loses its viewport information
287 : * (or for whatever reason wants to refresh the viewport information).
288 : * The information refresh happens because the compositor will call
289 : * SetFirstPaintViewport on the next frame of composition.
290 : */
291 : mozilla::ipc::IPCResult RecvForceIsFirstPaint() override;
292 :
293 : static void SetShadowProperties(Layer* aLayer);
294 :
295 : void NotifyChildCreated(LayersId aChild);
296 :
297 : void AsyncRender();
298 :
299 : // Can be called from any thread
300 : void ScheduleRenderOnCompositorThread() override;
301 : void SchedulePauseOnCompositorThread();
302 : void InvalidateOnCompositorThread();
303 : /**
304 : * Returns true if a surface was obtained and the resume succeeded; false
305 : * otherwise.
306 : */
307 : bool ScheduleResumeOnCompositorThread();
308 : bool ScheduleResumeOnCompositorThread(int width, int height);
309 :
310 : void ScheduleComposition();
311 : void NotifyShadowTreeTransaction(LayersId aId, bool aIsFirstPaint,
312 : const FocusTarget& aFocusTarget,
313 : bool aScheduleComposite, uint32_t aPaintSequenceNumber,
314 : bool aIsRepeatTransaction, bool aHitTestUpdate);
315 :
316 : void UpdatePaintTime(LayerTransactionParent* aLayerTree,
317 : const TimeDuration& aPaintTime) override;
318 :
319 : /**
320 : * Check rotation info and schedule a rendering task if needed.
321 : * Only can be called from compositor thread.
322 : */
323 : void ScheduleRotationOnCompositorThread(const TargetConfig& aTargetConfig, bool aIsFirstPaint);
324 :
325 : /**
326 : * Returns the unique layer tree identifier that corresponds to the root
327 : * tree of this compositor.
328 : */
329 : LayersId RootLayerTreeId();
330 :
331 : /**
332 : * Notify local and remote layer trees connected to this compositor that
333 : * the compositor's local device is being reset. All layers must be
334 : * invalidated to clear any cached TextureSources.
335 : *
336 : * This must be called on the compositor thread.
337 : */
338 : void InvalidateRemoteLayers();
339 :
340 : /**
341 : * Returns a pointer to the CompositorBridgeParent corresponding to the given ID.
342 : */
343 : static CompositorBridgeParent* GetCompositorBridgeParent(uint64_t id);
344 :
345 : /**
346 : * Notify the compositor for the given layer tree that vsync has occurred.
347 : */
348 : static void NotifyVsync(const TimeStamp& aTimeStamp, const LayersId& aLayersId);
349 :
350 : /**
351 : * Set aController as the pan/zoom callback for the subtree referred
352 : * to by aLayersId.
353 : *
354 : * Must run on content main thread.
355 : */
356 : static void SetControllerForLayerTree(LayersId aLayersId,
357 : GeckoContentController* aController);
358 :
359 : struct LayerTreeState {
360 : LayerTreeState();
361 : ~LayerTreeState();
362 : RefPtr<Layer> mRoot;
363 : RefPtr<GeckoContentController> mController;
364 : APZCTreeManagerParent* mApzcTreeManagerParent;
365 : RefPtr<CompositorBridgeParent> mParent;
366 : HostLayerManager* mLayerManager;
367 : RefPtr<WebRenderBridgeParent> mWrBridge;
368 : // Pointer to the CrossProcessCompositorBridgeParent. Used by APZCs to share
369 : // their FrameMetrics with the corresponding child process that holds
370 : // the PCompositorBridgeChild
371 : CrossProcessCompositorBridgeParent* mCrossProcessParent;
372 : TargetConfig mTargetConfig;
373 : LayerTransactionParent* mLayerTree;
374 : nsTArray<PluginWindowData> mPluginData;
375 : bool mUpdatedPluginDataAvailable;
376 :
377 : CompositorController* GetCompositorController() const;
378 : MetricsSharingController* CrossProcessSharingController() const;
379 : MetricsSharingController* InProcessSharingController() const;
380 : RefPtr<UiCompositorControllerParent> mUiControllerParent;
381 : };
382 :
383 : /**
384 : * Lookup the indirect shadow tree for |aId| and return it if it
385 : * exists. Otherwise null is returned. This must only be called on
386 : * the compositor thread.
387 : */
388 : static LayerTreeState* GetIndirectShadowTree(LayersId aId);
389 :
390 : /**
391 : * Lookup the indirect shadow tree for |aId|, call the function object and
392 : * return true if found. If not found, return false.
393 : */
394 : static bool CallWithIndirectShadowTree(
395 : LayersId aId,
396 : const std::function<void(LayerTreeState&)>& aFunc);
397 :
398 : /**
399 : * Given the layers id for a content process, get the APZCTreeManagerParent
400 : * for the corresponding *root* layers id. That is, the APZCTreeManagerParent,
401 : * if one is found, will always be connected to the parent process rather
402 : * than a content process. Note that unless the compositor process is
403 : * separated this is expected to return null, because if the compositor is
404 : * living in the gecko parent process then there is no APZCTreeManagerParent
405 : * for the parent process.
406 : */
407 : static APZCTreeManagerParent* GetApzcTreeManagerParentForRoot(
408 : LayersId aContentLayersId);
409 : /**
410 : * Same as the GetApzcTreeManagerParentForRoot function, but returns
411 : * the GeckoContentController for the parent process.
412 : */
413 : static GeckoContentController* GetGeckoContentControllerForRoot(
414 : LayersId aContentLayersId);
415 :
416 : #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
417 : /**
418 : * Calculates and requests the main thread update plugin positioning, clip,
419 : * and visibility via ipc.
420 : */
421 : bool UpdatePluginWindowState(LayersId aId);
422 :
423 : /**
424 : * Plugin visibility helpers for the apz (main thread) and compositor
425 : * thread.
426 : */
427 : void ScheduleShowAllPluginWindows() override;
428 : void ScheduleHideAllPluginWindows() override;
429 : void ShowAllPluginWindows();
430 : void HideAllPluginWindows();
431 : #else
432 : void ScheduleShowAllPluginWindows() override {}
433 : void ScheduleHideAllPluginWindows() override {}
434 : #endif
435 :
436 : /**
437 : * Main thread response for a plugin visibility request made by the
438 : * compositor thread.
439 : */
440 : mozilla::ipc::IPCResult RecvRemotePluginsReady() override;
441 :
442 : /**
443 : * Used by the profiler to denote when a vsync occured
444 : */
445 : static void PostInsertVsyncProfilerMarker(mozilla::TimeStamp aVsyncTimestamp);
446 :
447 : widget::CompositorWidget* GetWidget() { return mWidget; }
448 :
449 : void ForceComposeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr);
450 :
451 : PAPZCTreeManagerParent* AllocPAPZCTreeManagerParent(const LayersId& aLayersId) override;
452 : bool DeallocPAPZCTreeManagerParent(PAPZCTreeManagerParent* aActor) override;
453 :
454 : // Helper method so that we don't have to expose mApzcTreeManager to
455 : // CrossProcessCompositorBridgeParent.
456 : void AllocateAPZCTreeManagerParent(const MonitorAutoLock& aProofOfLayerTreeStateLock,
457 : const LayersId& aLayersId,
458 : LayerTreeState& aLayerTreeStateToUpdate);
459 :
460 : PAPZParent* AllocPAPZParent(const LayersId& aLayersId) override;
461 : bool DeallocPAPZParent(PAPZParent* aActor) override;
462 :
463 : #if defined(MOZ_WIDGET_ANDROID)
464 : AndroidDynamicToolbarAnimator* GetAndroidDynamicToolbarAnimator();
465 : #endif
466 : RefPtr<APZSampler> GetAPZSampler();
467 : RefPtr<APZUpdater> GetAPZUpdater();
468 :
469 : CompositorOptions GetOptions() const {
470 : return mOptions;
471 : }
472 :
473 : TimeDuration GetVsyncInterval() const {
474 : // the variable is called "rate" but really it's an interval
475 : return mVsyncRate;
476 : }
477 :
478 : PWebRenderBridgeParent* AllocPWebRenderBridgeParent(const wr::PipelineId& aPipelineId,
479 : const LayoutDeviceIntSize& aSize,
480 : TextureFactoryIdentifier* aTextureFactoryIdentifier,
481 : wr::IdNamespace* aIdNamespace) override;
482 : bool DeallocPWebRenderBridgeParent(PWebRenderBridgeParent* aActor) override;
483 : RefPtr<WebRenderBridgeParent> GetWebRenderBridgeParent() const;
484 : Maybe<TimeStamp> GetTestingTimeStamp() const;
485 :
486 : static CompositorBridgeParent* GetCompositorBridgeParentFromLayersId(const LayersId& aLayersId);
487 : static RefPtr<CompositorBridgeParent> GetCompositorBridgeParentFromWindowId(const wr::WindowId& aWindowId);
488 :
489 : /**
490 : * This returns a reference to the IAPZCTreeManager "controller subinterface"
491 : * to which pan/zoom-related events can be sent. The controller subinterface
492 : * doesn't expose any sampler-thread APZCTreeManager methods.
493 : */
494 : static already_AddRefed<IAPZCTreeManager> GetAPZCTreeManager(LayersId aLayersId);
495 :
496 : #if defined(MOZ_WIDGET_ANDROID)
497 : gfx::IntSize GetEGLSurfaceSize() {
498 : return mEGLSurfaceSize;
499 : }
500 : #endif // defined(MOZ_WIDGET_ANDROID)
501 :
502 : private:
503 :
504 : void Initialize();
505 :
506 : /**
507 : * Called during destruction in order to release resources as early as possible.
508 : */
509 : void StopAndClearResources();
510 :
511 : /**
512 : * Release compositor-thread resources referred to by |aID|.
513 : *
514 : * Must run on the content main thread.
515 : */
516 : static void DeallocateLayerTreeId(LayersId aId);
517 :
518 : protected:
519 : // Protected destructor, to discourage deletion outside of Release():
520 : virtual ~CompositorBridgeParent();
521 :
522 : void DeferredDestroy();
523 :
524 : PLayerTransactionParent* AllocPLayerTransactionParent(
525 : const nsTArray<LayersBackend>& aBackendHints,
526 : const LayersId& aId) override;
527 : bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) override;
528 : virtual void ScheduleTask(already_AddRefed<CancelableRunnable>, int);
529 :
530 : void SetEGLSurfaceSize(int width, int height);
531 :
532 : void InitializeLayerManager(const nsTArray<LayersBackend>& aBackendHints);
533 :
534 : public:
535 : void PauseComposition();
536 : void ResumeComposition();
537 : void ResumeCompositionAndResize(int width, int height);
538 : void Invalidate();
539 :
540 : protected:
541 : void ForceComposition();
542 : void CancelCurrentCompositeTask();
543 :
544 : // CompositorVsyncSchedulerOwner
545 : bool IsPendingComposite() override;
546 : void FinishPendingComposite() override;
547 : void CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr) override;
548 :
549 : bool InitializeAdvancedLayers(const nsTArray<LayersBackend>& aBackendHints,
550 : TextureFactoryIdentifier* aOutIdentifier);
551 : RefPtr<Compositor> NewCompositor(const nsTArray<LayersBackend>& aBackendHints);
552 :
553 : /**
554 : * Add a compositor to the global compositor map.
555 : */
556 : static void AddCompositor(CompositorBridgeParent* compositor, uint64_t* id);
557 : /**
558 : * Remove a compositor from the global compositor map.
559 : */
560 : static CompositorBridgeParent* RemoveCompositor(uint64_t id);
561 :
562 : /**
563 : * Creates the global compositor map.
564 : */
565 : static void Setup();
566 :
567 : /**
568 : * Destroys the compositor thread and global compositor map.
569 : */
570 : static void Shutdown();
571 :
572 : /**
573 : * Finish the shutdown operation on the compositor thread.
574 : */
575 : static void FinishShutdown();
576 :
577 : /**
578 : * Return true if current state allows compositing, that is
579 : * finishing a layers transaction.
580 : */
581 : bool CanComposite();
582 :
583 : void DidComposite(LayersId aId, TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd) override;
584 : void DidComposite(TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd);
585 :
586 : void NotifyDidComposite(TransactionId aTransactionId, TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd);
587 :
588 : // The indirect layer tree lock must be held before calling this function.
589 : // Callback should take (LayerTreeState* aState, const LayersId& aLayersId)
590 : template <typename Lambda>
591 : inline void ForEachIndirectLayerTree(const Lambda& aCallback);
592 :
593 : RefPtr<HostLayerManager> mLayerManager;
594 : RefPtr<Compositor> mCompositor;
595 : RefPtr<AsyncCompositionManager> mCompositionManager;
596 : RefPtr<AsyncImagePipelineManager> mAsyncImageManager;
597 : RefPtr<WebRenderBridgeParent> mWrBridge;
598 : widget::CompositorWidget* mWidget;
599 : Maybe<TimeStamp> mTestTime;
600 : CSSToLayoutDeviceScale mScale;
601 : TimeDuration mVsyncRate;
602 :
603 : TransactionId mPendingTransaction;
604 : TimeStamp mTxnStartTime;
605 : TimeStamp mFwdTime;
606 :
607 : bool mPaused;
608 :
609 : bool mUseExternalSurfaceSize;
610 : gfx::IntSize mEGLSurfaceSize;
611 :
612 : CompositorOptions mOptions;
613 :
614 : mozilla::Monitor mPauseCompositionMonitor;
615 : mozilla::Monitor mResumeCompositionMonitor;
616 :
617 : uint64_t mCompositorBridgeID;
618 : LayersId mRootLayerTreeID;
619 :
620 : bool mOverrideComposeReadiness;
621 : RefPtr<CancelableRunnable> mForceCompositionTask;
622 :
623 : RefPtr<APZCTreeManager> mApzcTreeManager;
624 : RefPtr<APZSampler> mApzSampler;
625 : RefPtr<APZUpdater> mApzUpdater;
626 :
627 : RefPtr<CompositorVsyncScheduler> mCompositorScheduler;
628 : // This makes sure the compositorParent is not destroyed before receiving
629 : // confirmation that the channel is closed.
630 : // mSelfRef is cleared in DeferredDestroy which is scheduled by ActorDestroy.
631 : RefPtr<CompositorBridgeParent> mSelfRef;
632 : RefPtr<CompositorAnimationStorage> mAnimationStorage;
633 :
634 : TimeDuration mPaintTime;
635 :
636 : #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
637 : // cached plugin data used to reduce the number of updates we request.
638 : LayersId mLastPluginUpdateLayerTreeId;
639 : nsIntPoint mPluginsLayerOffset;
640 : nsIntRegion mPluginsLayerVisibleRegion;
641 : nsTArray<PluginWindowData> mCachedPluginData;
642 : // Time until which we will block composition to wait for plugin updates.
643 : TimeStamp mWaitForPluginsUntil;
644 : // Indicates that we have actually blocked a composition waiting for plugins.
645 : bool mHaveBlockedForPlugins = false;
646 : // indicates if plugin window visibility and metric updates are currently
647 : // being defered due to a scroll operation.
648 : bool mDeferPluginWindows;
649 : // indicates if the plugin windows were hidden, and need to be made
650 : // visible again even if their geometry has not changed.
651 : bool mPluginWindowsHidden;
652 : #endif
653 :
654 : DISALLOW_EVIL_CONSTRUCTORS(CompositorBridgeParent);
655 : };
656 :
657 : } // namespace layers
658 : } // namespace mozilla
659 :
660 : #endif // mozilla_layers_CompositorBridgeParent_h
|