Skip to content

Commit 49446b5

Browse files
author
synap
committed
2006-02-13 Dennis Smit <[email protected]>
* standalone/*: Adding a shitload more of display drivers.
1 parent 8665ae2 commit 49446b5

File tree

17 files changed

+1564
-13
lines changed

17 files changed

+1564
-13
lines changed

libvisual-hackground/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2006-02-13 Dennis Smit <[email protected]>
2+
3+
* standalone/*: Adding a shitload more of display drivers.
4+
15
2006-01-31 Dennis Smit <[email protected]>
26

37
* standalone/morphclient.c: Kinda works now, this once again reminds
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
#include <caca.h>
2+
3+
#include <stdio.h>
4+
#include <unistd.h>
5+
#include <stdlib.h>
6+
7+
#include "cacadriver.h"
8+
9+
#define CACA_NATIVE(obj) (VISUAL_CHECK_CAST ((obj), CacaNative))
10+
11+
12+
typedef struct _CacaNative CacaNative;
13+
14+
static int native_create (SADisplay *display, VisVideoDepth depth, VisVideoAttributeOptions *vidoptions,
15+
int width, int height, int resizable);
16+
static int native_close (SADisplay *display);
17+
static int native_lock (SADisplay *display);
18+
static int native_unlock (SADisplay *display);
19+
static int native_fullscreen (SADisplay *display, int fullscreen, int autoscale);
20+
static int native_getvideo (SADisplay *display, VisVideo *screen);
21+
static int native_updaterect (SADisplay *display, VisRectangle *rect);
22+
static int native_drainevents (SADisplay *display, VisEventQueue *eventqueue);
23+
24+
25+
static int caca_initialized;
26+
27+
struct _CacaNative {
28+
VisObject object;
29+
30+
struct caca_bitmap *bitmap;
31+
unsigned char *area;
32+
33+
VisVideoDepth depth;
34+
int width;
35+
int height;
36+
37+
unsigned int red[256];
38+
unsigned int green[256];
39+
unsigned int blue[256];
40+
unsigned int alpha[256];
41+
};
42+
43+
SADisplayDriver *caca_driver_new ()
44+
{
45+
SADisplayDriver *driver;
46+
47+
driver = visual_mem_new0 (SADisplayDriver, 1);
48+
49+
visual_object_initialize (VISUAL_OBJECT (driver), TRUE, NULL);
50+
51+
driver->create = native_create;
52+
driver->close = native_close;
53+
driver->lock = native_lock;
54+
driver->unlock = native_unlock;
55+
driver->fullscreen = native_fullscreen;
56+
driver->getvideo = native_getvideo;
57+
driver->updaterect = native_updaterect;
58+
driver->drainevents = native_drainevents;
59+
60+
return driver;
61+
}
62+
63+
static int native_create (SADisplay *display, VisVideoDepth depth, VisVideoAttributeOptions *vidoptions,
64+
int width, int height, int resizable)
65+
{
66+
CacaNative *native = CACA_NATIVE (display->native);
67+
unsigned int rmask;
68+
unsigned int gmask;
69+
unsigned int bmask;
70+
unsigned int amask;
71+
72+
if (native == NULL) {
73+
native = visual_mem_new0 (CacaNative, 1);
74+
75+
visual_object_initialize (VISUAL_OBJECT (native), TRUE, NULL);
76+
}
77+
78+
if (caca_initialized == FALSE) {
79+
if (caca_init () < 0)
80+
return -1;
81+
82+
caca_set_window_title ("Libcaca libvisual display");
83+
}
84+
85+
if (native->bitmap != NULL)
86+
caca_free_bitmap (native->bitmap);
87+
88+
89+
if (native->area != NULL)
90+
visual_mem_free (native->area);
91+
92+
switch (depth) {
93+
case VISUAL_VIDEO_DEPTH_32BIT:
94+
rmask = 0xff000000;
95+
gmask = 0x00ff0000;
96+
bmask = 0x0000ff00;
97+
amask = 0x000000ff;
98+
99+
break;
100+
101+
case VISUAL_VIDEO_DEPTH_24BIT:
102+
rmask = 0xff0000;
103+
gmask = 0x00ff00;
104+
bmask = 0x0000ff;
105+
amask = 0x000000;
106+
107+
break;
108+
109+
case VISUAL_VIDEO_DEPTH_16BIT:
110+
rmask = 0x7c00;
111+
gmask = 0x03e0;
112+
bmask = 0x001f;
113+
amask = 0x0000;
114+
115+
break;
116+
117+
case VISUAL_VIDEO_DEPTH_8BIT:
118+
rmask = gmask = bmask = amask = 0;
119+
120+
break;
121+
122+
default:
123+
rmask = gmask = bmask = amask = 0;
124+
125+
break;
126+
}
127+
128+
native->bitmap = caca_create_bitmap (visual_video_depth_value_from_enum (depth),
129+
width,
130+
height,
131+
width * (visual_video_depth_value_from_enum (depth) / 8),
132+
rmask, gmask, bmask, amask);
133+
134+
native->area = visual_mem_malloc0 (width * height * (visual_video_depth_value_from_enum (depth) / 8));
135+
136+
native->width = width;
137+
native->height = height;
138+
native->depth = depth;
139+
140+
display->native = VISUAL_OBJECT (native);
141+
142+
caca_initialized = TRUE;
143+
144+
return 0;
145+
}
146+
147+
static int native_close (SADisplay *display)
148+
{
149+
caca_end ();
150+
151+
return 0;
152+
}
153+
154+
static int native_lock (SADisplay *display)
155+
{
156+
return 0;
157+
}
158+
159+
static int native_unlock (SADisplay *display)
160+
{
161+
return 0;
162+
}
163+
164+
static int native_fullscreen (SADisplay *display, int fullscreen, int autoscale)
165+
{
166+
return 0;
167+
}
168+
169+
static int native_getvideo (SADisplay *display, VisVideo *screen)
170+
{
171+
CacaNative *native = CACA_NATIVE (display->native);
172+
173+
visual_video_set_depth (screen, native->depth);
174+
175+
visual_video_set_dimension (screen, native->width, native->height);
176+
visual_video_set_buffer (screen, native->area);
177+
178+
return 0;
179+
}
180+
181+
static int native_updaterect (SADisplay *display, VisRectangle *rect)
182+
{
183+
CacaNative *native = CACA_NATIVE (display->native);
184+
VisPalette *pal;
185+
int i;
186+
187+
pal = display->screen->pal;
188+
189+
if (display->screen->depth == VISUAL_VIDEO_DEPTH_8BIT) {
190+
for (i = 0; i < 256; i++) {
191+
native->red[i] = pal->colors[i].r * 16;
192+
native->green[i] = pal->colors[i].g * 16;
193+
native->blue[i] = pal->colors[i].b * 16;
194+
}
195+
196+
caca_set_bitmap_palette (native->bitmap,
197+
native->red,
198+
native->green,
199+
native->blue,
200+
native->alpha);
201+
}
202+
203+
caca_draw_bitmap (0, 0, caca_get_width() - 1, caca_get_height() - 1,
204+
native->bitmap, native->area);
205+
206+
caca_refresh ();
207+
208+
return 0;
209+
}
210+
211+
static int native_drainevents (SADisplay *display, VisEventQueue *eventqueue)
212+
{
213+
CacaNative *native = CACA_NATIVE (display->native);
214+
unsigned int event;
215+
216+
while ((event = caca_get_event (CACA_EVENT_ANY)) > 0) {
217+
218+
if (event & CACA_EVENT_KEY_PRESS) {
219+
220+
visual_event_queue_add_keyboard (eventqueue, event & 0xff, 0,
221+
VISUAL_KEY_DOWN);
222+
223+
} else if (event & CACA_EVENT_KEY_RELEASE) {
224+
225+
visual_event_queue_add_keyboard (eventqueue, event & 0xff, 0,
226+
VISUAL_KEY_UP);
227+
228+
} else if (event & CACA_EVENT_MOUSE_MOTION) {
229+
230+
visual_event_queue_add_mousemotion (eventqueue, caca_get_mouse_x (), caca_get_mouse_y ());
231+
232+
} else if (event & CACA_EVENT_MOUSE_PRESS) {
233+
234+
visual_event_queue_add_mousebutton (eventqueue, event & 0xff, VISUAL_MOUSE_DOWN,
235+
caca_get_mouse_x (), caca_get_mouse_y ());
236+
237+
} else if (event & CACA_EVENT_MOUSE_RELEASE) {
238+
239+
visual_event_queue_add_mousebutton (eventqueue, event & 0xff, VISUAL_MOUSE_UP,
240+
caca_get_mouse_x (), caca_get_mouse_y ());
241+
} else if (event & CACA_EVENT_RESIZE) {
242+
243+
244+
native_create (display, display->screen->depth,
245+
NULL,
246+
caca_get_window_width (),
247+
caca_get_window_height (),
248+
TRUE);
249+
250+
visual_event_queue_add_resize (eventqueue, display->screen,
251+
caca_get_window_width (),
252+
caca_get_window_height ());
253+
254+
}
255+
}
256+
257+
return 0;
258+
}
259+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _LV_STANDALONE_CACADRIVER_H
2+
#define _LV_STANDALONE_CACADRIVER_H
3+
4+
#include "display.h"
5+
6+
/* prototypes */
7+
SADisplayDriver *caca_driver_new (void);
8+
9+
#endif /* _LV_STANDALONE_CACADRIVER_H */

