2
// C++ Implementation: GUI_sdlDraw
6
// YUY2 does not work on win32, U&V seems to be zeroed
8
// The pitch stride has to be changed as there could be some padding depending on the OS
11
// Author: mean <fixounet@free.fr>, (C) 2004
13
// Copyright: See COPYING file that comes with this distribution
24
#include "ADM_library/default.h"
27
#include <X11/Xutil.h>
33
#include "ADM_toolkit/toolkit_gtk.h"
35
#define GtkWidget void
40
#include <ADM_assert.h>
41
#include "ADM_colorspace/ADM_rgb.h"
42
#include "ADM_gui2/GUI_render.h"
44
#include "ADM_gui2/GUI_accelRender.h"
45
#include "ADM_gui2/GUI_sdlDraw.h"
50
#include "SDL/SDL_syswm.h"
54
static uint8_t sdl_running=0;
55
static SDL_Overlay *sdl_overlay=NULL;
56
static SDL_Surface *sdl_display=NULL;
59
static ColBase *color=NULL;
61
sdlAccelRender::sdlAccelRender( void)
66
uint8_t sdlAccelRender::end( void)
70
SDL_FreeYUVOverlay(sdl_overlay);
74
SDL_UnlockSurface(sdl_display);
75
SDL_FreeSurface(sdl_display);
79
SDL_QuitSubSystem(SDL_INIT_VIDEO);
89
printf("SDL killed\n");
93
uint8_t sdlAccelRender::init( GtkWidget * window, uint32_t w, uint32_t h)
98
// Ask for the position of the drawing window at start
99
//_______________________________________________________
108
color=new ColBase(720,480);
109
decoded=new uint8_t[w*h*2];
111
/* Hack to get SDL to use GTK window, ugly but works */
112
#if !defined(CONFIG_DARWIN) && !defined(CYG_MANGLING)
113
{ char SDL_windowhack[32];
114
sprintf(SDL_windowhack,"SDL_WINDOWID=%ld",
115
GDK_WINDOW_XWINDOW(window->window));
116
putenv(SDL_windowhack);
119
if ( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 )
121
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
125
flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_NOFRAME;
126
bpp= SDL_VideoModeOK( w, h, 16, flags );
127
sdl_display= SDL_SetVideoMode( w, h, bpp, flags );
131
printf("Cannot create get surface\n");
135
SDL_LockSurface(sdl_display);
138
if(useYV12) cspace=SDL_YV12_OVERLAY;
139
else cspace=SDL_YUY2_OVERLAY;
140
//_______________________________________________________
141
sdl_overlay=SDL_CreateYUVOverlay((w),(h),
147
printf("Cannot create SDL overlay\n");
151
int pitch=sdl_overlay->pitches[0];
152
printf("SDL_init ok, type is : %d,planes :%d pitch:%d\n",sdl_overlay->hw_overlay,sdl_overlay->planes,pitch);
153
if(!sdl_overlay->hw_overlay)
155
printf("** HW Acceleration disabled **\n");
157
printf("** Darwin**\n");
160
if(!useYV12) color->reset(w,h);
163
static void interleave(uint8_t *dst,uint8_t *src,int width, int stride, int lines)
165
for(int y=0;y<lines;y++)
167
memcpy(dst,src,width);
172
uint8_t sdlAccelRender::display(uint8_t *ptr, uint32_t w, uint32_t h)
176
ADM_assert(sdl_overlay);
177
SDL_LockYUVOverlay(sdl_overlay);
178
pitch=sdl_overlay->pitches[0];
179
// printf("SDL: new pitch :%d\n",pitch);
183
memcpy(sdl_overlay->pixels[0],ptr,w*h);
185
interleave(sdl_overlay->pixels[0],ptr,w,pitch,h);
187
pitch=sdl_overlay->pitches[1];
189
memcpy(sdl_overlay->pixels[1],ptr+page,(w*h)>>2);
191
interleave(sdl_overlay->pixels[1],ptr+page,w>>1,pitch,h>>1);
193
pitch=sdl_overlay->pitches[2];
195
memcpy(sdl_overlay->pixels[2],ptr+(page*5)/4,(w*h)>>2);
197
interleave(sdl_overlay->pixels[2],ptr+(page*5)/4,w>>1,pitch,h>>1);
203
color->scale(ptr,sdl_overlay->pixels[0]);
207
color->scale(ptr,decoded);
208
interleave(sdl_overlay->pixels[0],decoded,2*w,pitch,h);
217
SDL_UnlockYUVOverlay(sdl_overlay);
218
SDL_DisplayYUVOverlay(sdl_overlay,&disp);