/src/libreoffice/canvas/inc/base/canvascustomspritebase.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <com/sun/star/rendering/XCanvas.hpp> |
23 | | |
24 | | #include <basegfx/point/b2dpoint.hxx> |
25 | | #include <basegfx/vector/b2dvector.hxx> |
26 | | #include <basegfx/range/b2drange.hxx> |
27 | | #include <base/integerbitmapbase.hxx> |
28 | | #include <base/bitmapcanvasbase.hxx> |
29 | | |
30 | | namespace com::sun::star::rendering { class XPolyPolygon2D; } |
31 | | |
32 | | namespace canvas |
33 | | { |
34 | | /** Helper template to handle XCustomSprite method forwarding to |
35 | | CanvasCustomSpriteHelper |
36 | | |
37 | | Use this helper to handle the XCustomSprite part of your |
38 | | implementation. |
39 | | |
40 | | @tpl Base |
41 | | Base class to use, most probably one of the |
42 | | WeakComponentImplHelperN templates with the appropriate |
43 | | interfaces. At least XCustomSprite and Sprite should be among |
44 | | them (why else would you use this template, then?). Base class |
45 | | must have a Base( const Mutex& ) constructor (like the |
46 | | WeakComponentImplHelperN templates have). |
47 | | |
48 | | @tpl SpriteHelper |
49 | | Sprite helper implementation for the backend in question |
50 | | |
51 | | @tpl CanvasHelper |
52 | | Canvas helper implementation for the backend in question |
53 | | |
54 | | @tpl Mutex |
55 | | Lock strategy to use. Defaults to using the |
56 | | BaseMutex-provided lock. Every time one of the methods is |
57 | | entered, an object of type Mutex is created with m_aMutex as |
58 | | the sole parameter, and destroyed again when the method scope |
59 | | is left. |
60 | | |
61 | | @tpl UnambiguousBase |
62 | | Optional unambiguous base class for XInterface of Base. It's |
63 | | sometimes necessary to specify this parameter, e.g. if Base |
64 | | derives from multiple UNO interface (were each provides its |
65 | | own version of XInterface, making the conversion ambiguous) |
66 | | |
67 | | @see CanvasCustomSpriteHelper for further contractual |
68 | | requirements towards the SpriteHelper type, and some examples. |
69 | | */ |
70 | | template< class Base, |
71 | | class SpriteHelper, |
72 | | class CanvasHelper, |
73 | | class Mutex=::osl::MutexGuard, |
74 | | class UnambiguousBase = css::uno::XInterface > class CanvasCustomSpriteBase : |
75 | | public IntegerBitmapBase< BitmapCanvasBase2<Base, CanvasHelper, Mutex, UnambiguousBase> > |
76 | | { |
77 | | public: |
78 | | typedef IntegerBitmapBase< BitmapCanvasBase2<Base, CanvasHelper, Mutex, UnambiguousBase> > BaseType; |
79 | | |
80 | | CanvasCustomSpriteBase() : |
81 | 0 | maSpriteHelper() |
82 | 0 | { |
83 | 0 | } |
84 | | |
85 | | /** Object is being disposed. |
86 | | |
87 | | Called from the cppu helper base, to notify disposal of |
88 | | this object. Already releases all internal references. |
89 | | |
90 | | @derive when overriding this method in derived classes, |
91 | | <em>always</em> call the base class' method! |
92 | | */ |
93 | | virtual void disposeThis() override |
94 | 0 | { |
95 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
96 | |
|
97 | 0 | maSpriteHelper.disposing(); |
98 | | |
99 | | // pass on to base class |
100 | 0 | BaseType::disposeThis(); |
101 | 0 | } |
102 | | |
103 | | // XCanvas: selectively override base's methods here, for opacity tracking |
104 | | virtual void SAL_CALL clear() override |
105 | 0 | { |
106 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
107 | |
|
108 | 0 | maSpriteHelper.clearingContent( this ); |
109 | | |
110 | | // and forward to base class, which handles the actual rendering |
111 | 0 | return BaseType::clear(); |
112 | 0 | } |
113 | | |
114 | | virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL |
115 | | drawBitmap( const css::uno::Reference< css::rendering::XBitmap >& xBitmap, |
116 | | const css::rendering::ViewState& viewState, |
117 | | const css::rendering::RenderState& renderState ) override |
118 | 0 | { |
119 | 0 | canvastools::verifyArgs(xBitmap, viewState, renderState, |
120 | 0 | __func__, |
121 | 0 | static_cast< typename BaseType::UnambiguousBaseType* >(this)); |
122 | |
|
123 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
124 | |
|
125 | 0 | maSpriteHelper.checkDrawBitmap( this, xBitmap, viewState, renderState ); |
126 | | |
127 | | // and forward to base class, which handles the actual rendering |
128 | 0 | return BaseType::drawBitmap( xBitmap, |
129 | 0 | viewState, |
130 | 0 | renderState ); |
131 | 0 | } |
132 | | |
133 | | // TODO(F3): If somebody uses the XIntegerBitmap methods to |
134 | | // clear pixel (setting alpha != 1.0 there), or a compositing |
135 | | // mode results in similar alpha, maSpriteHelper might |
136 | | // erroneously report fully opaque sprites. Effectively, all |
137 | | // render methods must be overridden here; or better, |
138 | | // functionality provided at the baseclass. |
139 | | |
140 | | // XSprite |
141 | | virtual void SAL_CALL setAlpha( double alpha ) override |
142 | 0 | { |
143 | 0 | canvastools::verifyRange( alpha, 0.0, 1.0 ); |
144 | |
|
145 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
146 | |
|
147 | 0 | maSpriteHelper.setAlpha( this, alpha ); |
148 | 0 | } |
149 | | |
150 | | virtual void SAL_CALL move( const css::geometry::RealPoint2D& aNewPos, |
151 | | const css::rendering::ViewState& viewState, |
152 | | const css::rendering::RenderState& renderState ) override |
153 | 0 | { |
154 | 0 | canvastools::verifyArgs(aNewPos, viewState, renderState, |
155 | 0 | __func__, |
156 | 0 | static_cast< typename BaseType::UnambiguousBaseType* >(this)); |
157 | |
|
158 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
159 | |
|
160 | 0 | maSpriteHelper.move( this, aNewPos, viewState, renderState ); |
161 | 0 | } |
162 | | |
163 | | virtual void SAL_CALL transform( const css::geometry::AffineMatrix2D& aTransformation ) override |
164 | 0 | { |
165 | 0 | canvastools::verifyArgs(aTransformation, |
166 | 0 | __func__, |
167 | 0 | static_cast< typename BaseType::UnambiguousBaseType* >(this)); |
168 | |
|
169 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
170 | |
|
171 | 0 | maSpriteHelper.transform( this, aTransformation ); |
172 | 0 | } |
173 | | |
174 | | virtual void SAL_CALL clip( const css::uno::Reference< css::rendering::XPolyPolygon2D >& aClip ) override |
175 | 0 | { |
176 | | // NULL xClip explicitly allowed here (to clear clipping) |
177 | |
|
178 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
179 | |
|
180 | 0 | maSpriteHelper.clip( this, aClip ); |
181 | 0 | } |
182 | | |
183 | | virtual void SAL_CALL setPriority( double nPriority ) override |
184 | 0 | { |
185 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
186 | |
|
187 | 0 | maSpriteHelper.setPriority( this, nPriority ); |
188 | 0 | } |
189 | | |
190 | | virtual void SAL_CALL show() override |
191 | 0 | { |
192 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
193 | |
|
194 | 0 | maSpriteHelper.show( this ); |
195 | 0 | } |
196 | | |
197 | | virtual void SAL_CALL hide() override |
198 | 0 | { |
199 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
200 | |
|
201 | 0 | maSpriteHelper.hide( this ); |
202 | 0 | } |
203 | | |
204 | | // XCustomSprite |
205 | | virtual css::uno::Reference< css::rendering::XCanvas > SAL_CALL |
206 | | getContentCanvas() override |
207 | 0 | { |
208 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
209 | |
|
210 | 0 | return this; |
211 | 0 | } |
212 | | |
213 | | // Sprite |
214 | | virtual bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const override |
215 | 0 | { |
216 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
217 | |
|
218 | 0 | return maSpriteHelper.isAreaUpdateOpaque( rUpdateArea ); |
219 | 0 | } |
220 | | |
221 | | virtual bool isContentChanged() const override |
222 | 0 | { |
223 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
224 | |
|
225 | 0 | return BaseType::mbSurfaceDirty; |
226 | 0 | } |
227 | | |
228 | | virtual ::basegfx::B2DPoint getPosPixel() const override |
229 | 0 | { |
230 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
231 | |
|
232 | 0 | return maSpriteHelper.getPosPixel(); |
233 | 0 | } |
234 | | |
235 | | virtual ::basegfx::B2DVector getSizePixel() const override |
236 | 0 | { |
237 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
238 | |
|
239 | 0 | return maSpriteHelper.getSizePixel(); |
240 | 0 | } |
241 | | |
242 | | virtual ::basegfx::B2DRange getUpdateArea() const override |
243 | 0 | { |
244 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
245 | |
|
246 | 0 | return maSpriteHelper.getUpdateArea(); |
247 | 0 | } |
248 | | |
249 | | virtual double getPriority() const override |
250 | 0 | { |
251 | 0 | typename BaseType::MutexType aGuard( BaseType::m_aMutex ); |
252 | |
|
253 | 0 | return maSpriteHelper.getPriority(); |
254 | 0 | } |
255 | | |
256 | | protected: |
257 | | SpriteHelper maSpriteHelper; |
258 | | }; |
259 | | } |
260 | | |
261 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |