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" |
18 | #include "linux/fbdev.h" |
0b49a8f7 |
19 | #include "linux/xenv.h" |
69af03a2 |
20 | #include "plugin_lib.h" |
4c08b9e7 |
21 | #include "pl_gun_ts.h" |
55b0eeea |
22 | #include "plat.h" |
6469a8c4 |
23 | #include "menu.h" |
69af03a2 |
24 | |
6469a8c4 |
25 | static struct vout_fbdev *main_fb, *layer_fb; |
69af03a2 |
26 | |
366631aa |
27 | static int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h) |
69af03a2 |
28 | { |
2c886904 |
29 | struct omapfb_plane_info pi = { 0, }; |
30 | struct omapfb_mem_info mi = { 0, }; |
69af03a2 |
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 | |
366631aa |
53 | if (mi.size < 640*512*3*3) { |
2cb46552 |
54 | mi.size = 640*512*3*3; |
96d9fde1 |
55 | ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); |
56 | if (ret != 0) { |
57 | perror("SETUP_MEM"); |
58 | return -1; |
59 | } |
69af03a2 |
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 | |
6469a8c4 |
77 | static int omap_enable_layer(int enabled) |
69af03a2 |
78 | { |
4c08b9e7 |
79 | if (enabled) |
80 | pl_set_gun_rect(g_layer_x, g_layer_y, g_layer_w, g_layer_h); |
81 | |
69af03a2 |
82 | return omap_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled, |
366631aa |
83 | g_layer_x, g_layer_y, g_layer_w, g_layer_h); |
69af03a2 |
84 | } |
85 | |
6469a8c4 |
86 | void 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 | |
94 | void *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 | |
106 | void *plat_gvideo_flip(void) |
107 | { |
108 | return vout_fbdev_flip(layer_fb); |
109 | } |
110 | |
111 | void plat_gvideo_close(void) |
112 | { |
113 | omap_enable_layer(0); |
114 | } |
115 | |
fba06457 |
116 | void 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"); |
0b49a8f7 |
122 | |
3a321131 |
123 | xenv_update(NULL, NULL, NULL, NULL); |
fba06457 |
124 | } |
125 | |
69af03a2 |
126 | void plat_video_menu_begin(void) |
127 | { |
128 | } |
129 | |
130 | void plat_video_menu_end(void) |
131 | { |
132 | g_menuscreen_ptr = vout_fbdev_flip(main_fb); |
133 | } |
134 | |
fba06457 |
135 | void 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 | |
a805c855 |
146 | void plat_minimize(void) |
147 | { |
148 | omap_enable_layer(0); |
149 | xenv_minimize(); |
150 | omap_enable_layer(1); |
151 | } |
152 | |
221be40d |
153 | void plat_step_volume(int is_up) |
154 | { |
155 | } |
156 | |
3a40ff14 |
157 | void plat_trigger_vibrate(int is_strong) |
b944a30e |
158 | { |
159 | } |
160 | |
6469a8c4 |
161 | void *plat_prepare_screenshot(int *w, int *h, int *bpp) |
162 | { |
163 | return NULL; |
164 | } |
165 | |
69af03a2 |
166 | void plat_init(void) |
167 | { |
168 | const char *main_fb_name, *layer_fb_name; |
69af03a2 |
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 | |
6469a8c4 |
187 | g_layer_x = 80, g_layer_y = 0; |
188 | g_layer_w = 640, g_layer_h = 480; |
189 | |
366631aa |
190 | ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h); |
69af03a2 |
191 | close(fd); |
192 | if (ret != 0) { |
193 | fprintf(stderr, "failed to set up layer, exiting.\n"); |
194 | exit(1); |
195 | } |
196 | |
3a321131 |
197 | xenv_init(NULL, "PCSX-ReARMed"); |
69af03a2 |
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); |
bb88ec28 |
209 | pl_rearmed_cbs.screen_w = w; |
210 | pl_rearmed_cbs.screen_h = h; |
69af03a2 |
211 | |
212 | w = 640; |
0b49a8f7 |
213 | h = 512; |
69af03a2 |
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 | |
9b4bd105 |
220 | plat_pandora_init(); // XXX |
221 | |
69af03a2 |
222 | return; |
223 | |
224 | fail1: |
225 | vout_fbdev_finish(layer_fb); |
226 | fail0: |
227 | vout_fbdev_finish(main_fb); |
228 | exit(1); |
229 | |
230 | } |
231 | |
bd6267e6 |
232 | void plat_finish(void) |
233 | { |
234 | omap_enable_layer(0); |
235 | vout_fbdev_finish(layer_fb); |
236 | vout_fbdev_finish(main_fb); |
0b49a8f7 |
237 | xenv_finish(); |
bd6267e6 |
238 | } |
239 | |