xref: /aoo41x/main/canvas/source/tools/surface.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_CANVAS_SURFACE_HXX
29 #define INCLUDED_CANVAS_SURFACE_HXX
30 
31 #include <basegfx/point/b2ipoint.hxx>
32 #include <basegfx/point/b2dpoint.hxx>
33 #include <basegfx/polygon/b2dpolygon.hxx>
34 #include <basegfx/range/b2drectangle.hxx>
35 #include <basegfx/vector/b2isize.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <canvas/rendering/irendermodule.hxx>
38 #include <canvas/rendering/icolorbuffer.hxx>
39 #include <canvas/rendering/isurface.hxx>
40 
41 #include "surfacerect.hxx"
42 #include "pagemanager.hxx"
43 
44 namespace canvas
45 {
46 	//////////////////////////////////////////////////////////////////////////////////
47 	// Surface
48 	//////////////////////////////////////////////////////////////////////////////////
49 
50 	/** surfaces denote occupied areas withing pages.
51 
52 		pages encapsulate the hardware buffers that
53 		contain image data which can be used for texturing.
54 		surfaces are areas within those pages.
55 	*/
56 	class Surface
57 	{
58     public:
59 
60         Surface( const PageManagerSharedPtr&  rPageManager,
61                  const IColorBufferSharedPtr& rColorBuffer,
62                  const ::basegfx::B2IPoint&   rPos,
63                  const ::basegfx::B2ISize&    rSize );
64         ~Surface();
65 
66         void setColorBufferDirty();
67 
68         /** Render the surface content to screen.
69 
70             @param fAlpha
71             Overall alpha for content
72 
73             @param rPos
74             Output position
75 
76             @param rTransform
77             Output transformation (does not affect output position)
78         */
79         bool draw( double                         fAlpha,
80                    const ::basegfx::B2DPoint&     rPos,
81                    const ::basegfx::B2DHomMatrix& rTransform );
82 
83         /** Render the surface content to screen.
84 
85             @param fAlpha
86             Overall alpha for content
87 
88             @param rPos
89             Output position
90 
91             @param rArea
92             Subset of the surface to render. Coordinate system are
93             surface area pixel, given area will be clipped to the
94             surface bounds.
95 
96             @param rTransform
97             Output transformation (does not affect output position)
98         */
99         bool drawRectangularArea(
100             double                         fAlpha,
101             const ::basegfx::B2DPoint&     rPos,
102             const ::basegfx::B2DRange&     rArea,
103             const ::basegfx::B2DHomMatrix& rTransform );
104 
105         /** Render the surface content to screen.
106 
107             @param fAlpha
108             Overall alpha for content
109 
110             @param rPos
111             Output position
112 
113             @param rClipPoly
114             Clip polygon for the surface. The clip polygon is also
115             subject to the output transformation.
116 
117             @param rTransform
118             Output transformation (does not affect output position)
119         */
120         bool drawWithClip( double                           fAlpha,
121                            const ::basegfx::B2DPoint&       rPos,
122                            const ::basegfx::B2DPolygon&     rClipPoly,
123                            const ::basegfx::B2DHomMatrix&   rTransform );
124 
125 		// private attributes
126     private:
127         IColorBufferSharedPtr mpColorBuffer;
128 
129         // invoking any of the above defined 'draw' methods
130         // will forward primitive commands to the rendermodule.
131         PageManagerSharedPtr  mpPageManager;
132 
133         FragmentSharedPtr     mpFragment;
134 
135         // the offset of this surface with regard to the source
136         // image. if the source image had to be tiled into multiple
137         // surfaces, this offset denotes the relative pixel distance
138         // from the source image's upper, left corner
139         ::basegfx::B2IPoint   maSourceOffset;
140 
141         // the size in pixels of this surface. please note that
142         // this size is likely to be smaller than the size of
143         // the colorbuffer we're associated with since we
144         // maybe represent only a part of it.
145         ::basegfx::B2ISize    maSize;
146 
147         bool                  mbIsDirty;
148 
149 		// private methods
150     private:
151         bool refresh( canvas::IColorBuffer& rBuffer ) const;
152         void prepareRendering();
153 
154         basegfx::B2DRectangle getUVCoords() const;
155         basegfx::B2DRectangle getUVCoords( const ::basegfx::B2IPoint& rPos,
156                                            const ::basegfx::B2ISize&  rSize ) const;
157 	};
158 
159 	typedef ::boost::shared_ptr< Surface > SurfaceSharedPtr;
160 }
161 
162 #endif
163