diff options
author | Daniel Robertson <danlrobertson89@gmail.com> | 2015-08-14 21:35:00 -0400 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2015-08-16 18:30:15 +0000 |
commit | 720cea21f352933fa5d36d4b6faff11799c604f2 (patch) | |
tree | 83d51495c3b59d0bce6be3f3d17d1905ea36bdd8 /canvas | |
parent | Fix tdf#87889 and tdf#92535, vertical align issue when docgrid enable. (diff) | |
download | core-720cea21f352933fa5d36d4b6faff11799c604f2.tar.gz core-720cea21f352933fa5d36d4b6faff11799c604f2.zip |
canvas: replace for_each with range-based for-loop
Replace ::std::for_each for a more readable range-based for loop in
cases in which the function object to be applied by for_each is more
readable as the body of a for loop.
Change-Id: I5ea0f6a464855b8cc8af38f211bb784dd91eca0d
Reviewed-on: https://gerrit.libreoffice.org/17775
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'canvas')
-rw-r--r-- | canvas/source/directx/dx_spritecanvashelper.cxx | 69 | ||||
-rw-r--r-- | canvas/source/opengl/ogl_canvashelper.cxx | 5 | ||||
-rw-r--r-- | canvas/source/opengl/ogl_spritedevicehelper.cxx | 5 | ||||
-rw-r--r-- | canvas/source/vcl/spritecanvashelper.cxx | 146 |
4 files changed, 83 insertions, 142 deletions
diff --git a/canvas/source/directx/dx_spritecanvashelper.cxx b/canvas/source/directx/dx_spritecanvashelper.cxx index 9508fc7bbd0b..ff2be01a0bd5 100644 --- a/canvas/source/directx/dx_spritecanvashelper.cxx +++ b/canvas/source/directx/dx_spritecanvashelper.cxx @@ -19,7 +19,6 @@ #include <sal/config.h> -#include <boost/bind.hpp> #include <boost/cast.hpp> #include <basegfx/range/b2drectangle.hxx> @@ -59,28 +58,6 @@ namespace dxcanvas ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw(); } - - void spriteRedrawStub( const ::canvas::Sprite::Reference& rSprite ) - { - if( rSprite.is() ) - { - // downcast to derived dxcanvas::Sprite interface, which - // provides the actual redraw methods. - ::boost::polymorphic_downcast< Sprite* >( - rSprite.get() )->redraw(); - } - } - - void spriteRedrawStub2( const ::canvas::SpriteRedrawManager::AreaComponent& rComponent ) - { - if( rComponent.second.getSprite().is() ) - { - // downcast to derived dxcanvas::Sprite interface, which - // provides the actual redraw methods. - ::boost::polymorphic_downcast< Sprite* >( - rComponent.second.getSprite().get() )->redraw(); - } - } } SpriteCanvasHelper::SpriteCanvasHelper() : @@ -273,9 +250,17 @@ namespace dxcanvas // the full sprite area, anyway. But at least optimized in the // sense that unnecessary background paints behind the sprites // are avoided. - ::std::for_each( rUpdateArea.maComponentList.begin(), - rUpdateArea.maComponentList.end(), - &spriteRedrawStub2 ); + for( const auto& rComponent : rUpdateArea.maComponentList ) + { + const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() ); + + if( rSprite.is() ) + { + // downcast to derived dxcanvas::Sprite interface, which + // provides the actual redraw methods. + ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw(); + } + } // repaint uncovered areas from backbuffer - take the // _rounded_ rectangles from above, to have the update @@ -284,12 +269,8 @@ namespace dxcanvas ::basegfx::computeSetDifference( aUncoveredAreas, rUpdateArea.maTotalBounds, ::basegfx::B2DRange( rDestRect ) ); - ::std::for_each( aUncoveredAreas.begin(), - aUncoveredAreas.end(), - ::boost::bind( &repaintBackground, - _1, - ::boost::cref(maScrapRect), - ::boost::cref(mpBackBuffer) ) ); + for( const auto& rUpdateArea : aUncoveredAreas ) + repaintBackground( rUpdateArea, maScrapRect, mpBackBuffer ); // TODO(E1): Use numeric_cast to catch overflow here ::basegfx::B2IRange aActualArea( 0, 0, @@ -311,9 +292,15 @@ namespace dxcanvas // TODO(P2): optimize this by truly rendering to the front // buffer. Currently, we've the 3D device only for the back // buffer. - ::std::for_each( rSortedUpdateSprites.begin(), - rSortedUpdateSprites.end(), - &spriteRedrawStub ); + for( const auto& rSprite : rSortedUpdateSprites ) + { + if( rSprite.is() ) + { + // downcast to derived dxcanvas::Sprite interface, which + // provides the actual redraw methods. + ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw(); + } + } // TODO(E1): Use numeric_cast to catch overflow here ::basegfx::B2IRange aActualArea( 0, 0, @@ -347,9 +334,15 @@ namespace dxcanvas // paint sprite // ============ - ::std::for_each( rSortedUpdateSprites.begin(), - rSortedUpdateSprites.end(), - &spriteRedrawStub ); + for( const auto& rSprite : rSortedUpdateSprites ) + { + if( rSprite.is() ) + { + // downcast to derived dxcanvas::Sprite interface, which + // provides the actual redraw methods. + ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw(); + } + } // add given update area to the 'blit to foreground' rect maUpdateRect.expand( aActualArea ); diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx index 4ecf9914174b..1534f7c3b10a 100644 --- a/canvas/source/opengl/ogl_canvashelper.cxx +++ b/canvas/source/opengl/ogl_canvashelper.cxx @@ -800,9 +800,8 @@ namespace oglcanvas } // own copy, for thread safety - std::for_each(rAct.maPolyPolys.begin(), - rAct.maPolyPolys.end(), - ::boost::mem_fn(&::basegfx::B2DPolyPolygon::makeUnique)); + for( auto& rPoly : rAct.maPolyPolys ) + rPoly.makeUnique(); rAct.maFunction = &lcl_fillPolyPolygon; } diff --git a/canvas/source/opengl/ogl_spritedevicehelper.cxx b/canvas/source/opengl/ogl_spritedevicehelper.cxx index e5da0f23d1a4..3c58b4051bb5 100644 --- a/canvas/source/opengl/ogl_spritedevicehelper.cxx +++ b/canvas/source/opengl/ogl_spritedevicehelper.cxx @@ -293,9 +293,8 @@ namespace oglcanvas std::sort(aSprites.begin(), aSprites.end(), SpriteComparator()); - std::for_each(aSprites.begin(), - aSprites.end(), - std::mem_fn(&CanvasCustomSprite::renderSprite)); + for( const auto& rSprite : aSprites ) + rSprite->renderSprite(); // frame counter, other info diff --git a/canvas/source/vcl/spritecanvashelper.cxx b/canvas/source/vcl/spritecanvashelper.cxx index 00ba17541b3b..fd4bb1d6bf68 100644 --- a/canvas/source/vcl/spritecanvashelper.cxx +++ b/canvas/source/vcl/spritecanvashelper.cxx @@ -19,7 +19,6 @@ #include <sal/config.h> -#include <boost/bind.hpp> #include <boost/cast.hpp> #include <basegfx/range/b2drectangle.hxx> @@ -99,63 +98,6 @@ namespace vclcanvas // frontbuffer } - /** Repaint sprite at original position - - Used for opaque updates, which render directly to the - front buffer. - */ - void spriteRedrawStub( OutputDevice& rOutDev, - const ::canvas::Sprite::Reference& rSprite ) - { - if( rSprite.is() ) - { - ::boost::polymorphic_downcast< Sprite* >( - rSprite.get() )->redraw( rOutDev, - false ); - } - } - - /** Repaint sprite at given position - - Used for generic update, which renders into vdev of - adapted size. - */ - void spriteRedrawStub2( OutputDevice& rOutDev, - const ::basegfx::B2DPoint& rOutPos, - const ::canvas::Sprite::Reference& rSprite ) - { - if( rSprite.is() ) - { - Sprite* pSprite = ::boost::polymorphic_downcast< Sprite* >( - rSprite.get() ); - - // calc relative sprite position in rUpdateArea (which - // need not be the whole screen!) - const ::basegfx::B2DPoint& rSpriteScreenPos( pSprite->getPosPixel() ); - const ::basegfx::B2DPoint& rSpriteRenderPos( rSpriteScreenPos - rOutPos ); - - pSprite->redraw( rOutDev, rSpriteRenderPos, true ); - } - } - - /** Repaint sprite at original position - - Used for opaque updates from scrollUpdate(), which render - directly to the front buffer. - */ - void spriteRedrawStub3( OutputDevice& rOutDev, - const ::canvas::SpriteRedrawManager::AreaComponent& rComponent ) - { - const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() ); - - if( rSprite.is() ) - { - ::boost::polymorphic_downcast< Sprite* >( - rSprite.get() )->redraw( rOutDev, - false ); - } - } - void renderInfoText( OutputDevice& rOutDev, const OUString& rStr, const Point& rPos ) @@ -320,11 +262,11 @@ namespace vclcanvas // repaint all active sprites on top of background into // VDev. + OutputDevice& rTmpOutDev( *maVDev.get() ); mpRedrawManager->forEachSprite( - ::boost::bind( - &spriteRedraw, - ::boost::ref( *maVDev.get() ), - _1 ) ); + [&rTmpOutDev]( const ::canvas::Sprite::Reference& rSprite ) + { spriteRedraw( rTmpOutDev, rSprite ); } + ); // flush to screen rOutDev.EnableMapMode( false ); @@ -433,12 +375,15 @@ namespace vclcanvas // opaque sprite content) // repaint all affected sprites directly to output device - ::std::for_each( rUpdateArea.maComponentList.begin(), - rUpdateArea.maComponentList.end(), - ::boost::bind( - &spriteRedrawStub3, - ::boost::ref( rOutDev ), - _1 ) ); + for( const auto rComponent : rUpdateArea.maComponentList ) + { + const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() ); + + if( rSprite.is() ) + ::boost::polymorphic_downcast< Sprite* >( + rSprite.get() )->redraw( rOutDev, + false ); + } } else { @@ -459,12 +404,11 @@ namespace vclcanvas // clip here, since we're only repainting _parts_ of the // sprite rOutDev.Push( PushFlags::CLIPREGION ); - ::std::for_each( aUnscrollableAreas.begin(), - aUnscrollableAreas.end(), - ::boost::bind( &opaqueUpdateSpriteArea, - ::boost::cref(aFirst->second.getSprite()), - ::boost::ref(rOutDev), - _1 ) ); + + for( const auto& rArea : aUnscrollableAreas ) + opaqueUpdateSpriteArea( aFirst->second.getSprite(), + rOutDev, rArea ); + rOutDev.Pop(); } @@ -475,12 +419,9 @@ namespace vclcanvas ::basegfx::computeSetDifference( aUncoveredAreas, rUpdateArea.maTotalBounds, ::basegfx::B2DRange( rDestRect ) ); - ::std::for_each( aUncoveredAreas.begin(), - aUncoveredAreas.end(), - ::boost::bind( &repaintBackground, - ::boost::ref(rOutDev), - ::boost::ref(rBackOutDev), - _1 ) ); + + for( const auto& rArea : aUncoveredAreas ) + repaintBackground( rOutDev, rBackOutDev, rArea ); } void SpriteCanvasHelper::opaqueUpdate( SAL_UNUSED_PARAMETER const ::basegfx::B2DRange&, @@ -501,12 +442,13 @@ namespace vclcanvas // and the update will be constrained to that rect. // repaint all affected sprites directly to output device - ::std::for_each( rSortedUpdateSprites.begin(), - rSortedUpdateSprites.end(), - ::boost::bind( - &spriteRedrawStub, - ::boost::ref( rOutDev ), - _1 ) ); + for( const auto& rSprite : rSortedUpdateSprites ) + { + if( rSprite.is() ) + ::boost::polymorphic_downcast< Sprite* >( + rSprite.get() )->redraw( rOutDev, + false ); + } } void SpriteCanvasHelper::genericUpdate( const ::basegfx::B2DRange& rRequestedArea, @@ -578,13 +520,22 @@ namespace vclcanvas // repaint all affected sprites on top of background into // VDev. - ::std::for_each( rSortedUpdateSprites.begin(), - rSortedUpdateSprites.end(), - ::boost::bind( &spriteRedrawStub2, - ::boost::ref( *maVDev.get() ), - vcl::unotools::b2DPointFromPoint( - aOutputPosition), - _1 ) ); + for( const auto& rSprite : rSortedUpdateSprites ) + { + if( rSprite.is() ) + { + Sprite* pSprite = ::boost::polymorphic_downcast< Sprite* >( rSprite.get() ); + + // calc relative sprite position in rUpdateArea (which + // need not be the whole screen!) + const ::basegfx::B2DPoint& rSpriteScreenPos( pSprite->getPosPixel() ); + const ::basegfx::B2DPoint& rSpriteRenderPos( + rSpriteScreenPos - vcl::unotools::b2DPointFromPoint(aOutputPosition) + ); + + pSprite->redraw( *maVDev.get(), rSpriteRenderPos, true ); + } + } // flush to screen rOutDev.EnableMapMode( false ); @@ -673,11 +624,10 @@ namespace vclcanvas double nPixel(0.0); // accumulate pixel count for each sprite into fCount - mpRedrawManager->forEachSprite( ::boost::bind( - makeAdder(nPixel,1.0), - ::boost::bind( - &calcNumPixel, - _1 ) ) ); + mpRedrawManager->forEachSprite( + [&nPixel]( const ::canvas::Sprite::Reference& rSprite ) + { makeAdder( nPixel, 1.0 )( calcNumPixel(rSprite) ); } + ); static const int NUM_VIRDEV(2); static const int BYTES_PER_PIXEL(3); |