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 <ctype.h> // don't ask. msdev breaks otherwise... 32*cdf0e10cSrcweir #include <canvas/debug.hxx> 33*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 34*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <canvas/canvastools.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <osl/mutex.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/lang/NoSupportException.hpp> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 46*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 47*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 48*cdf0e10cSrcweir #include <comphelper/servicedecl.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 51*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 52*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 53*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include "dx_winstuff.hxx" 56*cdf0e10cSrcweir #include "dx_spritecanvas.hxx" 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #if DIRECTX_VERSION < 0x0900 59*cdf0e10cSrcweir # define CANVAS_TECH "DX5" 60*cdf0e10cSrcweir #else 61*cdf0e10cSrcweir # define CANVAS_TECH "DX9" 62*cdf0e10cSrcweir #endif 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas." CANVAS_TECH 65*cdf0e10cSrcweir #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas." CANVAS_TECH 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir using namespace ::com::sun::star; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir namespace dxcanvas 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments, 73*cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& rxContext ) : 74*cdf0e10cSrcweir maArguments(aArguments), 75*cdf0e10cSrcweir mxComponentContext( rxContext ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir void SpriteCanvas::initialize() 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir // #i64742# Only call initialize when not in probe mode 82*cdf0e10cSrcweir if( maArguments.getLength() == 0 ) 83*cdf0e10cSrcweir return; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir VERBOSE_TRACE( "SpriteCanvas::initialize called" ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /* aArguments: 88*cdf0e10cSrcweir 0: ptr to creating instance (Window or VirtualDevice) 89*cdf0e10cSrcweir 1: SystemEnvData as a streamed Any (or empty for VirtualDevice) 90*cdf0e10cSrcweir 2: current bounds of creating instance 91*cdf0e10cSrcweir 3: bool, denoting always on top state for Window (always false for VirtualDevice) 92*cdf0e10cSrcweir 4: XWindow for creating Window (or empty for VirtualDevice) 93*cdf0e10cSrcweir 5: SystemGraphicsData as a streamed Any 94*cdf0e10cSrcweir */ 95*cdf0e10cSrcweir ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 && 96*cdf0e10cSrcweir maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE, 97*cdf0e10cSrcweir "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir uno::Reference< awt::XWindow > xParentWindow; 100*cdf0e10cSrcweir maArguments[4] >>= xParentWindow; 101*cdf0e10cSrcweir Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 102*cdf0e10cSrcweir if( !pParentWindow ) 103*cdf0e10cSrcweir throw lang::NoSupportException( 104*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 105*cdf0e10cSrcweir "Parent window not VCL window, or canvas out-of-process!")), 106*cdf0e10cSrcweir NULL); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir awt::Rectangle aRect; 109*cdf0e10cSrcweir maArguments[2] >>= aRect; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir sal_Bool bIsFullscreen( sal_False ); 112*cdf0e10cSrcweir maArguments[3] >>= bIsFullscreen; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // setup helper 115*cdf0e10cSrcweir maDeviceHelper.init( *pParentWindow, 116*cdf0e10cSrcweir *this, 117*cdf0e10cSrcweir aRect, 118*cdf0e10cSrcweir bIsFullscreen ); 119*cdf0e10cSrcweir maCanvasHelper.init( *this, 120*cdf0e10cSrcweir maRedrawManager, 121*cdf0e10cSrcweir maDeviceHelper.getRenderModule(), 122*cdf0e10cSrcweir maDeviceHelper.getSurfaceProxy(), 123*cdf0e10cSrcweir maDeviceHelper.getBackBuffer(), 124*cdf0e10cSrcweir ::basegfx::B2ISize() ); 125*cdf0e10cSrcweir maArguments.realloc(0); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir void SAL_CALL SpriteCanvas::disposing() 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir mxComponentContext.clear(); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // forward to parent 135*cdf0e10cSrcweir SpriteCanvasBaseT::disposing(); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 143*cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 144*cdf0e10cSrcweir // been updated (caller should try again later) 145*cdf0e10cSrcweir return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 153*cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 154*cdf0e10cSrcweir // been updated (caller should try again later) 155*cdf0e10cSrcweir return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 163*cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 164*cdf0e10cSrcweir // been updated (caller should try again later) 165*cdf0e10cSrcweir return !mbIsVisible ? false : maCanvasHelper.updateScreen( 166*cdf0e10cSrcweir ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds), 167*cdf0e10cSrcweir bUpdateAll, 168*cdf0e10cSrcweir mbSurfaceDirty ); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME ) ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir const IDXRenderModuleSharedPtr& SpriteCanvas::getRenderModule() const 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir return maDeviceHelper.getRenderModule(); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir const DXSurfaceBitmapSharedPtr& SpriteCanvas::getBackBuffer() const 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir return maDeviceHelper.getBackBuffer(); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir IBitmapSharedPtr SpriteCanvas::getBitmap() const 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir return maDeviceHelper.getBackBuffer(); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas)); 198*cdf0e10cSrcweir pCanvas->initialize(); 199*cdf0e10cSrcweir return xRet; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl; 203*cdf0e10cSrcweir sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas); 204*cdf0e10cSrcweir const sdecl::ServiceDecl dxSpriteCanvasDecl( 205*cdf0e10cSrcweir serviceImpl, 206*cdf0e10cSrcweir SPRITECANVAS_IMPLEMENTATION_NAME, 207*cdf0e10cSrcweir SPRITECANVAS_SERVICE_NAME ); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // The C shared lib entry points 211*cdf0e10cSrcweir COMPHELPER_SERVICEDECL_EXPORTS1(dxcanvas::dxSpriteCanvasDecl); 212