CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / canvas / source / directx / dx_spritecanvas.cxx
blob43350287d92ae1f89e7099e54ceb23fee1e5a793
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <ctype.h> // don't ask. msdev breaks otherwise...
32 #include <canvas/debug.hxx>
33 #include <canvas/verbosetrace.hxx>
34 #include <tools/diagnose_ex.h>
36 #include <canvas/canvastools.hxx>
38 #include <osl/mutex.hxx>
40 #include <com/sun/star/registry/XRegistryKey.hpp>
41 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <com/sun/star/lang/NoSupportException.hpp>
45 #include <toolkit/helper/vclunohelper.hxx>
46 #include <cppuhelper/factory.hxx>
47 #include <cppuhelper/implementationentry.hxx>
48 #include <comphelper/servicedecl.hxx>
50 #include <basegfx/matrix/b2dhommatrix.hxx>
51 #include <basegfx/point/b2dpoint.hxx>
52 #include <basegfx/tools/canvastools.hxx>
53 #include <basegfx/numeric/ftools.hxx>
55 #include "dx_winstuff.hxx"
56 #include "dx_spritecanvas.hxx"
58 #if DIRECTX_VERSION < 0x0900
59 # define CANVAS_TECH "DX5"
60 #else
61 # define CANVAS_TECH "DX9"
62 #endif
64 #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas." CANVAS_TECH
65 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas." CANVAS_TECH
68 using namespace ::com::sun::star;
70 namespace dxcanvas
72 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
73 const uno::Reference< uno::XComponentContext >& rxContext ) :
74 maArguments(aArguments),
75 mxComponentContext( rxContext )
79 void SpriteCanvas::initialize()
81 // #i64742# Only call initialize when not in probe mode
82 if( maArguments.getLength() == 0 )
83 return;
85 VERBOSE_TRACE( "SpriteCanvas::initialize called" );
87 /* aArguments:
88 0: ptr to creating instance (Window or VirtualDevice)
89 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
90 2: current bounds of creating instance
91 3: bool, denoting always on top state for Window (always false for VirtualDevice)
92 4: XWindow for creating Window (or empty for VirtualDevice)
93 5: SystemGraphicsData as a streamed Any
95 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
96 maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
97 "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
99 uno::Reference< awt::XWindow > xParentWindow;
100 maArguments[4] >>= xParentWindow;
101 Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
102 if( !pParentWindow )
103 throw lang::NoSupportException(
104 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
105 "Parent window not VCL window, or canvas out-of-process!")),
106 NULL);
108 awt::Rectangle aRect;
109 maArguments[2] >>= aRect;
111 sal_Bool bIsFullscreen( sal_False );
112 maArguments[3] >>= bIsFullscreen;
114 // setup helper
115 maDeviceHelper.init( *pParentWindow,
116 *this,
117 aRect,
118 bIsFullscreen );
119 maCanvasHelper.init( *this,
120 maRedrawManager,
121 maDeviceHelper.getRenderModule(),
122 maDeviceHelper.getSurfaceProxy(),
123 maDeviceHelper.getBackBuffer(),
124 ::basegfx::B2ISize() );
125 maArguments.realloc(0);
128 void SAL_CALL SpriteCanvas::disposing()
130 ::osl::MutexGuard aGuard( m_aMutex );
132 mxComponentContext.clear();
134 // forward to parent
135 SpriteCanvasBaseT::disposing();
138 ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
140 ::osl::MutexGuard aGuard( m_aMutex );
142 // avoid repaints on hidden window (hidden: not mapped to
143 // screen). Return failure, since the screen really has _not_
144 // been updated (caller should try again later)
145 return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll );
148 ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
150 ::osl::MutexGuard aGuard( m_aMutex );
152 // avoid repaints on hidden window (hidden: not mapped to
153 // screen). Return failure, since the screen really has _not_
154 // been updated (caller should try again later)
155 return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll );
158 sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
160 ::osl::MutexGuard aGuard( m_aMutex );
162 // avoid repaints on hidden window (hidden: not mapped to
163 // screen). Return failure, since the screen really has _not_
164 // been updated (caller should try again later)
165 return !mbIsVisible ? false : maCanvasHelper.updateScreen(
166 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
167 bUpdateAll,
168 mbSurfaceDirty );
171 ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException)
173 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME ) );
176 const IDXRenderModuleSharedPtr& SpriteCanvas::getRenderModule() const
178 ::osl::MutexGuard aGuard( m_aMutex );
180 return maDeviceHelper.getRenderModule();
183 const DXSurfaceBitmapSharedPtr& SpriteCanvas::getBackBuffer() const
185 ::osl::MutexGuard aGuard( m_aMutex );
187 return maDeviceHelper.getBackBuffer();
190 IBitmapSharedPtr SpriteCanvas::getBitmap() const
192 return maDeviceHelper.getBackBuffer();
195 static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
197 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
198 pCanvas->initialize();
199 return xRet;
202 namespace sdecl = comphelper::service_decl;
203 sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas);
204 const sdecl::ServiceDecl dxSpriteCanvasDecl(
205 serviceImpl,
206 SPRITECANVAS_IMPLEMENTATION_NAME,
207 SPRITECANVAS_SERVICE_NAME );
210 // The C shared lib entry points
211 COMPHELPER_SERVICEDECL_EXPORTS1(dxcanvas::dxSpriteCanvasDecl);