xref: /trunk/main/canvas/source/vcl/canvashelper.hxx (revision 91c99ff4)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _VCLCANVAS_CANVASHELPER_HXX_
25 #define _VCLCANVAS_CANVASHELPER_HXX_
26 
27 #include <com/sun/star/rendering/XCanvas.hpp>
28 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
29 
30 #include <vcl/outdev.hxx>
31 
32 #include <canvas/vclwrapper.hxx>
33 
34 #include "cachedbitmap.hxx"
35 #include "outdevprovider.hxx"
36 
37 #include <boost/utility.hpp>
38 
39 
40 namespace vclcanvas
41 {
42     class SpriteCanvas;
43 
44     /** Helper class for basic canvas functionality. Also offers
45         optional backbuffer painting, when providing it with a second
46         OutputDevice to render into.
47      */
48     class CanvasHelper : private ::boost::noncopyable
49     {
50     public:
51 		/** Create canvas helper
52          */
53         CanvasHelper();
54 
55         /// Release all references
56         void disposing();
57 
58 		/** Initialize canvas helper
59 
60         	This method late-initializes the canvas helper, providing
61         	it with the necessary device and output objects. Note that
62         	the CanvasHelper does <em>not</em> take ownership of the
63         	passed rDevice reference, nor does it perform any
64         	reference counting. Thus, to prevent the reference counted
65         	SpriteCanvas object from deletion, the user of this class
66         	is responsible for holding ref-counted references itself!
67 
68         	@param rDevice
69             Reference device this canvas is associated with
70 
71             @param rOutDev
72             Set primary output device for this canvas. That's where
73             all content is output to.
74 
75         	@param bProtect
76             When true, all output operations preserve outdev
77             state. When false, outdev state might change at any time.
78 
79         	@param bHaveAlpha
80             When true, hasAlpha() will always return true, otherwise, false.
81          */
82         void init( ::com::sun::star::rendering::XGraphicDevice& rDevice,
83                    const OutDevProviderSharedPtr&               rOutDev,
84                    bool                                         bProtect,
85                    bool                                         bHaveAlpha );
86 
87         /** Set primary output device
88 
89         	This changes the primary output device, where rendering is
90         	sent to.
91          */
92         void setOutDev( const OutDevProviderSharedPtr&	rOutDev,
93                         bool							bProtect);
94 
95         /** Set secondary output device
96 
97         	Used for sprites, to generate mask bitmap.
98          */
99         void setBackgroundOutDev( const OutDevProviderSharedPtr& rOutDev );
100 
101 
102         // CanvasHelper functionality
103         // ==========================
104 
105         // XCanvas (only providing, not implementing the
106         // interface. Also note subtle method parameter differences)
107         void clear();
108         void drawPoint( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
109                         const ::com::sun::star::geometry::RealPoint2D& 		aPoint,
110                         const ::com::sun::star::rendering::ViewState& 		viewState,
111                         const ::com::sun::star::rendering::RenderState& 	renderState );
112         void drawLine( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
113                        const ::com::sun::star::geometry::RealPoint2D& 	aStartPoint,
114                        const ::com::sun::star::geometry::RealPoint2D& 	aEndPoint,
115                        const ::com::sun::star::rendering::ViewState& 	viewState,
116                        const ::com::sun::star::rendering::RenderState& 	renderState	);
117         void drawBezier( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
118                          const ::com::sun::star::geometry::RealBezierSegment2D&	aBezierSegment,
119                          const ::com::sun::star::geometry::RealPoint2D& 		aEndPoint,
120                          const ::com::sun::star::rendering::ViewState& 			viewState,
121                          const ::com::sun::star::rendering::RenderState& 		renderState );
122         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
123         	drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
124                              const ::com::sun::star::uno::Reference<
125                              	::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
126                              const ::com::sun::star::rendering::ViewState& 		viewState,
127                              const ::com::sun::star::rendering::RenderState& 	renderState );
128         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
129         	strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
130                                const ::com::sun::star::uno::Reference<
131                                		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
132                                const ::com::sun::star::rendering::ViewState& 		viewState,
133                                const ::com::sun::star::rendering::RenderState& 		renderState,
134                                const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
135         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
136         	strokeTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
137                                        const ::com::sun::star::uno::Reference<
138                                        		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
139                                        const ::com::sun::star::rendering::ViewState& 		viewState,
140                                        const ::com::sun::star::rendering::RenderState& 		renderState,
141                                        const ::com::sun::star::uno::Sequence<
142                                        		::com::sun::star::rendering::Texture >& 		textures,
143                                        const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
144         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
145         	strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
146                                             const ::com::sun::star::uno::Reference<
147                                             		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
148                                             const ::com::sun::star::rendering::ViewState& 			viewState,
149                                             const ::com::sun::star::rendering::RenderState& 		renderState,
150                                             const ::com::sun::star::uno::Sequence<
151                                             		::com::sun::star::rendering::Texture >& 		textures,
152                                             const ::com::sun::star::uno::Reference<
153                                             		::com::sun::star::geometry::XMapping2D >& 		xMapping,
154                                             const ::com::sun::star::rendering::StrokeAttributes& 	strokeAttributes );
155         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
156         	queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
157                                const ::com::sun::star::uno::Reference<
158                                		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
159                                const ::com::sun::star::rendering::ViewState& 		viewState,
160                                const ::com::sun::star::rendering::RenderState& 		renderState,
161                                const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
162         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
163         	fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
164                              const ::com::sun::star::uno::Reference<
165                              		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
166                              const ::com::sun::star::rendering::ViewState& 			viewState,
167                              const ::com::sun::star::rendering::RenderState& 		renderState );
168         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
169         	fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
170                                      const ::com::sun::star::uno::Reference<
171                                      		::com::sun::star::rendering::XPolyPolygon2D >&	xPolyPolygon,
172                                      const ::com::sun::star::rendering::ViewState& 			viewState,
173                                      const ::com::sun::star::rendering::RenderState& 		renderState,
174                                      const ::com::sun::star::uno::Sequence<
175                                      		::com::sun::star::rendering::Texture >& 		textures );
176         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
177         	fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
178                                           const ::com::sun::star::uno::Reference<
179                                           		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
180                                           const ::com::sun::star::rendering::ViewState& 		viewState,
181                                           const ::com::sun::star::rendering::RenderState& 		renderState,
182                                           const ::com::sun::star::uno::Sequence<
183                                           		::com::sun::star::rendering::Texture >& 		textures,
184                                           const ::com::sun::star::uno::Reference<
185                                           		::com::sun::star::geometry::XMapping2D >& 		xMapping );
186 
187         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont >
188 	        createFont( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
189                         const ::com::sun::star::rendering::FontRequest& 	fontRequest,
190                         const ::com::sun::star::uno::Sequence<
191                         	::com::sun::star::beans::PropertyValue >& 		extraFontProperties,
192                         const ::com::sun::star::geometry::Matrix2D& 		fontMatrix );
193 
194         ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
195         	queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
196                                  const ::com::sun::star::rendering::FontInfo& 		aFilter,
197                                  const ::com::sun::star::uno::Sequence<
198                                  		::com::sun::star::beans::PropertyValue >& 	aFontProperties );
199 
200         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
201         	drawText( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
202                       const ::com::sun::star::rendering::StringContext& text,
203                       const ::com::sun::star::uno::Reference<
204                       		::com::sun::star::rendering::XCanvasFont >& xFont,
205                       const ::com::sun::star::rendering::ViewState& 	viewState,
206                       const ::com::sun::star::rendering::RenderState& 	renderState,
207                       sal_Int8 											textDirection );
208 
209         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
210         	drawTextLayout( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
211                             const ::com::sun::star::uno::Reference<
212                             		::com::sun::star::rendering::XTextLayout >& layoutetText,
213                             const ::com::sun::star::rendering::ViewState& 		viewState,
214                             const ::com::sun::star::rendering::RenderState& 	renderState );
215 
216         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
217         	drawBitmap( const ::com::sun::star::rendering::XCanvas* 	rCanvas,
218                         const ::com::sun::star::uno::Reference<
219                         		::com::sun::star::rendering::XBitmap >& xBitmap,
220                         const ::com::sun::star::rendering::ViewState& 	viewState,
221                         const ::com::sun::star::rendering::RenderState& renderState );
222         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
223         	drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
224                                  const ::com::sun::star::uno::Reference<
225                                  		::com::sun::star::rendering::XBitmap >&		xBitmap,
226                                  const ::com::sun::star::rendering::ViewState& 		viewState,
227                                  const ::com::sun::star::rendering::RenderState&	renderState );
228         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
229         	getDevice();
230 
231         // BitmapCanvasHelper functionality
232         // ================================
233 
234         void copyRect( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
235                        const ::com::sun::star::uno::Reference<
236                        		::com::sun::star::rendering::XBitmapCanvas >& 	sourceCanvas,
237                        const ::com::sun::star::geometry::RealRectangle2D& 	sourceRect,
238                        const ::com::sun::star::rendering::ViewState& 		sourceViewState,
239                        const ::com::sun::star::rendering::RenderState& 		sourceRenderState,
240                        const ::com::sun::star::geometry::RealRectangle2D& 	destRect,
241                        const ::com::sun::star::rendering::ViewState& 		destViewState,
242                        const ::com::sun::star::rendering::RenderState& 		destRenderState );
243 
244         ::com::sun::star::geometry::IntegerSize2D getSize();
245 
246         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > queryBitmapCanvas();
247 
248         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
249         	getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& 	newSize,
250                              sal_Bool 												beFast );
251 
252         ::com::sun::star::uno::Sequence< sal_Int8 >
253 	        getData( ::com::sun::star::rendering::IntegerBitmapLayout& 		bitmapLayout,
254                      const ::com::sun::star::geometry::IntegerRectangle2D&	rect );
255 
256         void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& 		data,
257                       const ::com::sun::star::rendering::IntegerBitmapLayout& 	bitmapLayout,
258                       const ::com::sun::star::geometry::IntegerRectangle2D& 	rect );
259 
260         void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& 		color,
261                        const ::com::sun::star::rendering::IntegerBitmapLayout&	bitmapLayout,
262                        const ::com::sun::star::geometry::IntegerPoint2D& 		pos );
263 
264         ::com::sun::star::uno::Sequence< sal_Int8 >
265 	        getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
266                       const ::com::sun::star::geometry::IntegerPoint2D& pos );
267 
268         ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
269 
270         /// Repaint a cached bitmap
271         bool repaint( const GraphicObjectSharedPtr&                   rGrf,
272                       const ::com::sun::star::rendering::ViewState&   viewState,
273                       const ::com::sun::star::rendering::RenderState& renderState,
274                       const ::Point&                                  rPt,
275                       const ::Size&                                   rSz,
276                       const GraphicAttr&                              rAttr ) const;
277 
278         /** Flush drawing queue.
279 
280             This only works for Window canvases, and ensures that all
281             pending render operations are flushed to the
282             driver/hardware.
283          */
284         void flush() const;
285 
286         enum ColorType
287         {
288             LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
289         };
290 
291         // returns transparency of color
292         int setupOutDevState( const ::com::sun::star::rendering::ViewState& 	viewState,
293                               const ::com::sun::star::rendering::RenderState& 	renderState,
294                               ColorType											eColorType ) const;
295 
296         /** Called from XCanvas base classes, to notify that content
297             is _about_ to change
298         */
modifying()299         void modifying() {}
300 
hasAlpha() const301         bool hasAlpha() const { return mbHaveAlpha; }
302 
303     protected:
304         /** Phyical output device
305 
306             Deliberately not a refcounted reference, because of
307             potential circular references for spritecanvas.
308          */
309         ::com::sun::star::rendering::XGraphicDevice* mpDevice;
310 
311         /// Rendering to this outdev preserves its state
312         OutDevProviderSharedPtr                      mpProtectedOutDev;
313 
314         /// Rendering to this outdev does not preserve its state
315         OutDevProviderSharedPtr                      mpOutDev;
316 
317         /// Rendering to this outdev does not preserve its state
318         OutDevProviderSharedPtr                      mp2ndOutDev;
319 
320         /// When true, content is able to represent alpha
321         bool                                         mbHaveAlpha;
322 
323     private:
324         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
325         	implDrawBitmap( const ::com::sun::star::rendering::XCanvas* 	rCanvas,
326                             const ::com::sun::star::uno::Reference<
327                   		          ::com::sun::star::rendering::XBitmap >& 	xBitmap,
328                             const ::com::sun::star::rendering::ViewState& 	viewState,
329                             const ::com::sun::star::rendering::RenderState& renderState,
330                             bool 											bModulateColors );
331 
332         bool setupTextOutput( ::Point&																				o_rOutPos,
333                               const ::com::sun::star::rendering::ViewState& 										viewState,
334                               const ::com::sun::star::rendering::RenderState& 										renderState,
335                               const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont >&	xFont ) const;
336 
337     };
338 }
339 
340 #endif /* _VCLCANVAS_CANVASHELPER_HXX_ */
341