1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_canvas.hxx" 26 27 #include <canvas/debug.hxx> 28 #include <canvas/verbosetrace.hxx> 29 #include <canvas/canvastools.hxx> 30 #include <tools/diagnose_ex.h> 31 32 #include <vcl/canvastools.hxx> 33 34 #include <comphelper/scopeguard.hxx> 35 36 #include <basegfx/range/b2drectangle.hxx> 37 #include <basegfx/tools/canvastools.hxx> 38 39 #include <boost/cast.hpp> 40 41 #include "cairo_spritecanvashelper.hxx" 42 #include "cairo_canvascustomsprite.hxx" 43 44 using namespace ::cairo; 45 using namespace ::com::sun::star; 46 47 namespace cairocanvas 48 { 49 namespace 50 { 51 /** Sprite redraw at original position 52 53 Used to repaint the whole canvas (background and all 54 sprites) 55 */ spriteRedraw(const CairoSharedPtr & pCairo,const::canvas::Sprite::Reference & rSprite)56 void spriteRedraw( const CairoSharedPtr& pCairo, 57 const ::canvas::Sprite::Reference& rSprite ) 58 { 59 // downcast to derived cairocanvas::Sprite interface, which 60 // provides the actual redraw methods. 61 ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->redraw( pCairo, true); 62 } 63 repaintBackground(const CairoSharedPtr & pCairo,const SurfaceSharedPtr & pBackgroundSurface,const::basegfx::B2DRange & rArea)64 void repaintBackground( const CairoSharedPtr& pCairo, 65 const SurfaceSharedPtr& pBackgroundSurface, 66 const ::basegfx::B2DRange& rArea ) 67 { 68 cairo_save( pCairo.get() ); 69 cairo_rectangle( pCairo.get(), ceil( rArea.getMinX() ), ceil( rArea.getMinY() ), 70 floor( rArea.getWidth() ), floor( rArea.getHeight() ) ); 71 cairo_clip( pCairo.get() ); 72 cairo_set_source_surface( pCairo.get(), pBackgroundSurface->getCairoSurface().get(), 0, 0 ); 73 cairo_set_operator( pCairo.get(), CAIRO_OPERATOR_SOURCE ); 74 cairo_paint( pCairo.get() ); 75 cairo_restore( pCairo.get() ); 76 } 77 opaqueUpdateSpriteArea(const::canvas::Sprite::Reference & rSprite,const CairoSharedPtr & pCairo,const::basegfx::B2IRange & rArea)78 void opaqueUpdateSpriteArea( const ::canvas::Sprite::Reference& rSprite, 79 const CairoSharedPtr& pCairo, 80 const ::basegfx::B2IRange& rArea ) 81 { 82 // clip output to actual update region (otherwise a) 83 // wouldn't save much render time, and b) will clutter 84 // scrolled sprite content outside this area) 85 cairo_save( pCairo.get() ); 86 cairo_rectangle( pCairo.get(), rArea.getMinX(), rArea.getMinY(), 87 sal::static_int_cast<sal_Int32>(rArea.getWidth()), 88 sal::static_int_cast<sal_Int32>(rArea.getHeight()) ); 89 cairo_clip( pCairo.get() ); 90 91 // repaint affected sprite directly to output device (at 92 // the actual screen output position) 93 // rendering directly to device buffer 94 ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, false ); 95 96 cairo_restore( pCairo.get() ); 97 } 98 99 /** Repaint sprite at original position 100 101 Used for opaque updates, which render directly to the 102 device buffer. 103 */ spriteRedrawStub(const CairoSharedPtr & pCairo,const::canvas::Sprite::Reference & rSprite)104 void spriteRedrawStub( const CairoSharedPtr& pCairo, 105 const ::canvas::Sprite::Reference& rSprite ) 106 { 107 if( rSprite.is() ) 108 { 109 ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, false ); 110 } 111 } 112 113 /** Repaint sprite at given position 114 115 Used for generic update, which renders into device buffer. 116 */ spriteRedrawStub2(const CairoSharedPtr & pCairo,const::canvas::Sprite::Reference & rSprite)117 void spriteRedrawStub2( const CairoSharedPtr& pCairo, 118 const ::canvas::Sprite::Reference& rSprite ) 119 { 120 if( rSprite.is() ) 121 { 122 ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, true );; 123 } 124 } 125 126 /** Repaint sprite at original position 127 128 Used for opaque updates from scrollUpdate(), which render 129 directly to the front buffer. 130 */ spriteRedrawStub3(const CairoSharedPtr & pCairo,const::canvas::SpriteRedrawManager::AreaComponent & rComponent)131 void spriteRedrawStub3( const CairoSharedPtr& pCairo, 132 const ::canvas::SpriteRedrawManager::AreaComponent& rComponent ) 133 { 134 const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() ); 135 136 if( rSprite.is() ) 137 ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, false ); 138 } 139 } 140 SpriteCanvasHelper()141 SpriteCanvasHelper::SpriteCanvasHelper() : 142 mpRedrawManager( NULL ), 143 mpOwningSpriteCanvas( NULL ), 144 mpCompositingSurface(), 145 maCompositingSurfaceSize() 146 { 147 } 148 init(::canvas::SpriteRedrawManager & rManager,SpriteCanvas & rDevice,const::basegfx::B2ISize & rSize)149 void SpriteCanvasHelper::init( ::canvas::SpriteRedrawManager& rManager, 150 SpriteCanvas& rDevice, 151 const ::basegfx::B2ISize& rSize ) 152 { 153 mpRedrawManager = &rManager; 154 mpOwningSpriteCanvas = &rDevice; 155 156 CanvasHelper::init( rSize, rDevice, &rDevice ); 157 } 158 disposing()159 void SpriteCanvasHelper::disposing() 160 { 161 mpCompositingSurface.reset(); 162 mpOwningSpriteCanvas = NULL; 163 mpRedrawManager = NULL; 164 165 // forward to base 166 CanvasHelper::disposing(); 167 } 168 createSpriteFromAnimation(const uno::Reference<rendering::XAnimation> &)169 uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromAnimation( 170 const uno::Reference< rendering::XAnimation >& ) 171 { 172 return uno::Reference< rendering::XAnimatedSprite >(); 173 } 174 createSpriteFromBitmaps(const uno::Sequence<uno::Reference<rendering::XBitmap>> &,sal_Int8)175 uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromBitmaps( 176 const uno::Sequence< uno::Reference< rendering::XBitmap > >& /*animationBitmaps*/, 177 sal_Int8 /*interpolationMode*/ ) 178 { 179 return uno::Reference< rendering::XAnimatedSprite >(); 180 } 181 createCustomSprite(const geometry::RealSize2D & spriteSize)182 uno::Reference< rendering::XCustomSprite > SpriteCanvasHelper::createCustomSprite( const geometry::RealSize2D& spriteSize ) 183 { 184 if( !mpRedrawManager ) 185 return uno::Reference< rendering::XCustomSprite >(); // we're disposed 186 187 return uno::Reference< rendering::XCustomSprite >( 188 new CanvasCustomSprite( spriteSize, 189 mpOwningSpriteCanvas ) ); 190 } 191 createClonedSprite(const uno::Reference<rendering::XSprite> &)192 uno::Reference< rendering::XSprite > SpriteCanvasHelper::createClonedSprite( 193 const uno::Reference< rendering::XSprite >& ) 194 { 195 return uno::Reference< rendering::XSprite >(); 196 } 197 updateScreen(const::basegfx::B2IRange &,sal_Bool bUpdateAll,bool & io_bSurfaceDirty)198 sal_Bool SpriteCanvasHelper::updateScreen( const ::basegfx::B2IRange& /*rCurrArea*/, 199 sal_Bool bUpdateAll, 200 bool& io_bSurfaceDirty ) 201 { 202 if( !mpRedrawManager || 203 !mpOwningSpriteCanvas || 204 !mpOwningSpriteCanvas->getWindowSurface() || 205 !mpOwningSpriteCanvas->getBufferSurface() ) 206 { 207 return sal_False; // disposed, or otherwise dysfunctional 208 } 209 210 OSL_TRACE("SpriteCanvasHelper::updateScreen called"); 211 212 const ::basegfx::B2ISize& rSize = mpOwningSpriteCanvas->getSizePixel(); 213 214 // force compositing surface to be available before using it 215 // inside forEachSpriteArea 216 SurfaceSharedPtr pCompositingSurface = getCompositingSurface(rSize); 217 SurfaceSharedPtr pWindowSurface = mpOwningSpriteCanvas->getWindowSurface(); 218 CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo(); 219 CairoSharedPtr pWindowCairo = pWindowSurface->getCairo(); 220 221 // TODO(P1): Might be worthwhile to track areas of background 222 // changes, too. 223 if( !bUpdateAll && !io_bSurfaceDirty ) 224 { 225 // background has not changed, so we're free to optimize 226 // repaint to areas where a sprite has changed 227 228 // process each independent area of overlapping sprites 229 // separately. 230 mpRedrawManager->forEachSpriteArea( *this ); 231 } 232 else 233 { 234 OSL_TRACE("SpriteCanvasHelper::updateScreen update ALL"); 235 236 // background has changed, so we currently have no choice 237 // but repaint everything (or caller requested that) 238 239 cairo_rectangle( pCompositingCairo.get(), 0, 0, rSize.getX(), rSize.getY() ); 240 cairo_clip( pCompositingCairo.get() ); 241 cairo_save( pCompositingCairo.get() ); 242 cairo_set_source_surface( pCompositingCairo.get(), 243 mpOwningSpriteCanvas->getBufferSurface()->getCairoSurface().get(), 244 0, 0 ); 245 cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE ); 246 cairo_paint( pCompositingCairo.get() ); 247 cairo_restore( pCompositingCairo.get() ); 248 249 // repaint all active sprites on top of background into 250 // VDev. 251 mpRedrawManager->forEachSprite( 252 ::boost::bind( 253 &spriteRedraw, 254 boost::cref(pCompositingCairo), 255 _1 ) ); 256 257 // flush to screen 258 cairo_rectangle( pWindowCairo.get(), 0, 0, rSize.getX(), rSize.getY() ); 259 cairo_clip( pWindowCairo.get() ); 260 cairo_set_source_surface( pWindowCairo.get(), 261 pCompositingSurface->getCairoSurface().get(), 262 0, 0 ); 263 cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE ); 264 cairo_paint( pWindowCairo.get() ); 265 } 266 267 // change record vector must be cleared, for the next turn of 268 // rendering and sprite changing 269 mpRedrawManager->clearChangeRecords(); 270 271 io_bSurfaceDirty = false; 272 273 // commit to screen 274 mpOwningSpriteCanvas->flush(); 275 276 return sal_True; 277 } 278 backgroundPaint(const::basegfx::B2DRange & rUpdateRect)279 void SpriteCanvasHelper::backgroundPaint( const ::basegfx::B2DRange& rUpdateRect ) 280 { 281 if( mpOwningSpriteCanvas && mpCompositingSurface ) 282 repaintBackground( mpCompositingSurface->getCairo(), 283 mpOwningSpriteCanvas->getBufferSurface(), 284 rUpdateRect ); 285 } 286 scrollUpdate(const::basegfx::B2DRange & rMoveStart,const::basegfx::B2DRange & rMoveEnd,const::canvas::SpriteRedrawManager::UpdateArea & rUpdateArea)287 void SpriteCanvasHelper::scrollUpdate( const ::basegfx::B2DRange& rMoveStart, 288 const ::basegfx::B2DRange& rMoveEnd, 289 const ::canvas::SpriteRedrawManager::UpdateArea& rUpdateArea ) 290 { 291 ENSURE_OR_THROW( mpOwningSpriteCanvas && 292 mpOwningSpriteCanvas->getBufferSurface(), 293 "SpriteCanvasHelper::scrollUpdate(): NULL device pointer " ); 294 295 OSL_TRACE("SpriteCanvasHelper::scrollUpdate called"); 296 297 const ::basegfx::B2ISize& rSize = mpOwningSpriteCanvas->getSizePixel(); 298 const ::basegfx::B2IRange aOutputBounds( 0,0, 299 rSize.getX(), 300 rSize.getY() ); 301 302 SurfaceSharedPtr pCompositingSurface = getCompositingSurface(rSize); 303 SurfaceSharedPtr pWindowSurface = mpOwningSpriteCanvas->getWindowSurface(); 304 CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo(); 305 CairoSharedPtr pWindowCairo = pWindowSurface->getCairo(); 306 307 // round rectangles to integer pixel. Note: have to be 308 // extremely careful here, to avoid off-by-one errors for 309 // the destination area: otherwise, the next scroll update 310 // would copy pixel that are not supposed to be part of 311 // the sprite. 312 ::basegfx::B2IRange aSourceRect( 313 ::canvas::tools::spritePixelAreaFromB2DRange( rMoveStart ) ); 314 const ::basegfx::B2IRange& rDestRect( 315 ::canvas::tools::spritePixelAreaFromB2DRange( rMoveEnd ) ); 316 ::basegfx::B2IPoint aDestPos( rDestRect.getMinimum() ); 317 318 ::std::vector< ::basegfx::B2IRange > aUnscrollableAreas; 319 320 // TODO(E3): This is plain buggy (but copies the behaviour of 321 // the old Impress slideshow) - the scrolled area might 322 // actually lie _below_ another window! 323 324 // clip to output bounds (cannot properly scroll stuff 325 // _outside_ our screen area) 326 if( !::canvas::tools::clipScrollArea( aSourceRect, 327 aDestPos, 328 aUnscrollableAreas, 329 aOutputBounds ) ) 330 { 331 // fully clipped scroll area: cannot simply scroll 332 // then. Perform normal opaque update (can use that, since 333 // one of the preconditions for scrollable update is 334 // opaque sprite content) 335 336 // repaint all affected sprites directly to output device 337 ::std::for_each( rUpdateArea.maComponentList.begin(), 338 rUpdateArea.maComponentList.end(), 339 ::boost::bind( 340 &spriteRedrawStub3, 341 boost::cref(pCompositingCairo), 342 _1 ) ); 343 } 344 else 345 { 346 const ::basegfx::B2IVector aSourceUpperLeftPos( aSourceRect.getMinimum() ); 347 348 // clip dest area (which must be inside rDestBounds) 349 ::basegfx::B2IRange aDestRect( rDestRect ); 350 aDestRect.intersect( aOutputBounds ); 351 352 cairo_save( pCompositingCairo.get() ); 353 // scroll content in device back buffer 354 cairo_set_source_surface( pCompositingCairo.get(), 355 mpOwningSpriteCanvas->getBufferSurface()->getCairoSurface().get(), 356 aDestPos.getX() - aSourceUpperLeftPos.getX(), 357 aDestPos.getY() - aSourceUpperLeftPos.getY() ); 358 cairo_rectangle( pCompositingCairo.get(), 359 aDestPos.getX(), aDestPos.getY(), 360 sal::static_int_cast<sal_Int32>(aDestRect.getWidth()), 361 sal::static_int_cast<sal_Int32>(aDestRect.getHeight()) ); 362 cairo_clip( pCompositingCairo.get() ); 363 cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE ); 364 cairo_paint( pCompositingCairo.get() ); 365 cairo_restore( pCompositingCairo.get() ); 366 367 const ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator 368 aFirst( rUpdateArea.maComponentList.begin() ); 369 ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator 370 aSecond( aFirst ); ++aSecond; 371 372 ENSURE_OR_THROW( aFirst->second.getSprite().is(), 373 "VCLCanvas::scrollUpdate(): no sprite" ); 374 375 // repaint uncovered areas from sprite. Need to actually 376 // clip here, since we're only repainting _parts_ of the 377 // sprite 378 ::std::for_each( aUnscrollableAreas.begin(), 379 aUnscrollableAreas.end(), 380 ::boost::bind( &opaqueUpdateSpriteArea, 381 ::boost::cref(aFirst->second.getSprite()), 382 boost::cref(pCompositingCairo), 383 _1 ) ); 384 } 385 386 // repaint uncovered areas from backbuffer - take the 387 // _rounded_ rectangles from above, to have the update 388 // consistent with the scroll above. 389 ::std::vector< ::basegfx::B2DRange > aUncoveredAreas; 390 ::basegfx::computeSetDifference( aUncoveredAreas, 391 rUpdateArea.maTotalBounds, 392 ::basegfx::B2DRange( rDestRect ) ); 393 SurfaceSharedPtr pBufferSurface = mpOwningSpriteCanvas->getBufferSurface(); 394 ::std::for_each( aUncoveredAreas.begin(), 395 aUncoveredAreas.end(), 396 ::boost::bind( &repaintBackground, 397 boost::cref(pCompositingCairo), 398 boost::cref(pBufferSurface), 399 _1 ) ); 400 401 cairo_rectangle( pWindowCairo.get(), 0, 0, rSize.getX(), rSize.getY() ); 402 cairo_clip( pWindowCairo.get() ); 403 cairo_set_source_surface( pWindowCairo.get(), 404 pCompositingSurface->getCairoSurface().get(), 405 0, 0 ); 406 cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE ); 407 cairo_paint( pWindowCairo.get() ); 408 } 409 opaqueUpdate(const::basegfx::B2DRange & rTotalArea,const::std::vector<::canvas::Sprite::Reference> & rSortedUpdateSprites)410 void SpriteCanvasHelper::opaqueUpdate( const ::basegfx::B2DRange& rTotalArea, 411 const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites ) 412 { 413 ENSURE_OR_THROW( mpOwningSpriteCanvas && 414 mpOwningSpriteCanvas->getBufferSurface(), 415 "SpriteCanvasHelper::opaqueUpdate(): NULL device pointer " ); 416 417 OSL_TRACE("SpriteCanvasHelper::opaqueUpdate called"); 418 419 const ::basegfx::B2ISize& rDeviceSize = mpOwningSpriteCanvas->getSizePixel(); 420 421 SurfaceSharedPtr pCompositingSurface = getCompositingSurface(rDeviceSize); 422 SurfaceSharedPtr pWindowSurface = mpOwningSpriteCanvas->getWindowSurface(); 423 CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo(); 424 CairoSharedPtr pWindowCairo = pWindowSurface->getCairo(); 425 426 cairo_rectangle( pCompositingCairo.get(), 0, 0, rDeviceSize.getX(), rDeviceSize.getY() ); 427 cairo_clip( pCompositingCairo.get() ); 428 429 ::basegfx::B2DVector aPos( ceil( rTotalArea.getMinX() ), ceil( rTotalArea.getMinY() ) ); 430 ::basegfx::B2DVector aSize( floor( rTotalArea.getMaxX() - aPos.getX() ), floor( rTotalArea.getMaxY() - aPos.getY() ) ); 431 432 cairo_rectangle( pCompositingCairo.get(), aPos.getX(), aPos.getY(), aSize.getX(), aSize.getY() ); 433 cairo_clip( pCompositingCairo.get() ); 434 435 // repaint all affected sprites directly to output device 436 ::std::for_each( rSortedUpdateSprites.begin(), 437 rSortedUpdateSprites.end(), 438 ::boost::bind( 439 &spriteRedrawStub, 440 boost::cref(pCompositingCairo), 441 _1 ) ); 442 443 // flush to screen 444 cairo_rectangle( pWindowCairo.get(), 0, 0, rDeviceSize.getX(), rDeviceSize.getY() ); 445 cairo_clip( pWindowCairo.get() ); 446 cairo_rectangle( pWindowCairo.get(), aPos.getX(), aPos.getY(), aSize.getX(), aSize.getY() ); 447 cairo_clip( pWindowCairo.get() ); 448 cairo_set_source_surface( pWindowCairo.get(), 449 pCompositingSurface->getCairoSurface().get(), 450 0, 0 ); 451 cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE ); 452 cairo_paint( pWindowCairo.get() ); 453 } 454 genericUpdate(const::basegfx::B2DRange & rRequestedArea,const::std::vector<::canvas::Sprite::Reference> & rSortedUpdateSprites)455 void SpriteCanvasHelper::genericUpdate( const ::basegfx::B2DRange& rRequestedArea, 456 const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites ) 457 { 458 // TODO 459 OSL_TRACE("SpriteCanvasHelper::genericUpdate called"); 460 461 ENSURE_OR_THROW( mpOwningSpriteCanvas && 462 mpOwningSpriteCanvas->getBufferSurface(), 463 "SpriteCanvasHelper::genericUpdate(): NULL device pointer " ); 464 465 // limit size of update VDev to target outdev's size 466 const ::basegfx::B2ISize& rSize = mpOwningSpriteCanvas->getSizePixel(); 467 468 SurfaceSharedPtr pCompositingSurface = getCompositingSurface(rSize); 469 SurfaceSharedPtr pWindowSurface = mpOwningSpriteCanvas->getWindowSurface(); 470 CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo(); 471 CairoSharedPtr pWindowCairo = pWindowSurface->getCairo(); 472 473 // round output position towards zero. Don't want to truncate 474 // a fraction of a sprite pixel... Clip position at origin, 475 // otherwise, truncation of size below might leave visible 476 // areas uncovered by VDev. 477 const Point aOutputPosition( 478 ::std::max( sal_Int32( 0 ), 479 static_cast< sal_Int32 >(rRequestedArea.getMinX()) ), 480 ::std::max( sal_Int32( 0 ), 481 static_cast< sal_Int32 >(rRequestedArea.getMinY()) ) ); 482 // round output size towards +infty. Don't want to truncate a 483 // fraction of a sprite pixel... Limit size of VDev to output 484 // device's area. 485 const Size aOutputSize( 486 ::std::min( rSize.getX(), 487 ::canvas::tools::roundUp( rRequestedArea.getMaxX() - aOutputPosition.X()) ), 488 ::std::min( rSize.getY(), 489 ::canvas::tools::roundUp( rRequestedArea.getMaxY() - aOutputPosition.Y()) ) ); 490 491 cairo_rectangle( pCompositingCairo.get(), aOutputPosition.X(), aOutputPosition.Y(), aOutputSize.Width(), aOutputSize.Height() ); 492 cairo_clip( pCompositingCairo.get() ); 493 494 // paint background 495 cairo_save( pCompositingCairo.get() ); 496 cairo_set_source_surface( pCompositingCairo.get(), 497 mpOwningSpriteCanvas->getBufferSurface()->getCairoSurface().get(), 498 0, 0 ); 499 cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE ); 500 cairo_paint( pCompositingCairo.get() ); 501 cairo_restore( pCompositingCairo.get() ); 502 503 // repaint all affected sprites on top of background into 504 // VDev. 505 ::std::for_each( rSortedUpdateSprites.begin(), 506 rSortedUpdateSprites.end(), 507 ::boost::bind( &spriteRedrawStub2, 508 boost::cref(pCompositingCairo), 509 _1 ) ); 510 511 // flush to screen 512 cairo_rectangle( pWindowCairo.get(), aOutputPosition.X(), aOutputPosition.Y(), aOutputSize.Width(), aOutputSize.Height() ); 513 cairo_clip( pWindowCairo.get() ); 514 cairo_set_source_surface( pWindowCairo.get(), 515 pCompositingSurface->getCairoSurface().get(), 516 0, 0 ); 517 cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE ); 518 cairo_paint( pWindowCairo.get() ); 519 } 520 getCompositingSurface(const::basegfx::B2ISize & rNeededSize)521 ::cairo::SurfaceSharedPtr SpriteCanvasHelper::getCompositingSurface( const ::basegfx::B2ISize& rNeededSize ) 522 { 523 if( rNeededSize.getX() < maCompositingSurfaceSize.getX() || 524 rNeededSize.getY() < maCompositingSurfaceSize.getY() ) 525 { 526 // need to give buffer more size 527 mpCompositingSurface.reset(); 528 } 529 530 if( !mpCompositingSurface ) 531 { 532 mpCompositingSurface = 533 mpOwningSpriteCanvas->getWindowSurface()->getSimilar( 534 CAIRO_CONTENT_COLOR, 535 rNeededSize.getX(), rNeededSize.getY() ); 536 maCompositingSurfaceSize = rNeededSize; 537 } 538 539 return mpCompositingSurface; 540 } 541 } 542