Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <canvas/debug.hxx>
21 : #include <canvas/verbosetrace.hxx>
22 : #include <canvas/canvastools.hxx>
23 : #include <tools/diagnose_ex.h>
24 :
25 : #include <osl/mutex.hxx>
26 :
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>
31 :
32 : #include <toolkit/helper/vclunohelper.hxx>
33 :
34 : #include <basegfx/matrix/b2dhommatrix.hxx>
35 : #include <basegfx/point/b2dpoint.hxx>
36 : #include <basegfx/tools/canvastools.hxx>
37 : #include <basegfx/numeric/ftools.hxx>
38 :
39 : #include "cairo_spritecanvas.hxx"
40 :
41 : using namespace ::cairo;
42 : using namespace ::com::sun::star;
43 :
44 : namespace cairocanvas
45 : {
46 0 : SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
47 : const uno::Reference< uno::XComponentContext >& rxContext ) :
48 : maArguments(aArguments),
49 0 : mxComponentContext( rxContext )
50 : {
51 0 : }
52 :
53 0 : void SpriteCanvas::initialize()
54 : {
55 : VERBOSE_TRACE("CairoSpriteCanvas created %p\n", this);
56 :
57 : // #i64742# Only call initialize when not in probe mode
58 0 : if( maArguments.getLength() == 0 )
59 0 : return;
60 :
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
68 : */
69 0 : 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" );
73 :
74 0 : awt::Rectangle aRect;
75 0 : maArguments[2] >>= aRect;
76 :
77 0 : bool bIsFullscreen( false );
78 0 : maArguments[3] >>= bIsFullscreen;
79 :
80 0 : uno::Reference< awt::XWindow > xParentWindow;
81 0 : maArguments[4] >>= xParentWindow;
82 :
83 0 : vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
84 0 : if( !pParentWindow )
85 : throw lang::NoSupportException(
86 0 : "Parent window not VCL window, or canvas out-of-process!", NULL);
87 :
88 0 : bool bHasCairo = pParentWindow->SupportsCairo();
89 0 : ENSURE_ARG_OR_THROW(bHasCairo,
90 : "CairoSpriteCanvas::SpriteCanvas: No Cairo capability");
91 :
92 0 : Size aPixelSize( pParentWindow->GetOutputSizePixel() );
93 0 : const ::basegfx::B2ISize aSize( aPixelSize.Width(),
94 0 : aPixelSize.Height() );
95 :
96 : // setup helper
97 : maDeviceHelper.init( *pParentWindow,
98 : *this,
99 : aSize,
100 0 : bIsFullscreen );
101 :
102 0 : setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
103 :
104 : maCanvasHelper.init( maRedrawManager,
105 : *this,
106 0 : aSize );
107 :
108 0 : maArguments.realloc(0);
109 : }
110 :
111 0 : void SpriteCanvas::disposeThis()
112 : {
113 0 : ::osl::MutexGuard aGuard( m_aMutex );
114 :
115 0 : mxComponentContext.clear();
116 :
117 : // forward to parent
118 0 : SpriteCanvasBaseT::disposeThis();
119 0 : }
120 :
121 0 : sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException, std::exception)
122 : {
123 0 : return updateScreen( bUpdateAll );
124 : }
125 :
126 0 : sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
127 : {
128 0 : return updateScreen( bUpdateAll );
129 : }
130 :
131 0 : sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException, std::exception)
132 : {
133 0 : ::osl::MutexGuard aGuard( m_aMutex );
134 :
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 0 : return mbIsVisible && maCanvasHelper.updateScreen(
139 0 : ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
140 : bUpdateAll,
141 0 : mbSurfaceDirty);
142 : }
143 :
144 0 : OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException, std::exception)
145 : {
146 0 : return OUString( SPRITECANVAS_SERVICE_NAME );
147 : }
148 :
149 0 : SurfaceSharedPtr SpriteCanvas::getSurface()
150 : {
151 0 : return maDeviceHelper.getBufferSurface();
152 : }
153 :
154 0 : SurfaceSharedPtr SpriteCanvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
155 : {
156 0 : return maDeviceHelper.createSurface( rSize, aContent );
157 : }
158 :
159 0 : SurfaceSharedPtr SpriteCanvas::createSurface( ::Bitmap& rBitmap )
160 : {
161 : BitmapSystemData aData;
162 0 : if( rBitmap.GetSystemData( aData ) ) {
163 0 : const Size& rSize = rBitmap.GetSizePixel();
164 :
165 0 : return maDeviceHelper.createSurface( aData, rSize );
166 : }
167 :
168 0 : return SurfaceSharedPtr();
169 : }
170 :
171 0 : SurfaceSharedPtr SpriteCanvas::changeSurface( bool, bool )
172 : {
173 : // non-modifiable surface here
174 0 : return SurfaceSharedPtr();
175 : }
176 :
177 0 : OutputDevice* SpriteCanvas::getOutputDevice()
178 : {
179 0 : return maDeviceHelper.getOutputDevice();
180 : }
181 :
182 0 : SurfaceSharedPtr SpriteCanvas::getBufferSurface()
183 : {
184 0 : return maDeviceHelper.getBufferSurface();
185 : }
186 :
187 0 : SurfaceSharedPtr SpriteCanvas::getWindowSurface()
188 : {
189 0 : return maDeviceHelper.getWindowSurface();
190 : }
191 :
192 0 : const ::basegfx::B2ISize& SpriteCanvas::getSizePixel()
193 : {
194 0 : return maDeviceHelper.getSizePixel();
195 : }
196 :
197 0 : void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize& rSize )
198 : {
199 0 : maCanvasHelper.setSize( rSize );
200 : // re-set background surface, in case it needed recreation
201 : maCanvasHelper.setSurface( maDeviceHelper.getBufferSurface(),
202 0 : false );
203 0 : }
204 :
205 0 : void SpriteCanvas::flush()
206 : {
207 0 : maDeviceHelper.flush();
208 0 : }
209 :
210 0 : bool SpriteCanvas::repaint( const SurfaceSharedPtr& pSurface,
211 : const rendering::ViewState& viewState,
212 : const rendering::RenderState& renderState )
213 : {
214 0 : return maCanvasHelper.repaint( pSurface, viewState, renderState );
215 : }
216 6 : }
217 :
218 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|