1*25ea7f45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25ea7f45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25ea7f45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25ea7f45SAndrew Rist * distributed with this work for additional information 6*25ea7f45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25ea7f45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25ea7f45SAndrew Rist * "License"); you may not use this file except in compliance 9*25ea7f45SAndrew Rist * with the License. You may obtain a copy of the License at 10*25ea7f45SAndrew Rist * 11*25ea7f45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*25ea7f45SAndrew Rist * 13*25ea7f45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25ea7f45SAndrew Rist * software distributed under the License is distributed on an 15*25ea7f45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25ea7f45SAndrew Rist * KIND, either express or implied. See the License for the 17*25ea7f45SAndrew Rist * specific language governing permissions and limitations 18*25ea7f45SAndrew Rist * under the License. 19*25ea7f45SAndrew Rist * 20*25ea7f45SAndrew Rist *************************************************************/ 21*25ea7f45SAndrew Rist 22*25ea7f45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_canvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <ctype.h> // don't ask. msdev breaks otherwise... 28cdf0e10cSrcweir #include <canvas/debug.hxx> 29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 30cdf0e10cSrcweir #include <tools/diagnose_ex.h> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <canvas/canvastools.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <osl/mutex.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 37cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 38cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 39cdf0e10cSrcweir #include <com/sun/star/lang/NoSupportException.hpp> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 42cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 43cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 44cdf0e10cSrcweir #include <comphelper/servicedecl.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 47cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 48cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 49cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include "dx_winstuff.hxx" 52cdf0e10cSrcweir #include "dx_spritecanvas.hxx" 53cdf0e10cSrcweir 54cdf0e10cSrcweir #if DIRECTX_VERSION < 0x0900 55cdf0e10cSrcweir # define CANVAS_TECH "DX5" 56cdf0e10cSrcweir #else 57cdf0e10cSrcweir # define CANVAS_TECH "DX9" 58cdf0e10cSrcweir #endif 59cdf0e10cSrcweir 60cdf0e10cSrcweir #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas." CANVAS_TECH 61cdf0e10cSrcweir #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas." CANVAS_TECH 62cdf0e10cSrcweir 63cdf0e10cSrcweir 64cdf0e10cSrcweir using namespace ::com::sun::star; 65cdf0e10cSrcweir 66cdf0e10cSrcweir namespace dxcanvas 67cdf0e10cSrcweir { SpriteCanvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)68cdf0e10cSrcweir SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments, 69cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& rxContext ) : 70cdf0e10cSrcweir maArguments(aArguments), 71cdf0e10cSrcweir mxComponentContext( rxContext ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir } 74cdf0e10cSrcweir initialize()75cdf0e10cSrcweir void SpriteCanvas::initialize() 76cdf0e10cSrcweir { 77cdf0e10cSrcweir // #i64742# Only call initialize when not in probe mode 78cdf0e10cSrcweir if( maArguments.getLength() == 0 ) 79cdf0e10cSrcweir return; 80cdf0e10cSrcweir 81cdf0e10cSrcweir VERBOSE_TRACE( "SpriteCanvas::initialize called" ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir /* aArguments: 84cdf0e10cSrcweir 0: ptr to creating instance (Window or VirtualDevice) 85cdf0e10cSrcweir 1: SystemEnvData as a streamed Any (or empty for VirtualDevice) 86cdf0e10cSrcweir 2: current bounds of creating instance 87cdf0e10cSrcweir 3: bool, denoting always on top state for Window (always false for VirtualDevice) 88cdf0e10cSrcweir 4: XWindow for creating Window (or empty for VirtualDevice) 89cdf0e10cSrcweir 5: SystemGraphicsData as a streamed Any 90cdf0e10cSrcweir */ 91cdf0e10cSrcweir ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 && 92cdf0e10cSrcweir maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE, 93cdf0e10cSrcweir "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir uno::Reference< awt::XWindow > xParentWindow; 96cdf0e10cSrcweir maArguments[4] >>= xParentWindow; 97cdf0e10cSrcweir Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 98cdf0e10cSrcweir if( !pParentWindow ) 99cdf0e10cSrcweir throw lang::NoSupportException( 100cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 101cdf0e10cSrcweir "Parent window not VCL window, or canvas out-of-process!")), 102cdf0e10cSrcweir NULL); 103cdf0e10cSrcweir 104cdf0e10cSrcweir awt::Rectangle aRect; 105cdf0e10cSrcweir maArguments[2] >>= aRect; 106cdf0e10cSrcweir 107cdf0e10cSrcweir sal_Bool bIsFullscreen( sal_False ); 108cdf0e10cSrcweir maArguments[3] >>= bIsFullscreen; 109cdf0e10cSrcweir 110cdf0e10cSrcweir // setup helper 111cdf0e10cSrcweir maDeviceHelper.init( *pParentWindow, 112cdf0e10cSrcweir *this, 113cdf0e10cSrcweir aRect, 114cdf0e10cSrcweir bIsFullscreen ); 115cdf0e10cSrcweir maCanvasHelper.init( *this, 116cdf0e10cSrcweir maRedrawManager, 117cdf0e10cSrcweir maDeviceHelper.getRenderModule(), 118cdf0e10cSrcweir maDeviceHelper.getSurfaceProxy(), 119cdf0e10cSrcweir maDeviceHelper.getBackBuffer(), 120cdf0e10cSrcweir ::basegfx::B2ISize() ); 121cdf0e10cSrcweir maArguments.realloc(0); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir disposing()124cdf0e10cSrcweir void SAL_CALL SpriteCanvas::disposing() 125cdf0e10cSrcweir { 126cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 127cdf0e10cSrcweir 128cdf0e10cSrcweir mxComponentContext.clear(); 129cdf0e10cSrcweir 130cdf0e10cSrcweir // forward to parent 131cdf0e10cSrcweir SpriteCanvasBaseT::disposing(); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir showBuffer(::sal_Bool bUpdateAll)134cdf0e10cSrcweir ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 139cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 140cdf0e10cSrcweir // been updated (caller should try again later) 141cdf0e10cSrcweir return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir switchBuffer(::sal_Bool bUpdateAll)144cdf0e10cSrcweir ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 147cdf0e10cSrcweir 148cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 149cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 150cdf0e10cSrcweir // been updated (caller should try again later) 151cdf0e10cSrcweir return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir updateScreen(sal_Bool bUpdateAll)154cdf0e10cSrcweir sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir // avoid repaints on hidden window (hidden: not mapped to 159cdf0e10cSrcweir // screen). Return failure, since the screen really has _not_ 160cdf0e10cSrcweir // been updated (caller should try again later) 161cdf0e10cSrcweir return !mbIsVisible ? false : maCanvasHelper.updateScreen( 162cdf0e10cSrcweir ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds), 163cdf0e10cSrcweir bUpdateAll, 164cdf0e10cSrcweir mbSurfaceDirty ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir getServiceName()167cdf0e10cSrcweir ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME ) ); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir getRenderModule() const172cdf0e10cSrcweir const IDXRenderModuleSharedPtr& SpriteCanvas::getRenderModule() const 173cdf0e10cSrcweir { 174cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir return maDeviceHelper.getRenderModule(); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir getBackBuffer() const179cdf0e10cSrcweir const DXSurfaceBitmapSharedPtr& SpriteCanvas::getBackBuffer() const 180cdf0e10cSrcweir { 181cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 182cdf0e10cSrcweir 183cdf0e10cSrcweir return maDeviceHelper.getBackBuffer(); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir getBitmap() const186cdf0e10cSrcweir IBitmapSharedPtr SpriteCanvas::getBitmap() const 187cdf0e10cSrcweir { 188cdf0e10cSrcweir return maDeviceHelper.getBackBuffer(); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir initCanvas(SpriteCanvas * pCanvas)191cdf0e10cSrcweir static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas)); 194cdf0e10cSrcweir pCanvas->initialize(); 195cdf0e10cSrcweir return xRet; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir namespace sdecl = comphelper::service_decl; 199cdf0e10cSrcweir sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas); 200cdf0e10cSrcweir const sdecl::ServiceDecl dxSpriteCanvasDecl( 201cdf0e10cSrcweir serviceImpl, 202cdf0e10cSrcweir SPRITECANVAS_IMPLEMENTATION_NAME, 203cdf0e10cSrcweir SPRITECANVAS_SERVICE_NAME ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // The C shared lib entry points 207cdf0e10cSrcweir COMPHELPER_SERVICEDECL_EXPORTS1(dxcanvas::dxSpriteCanvasDecl); 208