LCOV - code coverage report
Current view: top level - slideshow/source/engine/slide - layer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 94 0.0 %
Date: 2014-04-14 Functions: 0 20 0.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             :             void dismiss() { mpLayer.reset(); }
     236             : 
     237             :         private:
     238             :             LayerSharedPtr mpLayer;
     239             :         };
     240             : 
     241           0 :         Layer::EndUpdater Layer::beginUpdate()
     242             :         {
     243           0 :             if( maUpdateAreas.count() )
     244             :             {
     245             :                 // perform proper layer update. That means, setup proper
     246             :                 // clipping, and render each shape that intersects with
     247             :                 // the calculated update area
     248           0 :                 ::basegfx::B2DPolyPolygon aClip( maUpdateAreas.solveCrossovers() );
     249           0 :                 aClip = ::basegfx::tools::stripNeutralPolygons(aClip);
     250           0 :                 aClip = ::basegfx::tools::stripDispensablePolygons(aClip, false);
     251             : 
     252             :                 // actually, if there happen to be shapes with zero
     253             :                 // update area in the maUpdateAreas vector, the
     254             :                 // resulting clip polygon will be empty.
     255           0 :                 if( aClip.count() )
     256             :                 {
     257             :                     // set clip to all view layers
     258             :                     std::for_each( maViewEntries.begin(),
     259             :                                    maViewEntries.end(),
     260             :                                    boost::bind(
     261             :                                        &ViewLayer::setClip,
     262             :                                        boost::bind(
     263             :                                            &ViewEntry::getViewLayer,
     264             :                                            _1),
     265           0 :                                        boost::cref(aClip)));
     266             : 
     267             :                     // clear update area on all view layers
     268             :                     std::for_each( maViewEntries.begin(),
     269             :                                    maViewEntries.end(),
     270             :                                    boost::bind(
     271             :                                        &ViewLayer::clear,
     272             :                                        boost::bind(
     273             :                                            &ViewEntry::getViewLayer,
     274           0 :                                            _1)));
     275             : 
     276           0 :                     mbClipSet = true;
     277           0 :                 }
     278             :             }
     279             : 
     280           0 :             return EndUpdater(new LayerEndUpdate(shared_from_this()));
     281             :         }
     282             : 
     283           0 :         void Layer::endUpdate()
     284             :         {
     285           0 :             if( mbClipSet )
     286             :             {
     287           0 :                 mbClipSet = false;
     288             : 
     289           0 :                 basegfx::B2DPolyPolygon aEmptyClip;
     290             :                 std::for_each( maViewEntries.begin(),
     291             :                                maViewEntries.end(),
     292             :                                boost::bind(
     293             :                                    &ViewLayer::setClip,
     294             :                                    boost::bind(
     295             :                                        &ViewEntry::getViewLayer,
     296             :                                        _1),
     297           0 :                                    boost::cref(aEmptyClip)));
     298             :             }
     299             : 
     300           0 :             clearUpdateRanges();
     301           0 :         }
     302             : 
     303           0 :         bool Layer::isInsideUpdateArea( ShapeSharedPtr const& rShape ) const
     304             :         {
     305           0 :             return maUpdateAreas.overlaps( rShape->getUpdateArea() );
     306             :         }
     307             : 
     308           0 :         LayerSharedPtr Layer::createBackgroundLayer( const basegfx::B2DRange& rMaxLayerBounds )
     309             :         {
     310             :             return LayerSharedPtr(new Layer( rMaxLayerBounds,
     311           0 :                                              BackgroundLayer ));
     312             :         }
     313             : 
     314           0 :         LayerSharedPtr Layer::createLayer( const basegfx::B2DRange& rMaxLayerBounds )
     315             :         {
     316           0 :             return LayerSharedPtr( new Layer( rMaxLayerBounds ) );
     317             :         }
     318             : 
     319             :     }
     320           0 : }
     321             : 
     322             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10