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>
34 #include <tools/diagnose_ex.h>
35 
36 #include <canvas/canvastools.hxx>
37 
38 #include "dx_spritecanvas.hxx"
39 #include "dx_winstuff.hxx"
40 
41 
42 using namespace ::com::sun::star;
43 
44 namespace 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 
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,
92  maDeviceHelper.getRenderModule(),
93  maDeviceHelper.getSurfaceProxy(),
94  maDeviceHelper.getBackBuffer(),
96  maArguments.realloc(0);
97  }
98 
100  {
101  ::osl::MutexGuard aGuard( m_aMutex );
102 
103  mxComponentContext.clear();
104 
105  // forward to parent
107  }
108 
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 
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 
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(
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  }
153  {
154  return "com.sun.star.comp.rendering.SpriteCanvas.DX9";
155  }
156  sal_Bool SpriteCanvas::supportsService( const OUString& sServiceName )
157  {
158  return cppu::supportsService(this, sServiceName);
159  }
160 
162  {
163  ::osl::MutexGuard aGuard( m_aMutex );
164 
165  return maDeviceHelper.getRenderModule();
166  }
167 
169  {
170  ::osl::MutexGuard aGuard( m_aMutex );
171 
172  return maDeviceHelper.getBackBuffer();
173  }
174 
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  xCanvas->acquire();
187  return static_cast<cppu::OWeakObject*>(xCanvas.get());
188  }
189 
190 }
191 
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< css::uno::Any > maArguments
std::shared_ptr< IBitmap > IBitmapSharedPtr
Definition: dx_ibitmap.hxx:58
std::shared_ptr< IDXRenderModule > IDXRenderModuleSharedPtr
virtual sal_Bool SAL_CALL updateScreen(sal_Bool bUpdateAll) override
virtual void disposeThis() override
Dispose all internal references.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::mutex m_aMutex
SpriteRedrawManager maRedrawManager
::basegfx::B2IRange b2IRectangleFromAwtRectangle(const awt::Rectangle &rRect)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * canvas_directx9_SpriteCanvas_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
virtual sal_Bool SAL_CALL supportsService(const OUString &) override
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
unsigned char sal_Bool
const IDXRenderModuleSharedPtr & getRenderModule() const
Retrieve rendermodule object for this Canvas.
virtual sal_Bool SAL_CALL switchBuffer(sal_Bool bUpdateAll) override
virtual sal_Bool SAL_CALL showBuffer(sal_Bool bUpdateAll) override
virtual OUString SAL_CALL getImplementationName() override
virtual void disposeThis() override
std::shared_ptr< DXSurfaceBitmap > DXSurfaceBitmapSharedPtr
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:441
#define ENSURE_ARG_OR_THROW(c, m)
virtual IBitmapSharedPtr getBitmap() const override
SpriteCanvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
const DXSurfaceBitmapSharedPtr & getBackBuffer() const
Get backbuffer for this canvas.
#define SAL_INFO(area, stream)
virtual OUString SAL_CALL getServiceName() override
Product of this component's factory.
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
::basegfx::B2DRectangle maBounds