Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <canvas/debug.hxx>
30 : : #include <canvas/verbosetrace.hxx>
31 : : #include <canvas/canvastools.hxx>
32 : : #include <tools/diagnose_ex.h>
33 : :
34 : : #include <osl/mutex.hxx>
35 : :
36 : : #include <com/sun/star/registry/XRegistryKey.hpp>
37 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 : : #include <com/sun/star/uno/XComponentContext.hpp>
39 : : #include <com/sun/star/lang/NoSupportException.hpp>
40 : :
41 : : #include <toolkit/helper/vclunohelper.hxx>
42 : :
43 : : #include <basegfx/matrix/b2dhommatrix.hxx>
44 : : #include <basegfx/point/b2dpoint.hxx>
45 : : #include <basegfx/tools/canvastools.hxx>
46 : : #include <basegfx/numeric/ftools.hxx>
47 : :
48 : : #include "cairo_spritecanvas.hxx"
49 : :
50 : : using namespace ::cairo;
51 : : using namespace ::com::sun::star;
52 : :
53 : : namespace cairocanvas
54 : : {
55 : 0 : SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
56 : : const uno::Reference< uno::XComponentContext >& rxContext ) :
57 : : maArguments(aArguments),
58 : 0 : mxComponentContext( rxContext )
59 : : {
60 : 0 : }
61 : :
62 : 0 : void SpriteCanvas::initialize()
63 : : {
64 : : VERBOSE_TRACE("CairoSpriteCanvas created %p\n", this);
65 : :
66 : : // #i64742# Only call initialize when not in probe mode
67 : 0 : if( maArguments.getLength() == 0 )
68 : 0 : return;
69 : :
70 : : /* maArguments:
71 : : 0: ptr to creating instance (Window or VirtualDevice)
72 : : 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
73 : : 2: current bounds of creating instance
74 : : 3: bool, denoting always on top state for Window (always false for VirtualDevice)
75 : : 4: XWindow for creating Window (or empty for VirtualDevice)
76 : : 5: SystemGraphicsData as a streamed Any
77 : : */
78 : 0 : ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
79 : : maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
80 : : maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
81 : : "CairoSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
82 : :
83 : 0 : awt::Rectangle aRect;
84 : 0 : maArguments[2] >>= aRect;
85 : :
86 : 0 : sal_Bool bIsFullscreen( sal_False );
87 : 0 : maArguments[3] >>= bIsFullscreen;
88 : :
89 : 0 : uno::Reference< awt::XWindow > xParentWindow;
90 : 0 : maArguments[4] >>= xParentWindow;
91 : :
92 : 0 : Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
93 : 0 : if( !pParentWindow )
94 : : throw lang::NoSupportException(
95 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
96 : : "Parent window not VCL window, or canvas out-of-process!")),
97 : 0 : NULL);
98 : :
99 : 0 : bool bHasXRender = IsCairoWorking(pParentWindow);
100 : 0 : ENSURE_ARG_OR_THROW( bHasXRender == true,
101 : : "CairoSpriteCanvas::SpriteCanvas: No RENDER extension" );
102 : :
103 : 0 : Size aPixelSize( pParentWindow->GetOutputSizePixel() );
104 : 0 : const ::basegfx::B2ISize aSize( aPixelSize.Width(),
105 : 0 : aPixelSize.Height() );
106 : :
107 : 0 : ENSURE_ARG_OR_THROW( pParentWindow != NULL,
108 : : "CairoSpriteCanvas::initialize: invalid Window pointer" );
109 : :
110 : : // setup helper
111 : : maDeviceHelper.init( *pParentWindow,
112 : : *this,
113 : : aSize,
114 : 0 : bIsFullscreen );
115 : :
116 : 0 : setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
117 : :
118 : : maCanvasHelper.init( maRedrawManager,
119 : : *this,
120 : 0 : aSize );
121 : :
122 : 0 : maArguments.realloc(0);
123 : : }
124 : :
125 : 0 : void SpriteCanvas::disposeThis()
126 : : {
127 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
128 : :
129 : 0 : mxComponentContext.clear();
130 : :
131 : : // forward to parent
132 : 0 : SpriteCanvasBaseT::disposeThis();
133 : 0 : }
134 : :
135 : 0 : ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
136 : : {
137 : 0 : return updateScreen( bUpdateAll );
138 : : }
139 : :
140 : 0 : ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
141 : : {
142 : 0 : return updateScreen( bUpdateAll );
143 : : }
144 : :
145 : 0 : sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
146 : : {
147 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
148 : :
149 : : // avoid repaints on hidden window (hidden: not mapped to
150 : : // screen). Return failure, since the screen really has _not_
151 : : // been updated (caller should try again later)
152 : : return !mbIsVisible ? false : maCanvasHelper.updateScreen(
153 : 0 : ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
154 : : bUpdateAll,
155 : 0 : mbSurfaceDirty);
156 : : }
157 : :
158 : 0 : ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException)
159 : : {
160 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME ) );
161 : : }
162 : :
163 : 0 : SurfaceSharedPtr SpriteCanvas::getSurface()
164 : : {
165 : 0 : return maDeviceHelper.getBufferSurface();
166 : : }
167 : :
168 : 0 : SurfaceSharedPtr SpriteCanvas::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
169 : : {
170 : 0 : return maDeviceHelper.createSurface( rSize, aContent );
171 : : }
172 : :
173 : 0 : SurfaceSharedPtr SpriteCanvas::createSurface( ::Bitmap& rBitmap )
174 : : {
175 : : BitmapSystemData aData;
176 : 0 : if( rBitmap.GetSystemData( aData ) ) {
177 : 0 : const Size& rSize = rBitmap.GetSizePixel();
178 : :
179 : 0 : return maDeviceHelper.createSurface( aData, rSize );
180 : : }
181 : :
182 : 0 : return SurfaceSharedPtr();
183 : : }
184 : :
185 : 0 : SurfaceSharedPtr SpriteCanvas::changeSurface( bool, bool )
186 : : {
187 : : // non-modifiable surface here
188 : 0 : return SurfaceSharedPtr();
189 : : }
190 : :
191 : 0 : OutputDevice* SpriteCanvas::getOutputDevice()
192 : : {
193 : 0 : return maDeviceHelper.getOutputDevice();
194 : : }
195 : :
196 : 0 : SurfaceSharedPtr SpriteCanvas::getBufferSurface()
197 : : {
198 : 0 : return maDeviceHelper.getBufferSurface();
199 : : }
200 : :
201 : 0 : SurfaceSharedPtr SpriteCanvas::getWindowSurface()
202 : : {
203 : 0 : return maDeviceHelper.getWindowSurface();
204 : : }
205 : :
206 : 0 : const ::basegfx::B2ISize& SpriteCanvas::getSizePixel()
207 : : {
208 : 0 : return maDeviceHelper.getSizePixel();
209 : : }
210 : :
211 : 0 : void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize& rSize )
212 : : {
213 : 0 : maCanvasHelper.setSize( rSize );
214 : : // re-set background surface, in case it needed recreation
215 : : maCanvasHelper.setSurface( maDeviceHelper.getBufferSurface(),
216 : 0 : false );
217 : 0 : }
218 : :
219 : 0 : void SpriteCanvas::flush()
220 : : {
221 : 0 : maDeviceHelper.flush();
222 : 0 : }
223 : :
224 : 0 : bool SpriteCanvas::repaint( const SurfaceSharedPtr& pSurface,
225 : : const rendering::ViewState& viewState,
226 : : const rendering::RenderState& renderState )
227 : : {
228 : 0 : return maCanvasHelper.repaint( pSurface, viewState, renderState );
229 : : }
230 : 0 : }
231 : :
232 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|