frontend: generic: preliminary SDL support
[pcsx_rearmed.git] / frontend / plat_omap.c
... / ...
CommitLineData
1/*
2 * (C) GraÅžvydas "notaz" Ignotas, 2010-2012
3 *
4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <fcntl.h>
13#include <sys/ioctl.h>
14#include <unistd.h>
15#include <linux/omapfb.h>
16
17#include "common/menu.h"
18#include "linux/fbdev.h"
19#include "linux/xenv.h"
20#include "plugin_lib.h"
21#include "pl_gun_ts.h"
22#include "plat.h"
23#include "menu.h"
24
25static struct vout_fbdev *main_fb, *layer_fb;
26
27static int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h)
28{
29 struct omapfb_plane_info pi = { 0, };
30 struct omapfb_mem_info mi = { 0, };
31 int ret;
32
33 ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
34 if (ret != 0) {
35 perror("QUERY_PLANE");
36 return -1;
37 }
38
39 ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
40 if (ret != 0) {
41 perror("QUERY_MEM");
42 return -1;
43 }
44
45 /* must disable when changing stuff */
46 if (pi.enabled) {
47 pi.enabled = 0;
48 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
49 if (ret != 0)
50 perror("SETUP_PLANE");
51 }
52
53 if (mi.size < 640*512*3*3) {
54 mi.size = 640*512*3*3;
55 ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
56 if (ret != 0) {
57 perror("SETUP_MEM");
58 return -1;
59 }
60 }
61
62 pi.pos_x = x;
63 pi.pos_y = y;
64 pi.out_width = w;
65 pi.out_height = h;
66 pi.enabled = enabled;
67
68 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
69 if (ret != 0) {
70 perror("SETUP_PLANE");
71 return -1;
72 }
73
74 return 0;
75}
76
77static int omap_enable_layer(int enabled)
78{
79 if (enabled)
80 pl_set_gun_rect(g_layer_x, g_layer_y, g_layer_w, g_layer_h);
81
82 return omap_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled,
83 g_layer_x, g_layer_y, g_layer_w, g_layer_h);
84}
85
86void plat_gvideo_open(void)
87{
88 omap_enable_layer(1);
89
90 // try to align redraws to vsync
91 vout_fbdev_wait_vsync(layer_fb);
92}
93
94void *plat_gvideo_set_mode(int *w, int *h, int *bpp)
95{
96 void *buf;
97
98 vout_fbdev_clear(layer_fb);
99 buf = vout_fbdev_resize(layer_fb, *w, *h, *bpp, 0, 0, 0, 0, 3);
100
101 omap_enable_layer(1);
102
103 return buf;
104}
105
106void *plat_gvideo_flip(void)
107{
108 return vout_fbdev_flip(layer_fb);
109}
110
111void plat_gvideo_close(void)
112{
113 omap_enable_layer(0);
114}
115
116void plat_video_menu_enter(int is_rom_loaded)
117{
118 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
119 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 3);
120 if (g_menuscreen_ptr == NULL)
121 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
122
123 xenv_update(NULL, NULL, NULL, NULL);
124}
125
126void plat_video_menu_begin(void)
127{
128}
129
130void plat_video_menu_end(void)
131{
132 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
133}
134
135void plat_video_menu_leave(void)
136{
137 /* have to get rid of panning so that plugins that
138 * use fb0 and don't ever pan can work. */
139 vout_fbdev_clear(main_fb);
140 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
141 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 1);
142 if (g_menuscreen_ptr == NULL)
143 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
144}
145
146void plat_minimize(void)
147{
148 omap_enable_layer(0);
149 xenv_minimize();
150 omap_enable_layer(1);
151}
152
153void plat_step_volume(int is_up)
154{
155}
156
157void plat_trigger_vibrate(int is_strong)
158{
159}
160
161void *plat_prepare_screenshot(int *w, int *h, int *bpp)
162{
163 return NULL;
164}
165
166void plat_init(void)
167{
168 const char *main_fb_name, *layer_fb_name;
169 int fd, ret, w, h;
170
171 main_fb_name = getenv("FBDEV_MAIN");
172 if (main_fb_name == NULL)
173 main_fb_name = "/dev/fb0";
174
175 layer_fb_name = getenv("FBDEV_LAYER");
176 if (layer_fb_name == NULL)
177 layer_fb_name = "/dev/fb1";
178
179 // must set the layer up first to be able to use it
180 fd = open(layer_fb_name, O_RDWR);
181 if (fd == -1) {
182 fprintf(stderr, "%s: ", layer_fb_name);
183 perror("open");
184 exit(1);
185 }
186
187 g_layer_x = 80, g_layer_y = 0;
188 g_layer_w = 640, g_layer_h = 480;
189
190 ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h);
191 close(fd);
192 if (ret != 0) {
193 fprintf(stderr, "failed to set up layer, exiting.\n");
194 exit(1);
195 }
196
197 xenv_init(NULL, "PCSX-ReARMed");
198
199 w = h = 0;
200 main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2);
201 if (main_fb == NULL) {
202 fprintf(stderr, "couldn't init fb: %s\n", main_fb_name);
203 exit(1);
204 }
205
206 g_menuscreen_w = w;
207 g_menuscreen_h = h;
208 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
209 pl_rearmed_cbs.screen_w = w;
210 pl_rearmed_cbs.screen_h = h;
211
212 w = 640;
213 h = 512;
214 layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3);
215 if (layer_fb == NULL) {
216 fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name);
217 goto fail0;
218 }
219
220 plat_pandora_init(); // XXX
221
222 return;
223
224fail1:
225 vout_fbdev_finish(layer_fb);
226fail0:
227 vout_fbdev_finish(main_fb);
228 exit(1);
229
230}
231
232void plat_finish(void)
233{
234 omap_enable_layer(0);
235 vout_fbdev_finish(layer_fb);
236 vout_fbdev_finish(main_fb);
237 xenv_finish();
238}
239