1 /*
2 (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
3 (c) Copyright 2000-2004 Convergence (integrated media) GmbH
4
5 All rights reserved.
6
7 Written by Denis Oliver Kropp <dok@directfb.org>,
8 Andreas Hundt <andi@fischlustig.de>,
9 Sven Neumann <neo@directfb.org>,
10 Ville Syrjälä <syrjala@sci.fi> and
11 Claudio Ciccani <klan@users.sf.net>.
12
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 2 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the
25 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27 */
28
29 #ifndef __GFX__CLIP_H__
30 #define __GFX__CLIP_H__
31
32 #include <directfb.h>
33
34 typedef enum {
35 DFEF_NONE = 0x00000000,
36
37 DFEF_LEFT = 0x00000001,
38 DFEF_RIGHT = 0x00000002,
39 DFEF_TOP = 0x00000004,
40 DFEF_BOTTOM = 0x00000008,
41
42 DFEF_ALL = 0x0000000F
43 } DFBEdgeFlags;
44
45 /*
46 * Clips the line to the clipping region.
47 * Returns DFB_TRUE if at least one pixel of the line resides in the region.
48 */
49 DFBBoolean dfb_clip_line( const DFBRegion *clip, DFBRegion *line );
50
51 /*
52 * Clips the rectangle to the clipping region.
53 * Returns true if there was an intersection with the clipping region.
54 */
55 DFBBoolean dfb_clip_rectangle( const DFBRegion *clip, DFBRectangle *rect );
56
57 /*
58 * Clips the rectangle to the clipping region.
59 * Returns a flag for each edge that wasn't cut off.
60 */
61 DFBEdgeFlags dfb_clip_edges( const DFBRegion *clip, DFBRectangle *rect );
62
63 static inline DFBBoolean
dfb_clip_needed(const DFBRegion * clip,DFBRectangle * rect)64 dfb_clip_needed( const DFBRegion *clip, DFBRectangle *rect )
65 {
66 return ((clip->x1 > rect->x) ||
67 (clip->y1 > rect->y) ||
68 (clip->x2 < rect->x + rect->w - 1) ||
69 (clip->y2 < rect->y + rect->h - 1)) ? DFB_TRUE : DFB_FALSE;
70 }
71
72 /*
73 * Simple check if triangle lies outside the clipping region.
74 * Returns true if the triangle may be visible within the region.
75 */
76 DFBBoolean dfb_clip_triangle_precheck( const DFBRegion *clip,
77 const DFBTriangle *tri );
78
79 /*
80 * Clips the triangle to the clipping region.
81 * Returns true if the triangle if visible within the region.
82 * The vertices of the polygon resulting from intersection are returned in buf.
83 * The number of vertices is at least 3.
84 */
85 DFBBoolean dfb_clip_triangle( const DFBRegion *clip,
86 const DFBTriangle *tri,
87 DFBPoint buf[6],
88 int *num );
89
90 /*
91 * Simple check if requested blitting lies outside of the clipping region.
92 * Returns true if blitting may need to be performed.
93 */
94 static inline DFBBoolean
dfb_clip_blit_precheck(const DFBRegion * clip,int w,int h,int dx,int dy)95 dfb_clip_blit_precheck( const DFBRegion *clip,
96 int w, int h, int dx, int dy )
97 {
98 if (w < 1 || h < 1 ||
99 (clip->x1 >= dx + w) ||
100 (clip->x2 < dx) ||
101 (clip->y1 >= dy + h) ||
102 (clip->y2 < dy))
103 return DFB_FALSE;
104
105 return DFB_TRUE;
106 }
107
108 /*
109 * Clips the blitting request to the clipping region.
110 * This includes adjustment of source AND destination coordinates.
111 */
112 void dfb_clip_blit( const DFBRegion *clip,
113 DFBRectangle *srect, int *dx, int *dy );
114
115 /*
116 * Clips the stretch blit request to the clipping region.
117 * This includes adjustment of source AND destination coordinates
118 * based on the scaling factor.
119 */
120 void dfb_clip_stretchblit( const DFBRegion *clip,
121 DFBRectangle *srect,
122 DFBRectangle *drect );
123
124 /*
125 * Clips the blitting request to the clipping region.
126 * This includes adjustment of source AND destination coordinates.
127 *
128 * In contrast to dfb_clip_blit() this also honors DSBLIT_ROTATE_ and DSBLIT_FLIP_ blittingflags.
129 *
130 * FIXME: rotation and flipping is not supported simultaniously since the software driver
131 * would crash in its current state.
132 */
133
134 void
135 dfb_clip_blit_flipped_rotated( const DFBRegion *clip,
136 DFBRectangle *srect, DFBRectangle *drect, DFBSurfaceBlittingFlags flags );
137
138
139
140 #endif
141
142