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 #include <vcl/window.hxx>
36 
37 #include <canvas/canvastools.hxx>
38 
39 #include "dx_spritecanvas.hxx"
40 #include "dx_winstuff.hxx"
41 
42 
43 using namespace ::com::sun::star;
44 
45 namespace dxcanvas
46 {
47  SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
48  const uno::Reference< uno::XComponentContext >& rxContext ) :
49  maArguments(aArguments),
50  mxComponentContext( rxContext )
51  {
52  }
53 
55  {
56  // #i64742# Only call initialize when not in probe mode
57  if( maArguments.getLength() == 0 )
58  return;
59 
60  SAL_INFO("canvas.directx", "SpriteCanvas::initialize called" );
61 
62  /* aArguments:
63  0: ptr to creating instance (Window or VirtualDevice)
64  1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
65  2: current bounds of creating instance
66  3: bool, denoting always on top state for Window (always false for VirtualDevice)
67  4: XWindow for creating Window (or empty for VirtualDevice)
68  5: SystemGraphicsData as a streamed Any
69  */
70  ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
71  maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
72  "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
73 
74  uno::Reference< awt::XWindow > xParentWindow;
75  maArguments[3] >>= xParentWindow;
76  auto pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
77  if( !pParentWindow )
78  throw lang::NoSupportException( "Parent window not VCL window, or canvas out-of-process!" );
79 
80  awt::Rectangle aRect;
81  maArguments[1] >>= aRect;
82 
83  bool bIsFullscreen( false );
84  maArguments[2] >>= bIsFullscreen;
85 
86  // setup helper
87  maDeviceHelper.init( *pParentWindow,
88  *this,
89  aRect,
90  bIsFullscreen );
91  maCanvasHelper.init( *this,
93  maDeviceHelper.getRenderModule(),
94  maDeviceHelper.getSurfaceProxy(),
95  maDeviceHelper.getBackBuffer(),
97  maArguments.realloc(0);
98  }
99 
101  {
102  ::osl::MutexGuard aGuard( m_aMutex );
103 
104  mxComponentContext.clear();
105 
106  // forward to parent
108  }
109 
111  {
112  ::osl::MutexGuard aGuard( m_aMutex );
113 
114  // avoid repaints on hidden window (hidden: not mapped to
115  // screen). Return failure, since the screen really has _not_
116  // been updated (caller should try again later)
117  return mbIsVisible && SpriteCanvasBaseT::showBuffer( bUpdateAll );
118  }
119 
121  {
122  ::osl::MutexGuard aGuard( m_aMutex );
123 
124  // avoid repaints on hidden window (hidden: not mapped to
125  // screen). Return failure, since the screen really has _not_
126  // been updated (caller should try again later)
127  return mbIsVisible && SpriteCanvasBaseT::switchBuffer( bUpdateAll );
128  }
129 
131  {
132  ::osl::MutexGuard aGuard( m_aMutex );
133 
134  // avoid repaints on hidden window (hidden: not mapped to
135  // screen). Return failure, since the screen really has _not_
136  // been updated (caller should try again later)
137  return mbIsVisible && maCanvasHelper.updateScreen(
139  bUpdateAll,
140  mbSurfaceDirty );
141  }
142 
143  OUString SAL_CALL SpriteCanvas::getServiceName( )
144  {
145  return "com.sun.star.rendering.SpriteCanvas.DX9";
146  }
147 
148  // XServiceInfo
149  css::uno::Sequence<OUString> SpriteCanvas::getSupportedServiceNames( )
150  {
151  return { "com.sun.star.rendering.SpriteCanvas.DX9" };
152  }
154  {
155  return "com.sun.star.comp.rendering.SpriteCanvas.DX9";
156  }
157  sal_Bool SpriteCanvas::supportsService( const OUString& sServiceName )
158  {
159  return cppu::supportsService(this, sServiceName);
160  }
161 
163  {
164  ::osl::MutexGuard aGuard( m_aMutex );
165 
166  return maDeviceHelper.getRenderModule();
167  }
168 
170  {
171  ::osl::MutexGuard aGuard( m_aMutex );
172 
173  return maDeviceHelper.getBackBuffer();
174  }
175 
177  {
178  return maDeviceHelper.getBackBuffer();
179  }
180 
181  extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
183  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
184  {
185  rtl::Reference<SpriteCanvas> xCanvas(new SpriteCanvas(args, context));
186  xCanvas->initialize();
187  xCanvas->acquire();
188  return static_cast<cppu::OWeakObject*>(xCanvas.get());
189  }
190 
191 }
192 
193 
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
osl::Mutex m_aMutex
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
static VclPtr< vcl::Window > GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual void disposeThis() override
Dispose all internal references.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
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