LCOV - code coverage report
Current view: top level - gfx/layers/composite - CompositableHost.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 25 80 31.2 %
Date: 2017-07-14 16:53:18 Functions: 6 13 46.2 %
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             : #include "CompositableHost.h"
       7             : #include <map>                          // for _Rb_tree_iterator, map, etc
       8             : #include <utility>                      // for pair
       9             : #include "ContentHost.h"                // for ContentHostDoubleBuffered, etc
      10             : #include "Effects.h"                    // for EffectMask, Effect, etc
      11             : #include "gfxUtils.h"
      12             : #include "ImageHost.h"                  // for ImageHostBuffered, etc
      13             : #include "TiledContentHost.h"           // for TiledContentHost
      14             : #include "mozilla/gfx/gfxVars.h"
      15             : #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
      16             : #include "mozilla/layers/TextureHost.h"  // for TextureHost, etc
      17             : #include "mozilla/layers/WebRenderImageHost.h"
      18             : #include "mozilla/RefPtr.h"                   // for nsRefPtr
      19             : #include "nsDebug.h"                    // for NS_WARNING
      20             : #include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
      21             : #include "gfxPlatform.h"                // for gfxPlatform
      22             : #include "IPDLActor.h"
      23             : 
      24             : namespace mozilla {
      25             : 
      26             : using namespace gfx;
      27             : 
      28             : namespace layers {
      29             : 
      30             : class Compositor;
      31             : 
      32          22 : CompositableHost::CompositableHost(const TextureInfo& aTextureInfo)
      33             :   : mTextureInfo(aTextureInfo)
      34             :   , mCompositorBridgeID(0)
      35             :   , mLayer(nullptr)
      36             :   , mFlashCounter(0)
      37             :   , mAttached(false)
      38          22 :   , mKeepAttached(false)
      39             : {
      40          22 :   MOZ_COUNT_CTOR(CompositableHost);
      41          22 : }
      42             : 
      43          38 : CompositableHost::~CompositableHost()
      44             : {
      45          19 :   MOZ_COUNT_DTOR(CompositableHost);
      46          19 : }
      47             : 
      48             : void
      49          33 : CompositableHost::UseTextureHost(const nsTArray<TimedTexture>& aTextures)
      50             : {
      51          33 :   if (mTextureSourceProvider) {
      52          66 :     for (auto& texture : aTextures) {
      53          33 :       texture.mTexture->SetTextureSourceProvider(mTextureSourceProvider);
      54             :     }
      55             :   }
      56          33 : }
      57             : 
      58             : void
      59           0 : CompositableHost::UseComponentAlphaTextures(TextureHost* aTextureOnBlack,
      60             :                                             TextureHost* aTextureOnWhite)
      61             : {
      62           0 :   MOZ_ASSERT(aTextureOnBlack && aTextureOnWhite);
      63           0 :   if (mTextureSourceProvider) {
      64           0 :     aTextureOnBlack->SetTextureSourceProvider(mTextureSourceProvider);
      65           0 :     aTextureOnWhite->SetTextureSourceProvider(mTextureSourceProvider);
      66             :   }
      67           0 : }
      68             : 
      69             : void
      70           0 : CompositableHost::RemoveTextureHost(TextureHost* aTexture)
      71           0 : {}
      72             : 
      73             : void
      74          22 : CompositableHost::SetTextureSourceProvider(TextureSourceProvider* aProvider)
      75             : {
      76          22 :   MOZ_ASSERT(aProvider);
      77          22 :   mTextureSourceProvider = aProvider;
      78          22 : }
      79             : 
      80             : bool
      81           0 : CompositableHost::AddMaskEffect(EffectChain& aEffects,
      82             :                                 const gfx::Matrix4x4& aTransform)
      83             : {
      84           0 :   CompositableTextureSourceRef source;
      85           0 :   RefPtr<TextureHost> host = GetAsTextureHost();
      86             : 
      87           0 :   if (!host) {
      88           0 :     NS_WARNING("Using compositable with no valid TextureHost as mask");
      89           0 :     return false;
      90             :   }
      91             : 
      92           0 :   if (!host->Lock()) {
      93           0 :     NS_WARNING("Failed to lock the mask texture");
      94           0 :     return false;
      95             :   }
      96             : 
      97           0 :   if (!host->BindTextureSource(source)) {
      98           0 :     NS_WARNING("The TextureHost was successfully locked but can't provide a TextureSource");
      99           0 :     host->Unlock();
     100           0 :     return false;
     101             :   }
     102           0 :   MOZ_ASSERT(source);
     103             : 
     104             :   RefPtr<EffectMask> effect = new EffectMask(source,
     105           0 :                                              source->GetSize(),
     106           0 :                                              aTransform);
     107           0 :   aEffects.mSecondaryEffects[EffectTypes::MASK] = effect;
     108           0 :   return true;
     109             : }
     110             : 
     111             : void
     112           0 : CompositableHost::RemoveMaskEffect()
     113             : {
     114           0 :   RefPtr<TextureHost> host = GetAsTextureHost();
     115           0 :   if (host) {
     116           0 :     host->Unlock();
     117             :   }
     118           0 : }
     119             : 
     120             : /* static */ already_AddRefed<CompositableHost>
     121          22 : CompositableHost::Create(const TextureInfo& aTextureInfo)
     122             : {
     123          44 :   RefPtr<CompositableHost> result;
     124          22 :   switch (aTextureInfo.mCompositableType) {
     125             :   case CompositableType::IMAGE_BRIDGE:
     126           0 :     NS_ERROR("Cannot create an image bridge compositable this way");
     127           0 :     break;
     128             :   case CompositableType::CONTENT_TILED:
     129           0 :     result = new TiledContentHost(aTextureInfo);
     130           0 :     break;
     131             :   case CompositableType::IMAGE:
     132           0 :     if (gfxVars::UseWebRender()) {
     133           0 :       result = new WebRenderImageHost(aTextureInfo);
     134             :     } else {
     135           0 :       result = new ImageHost(aTextureInfo);
     136             :     }
     137           0 :     break;
     138             :   case CompositableType::CONTENT_SINGLE:
     139           0 :     if (gfxVars::UseWebRender()) {
     140           0 :       result = new WebRenderImageHost(aTextureInfo);
     141             :     } else {
     142           0 :       result = new ContentHostSingleBuffered(aTextureInfo);
     143             :     }
     144           0 :     break;
     145             :   case CompositableType::CONTENT_DOUBLE:
     146          22 :     MOZ_ASSERT(!gfxVars::UseWebRender());
     147          22 :     result = new ContentHostDoubleBuffered(aTextureInfo);
     148          22 :     break;
     149             :   default:
     150           0 :     NS_ERROR("Unknown CompositableType");
     151             :   }
     152          44 :   return result.forget();
     153             : }
     154             : 
     155             : void
     156           0 : CompositableHost::DumpTextureHost(std::stringstream& aStream, TextureHost* aTexture)
     157             : {
     158           0 :   if (!aTexture) {
     159           0 :     return;
     160             :   }
     161           0 :   RefPtr<gfx::DataSourceSurface> dSurf = aTexture->GetAsSurface();
     162           0 :   if (!dSurf) {
     163           0 :     return;
     164             :   }
     165           0 :   aStream << gfxUtils::GetAsDataURI(dSurf).get();
     166             : }
     167             : 
     168             : HostLayerManager*
     169           0 : CompositableHost::GetLayerManager() const
     170             : {
     171           0 :   if (!mLayer || !mLayer->Manager()) {
     172           0 :     return nullptr;
     173             :   }
     174           0 :   return mLayer->Manager()->AsHostLayerManager();
     175             : }
     176             : 
     177             : TextureSourceProvider*
     178         122 : CompositableHost::GetTextureSourceProvider() const
     179             : {
     180         122 :   return mTextureSourceProvider;
     181             : }
     182             : 
     183             : } // namespace layers
     184             : } // namespace mozilla

Generated by: LCOV version 1.13