1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
24 #include <sal/log.hxx>
26 #include <basegfx/utils/canvastools.hxx>
27 #include <canvas/canvastools.hxx>
28 #include <com/sun/star/lang/NoSupportException.hpp>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <comphelper/diagnose_ex.hxx>
31 #include <vcl/sysdata.hxx>
32 #include <vcl/window.hxx>
34 #include "dx_canvasbitmap.hxx"
35 #include "dx_linepolypolygon.hxx"
36 #include "dx_spritecanvas.hxx"
37 #include "dx_spritedevicehelper.hxx"
38 #include "dx_winstuff.hxx"
41 using namespace ::com::sun::star
;
45 SpriteDeviceHelper::SpriteDeviceHelper() :
47 mpSpriteCanvas( nullptr ),
49 mpSurfaceProxyManager(),
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
;
77 // setup directx rendermodule
78 mpRenderModule
= createRenderModule( rWindow
);
82 throw lang::NoSupportException( "Could not create DirectX device!",
83 rSpriteCanvas
.getXWeak() );
86 // create the surfaceproxy manager
87 mpSurfaceProxyManager
= ::canvas::createSurfaceProxyManager( mpRenderModule
);
89 // #i60490# ensure backbuffer has sensible minimal size
90 mpBackBuffer
= std::make_shared
<DXSurfaceBitmap
>(
91 basegfx::B2ISize(w
,h
),
92 mpSurfaceProxyManager
,
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
= nullptr;
108 DeviceHelper::disposing();
111 uno::Reference
< rendering::XBitmap
> SpriteDeviceHelper::createCompatibleBitmap(
112 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
113 const geometry::IntegerSize2D
& size
)
116 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
118 DXSurfaceBitmapSharedPtr pBitmap
= std::make_shared
<DXSurfaceBitmap
>(
119 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size
),
120 mpSurfaceProxyManager
,
124 // create a 24bit RGB system memory surface
125 return uno::Reference
< rendering::XBitmap
>(new CanvasBitmap(pBitmap
,getDevice()));
128 uno::Reference
< rendering::XVolatileBitmap
> SpriteDeviceHelper::createVolatileBitmap(
129 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
130 const geometry::IntegerSize2D
& /*size*/ )
132 return uno::Reference
< rendering::XVolatileBitmap
>();
135 uno::Reference
< rendering::XBitmap
> SpriteDeviceHelper::createCompatibleAlphaBitmap(
136 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
137 const geometry::IntegerSize2D
& size
)
140 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
142 DXSurfaceBitmapSharedPtr pBitmap
= std::make_shared
<DXSurfaceBitmap
>(
143 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size
),
144 mpSurfaceProxyManager
,
148 // create a 32bit ARGB system memory surface
149 return uno::Reference
< rendering::XBitmap
>(new CanvasBitmap(pBitmap
,getDevice()));
152 uno::Reference
< rendering::XVolatileBitmap
> SpriteDeviceHelper::createVolatileAlphaBitmap(
153 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
154 const geometry::IntegerSize2D
& /*size*/ )
156 return uno::Reference
< rendering::XVolatileBitmap
>();
159 void SpriteDeviceHelper::destroyBuffers()
161 // TODO(F3): implement XBufferStrategy interface. For now, we
162 // _always_ will have exactly one backbuffer
165 bool SpriteDeviceHelper::showBuffer( bool, bool )
167 SAL_WARN("canvas.directx", "Not supposed to be called, handled by SpriteCanvas");
171 bool SpriteDeviceHelper::switchBuffer( bool, bool )
173 SAL_WARN("canvas.directx", "Not supposed to be called, handled by SpriteCanvas");
177 uno::Any
SpriteDeviceHelper::isAccelerated() const
179 return css::uno::Any(true);
182 void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle
& rBounds
)
184 // #i60490# ensure backbuffer has sensible minimal size
185 const sal_Int32
x(rBounds
.X
);
186 const sal_Int32
y(rBounds
.Y
);
187 const sal_Int32
w(std::max(sal_Int32(1),sal_Int32(rBounds
.Width
)));
188 const sal_Int32
h(std::max(sal_Int32(1),sal_Int32(rBounds
.Height
)));
191 mpRenderModule
->resize(::basegfx::B2IRange(x
,y
,x
+w
,y
+h
));
193 resizeBackBuffer(::basegfx::B2ISize(w
,h
));
196 void SpriteDeviceHelper::resizeBackBuffer( const ::basegfx::B2ISize
& rNewSize
)
202 mpBackBuffer
->resize(rNewSize
);
203 mpBackBuffer
->clear();
206 HWND
SpriteDeviceHelper::getHwnd() const
209 return mpRenderModule
->getHWND();
214 void SpriteDeviceHelper::dumpScreenContent() const
217 mpRenderModule
->screenShot();
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */