1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
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 )
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" );
75 maArguments
[2] >>= aRect
;
77 sal_Bool
bIsFullscreen( sal_False
);
78 maArguments
[3] >>= bIsFullscreen
;
80 uno::Reference
< awt::XWindow
> xParentWindow
;
81 maArguments
[4] >>= xParentWindow
;
83 Window
* pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
85 throw lang::NoSupportException(
86 "Parent window not VCL window, or canvas out-of-process!", NULL
);
88 bool bHasXRender
= IsCairoWorking(pParentWindow
);
89 ENSURE_ARG_OR_THROW( bHasXRender
== true,
90 "CairoSpriteCanvas::SpriteCanvas: No RENDER extension" );
92 Size
aPixelSize( pParentWindow
->GetOutputSizePixel() );
93 const ::basegfx::B2ISize
aSize( aPixelSize
.Width(),
94 aPixelSize
.Height() );
96 ENSURE_ARG_OR_THROW( pParentWindow
!= NULL
,
97 "CairoSpriteCanvas::initialize: invalid Window pointer" );
100 maDeviceHelper
.init( *pParentWindow
,
105 setWindow(uno::Reference
<awt::XWindow2
>(xParentWindow
, uno::UNO_QUERY_THROW
));
107 maCanvasHelper
.init( maRedrawManager
,
111 maArguments
.realloc(0);
114 void SpriteCanvas::disposeThis()
116 ::osl::MutexGuard
aGuard( m_aMutex
);
118 mxComponentContext
.clear();
121 SpriteCanvasBaseT::disposeThis();
124 ::sal_Bool SAL_CALL
SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
126 return updateScreen( bUpdateAll
);
129 ::sal_Bool SAL_CALL
SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
131 return updateScreen( bUpdateAll
);
134 sal_Bool SAL_CALL
SpriteCanvas::updateScreen( sal_Bool bUpdateAll
) throw (uno::RuntimeException
)
136 ::osl::MutexGuard
aGuard( m_aMutex
);
138 // avoid repaints on hidden window (hidden: not mapped to
139 // screen). Return failure, since the screen really has _not_
140 // been updated (caller should try again later)
141 return !mbIsVisible
? false : maCanvasHelper
.updateScreen(
142 ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds
),
147 OUString SAL_CALL
SpriteCanvas::getServiceName( ) throw (uno::RuntimeException
)
149 return OUString( SPRITECANVAS_SERVICE_NAME
);
152 SurfaceSharedPtr
SpriteCanvas::getSurface()
154 return maDeviceHelper
.getBufferSurface();
157 SurfaceSharedPtr
SpriteCanvas::createSurface( const ::basegfx::B2ISize
& rSize
, Content aContent
)
159 return maDeviceHelper
.createSurface( rSize
, aContent
);
162 SurfaceSharedPtr
SpriteCanvas::createSurface( ::Bitmap
& rBitmap
)
164 BitmapSystemData aData
;
165 if( rBitmap
.GetSystemData( aData
) ) {
166 const Size
& rSize
= rBitmap
.GetSizePixel();
168 return maDeviceHelper
.createSurface( aData
, rSize
);
171 return SurfaceSharedPtr();
174 SurfaceSharedPtr
SpriteCanvas::changeSurface( bool, bool )
176 // non-modifiable surface here
177 return SurfaceSharedPtr();
180 OutputDevice
* SpriteCanvas::getOutputDevice()
182 return maDeviceHelper
.getOutputDevice();
185 SurfaceSharedPtr
SpriteCanvas::getBufferSurface()
187 return maDeviceHelper
.getBufferSurface();
190 SurfaceSharedPtr
SpriteCanvas::getWindowSurface()
192 return maDeviceHelper
.getWindowSurface();
195 const ::basegfx::B2ISize
& SpriteCanvas::getSizePixel()
197 return maDeviceHelper
.getSizePixel();
200 void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize
& rSize
)
202 maCanvasHelper
.setSize( rSize
);
203 // re-set background surface, in case it needed recreation
204 maCanvasHelper
.setSurface( maDeviceHelper
.getBufferSurface(),
208 void SpriteCanvas::flush()
210 maDeviceHelper
.flush();
213 bool SpriteCanvas::repaint( const SurfaceSharedPtr
& pSurface
,
214 const rendering::ViewState
& viewState
,
215 const rendering::RenderState
& renderState
)
217 return maCanvasHelper
.repaint( pSurface
, viewState
, renderState
);
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */