psx_gpu: some argument checks
[pcsx_rearmed.git] / plugins / gpu_neon / vout_sdl.c
CommitLineData
56f08d83 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
16static SDL_Surface *screen;
17static Display *x11_display;
18
19int 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
45int vout_finish(void)
46{
47 SDL_Quit();
48 return 0;
49}
50
51static 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;
6f2ee2be 71 d = (uint32_t *)screen->pixels;
56f08d83 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
80void GPUupdateLace(void)
81{
9394ada5 82 if (!gpu.status.blanking && gpu.state.fb_dirty) {
83 renderer_flush_queues();
56f08d83 84 blit();
9394ada5 85 gpu.state.fb_dirty = 0;
86 }
56f08d83 87}
88
89long GPUopen(void **dpy)
90{
91 *dpy = x11_display;
92 return 0;
93}
94
95long GPUclose(void)
96{
97 return 0;
98}
99
914455e6 100#include "../../frontend/plugin_lib.h"
101
102void GPUrearmedCallbacks(const struct rearmed_cbs *cbs)
56f08d83 103{
914455e6 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);
56f08d83 110}
111
112// vim:shiftwidth=2:expandtab