Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / directx / dx_spritecanvas.cxx
blobab76e7766af22bc8163392ca7baead5f3a386051
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <ctype.h>
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <tools/diagnose_ex.h>
26 #include <canvas/canvastools.hxx>
28 #include <osl/mutex.hxx>
30 #include <com/sun/star/registry/XRegistryKey.hpp>
31 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <com/sun/star/lang/NoSupportException.hpp>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <cppuhelper/factory.hxx>
37 #include <cppuhelper/implementationentry.hxx>
38 #include <comphelper/servicedecl.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/point/b2dpoint.hxx>
42 #include <basegfx/tools/canvastools.hxx>
43 #include <basegfx/numeric/ftools.hxx>
45 #include "dx_winstuff.hxx"
46 #include "dx_spritecanvas.hxx"
48 #define CANVAS_TECH "DX9"
50 #define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas." CANVAS_TECH
51 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas." CANVAS_TECH
54 using namespace ::com::sun::star;
56 namespace dxcanvas
58 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
59 const uno::Reference< uno::XComponentContext >& rxContext ) :
60 maArguments(aArguments),
61 mxComponentContext( rxContext )
65 void SpriteCanvas::initialize()
67 // #i64742# Only call initialize when not in probe mode
68 if( maArguments.getLength() == 0 )
69 return;
71 VERBOSE_TRACE( "SpriteCanvas::initialize called" );
73 /* aArguments:
74 0: ptr to creating instance (Window or VirtualDevice)
75 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
76 2: current bounds of creating instance
77 3: bool, denoting always on top state for Window (always false for VirtualDevice)
78 4: XWindow for creating Window (or empty for VirtualDevice)
79 5: SystemGraphicsData as a streamed Any
81 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
82 maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
83 "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
85 uno::Reference< awt::XWindow > xParentWindow;
86 maArguments[4] >>= xParentWindow;
87 vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
88 if( !pParentWindow )
89 throw lang::NoSupportException( "Parent window not VCL window, or canvas out-of-process!" );
91 awt::Rectangle aRect;
92 maArguments[2] >>= aRect;
94 sal_Bool bIsFullscreen( sal_False );
95 maArguments[3] >>= bIsFullscreen;
97 // setup helper
98 maDeviceHelper.init( *pParentWindow,
99 *this,
100 aRect,
101 bIsFullscreen );
102 maCanvasHelper.init( *this,
103 maRedrawManager,
104 maDeviceHelper.getRenderModule(),
105 maDeviceHelper.getSurfaceProxy(),
106 maDeviceHelper.getBackBuffer(),
107 ::basegfx::B2ISize() );
108 maArguments.realloc(0);
111 void SpriteCanvas::disposeThis()
113 ::osl::MutexGuard aGuard( m_aMutex );
115 mxComponentContext.clear();
117 // forward to parent
118 SpriteCanvasBaseT::disposeThis();
121 sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
123 ::osl::MutexGuard aGuard( m_aMutex );
125 // avoid repaints on hidden window (hidden: not mapped to
126 // screen). Return failure, since the screen really has _not_
127 // been updated (caller should try again later)
128 return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll );
131 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
133 ::osl::MutexGuard aGuard( m_aMutex );
135 // avoid repaints on hidden window (hidden: not mapped to
136 // screen). Return failure, since the screen really has _not_
137 // been updated (caller should try again later)
138 return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll );
141 sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
143 ::osl::MutexGuard aGuard( m_aMutex );
145 // avoid repaints on hidden window (hidden: not mapped to
146 // screen). Return failure, since the screen really has _not_
147 // been updated (caller should try again later)
148 return !mbIsVisible ? false : maCanvasHelper.updateScreen(
149 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
150 bUpdateAll,
151 mbSurfaceDirty );
154 OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException)
156 return OUString( SPRITECANVAS_SERVICE_NAME );
159 const IDXRenderModuleSharedPtr& SpriteCanvas::getRenderModule() const
161 ::osl::MutexGuard aGuard( m_aMutex );
163 return maDeviceHelper.getRenderModule();
166 const DXSurfaceBitmapSharedPtr& SpriteCanvas::getBackBuffer() const
168 ::osl::MutexGuard aGuard( m_aMutex );
170 return maDeviceHelper.getBackBuffer();
173 IBitmapSharedPtr SpriteCanvas::getBitmap() const
175 return maDeviceHelper.getBackBuffer();
178 static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
180 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
181 pCanvas->initialize();
182 return xRet;
185 namespace sdecl = comphelper::service_decl;
186 sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas);
187 const sdecl::ServiceDecl dxSpriteCanvasDecl(
188 serviceImpl,
189 SPRITECANVAS_IMPLEMENTATION_NAME,
190 SPRITECANVAS_SERVICE_NAME );
193 // The C shared lib entry points
194 COMPHELPER_SERVICEDECL_EXPORTS1(directx9canvas, dxcanvas::dxSpriteCanvasDecl)
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */