1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_canvas.hxx" 30 31 #include <canvas/debug.hxx> 32 #include <canvas/verbosetrace.hxx> 33 #include <tools/diagnose_ex.h> 34 35 #include <rtl/logfile.hxx> 36 #include <rtl/math.hxx> 37 38 #include <canvas/canvastools.hxx> 39 40 #include <basegfx/matrix/b2dhommatrix.hxx> 41 #include <basegfx/point/b2dpoint.hxx> 42 43 #include "cairo_canvascustomsprite.hxx" 44 #include "cairo_spritecanvas.hxx" 45 46 47 using namespace ::cairo; 48 using namespace ::com::sun::star; 49 50 namespace cairocanvas 51 { 52 CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& rSpriteSize, 53 const SpriteCanvasRef& rRefDevice ) : 54 mpSpriteCanvas( rRefDevice ), 55 maSize( ::canvas::tools::roundUp( rSpriteSize.Width ), 56 ::canvas::tools::roundUp( rSpriteSize.Height ) ) 57 { 58 ENSURE_OR_THROW( rRefDevice.get(), 59 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" ); 60 61 OSL_TRACE("sprite size: %d, %d", 62 ::canvas::tools::roundUp( rSpriteSize.Width ), 63 ::canvas::tools::roundUp( rSpriteSize.Height )); 64 65 mpBufferSurface = mpSpriteCanvas->createSurface( maSize ); 66 67 maCanvasHelper.init( maSize, 68 *rRefDevice, 69 rRefDevice.get() ); 70 maCanvasHelper.setSurface( mpBufferSurface, true ); 71 72 maSpriteHelper.init( rSpriteSize, 73 rRefDevice ); 74 maSpriteHelper.setSurface( mpBufferSurface ); 75 76 // clear sprite to 100% transparent 77 maCanvasHelper.clear(); 78 } 79 80 void SAL_CALL CanvasCustomSprite::disposing() 81 { 82 ::osl::MutexGuard aGuard( m_aMutex ); 83 84 mpSpriteCanvas.clear(); 85 mpBufferSurface.reset(); 86 87 // forward to parent 88 CanvasCustomSpriteBaseT::disposing(); 89 } 90 91 void CanvasCustomSprite::redraw( const CairoSharedPtr& pCairo, 92 bool bBufferedUpdate ) const 93 { 94 ::osl::MutexGuard aGuard( m_aMutex ); 95 96 redraw( pCairo, maSpriteHelper.getPosPixel(), bBufferedUpdate ); 97 } 98 99 void CanvasCustomSprite::redraw( const CairoSharedPtr& pCairo, 100 const ::basegfx::B2DPoint& rOrigOutputPos, 101 bool bBufferedUpdate ) const 102 { 103 ::osl::MutexGuard aGuard( m_aMutex ); 104 105 maSpriteHelper.redraw( pCairo, 106 rOrigOutputPos, 107 mbSurfaceDirty, 108 bBufferedUpdate ); 109 110 mbSurfaceDirty = false; 111 } 112 113 bool CanvasCustomSprite::repaint( const SurfaceSharedPtr& pSurface, 114 const rendering::ViewState& viewState, 115 const rendering::RenderState& renderState ) 116 { 117 return maCanvasHelper.repaint( pSurface, viewState, renderState ); 118 } 119 120 SurfaceSharedPtr CanvasCustomSprite::getSurface() 121 { 122 return mpBufferSurface; 123 } 124 125 SurfaceSharedPtr CanvasCustomSprite::createSurface( const ::basegfx::B2ISize& rSize, Content aContent ) 126 { 127 return mpSpriteCanvas->createSurface(rSize,aContent); 128 } 129 130 SurfaceSharedPtr CanvasCustomSprite::createSurface( ::Bitmap& rBitmap ) 131 { 132 return mpSpriteCanvas->createSurface(rBitmap); 133 } 134 135 SurfaceSharedPtr CanvasCustomSprite::changeSurface( bool bHasAlpha, bool bCopyContent ) 136 { 137 if( !bHasAlpha && !bCopyContent ) 138 { 139 OSL_TRACE("replacing sprite background surface"); 140 141 mpBufferSurface = mpSpriteCanvas->createSurface( maSize, CAIRO_CONTENT_COLOR ); 142 maSpriteHelper.setSurface( mpBufferSurface ); 143 144 return mpBufferSurface; 145 } 146 147 return SurfaceSharedPtr(); 148 } 149 150 OutputDevice* CanvasCustomSprite::getOutputDevice() 151 { 152 return mpSpriteCanvas->getOutputDevice(); 153 } 154 155 #define IMPLEMENTATION_NAME "CairoCanvas.CanvasCustomSprite" 156 #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite" 157 158 ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException ) 159 { 160 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 161 } 162 163 sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 164 { 165 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 166 } 167 168 uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException ) 169 { 170 uno::Sequence< ::rtl::OUString > aRet(1); 171 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 172 173 return aRet; 174 } 175 } 176