libvisual-hackground/standalone/client.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "display.h"
66
#include "sdldriver.h"
7+
#include "x11driver.h"
8+
#include "glxdriver.h"
79

810
int main (int argc, char **argv)
911
{
@@ -23,7 +25,7 @@ int main (int argc, char **argv)
2325

2426
visual_init (&argc, &argv);
2527

26-
display = display_new (sdl_driver_new ());
28+
display = display_new (caca_driver_new ());
2729

2830
/* Libvisual stuff */
2931
if (argc > 1)
@@ -82,6 +84,9 @@ int main (int argc, char **argv)
8284
break;
8385

8486
case VISUAL_EVENT_MOUSEBUTTONDOWN:
87+
88+
break;
89+
8590
case VISUAL_EVENT_MOUSEBUTTONUP:
8691
break;
8792

@@ -105,6 +110,7 @@ int main (int argc, char **argv)
105110
break;
106111

107112
default:
113+
printf ("key: %c\n", ev->event.keyboard.keysym.sym);
108114
break;
109115
}
110116

@@ -148,6 +154,7 @@ int main (int argc, char **argv)
148154

149155
/* Termination procedure */
150156
display_set_fullscreen (display, FALSE, TRUE);
157+
display_close (display);
151158

152159
printf ("Total frames: %d, average fps: %f\n", display_fps_total (display), display_fps_average (display));
153160

