1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_canvas.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <canvas/debug.hxx> 32*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 33*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <rtl/math.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <vcl/outdev.hxx> 38*cdf0e10cSrcweir #include <vcl/bitmap.hxx> 39*cdf0e10cSrcweir #include <vcl/alpha.hxx> 40*cdf0e10cSrcweir #include <vcl/bitmapex.hxx> 41*cdf0e10cSrcweir #include <vcl/canvastools.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 44*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 45*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 46*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 47*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 48*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 49*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include <canvas/canvastools.hxx> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include "canvascustomsprite.hxx" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir using namespace ::com::sun::star; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir namespace vclcanvas 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D& rSpriteSize, 63*cdf0e10cSrcweir rendering::XGraphicDevice& rDevice, 64*cdf0e10cSrcweir const ::canvas::SpriteSurface::Reference& rOwningSpriteCanvas, 65*cdf0e10cSrcweir const OutDevProviderSharedPtr& rOutDevProvider, 66*cdf0e10cSrcweir bool bShowSpriteBounds ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir ENSURE_OR_THROW( rOwningSpriteCanvas.get() && 69*cdf0e10cSrcweir rOutDevProvider, 70*cdf0e10cSrcweir "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" ); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir // setup back buffer 73*cdf0e10cSrcweir // ----------------- 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir const ::Size aSize( 76*cdf0e10cSrcweir static_cast<sal_Int32>( ::std::max( 1.0, 77*cdf0e10cSrcweir ceil( rSpriteSize.Width ))), // round up to nearest int, 78*cdf0e10cSrcweir // enforce sprite to have at 79*cdf0e10cSrcweir // least (1,1) pixel size 80*cdf0e10cSrcweir static_cast<sal_Int32>( ::std::max( 1.0, 81*cdf0e10cSrcweir ceil( rSpriteSize.Height ))) ); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir // create content backbuffer in screen depth 84*cdf0e10cSrcweir BackBufferSharedPtr pBackBuffer( new BackBuffer( rOutDevProvider->getOutDev() ) ); 85*cdf0e10cSrcweir pBackBuffer->setSize( aSize ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // create mask backbuffer, with one bit color depth 88*cdf0e10cSrcweir BackBufferSharedPtr pBackBufferMask( new BackBuffer( rOutDevProvider->getOutDev(), 89*cdf0e10cSrcweir true ) ); 90*cdf0e10cSrcweir pBackBufferMask->setSize( aSize ); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // TODO(F1): Implement alpha vdev (could prolly enable 93*cdf0e10cSrcweir // antialiasing again, then) 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // disable font antialiasing (causes ugly shadows otherwise) 96*cdf0e10cSrcweir pBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT ); 97*cdf0e10cSrcweir pBackBufferMask->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // set mask vdev drawmode, such that everything is painted 100*cdf0e10cSrcweir // black. That leaves us with a binary image, white for 101*cdf0e10cSrcweir // background, black for painted content 102*cdf0e10cSrcweir pBackBufferMask->getOutDev().SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT | 103*cdf0e10cSrcweir DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP ); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // setup canvas helper 107*cdf0e10cSrcweir // ------------------- 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // always render into back buffer, don't preserve state (it's 110*cdf0e10cSrcweir // our private VDev, after all), have notion of alpha 111*cdf0e10cSrcweir maCanvasHelper.init( rDevice, 112*cdf0e10cSrcweir pBackBuffer, 113*cdf0e10cSrcweir false, 114*cdf0e10cSrcweir true ); 115*cdf0e10cSrcweir maCanvasHelper.setBackgroundOutDev( pBackBufferMask ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // setup sprite helper 119*cdf0e10cSrcweir // ------------------- 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir maSpriteHelper.init( rSpriteSize, 122*cdf0e10cSrcweir rOwningSpriteCanvas, 123*cdf0e10cSrcweir pBackBuffer, 124*cdf0e10cSrcweir pBackBufferMask, 125*cdf0e10cSrcweir bShowSpriteBounds ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // clear sprite to 100% transparent 128*cdf0e10cSrcweir maCanvasHelper.clear(); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir void SAL_CALL CanvasCustomSprite::disposing() 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir tools::LocalGuard aGuard; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // forward to parent 136*cdf0e10cSrcweir CanvasCustomSpriteBaseT::disposing(); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir #define IMPLEMENTATION_NAME "VCLCanvas.CanvasCustomSprite" 140*cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite" 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(1); 155*cdf0e10cSrcweir aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir return aRet; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // Sprite 161*cdf0e10cSrcweir void CanvasCustomSprite::redraw( OutputDevice& rOutDev, 162*cdf0e10cSrcweir bool bBufferedUpdate ) const 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir tools::LocalGuard aGuard; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir redraw( rOutDev, maSpriteHelper.getPosPixel(), bBufferedUpdate ); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir void CanvasCustomSprite::redraw( OutputDevice& rOutDev, 170*cdf0e10cSrcweir const ::basegfx::B2DPoint& rOrigOutputPos, 171*cdf0e10cSrcweir bool bBufferedUpdate ) const 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir tools::LocalGuard aGuard; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir maSpriteHelper.redraw( rOutDev, 176*cdf0e10cSrcweir rOrigOutputPos, 177*cdf0e10cSrcweir mbSurfaceDirty, 178*cdf0e10cSrcweir bBufferedUpdate ); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir mbSurfaceDirty = false; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir bool CanvasCustomSprite::repaint( const GraphicObjectSharedPtr& rGrf, 184*cdf0e10cSrcweir const rendering::ViewState& viewState, 185*cdf0e10cSrcweir const rendering::RenderState& renderState, 186*cdf0e10cSrcweir const ::Point& rPt, 187*cdf0e10cSrcweir const ::Size& rSz, 188*cdf0e10cSrcweir const GraphicAttr& rAttr ) const 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir tools::LocalGuard aGuard; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir mbSurfaceDirty = true; 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr ); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir } 198