frontend: merge updates from SDL project
[pcsx_rearmed.git] / frontend / plat_omap.c
CommitLineData
69af03a2 1/*
2 * (C) notaz, 2010
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>
799b0b87 13#include <sys/ioctl.h>
69af03a2 14#include <unistd.h>
69af03a2 15#include <linux/omapfb.h>
16
69af03a2 17#include "common/menu.h"
18#include "linux/fbdev.h"
0b49a8f7 19#include "linux/xenv.h"
69af03a2 20#include "plugin_lib.h"
4c08b9e7 21#include "pl_gun_ts.h"
69af03a2 22#include "omap.h"
55b0eeea 23#include "plat.h"
69af03a2 24
25
26static struct vout_fbdev *main_fb;
27int g_layer_x = 80, g_layer_y = 0;
28int g_layer_w = 640, g_layer_h = 480;
29
30struct vout_fbdev *layer_fb;
31
366631aa 32static int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h)
69af03a2 33{
2c886904 34 struct omapfb_plane_info pi = { 0, };
35 struct omapfb_mem_info mi = { 0, };
69af03a2 36 int ret;
37
38 ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
39 if (ret != 0) {
40 perror("QUERY_PLANE");
41 return -1;
42 }
43
44 ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
45 if (ret != 0) {
46 perror("QUERY_MEM");
47 return -1;
48 }
49
50 /* must disable when changing stuff */
51 if (pi.enabled) {
52 pi.enabled = 0;
53 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
54 if (ret != 0)
55 perror("SETUP_PLANE");
56 }
57
366631aa 58 if (mi.size < 640*512*3*3) {
2cb46552 59 mi.size = 640*512*3*3;
96d9fde1 60 ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
61 if (ret != 0) {
62 perror("SETUP_MEM");
63 return -1;
64 }
69af03a2 65 }
66
67 pi.pos_x = x;
68 pi.pos_y = y;
69 pi.out_width = w;
70 pi.out_height = h;
71 pi.enabled = enabled;
72
73 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
74 if (ret != 0) {
75 perror("SETUP_PLANE");
76 return -1;
77 }
78
79 return 0;
80}
81
82int omap_enable_layer(int enabled)
83{
4c08b9e7 84 if (enabled)
85 pl_set_gun_rect(g_layer_x, g_layer_y, g_layer_w, g_layer_h);
86
69af03a2 87 return omap_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled,
366631aa 88 g_layer_x, g_layer_y, g_layer_w, g_layer_h);
69af03a2 89}
90
fba06457 91void plat_video_menu_enter(int is_rom_loaded)
92{
93 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
94 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 3);
95 if (g_menuscreen_ptr == NULL)
96 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
0b49a8f7 97
3a321131 98 xenv_update(NULL, NULL, NULL, NULL);
fba06457 99}
100
69af03a2 101void plat_video_menu_begin(void)
102{
103}
104
105void plat_video_menu_end(void)
106{
107 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
108}
109
fba06457 110void plat_video_menu_leave(void)
111{
112 /* have to get rid of panning so that plugins that
113 * use fb0 and don't ever pan can work. */
114 vout_fbdev_clear(main_fb);
115 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
116 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 1);
117 if (g_menuscreen_ptr == NULL)
118 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
119}
120
a805c855 121void plat_minimize(void)
122{
123 omap_enable_layer(0);
124 xenv_minimize();
125 omap_enable_layer(1);
126}
127
221be40d 128void plat_step_volume(int is_up)
129{
130}
131
3a40ff14 132void plat_trigger_vibrate(int is_strong)
b944a30e 133{
134}
135
69af03a2 136void plat_init(void)
137{
138 const char *main_fb_name, *layer_fb_name;
139 void *temp_frame;
140 int fd, ret, w, h;
141
142 main_fb_name = getenv("FBDEV_MAIN");
143 if (main_fb_name == NULL)
144 main_fb_name = "/dev/fb0";
145
146 layer_fb_name = getenv("FBDEV_LAYER");
147 if (layer_fb_name == NULL)
148 layer_fb_name = "/dev/fb1";
149
150 // must set the layer up first to be able to use it
151 fd = open(layer_fb_name, O_RDWR);
152 if (fd == -1) {
153 fprintf(stderr, "%s: ", layer_fb_name);
154 perror("open");
155 exit(1);
156 }
157
366631aa 158 ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h);
69af03a2 159 close(fd);
160 if (ret != 0) {
161 fprintf(stderr, "failed to set up layer, exiting.\n");
162 exit(1);
163 }
164
3a321131 165 xenv_init(NULL, "PCSX-ReARMed");
69af03a2 166
167 w = h = 0;
168 main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2);
169 if (main_fb == NULL) {
170 fprintf(stderr, "couldn't init fb: %s\n", main_fb_name);
171 exit(1);
172 }
173
174 g_menuscreen_w = w;
175 g_menuscreen_h = h;
176 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
bb88ec28 177 pl_rearmed_cbs.screen_w = w;
178 pl_rearmed_cbs.screen_h = h;
69af03a2 179
180 w = 640;
0b49a8f7 181 h = 512;
69af03a2 182 layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3);
183 if (layer_fb == NULL) {
184 fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name);
185 goto fail0;
186 }
187
188 temp_frame = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
189 if (temp_frame == NULL) {
190 fprintf(stderr, "OOM\n");
191 goto fail1;
192 }
193 g_menubg_ptr = temp_frame;
69af03a2 194
9b4bd105 195 plat_pandora_init(); // XXX
196
69af03a2 197 return;
198
199fail1:
200 vout_fbdev_finish(layer_fb);
201fail0:
202 vout_fbdev_finish(main_fb);
203 exit(1);
204
205}
206
bd6267e6 207void plat_finish(void)
208{
209 omap_enable_layer(0);
210 vout_fbdev_finish(layer_fb);
211 vout_fbdev_finish(main_fb);
0b49a8f7 212 xenv_finish();
bd6267e6 213}
214