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

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef GFX_WEBRENDERSCROLLDATA_H
       7             : #define GFX_WEBRENDERSCROLLDATA_H
       8             : 
       9             : #include <map>
      10             : 
      11             : #include "chrome/common/ipc_message_utils.h"
      12             : #include "FrameMetrics.h"
      13             : #include "ipc/IPCMessageUtils.h"
      14             : #include "LayersTypes.h"
      15             : #include "mozilla/GfxMessageUtils.h"
      16             : #include "mozilla/layers/LayerAttributes.h"
      17             : #include "mozilla/layers/LayersMessageUtils.h"
      18             : #include "mozilla/layers/FocusTarget.h"
      19             : #include "mozilla/Maybe.h"
      20             : #include "nsTArrayForwardDeclare.h"
      21             : 
      22             : namespace mozilla {
      23             : namespace layers {
      24             : 
      25             : class Layer;
      26             : class WebRenderScrollData;
      27             : 
      28             : // Data needed by APZ, per layer. One instance of this class is created for
      29             : // each layer in the layer tree and sent over PWebRenderBridge to the APZ code.
      30             : // Each WebRenderLayerScrollData is conceptually associated with an "owning"
      31             : // WebRenderScrollData.
      32           0 : class WebRenderLayerScrollData
      33             : {
      34             : public:
      35             :   WebRenderLayerScrollData(); // needed for IPC purposes
      36             :   ~WebRenderLayerScrollData();
      37             : 
      38             :   // Actually initialize the object. This is not done during the constructor
      39             :   // for optimization purposes (the call site is hard to write efficiently
      40             :   // if we do this in the constructor).
      41             :   void Initialize(WebRenderScrollData& aOwner,
      42             :                   Layer* aLayer,
      43             :                   int32_t aDescendantCount);
      44             : 
      45             :   int32_t GetDescendantCount() const;
      46             :   size_t GetScrollMetadataCount() const;
      47             : 
      48             :   // Return the ScrollMetadata object that used to be on the original Layer
      49             :   // at the given index. Since we deduplicate the ScrollMetadata objects into
      50             :   // the array in the owning WebRenderScrollData object, we need to be passed
      51             :   // in a reference to that owner as well.
      52             :   const ScrollMetadata& GetScrollMetadata(const WebRenderScrollData& aOwner,
      53             :                                           size_t aIndex) const;
      54             : 
      55           0 :   bool IsScrollInfoLayer() const { return mIsScrollInfoLayer; }
      56           0 :   gfx::Matrix4x4 GetTransform() const { return mTransform; }
      57             :   CSSTransformMatrix GetTransformTyped() const;
      58           0 :   bool GetTransformIsPerspective() const { return mTransformIsPerspective; }
      59           0 :   EventRegions GetEventRegions() const { return mEventRegions; }
      60           0 :   const LayerIntRegion& GetVisibleRegion() const { return mVisibleRegion; }
      61           0 :   Maybe<uint64_t> GetReferentId() const { return mReferentId; }
      62           0 :   EventRegionsOverride GetEventRegionsOverride() const { return mEventRegionsOverride; }
      63           0 :   const ScrollThumbData& GetScrollThumbData() const { return mScrollThumbData; }
      64           0 :   const uint64_t& GetScrollbarAnimationId() const { return mScrollbarAnimationId; }
      65           0 :   FrameMetrics::ViewID GetScrollbarTargetContainerId() const { return mScrollbarTargetContainerId; }
      66           0 :   bool IsScrollbarContainer() const { return mIsScrollbarContainer; }
      67           0 :   FrameMetrics::ViewID GetFixedPositionScrollContainerId() const { return mFixedPosScrollContainerId; }
      68             : 
      69             :   friend struct IPC::ParamTraits<WebRenderLayerScrollData>;
      70             : 
      71             : private:
      72             :   // The number of descendants this layer has (not including the layer itself).
      73             :   // This is needed to reconstruct the depth-first layer tree traversal
      74             :   // efficiently. Leaf layers should always have 0 descendants.
      75             :   int32_t mDescendantCount;
      76             : 
      77             :   // Handles to the ScrollMetadata objects that were on this layer. The values
      78             :   // stored in this array are indices into the owning WebRenderScrollData's
      79             :   // mScrollMetadatas array. This indirection is used to deduplicate the
      80             :   // ScrollMetadata objects, since there is usually heavy duplication of them
      81             :   // within a layer tree.
      82             :   nsTArray<size_t> mScrollIds;
      83             : 
      84             :   // Various data that we collect from the Layer in Initialize(), serialize
      85             :   // over IPC, and use on the parent side in APZ.
      86             : 
      87             :   bool mIsScrollInfoLayer;
      88             :   gfx::Matrix4x4 mTransform;
      89             :   bool mTransformIsPerspective;
      90             :   EventRegions mEventRegions;
      91             :   LayerIntRegion mVisibleRegion;
      92             :   Maybe<uint64_t> mReferentId;
      93             :   EventRegionsOverride mEventRegionsOverride;
      94             :   ScrollThumbData mScrollThumbData;
      95             :   uint64_t mScrollbarAnimationId;
      96             :   FrameMetrics::ViewID mScrollbarTargetContainerId;
      97             :   bool mIsScrollbarContainer;
      98             :   FrameMetrics::ViewID mFixedPosScrollContainerId;
      99             : };
     100             : 
     101             : // Data needed by APZ, for the whole layer tree. One instance of this class
     102             : // is created for each transaction sent over PWebRenderBridge. It is populated
     103             : // with information from the WebRender layer tree on the client side and the
     104             : // information is used by APZ on the parent side.
     105           0 : class WebRenderScrollData
     106             : {
     107             : public:
     108             :   WebRenderScrollData();
     109             :   ~WebRenderScrollData();
     110             : 
     111             :   // Add the given ScrollMetadata if it doesn't already exist. Return an index
     112             :   // that can be used to look up the metadata later.
     113             :   size_t AddMetadata(const ScrollMetadata& aMetadata);
     114             :   // Add a new empty WebRenderLayerScrollData and return the index that can be
     115             :   // used to look it up via GetLayerData.
     116             :   size_t AddNewLayerData();
     117             : 
     118             :   size_t GetLayerCount() const;
     119             : 
     120             :   // Return a pointer to the scroll data at the given index. Use with caution,
     121             :   // as the pointer may be invalidated if this WebRenderScrollData is mutated.
     122             :   WebRenderLayerScrollData* GetLayerDataMutable(size_t aIndex);
     123             :   const WebRenderLayerScrollData* GetLayerData(size_t aIndex) const;
     124             : 
     125             :   const ScrollMetadata& GetScrollMetadata(size_t aIndex) const;
     126             : 
     127           0 :   const FocusTarget& GetFocusTarget() const { return mFocusTarget; }
     128             :   void SetFocusTarget(const FocusTarget& aFocusTarget);
     129             : 
     130             :   void SetIsFirstPaint();
     131             :   bool IsFirstPaint() const;
     132             :   void SetPaintSequenceNumber(uint32_t aPaintSequenceNumber);
     133             :   uint32_t GetPaintSequenceNumber() const;
     134             : 
     135             :   friend struct IPC::ParamTraits<WebRenderScrollData>;
     136             : 
     137             : private:
     138             :   // Internal data structure used to maintain uniqueness of mScrollMetadatas.
     139             :   // This is not serialized/deserialized over IPC because there's no need for it,
     140             :   // as the parent side doesn't need this at all. Also because we don't have any
     141             :   // IPC-friendly hashtable implementation lying around.
     142             :   // The key into this map is the scrollId of a ScrollMetadata, and the value is
     143             :   // an index into the mScrollMetadatas array.
     144             :   std::map<FrameMetrics::ViewID, size_t> mScrollIdMap;
     145             : 
     146             :   // A list of all the unique ScrollMetadata objects from the layer tree. Each
     147             :   // ScrollMetadata in this list must have a unique scroll id.
     148             :   nsTArray<ScrollMetadata> mScrollMetadatas;
     149             : 
     150             :   // A list of per-layer scroll data objects, generated via a depth-first,
     151             :   // pre-order, last-to-first traversal of the layer tree (i.e. a recursive
     152             :   // traversal where a node N first pushes itself, followed by its children in
     153             :   // last-to-first order). Each layer's scroll data object knows how many
     154             :   // descendants that layer had, which allows reconstructing the traversal on the
     155             :   // other side.
     156             :   nsTArray<WebRenderLayerScrollData> mLayerScrollData;
     157             : 
     158             :   // The focus information for this layer tree
     159             :   FocusTarget mFocusTarget;
     160             : 
     161             :   bool mIsFirstPaint;
     162             :   uint32_t mPaintSequenceNumber;
     163             : };
     164             : 
     165             : } // namespace layers
     166             : } // namespace mozilla
     167             : 
     168             : namespace IPC {
     169             : 
     170             : // When ScrollThumbData is stored on the layer tree, it's part of
     171             : // SimpleAttributes which itself uses PlainOldDataSerializer, so
     172             : // we don't need a ParamTraits specialization for ScrollThumbData
     173             : // separately. Here, however, ScrollThumbData is stored as part
     174             : // of WebRenderLayerScrollData whose fields are serialized
     175             : // individually, so we do.
     176             : template<>
     177             : struct ParamTraits<mozilla::layers::ScrollThumbData>
     178             :   : public PlainOldDataSerializer<mozilla::layers::ScrollThumbData>
     179             : { };
     180             : 
     181             : template<>
     182             : struct ParamTraits<mozilla::layers::WebRenderLayerScrollData>
     183             : {
     184             :   typedef mozilla::layers::WebRenderLayerScrollData paramType;
     185             : 
     186             :   static void
     187           0 :   Write(Message* aMsg, const paramType& aParam)
     188             :   {
     189           0 :     WriteParam(aMsg, aParam.mDescendantCount);
     190           0 :     WriteParam(aMsg, aParam.mScrollIds);
     191           0 :     WriteParam(aMsg, aParam.mIsScrollInfoLayer);
     192           0 :     WriteParam(aMsg, aParam.mTransform);
     193           0 :     WriteParam(aMsg, aParam.mTransformIsPerspective);
     194           0 :     WriteParam(aMsg, aParam.mEventRegions);
     195           0 :     WriteParam(aMsg, aParam.mVisibleRegion);
     196           0 :     WriteParam(aMsg, aParam.mReferentId);
     197           0 :     WriteParam(aMsg, aParam.mEventRegionsOverride);
     198           0 :     WriteParam(aMsg, aParam.mScrollThumbData);
     199           0 :     WriteParam(aMsg, aParam.mScrollbarAnimationId);
     200           0 :     WriteParam(aMsg, aParam.mScrollbarTargetContainerId);
     201           0 :     WriteParam(aMsg, aParam.mIsScrollbarContainer);
     202           0 :     WriteParam(aMsg, aParam.mFixedPosScrollContainerId);
     203           0 :   }
     204             : 
     205             :   static bool
     206           0 :   Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
     207             :   {
     208           0 :     return ReadParam(aMsg, aIter, &aResult->mDescendantCount)
     209           0 :         && ReadParam(aMsg, aIter, &aResult->mScrollIds)
     210           0 :         && ReadParam(aMsg, aIter, &aResult->mIsScrollInfoLayer)
     211           0 :         && ReadParam(aMsg, aIter, &aResult->mTransform)
     212           0 :         && ReadParam(aMsg, aIter, &aResult->mTransformIsPerspective)
     213           0 :         && ReadParam(aMsg, aIter, &aResult->mEventRegions)
     214           0 :         && ReadParam(aMsg, aIter, &aResult->mVisibleRegion)
     215           0 :         && ReadParam(aMsg, aIter, &aResult->mReferentId)
     216           0 :         && ReadParam(aMsg, aIter, &aResult->mEventRegionsOverride)
     217           0 :         && ReadParam(aMsg, aIter, &aResult->mScrollThumbData)
     218           0 :         && ReadParam(aMsg, aIter, &aResult->mScrollbarAnimationId)
     219           0 :         && ReadParam(aMsg, aIter, &aResult->mScrollbarTargetContainerId)
     220           0 :         && ReadParam(aMsg, aIter, &aResult->mIsScrollbarContainer)
     221           0 :         && ReadParam(aMsg, aIter, &aResult->mFixedPosScrollContainerId);
     222             :   }
     223             : };
     224             : 
     225             : template<>
     226             : struct ParamTraits<mozilla::layers::WebRenderScrollData>
     227             : {
     228             :   typedef mozilla::layers::WebRenderScrollData paramType;
     229             : 
     230             :   static void
     231           0 :   Write(Message* aMsg, const paramType& aParam)
     232             :   {
     233           0 :     WriteParam(aMsg, aParam.mScrollMetadatas);
     234           0 :     WriteParam(aMsg, aParam.mLayerScrollData);
     235           0 :     WriteParam(aMsg, aParam.mFocusTarget);
     236           0 :     WriteParam(aMsg, aParam.mIsFirstPaint);
     237           0 :     WriteParam(aMsg, aParam.mPaintSequenceNumber);
     238           0 :   }
     239             : 
     240             :   static bool
     241           0 :   Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
     242             :   {
     243           0 :     return ReadParam(aMsg, aIter, &aResult->mScrollMetadatas)
     244           0 :         && ReadParam(aMsg, aIter, &aResult->mLayerScrollData)
     245           0 :         && ReadParam(aMsg, aIter, &aResult->mFocusTarget)
     246           0 :         && ReadParam(aMsg, aIter, &aResult->mIsFirstPaint)
     247           0 :         && ReadParam(aMsg, aIter, &aResult->mPaintSequenceNumber);
     248             :   }
     249             : };
     250             : 
     251             : } // namespace IPC
     252             : 
     253             : #endif /* GFX_WEBRENDERSCROLLDATA_H */

Generated by: LCOV version 1.13