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 <canvas/verbosetrace.hxx> 33*cdf0e10cSrcweir #include <canvas/canvastools.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <osl/mutex.hxx> 36*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <com/sun/star/lang/NoSupportException.hpp> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 41*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 42*cdf0e10cSrcweir #include <basegfx/tools/unopolypolygon.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <vcl/syschild.hxx> 45*cdf0e10cSrcweir #include <vcl/canvastools.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include "cairo_spritecanvas.hxx" 48*cdf0e10cSrcweir #include "cairo_canvasbitmap.hxx" 49*cdf0e10cSrcweir #include "cairo_devicehelper.hxx" 50*cdf0e10cSrcweir #include "cairo_cairo.hxx" 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir using namespace ::cairo; 53*cdf0e10cSrcweir using namespace ::com::sun::star; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir namespace cairocanvas 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir SpriteDeviceHelper::SpriteDeviceHelper() : 59*cdf0e10cSrcweir mpSpriteCanvas( NULL ), 60*cdf0e10cSrcweir mpBufferSurface(), 61*cdf0e10cSrcweir maSize(), 62*cdf0e10cSrcweir mbFullScreen( false ) 63*cdf0e10cSrcweir {} 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir void SpriteDeviceHelper::init( Window& rOutputWindow, 66*cdf0e10cSrcweir SpriteCanvas& rSpriteCanvas, 67*cdf0e10cSrcweir const ::basegfx::B2ISize& rSize, 68*cdf0e10cSrcweir bool bFullscreen ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir DeviceHelper::init(rSpriteCanvas, 71*cdf0e10cSrcweir rOutputWindow); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir mpSpriteCanvas = &rSpriteCanvas; 74*cdf0e10cSrcweir mbFullScreen = bFullscreen; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir setSize( rSize ); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir void SpriteDeviceHelper::disposing() 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir // release all references 82*cdf0e10cSrcweir mpBufferSurface.reset(); 83*cdf0e10cSrcweir mpSpriteCanvas = NULL; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir ::sal_Int32 SpriteDeviceHelper::createBuffers( ::sal_Int32 /*nBuffers*/ ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir // TODO(F3): implement XBufferStrategy interface. For now, we 89*cdf0e10cSrcweir // _always_ will have exactly one backbuffer 90*cdf0e10cSrcweir return 1; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir void SpriteDeviceHelper::destroyBuffers() 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir // TODO(F3): implement XBufferStrategy interface. For now, we 96*cdf0e10cSrcweir // _always_ will have exactly one backbuffer 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir ::sal_Bool SpriteDeviceHelper::showBuffer( bool, ::sal_Bool ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas"); 102*cdf0e10cSrcweir return sal_False; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir ::sal_Bool SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas"); 108*cdf0e10cSrcweir return sal_False; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir uno::Any SpriteDeviceHelper::isAccelerated() const 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir return ::com::sun::star::uno::makeAny(true); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir uno::Any SpriteDeviceHelper::getDeviceHandle() const 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir return DeviceHelper::getDeviceHandle(); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir uno::Any SpriteDeviceHelper::getSurfaceHandle() const 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir return DeviceHelper::getSurfaceHandle(); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir void SpriteDeviceHelper::setSize( const ::basegfx::B2ISize& rSize ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir OSL_TRACE("SpriteDeviceHelper::setSize(): device size %d x %d", rSize.getX(), rSize.getY() ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir if( !mpSpriteCanvas ) 131*cdf0e10cSrcweir return; // disposed 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir DeviceHelper::setSize(rSize); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir if( mpBufferSurface && maSize != rSize ) 136*cdf0e10cSrcweir mpBufferSurface.reset(); 137*cdf0e10cSrcweir if( !mpBufferSurface ) 138*cdf0e10cSrcweir mpBufferSurface = getWindowSurface()->getSimilar( 139*cdf0e10cSrcweir CAIRO_CONTENT_COLOR, 140*cdf0e10cSrcweir rSize.getX(), rSize.getY() ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir if( maSize != rSize ) 143*cdf0e10cSrcweir maSize = rSize; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir mpSpriteCanvas->setSizePixel( maSize ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir const ::basegfx::B2ISize& SpriteDeviceHelper::getSizePixel() 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir return maSize; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir setSize( ::basegfx::B2ISize(rBounds.Width, rBounds.Height) ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::getSurface() 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir return mpBufferSurface; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::getBufferSurface() 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir return mpBufferSurface; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::getWindowSurface() 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir return DeviceHelper::getSurface(); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, Content aContent ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir if( mpBufferSurface ) 176*cdf0e10cSrcweir return mpBufferSurface->getSimilar( aContent, rSize.getX(), rSize.getY() ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir return SurfaceSharedPtr(); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::createSurface( BitmapSystemData& rData, const Size& rSize ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir if( getOutputDevice() ) 184*cdf0e10cSrcweir return createBitmapSurface( *getOutputDevice(), rData, rSize ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir return SurfaceSharedPtr(); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir /** SpriteDeviceHelper::flush Flush the platform native window 191*cdf0e10cSrcweir * 192*cdf0e10cSrcweir * Flushes the window by using the internally stored mpSysData. 193*cdf0e10cSrcweir * 194*cdf0e10cSrcweir **/ 195*cdf0e10cSrcweir void SpriteDeviceHelper::flush() 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir SurfaceSharedPtr pWinSurface=getWindowSurface(); 198*cdf0e10cSrcweir if( pWinSurface ) 199*cdf0e10cSrcweir pWinSurface->flush(); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202