Merge branch 'enhancement'
[pcsx_rearmed.git] / plugins / gpulib / vout_sdl.c
1 /*
2  * (C) GraÅžvydas "notaz" Ignotas, 2011
3  *
4  * This work is licensed under the terms of any of these licenses
5  * (at your option):
6  *  - GNU GPL, version 2 or later.
7  *  - GNU LGPL, version 2.1 or later.
8  * See the COPYING file in the top-level directory.
9  */
10
11 #include <stdio.h>
12 #include <SDL.h>
13 #include <SDL_syswm.h>
14 #include "gpu.h"
15
16 static SDL_Surface *screen;
17 static Display *x11_display;
18
19 int vout_init(void)
20 {
21   SDL_SysWMinfo wminfo;
22   int ret;
23
24   ret = SDL_Init(SDL_INIT_VIDEO);
25   if (ret != 0) {
26     fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
27     return ret;
28   }
29
30   screen = SDL_SetVideoMode(1024, 512, 32, 0);
31   if (screen == NULL) {
32     fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
33     SDL_Quit();
34     return -1;
35   }
36
37   SDL_VERSION(&wminfo.version);
38   ret = SDL_GetWMInfo(&wminfo);
39   if (ret == 1)
40     x11_display = wminfo.info.x11.display;
41
42   return 0;
43 }
44
45 int vout_finish(void)
46 {
47   SDL_Quit();
48   return 0;
49 }
50
51 void vout_update(void)
52 {
53   uint32_t *d;
54   int i;
55
56   SDL_LockSurface(screen);
57   if (gpu.status.rgb24)
58   {
59     uint8_t *s;
60     int y;
61     for (y = 0; y < 512; y++) {
62       s = (uint8_t *)gpu.vram + y * 2*1024;
63       d = (uint32_t *)screen->pixels + y * 1024;
64       for (i = 0; i < 1024 * 2 / 3; i++, s += 3)
65         d[i] = (s[0] << 16) | (s[1] << 8) | s[2];
66     }
67   }
68   else
69   {
70     uint16_t *s = gpu.vram;
71     d = (uint32_t *)screen->pixels;
72     for (i = 0; i < 1024 * 512; i++)
73       d[i] = (((uint32_t)s[i] << 19) & 0xf80000) | ((s[i] << 6) & 0xf800) |
74         ((s[i] >> 7) & 0xf8);
75   }
76   SDL_UnlockSurface(screen);
77   SDL_UpdateRect(screen, 0, 0, 1024, 512);
78 }
79
80 void vout_blank(void)
81 {
82 }
83
84 long GPUopen(void **dpy)
85 {
86   *dpy = x11_display;
87   return 0;
88 }
89
90 long GPUclose(void)
91 {
92   return 0;
93 }
94
95 void vout_set_config(const struct rearmed_cbs *cbs)
96 {
97 }
98
99 // vim:shiftwidth=2:expandtab