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_spritedevicehelper.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 #include <ctype.h> // don't ask. msdev breaks otherwise...
32 #include <vcl/window.hxx>
33 #include <canvas/debug.hxx>
34 #include <canvas/verbosetrace.hxx>
35 #include <canvas/canvastools.hxx>
36 #include <tools/diagnose_ex.h>
38 #include <osl/mutex.hxx>
39 #include <cppuhelper/compbase1.hxx>
41 #include <com/sun/star/lang/NoSupportException.hpp>
42 #include <toolkit/helper/vclunohelper.hxx>
43 #include <basegfx/tools/canvastools.hxx>
44 #include "dx_linepolypolygon.hxx"
45 #include "dx_spritecanvas.hxx"
46 #include "dx_canvasbitmap.hxx"
47 #include "dx_spritedevicehelper.hxx"
52 #include "dx_winstuff.hxx"
55 #include <vcl/sysdata.hxx>
57 using namespace ::com::sun::star
;
61 SpriteDeviceHelper::SpriteDeviceHelper() :
63 mpSpriteCanvas( NULL
),
64 mpSurfaceProxyManager(),
70 void SpriteDeviceHelper::init( Window
& rWindow
,
71 SpriteCanvas
& rSpriteCanvas
,
72 const awt::Rectangle
& rRect
,
73 bool /*bFullscreen*/ )
75 // #i60490# ensure backbuffer has sensible minimal size
76 const sal_Int32
w( ::std::max(sal_Int32(1),sal_Int32(rRect
.Width
)));
77 const sal_Int32
h( ::std::max(sal_Int32(1),sal_Int32(rRect
.Height
)));
79 rSpriteCanvas
.setWindow(
80 uno::Reference
<awt::XWindow2
>(
81 VCLUnoHelper::GetInterface(&rWindow
),
82 uno::UNO_QUERY_THROW
) );
84 const SystemEnvData
*pData
= rWindow
.GetSystemData();
85 const HWND hWnd
= reinterpret_cast<HWND
>(pData
->hWnd
);
86 if( !IsWindow( hWnd
) )
87 throw lang::NoSupportException(
88 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
89 "Passed window has invalid system window, or canvas out-of-process!")),
92 mpSpriteCanvas
= &rSpriteCanvas
;
96 // setup directx rendermodule
97 mpRenderModule
= createRenderModule( rWindow
);
101 throw lang::NoSupportException(
102 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
103 "Could not create DirectX device!") ),
104 static_cast< ::cppu::OWeakObject
* >(&rSpriteCanvas
) );
107 // create the surfaceproxy manager
108 mpSurfaceProxyManager
= ::canvas::createSurfaceProxyManager( mpRenderModule
);
110 // #i60490# ensure backbuffer has sensible minimal size
111 mpBackBuffer
.reset(new DXSurfaceBitmap(
112 ::basegfx::B2ISize(w
,h
),
113 mpSurfaceProxyManager
,
117 // Assumes: SystemChildWindow() has CS_OWNDC
118 DeviceHelper::init(GetDC(mpRenderModule
->getHWND()),
122 void SpriteDeviceHelper::disposing()
124 // release all references
125 mpBackBuffer
.reset();
126 mpSurfaceProxyManager
.reset();
127 mpRenderModule
.reset();
128 mpSpriteCanvas
= NULL
;
130 DeviceHelper::disposing();
133 uno::Reference
< rendering::XBitmap
> SpriteDeviceHelper::createCompatibleBitmap(
134 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
135 const geometry::IntegerSize2D
& size
)
138 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
140 DXSurfaceBitmapSharedPtr
pBitmap(
142 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size
),
143 mpSurfaceProxyManager
,
147 // create a 24bit RGB system memory surface
148 return uno::Reference
< rendering::XBitmap
>(new CanvasBitmap(pBitmap
,getDevice()));
151 uno::Reference
< rendering::XVolatileBitmap
> SpriteDeviceHelper::createVolatileBitmap(
152 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
153 const geometry::IntegerSize2D
& /*size*/ )
155 return uno::Reference
< rendering::XVolatileBitmap
>();
158 uno::Reference
< rendering::XBitmap
> SpriteDeviceHelper::createCompatibleAlphaBitmap(
159 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
160 const geometry::IntegerSize2D
& size
)
163 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
165 DXSurfaceBitmapSharedPtr
pBitmap(
167 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size
),
168 mpSurfaceProxyManager
,
172 // create a 32bit ARGB system memory surface
173 return uno::Reference
< rendering::XBitmap
>(new CanvasBitmap(pBitmap
,getDevice()));
176 uno::Reference
< rendering::XVolatileBitmap
> SpriteDeviceHelper::createVolatileAlphaBitmap(
177 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
178 const geometry::IntegerSize2D
& /*size*/ )
180 return uno::Reference
< rendering::XVolatileBitmap
>();
183 sal_Bool
SpriteDeviceHelper::hasFullScreenMode()
185 // TODO(F3): offer fullscreen mode the XCanvas way
189 sal_Bool
SpriteDeviceHelper::enterFullScreenMode( sal_Bool
/*bEnter*/ )
191 // TODO(F3): offer fullscreen mode the XCanvas way
195 ::sal_Int32
SpriteDeviceHelper::createBuffers( ::sal_Int32
/*nBuffers*/ )
197 // TODO(F3): implement XBufferStrategy interface. For now, we
198 // _always_ will have exactly one backbuffer
202 void SpriteDeviceHelper::destroyBuffers()
204 // TODO(F3): implement XBufferStrategy interface. For now, we
205 // _always_ will have exactly one backbuffer
208 ::sal_Bool
SpriteDeviceHelper::showBuffer( bool, ::sal_Bool
)
210 OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
214 ::sal_Bool
SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool
)
216 OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
220 uno::Any
SpriteDeviceHelper::isAccelerated() const
222 return ::com::sun::star::uno::makeAny(true);
225 void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle
& rBounds
)
227 // #i60490# ensure backbuffer has sensible minimal size
228 const sal_Int32
x(rBounds
.X
);
229 const sal_Int32
y(rBounds
.Y
);
230 const sal_Int32
w(::std::max(sal_Int32(1),sal_Int32(rBounds
.Width
)));
231 const sal_Int32
h(::std::max(sal_Int32(1),sal_Int32(rBounds
.Height
)));
234 mpRenderModule
->resize(::basegfx::B2IRange(x
,y
,x
+w
,y
+h
));
236 resizeBackBuffer(::basegfx::B2ISize(w
,h
));
239 void SpriteDeviceHelper::resizeBackBuffer( const ::basegfx::B2ISize
& rNewSize
)
245 mpBackBuffer
->resize(rNewSize
);
246 mpBackBuffer
->clear();
249 HWND
SpriteDeviceHelper::getHwnd() const
252 return mpRenderModule
->getHWND();
257 void SpriteDeviceHelper::dumpScreenContent() const
260 mpRenderModule
->screenShot();