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 #include <canvas/canvastools.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <osl/mutex.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 43*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 44*cdf0e10cSrcweir #include <comphelper/servicedecl.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 47*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 48*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 49*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include "null_spritecanvas.hxx" 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace ::com::sun::star; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.NullCanvas" 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir namespace nullcanvas 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments, 61*cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& rxContext ) : 62*cdf0e10cSrcweir maArguments(aArguments), 63*cdf0e10cSrcweir mxComponentContext( rxContext ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir void SpriteCanvas::initialize() 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir // #i64742# Only call initialize when not in probe mode 70*cdf0e10cSrcweir if( maArguments.getLength() == 0 ) 71*cdf0e10cSrcweir return; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir VERBOSE_TRACE( "SpriteCanvas::initialize called" ); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir // At index 1, we expect a system window handle here, 76*cdf0e10cSrcweir // containing a pointer to a valid window, on which to output 77*cdf0e10cSrcweir // At index 2, we expect the current window bound rect 78*cdf0e10cSrcweir ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 && 79*cdf0e10cSrcweir maArguments[1].getValueTypeClass() == uno::TypeClass_LONG, 80*cdf0e10cSrcweir "SpriteCanvas::initialize: wrong number of arguments, or wrong types" ); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir awt::Rectangle aRect; 83*cdf0e10cSrcweir maArguments[2] >>= aRect; 84*cdf0e10cSrcweir const ::basegfx::B2ISize aSize(aRect.Width, 85*cdf0e10cSrcweir aRect.Height); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir sal_Bool bIsFullscreen( sal_False ); 88*cdf0e10cSrcweir maArguments[3] >>= bIsFullscreen; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // setup helper 91*cdf0e10cSrcweir maDeviceHelper.init( *this, 92*cdf0e10cSrcweir aSize, 93*cdf0e10cSrcweir bIsFullscreen ); 94*cdf0e10cSrcweir maCanvasHelper.init( maRedrawManager, 95*cdf0e10cSrcweir *this, 96*cdf0e10cSrcweir aSize, 97*cdf0e10cSrcweir false ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir maArguments.realloc(0); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir void SAL_CALL SpriteCanvas::disposing() 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir mxComponentContext.clear(); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir // forward to parent 109*cdf0e10cSrcweir SpriteCanvasBaseT::disposing(); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 117*cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 118*cdf0e10cSrcweir // been updated (caller should try again later) 119*cdf0e10cSrcweir return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll ); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 127*cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 128*cdf0e10cSrcweir // been updated (caller should try again later) 129*cdf0e10cSrcweir return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll ); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 137*cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 138*cdf0e10cSrcweir // been updated (caller should try again later) 139*cdf0e10cSrcweir return !mbIsVisible ? false : maCanvasHelper.updateScreen( 140*cdf0e10cSrcweir ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds), 141*cdf0e10cSrcweir bUpdateAll, 142*cdf0e10cSrcweir mbSurfaceDirty ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas)); 153*cdf0e10cSrcweir pCanvas->initialize(); 154*cdf0e10cSrcweir return xRet; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl; 158*cdf0e10cSrcweir sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas); 159*cdf0e10cSrcweir const sdecl::ServiceDecl nullCanvasDecl( 160*cdf0e10cSrcweir serviceImpl, 161*cdf0e10cSrcweir "com.sun.star.comp.rendering.NullCanvas", 162*cdf0e10cSrcweir SERVICE_NAME ); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // The C shared lib entry points 166*cdf0e10cSrcweir COMPHELPER_SERVICEDECL_EXPORTS1(nullcanvas::nullCanvasDecl) 167