select builtin gpu plugin on configure
[pcsx_rearmed.git] / frontend / plat_omap.c
CommitLineData
69af03a2 1/*
6469a8c4 2 * (C) GraÅžvydas "notaz" Ignotas, 2010-2012
69af03a2 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"
61f97bb0 18#include "common/input.h"
69af03a2 19#include "linux/fbdev.h"
0b49a8f7 20#include "linux/xenv.h"
69af03a2 21#include "plugin_lib.h"
4c08b9e7 22#include "pl_gun_ts.h"
55b0eeea 23#include "plat.h"
ab423939 24#include "plat_omap.h"
6469a8c4 25#include "menu.h"
69af03a2 26
6469a8c4 27static struct vout_fbdev *main_fb, *layer_fb;
69af03a2 28
366631aa 29static int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h)
69af03a2 30{
2c886904 31 struct omapfb_plane_info pi = { 0, };
32 struct omapfb_mem_info mi = { 0, };
69af03a2 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
366631aa 55 if (mi.size < 640*512*3*3) {
2cb46552 56 mi.size = 640*512*3*3;
96d9fde1 57 ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
58 if (ret != 0) {
59 perror("SETUP_MEM");
60 return -1;
61 }
69af03a2 62 }
63
64 pi.pos_x = x;
65 pi.pos_y = y;
66 pi.out_width = w;
67 pi.out_height = h;
68 pi.enabled = enabled;
69
70 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
71 if (ret != 0) {
72 perror("SETUP_PLANE");
73 return -1;
74 }
75
76 return 0;
77}
78
6469a8c4 79static int omap_enable_layer(int enabled)
69af03a2 80{
4c08b9e7 81 if (enabled)
82 pl_set_gun_rect(g_layer_x, g_layer_y, g_layer_w, g_layer_h);
83
69af03a2 84 return omap_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled,
366631aa 85 g_layer_x, g_layer_y, g_layer_w, g_layer_h);
69af03a2 86}
87
ab423939 88void plat_omap_gvideo_open(void)
6469a8c4 89{
90 omap_enable_layer(1);
91
92 // try to align redraws to vsync
93 vout_fbdev_wait_vsync(layer_fb);
94}
95
96void *plat_gvideo_set_mode(int *w, int *h, int *bpp)
97{
98 void *buf;
99
100 vout_fbdev_clear(layer_fb);
101 buf = vout_fbdev_resize(layer_fb, *w, *h, *bpp, 0, 0, 0, 0, 3);
102
103 omap_enable_layer(1);
104
105 return buf;
106}
107
108void *plat_gvideo_flip(void)
109{
110 return vout_fbdev_flip(layer_fb);
111}
112
113void plat_gvideo_close(void)
114{
115 omap_enable_layer(0);
116}
117
fba06457 118void plat_video_menu_enter(int is_rom_loaded)
119{
120 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
121 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 3);
122 if (g_menuscreen_ptr == NULL)
123 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
0b49a8f7 124
3a321131 125 xenv_update(NULL, NULL, NULL, NULL);
fba06457 126}
127
69af03a2 128void plat_video_menu_begin(void)
129{
130}
131
132void plat_video_menu_end(void)
133{
134 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
135}
136
fba06457 137void plat_video_menu_leave(void)
138{
139 /* have to get rid of panning so that plugins that
140 * use fb0 and don't ever pan can work. */
141 vout_fbdev_clear(main_fb);
142 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
143 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 1);
144 if (g_menuscreen_ptr == NULL)
145 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
146}
147
a805c855 148void plat_minimize(void)
149{
150 omap_enable_layer(0);
151 xenv_minimize();
61f97bb0 152 in_set_config_int(0, IN_CFG_BLOCKING, 0); /* flush event queue */
a805c855 153 omap_enable_layer(1);
154}
155
6469a8c4 156void *plat_prepare_screenshot(int *w, int *h, int *bpp)
157{
158 return NULL;
159}
160
ab423939 161void plat_omap_init(void)
69af03a2 162{
163 const char *main_fb_name, *layer_fb_name;
69af03a2 164 int fd, ret, w, h;
165
166 main_fb_name = getenv("FBDEV_MAIN");
167 if (main_fb_name == NULL)
168 main_fb_name = "/dev/fb0";
169
170 layer_fb_name = getenv("FBDEV_LAYER");
171 if (layer_fb_name == NULL)
172 layer_fb_name = "/dev/fb1";
173
174 // must set the layer up first to be able to use it
175 fd = open(layer_fb_name, O_RDWR);
176 if (fd == -1) {
177 fprintf(stderr, "%s: ", layer_fb_name);
178 perror("open");
179 exit(1);
180 }
181
6469a8c4 182 g_layer_x = 80, g_layer_y = 0;
183 g_layer_w = 640, g_layer_h = 480;
184
366631aa 185 ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h);
69af03a2 186 close(fd);
187 if (ret != 0) {
188 fprintf(stderr, "failed to set up layer, exiting.\n");
189 exit(1);
190 }
191
3a321131 192 xenv_init(NULL, "PCSX-ReARMed");
69af03a2 193
194 w = h = 0;
195 main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2);
196 if (main_fb == NULL) {
197 fprintf(stderr, "couldn't init fb: %s\n", main_fb_name);
198 exit(1);
199 }
200
201 g_menuscreen_w = w;
202 g_menuscreen_h = h;
203 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
bb88ec28 204 pl_rearmed_cbs.screen_w = w;
205 pl_rearmed_cbs.screen_h = h;
69af03a2 206
207 w = 640;
0b49a8f7 208 h = 512;
69af03a2 209 layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3);
210 if (layer_fb == NULL) {
211 fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name);
212 goto fail0;
213 }
214
69af03a2 215 return;
216
69af03a2 217fail0:
218 vout_fbdev_finish(main_fb);
219 exit(1);
69af03a2 220}
221
ab423939 222void plat_omap_finish(void)
bd6267e6 223{
224 omap_enable_layer(0);
225 vout_fbdev_finish(layer_fb);
226 vout_fbdev_finish(main_fb);
0b49a8f7 227 xenv_finish();
bd6267e6 228}
229