2 * (C) GraÅžvydas "notaz" Ignotas, 2010-2012
4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
10 #include <sys/types.h>
13 #include <sys/ioctl.h>
15 #include <linux/omapfb.h>
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"
24 #include "plat_omap.h"
27 static struct vout_fbdev *main_fb, *layer_fb;
29 static int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h)
31 struct omapfb_plane_info pi = { 0, };
32 struct omapfb_mem_info mi = { 0, };
35 ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
37 perror("QUERY_PLANE");
41 ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
47 /* must disable when changing stuff */
50 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
52 perror("SETUP_PLANE");
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);
71 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
73 perror("SETUP_PLANE");
80 static int omap_enable_layer(int enabled)
83 pl_set_gun_rect(g_layer_x, g_layer_y, g_layer_w, g_layer_h);
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);
89 void plat_omap_gvideo_open(void)
93 // try to align redraws to vsync
94 vout_fbdev_wait_vsync(layer_fb);
97 void *plat_gvideo_set_mode(int *w_in, int *h_in, int *bpp)
99 int l = 0, r = 0, t = 0, b = 0;
100 int w = *w_in, h = *h_in;
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;
108 if (h > g_menuscreen_h) {
109 t = b = (h - g_menuscreen_h) / 2;
114 buf = vout_fbdev_resize(layer_fb, w, h, *bpp,
117 vout_fbdev_clear(layer_fb);
119 omap_enable_layer(1);
124 void *plat_gvideo_flip(void)
126 return vout_fbdev_flip(layer_fb);
129 void plat_gvideo_close(void)
131 omap_enable_layer(0);
134 void plat_video_menu_enter(int is_rom_loaded)
136 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
137 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 3);
138 if (g_menuscreen_ptr == NULL)
139 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
141 xenv_update(NULL, NULL, NULL, NULL);
144 void plat_video_menu_begin(void)
148 void plat_video_menu_end(void)
150 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
153 void plat_video_menu_leave(void)
155 /* have to get rid of panning so that plugins that
156 * use fb0 and don't ever pan can work. */
157 vout_fbdev_clear(main_fb);
158 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
159 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 1);
160 if (g_menuscreen_ptr == NULL)
161 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
164 void plat_minimize(void)
168 ret = vout_fbdev_save(layer_fb);
170 printf("minimize: layer/fb handling failed\n");
176 in_set_config_int(0, IN_CFG_BLOCKING, 0); /* flush event queue */
177 omap_enable_layer(0); /* restore layer mem */
178 vout_fbdev_restore(layer_fb);
181 void *plat_prepare_screenshot(int *w, int *h, int *bpp)
186 void plat_omap_init(void)
188 const char *main_fb_name, *layer_fb_name;
191 main_fb_name = getenv("FBDEV_MAIN");
192 if (main_fb_name == NULL)
193 main_fb_name = "/dev/fb0";
195 layer_fb_name = getenv("FBDEV_LAYER");
196 if (layer_fb_name == NULL)
197 layer_fb_name = "/dev/fb1";
199 // must set the layer up first to be able to use it
200 fd = open(layer_fb_name, O_RDWR);
202 fprintf(stderr, "%s: ", layer_fb_name);
207 g_layer_x = 80, g_layer_y = 0;
208 g_layer_w = 640, g_layer_h = 480;
210 ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h);
213 fprintf(stderr, "failed to set up layer, exiting.\n");
217 xenv_init(NULL, "PCSX-ReARMed");
220 main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2);
221 if (main_fb == NULL) {
222 fprintf(stderr, "couldn't init fb: %s\n", main_fb_name);
228 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
229 pl_rearmed_cbs.screen_w = w;
230 pl_rearmed_cbs.screen_h = h;
234 layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3);
235 if (layer_fb == NULL) {
236 fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name);
243 vout_fbdev_finish(main_fb);
247 void plat_omap_finish(void)
249 omap_enable_layer(0);
250 vout_fbdev_finish(layer_fb);
251 vout_fbdev_finish(main_fb);