xref: /trunk/main/canvas/source/tools/surface.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 INCLUDED_CANVAS_SURFACE_HXX
25 #define INCLUDED_CANVAS_SURFACE_HXX
26 
27 #include <basegfx/point/b2ipoint.hxx>
28 #include <basegfx/point/b2dpoint.hxx>
29 #include <basegfx/polygon/b2dpolygon.hxx>
30 #include <basegfx/range/b2drectangle.hxx>
31 #include <basegfx/vector/b2isize.hxx>
32 #include <basegfx/matrix/b2dhommatrix.hxx>
33 #include <canvas/rendering/irendermodule.hxx>
34 #include <canvas/rendering/icolorbuffer.hxx>
35 #include <canvas/rendering/isurface.hxx>
36 
37 #include "surfacerect.hxx"
38 #include "pagemanager.hxx"
39 
40 namespace canvas
41 {
42 	//////////////////////////////////////////////////////////////////////////////////
43 	// Surface
44 	//////////////////////////////////////////////////////////////////////////////////
45 
46 	/** surfaces denote occupied areas withing pages.
47 
48 		pages encapsulate the hardware buffers that
49 		contain image data which can be used for texturing.
50 		surfaces are areas within those pages.
51 	*/
52 	class Surface
53 	{
54     public:
55 
56         Surface( const PageManagerSharedPtr&  rPageManager,
57                  const IColorBufferSharedPtr& rColorBuffer,
58                  const ::basegfx::B2IPoint&   rPos,
59                  const ::basegfx::B2ISize&    rSize );
60         ~Surface();
61 
62         void setColorBufferDirty();
63 
64         /** Render the surface content to screen.
65 
66             @param fAlpha
67             Overall alpha for content
68 
69             @param rPos
70             Output position
71 
72             @param rTransform
73             Output transformation (does not affect output position)
74         */
75         bool draw( double                         fAlpha,
76                    const ::basegfx::B2DPoint&     rPos,
77                    const ::basegfx::B2DHomMatrix& rTransform );
78 
79         /** Render the surface content to screen.
80 
81             @param fAlpha
82             Overall alpha for content
83 
84             @param rPos
85             Output position
86 
87             @param rArea
88             Subset of the surface to render. Coordinate system are
89             surface area pixel, given area will be clipped to the
90             surface bounds.
91 
92             @param rTransform
93             Output transformation (does not affect output position)
94         */
95         bool drawRectangularArea(
96             double                         fAlpha,
97             const ::basegfx::B2DPoint&     rPos,
98             const ::basegfx::B2DRange&     rArea,
99             const ::basegfx::B2DHomMatrix& rTransform );
100 
101         /** Render the surface content to screen.
102 
103             @param fAlpha
104             Overall alpha for content
105 
106             @param rPos
107             Output position
108 
109             @param rClipPoly
110             Clip polygon for the surface. The clip polygon is also
111             subject to the output transformation.
112 
113             @param rTransform
114             Output transformation (does not affect output position)
115         */
116         bool drawWithClip( double                           fAlpha,
117                            const ::basegfx::B2DPoint&       rPos,
118                            const ::basegfx::B2DPolygon&     rClipPoly,
119                            const ::basegfx::B2DHomMatrix&   rTransform );
120 
121 		// private attributes
122     private:
123         IColorBufferSharedPtr mpColorBuffer;
124 
125         // invoking any of the above defined 'draw' methods
126         // will forward primitive commands to the rendermodule.
127         PageManagerSharedPtr  mpPageManager;
128 
129         FragmentSharedPtr     mpFragment;
130 
131         // the offset of this surface with regard to the source
132         // image. if the source image had to be tiled into multiple
133         // surfaces, this offset denotes the relative pixel distance
134         // from the source image's upper, left corner
135         ::basegfx::B2IPoint   maSourceOffset;
136 
137         // the size in pixels of this surface. please note that
138         // this size is likely to be smaller than the size of
139         // the colorbuffer we're associated with since we
140         // maybe represent only a part of it.
141         ::basegfx::B2ISize    maSize;
142 
143         bool                  mbIsDirty;
144 
145 		// private methods
146     private:
147         bool refresh( canvas::IColorBuffer& rBuffer ) const;
148         void prepareRendering();
149 
150         basegfx::B2DRectangle getUVCoords() const;
151         basegfx::B2DRectangle getUVCoords( const ::basegfx::B2IPoint& rPos,
152                                            const ::basegfx::B2ISize&  rSize ) const;
153 	};
154 
155 	typedef ::boost::shared_ptr< Surface > SurfaceSharedPtr;
156 }
157 
158 #endif
159