aboutsummaryrefslogtreecommitdiff
path: root/modules/pdp_sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/pdp_sdl.c')
-rw-r--r--modules/pdp_sdl.c245
1 files changed, 164 insertions, 81 deletions
diff --git a/modules/pdp_sdl.c b/modules/pdp_sdl.c
index 7bd8992..d30ef84 100644
--- a/modules/pdp_sdl.c
+++ b/modules/pdp_sdl.c
@@ -1,6 +1,6 @@
/*
* Pure Data Packet module.
- * Copyright (c) by martin pi <pi@attacksyour.net>
+ * Copyright (c) 2003 by martin pi <pi@attacksyour.net>
* Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -33,16 +33,15 @@ TODO:
*/
-
#include <stdio.h>
-#include <unistd.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
+//#include <unistd.h>
+//#include <sys/ipc.h>
+//#include <sys/shm.h>
#include <SDL/SDL.h>
-#include <quicktime/lqt.h>
-#include <quicktime/colormodels.h>
+//#include <quicktime/lqt.h>
+//#include <quicktime/colormodels.h>
#include "pdp.h"
#include "pdp_llconv.h"
@@ -52,8 +51,6 @@ TODO:
#define PDP_SDL_W 320
#define PDP_SDL_H 240
-#define PDP_AUTOCREATE_RETRY 3
-
typedef struct pdp_sdl_struct {
t_object x_obj;
@@ -65,6 +62,8 @@ typedef struct pdp_sdl_struct {
SDL_Surface *x_sdl_surface;
SDL_Overlay *x_sdl_overlay;
SDL_Rect x_sdl_rect;
+
+ int x_xid;
Uint32 x_sdl_format;
@@ -74,59 +73,69 @@ typedef struct pdp_sdl_struct {
unsigned int x_width;
unsigned int x_height;
int x_last_encoding;
+ int x_cursor;
int x_initialized;
int x_backfromthread;
- int x_autocreate;
-
int x_fullscreen;
} t_pdp_sdl;
-static SDL_Surface *pdp_sdl_getSurface(char* title, int width, int height, int bits, int fullscreenflag) {
+static SDL_Surface *pdp_sdl_getSurface(int xid, char* title, int width, int height, int bits, int fullscreenflag, int cursorflag) {
Uint32 flags;
int size,i;
SDL_Surface *screen;
+ char SDL_hack[32];
+
+ /* next lines from gstreamer plugin sdlvideosink */
+ if (xid < 0) unsetenv("SDL_WINDOWID");
+ else {
+ sprintf(SDL_hack, "%d", xid);
+ setenv("SDL_WINDOWID", SDL_hack, 1);
+ }
/* Initialize SDL */
if (!SDL_WasInit(SDL_INIT_VIDEO)) {
if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)) {
- printf("SDL: Initializing of SDL failed: %s.\n", SDL_GetError());
- return (SDL_Surface *)-1;
+ post("SDL: Initializing of SDL failed: %s.\n", SDL_GetError());
+ return NULL;
}
- }
-
+ /* ignore events :: only keys and wm_quit */
+ for ( i=SDL_NOEVENT; i<SDL_NUMEVENTS; ++i )
+ if( !(i & (SDL_KEYDOWN|SDL_VIDEORESIZE)) )
+ SDL_EventState(i, SDL_IGNORE);
+
+ }
/*
gem : SDL_OPENGL|SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT|SDL_OPENGLBLIT;
working: SDL_ANYFORMAT|SDL_RESIZABLE|SDL_RLEACCEL;
*/
-
- flags = SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL;
+ flags = SDL_SWSURFACE | SDL_RESIZABLE;
+// flags = SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT|SDL_RLEACCEL;
if ( fullscreenflag>0 ) {
flags |= SDL_FULLSCREEN|SDL_DOUBLEBUF;
}
- /* Have a preference for 8-bit, but accept any depth */
screen = SDL_SetVideoMode(width, height, bits, flags);
if ( screen == NULL ) {
- fprintf(stderr, "Couldn't set video mode: %s\n",
- SDL_GetError());
+ post("Couldn't set video mode: %s\n", SDL_GetError());
return NULL;
}
SDL_WM_SetCaption (title, title);
- /* ignore events :: only keys and wm_quit */
- for ( i=SDL_NOEVENT; i<SDL_NUMEVENTS; ++i )
- if( !(i & (SDL_KEYDOWN|SDL_QUIT)) )
- SDL_EventState(i, SDL_IGNORE);
+ SDL_ShowCursor(cursorflag);
- SDL_ShowCursor(1);
+ return screen;
+}
- return screen; // Success
+static SDL_Surface *pdp_sdl_recreateSurface(SDL_Surface *old, int xid, char* title, int width, int height, int bits, int fullscreenflag, int cursorflag) {
+ SDL_Surface *new = pdp_sdl_getSurface(xid, title, width, height, bits, fullscreenflag, cursorflag);
+ if (new != NULL) SDL_FreeSurface(old);
+ return new;
}
static inline void pdp_sdl_getOverlay(t_pdp_sdl* x) {
@@ -169,30 +178,26 @@ static int pdp_sdl_drawImage(t_pdp_sdl* x, t_image *image, short int *pixels) {
return 1;
}
-static void pdp_sdl_resize(t_pdp_sdl* x, t_floatarg width, t_floatarg height) {
+static void pdp_sdl_fullscreen(t_pdp_sdl *x, t_floatarg f);
- if (x->x_initialized && (!x->x_fullscreen) && (width>0) && (height>0)){
-// disabled for now
-// if media size is different to the one set, it will resize (yet never dither)
- }
+static inline void pdp_sdl_recreate(t_pdp_sdl *x) {
+ x->x_sdl_surface = pdp_sdl_recreateSurface(x->x_sdl_surface, x->x_xid,"pdp-sdl", x->x_winwidth, x->x_winheight, 16, x->x_fullscreen,x->x_cursor);
}
-static void pdp_sdl_fullscreen(t_pdp_sdl *x, t_floatarg f);
-
static int pdp_sdl_create(t_pdp_sdl *x) {
if (x->x_initialized){
return 0;
}
x->x_initialized = 0;
- x->x_sdl_surface = pdp_sdl_getSurface("pdp-sdl", x->x_winwidth, x->x_winheight, 16, x->x_fullscreen);
+ x->x_sdl_surface = pdp_sdl_getSurface(x->x_xid, "pdp-sdl", x->x_winwidth, x->x_winheight, 16, x->x_fullscreen,x->x_cursor);
if (x->x_sdl_surface != NULL) {
pdp_sdl_getOverlay(x);
if (x->x_sdl_overlay != NULL) {
x->x_sdl_rect.x = 0;
x->x_sdl_rect.y = 0;
- x->x_sdl_rect.w = x->x_width;
- x->x_sdl_rect.h = x->x_height;
+ x->x_sdl_rect.w = x->x_winwidth;
+ x->x_sdl_rect.h = x->x_winheight;
x->x_initialized = 1;
post("created successfully");
}
@@ -203,12 +208,13 @@ static int pdp_sdl_create(t_pdp_sdl *x) {
}
static void pdp_sdl_destroy(t_pdp_sdl *x);
+static void pdp_sdl_resize(t_pdp_sdl *x,t_floatarg,t_floatarg);
static void pdp_sdl_checkEvents(t_pdp_sdl *x) {
Uint8 *keys;
SDL_Event event;
- if (!SDL_PollEvent(&event)) return;
+ if (SDL_PollEvent(&event)!=1) return;
switch( event.type ){
case SDL_KEYDOWN:
@@ -224,6 +230,9 @@ static void pdp_sdl_checkEvents(t_pdp_sdl *x) {
case SDL_QUIT:
pdp_sdl_destroy(x);
break;
+ case SDL_VIDEORESIZE:
+ pdp_sdl_resize(x,(t_floatarg)event.resize.w,(t_floatarg)event.resize.h);
+ break;
default:
break;
}
@@ -231,26 +240,6 @@ static void pdp_sdl_checkEvents(t_pdp_sdl *x) {
}
-static int pdp_sdl_try_autocreate(t_pdp_sdl *x)
-{
-
- if (x->x_autocreate){
- post("pdp_sdl: autocreate window");
- pdp_sdl_create(x);
- if (!(x->x_initialized)){
- x->x_autocreate--;
- if (!x->x_autocreate){
- post ("pdp_sdl: autocreate failed %d times: disabled", PDP_AUTOCREATE_RETRY);
- post ("pdp_sdl: send [autocreate 1] message to re-enable");
- return 0;
- }
- }
- else return 1;
-
- }
- return 0;
-}
-
static void pdp_sdl_bang(t_pdp_sdl *x);
static void pdp_sdl_process(t_pdp_sdl *x)
@@ -263,8 +252,7 @@ static void pdp_sdl_process(t_pdp_sdl *x)
/* check if window is initialized */
if (!(x->x_initialized)){
- post("trying to autocreate");
- if (!pdp_sdl_try_autocreate(x)) return;
+ if (!pdp_sdl_create(x)) return;
}
/* check for pending sdl events */
@@ -296,6 +284,7 @@ static void pdp_sdl_destroy(t_pdp_sdl *x) {
pdp_sdl_freeOverlay(x);
SDL_FreeSurface(x->x_sdl_surface);
x->x_initialized = 0;
+ SDL_Quit();
}
}
@@ -309,10 +298,8 @@ static void pdp_sdl_random(t_pdp_sdl *x) {
/* redisplays image */
static void pdp_sdl_bang_thread(t_pdp_sdl *x) {
-// if (x->x_sdl_overlay->pixels) {
- if (SDL_DisplayYUVOverlay(x->x_sdl_overlay, &(* x).x_sdl_rect) <0)
- post("pdp_sdl: __LINE__ cannot display");
-// }
+ if (SDL_DisplayYUVOverlay(x->x_sdl_overlay, &(* x).x_sdl_rect) <0)
+ post("pdp_sdl: __LINE__ cannot display");
}
static void pdp_sdl_bang_callback(t_pdp_sdl *x)
@@ -340,34 +327,122 @@ static void pdp_sdl_input_0(t_pdp_sdl *x, t_symbol *s, t_floatarg f) {
}
-static void pdp_sdl_autocreate(t_pdp_sdl *x, t_floatarg f) {
- if (f != 0.0f) x->x_autocreate = PDP_AUTOCREATE_RETRY;
- else x->x_autocreate = 0;
+static void pdp_sdl_resize(t_pdp_sdl* x, t_floatarg width, t_floatarg height) {
+
+ if (x->x_initialized && (!x->x_fullscreen) && (width>0) && (height>0)) {
+ post("should get %d/%d",(int)width,(int) height);
+ x->x_winwidth=(int)width;
+ x->x_winheight=(int)height;
+ pdp_sdl_recreate(x);
+ }
}
+
static void pdp_sdl_fullscreen(t_pdp_sdl *x, t_floatarg f) {
if (f == x->x_fullscreen) return;
- x->x_fullscreen = (f != 0.0f);
+ x->x_fullscreen = (f != 0.0f);
+ x->x_cursor=0;
+
+ pdp_sdl_recreate(x);
+}
+
+static void pdp_sdl_cursor(t_pdp_sdl *x, t_floatarg f) {
+ if (f == x->x_cursor) return;
+
+ x->x_cursor = (f != 0.0f);
+ SDL_ShowCursor(x->x_cursor);
+}
+
+
+/* sets new target window */
+
+static void pdp_sdl_win(t_pdp_sdl *x, t_floatarg *f) {
+ pdp_queue_finish(x->x_queue_id);
+ x->x_queue_id = -1;
+ x->x_xid = (int)f;
+ pdp_sdl_recreate(x);
+}
+
+/* be very carefule not to set DGA fro here! */
+/* use export SDL_VIDEODRIVER=dga (or equivalent for your shell) instead */
+
+static void pdp_sdl_renderer(t_pdp_sdl *x, t_symbol *s) {
+ char SDL_hack[32];
pdp_sdl_destroy(x);
+
+ /* next lines from gstreamer plugin sdlvideosink */
+ unsetenv("SDL_VIDEODRIVER");
+
+ sprintf(SDL_hack, "%s", s->s_name);
+ setenv("SDL_VIDEODRIVER", SDL_hack, 1);
+
pdp_sdl_create(x);
- SDL_ShowCursor(0);
}
static void pdp_sdl_free(t_pdp_sdl *x)
{
- pdp_queue_finish(x->x_queue_id);
- pdp_sdl_destroy(x);
- pdp_packet_mark_unused(x->x_packet0);
- SDL_Quit();
+ pdp_queue_finish(x->x_queue_id);
+ pdp_sdl_destroy(x);
+ pdp_packet_mark_unused(x->x_packet0);
+// SDL_Quit();
+}
+
+static void pdp_sdl_listmodes(const char* title, Uint32 flags) {
+ SDL_Rect ** modes;
+ int i;
+
+ /* Get available modes */
+ modes = SDL_ListModes(NULL, flags);
+
+ /* Check is there are any modes available */
+ if(modes == (SDL_Rect **)0){
+ printf("%s : No modes available!", title);
+ return;
+ }
+
+ /* Check if our resolution is restricted */
+ if(modes == (SDL_Rect **)-1){
+ post("%s : All resolutions available.", title);
+ } else {
+ /* Print valid modes */
+ for(i=0;modes[i];++i)
+ post("%s : %d x %d", title, modes[i]->w, modes[i]->h);
+ }
+
+}
+
+static void pdp_sdl_modes(t_pdp_sdl *x) {
+ pdp_sdl_listmodes("FULL|HWSURF|||||||||||||||||||||||||", SDL_FULLSCREEN|SDL_HWSURFACE);
+ pdp_sdl_listmodes("HWSURF|RESIZ|ASYNC|HWACCEL||||||||||", SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
+ pdp_sdl_listmodes("HWSURF|RESIZ|ASYNC|HWACCEL|FULL|DBUF", SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_FULLSCREEN|SDL_DOUBLEBUF);
+ pdp_sdl_listmodes("OPENGL|DBUF|HWSURF|ANYF|GLBLIT||||||", SDL_OPENGL|SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT|SDL_OPENGLBLIT);
+ pdp_sdl_listmodes("ANYF|RESIZ|RLEA|||||||||||||||||||||", SDL_ANYFORMAT|SDL_RESIZABLE|SDL_RLEACCEL);
}
+static void pdp_sdl_info(t_pdp_sdl *x) {
+ const SDL_VideoInfo *narf;
+ post("\nSDL video info: note that this only works under dga mode\n");
+ narf = SDL_GetVideoInfo();
+ post("Is it possible to create hardware surfaces?\t\thw_available=%d",narf->hw_available);
+ post("Is there a window manager available?\t\t\twm_available=%d",narf->wm_available);
+ post("Are hardware to hardware blits accelerated?\t\tblit_hw=%d",narf->blit_hw);
+ post("Are hardware to hardware colorkey blits accelerated?\tblit_hw_CC=%d",narf->blit_hw_CC);
+ post("Are hardware to hardware alpha bits accelerated?\tblit_hw_A=%d",narf->blit_hw_A);
+ post("Are software to hardware blits accelerated?\t\tblit_sw=%d",narf->blit_sw);
+ post("Are software to hardware colorkey blits accelerated?\tblit_sw_CC=%d",narf->blit_sw_CC);
+ post("Are software to hardware alpha blits accelerated?\tblit_sw_A=%d",narf->blit_sw_A);
+ post("Are color fills accelerated?\t\t\t\tblit_fill=%d",narf->blit_fill);
+ post("Total amount of video_mem: %d",narf->video_mem);
+
+}
t_class *pdp_sdl_class;
-void *pdp_sdl_new(void)
-{
+void *pdp_sdl_new(void) {
+
+
t_pdp_sdl *x = (t_pdp_sdl *)pd_new(pdp_sdl_class);
x->x_packet0 = -1;
@@ -385,9 +460,13 @@ void *pdp_sdl_new(void)
x->x_backfromthread = 1;
x->x_initialized = 0;
- pdp_sdl_autocreate(x,1);
- x->x_fullscreen = 0;
+ x->x_fullscreen = 0;
+ x->x_cursor=1;
+
+ x->x_xid = -1;
+
+ pdp_sdl_create(x);
return (void *)x;
}
@@ -411,13 +490,16 @@ void pdp_sdl_setup(void)
class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_bang, gensym("bang"), A_NULL);
class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_random, gensym("random"), A_NULL);
class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_create, gensym("create"), A_NULL);
- class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_autocreate, gensym("autocreate"), A_FLOAT, A_NULL);
+ class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_info, gensym("info"), A_NULL);
+ class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_modes, gensym("modes"), A_NULL);
class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_destroy, gensym("destroy"), A_NULL);
class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_destroy, gensym("close"), A_NULL);
-// class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_resize, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL);
-// class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_resize, gensym("size"), A_FLOAT, A_FLOAT, A_NULL);
+ class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_resize, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL);
+ class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_resize, gensym("size"), A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_fullscreen, gensym("fullscreen"), A_FLOAT, A_NULL);
-// class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_display, gensym("display"), A_SYMBOL, A_NULL);
+ class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_cursor, gensym("cursor"), A_FLOAT, A_NULL);
+ class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_win, gensym("window"), A_FLOAT, A_NULL);
+ class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_renderer, gensym("renderer"), A_SYMBOL, A_NULL);
class_addmethod(pdp_sdl_class, (t_method)pdp_sdl_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL);
}
@@ -425,3 +507,4 @@ void pdp_sdl_setup(void)
#ifdef __cplusplus
}
#endif
+