1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dx_spritecanvas.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <ctype.h> // don't ask. msdev breaks otherwise...
35 #include <canvas/debug.hxx>
36 #include <canvas/verbosetrace.hxx>
37 #include <tools/diagnose_ex.h>
39 #include <canvas/canvastools.hxx>
41 #include <osl/mutex.hxx>
43 #include <com/sun/star/registry/XRegistryKey.hpp>
44 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
45 #include <com/sun/star/uno/XComponentContext.hpp>
46 #include <com/sun/star/lang/NoSupportException.hpp>
48 #include <toolkit/helper/vclunohelper.hxx>
49 #include <cppuhelper/factory.hxx>
50 #include <cppuhelper/implementationentry.hxx>
51 #include <comphelper/servicedecl.hxx>
53 #include <basegfx/matrix/b2dhommatrix.hxx>
54 #include <basegfx/point/b2dpoint.hxx>
55 #include <basegfx/tools/canvastools.hxx>
56 #include <basegfx/numeric/ftools.hxx>
58 #include "dx_winstuff.hxx"
59 #include "dx_spritecanvas.hxx"
61 #if DIRECTX_VERSION < 0x0900
62 # define CANVAS_TECH "DX5"
64 # define CANVAS_TECH "DX9"
67 #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas." CANVAS_TECH
68 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas." CANVAS_TECH
71 using namespace ::com::sun::star
;
75 SpriteCanvas::SpriteCanvas( const uno::Sequence
< uno::Any
>& aArguments
,
76 const uno::Reference
< uno::XComponentContext
>& rxContext
) :
77 maArguments(aArguments
),
78 mxComponentContext( rxContext
)
82 void SpriteCanvas::initialize()
84 // #i64742# Only call initialize when not in probe mode
85 if( maArguments
.getLength() == 0 )
88 VERBOSE_TRACE( "SpriteCanvas::initialize called" );
91 0: ptr to creating instance (Window or VirtualDevice)
92 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
93 2: current bounds of creating instance
94 3: bool, denoting always on top state for Window (always false for VirtualDevice)
95 4: XWindow for creating Window (or empty for VirtualDevice)
96 5: SystemGraphicsData as a streamed Any
98 ENSURE_ARG_OR_THROW( maArguments
.getLength() >= 5 &&
99 maArguments
[4].getValueTypeClass() == uno::TypeClass_INTERFACE
,
100 "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
102 uno::Reference
< awt::XWindow
> xParentWindow
;
103 maArguments
[4] >>= xParentWindow
;
104 Window
* pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
106 throw lang::NoSupportException(
107 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
108 "Parent window not VCL window, or canvas out-of-process!")),
111 awt::Rectangle aRect
;
112 maArguments
[2] >>= aRect
;
114 sal_Bool
bIsFullscreen( sal_False
);
115 maArguments
[3] >>= bIsFullscreen
;
118 maDeviceHelper
.init( *pParentWindow
,
122 maCanvasHelper
.init( *this,
124 maDeviceHelper
.getRenderModule(),
125 maDeviceHelper
.getSurfaceProxy(),
126 maDeviceHelper
.getBackBuffer(),
127 ::basegfx::B2ISize() );
128 maArguments
.realloc(0);
131 void SAL_CALL
SpriteCanvas::disposing()
133 ::osl::MutexGuard
aGuard( m_aMutex
);
135 mxComponentContext
.clear();
138 SpriteCanvasBaseT::disposing();
141 ::sal_Bool SAL_CALL
SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
143 ::osl::MutexGuard
aGuard( m_aMutex
);
145 // avoid repaints on hidden window (hidden: not mapped to
146 // screen). Return failure, since the screen really has _not_
147 // been updated (caller should try again later)
148 return !mbIsVisible
? false : SpriteCanvasBaseT::showBuffer( bUpdateAll
);
151 ::sal_Bool SAL_CALL
SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
153 ::osl::MutexGuard
aGuard( m_aMutex
);
155 // avoid repaints on hidden window (hidden: not mapped to
156 // screen). Return failure, since the screen really has _not_
157 // been updated (caller should try again later)
158 return !mbIsVisible
? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll
);
161 sal_Bool SAL_CALL
SpriteCanvas::updateScreen( sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
163 ::osl::MutexGuard
aGuard( m_aMutex
);
165 // avoid repaints on hidden window (hidden: not mapped to
166 // screen). Return failure, since the screen really has _not_
167 // been updated (caller should try again later)
168 return !mbIsVisible
? false : maCanvasHelper
.updateScreen(
169 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds
),
174 ::rtl::OUString SAL_CALL
SpriteCanvas::getServiceName( ) throw (uno::RuntimeException
)
176 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME
) );
179 const IDXRenderModuleSharedPtr
& SpriteCanvas::getRenderModule() const
181 ::osl::MutexGuard
aGuard( m_aMutex
);
183 return maDeviceHelper
.getRenderModule();
186 const DXSurfaceBitmapSharedPtr
& SpriteCanvas::getBackBuffer() const
188 ::osl::MutexGuard
aGuard( m_aMutex
);
190 return maDeviceHelper
.getBackBuffer();
193 IBitmapSharedPtr
SpriteCanvas::getBitmap() const
195 return maDeviceHelper
.getBackBuffer();
198 static uno::Reference
<uno::XInterface
> initCanvas( SpriteCanvas
* pCanvas
)
200 uno::Reference
<uno::XInterface
> xRet(static_cast<cppu::OWeakObject
*>(pCanvas
));
201 pCanvas
->initialize();
205 namespace sdecl
= comphelper::service_decl
;
206 sdecl::class_
<SpriteCanvas
, sdecl::with_args
<true> > serviceImpl(&initCanvas
);
207 const sdecl::ServiceDecl
dxSpriteCanvasDecl(
209 SPRITECANVAS_IMPLEMENTATION_NAME
,
210 SPRITECANVAS_SERVICE_NAME
);
213 // The C shared lib entry points
214 COMPHELPER_SERVICEDECL_EXPORTS1(dxcanvas::dxSpriteCanvasDecl
);