summaryrefslogtreecommitdiff
path: root/Source/DirectFB/gfxdrivers/cle266/uc_state.c
blob: 7ac74e90967d5d34dbd9ae114066e078da708ae4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
   Copyright (c) 2003 Andreas Robinson, All rights reserved.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
*/

#include <config.h>

#include <gfx/convert.h>
#include "unichrome.h"
#include "uc_state.h"
#include "uc_accel.h"
#include "uc_hw.h"

enum uc_state_type {
     UC_TYPE_UNSUPPORTED,
     UC_TYPE_2D,
     UC_TYPE_3D
};

/// GPU selecting functions --------------------------------------------------

static inline bool
uc_has_dst_format( DFBSurfacePixelFormat format )
{
     switch (format) {
          case DSPF_ARGB1555:
          case DSPF_RGB16:
          case DSPF_RGB32:
          case DSPF_ARGB:
               return true;

          default:
               break;
     }

     return false;
}

static inline bool
uc_has_src_format_3d( DFBSurfacePixelFormat format )
{
     switch (format) {
          case DSPF_ARGB1555:
          case DSPF_RGB16:
          case DSPF_RGB32:
          case DSPF_ARGB:
          case DSPF_A8:
          case DSPF_LUT8:
               return true;

          default:
               break;
     }

     return false;
}

static inline enum uc_state_type
uc_select_drawtype( CardState* state,
                    DFBAccelerationMask accel )
{
     if (!(state->drawingflags & ~UC_DRAWING_FLAGS_2D) &&
         !(accel & DFXL_FILLTRIANGLE))
          return UC_TYPE_2D;

     if (!(state->drawingflags & ~UC_DRAWING_FLAGS_3D))
          return UC_TYPE_3D;

     return UC_TYPE_UNSUPPORTED;
}

static inline enum uc_state_type
uc_select_blittype( CardState* state,
                    DFBAccelerationMask accel )
{
     if (!(state->blittingflags & ~UC_BLITTING_FLAGS_2D)) {
          if ((state->source->config.format == state->destination->config.format) &&
              !((state->blittingflags & DSBLIT_SRC_COLORKEY) &&
                (state->blittingflags & DSBLIT_DST_COLORKEY)) &&
              !(accel & (DFXL_STRETCHBLIT | DFXL_TEXTRIANGLES)))
               return UC_TYPE_2D;
     }

     if (!(state->blittingflags & ~UC_BLITTING_FLAGS_3D)) {
          if (uc_has_src_format_3d( state->source->config.format ))
               return UC_TYPE_3D;
     }

     return UC_TYPE_UNSUPPORTED;
}

// DirectFB interfacing functions --------------------------------------------

void uc_check_state(void *drv, void *dev,
                    CardState *state, DFBAccelerationMask accel)
{
     /* Check destination format. */
     if (!uc_has_dst_format( state->destination->config.format ))
          return;

     if (DFB_DRAWING_FUNCTION(accel)) {
          /* Check drawing parameters. */
          switch (uc_select_drawtype(state, accel)) {
               case UC_TYPE_2D:
                    state->accel |= UC_DRAWING_FUNCTIONS_2D;
                    break;
               case UC_TYPE_3D:
                    state->accel |= UC_DRAWING_FUNCTIONS_3D;
                    break;
               default:
                    return;
          }
     }
     else {
          /* Check blitting parameters. */
          switch (uc_select_blittype(state, accel)) {
               case UC_TYPE_2D:
                    state->accel |= UC_BLITTING_FUNCTIONS_2D;
                    break;
               case UC_TYPE_3D:
                    state->accel |= UC_BLITTING_FUNCTIONS_3D;
                    break;
               default:
                    return;
          }
     }
}