libvisual-hackground/standalone/display.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ int display_create (SADisplay *display, VisVideoDepth depth, VisVideoAttributeOp
2020
return display->driver->create (display, depth, vidoptions, width, height, resizable);
2121
}
2222

23+
int display_close (SADisplay *display)
24+
{
25+
return display->driver->close (display);
26+
}
27+
2328
VisVideo *display_get_video (SADisplay *display)
2429
{
2530
display->driver->getvideo (display, display->screen);

libvisual-hackground/standalone/display.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef struct _SADisplay SADisplay;
99

1010
typedef int (*SADisplayDriverCreateFunc)(SADisplay *display, VisVideoDepth depth, VisVideoAttributeOptions *vidoptions,
1111
int width, int height, int resizable);
12+
typedef int (*SADisplayDriverCloseFunc)(SADisplay *display);
1213
typedef int (*SADisplayDriverLockFunc)(SADisplay *display);
1314
typedef int (*SADisplayDriverUnlockFunc)(SADisplay *display);
1415
typedef int (*SADisplayDriverFullScreenFunc)(SADisplay *display, int fullscreen, int autoscale);
@@ -20,6 +21,7 @@ struct _SADisplayDriver {
2021
VisObject object;
2122

2223
SADisplayDriverCreateFunc create;
24+
SADisplayDriverCloseFunc close;
2325
SADisplayDriverLockFunc lock;
2426
SADisplayDriverUnlockFunc unlock;
2527
SADisplayDriverFullScreenFunc fullscreen;
@@ -46,6 +48,8 @@ SADisplay *display_new (SADisplayDriver *driver);
4648
int display_create (SADisplay *display, VisVideoDepth depth, VisVideoAttributeOptions *vidoptions,
4749
int width, int height, int resizable);
4850

51+
int display_close (SADisplay *display);
52+
4953
VisVideo *display_get_video (SADisplay *display);
5054

5155
int display_lock (SADisplay *display);

0 commit comments

Comments
 (0)