cdrom: change pause timing again
[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 "libpicofe/menu.h"
18#include "libpicofe/input.h"
19#include "libpicofe/linux/fbdev.h"
20#include "libpicofe/linux/xenv.h"
21#include "plugin_lib.h"
22#include "pl_gun_ts.h"
23#include "plat.h"
24#include "plat_omap.h"
25#include "menu.h"
26
27static struct vout_fbdev *main_fb, *layer_fb;
28
29static int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h)
30{
31 struct omapfb_plane_info pi = { 0, };
32 struct omapfb_mem_info mi = { 0, };
33 int ret;
34
35 ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
36 if (ret != 0) {
37 perror("QUERY_PLANE");
38 return -1;
39 }
40
41 ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
42 if (ret != 0) {
43 perror("QUERY_MEM");
44 return -1;
45 }
46
47 /* must disable when changing stuff */
48 if (pi.enabled) {
49 pi.enabled = 0;
50 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
51 if (ret != 0)
52 perror("SETUP_PLANE");
53 }
54
55 // upto 1024x512 (2x resolution enhancement)
56 if (mi.size < 1024*512*2 * 3) {
57 mi.size = 1024*512*2 * 3;
58 ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
59 if (ret != 0) {
60 perror("SETUP_MEM");
61 return -1;
62 }
63 }
64
65 pi.pos_x = x;
66 pi.pos_y = y;
67 pi.out_width = w;
68 pi.out_height = h;
69 pi.enabled = enabled;
70
71 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
72 if (ret != 0) {
73 perror("SETUP_PLANE");
74 return -1;
75 }
76
77 return 0;
78}
79
80static int omap_enable_layer(int enabled)
81{
82 if (enabled)
83 pl_set_gun_rect(g_layer_x, g_layer_y, g_layer_w, g_layer_h);
84
85 return omap_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled,
86 g_layer_x, g_layer_y, g_layer_w, g_layer_h);
87}
88
89void plat_omap_gvideo_open(void)
90{
91 omap_enable_layer(1);
92
93 // try to align redraws to vsync
94 vout_fbdev_wait_vsync(layer_fb);
95}
96
97void *plat_gvideo_set_mode(int *w_in, int *h_in, int *bpp)
98{
99 int l = 0, r = 0, t = 0, b = 0;
100 int w = *w_in, h = *h_in;
101 void *buf;
102
103 if (g_scaler == SCALE_1_1 || g_scaler == SCALE_2_2) {
104 if (w > g_menuscreen_w) {
105 l = r = (w - g_menuscreen_w) / 2;
106 w -= l + r;
107 }
108 if (h > g_menuscreen_h) {
109 t = b = (h - g_menuscreen_h) / 2;
110 h -= t + b;
111 }
112 }
113
114 buf = vout_fbdev_resize(layer_fb, w, h, *bpp,
115 l, r, t, b, 3, 1);
116
117 vout_fbdev_clear(layer_fb);
118
119 omap_enable_layer(1);
120
121 return buf;
122}
123
124void *plat_gvideo_flip(void)
125{
126 return vout_fbdev_flip(layer_fb);
127}
128
129void plat_gvideo_close(void)
130{
131 omap_enable_layer(0);
132}
133
134void plat_video_menu_enter(int is_rom_loaded)
135{
136 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
137 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 3, 0);
138 if (g_menuscreen_ptr == NULL)
139 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
140 vout_fbdev_clear(main_fb);
141
142 xenv_update(NULL, NULL, NULL, NULL);
143}
144
145void plat_video_menu_begin(void)
146{
147}
148
149void plat_video_menu_end(void)
150{
151 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
152}
153
154void plat_video_menu_leave(void)
155{
156 /* have to get rid of panning so that plugins that
157 * use fb0 and don't ever pan can work. */
158 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
159 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 1, 0);
160 if (g_menuscreen_ptr == NULL)
161 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
162 vout_fbdev_clear(main_fb);
163}
164
165void plat_minimize(void)
166{
167 int ret;
168
169 ret = vout_fbdev_save(layer_fb);
170 if (ret != 0) {
171 printf("minimize: layer/fb handling failed\n");
172 return;
173 }
174
175 xenv_minimize();
176
177 in_set_config_int(0, IN_CFG_BLOCKING, 0); /* flush event queue */
178 omap_enable_layer(0); /* restore layer mem */
179 vout_fbdev_restore(layer_fb);
180}
181
182void *plat_prepare_screenshot(int *w, int *h, int *bpp)
183{
184 return NULL;
185}
186
187void plat_omap_init(void)
188{
189 const char *main_fb_name, *layer_fb_name;
190 int fd, ret, w, h;
191
192 main_fb_name = getenv("FBDEV_MAIN");
193 if (main_fb_name == NULL)
194 main_fb_name = "/dev/fb0";
195
196 layer_fb_name = getenv("FBDEV_LAYER");
197 if (layer_fb_name == NULL)
198 layer_fb_name = "/dev/fb1";
199
200 // must set the layer up first to be able to use it
201 fd = open(layer_fb_name, O_RDWR);
202 if (fd == -1) {
203 fprintf(stderr, "%s: ", layer_fb_name);
204 perror("open");
205 exit(1);
206 }
207
208 g_layer_x = 80, g_layer_y = 0;
209 g_layer_w = 640, g_layer_h = 480;
210
211 ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h);
212 close(fd);
213 if (ret != 0) {
214 fprintf(stderr, "failed to set up layer, exiting.\n");
215 exit(1);
216 }
217
218 xenv_init(NULL, "PCSX-ReARMed");
219
220 w = h = 0;
221 main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2);
222 if (main_fb == NULL) {
223 fprintf(stderr, "couldn't init fb: %s\n", main_fb_name);
224 exit(1);
225 }
226
227 g_menuscreen_w = g_menuscreen_pp = w;
228 g_menuscreen_h = h;
229 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
230 pl_rearmed_cbs.screen_w = w;
231 pl_rearmed_cbs.screen_h = h;
232
233 w = 640;
234 h = 512;
235 layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3);
236 if (layer_fb == NULL) {
237 fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name);
238 goto fail0;
239 }
240
241 return;
242
243fail0:
244 vout_fbdev_finish(main_fb);
245 exit(1);
246}
247
248void plat_omap_finish(void)
249{
250 omap_enable_layer(0);
251 vout_fbdev_finish(layer_fb);
252 vout_fbdev_finish(main_fb);
253 xenv_finish();
254}
255