LCOV - code coverage report
Current view: top level - slideshow/source/engine/slide - layer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 94 1.1 %
Date: 2014-11-03 Functions: 2 20 10.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : // must be first
      22             : #include <canvas/debug.hxx>
      23             : 
      24             : #include <basegfx/range/b2drange.hxx>
      25             : #include <basegfx/range/b1drange.hxx>
      26             : #include <basegfx/range/b2dpolyrange.hxx>
      27             : #include <basegfx/matrix/b2dhommatrix.hxx>
      28             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      29             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      30             : #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
      31             : 
      32             : #include "layer.hxx"
      33             : 
      34             : #include <boost/bind.hpp>
      35             : 
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : namespace slideshow
      40             : {
      41             :     namespace internal
      42             :     {
      43           0 :         Layer::Layer( const basegfx::B2DRange& rMaxLayerBounds,
      44             :                       Dummy                     ) :
      45             :             maViewEntries(),
      46             :             maBounds(),
      47             :             maNewBounds(),
      48             :             maMaxBounds( rMaxLayerBounds ),
      49             :             mbBoundsDirty(false),
      50             :             mbBackgroundLayer(true),
      51           0 :             mbClipSet(false)
      52             :         {
      53           0 :         }
      54             : 
      55           0 :         Layer::Layer( const basegfx::B2DRange& rMaxLayerBounds ) :
      56             :             maViewEntries(),
      57             :             maBounds(),
      58             :             maNewBounds(),
      59             :             maMaxBounds( rMaxLayerBounds ),
      60             :             mbBoundsDirty(false),
      61             :             mbBackgroundLayer(false),
      62           0 :             mbClipSet(false)
      63             :         {
      64           0 :         }
      65             : 
      66           0 :         ViewLayerSharedPtr Layer::addView( const ViewSharedPtr& rNewView )
      67             :         {
      68             :             OSL_ASSERT( rNewView );
      69             : 
      70           0 :             ViewEntryVector::iterator aIter;
      71           0 :             const ViewEntryVector::iterator aEnd( maViewEntries.end() );
      72           0 :             if( (aIter=std::find_if( maViewEntries.begin(),
      73             :                                      aEnd,
      74             :                                      boost::bind<bool>(
      75             :                                          std::equal_to< ViewSharedPtr >(),
      76             :                                          boost::bind( &ViewEntry::getView, _1 ),
      77           0 :                                          boost::cref( rNewView )))) != aEnd )
      78             :             {
      79             :                 // already added - just return existing layer
      80           0 :                 return aIter->mpViewLayer;
      81             : 
      82             :             }
      83             : 
      84             :             // not yet added - create new view layer
      85           0 :             ViewLayerSharedPtr pNewLayer;
      86           0 :             if( mbBackgroundLayer )
      87           0 :                 pNewLayer = rNewView;
      88             :             else
      89           0 :                 pNewLayer = rNewView->createViewLayer(maBounds);
      90             : 
      91             :             // add to local list
      92             :             maViewEntries.push_back(
      93             :                 ViewEntry( rNewView,
      94           0 :                            pNewLayer ));
      95             : 
      96           0 :             return maViewEntries.back().mpViewLayer;
      97             :         }
      98             : 
      99           0 :         ViewLayerSharedPtr Layer::removeView( const ViewSharedPtr& rView )
     100             :         {
     101             :             OSL_ASSERT( rView );
     102             : 
     103           0 :             ViewEntryVector::iterator       aIter;
     104           0 :             const ViewEntryVector::iterator aEnd( maViewEntries.end() );
     105           0 :             if( (aIter=std::find_if( maViewEntries.begin(),
     106             :                                        aEnd,
     107             :                                        boost::bind<bool>(
     108             :                                            std::equal_to< ViewSharedPtr >(),
     109             :                                            boost::bind( &ViewEntry::getView, _1 ),
     110           0 :                                            boost::cref( rView )))) == aEnd )
     111             :             {
     112             :                 // View was not added/is already removed
     113           0 :                 return ViewLayerSharedPtr();
     114             :             }
     115             : 
     116             :             OSL_ENSURE( std::count_if( maViewEntries.begin(),
     117             :                                        aEnd,
     118             :                                        boost::bind<bool>(
     119             :                                            std::equal_to< ViewSharedPtr >(),
     120             :                                            boost::bind( &ViewEntry::getView, _1 ),
     121             :                                            boost::cref( rView ))) == 1,
     122             :                         "Layer::removeView(): view added multiple times" );
     123             : 
     124           0 :             ViewLayerSharedPtr pRet( aIter->mpViewLayer );
     125           0 :             maViewEntries.erase(aIter);
     126             : 
     127           0 :             return pRet;
     128             :         }
     129             : 
     130           0 :         void Layer::setShapeViews( ShapeSharedPtr const& rShape ) const
     131             :         {
     132           0 :             rShape->clearAllViewLayers();
     133             : 
     134             :             std::for_each( maViewEntries.begin(),
     135             :                            maViewEntries.end(),
     136             :                            boost::bind(&Shape::addViewLayer,
     137             :                                        boost::cref(rShape),
     138             :                                        boost::bind(&ViewEntry::getViewLayer,
     139             :                                                    _1),
     140           0 :                                        false ));
     141           0 :         }
     142             : 
     143           0 :         void Layer::setPriority( const ::basegfx::B1DRange& rPrioRange )
     144             :         {
     145           0 :             if( !mbBackgroundLayer )
     146             :             {
     147             :                 std::for_each( maViewEntries.begin(),
     148             :                                maViewEntries.end(),
     149             :                                boost::bind( &ViewLayer::setPriority,
     150             :                                             boost::bind( &ViewEntry::getViewLayer,
     151             :                                                          _1 ),
     152           0 :                                             boost::cref(rPrioRange)));
     153             :             }
     154           0 :         }
     155             : 
     156           0 :         void Layer::addUpdateRange( ::basegfx::B2DRange const& rUpdateRange )
     157             :         {
     158             :             // TODO(Q1): move this to B2DMultiRange
     159           0 :             if( !rUpdateRange.isEmpty() )
     160             :                 maUpdateAreas.appendElement( rUpdateRange,
     161           0 :                                              basegfx::ORIENTATION_POSITIVE );
     162           0 :         }
     163             : 
     164           0 :         void Layer::updateBounds( ShapeSharedPtr const& rShape )
     165             :         {
     166           0 :             if( !mbBackgroundLayer )
     167             :             {
     168           0 :                 if( !mbBoundsDirty )
     169           0 :                     maNewBounds.reset();
     170             : 
     171           0 :                 maNewBounds.expand( rShape->getUpdateArea() );
     172             :             }
     173             : 
     174           0 :             mbBoundsDirty = true;
     175           0 :         }
     176             : 
     177           0 :         bool Layer::commitBounds()
     178             :         {
     179           0 :             mbBoundsDirty = false;
     180             : 
     181           0 :             if( mbBackgroundLayer )
     182           0 :                 return false;
     183             : 
     184           0 :             if( maNewBounds == maBounds )
     185           0 :                 return false;
     186             : 
     187           0 :             maBounds = maNewBounds;
     188           0 :             if( std::count_if( maViewEntries.begin(),
     189             :                                maViewEntries.end(),
     190             :                                boost::bind( &ViewLayer::resize,
     191             :                                             boost::bind( &ViewEntry::getViewLayer,
     192             :                                                          _1 ),
     193           0 :                                             boost::cref(maBounds)) ) == 0 )
     194             :             {
     195           0 :                 return false;
     196             :             }
     197             : 
     198             :             // layer content invalid, update areas have wrong
     199             :             // coordinates/not sensible anymore.
     200           0 :             clearUpdateRanges();
     201             : 
     202           0 :             return true;
     203             :         }
     204             : 
     205           0 :         void Layer::clearUpdateRanges()
     206             :         {
     207           0 :             maUpdateAreas.clear();
     208           0 :         }
     209             : 
     210           0 :         void Layer::clearContent()
     211             :         {
     212             :             // clear content on all view layers
     213             :             std::for_each( maViewEntries.begin(),
     214             :                            maViewEntries.end(),
     215             :                            boost::bind(
     216             :                                &ViewLayer::clearAll,
     217             :                                boost::bind(
     218             :                                    &ViewEntry::getViewLayer,
     219           0 :                                    _1)));
     220             : 
     221             :             // layer content cleared, update areas are not sensible
     222             :             // anymore.
     223           0 :             clearUpdateRanges();
     224           0 :         }
     225             : 
     226             :         class LayerEndUpdate : private boost::noncopyable
     227             :         {
     228             :         public:
     229           0 :             LayerEndUpdate( LayerSharedPtr const& rLayer ) :
     230           0 :                 mpLayer( rLayer )
     231           0 :             {}
     232             : 
     233           0 :             ~LayerEndUpdate() { if(mpLayer) mpLayer->endUpdate(); }
     234             : 
     235             :         private:
     236             :             LayerSharedPtr mpLayer;
     237             :         };
     238             : 
     239           0 :         Layer::EndUpdater Layer::beginUpdate()
     240             :         {
     241           0 :             if( maUpdateAreas.count() )
     242             :             {
     243             :                 // perform proper layer update. That means, setup proper
     244             :                 // clipping, and render each shape that intersects with
     245             :                 // the calculated update area
     246           0 :                 ::basegfx::B2DPolyPolygon aClip( maUpdateAreas.solveCrossovers() );
     247           0 :                 aClip = ::basegfx::tools::stripNeutralPolygons(aClip);
     248           0 :                 aClip = ::basegfx::tools::stripDispensablePolygons(aClip, false);
     249             : 
     250             :                 // actually, if there happen to be shapes with zero
     251             :                 // update area in the maUpdateAreas vector, the
     252             :                 // resulting clip polygon will be empty.
     253           0 :                 if( aClip.count() )
     254             :                 {
     255             :                     // set clip to all view layers
     256             :                     std::for_each( maViewEntries.begin(),
     257             :                                    maViewEntries.end(),
     258             :                                    boost::bind(
     259             :                                        &ViewLayer::setClip,
     260             :                                        boost::bind(
     261             :                                            &ViewEntry::getViewLayer,
     262             :                                            _1),
     263           0 :                                        boost::cref(aClip)));
     264             : 
     265             :                     // clear update area on all view layers
     266             :                     std::for_each( maViewEntries.begin(),
     267             :                                    maViewEntries.end(),
     268             :                                    boost::bind(
     269             :                                        &ViewLayer::clear,
     270             :                                        boost::bind(
     271             :                                            &ViewEntry::getViewLayer,
     272           0 :                                            _1)));
     273             : 
     274           0 :                     mbClipSet = true;
     275           0 :                 }
     276             :             }
     277             : 
     278           0 :             return EndUpdater(new LayerEndUpdate(shared_from_this()));
     279             :         }
     280             : 
     281           0 :         void Layer::endUpdate()
     282             :         {
     283           0 :             if( mbClipSet )
     284             :             {
     285           0 :                 mbClipSet = false;
     286             : 
     287           0 :                 basegfx::B2DPolyPolygon aEmptyClip;
     288             :                 std::for_each( maViewEntries.begin(),
     289             :                                maViewEntries.end(),
     290             :                                boost::bind(
     291             :                                    &ViewLayer::setClip,
     292             :                                    boost::bind(
     293             :                                        &ViewEntry::getViewLayer,
     294             :                                        _1),
     295           0 :                                    boost::cref(aEmptyClip)));
     296             :             }
     297             : 
     298           0 :             clearUpdateRanges();
     299           0 :         }
     300             : 
     301           0 :         bool Layer::isInsideUpdateArea( ShapeSharedPtr const& rShape ) const
     302             :         {
     303           0 :             return maUpdateAreas.overlaps( rShape->getUpdateArea() );
     304             :         }
     305             : 
     306           0 :         LayerSharedPtr Layer::createBackgroundLayer( const basegfx::B2DRange& rMaxLayerBounds )
     307             :         {
     308             :             return LayerSharedPtr(new Layer( rMaxLayerBounds,
     309           0 :                                              BackgroundLayer ));
     310             :         }
     311             : 
     312           0 :         LayerSharedPtr Layer::createLayer( const basegfx::B2DRange& rMaxLayerBounds )
     313             :         {
     314           0 :             return LayerSharedPtr( new Layer( rMaxLayerBounds ) );
     315             :         }
     316             : 
     317             :     }
     318           6 : }
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10