CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / canvas / source / cairo / cairo_spritecanvas.cxx
blob43911c1113d68089f7db6b69bd6b818bb3e8de26
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <canvas/debug.hxx>
32 #include <canvas/verbosetrace.hxx>
33 #include <canvas/canvastools.hxx>
34 #include <tools/diagnose_ex.h>
36 #include <osl/mutex.hxx>
38 #include <com/sun/star/registry/XRegistryKey.hpp>
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 #include <com/sun/star/lang/NoSupportException.hpp>
43 #include <toolkit/helper/vclunohelper.hxx>
45 #include <basegfx/matrix/b2dhommatrix.hxx>
46 #include <basegfx/point/b2dpoint.hxx>
47 #include <basegfx/tools/canvastools.hxx>
48 #include <basegfx/numeric/ftools.hxx>
50 #include "cairo_spritecanvas.hxx"
52 using namespace ::cairo;
53 using namespace ::com::sun::star;
55 namespace cairocanvas
57 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
58 const uno::Reference< uno::XComponentContext >& rxContext ) :
59 maArguments(aArguments),
60 mxComponentContext( rxContext )
64 void SpriteCanvas::initialize()
66 VERBOSE_TRACE("CairoSpriteCanvas created %p\n", this);
68 // #i64742# Only call initialize when not in probe mode
69 if( maArguments.getLength() == 0 )
70 return;
72 /* maArguments:
73 0: ptr to creating instance (Window or VirtualDevice)
74 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
75 2: current bounds of creating instance
76 3: bool, denoting always on top state for Window (always false for VirtualDevice)
77 4: XWindow for creating Window (or empty for VirtualDevice)
78 5: SystemGraphicsData as a streamed Any
80 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
81 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
82 maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
83 "CairoSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
85 awt::Rectangle aRect;
86 maArguments[2] >>= aRect;
88 sal_Bool bIsFullscreen( sal_False );
89 maArguments[3] >>= bIsFullscreen;
91 uno::Reference< awt::XWindow > xParentWindow;
92 maArguments[4] >>= xParentWindow;
94 Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
95 if( !pParentWindow )
96 throw lang::NoSupportException(
97 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
98 "Parent window not VCL window, or canvas out-of-process!")),
99 NULL);
101 bool bHasXRender = IsCairoWorking(pParentWindow);
102 ENSURE_ARG_OR_THROW( bHasXRender == true,
103 "CairoSpriteCanvas::SpriteCanvas: No RENDER extension" );
105 Size aPixelSize( pParentWindow->GetOutputSizePixel() );
106 const ::basegfx::B2ISize aSize( aPixelSize.Width(),
107 aPixelSize.Height() );
109 ENSURE_ARG_OR_THROW( pParentWindow != NULL,
110 "CairoSpriteCanvas::initialize: invalid Window pointer" );
112 // setup helper
113 maDeviceHelper.init( *pParentWindow,
114 *this,
115 aSize,
116 bIsFullscreen );
118 setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
120 maCanvasHelper.init( maRedrawManager,
121 *this,
122 aSize );
124 maArguments.realloc(0);
127 void SAL_CALL SpriteCanvas::disposing()
129 ::osl::MutexGuard aGuard( m_aMutex );
131 mxComponentContext.clear();
133 // forward to parent
134 SpriteCanvasBaseT::disposing();
137 ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
139 return updateScreen( bUpdateAll );
142 ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
144 return updateScreen( bUpdateAll );
147 sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
149 ::osl::MutexGuard aGuard( m_aMutex );
151 // avoid repaints on hidden window (hidden: not mapped to
152 // screen). Return failure, since the screen really has _not_
153 // been updated (caller should try again later)
154 return !mbIsVisible ? false : maCanvasHelper.updateScreen(
155 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
156 bUpdateAll,
157 mbSurfaceDirty);
160 ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException)
162 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME ) );
165 SurfaceSharedPtr SpriteCanvas::getSurface()
167 return maDeviceHelper.getBufferSurface();
170 SurfaceSharedPtr SpriteCanvas::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
172 return maDeviceHelper.createSurface( rSize, aContent );
175 SurfaceSharedPtr SpriteCanvas::createSurface( ::Bitmap& rBitmap )
177 BitmapSystemData aData;
178 if( rBitmap.GetSystemData( aData ) ) {
179 const Size& rSize = rBitmap.GetSizePixel();
181 return maDeviceHelper.createSurface( aData, rSize );
184 return SurfaceSharedPtr();
187 SurfaceSharedPtr SpriteCanvas::changeSurface( bool, bool )
189 // non-modifiable surface here
190 return SurfaceSharedPtr();
193 OutputDevice* SpriteCanvas::getOutputDevice()
195 return maDeviceHelper.getOutputDevice();
198 SurfaceSharedPtr SpriteCanvas::getBufferSurface()
200 return maDeviceHelper.getBufferSurface();
203 SurfaceSharedPtr SpriteCanvas::getWindowSurface()
205 return maDeviceHelper.getWindowSurface();
208 const ::basegfx::B2ISize& SpriteCanvas::getSizePixel()
210 return maDeviceHelper.getSizePixel();
213 void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize& rSize )
215 maCanvasHelper.setSize( rSize );
216 // re-set background surface, in case it needed recreation
217 maCanvasHelper.setSurface( maDeviceHelper.getBufferSurface(),
218 false );
221 void SpriteCanvas::flush()
223 maDeviceHelper.flush();
226 bool SpriteCanvas::repaint( const SurfaceSharedPtr& pSurface,
227 const rendering::ViewState& viewState,
228 const rendering::RenderState& renderState )
230 return maCanvasHelper.repaint( pSurface, viewState, renderState );