LibreOffice Module canvas (master) 1
dx_spritecanvas.cxx
Go to the documentation of this file.
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
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>
32#include <osl/mutex.hxx>
35
37
38#include "dx_spritecanvas.hxx"
39#include "dx_winstuff.hxx"
40
41
42using namespace ::com::sun::star;
43
44namespace dxcanvas
45{
46 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
47 const uno::Reference< uno::XComponentContext >& rxContext ) :
48 maArguments(aArguments),
49 mxComponentContext( rxContext )
50 {
51 }
52
53 void SpriteCanvas::initialize()
54 {
55 // #i64742# Only call initialize when not in probe mode
56 if( maArguments.getLength() == 0 )
57 return;
58
59 SAL_INFO("canvas.directx", "SpriteCanvas::initialize called" );
60
61 /* aArguments:
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
68 */
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" );
72
73 uno::Reference< awt::XWindow > xParentWindow;
74 maArguments[3] >>= xParentWindow;
75 auto pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
76 if( !pParentWindow )
77 throw lang::NoSupportException( "Parent window not VCL window, or canvas out-of-process!" );
78
79 awt::Rectangle aRect;
80 maArguments[1] >>= aRect;
81
82 bool bIsFullscreen( false );
83 maArguments[2] >>= bIsFullscreen;
84
85 // setup helper
86 maDeviceHelper.init( *pParentWindow,
87 *this,
88 aRect,
89 bIsFullscreen );
90 maCanvasHelper.init( *this,
91 maRedrawManager,
92 maDeviceHelper.getRenderModule(),
93 maDeviceHelper.getSurfaceProxy(),
94 maDeviceHelper.getBackBuffer(),
96 maArguments.realloc(0);
97 }
98
99 void SpriteCanvas::disposeThis()
100 {
101 ::osl::MutexGuard aGuard( m_aMutex );
102
103 mxComponentContext.clear();
104
105 // forward to parent
106 SpriteCanvasBaseT::disposeThis();
107 }
108
109 sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll )
110 {
111 ::osl::MutexGuard aGuard( m_aMutex );
112
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 );
117 }
118
119 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( 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::switchBuffer( bUpdateAll );
127 }
128
129 sal_Bool SAL_CALL SpriteCanvas::updateScreen( 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 && maCanvasHelper.updateScreen(
137 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
138 bUpdateAll,
139 mbSurfaceDirty );
140 }
141
142 OUString SAL_CALL SpriteCanvas::getServiceName( )
143 {
144 return "com.sun.star.rendering.SpriteCanvas.DX9";
145 }
146
147 // XServiceInfo
148 css::uno::Sequence<OUString> SpriteCanvas::getSupportedServiceNames( )
149 {
150 return { "com.sun.star.rendering.SpriteCanvas.DX9" };
151 }
152 OUString SpriteCanvas::getImplementationName( )
153 {
154 return "com.sun.star.comp.rendering.SpriteCanvas.DX9";
155 }
156 sal_Bool SpriteCanvas::supportsService( const OUString& sServiceName )
157 {
159 }
160
161 const IDXRenderModuleSharedPtr& SpriteCanvas::getRenderModule() const
162 {
163 ::osl::MutexGuard aGuard( m_aMutex );
164
165 return maDeviceHelper.getRenderModule();
166 }
167
168 const DXSurfaceBitmapSharedPtr& SpriteCanvas::getBackBuffer() const
169 {
170 ::osl::MutexGuard aGuard( m_aMutex );
171
172 return maDeviceHelper.getBackBuffer();
173 }
174
175 IBitmapSharedPtr SpriteCanvas::getBitmap() const
176 {
177 return maDeviceHelper.getBackBuffer();
178 }
179
180 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
182 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
183 {
184 rtl::Reference<SpriteCanvas> xCanvas(new SpriteCanvas(args, context));
185 xCanvas->initialize();
186 return cppu::acquire(xCanvas.get());
187 }
188
189}
190
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
constexpr OUStringLiteral sServiceName
::basegfx::B2DRectangle maBounds
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
Product of this component's factory.
SpriteCanvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
#define ENSURE_ARG_OR_THROW(c, m)
std::mutex m_aMutex
Sequence< PropertyValue > aArguments
#define SAL_INFO(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::shared_ptr< IBitmap > IBitmapSharedPtr
Definition: dx_ibitmap.hxx:58
std::shared_ptr< DXSurfaceBitmap > DXSurfaceBitmapSharedPtr
std::shared_ptr< IDXRenderModule > IDXRenderModuleSharedPtr
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * canvas_directx9_SpriteCanvas_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
args
unsigned char sal_Bool