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 <vcl/sysdata.hxx>
40 :
41 : #include "cairo_canvas.hxx"
42 :
43 : using namespace ::cairo;
44 : using namespace ::com::sun::star;
45 :
46 : namespace cairocanvas
47 : {
48 3 : Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
49 : const uno::Reference< uno::XComponentContext >& rxContext ) :
50 : maArguments(aArguments),
51 3 : mxComponentContext( rxContext )
52 : {
53 3 : }
54 :
55 3 : void Canvas::initialize()
56 : {
57 : // #i64742# Only perform initialization when not in probe mode
58 3 : if( maArguments.getLength() == 0 )
59 2 : 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 : VERBOSE_TRACE("Canvas created %p\n", this);
70 :
71 3 : ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
72 : maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
73 : maArguments[5].getValueTypeClass() == uno::TypeClass_SEQUENCE,
74 : "Canvas::initialize: wrong number of arguments, or wrong types" );
75 :
76 : // We expect a single Any here, containing a pointer to a valid
77 : // VCL output device, on which to output (mostly needed for text)
78 3 : sal_Int64 nPtr = 0;
79 3 : maArguments[0] >>= nPtr;
80 3 : OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
81 :
82 3 : ENSURE_ARG_OR_THROW( pOutDev != NULL,
83 : "Canvas::initialize: invalid OutDev pointer" );
84 :
85 3 : awt::Rectangle aBounds;
86 3 : maArguments[2] >>= aBounds;
87 :
88 3 : uno::Sequence<sal_Int8> aSeq;
89 3 : maArguments[5] >>= aSeq;
90 :
91 3 : const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
92 3 : if( !pSysData || !pSysData->nSize )
93 0 : throw lang::NoSupportException( "Passed SystemGraphicsData invalid!" );
94 :
95 3 : bool bHasCairo = pOutDev->SupportsCairo();
96 3 : ENSURE_ARG_OR_THROW(bHasCairo, "SpriteCanvas::SpriteCanvas: No Cairo capability");
97 :
98 : // setup helper
99 2 : maDeviceHelper.init( *this, *pOutDev );
100 :
101 2 : maCanvasHelper.init( basegfx::B2ISize(aBounds.Width, aBounds.Height), *this, this );
102 :
103 : // forward surface to render on to canvashelper
104 2 : maCanvasHelper.setSurface( maDeviceHelper.getSurface(), false );
105 :
106 3 : maArguments.realloc(0);
107 : }
108 :
109 3 : Canvas::~Canvas()
110 : {
111 : OSL_TRACE( "CairoCanvas destroyed" );
112 3 : }
113 :
114 3 : void Canvas::disposeThis()
115 : {
116 3 : ::osl::MutexGuard aGuard( m_aMutex );
117 :
118 3 : mxComponentContext.clear();
119 :
120 : // forward to parent
121 3 : CanvasBaseT::disposeThis();
122 3 : }
123 :
124 0 : OUString SAL_CALL Canvas::getServiceName( ) throw (uno::RuntimeException, std::exception)
125 : {
126 0 : return OUString( CANVAS_SERVICE_NAME );
127 : }
128 :
129 0 : bool Canvas::repaint( const SurfaceSharedPtr& pSurface,
130 : const rendering::ViewState& viewState,
131 : const rendering::RenderState& renderState )
132 : {
133 0 : return maCanvasHelper.repaint( pSurface, viewState, renderState );
134 : }
135 :
136 0 : SurfaceSharedPtr Canvas::getSurface()
137 : {
138 0 : return maDeviceHelper.getSurface();
139 : }
140 :
141 2 : SurfaceSharedPtr Canvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
142 : {
143 2 : return maDeviceHelper.createSurface( rSize, aContent );
144 : }
145 :
146 0 : SurfaceSharedPtr Canvas::createSurface( ::Bitmap& rBitmap )
147 : {
148 0 : SurfaceSharedPtr pSurface;
149 :
150 : BitmapSystemData aData;
151 0 : if( rBitmap.GetSystemData( aData ) ) {
152 0 : const Size& rSize = rBitmap.GetSizePixel();
153 :
154 0 : pSurface = maDeviceHelper.createSurface( aData, rSize );
155 : }
156 :
157 0 : return pSurface;
158 : }
159 :
160 0 : SurfaceSharedPtr Canvas::changeSurface( bool, bool )
161 : {
162 : // non-modifiable surface here
163 0 : return SurfaceSharedPtr();
164 : }
165 :
166 2 : OutputDevice* Canvas::getOutputDevice()
167 : {
168 2 : return maDeviceHelper.getOutputDevice();
169 : }
170 6 : }
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|