LCOV - code coverage report
Current view: top level - gfx/layers/composite - PaintedLayerComposite.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 51 75 68.0 %
Date: 2017-07-14 16:53:18 Functions: 12 15 80.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             : #include "PaintedLayerComposite.h"
       7             : #include "CompositableHost.h"           // for TiledLayerProperties, etc
       8             : #include "FrameMetrics.h"               // for FrameMetrics
       9             : #include "Units.h"                      // for CSSRect, LayerPixel, etc
      10             : #include "gfxEnv.h"                     // for gfxEnv
      11             : #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
      12             : #include "mozilla/gfx/Matrix.h"         // for Matrix4x4
      13             : #include "mozilla/gfx/Point.h"          // for Point
      14             : #include "mozilla/gfx/Polygon.h"        // for Polygon
      15             : #include "mozilla/gfx/Rect.h"           // for RoundedToInt, Rect
      16             : #include "mozilla/gfx/Types.h"          // for SamplingFilter::LINEAR
      17             : #include "mozilla/layers/Compositor.h"  // for Compositor
      18             : #include "mozilla/layers/ContentHost.h"  // for ContentHost
      19             : #include "mozilla/layers/Effects.h"     // for EffectChain
      20             : #include "mozilla/mozalloc.h"           // for operator delete
      21             : #include "nsAString.h"
      22             : #include "mozilla/RefPtr.h"                   // for nsRefPtr
      23             : #include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
      24             : #include "nsMathUtils.h"                // for NS_lround
      25             : #include "nsString.h"                   // for nsAutoCString
      26             : #include "TextRenderer.h"
      27             : #include "GeckoProfiler.h"
      28             : 
      29             : namespace mozilla {
      30             : namespace layers {
      31             : 
      32          22 : PaintedLayerComposite::PaintedLayerComposite(LayerManagerComposite *aManager)
      33             :   : PaintedLayer(aManager, nullptr)
      34             :   , LayerComposite(aManager)
      35          22 :   , mBuffer(nullptr)
      36             : {
      37          22 :   MOZ_COUNT_CTOR(PaintedLayerComposite);
      38          22 :   mImplData = static_cast<LayerComposite*>(this);
      39          22 : }
      40             : 
      41          57 : PaintedLayerComposite::~PaintedLayerComposite()
      42             : {
      43          19 :   MOZ_COUNT_DTOR(PaintedLayerComposite);
      44          19 :   CleanupResources();
      45          57 : }
      46             : 
      47             : bool
      48          22 : PaintedLayerComposite::SetCompositableHost(CompositableHost* aHost)
      49             : {
      50          22 :   switch (aHost->GetType()) {
      51             :     case CompositableType::CONTENT_TILED:
      52             :     case CompositableType::CONTENT_SINGLE:
      53             :     case CompositableType::CONTENT_DOUBLE:
      54          22 :       mBuffer = static_cast<ContentHost*>(aHost);
      55          22 :       return true;
      56             :     default:
      57           0 :       return false;
      58             :   }
      59             : }
      60             : 
      61             : void
      62          19 : PaintedLayerComposite::Disconnect()
      63             : {
      64          19 :   Destroy();
      65          19 : }
      66             : 
      67             : void
      68          19 : PaintedLayerComposite::Destroy()
      69             : {
      70          19 :   if (!mDestroyed) {
      71          19 :     CleanupResources();
      72          19 :     mDestroyed = true;
      73             :   }
      74          19 : }
      75             : 
      76             : Layer*
      77         746 : PaintedLayerComposite::GetLayer()
      78             : {
      79         746 :   return this;
      80             : }
      81             : 
      82             : void
      83           0 : PaintedLayerComposite::SetLayerManager(HostLayerManager* aManager)
      84             : {
      85           0 :   LayerComposite::SetLayerManager(aManager);
      86           0 :   mManager = aManager;
      87           0 :   if (mBuffer && mCompositor) {
      88           0 :     mBuffer->SetTextureSourceProvider(mCompositor);
      89             :   }
      90           0 : }
      91             : 
      92             : void
      93          56 : PaintedLayerComposite::RenderLayer(const gfx::IntRect& aClipRect,
      94             :                                    const Maybe<gfx::Polygon>& aGeometry)
      95             : {
      96          56 :   if (!mBuffer || !mBuffer->IsAttached()) {
      97           0 :     return;
      98             :   }
      99         112 :   AUTO_PROFILER_LABEL("PaintedLayerComposite::RenderLayer", GRAPHICS);
     100             : 
     101          56 :   Compositor* compositor = mCompositeManager->GetCompositor();
     102             : 
     103          56 :   MOZ_ASSERT(mBuffer->GetTextureSourceProvider() == compositor &&
     104             :              mBuffer->GetLayer() == this,
     105             :              "buffer is corrupted");
     106             : 
     107         112 :   const nsIntRegion visibleRegion = GetLocalVisibleRegion().ToUnknownRegion();
     108             : 
     109             : #ifdef MOZ_DUMP_PAINTING
     110          56 :   if (gfxEnv::DumpCompositorTextures()) {
     111           0 :     RefPtr<gfx::DataSourceSurface> surf = mBuffer->GetAsSurface();
     112           0 :     if (surf) {
     113           0 :       WriteSnapshotToDumpFile(this, surf);
     114             :     }
     115             :   }
     116             : #endif
     117             : 
     118          56 :   RenderWithAllMasks(this, compositor, aClipRect,
     119             :                      [&](EffectChain& effectChain,
     120          56 :                      const gfx::IntRect& clipRect) {
     121         336 :     mBuffer->SetPaintWillResample(MayResample());
     122             : 
     123         336 :     mBuffer->Composite(compositor, this, effectChain, GetEffectiveOpacity(),
     124             :                        GetEffectiveTransform(), GetSamplingFilter(),
     125         112 :                        clipRect, &visibleRegion, aGeometry);
     126         168 :   });
     127             : 
     128          56 :   mBuffer->BumpFlashCounter();
     129             : 
     130          56 :   compositor->MakeCurrent();
     131             : }
     132             : 
     133             : CompositableHost*
     134          96 : PaintedLayerComposite::GetCompositableHost()
     135             : {
     136          96 :   if (mBuffer && mBuffer->IsAttached()) {
     137          96 :     return mBuffer.get();
     138             :   }
     139             : 
     140           0 :   return nullptr;
     141             : }
     142             : 
     143             : void
     144          38 : PaintedLayerComposite::CleanupResources()
     145             : {
     146          38 :   if (mBuffer) {
     147          19 :     mBuffer->Detach(this);
     148             :   }
     149          38 :   mBuffer = nullptr;
     150          38 : }
     151             : 
     152             : void
     153           0 : PaintedLayerComposite::GenEffectChain(EffectChain& aEffect)
     154             : {
     155           0 :   aEffect.mLayerRef = this;
     156           0 :   aEffect.mPrimaryEffect = mBuffer->GenEffect(GetSamplingFilter());
     157           0 : }
     158             : 
     159             : void
     160           0 : PaintedLayerComposite::PrintInfo(std::stringstream& aStream, const char* aPrefix)
     161             : {
     162           0 :   PaintedLayer::PrintInfo(aStream, aPrefix);
     163           0 :   if (mBuffer && mBuffer->IsAttached()) {
     164           0 :     aStream << "\n";
     165           0 :     nsAutoCString pfx(aPrefix);
     166           0 :     pfx += "  ";
     167           0 :     mBuffer->PrintInfo(aStream, pfx.get());
     168             :   }
     169           0 : }
     170             : 
     171             : const gfx::TiledIntRegion&
     172          67 : PaintedLayerComposite::GetInvalidRegion()
     173             : {
     174          67 :   if (mBuffer) {
     175         134 :     nsIntRegion region = mInvalidRegion.GetRegion();
     176          67 :     mBuffer->AddAnimationInvalidation(region);
     177             :   }
     178          67 :   return mInvalidRegion;
     179             : }
     180             : 
     181             : 
     182             : } // namespace layers
     183             : } // namespace mozilla

Generated by: LCOV version 1.13