void uc_set_state(void *drv, void *dev, GraphicsDeviceFuncs *funcs,
                  CardState *state, DFBAccelerationMask accel)
{
     UcDriverData   *ucdrv = (UcDriverData*) drv;
     UcDeviceData   *ucdev = (UcDeviceData*) dev;
     struct uc_fifo *fifo  = ucdrv->fifo;

     u32 rop3d     = HC_HROP_P;
     u32 regEnable = HC_HenCW_MASK | HC_HenAW_MASK;

     StateModificationFlags modified = state->mod_hw;

     // Check modified states and update hw

     if (modified & SMF_SOURCE)
          UC_INVALIDATE( uc_source2d );

     if (modified & (SMF_BLITTING_FLAGS | SMF_SOURCE))
          UC_INVALIDATE( uc_source3d | uc_texenv );

     if (modified & (SMF_BLITTING_FLAGS | SMF_SRC_COLORKEY | SMF_DST_COLORKEY))
          UC_INVALIDATE( uc_colorkey2d );

     if (modified & (SMF_COLOR | SMF_DESTINATION | SMF_DRAWING_FLAGS))
          UC_INVALIDATE( uc_color2d );

     if (modified & (SMF_SRC_BLEND | SMF_DST_BLEND))
          UC_INVALIDATE( uc_blending_fn );


     if (modified & SMF_COLOR)
          ucdev->color3d = PIXEL_ARGB( state->color.a, state->color.r,
                                       state->color.g, state->color.b );

     if (modified & SMF_DRAWING_FLAGS) {
          if (state->drawingflags & DSDRAW_XOR) {
               ucdev->draw_rop3d = HC_HROP_DPx;
               ucdev->draw_rop2d = VIA_ROP_DPx;
          }
          else {
               ucdev->draw_rop3d = HC_HROP_P;
               ucdev->draw_rop2d = VIA_ROP_P;
          }
     }

     ucdev->bflags = state->blittingflags;

     if (modified & SMF_DESTINATION)
          uc_set_destination(ucdrv, ucdev, state);

     if (modified & SMF_CLIP)
          uc_set_clip(ucdrv, ucdev, state);


     // Select GPU and check remaining states

     if (DFB_DRAWING_FUNCTION(accel)) {

          switch (uc_select_drawtype(state, accel)) {
               case UC_TYPE_2D:
                    funcs->FillRectangle = uc_fill_rectangle;
                    funcs->DrawRectangle = uc_draw_rectangle;
                    funcs->DrawLine = uc_draw_line;

                    uc_set_color_2d(ucdrv, ucdev, state);

                    state->set = UC_DRAWING_FUNCTIONS_2D;
                    break;

               case UC_TYPE_3D:
                    funcs->FillRectangle = uc_fill_rectangle_3d;
                    funcs->DrawRectangle = uc_draw_rectangle_3d;
                    funcs->DrawLine = uc_draw_line_3d;

                    if (state->drawingflags & DSDRAW_BLEND) {
                         uc_set_blending_fn(ucdrv, ucdev, state);
                         regEnable |= HC_HenABL_MASK;
                    }

                    rop3d = ucdev->draw_rop3d;

                    state->set = UC_DRAWING_FUNCTIONS_3D;
                    break;

               case UC_TYPE_UNSUPPORTED:
                    D_BUG("Unsupported drawing function!");
                    break;
          }
     }
     else { // DFB_BLITTING_FUNCTION(accel)
          switch (uc_select_blittype(state, accel)) {
               case UC_TYPE_2D:
                    uc_set_source_2d(ucdrv, ucdev, state);
                    funcs->Blit = uc_blit;

                    uc_set_colorkey_2d(ucdrv, ucdev, state);
                    state->set = UC_BLITTING_FUNCTIONS_2D;
                    break;

               case UC_TYPE_3D:
                    funcs->Blit = uc_blit_3d;
                    uc_set_source_3d(ucdrv, ucdev, state);
                    uc_set_texenv(ucdrv, ucdev, state);
                    uc_set_blending_fn(ucdrv, ucdev, state);

                    regEnable |= HC_HenTXMP_MASK | HC_HenTXCH_MASK | HC_HenTXPP_MASK | HC_HenDT_MASK;

                    if (state->blittingflags & (DSBLIT_BLEND_ALPHACHANNEL |
                                                DSBLIT_BLEND_COLORALPHA))
                         regEnable |= HC_HenABL_MASK;

                    state->set = UC_BLITTING_FUNCTIONS_3D;
                    break;

               case UC_TYPE_UNSUPPORTED:
                    D_BUG("Unsupported drawing function!");
                    break;
          }
     }

#ifdef UC_ENABLE_3D
     UC_FIFO_PREPARE( fifo, 6 );
     UC_FIFO_ADD_HDR( fifo, HC_ParaType_NotTex << 16 );

     /* Don't know what this does. DRI code always clears it. */
     UC_FIFO_ADD_3D ( fifo, HC_SubA_HPixGC,   0 );

     UC_FIFO_ADD_3D ( fifo, HC_SubA_HEnable,  regEnable );
     UC_FIFO_ADD_3D ( fifo, HC_SubA_HFBBMSKL, 0xffffff );
     UC_FIFO_ADD_3D ( fifo, HC_SubA_HROP,     rop3d | 0xff );
#endif

     UC_FIFO_CHECK(fifo);

     state->mod_hw = 0;
}