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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
|
/*
* Copyright (C) 2004-2006 Claudio Ciccani <klan@users.sf.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* Based on glfbdev.c, written by Brian Paul.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <direct/messages.h>
#include <direct/interface.h>
#include <direct/mem.h>
#include <directfb.h>
#include <directfb_version.h>
#define VERSION_CODE( M, m, r ) (((M) * 1000) + ((m) * 100) + ((r)))
#define DIRECTFB_VERSION_CODE VERSION_CODE( DIRECTFB_MAJOR_VERSION, \
DIRECTFB_MINOR_VERSION, \
DIRECTFB_MICRO_VERSION )
#ifdef CLAMP
# undef CLAMP
#endif
#include "GL/directfbgl.h"
#include "glheader.h"
#include "buffers.h"
#include "context.h"
#include "extensions.h"
#include "framebuffer.h"
#include "renderbuffer.h"
#include "imports.h"
#include "texformat.h"
#include "teximage.h"
#include "texstore.h"
#include "array_cache/acache.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
#include "tnl/t_pipeline.h"
#include "drivers/common/driverfuncs.h"
static DFBResult
Probe( void *data );
static DFBResult
Construct( IDirectFBGL *thiz,
IDirectFBSurface *surface );
#include <direct/interface_implementation.h>
DIRECT_INTERFACE_IMPLEMENTATION( IDirectFBGL, Mesa )
/*
* private data struct of IDirectFBGL
*/
typedef struct {
int ref; /* reference counter */
DFBBoolean locked;
IDirectFBSurface *surface;
DFBSurfacePixelFormat format;
int width;
int height;
struct {
__u8 *start;
__u8 *end;
int pitch;
} video;
GLvisual visual;
GLframebuffer framebuffer;
GLcontext context;
struct gl_renderbuffer render;
} IDirectFBGL_data;
/******************************************************************************/
static pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER;
static unsigned int global_ref = 0;
static inline int directfbgl_init( void )
{
pthread_mutexattr_t attr;
int ret;
if (global_ref++)
return 0;
pthread_mutexattr_init( &attr );
pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK );
ret = pthread_mutex_init( &global_lock, &attr );
pthread_mutexattr_destroy( &attr );
return ret;
}
static inline void directfbgl_finish( void )
{
if (--global_ref == 0)
pthread_mutex_destroy( &global_lock );
}
#define directfbgl_lock() pthread_mutex_lock( &global_lock )
#define directfbgl_unlock() pthread_mutex_unlock( &global_lock )
/******************************************************************************/
static bool directfbgl_init_visual ( GLvisual *visual,
DFBSurfacePixelFormat format );
static bool directfbgl_create_context ( GLcontext *context,
GLframebuffer *framebuffer,
GLvisual *visual,
DFBSurfacePixelFormat format,
IDirectFBGL_data *data );
static void directfbgl_destroy_context( GLcontext *context,
GLframebuffer *framebuffer );
/******************************************************************************/
static void
IDirectFBGL_Mesa_Destruct( IDirectFBGL *thiz )
{
IDirectFBGL_data *data = (IDirectFBGL_data*) thiz->priv;
directfbgl_destroy_context( &data->context, &data->framebuffer );
if (data->surface)
data->surface->Release( data->surface );
DIRECT_DEALLOCATE_INTERFACE( thiz );
directfbgl_finish();
}
static DFBResult
IDirectFBGL_Mesa_AddRef( IDirectFBGL *thiz )
{
DIRECT_INTERFACE_GET_DATA( IDirectFBGL );
data->ref++;
return DFB_OK;
}
static DFBResult
IDirectFBGL_Mesa_Release( IDirectFBGL *thiz )
{
DIRECT_INTERFACE_GET_DATA( IDirectFBGL )
if (--data->ref == 0)
IDirectFBGL_Mesa_Destruct( thiz );
return DFB_OK;
}
static DFBResult
IDirectFBGL_Mesa_Lock( IDirectFBGL *thiz )
{
IDirectFBSurface *surface;
int width = 0;
int height = 0;
DFBResult err;
DIRECT_INTERFACE_GET_DATA( IDirectFBGL );
if (data->locked)
return DFB_LOCKED;
if (directfbgl_lock())
return DFB_LOCKED;
surface = data->surface;
surface->GetSize( surface, &width, &height );
err = surface->Lock( surface, DSLF_READ | DSLF_WRITE,
(void*)&data->video.start, &data->video.pitch );
if (err != DFB_OK) {
D_ERROR( "DirectFBGL/Mesa: couldn't lock surface.\n" );
return err;
}
data->video.end = data->video.start + (height-1) * data->video.pitch;
data->render.Data = data->video.start;
_mesa_make_current( &data->context,
&data->framebuffer, &data->framebuffer );
if (data->width != width || data->height != height) {
data->width = width;
data->height = height;
_mesa_resize_framebuffer(&data->context,
&data->framebuffer, width, height);
}
data->locked = DFB_TRUE;
return DFB_OK;
}
static DFBResult
IDirectFBGL_Mesa_Unlock( IDirectFBGL *thiz )
{
DIRECT_INTERFACE_GET_DATA( IDirectFBGL );
if (!data->locked)
return DFB_OK;
_mesa_make_current( NULL, NULL, NULL );
data->surface->Unlock( data->surface );
directfbgl_unlock();
data->locked = DFB_FALSE;
return DFB_OK;
}
static DFBResult
IDirectFBGL_Mesa_GetAttributes( IDirectFBGL *thiz,
DFBGLAttributes *attributes )
{
DFBSurfaceCapabilities caps;
GLvisual *visual;
DIRECT_INTERFACE_GET_DATA( IDirectFBGL );
if (!attributes)
return DFB_INVARG;
data->surface->GetCapabilities( data->surface, &caps );
visual = &data->visual;
attributes->buffer_size = visual->rgbBits ? : visual->indexBits;
attributes->depth_size = visual->depthBits;
attributes->stencil_size = visual->stencilBits;
attributes->aux_buffers = visual->numAuxBuffers;
attributes->red_size = visual->redBits;
attributes->green_size = visual->greenBits;
attributes->blue_size = visual->blueBits;
attributes->alpha_size = visual->alphaBits;
attributes->accum_red_size = visual->accumRedBits;
attributes->accum_green_size = visual->accumGreenBits;
attributes->accum_blue_size = visual->accumBlueBits;
attributes->accum_alpha_size = visual->accumAlphaBits;
attributes->double_buffer = (caps & DSCAPS_FLIPPING) ? 1 : 0;
attributes->stereo = (visual->stereoMode != 0);
return DFB_OK;
}
/* exported symbols */
static DFBResult
Probe( void *data )
{
return DFB_OK;
}
static DFBResult
Construct( IDirectFBGL *thiz, IDirectFBSurface *surface )
{
/* Initialize global resources. */
if (directfbgl_init())
return DFB_INIT;
/* Allocate interface data. */
DIRECT_ALLOCATE_INTERFACE_DATA( thiz, IDirectFBGL );
/* Initialize interface data. */
data->ref = 1;
data->surface = surface;
surface->AddRef( surface );
surface->GetPixelFormat( surface, &data->format );
surface->GetSize( surface, &data->width, &data->height );
/* Configure visual. */
if (!directfbgl_init_visual( &data->visual, data->format )) {
D_ERROR( "DirectFBGL/Mesa: failed to initialize visual.\n" );
IDirectFBGL_Mesa_Destruct( thiz );
return DFB_UNSUPPORTED;
}
/* Create context. */
if (!directfbgl_create_context( &data->context, &data->framebuffer,
&data->visual, data->format, data )) {
D_ERROR( "DirectFBGL/Mesa: failed to create context.\n" );
IDirectFBGL_Mesa_Destruct( thiz );
return DFB_UNSUPPORTED;
}
/* Assign interface pointers. */
thiz->AddRef = IDirectFBGL_Mesa_AddRef;
thiz->Release = IDirectFBGL_Mesa_Release;
thiz->Lock = IDirectFBGL_Mesa_Lock;
thiz->Unlock = IDirectFBGL_Mesa_Unlock;
thiz->GetAttributes = IDirectFBGL_Mesa_GetAttributes;
return DFB_OK;
}
/***************************** Driver functions ******************************/
static const GLubyte*
dfbGetString( GLcontext *ctx, GLenum pname )
{
return NULL;
}
static void
dfbUpdateState( GLcontext *ctx, GLuint new_state )
{
_swrast_InvalidateState( ctx, new_state );
_swsetup_InvalidateState( ctx, new_state );
_ac_InvalidateState( ctx, new_state );
_tnl_InvalidateState( ctx, new_state );
}
static void
dfbGetBufferSize( GLframebuffer *buffer, GLuint *width, GLuint *height )
{
GLcontext *ctx = _mesa_get_current_context();
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
*width = (GLuint) data->width;
*height = (GLuint) data->height;
}
/**
* We only implement this function as a mechanism to check if the
* framebuffer size has changed (and update corresponding state).
*/
static void
dfbSetViewport( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h )
{
GLuint newWidth, newHeight;
GLframebuffer *buffer = ctx->WinSysDrawBuffer;
dfbGetBufferSize( buffer, &newWidth, &newHeight );
if (buffer->Width != newWidth || buffer->Height != newHeight) {
_mesa_resize_framebuffer(ctx, buffer, newWidth, newHeight );
}
}
static void
dfbClear( GLcontext *ctx, GLbitfield mask )
{
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
int x = ctx->DrawBuffer->_Xmin;
int y = ctx->DrawBuffer->_Ymin;
int width = ctx->DrawBuffer->_Xmax - x;
int height = ctx->DrawBuffer->_Ymax - y;
GLboolean all = (width == ctx->DrawBuffer->Width && height == ctx->DrawBuffer->height)
if (mask & BUFFER_BIT_FRONT_LEFT &&
ctx->Color.ColorMask[0] &&
ctx->Color.ColorMask[1] &&
ctx->Color.ColorMask[2] &&
ctx->Color.ColorMask[3])
{
DFBRegion clip;
__u8 a, r, g, b;
UNCLAMPED_FLOAT_TO_UBYTE( a, ctx->Color.ClearColor[ACOMP] );
UNCLAMPED_FLOAT_TO_UBYTE( r, ctx->Color.ClearColor[RCOMP] );
UNCLAMPED_FLOAT_TO_UBYTE( g, ctx->Color.ClearColor[GCOMP] );
UNCLAMPED_FLOAT_TO_UBYTE( b, ctx->Color.ClearColor[BCOMP] );
data->surface->Unlock( data->surface );
#if DIRECTFB_VERSION_CODE >= VERSION_CODE(0,9,25)
data->surface->GetClip( data->surface, &clip );
#else
(void)clip;
#endif
if (all) {
data->surface->SetClip( data->surface, NULL );
}
else {
DFBRegion reg = { x1:x, y1:y, x2:x+width-1, y2:y+height-1 };
data->surface->SetClip( data->surface, ® );
}
data->surface->Clear( data->surface, r, g, b, a );
#if DIRECTFB_VERSION_CODE >= VERSION_CODE(0,9,25)
data->surface->SetClip( data->surface, &clip );
#endif
data->surface->Lock( data->surface, DSLF_READ | DSLF_WRITE,
(void*)&data->video.start, &data->video.pitch );
mask &= ~BUFFER_BIT_FRONT_LEFT;
}
if (mask)
_swrast_Clear( ctx, mask );
}
/************************ RenderBuffer functions *****************************/
static void
dfbDeleteRenderbuffer( struct gl_renderbuffer *render )
{
return;
}
static GLboolean
dfbRenderbufferStorage( GLcontext *ctx, struct gl_renderbuffer *render,
GLenum internalFormat, GLuint width, GLuint height )
{
return GL_TRUE;
}
/***************************** Span functions ********************************/
/* RGB332 */
#define NAME(PREFIX) PREFIX##_RGB332
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLubyte *P = data->video.end - (Y) * data->video.pitch + (X);
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL(P, X, Y, S) \
*P = ( (((S[RCOMP]) & 0xe0) ) | \
(((S[GCOMP]) & 0xe0) >> 3) | \
(((S[BCOMP]) ) >> 6) )
#define FETCH_PIXEL(D, P) \
D[RCOMP] = ((*P & 0xe0) ); \
D[GCOMP] = ((*P & 0x1c) << 3); \
D[BCOMP] = ((*P & 0x03) << 6); \
D[ACOMP] = 0xff
#include "swrast/s_spantemp.h"
/* ARGB4444 */
#define NAME(PREFIX) PREFIX##_ARGB4444
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLushort *P = (GLushort *) (data->video.end - (Y) * data->video.pitch + (X) * 2);
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL_RGB(P, X, Y, S) \
*P = ( 0xf000 | \
(((S[RCOMP]) & 0xf0) << 4) | \
(((S[GCOMP]) & 0xf0) ) | \
(((S[BCOMP]) & 0xf0) >> 4) )
#define STORE_PIXEL(P, X, Y, S) \
*P = ( (((S[ACOMP]) & 0xf0) << 8) | \
(((S[RCOMP]) & 0xf0) << 4) | \
(((S[GCOMP]) & 0xf0) ) | \
(((S[BCOMP]) & 0xf0) >> 4) )
#define FETCH_PIXEL(D, P) \
D[RCOMP] = ((*P & 0x0f00) >> 4); \
D[GCOMP] = ((*P & 0x00f0) ); \
D[BCOMP] = ((*P & 0x000f) << 4); \
D[ACOMP] = ((*P & 0xf000) >> 8)
#include "swrast/s_spantemp.h"
/* ARGB2554 */
#define NAME(PREFIX) PREFIX##_ARGB2554
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLushort *P = (GLushort *) (data->video.end - (Y) * data->video.pitch + (X) * 2);
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL_RGB(P, X, Y, S) \
*P = ( 0xc000 | \
(((S[RCOMP]) & 0xf8) << 6) | \
(((S[GCOMP]) & 0xf8) << 1) | \
(((S[BCOMP]) & 0xf0) >> 4) )
#define STORE_PIXEL(P, X, Y, S) \
*P = ( (((S[ACOMP]) & 0xc0) << 8) | \
(((S[RCOMP]) & 0xf8) << 6) | \
(((S[GCOMP]) & 0xf8) << 1) | \
(((S[BCOMP]) & 0xf0) >> 4) )
#define FETCH_PIXEL(D, P) \
D[RCOMP] = ((*P & 0x3e00) >> 9); \
D[GCOMP] = ((*P & 0x01f0) >> 4); \
D[BCOMP] = ((*P & 0x000f) << 4); \
D[ACOMP] = ((*P & 0xc000) >> 14)
#include "swrast/s_spantemp.h"
/* ARGB1555 */
#define NAME(PREFIX) PREFIX##_ARGB1555
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLushort *P = (GLushort *) (data->video.end - (Y) * data->video.pitch + (X) * 2);
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL_RGB(P, X, Y, S) \
*P = ( 0x8000 | \
(((S[RCOMP]) & 0xf8) << 7) | \
(((S[GCOMP]) & 0xf8) << 2) | \
(((S[BCOMP]) ) >> 3) )
#define STORE_PIXEL(P, X, Y, S) \
*P = ( (((S[ACOMP]) & 0x80) << 16) | \
(((S[RCOMP]) & 0xf8) << 7) | \
(((S[GCOMP]) & 0xf8) << 2) | \
(((S[BCOMP]) ) >> 3) )
#define FETCH_PIXEL(D, P) \
D[RCOMP] = ((*P & 0x7c00) >> 7); \
D[GCOMP] = ((*P & 0x03e0) >> 2); \
D[BCOMP] = ((*P & 0x001f) << 3); \
D[ACOMP] = ((*P & 0x8000) ? 0xff : 0)
#include "swrast/s_spantemp.h"
/* RGB16 */
#define NAME(PREFIX) PREFIX##_RGB16
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLushort *P = (GLushort *) (data->video.end - (Y) * data->video.pitch + (X) * 2);
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL(P, X, Y, S) \
*P = ( (((S[RCOMP]) & 0xf8) << 8) | \
(((S[GCOMP]) & 0xfc) << 3) | \
(((S[BCOMP]) ) >> 3) )
#define FETCH_PIXEL(D, P) \
D[RCOMP] = ((*P & 0xf800) >> 8); \
D[GCOMP] = ((*P & 0x07e0) >> 3); \
D[BCOMP] = ((*P & 0x001f) << 3); \
D[ACOMP] = 0xff
#include "swrast/s_spantemp.h"
/* RGB24 */
#define NAME(PREFIX) PREFIX##_RGB24
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLubyte *P = data->video.end - (Y) * data->video.pitch + (X) * 3;
#define INC_PIXEL_PTR(P) P += 3
#define STORE_PIXEL(P, X, Y, S) \
P[0] = S[BCOMP]; P[1] = S[GCOMP]; P[2] = S[BCOMP]
#define FETCH_PIXEL(D, P) \
D[RCOMP] = P[2]; D[GCOMP] = P[1]; D[BCOMP] = P[0]; D[ACOMP] = 0xff
#include "swrast/s_spantemp.h"
/* RGB32 */
#define NAME(PREFIX) PREFIX##_RGB32
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLuint *P = (GLuint*) (data->video.end - (Y) * data->video.pitch + (X) * 4);
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL(P, X, Y, S) \
*P = ( ((S[RCOMP]) << 16) | \
((S[GCOMP]) << 8) | \
((S[BCOMP]) ) )
#define FETCH_PIXEL(D, P) \
D[RCOMP] = ((*P & 0x00ff0000) >> 16); \
D[GCOMP] = ((*P & 0x0000ff00) >> 8); \
D[BCOMP] = ((*P & 0x000000ff) ); \
D[ACOMP] = 0xff
#include "swrast/s_spantemp.h"
/* ARGB */
#define NAME(PREFIX) PREFIX##_ARGB
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLuint *P = (GLuint*) (data->video.end - (Y) * data->video.pitch + (X) * 4);
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL_RGB(P, X, Y, S) \
*P = ( 0xff000000 | \
((S[RCOMP]) << 16) | \
((S[GCOMP]) << 8) | \
((S[BCOMP]) ) )
#define STORE_PIXEL(P, X, Y, S) \
*P = ( ((S[ACOMP]) << 24) | \
((S[RCOMP]) << 16) | \
((S[GCOMP]) << 8) | \
((S[BCOMP]) ) )
#define FETCH_PIXEL(D, P) \
D[RCOMP] = ((*P & 0x00ff0000) >> 16); \
D[GCOMP] = ((*P & 0x0000ff00) >> 8); \
D[BCOMP] = ((*P & 0x000000ff) ); \
D[ACOMP] = ((*P & 0xff000000) >> 24)
#include "swrast/s_spantemp.h"
/* AiRGB */
#define NAME(PREFIX) PREFIX##_AiRGB
#define FORMAT GL_RGBA8
#define RB_TYPE GLubyte
#define SPAN_VARS \
IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLuint *P = (GLuint*) (data->video.end - (Y) * data->video.pitch + (X) * 4);
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL_RGB(P, X, Y, S) \
*P = ( ((S[RCOMP]) << 16) | \
((S[GCOMP]) << 8) | \
((S[BCOMP]) ) )
#define STORE_PIXEL(P, X, Y, S) \
*P = ( (((S[ACOMP]) ^ 0xff) << 24) | \
(((S[RCOMP]) ) << 16) | \
(((S[GCOMP]) ) << 8) | \
(((S[BCOMP]) ) ) )
#define FETCH_PIXEL(D, P) \
D[RCOMP] = ((*P & 0x00ff0000) >> 16); \
D[GCOMP] = ((*P & 0x0000ff00) >> 8); \
D[BCOMP] = ((*P & 0x000000ff) ); \
D[ACOMP] = (((*P & 0xff000000) >> 24) ^ 0xff)
#include "swrast/s_spantemp.h"
/*****************************************************************************/
static bool
directfbgl_init_visual( GLvisual *visual,
DFBSurfacePixelFormat format )
{
GLboolean rgbFlag = GL_TRUE;
GLboolean dbFlag = GL_FALSE;
GLboolean stereoFlag = GL_FALSE;
GLint redBits = 0;
GLint blueBits = 0;
GLint greenBits = 0;
GLint alphaBits = 0;
GLint indexBits = 0;
GLint depthBits = 0;
GLint stencilBits = 0;
GLint accumRedBits = 0;
GLint accumGreenBits = 0;
GLint accumBlueBits = 0;
GLint accumAlphaBits = 0;
GLint numSamples = 0;
/* FIXME: LUT8 support. */
switch (format) {
case DSPF_RGB332:
redBits = 3;
greenBits = 3;
blueBits = 2;
break;
case DSPF_ARGB4444:
redBits = 4;
greenBits = 4;
blueBits = 4;
alphaBits = 4;
break;
case DSPF_ARGB2554:
redBits = 5;
greenBits = 5;
blueBits = 4;
alphaBits = 2;
break;
case DSPF_ARGB1555:
redBits = 5;
greenBits = 5;
blueBits = 5;
alphaBits = 1;
break;
case DSPF_RGB16:
redBits = 5;
greenBits = 6;
blueBits = 5;
break;
case DSPF_ARGB:
case DSPF_AiRGB:
alphaBits = 8;
case DSPF_RGB24:
case DSPF_RGB32:
redBits = 8;
greenBits = 8;
blueBits = 8;
break;
default:
D_WARN( "unsupported pixelformat" );
return false;
}
if (rgbFlag) {
accumRedBits = redBits;
accumGreenBits = greenBits;
accumBlueBits = blueBits;
accumAlphaBits = alphaBits;
depthBits = redBits + greenBits + blueBits;
stencilBits = alphaBits;
} else
depthBits = 8;
return _mesa_initialize_visual( visual,
rgbFlag, dbFlag, stereoFlag,
redBits, greenBits, blueBits, alphaBits,
indexBits, depthBits, stencilBits,
accumRedBits, accumGreenBits,
accumBlueBits, accumAlphaBits,
numSamples );
}
static bool
directfbgl_create_context( GLcontext *context,
GLframebuffer *framebuffer,
GLvisual *visual,
DFBSurfacePixelFormat format,
IDirectFBGL_data *data )
{
struct dd_function_table functions;
_mesa_initialize_framebuffer( framebuffer, visual );
_mesa_init_driver_functions( &functions );
functions.GetString = dfbGetString;
functions.UpdateState = dfbUpdateState;
functions.GetBufferSize = dfbGetBufferSize;
functions.Viewport = dfbSetViewport;
functions.Clear = dfbClear;
if (!_mesa_initialize_context( context, visual, NULL,
&functions, (void*) data )) {
D_DEBUG( "DirectFBGL/Mesa: _mesa_initialize_context() failed.\n" );
_mesa_free_framebuffer_data( framebuffer );
return false;
}
_swrast_CreateContext( context );
_ac_CreateContext( context );
_tnl_CreateContext( context );
_swsetup_CreateContext( context );
_swsetup_Wakeup( context );
_mesa_init_renderbuffer( &data->render, 0 );
data->render.InternalFormat = GL_RGBA;
data->render._BaseFormat = GL_RGBA;
data->render.DataType = GL_UNSIGNED_BYTE;
data->render.Data = data->video.start;
data->render.Delete = dfbDeleteRenderbuffer;
data->render.AllocStorage = dfbRenderbufferStorage;
switch (format) {
case DSPF_RGB332:
data->render.GetRow = get_row_RGB332;
data->render.GetValues = get_values_RGB332;
data->render.PutRow = put_row_RGB332;
data->render.PutMonoRow = put_mono_row_RGB332;
data->render.PutValues = put_values_RGB332;
data->render.PutMonoValues = put_mono_values_RGB332;
break;
case DSPF_ARGB4444:
data->render.GetRow = get_row_ARGB4444;
data->render.GetValues = get_values_ARGB4444;
data->render.PutRow = put_row_ARGB4444;
data->render.PutMonoRow = put_mono_row_ARGB4444;
data->render.PutValues = put_values_ARGB4444;
data->render.PutMonoValues = put_mono_values_ARGB4444;
break;
case DSPF_ARGB2554:
data->render.GetRow = get_row_ARGB2554;
data->render.GetValues = get_values_ARGB2554;
data->render.PutRow = put_row_ARGB2554;
data->render.PutMonoRow = put_mono_row_ARGB2554;
data->render.PutValues = put_values_ARGB2554;
data->render.PutMonoValues = put_mono_values_ARGB2554;
break;
case DSPF_ARGB1555:
data->render.GetRow = get_row_ARGB1555;
data->render.GetValues = get_values_ARGB1555;
data->render.PutRow = put_row_ARGB1555;
data->render.PutMonoRow = put_mono_row_ARGB1555;
data->render.PutValues = put_values_ARGB1555;
data->render.PutMonoValues = put_mono_values_ARGB1555;
break;
case DSPF_RGB16:
data->render.GetRow = get_row_RGB16;
data->render.GetValues = get_values_RGB16;
data->render.PutRow = put_row_RGB16;
data->render.PutMonoRow = put_mono_row_RGB16;
data->render.PutValues = put_values_RGB16;
data->render.PutMonoValues = put_mono_values_RGB16;
break;
case DSPF_RGB24:
data->render.GetRow = get_row_RGB24;
data->render.GetValues = get_values_RGB24;
data->render.PutRow = put_row_RGB24;
data->render.PutMonoRow = put_mono_row_RGB24;
data->render.PutValues = put_values_RGB24;
data->render.PutMonoValues = put_mono_values_RGB24;
break;
case DSPF_RGB32:
data->render.GetRow = get_row_RGB32;
data->render.GetValues = get_values_RGB32;
data->render.PutRow = put_row_RGB32;
data->render.PutMonoRow = put_mono_row_RGB32;
data->render.PutValues = put_values_RGB32;
data->render.PutMonoValues = put_mono_values_RGB32;
break;
case DSPF_ARGB:
data->render.GetRow = get_row_ARGB;
data->render.GetValues = get_values_ARGB;
data->render.PutRow = put_row_ARGB;
data->render.PutMonoRow = put_mono_row_ARGB;
data->render.PutValues = put_values_ARGB;
data->render.PutMonoValues = put_mono_values_ARGB;
break;
case DSPF_AiRGB:
data->render.GetRow = get_row_AiRGB;
data->render.GetValues = get_values_AiRGB;
data->render.PutRow = put_row_AiRGB;
data->render.PutMonoRow = put_mono_row_AiRGB;
data->render.PutValues = put_values_AiRGB;
data->render.PutMonoValues = put_mono_values_AiRGB;
break;
default:
D_BUG( "unexpected pixelformat" );
return false;
}
_mesa_add_renderbuffer( framebuffer, BUFFER_FRONT_LEFT, &data->render );
_mesa_add_soft_renderbuffers( framebuffer,
GL_FALSE,
visual->haveDepthBuffer,
visual->haveStencilBuffer,
visual->haveAccumBuffer,
GL_FALSE,
GL_FALSE );
TNL_CONTEXT( context )->Driver.RunPipeline = _tnl_run_pipeline;
_mesa_enable_sw_extensions( context );
return true;
}
static void
directfbgl_destroy_context( GLcontext *context,
GLframebuffer *framebuffer )
{
_mesa_free_framebuffer_data( framebuffer );
_mesa_notifyDestroy( context );
_mesa_free_context_data( context );
}
|