LCOV - code coverage report
Current view: top level - gfx/layers/wr - WebRenderBridgeParent.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 20 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          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_WebRenderBridgeParent_h
       8             : #define mozilla_layers_WebRenderBridgeParent_h
       9             : 
      10             : #include <unordered_set>
      11             : 
      12             : #include "CompositableHost.h"           // for CompositableHost, ImageCompositeNotificationInfo
      13             : #include "GLContextProvider.h"
      14             : #include "mozilla/layers/CompositableTransactionParent.h"
      15             : #include "mozilla/layers/CompositorVsyncSchedulerOwner.h"
      16             : #include "mozilla/layers/PWebRenderBridgeParent.h"
      17             : #include "mozilla/Maybe.h"
      18             : #include "mozilla/webrender/WebRenderTypes.h"
      19             : #include "mozilla/webrender/WebRenderAPI.h"
      20             : #include "nsTArrayForwardDeclare.h"
      21             : 
      22             : namespace mozilla {
      23             : 
      24             : namespace gl {
      25             : class GLContext;
      26             : }
      27             : 
      28             : namespace widget {
      29             : class CompositorWidget;
      30             : }
      31             : 
      32             : namespace wr {
      33             : class WebRenderAPI;
      34             : }
      35             : 
      36             : namespace layers {
      37             : 
      38             : class Compositor;
      39             : class CompositorAnimationStorage;
      40             : class CompositorBridgeParentBase;
      41             : class CompositorVsyncScheduler;
      42             : class WebRenderCompositableHolder;
      43             : class WebRenderImageHost;
      44             : 
      45             : class WebRenderBridgeParent final : public PWebRenderBridgeParent
      46             :                                   , public CompositorVsyncSchedulerOwner
      47             :                                   , public CompositableParentManager
      48             : {
      49             : public:
      50             :   WebRenderBridgeParent(CompositorBridgeParentBase* aCompositorBridge,
      51             :                         const wr::PipelineId& aPipelineId,
      52             :                         widget::CompositorWidget* aWidget,
      53             :                         CompositorVsyncScheduler* aScheduler,
      54             :                         RefPtr<wr::WebRenderAPI>&& aApi,
      55             :                         RefPtr<WebRenderCompositableHolder>&& aHolder,
      56             :                         RefPtr<CompositorAnimationStorage>&& aAnimStorage);
      57             : 
      58             :   static WebRenderBridgeParent* CeateDestroyed();
      59             : 
      60           0 :   wr::PipelineId PipelineId() { return mPipelineId; }
      61           0 :   wr::WebRenderAPI* GetWebRenderAPI() { return mApi; }
      62           0 :   wr::Epoch WrEpoch() { return wr::NewEpoch(mWrEpoch); }
      63           0 :   WebRenderCompositableHolder* CompositableHolder() { return mCompositableHolder; }
      64           0 :   CompositorVsyncScheduler* CompositorScheduler() { return mCompositorScheduler.get(); }
      65             : 
      66             :   mozilla::ipc::IPCResult RecvNewCompositable(const CompositableHandle& aHandle,
      67             :                                               const TextureInfo& aInfo) override;
      68             :   mozilla::ipc::IPCResult RecvReleaseCompositable(const CompositableHandle& aHandle) override;
      69             : 
      70             :   mozilla::ipc::IPCResult RecvInitReadLocks(ReadLockArray&& aReadLocks) override;
      71             : 
      72             :   mozilla::ipc::IPCResult RecvCreate(const gfx::IntSize& aSize) override;
      73             :   mozilla::ipc::IPCResult RecvShutdown() override;
      74             :   mozilla::ipc::IPCResult RecvShutdownSync() override;
      75             :   mozilla::ipc::IPCResult RecvAddImage(const wr::ImageKey& aImageKey,
      76             :                                        const gfx::IntSize& aSize,
      77             :                                        const uint32_t& aStride,
      78             :                                        const gfx::SurfaceFormat& aFormat,
      79             :                                        const ByteBuffer& aBuffer) override;
      80             :   mozilla::ipc::IPCResult RecvAddBlobImage(const wr::ImageKey& aImageKey,
      81             :                                            const gfx::IntSize& aSize,
      82             :                                            const uint32_t& aStride,
      83             :                                            const gfx::SurfaceFormat& aFormat,
      84             :                                            const ByteBuffer& aBuffer) override;
      85             :   mozilla::ipc::IPCResult RecvUpdateImage(const wr::ImageKey& aImageKey,
      86             :                                           const gfx::IntSize& aSize,
      87             :                                           const gfx::SurfaceFormat& aFormat,
      88             :                                           const ByteBuffer& aBuffer) override;
      89             :   mozilla::ipc::IPCResult RecvDeleteImage(const wr::ImageKey& a1) override;
      90             :   mozilla::ipc::IPCResult RecvDeleteCompositorAnimations(InfallibleTArray<uint64_t>&& aIds) override;
      91             :   mozilla::ipc::IPCResult RecvAddRawFont(const wr::FontKey& aFontKey,
      92             :                                          const ByteBuffer& aBuffer,
      93             :                                          const uint32_t& aFontIndex) override;
      94             :   mozilla::ipc::IPCResult RecvDeleteFont(const wr::FontKey& aFontKey) override;
      95             :   mozilla::ipc::IPCResult RecvDPBegin(const gfx::IntSize& aSize) override;
      96             :   mozilla::ipc::IPCResult RecvDPEnd(const gfx::IntSize& aSize,
      97             :                                     InfallibleTArray<WebRenderParentCommand>&& aCommands,
      98             :                                     InfallibleTArray<OpDestroy>&& aToDestroy,
      99             :                                     const uint64_t& aFwdTransactionId,
     100             :                                     const uint64_t& aTransactionId,
     101             :                                     const WrSize& aContentSize,
     102             :                                     const ByteBuffer& dl,
     103             :                                     const WrBuiltDisplayListDescriptor& dlDesc,
     104             :                                     const WebRenderScrollData& aScrollData,
     105             :                                     const uint32_t& aIdNameSpace) override;
     106             :   mozilla::ipc::IPCResult RecvDPSyncEnd(const gfx::IntSize& aSize,
     107             :                                         InfallibleTArray<WebRenderParentCommand>&& aCommands,
     108             :                                         InfallibleTArray<OpDestroy>&& aToDestroy,
     109             :                                         const uint64_t& aFwdTransactionId,
     110             :                                         const uint64_t& aTransactionId,
     111             :                                         const WrSize& aContentSize,
     112             :                                         const ByteBuffer& dl,
     113             :                                         const WrBuiltDisplayListDescriptor& dlDesc,
     114             :                                         const WebRenderScrollData& aScrollData,
     115             :                                         const uint32_t& aIdNameSpace) override;
     116             :   mozilla::ipc::IPCResult RecvParentCommands(nsTArray<WebRenderParentCommand>&& commands) override;
     117             :   mozilla::ipc::IPCResult RecvDPGetSnapshot(PTextureParent* aTexture) override;
     118             : 
     119             :   mozilla::ipc::IPCResult RecvAddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineIds,
     120             :                                                                 const CompositableHandle& aHandle) override;
     121             :   mozilla::ipc::IPCResult RecvRemovePipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId) override;
     122             : 
     123             :   mozilla::ipc::IPCResult RecvAddExternalImageIdForCompositable(const ExternalImageId& aImageId,
     124             :                                                                 const CompositableHandle& aHandle) override;
     125             :   mozilla::ipc::IPCResult RecvRemoveExternalImageId(const ExternalImageId& aImageId) override;
     126             :   mozilla::ipc::IPCResult RecvSetLayerObserverEpoch(const uint64_t& aLayerObserverEpoch) override;
     127             : 
     128             :   mozilla::ipc::IPCResult RecvClearCachedResources() override;
     129             :   mozilla::ipc::IPCResult RecvForceComposite() override;
     130             : 
     131             :   mozilla::ipc::IPCResult RecvSetConfirmedTargetAPZC(const uint64_t& aBlockId,
     132             :                                                      nsTArray<ScrollableLayerGuid>&& aTargets) override;
     133             : 
     134             :   mozilla::ipc::IPCResult RecvSetTestSampleTime(const TimeStamp& aTime) override;
     135             :   mozilla::ipc::IPCResult RecvLeaveTestMode() override;
     136             :   mozilla::ipc::IPCResult RecvGetAnimationOpacity(const uint64_t& aCompositorAnimationsId,
     137             :                                                   float* aOpacity,
     138             :                                                   bool* aHasAnimationOpacity) override;
     139             :   mozilla::ipc::IPCResult RecvGetAnimationTransform(const uint64_t& aCompositorAnimationsId,
     140             :                                                     MaybeTransform* aTransform) override;
     141             :   mozilla::ipc::IPCResult RecvSetAsyncScrollOffset(const FrameMetrics::ViewID& aScrollId,
     142             :                                                    const float& aX,
     143             :                                                    const float& aY) override;
     144             :   mozilla::ipc::IPCResult RecvSetAsyncZoom(const FrameMetrics::ViewID& aScrollId,
     145             :                                            const float& aZoom) override;
     146             :   mozilla::ipc::IPCResult RecvFlushApzRepaints() override;
     147             :   mozilla::ipc::IPCResult RecvGetAPZTestData(APZTestData* data) override;
     148             : 
     149             :   void ActorDestroy(ActorDestroyReason aWhy) override;
     150             :   void SetWebRenderProfilerEnabled(bool aEnabled);
     151             : 
     152             :   void Pause();
     153             :   bool Resume();
     154             : 
     155             :   void Destroy();
     156             : 
     157             :   // CompositorVsyncSchedulerOwner
     158           0 :   bool IsPendingComposite() override { return false; }
     159           0 :   void FinishPendingComposite() override { }
     160             :   void CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr) override;
     161             : 
     162             :   // CompositableParentManager
     163             :   bool IsSameProcess() const override;
     164             :   base::ProcessId GetChildProcessId() override;
     165             :   void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override;
     166             :   void SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage) override;
     167             :   void SendPendingAsyncMessages() override;
     168             :   void SetAboutToSendAsyncMessages() override;
     169             : 
     170             :   void HoldPendingTransactionId(uint32_t aWrEpoch, uint64_t aTransactionId);
     171             :   uint64_t LastPendingTransactionId();
     172             :   uint64_t FlushPendingTransactionIds();
     173             :   uint64_t FlushTransactionIdsForEpoch(const wr::Epoch& aEpoch);
     174             : 
     175             :   TextureFactoryIdentifier GetTextureFactoryIdentifier();
     176             : 
     177             :   void AppendImageCompositeNotification(const ImageCompositeNotificationInfo& aNotification)
     178             :   {
     179             :     MOZ_ASSERT(mWidget);
     180             :     mImageCompositeNotifications.AppendElement(aNotification);
     181             :   }
     182             : 
     183           0 :   void ExtractImageCompositeNotifications(nsTArray<ImageCompositeNotificationInfo>* aNotifications)
     184             :   {
     185           0 :     MOZ_ASSERT(mWidget);
     186           0 :     aNotifications->AppendElements(Move(mImageCompositeNotifications));
     187           0 :   }
     188             : 
     189           0 :   uint32_t GetIdNameSpace()
     190             :   {
     191           0 :     return mIdNameSpace;
     192             :   }
     193             : 
     194             :   void UpdateAPZ();
     195             :   const WebRenderScrollData& GetScrollData() const;
     196             : 
     197           0 :   static uint32_t AllocIdNameSpace() {
     198           0 :     return ++sIdNameSpace;
     199             :   }
     200             : 
     201             :   void FlushRendering(bool aIsSync);
     202             : 
     203             :   void ScheduleComposition();
     204             : 
     205             :   void UpdateWebRender(CompositorVsyncScheduler* aScheduler,
     206             :                        wr::WebRenderAPI* aApi,
     207             :                        WebRenderCompositableHolder* aHolder,
     208             :                        CompositorAnimationStorage* aAnimStorage);
     209             : 
     210             : private:
     211             :   WebRenderBridgeParent();
     212             :   virtual ~WebRenderBridgeParent();
     213             : 
     214             :   uint64_t GetLayersId() const;
     215             :   void DeleteOldImages();
     216             :   void ProcessWebRenderParentCommands(InfallibleTArray<WebRenderParentCommand>& aCommands);
     217             :   void ProcessWebRenderCommands(const gfx::IntSize &aSize,
     218             :                                 InfallibleTArray<WebRenderParentCommand>& commands,
     219             :                                 const wr::Epoch& aEpoch,
     220             :                                 const WrSize& aContentSize,
     221             :                                 const ByteBuffer& dl,
     222             :                                 const WrBuiltDisplayListDescriptor& dlDesc,
     223             :                                 const uint32_t& aIdNameSpace);
     224             :   void ClearResources();
     225           0 :   uint64_t GetChildLayerObserverEpoch() const { return mChildLayerObserverEpoch; }
     226             :   bool ShouldParentObserveEpoch();
     227             :   void HandleDPEnd(const gfx::IntSize& aSize,
     228             :                    InfallibleTArray<WebRenderParentCommand>&& aCommands,
     229             :                    InfallibleTArray<OpDestroy>&& aToDestroy,
     230             :                    const uint64_t& aFwdTransactionId,
     231             :                    const uint64_t& aTransactionId,
     232             :                    const WrSize& aContentSize,
     233             :                    const ByteBuffer& dl,
     234             :                    const WrBuiltDisplayListDescriptor& dlDesc,
     235             :                    const WebRenderScrollData& aScrollData,
     236             :                    const uint32_t& aIdNameSpace);
     237             :   mozilla::ipc::IPCResult HandleShutdown();
     238             : 
     239             :   void AdvanceAnimations();
     240             :   void SampleAnimations(nsTArray<WrOpacityProperty>& aOpacityArray,
     241             :                         nsTArray<WrTransformProperty>& aTransformArray);
     242             : 
     243             :   CompositorBridgeParent* GetRootCompositorBridgeParent() const;
     244             : 
     245             :   // Have APZ push the async scroll state to WR. Returns true if an APZ
     246             :   // animation is in effect and we need to schedule another composition.
     247             :   // If scrollbars need their transforms updated, the provided aTransformArray
     248             :   // is populated with the property update details.
     249             :   bool PushAPZStateToWR(nsTArray<WrTransformProperty>& aTransformArray);
     250             : 
     251             :   // Helper method to get an APZC reference from a scroll id. Uses the layers
     252             :   // id of this bridge, and may return null if the APZC wasn't found.
     253             :   already_AddRefed<AsyncPanZoomController> GetTargetAPZC(const FrameMetrics::ViewID& aId);
     254             : 
     255             : private:
     256             :   struct PendingTransactionId {
     257           0 :     PendingTransactionId(wr::Epoch aEpoch, uint64_t aId)
     258           0 :       : mEpoch(aEpoch)
     259           0 :       , mId(aId)
     260           0 :     {}
     261             :     wr::Epoch mEpoch;
     262             :     uint64_t mId;
     263             :   };
     264             : 
     265             :   CompositorBridgeParentBase* MOZ_NON_OWNING_REF mCompositorBridge;
     266             :   wr::PipelineId mPipelineId;
     267             :   RefPtr<widget::CompositorWidget> mWidget;
     268             :   RefPtr<wr::WebRenderAPI> mApi;
     269             :   RefPtr<WebRenderCompositableHolder> mCompositableHolder;
     270             :   RefPtr<CompositorVsyncScheduler> mCompositorScheduler;
     271             :   RefPtr<CompositorAnimationStorage> mAnimStorage;
     272             :   std::vector<wr::ImageKey> mKeysToDelete;
     273             :   // mActiveImageKeys and mFontKeys are used to avoid leaking animations when
     274             :   // WebRenderBridgeParent is destroyed abnormally and Tab move between different windows.
     275             :   std::unordered_set<uint64_t> mActiveImageKeys;
     276             :   std::unordered_set<uint64_t> mFontKeys;
     277             :   // mActiveAnimations is used to avoid leaking animations when WebRenderBridgeParent is
     278             :   // destroyed abnormally and Tab move between different windows.
     279             :   std::unordered_set<uint64_t> mActiveAnimations;
     280             :   nsDataHashtable<nsUint64HashKey, RefPtr<WebRenderImageHost>> mAsyncCompositables;
     281             :   nsDataHashtable<nsUint64HashKey, RefPtr<WebRenderImageHost>> mExternalImageIds;
     282             :   nsTArray<ImageCompositeNotificationInfo> mImageCompositeNotifications;
     283             : 
     284             :   // These fields keep track of the latest layer observer epoch values in the child and the
     285             :   // parent. mChildLayerObserverEpoch is the latest epoch value received from the child.
     286             :   // mParentLayerObserverEpoch is the latest epoch value that we have told TabParent about
     287             :   // (via ObserveLayerUpdate).
     288             :   uint64_t mChildLayerObserverEpoch;
     289             :   uint64_t mParentLayerObserverEpoch;
     290             : 
     291             :   std::queue<PendingTransactionId> mPendingTransactionIds;
     292             :   uint32_t mWrEpoch;
     293             :   uint32_t mIdNameSpace;
     294             : 
     295             :   bool mPaused;
     296             :   bool mDestroyed;
     297             :   bool mForceRendering;
     298             : 
     299             :   // Can only be accessed on the compositor thread.
     300             :   WebRenderScrollData mScrollData;
     301             : 
     302             :   static uint32_t sIdNameSpace;
     303             : };
     304             : 
     305             : } // namespace layers
     306             : } // namespace mozilla
     307             : 
     308             : #endif // mozilla_layers_WebRenderBridgeParent_h

Generated by: LCOV version 1.13