CompositorBridgeParent.h (25674B)
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 #include <stdint.h> // for uint64_t 11 #include <unordered_map> 12 #include "mozilla/Maybe.h" 13 #include "mozilla/Monitor.h" // for Monitor 14 #include "mozilla/RefPtr.h" // for RefPtr 15 #include "mozilla/StaticMonitor.h" // for StaticMonitor 16 #include "mozilla/TimeStamp.h" // for TimeStamp 17 #include "mozilla/gfx/Point.h" // for IntSize 18 #include "mozilla/ipc/ProtocolUtils.h" 19 #include "mozilla/layers/CompositorController.h" 20 #include "mozilla/layers/CompositorVsyncSchedulerOwner.h" 21 #include "mozilla/layers/FocusTarget.h" 22 #include "mozilla/layers/ISurfaceAllocator.h" // for IShmemAllocator 23 #include "mozilla/layers/LayersTypes.h" 24 #include "mozilla/layers/PCompositorBridgeParent.h" 25 #include "mozilla/layers/PWebRenderBridgeParent.h" 26 #include "mozilla/layers/APZInputBridgeParent.h" 27 #include "mozilla/webrender/WebRenderTypes.h" 28 29 namespace mozilla { 30 31 namespace gfx { 32 class GPUProcessManager; 33 class GPUParent; 34 } // namespace gfx 35 36 namespace ipc { 37 class Shmem; 38 } // namespace ipc 39 40 namespace widget { 41 class CompositorWidget; 42 } 43 44 namespace wr { 45 class WebRenderPipelineInfo; 46 struct Epoch; 47 struct MemoryReport; 48 struct PipelineId; 49 struct RendererStats; 50 } // namespace wr 51 52 namespace layers { 53 54 class APZCTreeManager; 55 class APZCTreeManagerParent; 56 class APZSampler; 57 class APZTestData; 58 class APZUpdater; 59 class AsyncImagePipelineManager; 60 class CompositorAnimationStorage; 61 class CompositorBridgeParent; 62 class CompositorManagerParent; 63 class CompositorVsyncScheduler; 64 class FrameUniformityData; 65 class GeckoContentController; 66 class IAPZCTreeManager; 67 class OMTASampler; 68 class ContentCompositorBridgeParent; 69 class CompositorThreadHolder; 70 class InProcessCompositorSession; 71 class UiCompositorControllerParent; 72 class WebRenderBridgeParent; 73 class WebRenderScrollDataWrapper; 74 struct CollectedFrames; 75 76 struct ScopedLayerTreeRegistration { 77 // For WebRender 78 ScopedLayerTreeRegistration(LayersId aLayersId, 79 GeckoContentController* aController); 80 ~ScopedLayerTreeRegistration(); 81 82 private: 83 LayersId mLayersId; 84 }; 85 86 class CompositorBridgeParentBase : public PCompositorBridgeParent, 87 public HostIPCAllocator, 88 public mozilla::ipc::IShmemAllocator { 89 friend class PCompositorBridgeParent; 90 91 public: 92 explicit CompositorBridgeParentBase(CompositorManagerParent* aManager); 93 94 virtual bool SetTestSampleTime(const LayersId& aId, const TimeStamp& aTime) { 95 return true; 96 } 97 virtual void LeaveTestMode(const LayersId& aId) {} 98 enum class TransformsToSkip : uint8_t { NoneOfThem = 0, APZ = 1 }; 99 virtual void SetTestAsyncScrollOffset( 100 const LayersId& aLayersId, const ScrollableLayerGuid::ViewID& aScrollId, 101 const CSSPoint& aPoint) = 0; 102 virtual void SetTestAsyncZoom(const LayersId& aLayersId, 103 const ScrollableLayerGuid::ViewID& aScrollId, 104 const LayerToParentLayerScale& aZoom) = 0; 105 virtual void FlushApzRepaints(const LayersId& aLayersId) = 0; 106 virtual void GetAPZTestData(const LayersId& aLayersId, 107 APZTestData* aOutData) {} 108 virtual void GetFrameUniformity(const LayersId& aLayersId, 109 FrameUniformityData* data) = 0; 110 virtual void SetConfirmedTargetAPZC( 111 const LayersId& aLayersId, const uint64_t& aInputBlockId, 112 nsTArray<ScrollableLayerGuid>&& aTargets) = 0; 113 virtual void EndWheelTransaction( 114 const LayersId& aLayersId, 115 PWebRenderBridgeParent::EndWheelTransactionResolver&& aResolve) = 0; 116 117 IShmemAllocator* AsShmemAllocator() override { return this; } 118 119 CompositorBridgeParentBase* AsCompositorBridgeParentBase() override { 120 return this; 121 } 122 123 mozilla::ipc::IPCResult RecvSyncWithCompositor() { return IPC_OK(); } 124 125 mozilla::ipc::IPCResult Recv__delete__() override { return IPC_OK(); } 126 127 virtual void ObserveLayersUpdate(LayersId aLayersId, bool aActive) = 0; 128 129 // HostIPCAllocator 130 base::ProcessId GetChildProcessId() override; 131 dom::ContentParentId GetContentId() override; 132 void NotifyNotUsed(PTextureParent* aTexture, 133 uint64_t aTransactionId) override; 134 void SendAsyncMessage( 135 const nsTArray<AsyncParentMessageData>& aMessage) override; 136 137 // IShmemAllocator 138 bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override; 139 bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override; 140 bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override; 141 142 NS_IMETHOD_(MozExternalRefCountType) AddRef() override { 143 return HostIPCAllocator::AddRef(); 144 } 145 NS_IMETHOD_(MozExternalRefCountType) Release() override { 146 return HostIPCAllocator::Release(); 147 } 148 virtual bool IsRemote() const { return false; } 149 150 virtual void NotifyMemoryPressure() {} 151 virtual void AccumulateMemoryReport(wr::MemoryReport*) {} 152 153 protected: 154 virtual ~CompositorBridgeParentBase(); 155 156 virtual PAPZParent* AllocPAPZParent(const LayersId& layersId) = 0; 157 virtual bool DeallocPAPZParent(PAPZParent* aActor) = 0; 158 159 virtual PAPZCTreeManagerParent* AllocPAPZCTreeManagerParent( 160 const LayersId& layersId) = 0; 161 virtual bool DeallocPAPZCTreeManagerParent( 162 PAPZCTreeManagerParent* aActor) = 0; 163 164 virtual PTextureParent* AllocPTextureParent( 165 const SurfaceDescriptor& aSharedData, ReadLockDescriptor& aReadLock, 166 const LayersBackend& aBackend, const TextureFlags& aTextureFlags, 167 const LayersId& id, const uint64_t& aSerial, 168 const MaybeExternalImageId& aExternalImageId) = 0; 169 virtual bool DeallocPTextureParent(PTextureParent* aActor) = 0; 170 171 virtual PWebRenderBridgeParent* AllocPWebRenderBridgeParent( 172 const PipelineId& pipelineId, const LayoutDeviceIntSize& aSize, 173 const WindowKind& aWindowKind) = 0; 174 virtual bool DeallocPWebRenderBridgeParent( 175 PWebRenderBridgeParent* aActor) = 0; 176 177 virtual already_AddRefed<PCompositorWidgetParent> 178 AllocPCompositorWidgetParent(const CompositorWidgetInitData& aInitData) = 0; 179 180 virtual mozilla::ipc::IPCResult RecvAdoptChild(const LayersId& id) = 0; 181 virtual mozilla::ipc::IPCResult RecvFlushRenderingAsync( 182 const wr::RenderReasons& aReasons) = 0; 183 virtual mozilla::ipc::IPCResult RecvForcePresent( 184 const wr::RenderReasons& aReasons) = 0; 185 virtual mozilla::ipc::IPCResult RecvBeginRecording( 186 const TimeStamp& aRecordingStart, BeginRecordingResolver&& aResolve) = 0; 187 virtual mozilla::ipc::IPCResult RecvEndRecording( 188 EndRecordingResolver&& aResolve) = 0; 189 virtual mozilla::ipc::IPCResult RecvInitialize( 190 const LayersId& rootLayerTreeId) = 0; 191 virtual mozilla::ipc::IPCResult RecvWillClose() = 0; 192 virtual mozilla::ipc::IPCResult RecvPause() = 0; 193 virtual mozilla::ipc::IPCResult RecvRequestFxrOutput() = 0; 194 virtual mozilla::ipc::IPCResult RecvResume() = 0; 195 virtual mozilla::ipc::IPCResult RecvResumeAsync() = 0; 196 virtual mozilla::ipc::IPCResult RecvNotifyChildCreated( 197 const LayersId& id, CompositorOptions* compositorOptions) = 0; 198 virtual mozilla::ipc::IPCResult RecvMapAndNotifyChildCreated( 199 const LayersId& id, const ProcessId& owner, 200 CompositorOptions* compositorOptions) = 0; 201 virtual mozilla::ipc::IPCResult RecvNotifyChildRecreated( 202 const LayersId& id, CompositorOptions* compositorOptions) = 0; 203 virtual mozilla::ipc::IPCResult RecvFlushRendering( 204 const wr::RenderReasons& aReasons) = 0; 205 virtual mozilla::ipc::IPCResult RecvNotifyMemoryPressure() = 0; 206 virtual mozilla::ipc::IPCResult RecvWaitOnTransactionProcessed() = 0; 207 virtual mozilla::ipc::IPCResult RecvStartFrameTimeRecording( 208 const int32_t& bufferSize, uint32_t* startIndex) = 0; 209 virtual mozilla::ipc::IPCResult RecvStopFrameTimeRecording( 210 const uint32_t& startIndex, nsTArray<float>* intervals) = 0; 211 virtual mozilla::ipc::IPCResult RecvCheckContentOnlyTDR( 212 const uint32_t& sequenceNum, bool* isContentOnlyTDR) = 0; 213 virtual mozilla::ipc::IPCResult RecvDynamicToolbarOffsetChanged( 214 const int32_t& aOffset) = 0; 215 216 bool mCanSend; 217 218 protected: 219 RefPtr<CompositorManagerParent> mCompositorManager; 220 }; 221 222 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS( 223 CompositorBridgeParentBase::TransformsToSkip) 224 225 class CompositorBridgeParent final : public CompositorBridgeParentBase, 226 public CompositorController { 227 friend class CompositorThreadHolder; 228 friend class InProcessCompositorSession; 229 friend class gfx::GPUProcessManager; 230 friend class gfx::GPUParent; 231 friend class PCompositorBridgeParent; 232 233 public: 234 NS_IMETHOD_(MozExternalRefCountType) AddRef() override { 235 return CompositorBridgeParentBase::AddRef(); 236 } 237 NS_IMETHOD_(MozExternalRefCountType) Release() override { 238 return CompositorBridgeParentBase::Release(); 239 } 240 241 explicit CompositorBridgeParent(CompositorManagerParent* aManager, 242 CSSToLayoutDeviceScale aScale, 243 const TimeDuration& aVsyncRate, 244 const CompositorOptions& aOptions, 245 bool aUseExternalSurfaceSize, 246 const gfx::IntSize& aSurfaceSize, 247 uint64_t aInnerWindowId); 248 249 void InitSameProcess(widget::CompositorWidget* aWidget, 250 const LayersId& aLayerTreeId); 251 252 #ifdef XP_MACOSX 253 // macOS platform-specific initdata uses move semantics, which 254 // changes the method signature. Other platforms don't need to 255 // override the existing method. 256 mozilla::ipc::IPCResult RecvPCompositorWidgetConstructor( 257 PCompositorWidgetParent* actor, 258 CompositorWidgetInitData&& aInitData) override; 259 #endif 260 mozilla::ipc::IPCResult RecvInitialize( 261 const LayersId& aRootLayerTreeId) override; 262 mozilla::ipc::IPCResult RecvWillClose() override; 263 mozilla::ipc::IPCResult RecvPause() override; 264 mozilla::ipc::IPCResult RecvRequestFxrOutput() override; 265 mozilla::ipc::IPCResult RecvResume() override; 266 mozilla::ipc::IPCResult RecvResumeAsync() override; 267 mozilla::ipc::IPCResult RecvNotifyChildCreated( 268 const LayersId& child, CompositorOptions* aOptions) override; 269 mozilla::ipc::IPCResult RecvMapAndNotifyChildCreated( 270 const LayersId& child, const base::ProcessId& pid, 271 CompositorOptions* aOptions) override; 272 mozilla::ipc::IPCResult RecvNotifyChildRecreated( 273 const LayersId& child, CompositorOptions* aOptions) override; 274 mozilla::ipc::IPCResult RecvAdoptChild(const LayersId& child) override; 275 mozilla::ipc::IPCResult RecvFlushRendering( 276 const wr::RenderReasons& aReasons) override; 277 mozilla::ipc::IPCResult RecvFlushRenderingAsync( 278 const wr::RenderReasons& aReasons) override; 279 mozilla::ipc::IPCResult RecvWaitOnTransactionProcessed() override; 280 mozilla::ipc::IPCResult RecvForcePresent( 281 const wr::RenderReasons& aReasons) override; 282 283 mozilla::ipc::IPCResult RecvStartFrameTimeRecording( 284 const int32_t& aBufferSize, uint32_t* aOutStartIndex) override; 285 mozilla::ipc::IPCResult RecvStopFrameTimeRecording( 286 const uint32_t& aStartIndex, nsTArray<float>* intervals) override; 287 288 mozilla::ipc::IPCResult RecvCheckContentOnlyTDR( 289 const uint32_t& sequenceNum, bool* isContentOnlyTDR) override { 290 return IPC_OK(); 291 } 292 293 mozilla::ipc::IPCResult RecvDynamicToolbarOffsetChanged( 294 const int32_t& aOffset) override; 295 296 mozilla::ipc::IPCResult RecvNotifyMemoryPressure() override; 297 mozilla::ipc::IPCResult RecvBeginRecording( 298 const TimeStamp& aRecordingStart, 299 BeginRecordingResolver&& aResolve) override; 300 mozilla::ipc::IPCResult RecvEndRecording( 301 EndRecordingResolver&& aResolve) override; 302 303 void NotifyMemoryPressure() override; 304 void AccumulateMemoryReport(wr::MemoryReport*) override; 305 306 void ActorDestroy(ActorDestroyReason why) override; 307 308 bool SetTestSampleTime(const LayersId& aId, const TimeStamp& aTime) override; 309 void LeaveTestMode(const LayersId& aId) override; 310 CompositorAnimationStorage* GetAnimationStorage(); 311 using JankedAnimations = 312 std::unordered_map<LayersId, nsTArray<uint64_t>, LayersId::HashFn>; 313 void NotifyJankedAnimations(const JankedAnimations& aJankedAnimations); 314 void SetTestAsyncScrollOffset(const LayersId& aLayersId, 315 const ScrollableLayerGuid::ViewID& aScrollId, 316 const CSSPoint& aPoint) override; 317 void SetTestAsyncZoom(const LayersId& aLayersId, 318 const ScrollableLayerGuid::ViewID& aScrollId, 319 const LayerToParentLayerScale& aZoom) override; 320 void FlushApzRepaints(const LayersId& aLayersId) override; 321 void GetAPZTestData(const LayersId& aLayersId, 322 APZTestData* aOutData) override; 323 void GetFrameUniformity(const LayersId& aLayersId, 324 FrameUniformityData* data) override; 325 void SetConfirmedTargetAPZC( 326 const LayersId& aLayersId, const uint64_t& aInputBlockId, 327 nsTArray<ScrollableLayerGuid>&& aTargets) override; 328 void SetFixedLayerMargins(ScreenIntCoord aTop, ScreenIntCoord aBottom); 329 void EndWheelTransaction( 330 const LayersId& aLayersId, 331 PWebRenderBridgeParent::EndWheelTransactionResolver&& aResolve) override; 332 333 PTextureParent* AllocPTextureParent( 334 const SurfaceDescriptor& aSharedData, ReadLockDescriptor& aReadLock, 335 const LayersBackend& aLayersBackend, const TextureFlags& aFlags, 336 const LayersId& aId, const uint64_t& aSerial, 337 const wr::MaybeExternalImageId& aExternalImageId) override; 338 bool DeallocPTextureParent(PTextureParent* actor) override; 339 340 bool IsSameProcess() const override; 341 342 void NotifyWebRenderDisableNativeCompositor(); 343 344 void NotifyDidRender(const VsyncId& aCompositeStartId, 345 TimeStamp& aCompositeStart, TimeStamp& aRenderStart, 346 TimeStamp& aCompositeEnd, 347 wr::RendererStats* aStats = nullptr); 348 void NotifyPipelineRendered(const wr::PipelineId& aPipelineId, 349 const wr::Epoch& aEpoch, 350 const VsyncId& aCompositeStartId, 351 TimeStamp& aCompositeStart, 352 TimeStamp& aRenderStart, TimeStamp& aCompositeEnd, 353 wr::RendererStats* aStats = nullptr); 354 void ScheduleFrameAfterSceneBuild( 355 RefPtr<const wr::WebRenderPipelineInfo> aInfo); 356 RefPtr<AsyncImagePipelineManager> GetAsyncImagePipelineManager() const; 357 358 already_AddRefed<PCompositorWidgetParent> AllocPCompositorWidgetParent( 359 const CompositorWidgetInitData& aInitData) override; 360 361 void ObserveLayersUpdate(LayersId aLayersId, bool aActive) override {} 362 363 /** 364 * This forces the is-first-paint flag to true. This is intended to 365 * be called by the widget code when it loses its viewport information 366 * (or for whatever reason wants to refresh the viewport information). 367 * The information refresh happens because the compositor will call 368 * SetFirstPaintViewport on the next frame of composition. 369 */ 370 void ForceIsFirstPaint(); 371 372 void NotifyChildCreated(LayersId aChild); 373 374 void AsyncRender(); 375 376 // Can be called from any thread 377 void ScheduleRenderOnCompositorThread(wr::RenderReasons aReasons) override; 378 379 void ScheduleComposition(wr::RenderReasons aReasons); 380 381 static void ScheduleForcedComposition(const LayersId& aLayersId, 382 wr::RenderReasons aReasons); 383 384 /** 385 * Returns the unique layer tree identifier that corresponds to the root 386 * tree of this compositor. 387 */ 388 LayersId RootLayerTreeId(); 389 390 /** 391 * Initialize statics. 392 */ 393 static void InitializeStatics(); 394 395 /** 396 * Notify the compositor for the given layer tree that vsync has occurred. 397 */ 398 static void NotifyVsync(const VsyncEvent& aVsync, const LayersId& aLayersId); 399 400 /** 401 * Set aController as the pan/zoom callback for the subtree referred 402 * to by aLayersId. 403 * 404 * Must run on content main thread. 405 */ 406 static void SetControllerForLayerTree(LayersId aLayersId, 407 GeckoContentController* aController); 408 409 struct LayerTreeState { 410 LayerTreeState(); 411 ~LayerTreeState(); 412 RefPtr<GeckoContentController> mController; 413 APZCTreeManagerParent* mApzcTreeManagerParent; 414 // The mApzInputBridgeParent is only populated for LayerTreeState 415 // objects corresponding to root LayerIds (one for each top-level 416 // window). 417 APZInputBridgeParent* mApzInputBridgeParent; 418 RefPtr<CompositorBridgeParent> mParent; 419 RefPtr<WebRenderBridgeParent> mWrBridge; 420 // Pointer to the ContentCompositorBridgeParent. Used by APZCs to share 421 // their FrameMetrics with the corresponding child process that holds 422 // the PCompositorBridgeChild 423 ContentCompositorBridgeParent* mContentCompositorBridgeParent; 424 425 CompositorController* GetCompositorController() const; 426 RefPtr<UiCompositorControllerParent> mUiControllerParent; 427 }; 428 429 /** 430 * Lookup the indirect shadow tree for |aId| and return it if it 431 * exists. Otherwise null is returned. This must only be called on 432 * the compositor thread. 433 */ 434 static LayerTreeState* GetIndirectShadowTree(LayersId aId); 435 436 /** 437 * If a shadow tree exists for the given id |aId|, return true. Otherwise 438 * return false. 439 */ 440 static bool HasIndirectShadowTree(LayersId aId); 441 442 /** 443 * Lookup the indirect shadow tree for |aId|, call the function object and 444 * return true if found. If not found, return false. 445 */ 446 static bool CallWithIndirectShadowTree( 447 LayersId aId, const std::function<void(LayerTreeState&)>& aFunc); 448 449 /** 450 * Given the layers id for a content process, get the APZCTreeManagerParent 451 * for the corresponding *root* layers id. That is, the APZCTreeManagerParent, 452 * if one is found, will always be connected to the parent process rather 453 * than a content process. Note that unless the compositor process is 454 * separated this is expected to return null, because if the compositor is 455 * living in the gecko parent process then there is no APZCTreeManagerParent 456 * for the parent process. 457 */ 458 static APZCTreeManagerParent* GetApzcTreeManagerParentForRoot( 459 LayersId aContentLayersId); 460 /** 461 * Same as the GetApzcTreeManagerParentForRoot function, but returns 462 * the GeckoContentController for the parent process. 463 */ 464 static GeckoContentController* GetGeckoContentControllerForRoot( 465 LayersId aContentLayersId); 466 467 /** 468 * Same as the GetApzcTreeManagerParentForRoot function, but returns 469 * the APZInputBridge for the parent process. 470 */ 471 static APZInputBridgeParent* GetApzInputBridgeParentForRoot( 472 LayersId aContentLayersId); 473 474 /** 475 * Used by the profiler to denote when a vsync occured 476 */ 477 static void PostInsertVsyncProfilerMarker(mozilla::TimeStamp aVsyncTimestamp); 478 479 widget::CompositorWidget* GetWidget() { return mWidget; } 480 481 PAPZCTreeManagerParent* AllocPAPZCTreeManagerParent( 482 const LayersId& aLayersId) override; 483 bool DeallocPAPZCTreeManagerParent(PAPZCTreeManagerParent* aActor) override; 484 485 // Helper method so that we don't have to expose mApzcTreeManager to 486 // ContentCompositorBridgeParent. 487 void AllocateAPZCTreeManagerParent( 488 const StaticMonitorAutoLock& aProofOfLayerTreeStateLock, 489 const LayersId& aLayersId, LayerTreeState& aLayerTreeStateToUpdate); 490 491 static void SetAPZInputBridgeParent(const LayersId& aLayersId, 492 APZInputBridgeParent* aInputBridgeParent); 493 494 PAPZParent* AllocPAPZParent(const LayersId& aLayersId) override; 495 bool DeallocPAPZParent(PAPZParent* aActor) override; 496 497 RefPtr<APZSampler> GetAPZSampler() const; 498 RefPtr<APZUpdater> GetAPZUpdater() const; 499 RefPtr<OMTASampler> GetOMTASampler() const; 500 501 uint64_t GetInnerWindowId() const { return mInnerWindowId; } 502 503 CompositorOptions GetOptions() const { return mOptions; } 504 505 TimeDuration GetVsyncInterval() const { 506 // the variable is called "rate" but really it's an interval 507 return mVsyncRate; 508 } 509 510 PWebRenderBridgeParent* AllocPWebRenderBridgeParent( 511 const wr::PipelineId& aPipelineId, const LayoutDeviceIntSize& aSize, 512 const WindowKind& aWindowKind) override; 513 bool DeallocPWebRenderBridgeParent(PWebRenderBridgeParent* aActor) override; 514 RefPtr<WebRenderBridgeParent> GetWebRenderBridgeParent() const; 515 Maybe<TimeStamp> GetTestingTimeStamp() const; 516 517 static CompositorBridgeParent* GetCompositorBridgeParentFromLayersId( 518 const LayersId& aLayersId); 519 static RefPtr<CompositorBridgeParent> GetCompositorBridgeParentFromWindowId( 520 const wr::WindowId& aWindowId); 521 522 /** 523 * This returns a reference to the IAPZCTreeManager "controller subinterface" 524 * to which pan/zoom-related events can be sent. The controller subinterface 525 * doesn't expose any sampler-thread APZCTreeManager methods. 526 */ 527 static already_AddRefed<IAPZCTreeManager> GetAPZCTreeManager( 528 LayersId aLayersId); 529 530 WebRenderBridgeParent* GetWrBridge() { return mWrBridge; } 531 532 void FlushPendingWrTransactionEventsWithWait(); 533 534 private: 535 /** 536 * Lookup the indirect shadow tree for |aId| and return it if it 537 * exists. Otherwise null is returned. 538 */ 539 static LayerTreeState* GetIndirectShadowTreeInternal(LayersId aId); 540 541 void Initialize(); 542 543 /** 544 * Called during destruction in order to release resources as early as 545 * possible. 546 */ 547 void StopAndClearResources(); 548 549 /** 550 * Release compositor-thread resources referred to by |aID|. 551 * 552 * Must run on the content main thread. 553 */ 554 static void DeallocateLayerTreeId(LayersId aId); 555 556 /** 557 * Notify the compositor the quality settings have been updated. 558 */ 559 static void UpdateQualitySettings(); 560 561 /** 562 * Notify the compositor the debug flags have been updated. 563 */ 564 static void UpdateDebugFlags(); 565 566 /** 567 * Notify the compositor some webrender parameters have been updated. 568 */ 569 static void UpdateWebRenderParameters(); 570 571 /** 572 * Notify the compositor some webrender parameters have been updated. 573 */ 574 static void UpdateWebRenderBoolParameters(); 575 576 /** 577 * Notify the compositor webrender profiler UI string has been updated. 578 */ 579 static void UpdateWebRenderProfilerUI(); 580 581 static void ResetStable(); 582 583 void MaybeDeclareStable(); 584 585 protected: 586 // Protected destructor, to discourage deletion outside of Release(): 587 virtual ~CompositorBridgeParent(); 588 589 void DeferredDestroy(); 590 591 void SetEGLSurfaceRect(int x, int y, int width, int height); 592 593 public: 594 void PauseComposition(); 595 bool ResumeComposition(); 596 bool ResumeCompositionAndResize(int x, int y, int width, int height); 597 bool IsPaused(); 598 599 typedef std::map<LayersId, CompositorBridgeParent::LayerTreeState> 600 LayerTreeMap; 601 602 static StaticMonitor sIndirectLayerTreesLock; 603 static LayerTreeMap sIndirectLayerTrees 604 MOZ_GUARDED_BY(sIndirectLayerTreesLock); 605 606 protected: 607 /** 608 * Remaning cleanups after the compositore thread is gone. 609 */ 610 static void FinishShutdown(); 611 612 // The indirect layer tree lock must be held before calling this function. 613 // Callback should take (LayerTreeState* aState, const LayersId& aLayersId) 614 template <typename Lambda> 615 inline void ForEachIndirectLayerTree(const Lambda& aCallback); 616 617 // The indirect layer tree lock must be held before calling this function. 618 // Callback should take (LayerTreeState* aState, const LayersId& aLayersId) 619 template <typename Lambda> 620 static inline void ForEachWebRenderBridgeParent(const Lambda& aCallback); 621 622 static bool sStable; 623 static uint32_t sFramesComposited; 624 625 RefPtr<AsyncImagePipelineManager> mAsyncImageManager; 626 RefPtr<WebRenderBridgeParent> mWrBridge; 627 widget::CompositorWidget* mWidget; 628 Maybe<TimeStamp> mTestTime; 629 CSSToLayoutDeviceScale mScale; 630 TimeDuration mVsyncRate; 631 632 bool mPaused; 633 bool mHaveCompositionRecorder; 634 bool mIsForcedFirstPaint; 635 636 bool mUseExternalSurfaceSize; 637 gfx::IntSize mEGLSurfaceSize; 638 639 CompositorOptions mOptions; 640 641 LayersId mRootLayerTreeID; 642 643 RefPtr<APZCTreeManager> mApzcTreeManager; 644 RefPtr<APZSampler> mApzSampler; 645 RefPtr<APZUpdater> mApzUpdater; 646 RefPtr<OMTASampler> mOMTASampler; 647 648 // Store the inner window id of the browser window, to use it in 649 // profiler markers. 650 uint64_t mInnerWindowId; 651 652 RefPtr<CompositorVsyncScheduler> mCompositorScheduler; 653 // This makes sure the compositorParent is not destroyed before receiving 654 // confirmation that the channel is closed. 655 // mSelfRef is cleared in DeferredDestroy which is scheduled by ActorDestroy. 656 RefPtr<CompositorBridgeParent> mSelfRef; 657 RefPtr<CompositorAnimationStorage> mAnimationStorage; 658 659 DISALLOW_EVIL_CONSTRUCTORS(CompositorBridgeParent); 660 }; 661 662 int32_t RecordContentFrameTime( 663 const VsyncId& aTxnId, const TimeStamp& aVsyncStart, 664 const TimeStamp& aTxnStart, const VsyncId& aCompositeId, 665 const TimeStamp& aCompositeEnd, const TimeDuration& aFullPaintTime, 666 const TimeDuration& aVsyncRate, bool aContainsSVGGroup, 667 bool aRecordUploadStats, wr::RendererStats* aStats = nullptr); 668 669 void RecordCompositionPayloadsPresented( 670 const TimeStamp& aCompositionEndTime, 671 const nsTArray<CompositionPayload>& aPayloads); 672 673 } // namespace layers 674 } // namespace mozilla 675 676 #endif // mozilla_layers_CompositorBridgeParent_h