Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / directx / dx_spritedevicehelper.cxx
blob1581d52026203c49e004f14a26c3a4268ca53b36
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ctype.h>
21 #include <vcl/window.hxx>
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <canvas/canvastools.hxx>
25 #include <tools/diagnose_ex.h>
27 #include <osl/mutex.hxx>
28 #include <cppuhelper/compbase1.hxx>
30 #include <com/sun/star/lang/NoSupportException.hpp>
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include <basegfx/tools/canvastools.hxx>
33 #include "dx_linepolypolygon.hxx"
34 #include "dx_spritecanvas.hxx"
35 #include "dx_canvasbitmap.hxx"
36 #include "dx_spritedevicehelper.hxx"
37 #include "dx_winstuff.hxx"
39 #include <vcl/sysdata.hxx>
41 using namespace ::com::sun::star;
43 namespace dxcanvas
45 SpriteDeviceHelper::SpriteDeviceHelper() :
46 DeviceHelper(),
47 mpSpriteCanvas( NULL ),
48 mpSurfaceProxyManager(),
49 mpRenderModule(),
50 mpBackBuffer()
54 void SpriteDeviceHelper::init( vcl::Window& rWindow,
55 SpriteCanvas& rSpriteCanvas,
56 const awt::Rectangle& rRect,
57 bool /*bFullscreen*/ )
59 // #i60490# ensure backbuffer has sensible minimal size
60 const sal_Int32 w( ::std::max(sal_Int32(1),sal_Int32(rRect.Width)));
61 const sal_Int32 h( ::std::max(sal_Int32(1),sal_Int32(rRect.Height)));
63 rSpriteCanvas.setWindow(
64 uno::Reference<awt::XWindow2>(
65 VCLUnoHelper::GetInterface(&rWindow),
66 uno::UNO_QUERY_THROW) );
68 const SystemEnvData *pData = rWindow.GetSystemData();
69 const HWND hWnd = reinterpret_cast<HWND>(pData->hWnd);
70 if( !IsWindow( hWnd ) )
71 throw lang::NoSupportException( "Passed window has invalid system window, or canvas out-of-process!" );
73 mpSpriteCanvas = &rSpriteCanvas;
75 try
77 // setup directx rendermodule
78 mpRenderModule = createRenderModule( rWindow );
80 catch (...) {
82 throw lang::NoSupportException( "Could not create DirectX device!",
83 static_cast< ::cppu::OWeakObject* >(&rSpriteCanvas) );
86 // create the surfaceproxy manager
87 mpSurfaceProxyManager = ::canvas::createSurfaceProxyManager( mpRenderModule );
89 // #i60490# ensure backbuffer has sensible minimal size
90 mpBackBuffer.reset(new DXSurfaceBitmap(
91 ::basegfx::B2ISize(w,h),
92 mpSurfaceProxyManager,
93 mpRenderModule,
94 false));
96 // Assumes: SystemChildWindow() has CS_OWNDC
97 DeviceHelper::init(GetDC(mpRenderModule->getHWND()),rWindow.GetOutDev(), rSpriteCanvas);
100 void SpriteDeviceHelper::disposing()
102 // release all references
103 mpBackBuffer.reset();
104 mpSurfaceProxyManager.reset();
105 mpRenderModule.reset();
106 mpSpriteCanvas = NULL;
108 DeviceHelper::disposing();
111 uno::Reference< rendering::XBitmap > SpriteDeviceHelper::createCompatibleBitmap(
112 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
113 const geometry::IntegerSize2D& size )
115 if( !getDevice() )
116 return uno::Reference< rendering::XBitmap >(); // we're disposed
118 DXSurfaceBitmapSharedPtr pBitmap(
119 new DXSurfaceBitmap(
120 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
121 mpSurfaceProxyManager,
122 mpRenderModule,
123 false));
125 // create a 24bit RGB system memory surface
126 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,getDevice()));
129 uno::Reference< rendering::XVolatileBitmap > SpriteDeviceHelper::createVolatileBitmap(
130 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
131 const geometry::IntegerSize2D& /*size*/ )
133 return uno::Reference< rendering::XVolatileBitmap >();
136 uno::Reference< rendering::XBitmap > SpriteDeviceHelper::createCompatibleAlphaBitmap(
137 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
138 const geometry::IntegerSize2D& size )
140 if( !getDevice() )
141 return uno::Reference< rendering::XBitmap >(); // we're disposed
143 DXSurfaceBitmapSharedPtr pBitmap(
144 new DXSurfaceBitmap(
145 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
146 mpSurfaceProxyManager,
147 mpRenderModule,
148 true));
150 // create a 32bit ARGB system memory surface
151 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,getDevice()));
154 uno::Reference< rendering::XVolatileBitmap > SpriteDeviceHelper::createVolatileAlphaBitmap(
155 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
156 const geometry::IntegerSize2D& /*size*/ )
158 return uno::Reference< rendering::XVolatileBitmap >();
161 bool SpriteDeviceHelper::hasFullScreenMode()
163 // TODO(F3): offer fullscreen mode the XCanvas way
164 return false;
167 bool SpriteDeviceHelper::enterFullScreenMode( bool /*bEnter*/ )
169 // TODO(F3): offer fullscreen mode the XCanvas way
170 return false;
173 void SpriteDeviceHelper::destroyBuffers()
175 // TODO(F3): implement XBufferStrategy interface. For now, we
176 // _always_ will have exactly one backbuffer
179 sal_Bool SpriteDeviceHelper::showBuffer( bool, sal_Bool )
181 OSL_FAIL("Not supposed to be called, handled by SpriteCanvas");
182 return sal_False;
185 sal_Bool SpriteDeviceHelper::switchBuffer( bool, sal_Bool )
187 OSL_FAIL("Not supposed to be called, handled by SpriteCanvas");
188 return sal_False;
191 uno::Any SpriteDeviceHelper::isAccelerated() const
193 return ::com::sun::star::uno::makeAny(true);
196 void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
198 // #i60490# ensure backbuffer has sensible minimal size
199 const sal_Int32 x(rBounds.X);
200 const sal_Int32 y(rBounds.Y);
201 const sal_Int32 w(::std::max(sal_Int32(1),sal_Int32(rBounds.Width)));
202 const sal_Int32 h(::std::max(sal_Int32(1),sal_Int32(rBounds.Height)));
204 if( mpRenderModule )
205 mpRenderModule->resize(::basegfx::B2IRange(x,y,x+w,y+h));
207 resizeBackBuffer(::basegfx::B2ISize(w,h));
210 void SpriteDeviceHelper::resizeBackBuffer( const ::basegfx::B2ISize& rNewSize )
212 // disposed?
213 if(!(mpBackBuffer))
214 return;
216 mpBackBuffer->resize(rNewSize);
217 mpBackBuffer->clear();
220 HWND SpriteDeviceHelper::getHwnd() const
222 if( mpRenderModule )
223 return mpRenderModule->getHWND();
224 else
225 return 0;
228 void SpriteDeviceHelper::dumpScreenContent() const
230 if( mpRenderModule )
231 mpRenderModule->screenShot();
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */