Kaydet (Commit) b7f4940c authored tarafından Daniel Robertson's avatar Daniel Robertson Kaydeden (comit) Thorsten Behrens

canvas: replace while loops with range-based for

Change-Id: Ide16bee666cf4df41646f9336a585e22a7fe53bd
Reviewed-on: https://gerrit.libreoffice.org/18131Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 49cb81b4
...@@ -102,11 +102,9 @@ namespace dxcanvas ...@@ -102,11 +102,9 @@ namespace dxcanvas
uno::Sequence< sal_Int32 > aValues( sizeof(DeviceInfo)/sizeof(sal_Int32)*maValues.size() ); uno::Sequence< sal_Int32 > aValues( sizeof(DeviceInfo)/sizeof(sal_Int32)*maValues.size() );
sal_Int32* pValues = aValues.getArray(); sal_Int32* pValues = aValues.getArray();
ValueSet::const_iterator aIter( maValues.begin() ); for( const auto& rValueSet : maValues )
const ValueSet::const_iterator aEnd( maValues.end() );
while( aIter != aEnd )
{ {
const DeviceInfo& rInfo( *aIter ); const DeviceInfo& rInfo( rValueSet );
*pValues++ = rInfo.nVendorId; *pValues++ = rInfo.nVendorId;
*pValues++ = rInfo.nDeviceId; *pValues++ = rInfo.nDeviceId;
*pValues++ = rInfo.nDeviceSubSysId; *pValues++ = rInfo.nDeviceSubSysId;
...@@ -115,7 +113,6 @@ namespace dxcanvas ...@@ -115,7 +113,6 @@ namespace dxcanvas
*pValues++ = rInfo.nDriverVersion; *pValues++ = rInfo.nDriverVersion;
*pValues++ = rInfo.nDriverSubVersion; *pValues++ = rInfo.nDriverSubVersion;
*pValues++ = rInfo.nDriverBuildId; *pValues++ = rInfo.nDriverBuildId;
++aIter;
} }
uno::Sequence< uno::Any > aValue(1); uno::Sequence< uno::Any > aValue(1);
......
...@@ -139,10 +139,8 @@ namespace oglcanvas ...@@ -139,10 +139,8 @@ namespace oglcanvas
TransformationPreserver aPreserver; TransformationPreserver aPreserver;
setupState(rTransform, eSrcBlend, eDstBlend, rColor); setupState(rTransform, eSrcBlend, eDstBlend, rColor);
::basegfx::B2DPolyPolygonVector::const_iterator aCurr=rPolyPolygons.begin(); for( const auto& rPoly : rPolyPolygons )
const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end(); renderPolyPolygon( rPoly );
while( aCurr != aEnd )
renderPolyPolygon(*aCurr++);
return true; return true;
} }
...@@ -157,12 +155,10 @@ namespace oglcanvas ...@@ -157,12 +155,10 @@ namespace oglcanvas
TransformationPreserver aPreserver; TransformationPreserver aPreserver;
setupState(rTransform, eSrcBlend, eDstBlend, rColor); setupState(rTransform, eSrcBlend, eDstBlend, rColor);
::basegfx::B2DPolyPolygonVector::const_iterator aCurr=rPolyPolygons.begin(); for( const auto& rPoly : rPolyPolygons )
const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end();
while( aCurr != aEnd )
{ {
glBegin(GL_TRIANGLES); glBegin( GL_TRIANGLES );
renderComplexPolyPolygon(*aCurr++); renderComplexPolyPolygon( rPoly );
glEnd(); glEnd();
} }
...@@ -186,10 +182,8 @@ namespace oglcanvas ...@@ -186,10 +182,8 @@ namespace oglcanvas
::basegfx::unotools::homMatrixFromAffineMatrix( aTextureTransform, ::basegfx::unotools::homMatrixFromAffineMatrix( aTextureTransform,
rTexture.AffineTransform ); rTexture.AffineTransform );
::basegfx::B2DRange aBounds; ::basegfx::B2DRange aBounds;
::basegfx::B2DPolyPolygonVector::const_iterator aCurr=rPolyPolygons.begin(); for( const auto& rPoly : rPolyPolygons )
const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end(); aBounds.expand( ::basegfx::tools::getRange( rPoly ) );
while( aCurr != aEnd )
aBounds.expand(::basegfx::tools::getRange(*aCurr++));
aTextureTransform.translate(-aBounds.getMinX(), -aBounds.getMinY()); aTextureTransform.translate(-aBounds.getMinX(), -aBounds.getMinY());
aTextureTransform.scale(1/aBounds.getWidth(), 1/aBounds.getHeight()); aTextureTransform.scale(1/aBounds.getWidth(), 1/aBounds.getHeight());
...@@ -228,11 +222,10 @@ namespace oglcanvas ...@@ -228,11 +222,10 @@ namespace oglcanvas
} }
aCurr=rPolyPolygons.begin(); for( const auto& rPoly : rPolyPolygons )
while( aCurr != aEnd )
{ {
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
renderComplexPolyPolygon(*aCurr++); renderComplexPolyPolygon( rPoly );
glEnd(); glEnd();
} }
...@@ -333,10 +326,8 @@ namespace oglcanvas ...@@ -333,10 +326,8 @@ namespace oglcanvas
::basegfx::unotools::homMatrixFromAffineMatrix( aTextureTransform, ::basegfx::unotools::homMatrixFromAffineMatrix( aTextureTransform,
rTexture.AffineTransform ); rTexture.AffineTransform );
::basegfx::B2DRange aBounds; ::basegfx::B2DRange aBounds;
::basegfx::B2DPolyPolygonVector::const_iterator aCurr=rPolyPolygons.begin(); for( const auto& rPolyPolygon : rPolyPolygons )
const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end(); aBounds.expand( ::basegfx::tools::getRange( rPolyPolygon ) );
while( aCurr != aEnd )
aBounds.expand(::basegfx::tools::getRange(*aCurr++));
aTextureTransform.translate(-aBounds.getMinX(), -aBounds.getMinY()); aTextureTransform.translate(-aBounds.getMinX(), -aBounds.getMinY());
aTextureTransform.scale(1/aBounds.getWidth(), 1/aBounds.getHeight()); aTextureTransform.scale(1/aBounds.getWidth(), 1/aBounds.getHeight());
aTextureTransform.invert(); aTextureTransform.invert();
...@@ -354,11 +345,10 @@ namespace oglcanvas ...@@ -354,11 +345,10 @@ namespace oglcanvas
// blend against fixed vertex color; texture alpha is multiplied in // blend against fixed vertex color; texture alpha is multiplied in
glColor4f(1,1,1,rTexture.Alpha); glColor4f(1,1,1,rTexture.Alpha);
aCurr=rPolyPolygons.begin(); for( const auto& rPolyPolygon : rPolyPolygons )
while( aCurr != aEnd )
{ {
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
renderComplexPolyPolygon(*aCurr++); renderComplexPolyPolygon( rPolyPolygon );
glEnd(); glEnd();
} }
...@@ -973,19 +963,15 @@ namespace oglcanvas ...@@ -973,19 +963,15 @@ namespace oglcanvas
bool CanvasHelper::renderRecordedActions() const bool CanvasHelper::renderRecordedActions() const
{ {
std::vector<Action>::const_iterator aCurr(mpRecordedActions->begin()); for( const auto& rRecordedAction : *mpRecordedActions )
const std::vector<Action>::const_iterator aEnd(mpRecordedActions->end());
while( aCurr != aEnd )
{ {
if( !aCurr->maFunction( *this, if( !rRecordedAction.maFunction( *this,
aCurr->maTransform, rRecordedAction.maTransform,
aCurr->meSrcBlendMode, rRecordedAction.meSrcBlendMode,
aCurr->meDstBlendMode, rRecordedAction.meDstBlendMode,
aCurr->maARGBColor, rRecordedAction.maARGBColor,
aCurr->maPolyPolys ) ) rRecordedAction.maPolyPolys ) )
return false; return false;
++aCurr;
} }
return true; return true;
......
...@@ -37,12 +37,9 @@ namespace oglcanvas ...@@ -37,12 +37,9 @@ namespace oglcanvas
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
// delete all cached textures // delete all cached textures
TextureCacheMapT::const_iterator aCurr=maCache.begin(); for( const auto& rCache : maCache )
const TextureCacheMapT::const_iterator aEnd=maCache.end();
while( aCurr != aEnd )
{ {
glDeleteTextures(1, &aCurr->second.nTexture); glDeleteTextures( 1, &rCache.second.nTexture );
++aCurr;
} }
maCache.clear(); maCache.clear();
...@@ -56,22 +53,21 @@ namespace oglcanvas ...@@ -56,22 +53,21 @@ namespace oglcanvas
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
// delete already "old" textures, mark "new" entries "old" // delete already "old" textures, mark "new" entries "old"
TextureCacheMapT::iterator aNext; const TextureCacheMapT::const_iterator aEnd = maCache.end();
TextureCacheMapT::iterator aCurr=maCache.begin(); TextureCacheMapT::iterator aNext = maCache.begin();
const TextureCacheMapT::iterator aEnd=maCache.end(); ++aNext;
while( aCurr != aEnd ) for( auto aCurr = maCache.begin(); aCurr != aEnd; ++aNext )
{ {
aNext=aCurr; ++aNext;
if( aCurr->second.bOld ) if( aCurr->second.bOld )
{ {
glDeleteTextures(1, &aCurr->second.nTexture); glDeleteTextures( 1, &aCurr->second.nTexture );
maCache.erase(aCurr); maCache.erase( aCurr );
} }
else else
{ {
aCurr->second.bOld = true; aCurr->second.bOld = true;
} }
aCurr=aNext; aCurr = aNext;
} }
mnMissCount = 0; mnMissCount = 0;
......
...@@ -123,17 +123,14 @@ namespace canvas ...@@ -123,17 +123,14 @@ namespace canvas
// translate this area to the final position, // translate this area to the final position,
// coordinates need to be relative to the // coordinates need to be relative to the
// spritecanvas. // spritecanvas.
VectorOfRects::const_iterator aCurr( aClipDifferences.begin() ); for( const auto& rClipDiff : aClipDifferences )
const VectorOfRects::const_iterator aEnd( aClipDifferences.end() );
while( aCurr != aEnd )
{ {
mpSpriteCanvas->updateSprite( mpSpriteCanvas->updateSprite(
rSprite, rSprite,
maPosition, maPosition,
::basegfx::B2DRectangle( ::basegfx::B2DRectangle(
maPosition + aCurr->getMinimum(), maPosition + rClipDiff.getMinimum(),
maPosition + aCurr->getMaximum() ) ); maPosition + rClipDiff.getMaximum() ) );
++aCurr;
} }
// update calls all done // update calls all done
......
...@@ -84,11 +84,9 @@ namespace canvas ...@@ -84,11 +84,9 @@ namespace canvas
bool Page::insert( SurfaceRect& r ) bool Page::insert( SurfaceRect& r )
{ {
const FragmentContainer_t::const_iterator aEnd(mpFragments.end()); for( const auto& pFragment : mpFragments )
FragmentContainer_t::const_iterator it(mpFragments.begin());
while(it != aEnd)
{ {
const SurfaceRect &rect = (*it)->getRect(); const SurfaceRect &rect = pFragment->getRect();
const sal_Int32 x = rect.maPos.getX(); const sal_Int32 x = rect.maPos.getX();
const sal_Int32 y = rect.maPos.getY(); const sal_Int32 y = rect.maPos.getY();
// to avoid interpolation artifacts from other textures, // to avoid interpolation artifacts from other textures,
...@@ -107,8 +105,6 @@ namespace canvas ...@@ -107,8 +105,6 @@ namespace canvas
r.maPos.setY(y+h); r.maPos.setY(y+h);
if(isValidLocation(r)) if(isValidLocation(r))
return true; return true;
++it;
} }
r.maPos.setX(0); r.maPos.setX(0);
...@@ -126,14 +122,10 @@ namespace canvas ...@@ -126,14 +122,10 @@ namespace canvas
if( !r.inside(aBoundary) ) if( !r.inside(aBoundary) )
return false; return false;
const FragmentContainer_t::const_iterator aEnd(mpFragments.end()); for( const auto& pFragment : mpFragments )
FragmentContainer_t::const_iterator it(mpFragments.begin());
while(it != aEnd)
{ {
if(r.intersection((*it)->getRect())) if( r.intersection( pFragment->getRect() ) )
return false; return false;
++it;
} }
return true; return true;
......
...@@ -28,11 +28,9 @@ namespace canvas ...@@ -28,11 +28,9 @@ namespace canvas
// we are asked to find a location for the requested size. // we are asked to find a location for the requested size.
// first we try to satisfy the request from the // first we try to satisfy the request from the
// remaining space in the existing pages. // remaining space in the existing pages.
const PageContainer_t::iterator aEnd(maPages.end()); for( const auto& pPage : maPages )
PageContainer_t::iterator it(maPages.begin());
while(it != aEnd)
{ {
FragmentSharedPtr pFragment((*it)->allocateSpace(rSize)); FragmentSharedPtr pFragment( pPage->allocateSpace(rSize) );
if(pFragment) if(pFragment)
{ {
// the page created a new fragment, since we maybe want // the page created a new fragment, since we maybe want
...@@ -41,8 +39,6 @@ namespace canvas ...@@ -41,8 +39,6 @@ namespace canvas
maFragments.push_back(pFragment); maFragments.push_back(pFragment);
return pFragment; return pFragment;
} }
++it;
} }
// otherwise try to create a new page and allocate space there... // otherwise try to create a new page and allocate space there...
...@@ -140,23 +136,18 @@ namespace canvas ...@@ -140,23 +136,18 @@ namespace canvas
// be naked, that is it is not located on any page. // be naked, that is it is not located on any page.
// we try all available pages again, maybe some // we try all available pages again, maybe some
// other fragment was deleted and we can exploit the space. // other fragment was deleted and we can exploit the space.
const PageContainer_t::iterator aEnd(maPages.end()); for( const auto& pPage : maPages )
PageContainer_t::iterator it(maPages.begin());
while(it != aEnd)
{ {
// if the page at hand takes the fragment, we immediately // if the page at hand takes the fragment, we immediately
// call select() to pull the information from the associated // call select() to pull the information from the associated
// image to the hardware surface. // image to the hardware surface.
if((*it)->nakedFragment(pFragment)) if( pPage->nakedFragment( pFragment ) )
{ {
// dirty, since newly allocated. // dirty, since newly allocated.
pFragment->select(true); pFragment->select(true);
return true; return true;
} }
++it;
} }
return false; return false;
} }
......
...@@ -225,15 +225,12 @@ namespace canvas ...@@ -225,15 +225,12 @@ namespace canvas
SpriteWeakOrder aSpriteComparator; SpriteWeakOrder aSpriteComparator;
// put all sprites that have changed content into update areas // put all sprites that have changed content into update areas
ListOfSprites::const_iterator aCurrSprite( maSprites.begin() ); for( const auto& pSprite : maSprites )
const ListOfSprites::const_iterator aEndSprite ( maSprites.end() );
while( aCurrSprite != aEndSprite )
{ {
if( (*aCurrSprite)->isContentChanged() ) if( pSprite->isContentChanged() )
const_cast<SpriteRedrawManager*>(this)->updateSprite( *aCurrSprite, const_cast< SpriteRedrawManager* >( this )->updateSprite( pSprite,
(*aCurrSprite)->getPosPixel(), pSprite->getPosPixel(),
(*aCurrSprite)->getUpdateArea() ); pSprite->getUpdateArea() );
++aCurrSprite;
} }
// sort sprites after prio // sort sprites after prio
...@@ -250,14 +247,11 @@ namespace canvas ...@@ -250,14 +247,11 @@ namespace canvas
// sprite pointer). This assumes that, until this scope // sprite pointer). This assumes that, until this scope
// ends, nobody changes the maChangeRecords vector! // ends, nobody changes the maChangeRecords vector!
VectorOfSprites aUpdatableSprites; VectorOfSprites aUpdatableSprites;
VectorOfChangeRecords::const_iterator aCurrRecord( maChangeRecords.begin() ); for( const auto& rChangeRecord : maChangeRecords )
const VectorOfChangeRecords::const_iterator aEndRecords( maChangeRecords.end() );
while( aCurrRecord != aEndRecords )
{ {
const Sprite::Reference& rSprite( aCurrRecord->getSprite() ); const Sprite::Reference& rSprite( rChangeRecord.getSprite() );
if( rSprite.is() ) if( rSprite.is() )
aUpdatableSprites.push_back( rSprite ); aUpdatableSprites.push_back( rSprite );
++aCurrRecord;
} }
::std::sort( aUpdatableSprites.begin(), ::std::sort( aUpdatableSprites.begin(),
...@@ -294,17 +288,14 @@ namespace canvas ...@@ -294,17 +288,14 @@ namespace canvas
// add each remaining unchanged sprite to connected ranges, // add each remaining unchanged sprite to connected ranges,
// marked as "don't need update" // marked as "don't need update"
VectorOfSprites::const_iterator aCurr( aUnchangedSprites.begin() ); for( const auto& pUnchangedSprite : aUnchangedSprites )
const VectorOfSprites::const_iterator aEnd2( aUnchangedSprites.end() );
while( aCurr != aEnd2 )
{ {
const ::basegfx::B2DRange& rUpdateArea( (*aCurr)->getUpdateArea() ); const ::basegfx::B2DRange& rUpdateArea( pUnchangedSprite->getUpdateArea() );
rUpdateAreas.addRange( rUpdateAreas.addRange(
::basegfx::unotools::b2DSurroundingIntegerRangeFromB2DRange( rUpdateArea ), ::basegfx::unotools::b2DSurroundingIntegerRangeFromB2DRange( rUpdateArea ),
SpriteInfo(*aCurr, SpriteInfo( pUnchangedSprite,
rUpdateArea, rUpdateArea,
false) ); false ) );
++aCurr;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment