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

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; 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_TILEDCONTENTHOST_H
       7             : #define GFX_TILEDCONTENTHOST_H
       8             : 
       9             : #include <stdint.h>                     // for uint16_t
      10             : #include <stdio.h>                      // for FILE
      11             : #include <algorithm>                    // for swap
      12             : #include "ContentHost.h"                // for ContentHost
      13             : #include "TiledLayerBuffer.h"           // for TiledLayerBuffer, etc
      14             : #include "CompositableHost.h"
      15             : #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
      16             : #include "mozilla/Attributes.h"         // for override
      17             : #include "mozilla/RefPtr.h"             // for RefPtr
      18             : #include "mozilla/gfx/MatrixFwd.h"      // for Matrix4x4
      19             : #include "mozilla/gfx/Point.h"          // for Point
      20             : #include "mozilla/gfx/Rect.h"           // for Rect
      21             : #include "mozilla/gfx/Types.h"          // for SamplingFilter
      22             : #include "mozilla/layers/CompositorTypes.h"  // for TextureInfo, etc
      23             : #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
      24             : #include "mozilla/layers/LayersTypes.h"  // for LayerRenderState, etc
      25             : #include "mozilla/layers/TextureHost.h"  // for TextureHost
      26             : #include "mozilla/layers/TextureClient.h"
      27             : #include "mozilla/mozalloc.h"           // for operator delete
      28             : #include "nsRegion.h"                   // for nsIntRegion
      29             : #include "nscore.h"                     // for nsACString
      30             : 
      31             : namespace mozilla {
      32             : 
      33             : namespace layers {
      34             : 
      35             : class Compositor;
      36             : class ISurfaceAllocator;
      37             : class Layer;
      38             : class ThebesBufferData;
      39             : class TextureReadLock;
      40             : struct EffectChain;
      41             : 
      42             : 
      43           0 : class TileHost {
      44             : public:
      45             :   // Constructs a placeholder TileHost. See the comments above
      46             :   // TiledLayerBuffer for more information on what this is used for;
      47             :   // essentially, this is a sentinel used to represent an invalid or blank
      48             :   // tile.
      49           0 :   TileHost()
      50           0 :   {}
      51             : 
      52             :   // Constructs a TileHost from a TextureReadLock and TextureHost.
      53             :   TileHost(TextureReadLock* aSharedLock,
      54             :                TextureHost* aTextureHost,
      55             :                TextureHost* aTextureHostOnWhite,
      56             :                TextureSource* aSource,
      57             :                TextureSource* aSourceOnWhite)
      58             :     : mTextureHost(aTextureHost)
      59             :     , mTextureHostOnWhite(aTextureHostOnWhite)
      60             :     , mTextureSource(aSource)
      61             :     , mTextureSourceOnWhite(aSourceOnWhite)
      62             :   {}
      63             : 
      64             :   TileHost(const TileHost& o) {
      65             :     mTextureHost = o.mTextureHost;
      66             :     mTextureHostOnWhite = o.mTextureHostOnWhite;
      67             :     mTextureSource = o.mTextureSource;
      68             :     mTextureSourceOnWhite = o.mTextureSourceOnWhite;
      69             :     mTilePosition = o.mTilePosition;
      70             :   }
      71             :   TileHost& operator=(const TileHost& o) {
      72             :     if (this == &o) {
      73             :       return *this;
      74             :     }
      75             :     mTextureHost = o.mTextureHost;
      76             :     mTextureHostOnWhite = o.mTextureHostOnWhite;
      77             :     mTextureSource = o.mTextureSource;
      78             :     mTextureSourceOnWhite = o.mTextureSourceOnWhite;
      79             :     mTilePosition = o.mTilePosition;
      80             :     return *this;
      81             :   }
      82             : 
      83             :   bool operator== (const TileHost& o) const {
      84             :     return mTextureHost == o.mTextureHost;
      85             :   }
      86             :   bool operator!= (const TileHost& o) const {
      87             :     return mTextureHost != o.mTextureHost;
      88             :   }
      89             : 
      90           0 :   bool IsPlaceholderTile() const { return mTextureHost == nullptr; }
      91             : 
      92             :   void Dump(std::stringstream& aStream) {
      93             :     aStream << "TileHost(...)"; // fill in as needed
      94             :   }
      95             : 
      96           0 :   void DumpTexture(std::stringstream& aStream, TextureDumpMode /* aCompress, ignored for host tiles */) {
      97             :     // TODO We should combine the OnWhite/OnBlack here an just output a single image.
      98           0 :     CompositableHost::DumpTextureHost(aStream, mTextureHost);
      99           0 :   }
     100             : 
     101             :   /**
     102             :    * This does a linear tween of the passed opacity (which is assumed
     103             :    * to be between 0.0 and 1.0). The duration of the fade is controlled
     104             :    * by the 'layers.tiles.fade-in.duration-ms' preference. It is enabled
     105             :    * via 'layers.tiles.fade-in.enabled'
     106             :    */
     107             :   float GetFadeInOpacity(float aOpacity);
     108             : 
     109             :   CompositableTextureHostRef mTextureHost;
     110             :   CompositableTextureHostRef mTextureHostOnWhite;
     111             :   mutable CompositableTextureSourceRef mTextureSource;
     112             :   mutable CompositableTextureSourceRef mTextureSourceOnWhite;
     113             :   // This is not strictly necessary but makes debugging whole lot easier.
     114             :   TileIntPoint mTilePosition;
     115             :   TimeStamp mFadeStart;
     116             : };
     117             : 
     118             : class TiledLayerBufferComposite
     119             :   : public TiledLayerBuffer<TiledLayerBufferComposite, TileHost>
     120             : {
     121             :   friend class TiledLayerBuffer<TiledLayerBufferComposite, TileHost>;
     122             : 
     123             : public:
     124             :   TiledLayerBufferComposite();
     125             :   ~TiledLayerBufferComposite();
     126             : 
     127             :   bool UseTiles(const SurfaceDescriptorTiles& aTileDescriptors,
     128             :                 HostLayerManager* aLayerManager,
     129             :                 ISurfaceAllocator* aAllocator);
     130             : 
     131             :   void Clear();
     132             : 
     133             :   TileHost GetPlaceholderTile() const { return TileHost(); }
     134             : 
     135             :   // Stores the absolute resolution of the containing frame, calculated
     136             :   // by the sum of the resolutions of all parent layers' FrameMetrics.
     137           0 :   const CSSToParentLayerScale2D& GetFrameResolution() { return mFrameResolution; }
     138             : 
     139             :   void SetTextureSourceProvider(TextureSourceProvider* aProvider);
     140             : 
     141             :   void AddAnimationInvalidation(nsIntRegion& aRegion);
     142             : protected:
     143             : 
     144             :   CSSToParentLayerScale2D mFrameResolution;
     145             : };
     146             : 
     147             : /**
     148             :  * ContentHost for tiled PaintedLayers. Since tiled layers are special snow
     149             :  * flakes, we have a unique update process. All the textures that back the
     150             :  * tiles are added in the usual way, but Updated is called on the host side
     151             :  * in response to a message that describes the transaction for every tile.
     152             :  * Composition happens in the normal way.
     153             :  *
     154             :  * TiledContentHost has a TiledLayerBufferComposite which keeps hold of the tiles.
     155             :  * Each tile has a reference to a texture host. During the layers transaction, we
     156             :  * receive a list of descriptors for the client-side tile buffer tiles
     157             :  * (UseTiledLayerBuffer). If we receive two transactions before a composition,
     158             :  * we immediately unlock and discard the unused buffer.
     159             :  *
     160             :  * When the content host is composited, we first validate the TiledLayerBuffer
     161             :  * (Upload), which calls Updated on each tile's texture host to make sure the
     162             :  * texture data has been uploaded. For single-buffered tiles, we unlock at this
     163             :  * point, for double-buffered tiles we unlock and discard the last composited
     164             :  * buffer after compositing a new one. Rendering takes us to RenderTile which
     165             :  * is similar to Composite for non-tiled ContentHosts.
     166             :  */
     167             : class TiledContentHost : public ContentHost
     168             : {
     169             : public:
     170             :   explicit TiledContentHost(const TextureInfo& aTextureInfo);
     171             : 
     172             : protected:
     173             :   ~TiledContentHost();
     174             : 
     175             : public:
     176             :   // Generate effect for layerscope when using hwc.
     177             :   virtual already_AddRefed<TexturedEffect> GenEffect(const gfx::SamplingFilter aSamplingFilter) override;
     178             : 
     179           0 :   virtual bool UpdateThebes(const ThebesBufferData& aData,
     180             :                             const nsIntRegion& aUpdated,
     181             :                             const nsIntRegion& aOldValidRegionBack) override
     182             :   {
     183           0 :     NS_ERROR("N/A for tiled layers");
     184           0 :     return false;
     185             :   }
     186             : 
     187             :   const nsIntRegion& GetValidLowPrecisionRegion() const
     188             :   {
     189             :     return mLowPrecisionTiledBuffer.GetValidRegion();
     190             :   }
     191             : 
     192           0 :   const nsIntRegion& GetValidRegion() const
     193             :   {
     194           0 :     return mTiledBuffer.GetValidRegion();
     195             :   }
     196             : 
     197           0 :   virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override
     198             :   {
     199           0 :     CompositableHost::SetTextureSourceProvider(aProvider);
     200           0 :     mTiledBuffer.SetTextureSourceProvider(aProvider);
     201           0 :     mLowPrecisionTiledBuffer.SetTextureSourceProvider(aProvider);
     202           0 :   }
     203             : 
     204             :   bool UseTiledLayerBuffer(ISurfaceAllocator* aAllocator,
     205             :                            const SurfaceDescriptorTiles& aTiledDescriptor);
     206             : 
     207             :   virtual void Composite(Compositor* aCompositor,
     208             :                          LayerComposite* aLayer,
     209             :                          EffectChain& aEffectChain,
     210             :                          float aOpacity,
     211             :                          const gfx::Matrix4x4& aTransform,
     212             :                          const gfx::SamplingFilter aSamplingFilter,
     213             :                          const gfx::IntRect& aClipRect,
     214             :                          const nsIntRegion* aVisibleRegion = nullptr,
     215             :                          const Maybe<gfx::Polygon>& aGeometry = Nothing()) override;
     216             : 
     217           0 :   virtual CompositableType GetType() override { return CompositableType::CONTENT_TILED; }
     218             : 
     219           0 :   virtual TiledContentHost* AsTiledContentHost() override { return this; }
     220             : 
     221             :   virtual void Attach(Layer* aLayer,
     222             :                       TextureSourceProvider* aProvider,
     223             :                       AttachFlags aFlags = NO_FLAGS) override;
     224             : 
     225             :   virtual void Detach(Layer* aLayer = nullptr,
     226             :                       AttachFlags aFlags = NO_FLAGS) override;
     227             : 
     228             :   virtual void Dump(std::stringstream& aStream,
     229             :                     const char* aPrefix="",
     230             :                     bool aDumpHtml=false) override;
     231             : 
     232             :   virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
     233             : 
     234             :   virtual void AddAnimationInvalidation(nsIntRegion& aRegion) override;
     235             : 
     236             : private:
     237             : 
     238             :   void RenderLayerBuffer(TiledLayerBufferComposite& aLayerBuffer,
     239             :                          Compositor* aCompositor,
     240             :                          const gfx::Color* aBackgroundColor,
     241             :                          EffectChain& aEffectChain,
     242             :                          float aOpacity,
     243             :                          const gfx::SamplingFilter aSamplingFilter,
     244             :                          const gfx::IntRect& aClipRect,
     245             :                          nsIntRegion aMaskRegion,
     246             :                          gfx::Matrix4x4 aTransform,
     247             :                          const Maybe<gfx::Polygon>& aGeometry);
     248             : 
     249             :   // Renders a single given tile.
     250             :   void RenderTile(TileHost& aTile,
     251             :                   Compositor* aCompositor,
     252             :                   EffectChain& aEffectChain,
     253             :                   float aOpacity,
     254             :                   const gfx::Matrix4x4& aTransform,
     255             :                   const gfx::SamplingFilter aSamplingFilter,
     256             :                   const gfx::IntRect& aClipRect,
     257             :                   const nsIntRegion& aScreenRegion,
     258             :                   const gfx::IntPoint& aTextureOffset,
     259             :                   const gfx::IntSize& aTextureBounds,
     260             :                   const gfx::Rect& aVisibleRect,
     261             :                   const Maybe<gfx::Polygon>& aGeometry);
     262             : 
     263             :   void EnsureTileStore() {}
     264             : 
     265             :   TiledLayerBufferComposite    mTiledBuffer;
     266             :   TiledLayerBufferComposite    mLowPrecisionTiledBuffer;
     267             : };
     268             : 
     269             : } // namespace layers
     270             : } // namespace mozilla
     271             : 
     272             : #endif

Generated by: LCOV version 1.13