53ed197b9eff51305be5edcda07e12c688763bb1
[pcsx_rearmed.git] / plugins / gpu_neon / 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 static void blit(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 GPUupdateLace(void)
81 {
82   if (!gpu.status.blanking && gpu.state.fb_dirty) {
83     renderer_flush_queues();
84     blit();
85     gpu.state.fb_dirty = 0;
86   }
87 }
88
89 long GPUopen(void **dpy)
90 {
91   *dpy = x11_display;
92   return 0;
93 }
94
95 long GPUclose(void)
96 {
97   return 0;
98 }
99
100 #include "../../frontend/plugin_lib.h"
101
102 void GPUrearmedCallbacks(const struct rearmed_cbs *cbs)
103 {
104   gpu.state.hcnt = cbs->gpu_hcnt;
105   gpu.state.frame_count = cbs->gpu_frame_count;
106
107   if (cbs->pl_vout_set_raw_vram)
108     cbs->pl_vout_set_raw_vram(gpu.vram);
109   renderer_set_config(cbs);
110 }
111
112 // vim:shiftwidth=2:expandtab