Cosmetics
[rawv.git] / sdlu.c
blobb64624c849103d3ca6356e33cc820308c29d24f5
1 /* SDL utils
2 * Copyright (C) 2011 Kirill Smelkov <kirr@navytux.spb.ru>
3 * Copyright (C) 2011 Marine Bridge and Navigation Systems (http://mns.spb.ru/)
5 * This library is free software: you can Use, Study, Modify and Redistribute
6 * it under the terms of the GNU Lesser General Public License version 2.1, or
7 * any later version. This library is distributed WITHOUT ANY WARRANTY. See
8 * COPYING.LIB file for full License terms.
9 */
11 #include "sdlu.h"
13 /* From SDL_yuvfuncs.h - last updated from SDL-1.2.14. KEEP IN SYNC.
14 * TODO check SDL version at compile time.
16 * ---- 8< -----
18 typedef struct SDL_VideoDevice SDL_VideoDevice;
20 #ifndef _THIS
21 #define _THIS SDL_VideoDevice *_this
22 #endif
23 struct private_yuvhwfuncs {
24 int (*Lock)(_THIS, SDL_Overlay *overlay);
25 void (*Unlock)(_THIS, SDL_Overlay *overlay);
26 int (*Display)(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
27 void (*FreeHW)(_THIS, SDL_Overlay *overlay);
30 /* ---- 8< ----- */
34 * Determine SDL's current_video at runtime via temporarily faking overlay ->Lock hwfunc
36 static int SDLU_YUVDetectCurrentVideo_ViaLock(SDL_VideoDevice *_this, SDL_Overlay *overlay)
38 SDL_VideoDevice **pSDL_current_video = (SDL_VideoDevice **)overlay->hwdata;
39 *pSDL_current_video = _this; /* _this is set to current_video by SDL */
40 return 0; /* "locked" ok */
43 static SDL_VideoDevice *SDLU_YUVCurrentVideo(SDL_Overlay *overlay)
45 SDL_VideoDevice *SDL_current_video;
47 int (*yuvlock) (SDL_VideoDevice *, SDL_Overlay *);
48 struct private_yuvhwdata *hwdata;
50 yuvlock = overlay->hwfuncs->Lock;
51 hwdata = overlay->hwdata;
53 overlay->hwdata = (struct private_yuvhwdata *)&SDL_current_video;
54 overlay->hwfuncs->Lock = SDLU_YUVDetectCurrentVideo_ViaLock;
56 SDL_current_video = NULL;
57 SDL_LockYUVOverlay(overlay);
59 if (!SDL_current_video) {
60 fprintf(stderr, "Can't determine SDL_current_video\n"); /* should not happen */
61 abort();
64 overlay->hwfuncs->Lock = yuvlock;
65 overlay->hwdata = hwdata;
67 return SDL_current_video;
71 int SDLU_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *srcrect, SDL_Rect *dstrect)
73 SDL_VideoDevice *video = SDLU_YUVCurrentVideo(overlay);
75 /* Just do hwfuncs dispatch like in SDL_DisplayYUVOverlay, without clipping prologue */
76 return overlay->hwfuncs->Display(video, overlay, srcrect, dstrect);