1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <basegfx/numeric/ftools.hxx>
25 #include <basegfx/point/b2dpoint.hxx>
26 #include <basegfx/utils/canvastools.hxx>
27 #include <com/sun/star/lang/NoSupportException.hpp>
28 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
29 #include <com/sun/star/registry/XRegistryKey.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <comphelper/servicedecl.hxx>
32 #include <cppuhelper/factory.hxx>
33 #include <cppuhelper/implementationentry.hxx>
34 #include <osl/mutex.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <vcl/window.hxx>
38
39 #include <canvas/canvastools.hxx>
40
41 #include "dx_spritecanvas.hxx"
42 #include "dx_winstuff.hxx"
43
44 #define CANVAS_TECH "DX9"
45
46 #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas." CANVAS_TECH
47 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas." CANVAS_TECH
48
49
50 using namespace ::com::sun::star;
51
52 namespace sdecl = comphelper::service_decl;
53
54 namespace dxcanvas
55 {
SpriteCanvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)56 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
57 const uno::Reference< uno::XComponentContext >& rxContext ) :
58 maArguments(aArguments),
59 mxComponentContext( rxContext )
60 {
61 }
62
initialize()63 void SpriteCanvas::initialize()
64 {
65 // #i64742# Only call initialize when not in probe mode
66 if( maArguments.getLength() == 0 )
67 return;
68
69 SAL_INFO("canvas.directx", "SpriteCanvas::initialize called" );
70
71 /* aArguments:
72 0: ptr to creating instance (Window or VirtualDevice)
73 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
74 2: current bounds of creating instance
75 3: bool, denoting always on top state for Window (always false for VirtualDevice)
76 4: XWindow for creating Window (or empty for VirtualDevice)
77 5: SystemGraphicsData as a streamed Any
78 */
79 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
80 maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
81 "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
82
83 uno::Reference< awt::XWindow > xParentWindow;
84 maArguments[3] >>= xParentWindow;
85 auto pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
86 if( !pParentWindow )
87 throw lang::NoSupportException( "Parent window not VCL window, or canvas out-of-process!" );
88
89 awt::Rectangle aRect;
90 maArguments[1] >>= aRect;
91
92 bool bIsFullscreen( false );
93 maArguments[2] >>= bIsFullscreen;
94
95 // setup helper
96 maDeviceHelper.init( *pParentWindow,
97 *this,
98 aRect,
99 bIsFullscreen );
100 maCanvasHelper.init( *this,
101 maRedrawManager,
102 maDeviceHelper.getRenderModule(),
103 maDeviceHelper.getSurfaceProxy(),
104 maDeviceHelper.getBackBuffer(),
105 ::basegfx::B2ISize() );
106 maArguments.realloc(0);
107 }
108
disposeThis()109 void SpriteCanvas::disposeThis()
110 {
111 ::osl::MutexGuard aGuard( m_aMutex );
112
113 mxComponentContext.clear();
114
115 // forward to parent
116 SpriteCanvasBaseT::disposeThis();
117 }
118
showBuffer(sal_Bool bUpdateAll)119 sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll )
120 {
121 ::osl::MutexGuard aGuard( m_aMutex );
122
123 // avoid repaints on hidden window (hidden: not mapped to
124 // screen). Return failure, since the screen really has _not_
125 // been updated (caller should try again later)
126 return mbIsVisible && SpriteCanvasBaseT::showBuffer( bUpdateAll );
127 }
128
switchBuffer(sal_Bool bUpdateAll)129 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll )
130 {
131 ::osl::MutexGuard aGuard( m_aMutex );
132
133 // avoid repaints on hidden window (hidden: not mapped to
134 // screen). Return failure, since the screen really has _not_
135 // been updated (caller should try again later)
136 return mbIsVisible && SpriteCanvasBaseT::switchBuffer( bUpdateAll );
137 }
138
updateScreen(sal_Bool bUpdateAll)139 sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll )
140 {
141 ::osl::MutexGuard aGuard( m_aMutex );
142
143 // avoid repaints on hidden window (hidden: not mapped to
144 // screen). Return failure, since the screen really has _not_
145 // been updated (caller should try again later)
146 return mbIsVisible && maCanvasHelper.updateScreen(
147 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
148 bUpdateAll,
149 mbSurfaceDirty );
150 }
151
getServiceName()152 OUString SAL_CALL SpriteCanvas::getServiceName( )
153 {
154 return SPRITECANVAS_SERVICE_NAME;
155 }
156
getRenderModule() const157 const IDXRenderModuleSharedPtr& SpriteCanvas::getRenderModule() const
158 {
159 ::osl::MutexGuard aGuard( m_aMutex );
160
161 return maDeviceHelper.getRenderModule();
162 }
163
getBackBuffer() const164 const DXSurfaceBitmapSharedPtr& SpriteCanvas::getBackBuffer() const
165 {
166 ::osl::MutexGuard aGuard( m_aMutex );
167
168 return maDeviceHelper.getBackBuffer();
169 }
170
getBitmap() const171 IBitmapSharedPtr SpriteCanvas::getBitmap() const
172 {
173 return maDeviceHelper.getBackBuffer();
174 }
175
initCanvas(SpriteCanvas * pCanvas)176 static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
177 {
178 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
179 pCanvas->initialize();
180 return xRet;
181 }
182
183 sdecl::class_<SpriteCanvas, sdecl::with_args<true> > const serviceImpl(&initCanvas);
184 const sdecl::ServiceDecl dxSpriteCanvasDecl(
185 serviceImpl,
186 SPRITECANVAS_IMPLEMENTATION_NAME,
187 SPRITECANVAS_SERVICE_NAME );
188 }
189
190 // The C shared lib entry points
191 extern "C"
directx9canvas_component_getFactory(sal_Char const * pImplName,void *,void *)192 SAL_DLLPUBLIC_EXPORT void* directx9canvas_component_getFactory( sal_Char const* pImplName,
193 void*, void* )
194 {
195 return sdecl::component_getFactoryHelper( pImplName, {&dxcanvas::dxSpriteCanvasDecl} );
196 }
197
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
199