1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cairo_spritecanvas.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <canvas/verbosetrace.hxx>
36 #include <canvas/canvastools.hxx>
37 #include <tools/diagnose_ex.h>
39 #include <osl/mutex.hxx>
41 #include <com/sun/star/registry/XRegistryKey.hpp>
42 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 #include <com/sun/star/uno/XComponentContext.hpp>
44 #include <com/sun/star/lang/NoSupportException.hpp>
46 #include <toolkit/helper/vclunohelper.hxx>
48 #include <basegfx/matrix/b2dhommatrix.hxx>
49 #include <basegfx/point/b2dpoint.hxx>
50 #include <basegfx/tools/canvastools.hxx>
51 #include <basegfx/numeric/ftools.hxx>
53 #include "cairo_spritecanvas.hxx"
55 using namespace ::cairo
;
56 using namespace ::com::sun::star
;
60 SpriteCanvas::SpriteCanvas( const uno::Sequence
< uno::Any
>& aArguments
,
61 const uno::Reference
< uno::XComponentContext
>& rxContext
) :
62 maArguments(aArguments
),
63 mxComponentContext( rxContext
)
67 void SpriteCanvas::initialize()
69 VERBOSE_TRACE("CairoSpriteCanvas created %p\n", this);
71 // #i64742# Only call initialize when not in probe mode
72 if( maArguments
.getLength() == 0 )
76 0: ptr to creating instance (Window or VirtualDevice)
77 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
78 2: current bounds of creating instance
79 3: bool, denoting always on top state for Window (always false for VirtualDevice)
80 4: XWindow for creating Window (or empty for VirtualDevice)
81 5: SystemGraphicsData as a streamed Any
83 ENSURE_ARG_OR_THROW( maArguments
.getLength() >= 4 &&
84 maArguments
[0].getValueTypeClass() == uno::TypeClass_HYPER
&&
85 maArguments
[4].getValueTypeClass() == uno::TypeClass_INTERFACE
,
86 "CairoSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
89 maArguments
[2] >>= aRect
;
91 sal_Bool
bIsFullscreen( sal_False
);
92 maArguments
[3] >>= bIsFullscreen
;
94 uno::Reference
< awt::XWindow
> xParentWindow
;
95 maArguments
[4] >>= xParentWindow
;
97 Window
* pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
99 throw lang::NoSupportException(
100 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
101 "Parent window not VCL window, or canvas out-of-process!")),
104 bool bHasXRender
= IsCairoWorking(pParentWindow
);
105 ENSURE_ARG_OR_THROW( bHasXRender
== true,
106 "CairoSpriteCanvas::SpriteCanvas: No RENDER extension" );
108 Size
aPixelSize( pParentWindow
->GetOutputSizePixel() );
109 const ::basegfx::B2ISize
aSize( aPixelSize
.Width(),
110 aPixelSize
.Height() );
112 ENSURE_ARG_OR_THROW( pParentWindow
!= NULL
,
113 "CairoSpriteCanvas::initialize: invalid Window pointer" );
116 maDeviceHelper
.init( *pParentWindow
,
121 setWindow(uno::Reference
<awt::XWindow2
>(xParentWindow
, uno::UNO_QUERY_THROW
));
123 maCanvasHelper
.init( maRedrawManager
,
127 maArguments
.realloc(0);
130 void SAL_CALL
SpriteCanvas::disposing()
132 ::osl::MutexGuard
aGuard( m_aMutex
);
134 mxComponentContext
.clear();
137 SpriteCanvasBaseT::disposing();
140 ::sal_Bool SAL_CALL
SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
142 return updateScreen( bUpdateAll
);
145 ::sal_Bool SAL_CALL
SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
147 return updateScreen( bUpdateAll
);
150 sal_Bool SAL_CALL
SpriteCanvas::updateScreen( sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
152 ::osl::MutexGuard
aGuard( m_aMutex
);
154 // avoid repaints on hidden window (hidden: not mapped to
155 // screen). Return failure, since the screen really has _not_
156 // been updated (caller should try again later)
157 return !mbIsVisible
? false : maCanvasHelper
.updateScreen(
158 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds
),
163 ::rtl::OUString SAL_CALL
SpriteCanvas::getServiceName( ) throw (uno::RuntimeException
)
165 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME
) );
168 SurfaceSharedPtr
SpriteCanvas::getSurface()
170 return maDeviceHelper
.getBufferSurface();
173 SurfaceSharedPtr
SpriteCanvas::createSurface( const ::basegfx::B2ISize
& rSize
, Content aContent
)
175 return maDeviceHelper
.createSurface( rSize
, aContent
);
178 SurfaceSharedPtr
SpriteCanvas::createSurface( ::Bitmap
& rBitmap
)
180 BitmapSystemData aData
;
181 if( rBitmap
.GetSystemData( aData
) ) {
182 const Size
& rSize
= rBitmap
.GetSizePixel();
184 return maDeviceHelper
.createSurface( aData
, rSize
);
187 return SurfaceSharedPtr();
190 SurfaceSharedPtr
SpriteCanvas::changeSurface( bool, bool )
192 // non-modifiable surface here
193 return SurfaceSharedPtr();
196 OutputDevice
* SpriteCanvas::getOutputDevice()
198 return maDeviceHelper
.getOutputDevice();
201 SurfaceSharedPtr
SpriteCanvas::getBufferSurface()
203 return maDeviceHelper
.getBufferSurface();
206 SurfaceSharedPtr
SpriteCanvas::getWindowSurface()
208 return maDeviceHelper
.getWindowSurface();
211 const ::basegfx::B2ISize
& SpriteCanvas::getSizePixel()
213 return maDeviceHelper
.getSizePixel();
216 void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize
& rSize
)
218 maCanvasHelper
.setSize( rSize
);
219 // re-set background surface, in case it needed recreation
220 maCanvasHelper
.setSurface( maDeviceHelper
.getBufferSurface(),
224 void SpriteCanvas::flush()
226 maDeviceHelper
.flush();
229 bool SpriteCanvas::repaint( const SurfaceSharedPtr
& pSurface
,
230 const rendering::ViewState
& viewState
,
231 const rendering::RenderState
& renderState
)
233 return maCanvasHelper
.repaint( pSurface
, viewState
, renderState
);