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