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 __GENERIC_H__
30 #define __GENERIC_H__
31 
32 #include <dfb_types.h>
33 
34 #include <directfb.h>
35 #include <core/coretypes.h>
36 #include <core/gfxcard.h>
37 
38 /* this order is required for Intel with MMX, how about bigendian? */
39 
40 typedef union {
41      struct {
42           u16 b;
43           u16 g;
44           u16 r;
45           u16 a;
46      } RGB;
47      struct {
48           u16 u;
49           u16 v;
50           u16 y;
51           u16 a;
52      } YUV;
53 } GenefxAccumulator;
54 
55 
56 typedef struct _GenefxState GenefxState;
57 
58 typedef void (*GenefxFunc)(GenefxState *gfxs);
59 
60 /*
61  * State of the virtual graphics processing unit "Genefx" (pron. 'genie facts').
62  */
63 struct _GenefxState {
64      GenefxFunc funcs[32];
65 
66      int length;    /* span length */
67      int Slen;      /* span length (source) */
68      int Dlen;      /* span length (destination) */
69 
70      /*
71       * state values
72       */
73      void *dst_org[3];
74      void *src_org[3];
75      int dst_pitch;
76      int src_pitch;
77 
78      int dst_bpp;
79      int src_bpp;
80 
81      DFBSurfaceCapabilities dst_caps;
82      DFBSurfaceCapabilities src_caps;
83 
84      DFBSurfacePixelFormat src_format;
85      DFBSurfacePixelFormat dst_format;
86 
87      int dst_height;
88      int src_height;
89 
90      int dst_field_offset;
91      int src_field_offset;
92 
93      DFBColor color;
94 
95      /*
96       * operands
97       */
98      void *Aop[3];
99      void *Bop[3];
100      u32   Cop;
101 
102      int   Astep;
103      int   Bstep;
104 
105      u8 YCop;
106      u8 CbCop;
107      u8 CrCop;
108 
109      int Aop_field;
110      int Bop_field;
111 
112      int AopY;
113      int BopY;
114 
115      int s;
116      int t;
117 
118      /*
119       * color keys
120       */
121      u32 Dkey;
122      u32 Skey;
123 
124      /*
125       * color lookup tables
126       */
127      CorePalette *Alut;
128      CorePalette *Blut;
129 
130      /*
131       * accumulators
132       */
133      void              *ABstart;
134      int                ABsize;
135      GenefxAccumulator *Aacc;
136      GenefxAccumulator *Bacc;
137      GenefxAccumulator *Tacc; /* for simultaneous S+D blending */
138      GenefxAccumulator  Cacc;
139      GenefxAccumulator  SCacc;
140 
141      /*
142       * dataflow control
143       */
144      GenefxAccumulator *Xacc; /* writing pointer for blending */
145      GenefxAccumulator *Yacc; /* input pointer for blending */
146      GenefxAccumulator *Dacc;
147      GenefxAccumulator *Sacc;
148 
149      void        **Sop;
150      CorePalette  *Slut;
151 
152      int Ostep; /* controls horizontal blitting direction */
153 
154      int SperD;     /* for scaled/texture routines only */
155      int TperD;     /* for texture routines only */
156      int Xphase;    /* initial value for fractional steps (zero if not clipped) */
157 
158      bool need_accumulator;
159 
160      int *trans;
161      int  num_trans;
162 };
163 
164 /**********************************************************************************************************************/
165 
166 
167 typedef struct {
168      int x;
169      int y;
170      int s;
171      int t;
172 } GenefxVertexAffine;
173 
174 /**********************************************************************************************************************/
175 
176 void gGetDriverInfo( GraphicsDriverInfo *info );
177 void gGetDeviceInfo( GraphicsDeviceInfo *info );
178 
179 bool gAcquire  ( CardState *state, DFBAccelerationMask accel );
180 void gRelease ( CardState *state );
181 
182 void gFillRectangle ( CardState *state, DFBRectangle *rect );
183 void gDrawLine      ( CardState *state, DFBRegion    *line );
184 
185 void gBlit          ( CardState *state, DFBRectangle *rect, int dx, int dy );
186 void gStretchBlit   ( CardState *state, DFBRectangle *srect, DFBRectangle *drect );
187 
188 
189 void Genefx_TextureTriangles( CardState            *state,
190                               DFBVertex            *vertices,
191                               int                   num,
192                               DFBTriangleFormation  formation,
193                               const DFBRegion      *clip );
194 
195 void Genefx_TextureTrianglesAffine( CardState            *state,
196                                     GenefxVertexAffine   *vertices,
197                                     int                   num,
198                                     DFBTriangleFormation  formation,
199                                     const DFBRegion      *clip );
200 
201 /**********************************************************************************************************************/
202 /**********************************************************************************************************************/
203 
204 void Genefx_TextureTriangleAffine( GenefxState        *gfxs,
205                                    GenefxVertexAffine *v0,
206                                    GenefxVertexAffine *v1,
207                                    GenefxVertexAffine *v2,
208                                    const DFBRegion    *clip );
209 
210 
211 /**********************************************************************************************************************/
212 /**********************************************************************************************************************/
213 
214 
215 #define CHECK_PIPELINE()                                                             \
216      {                                                                               \
217           if (!gfxs->funcs[0])                                                       \
218                return;                                                               \
219                                                                                      \
220           if (dfb_config->software_trace) {                                          \
221                int         i;                                                        \
222                GenefxFunc *funcs = gfxs->funcs;                                      \
223                                                                                      \
224                direct_log_lock( NULL );                                              \
225                direct_log_printf( NULL, "  Software Fallback Pipeline:\n" );         \
226                                                                                      \
227                for (i=0; funcs[i]; ++i)                                              \
228                     direct_log_printf( NULL, "    [%2d] %s\n", i,                    \
229                                        direct_trace_lookup_symbol_at( funcs[i] ) );  \
230                                                                                      \
231                direct_log_printf( NULL, "\n" );                                      \
232                direct_log_unlock( NULL );                                            \
233           }                                                                          \
234      }
235 
236 #define RUN_PIPELINE()                     \
237      {                                     \
238           int         i;                   \
239           GenefxFunc *funcs = gfxs->funcs; \
240                                            \
241           for (i=0; funcs[i]; ++i)         \
242                funcs[i]( gfxs );           \
243      }
244 
245 
246 
247 /**********************************************************************************************************************/
248 
249 typedef void (*XopAdvanceFunc)( GenefxState *gfxs );
250 
251 
252 void Genefx_Aop_xy( GenefxState *gfxs, int x, int y );
253 
254 void Genefx_Aop_crab( GenefxState *gfxs );
255 
256 void Genefx_Aop_prev_crab( GenefxState *gfxs );
257 
258 void Genefx_Aop_next( GenefxState *gfxs );
259 
260 void Genefx_Aop_prev( GenefxState *gfxs );
261 
262 
263 void Genefx_Bop_xy( GenefxState *gfxs, int x, int y );
264 
265 void Genefx_Bop_next( GenefxState *gfxs );
266 
267 void Genefx_Bop_prev( GenefxState *gfxs );
268 
269 /**********************************************************************************************************************/
270 
271 bool Genefx_ABacc_prepare( GenefxState *gfxs, int width );
272 
273 void Genefx_ABacc_flush( GenefxState *gfxs );
274 
275 #endif
276