Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / cairo / cairo_spritecanvas.cxx
blob87379a8b37b8076f79aff4f6a8acabcc66fc2ee2
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 .
20 #include <canvas/debug.hxx>
21 #include <canvas/verbosetrace.hxx>
22 #include <canvas/canvastools.hxx>
23 #include <tools/diagnose_ex.h>
25 #include <osl/mutex.hxx>
27 #include <com/sun/star/registry/XRegistryKey.hpp>
28 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/lang/NoSupportException.hpp>
32 #include <toolkit/helper/vclunohelper.hxx>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <basegfx/point/b2dpoint.hxx>
36 #include <basegfx/tools/canvastools.hxx>
37 #include <basegfx/numeric/ftools.hxx>
39 #include "cairo_spritecanvas.hxx"
41 using namespace ::cairo;
42 using namespace ::com::sun::star;
44 namespace cairocanvas
46 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
47 const uno::Reference< uno::XComponentContext >& rxContext ) :
48 maArguments(aArguments),
49 mxComponentContext( rxContext )
53 void SpriteCanvas::initialize()
55 VERBOSE_TRACE("CairoSpriteCanvas created %p\n", this);
57 // #i64742# Only call initialize when not in probe mode
58 if( maArguments.getLength() == 0 )
59 return;
61 /* maArguments:
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
69 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
70 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
71 maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
72 "CairoSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
74 awt::Rectangle aRect;
75 maArguments[2] >>= aRect;
77 bool bIsFullscreen( false );
78 maArguments[3] >>= bIsFullscreen;
80 uno::Reference< awt::XWindow > xParentWindow;
81 maArguments[4] >>= xParentWindow;
83 vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
84 if( !pParentWindow )
85 throw lang::NoSupportException(
86 "Parent window not VCL window, or canvas out-of-process!", NULL);
88 bool bHasCairo = pParentWindow->SupportsCairo();
89 ENSURE_ARG_OR_THROW(bHasCairo,
90 "CairoSpriteCanvas::SpriteCanvas: No Cairo capability");
92 Size aPixelSize( pParentWindow->GetOutputSizePixel() );
93 const ::basegfx::B2ISize aSize( aPixelSize.Width(),
94 aPixelSize.Height() );
96 // setup helper
97 maDeviceHelper.init( *pParentWindow,
98 *this,
99 aSize,
100 bIsFullscreen );
102 setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
104 maCanvasHelper.init( maRedrawManager,
105 *this,
106 aSize );
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, std::exception)
123 return updateScreen( bUpdateAll );
126 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
128 return updateScreen( bUpdateAll );
131 sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException, std::exception)
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 && maCanvasHelper.updateScreen(
139 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
140 bUpdateAll,
141 mbSurfaceDirty);
144 OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException, std::exception)
146 return OUString( SPRITECANVAS_SERVICE_NAME );
149 SurfaceSharedPtr SpriteCanvas::getSurface()
151 return maDeviceHelper.getBufferSurface();
154 SurfaceSharedPtr SpriteCanvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
156 return maDeviceHelper.createSurface( rSize, aContent );
159 SurfaceSharedPtr SpriteCanvas::createSurface( ::Bitmap& rBitmap )
161 BitmapSystemData aData;
162 if( rBitmap.GetSystemData( aData ) ) {
163 const Size& rSize = rBitmap.GetSizePixel();
165 return maDeviceHelper.createSurface( aData, rSize );
168 return SurfaceSharedPtr();
171 SurfaceSharedPtr SpriteCanvas::changeSurface( bool, bool )
173 // non-modifiable surface here
174 return SurfaceSharedPtr();
177 OutputDevice* SpriteCanvas::getOutputDevice()
179 return maDeviceHelper.getOutputDevice();
182 SurfaceSharedPtr SpriteCanvas::getBufferSurface()
184 return maDeviceHelper.getBufferSurface();
187 SurfaceSharedPtr SpriteCanvas::getWindowSurface()
189 return maDeviceHelper.getWindowSurface();
192 const ::basegfx::B2ISize& SpriteCanvas::getSizePixel()
194 return maDeviceHelper.getSizePixel();
197 void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize& rSize )
199 maCanvasHelper.setSize( rSize );
200 // re-set background surface, in case it needed recreation
201 maCanvasHelper.setSurface( maDeviceHelper.getBufferSurface(),
202 false );
205 void SpriteCanvas::flush()
207 maDeviceHelper.flush();
210 bool SpriteCanvas::repaint( const SurfaceSharedPtr& pSurface,
211 const rendering::ViewState& viewState,
212 const rendering::RenderState& renderState )
214 return maCanvasHelper.repaint( pSurface, viewState, renderState );
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */