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>
21 #include <sal/log.hxx>
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 <cppuhelper/supportsservice.hxx>
32 #include <osl/mutex.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <comphelper/diagnose_ex.hxx>
36 #include <canvas/canvastools.hxx>
38 #include "dx_spritecanvas.hxx"
39 #include "dx_winstuff.hxx"
42 using namespace ::com::sun::star
;
46 SpriteCanvas::SpriteCanvas( const uno::Sequence
< uno::Any
>& aArguments
,
47 const uno::Reference
< uno::XComponentContext
>& rxContext
) :
48 maArguments(aArguments
),
49 mxComponentContext( rxContext
)
53 void SpriteCanvas::initialize()
55 // #i64742# Only call initialize when not in probe mode
56 if( maArguments
.getLength() == 0 )
59 SAL_INFO("canvas.directx", "SpriteCanvas::initialize called" );
62 0: ptr to creating instance (Window or VirtualDevice)
63 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
64 2: current bounds of creating instance
65 3: bool, denoting always on top state for Window (always false for VirtualDevice)
66 4: XWindow for creating Window (or empty for VirtualDevice)
67 5: SystemGraphicsData as a streamed Any
69 ENSURE_ARG_OR_THROW( maArguments
.getLength() >= 4 &&
70 maArguments
[3].getValueTypeClass() == uno::TypeClass_INTERFACE
,
71 "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
73 uno::Reference
< awt::XWindow
> xParentWindow
;
74 maArguments
[3] >>= xParentWindow
;
75 auto pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
77 throw lang::NoSupportException( "Parent window not VCL window, or canvas out-of-process!" );
80 maArguments
[1] >>= aRect
;
82 bool bIsFullscreen( false );
83 maArguments
[2] >>= bIsFullscreen
;
86 maDeviceHelper
.init( *pParentWindow
,
90 maCanvasHelper
.init( *this,
92 maDeviceHelper
.getRenderModule(),
93 maDeviceHelper
.getSurfaceProxy(),
94 maDeviceHelper
.getBackBuffer(),
95 ::basegfx::B2ISize() );
96 maArguments
.realloc(0);
99 void SpriteCanvas::disposeThis()
101 ::osl::MutexGuard
aGuard( m_aMutex
);
103 mxComponentContext
.clear();
106 SpriteCanvasBaseT::disposeThis();
109 sal_Bool SAL_CALL
SpriteCanvas::showBuffer( sal_Bool bUpdateAll
)
111 ::osl::MutexGuard
aGuard( m_aMutex
);
113 // avoid repaints on hidden window (hidden: not mapped to
114 // screen). Return failure, since the screen really has _not_
115 // been updated (caller should try again later)
116 return mbIsVisible
&& SpriteCanvasBaseT::showBuffer( bUpdateAll
);
119 sal_Bool SAL_CALL
SpriteCanvas::switchBuffer( sal_Bool bUpdateAll
)
121 ::osl::MutexGuard
aGuard( m_aMutex
);
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::switchBuffer( bUpdateAll
);
129 sal_Bool SAL_CALL
SpriteCanvas::updateScreen( sal_Bool bUpdateAll
)
131 ::osl::MutexGuard
aGuard( m_aMutex
);
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
&& maCanvasHelper
.updateScreen(
137 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds
),
142 OUString SAL_CALL
SpriteCanvas::getServiceName( )
144 return "com.sun.star.rendering.SpriteCanvas.DX9";
148 css::uno::Sequence
<OUString
> SpriteCanvas::getSupportedServiceNames( )
150 return { "com.sun.star.rendering.SpriteCanvas.DX9" };
152 OUString
SpriteCanvas::getImplementationName( )
154 return "com.sun.star.comp.rendering.SpriteCanvas.DX9";
156 sal_Bool
SpriteCanvas::supportsService( const OUString
& sServiceName
)
158 return cppu::supportsService(this, sServiceName
);
161 const IDXRenderModuleSharedPtr
& SpriteCanvas::getRenderModule() const
163 ::osl::MutexGuard
aGuard( m_aMutex
);
165 return maDeviceHelper
.getRenderModule();
168 const DXSurfaceBitmapSharedPtr
& SpriteCanvas::getBackBuffer() const
170 ::osl::MutexGuard
aGuard( m_aMutex
);
172 return maDeviceHelper
.getBackBuffer();
175 IBitmapSharedPtr
SpriteCanvas::getBitmap() const
177 return maDeviceHelper
.getBackBuffer();
180 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
181 canvas_directx9_SpriteCanvas_get_implementation(
182 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& args
)
184 rtl::Reference
<SpriteCanvas
> xCanvas(new SpriteCanvas(args
, context
));
185 xCanvas
->initialize();
186 return cppu::acquire(xCanvas
.get());
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */