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 <cppuhelper/factory.hxx>
34 #include <osl/mutex.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 
53 
54 namespace dxcanvas
55 {
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 
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,
102  maDeviceHelper.getRenderModule(),
103  maDeviceHelper.getSurfaceProxy(),
104  maDeviceHelper.getBackBuffer(),
105  ::basegfx::B2ISize() );
106  maArguments.realloc(0);
107  }
108 
110  {
111  ::osl::MutexGuard aGuard( m_aMutex );
112 
113  mxComponentContext.clear();
114 
115  // forward to parent
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::showBuffer( 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 && SpriteCanvasBaseT::switchBuffer( bUpdateAll );
137  }
138 
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(
148  bUpdateAll,
149  mbSurfaceDirty );
150  }
151 
152  OUString SAL_CALL SpriteCanvas::getServiceName( )
153  {
155  }
156 
158  {
159  ::osl::MutexGuard aGuard( m_aMutex );
160 
161  return maDeviceHelper.getRenderModule();
162  }
163 
165  {
166  ::osl::MutexGuard aGuard( m_aMutex );
167 
168  return maDeviceHelper.getBackBuffer();
169  }
170 
172  {
173  return maDeviceHelper.getBackBuffer();
174  }
175 
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 
185  serviceImpl,
188 }
189 
190 // The C shared lib entry points
191 extern "C"
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: */
::osl::Mutex m_aMutex
css::uno::Sequence< css::uno::Any > maArguments
std::shared_ptr< IBitmap > IBitmapSharedPtr
Definition: dx_ibitmap.hxx:59
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.
SAL_DLLPUBLIC_EXPORT void * directx9canvas_component_getFactory(sal_Char const *pImplName, void *, void *)
char sal_Char
#define SPRITECANVAS_SERVICE_NAME
::basegfx::B2DRange maBounds
sdecl::vba_service_class_< SwVbaDocument, sdecl::with_args< true > > const serviceImpl
SpriteRedrawManager maRedrawManager
::basegfx::B2IRange b2IRectangleFromAwtRectangle(const awt::Rectangle &rRect)
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
sdecl::class_< Canvas, sdecl::with_args< true > > const serviceImpl1 & initCanvas
Definition: dx_canvas.cxx:220
virtual sal_Bool SAL_CALL showBuffer(sal_Bool bUpdateAll) override
virtual void disposeThis() override
std::shared_ptr< DXSurfaceBitmap > DXSurfaceBitmapSharedPtr
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:443
#define ENSURE_ARG_OR_THROW(c, m)
#define SPRITECANVAS_IMPLEMENTATION_NAME
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
const sdecl::ServiceDecl dxSpriteCanvasDecl(serviceImpl, SPRITECANVAS_IMPLEMENTATION_NAME, SPRITECANVAS_SERVICE_NAME)
Product of this component's factory.
css::uno::Reference< css::uno::XComponentContext > mxComponentContext