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 | |
cc56203b |
17 | #include "libpicofe/menu.h" |
18 | #include "libpicofe/input.h" |
19 | #include "libpicofe/linux/fbdev.h" |
20 | #include "libpicofe/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 |
27 | static struct vout_fbdev *main_fb, *layer_fb; |
69af03a2 |
28 | |
366631aa |
29 | static 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 | |
99d767a0 |
55 | // upto 1024x512 (2x resolution enhancement) |
56 | if (mi.size < 1024*512*2 * 3) { |
57 | mi.size = 1024*512*2 * 3; |
96d9fde1 |
58 | ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); |
59 | if (ret != 0) { |
60 | perror("SETUP_MEM"); |
61 | return -1; |
62 | } |
69af03a2 |
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 | |
6469a8c4 |
80 | static int omap_enable_layer(int enabled) |
69af03a2 |
81 | { |
4c08b9e7 |
82 | if (enabled) |
83 | pl_set_gun_rect(g_layer_x, g_layer_y, g_layer_w, g_layer_h); |
84 | |
69af03a2 |
85 | return omap_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled, |
366631aa |
86 | g_layer_x, g_layer_y, g_layer_w, g_layer_h); |
69af03a2 |
87 | } |
88 | |
ab423939 |
89 | void plat_omap_gvideo_open(void) |
6469a8c4 |
90 | { |
91 | omap_enable_layer(1); |
92 | |
93 | // try to align redraws to vsync |
94 | vout_fbdev_wait_vsync(layer_fb); |
95 | } |
96 | |
97 | void *plat_gvideo_set_mode(int *w, int *h, int *bpp) |
98 | { |
f6edea0c |
99 | int l = 0, r = 0, t = 0, b = 0; |
6469a8c4 |
100 | void *buf; |
101 | |
f6edea0c |
102 | if (g_scaler == SCALE_1_1) { |
103 | if (*w > g_menuscreen_w) |
104 | l = r = (*w - g_menuscreen_w) / 2; |
105 | if (*h > g_menuscreen_h) |
106 | t = b = (*h - g_menuscreen_h) / 2; |
107 | } |
108 | |
6469a8c4 |
109 | vout_fbdev_clear(layer_fb); |
f6edea0c |
110 | buf = vout_fbdev_resize(layer_fb, *w, *h, *bpp, |
111 | l, r, t, b, 3); |
6469a8c4 |
112 | |
113 | omap_enable_layer(1); |
114 | |
115 | return buf; |
116 | } |
117 | |
118 | void *plat_gvideo_flip(void) |
119 | { |
120 | return vout_fbdev_flip(layer_fb); |
121 | } |
122 | |
123 | void plat_gvideo_close(void) |
124 | { |
125 | omap_enable_layer(0); |
126 | } |
127 | |
fba06457 |
128 | void plat_video_menu_enter(int is_rom_loaded) |
129 | { |
130 | g_menuscreen_ptr = vout_fbdev_resize(main_fb, |
131 | g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 3); |
132 | if (g_menuscreen_ptr == NULL) |
133 | fprintf(stderr, "warning: vout_fbdev_resize failed\n"); |
0b49a8f7 |
134 | |
3a321131 |
135 | xenv_update(NULL, NULL, NULL, NULL); |
fba06457 |
136 | } |
137 | |
69af03a2 |
138 | void plat_video_menu_begin(void) |
139 | { |
140 | } |
141 | |
142 | void plat_video_menu_end(void) |
143 | { |
144 | g_menuscreen_ptr = vout_fbdev_flip(main_fb); |
145 | } |
146 | |
fba06457 |
147 | void plat_video_menu_leave(void) |
148 | { |
149 | /* have to get rid of panning so that plugins that |
150 | * use fb0 and don't ever pan can work. */ |
151 | vout_fbdev_clear(main_fb); |
152 | g_menuscreen_ptr = vout_fbdev_resize(main_fb, |
153 | g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 1); |
154 | if (g_menuscreen_ptr == NULL) |
155 | fprintf(stderr, "warning: vout_fbdev_resize failed\n"); |
156 | } |
157 | |
a805c855 |
158 | void plat_minimize(void) |
159 | { |
36dfb787 |
160 | int ret; |
161 | |
162 | ret = vout_fbdev_save(layer_fb); |
163 | if (ret != 0) { |
164 | printf("minimize: layer/fb handling failed\n"); |
165 | return; |
166 | } |
167 | |
a805c855 |
168 | xenv_minimize(); |
36dfb787 |
169 | |
61f97bb0 |
170 | in_set_config_int(0, IN_CFG_BLOCKING, 0); /* flush event queue */ |
36dfb787 |
171 | omap_enable_layer(0); /* restore layer mem */ |
172 | vout_fbdev_restore(layer_fb); |
a805c855 |
173 | } |
174 | |
6469a8c4 |
175 | void *plat_prepare_screenshot(int *w, int *h, int *bpp) |
176 | { |
177 | return NULL; |
178 | } |
179 | |
ab423939 |
180 | void plat_omap_init(void) |
69af03a2 |
181 | { |
182 | const char *main_fb_name, *layer_fb_name; |
69af03a2 |
183 | int fd, ret, w, h; |
184 | |
185 | main_fb_name = getenv("FBDEV_MAIN"); |
186 | if (main_fb_name == NULL) |
187 | main_fb_name = "/dev/fb0"; |
188 | |
189 | layer_fb_name = getenv("FBDEV_LAYER"); |
190 | if (layer_fb_name == NULL) |
191 | layer_fb_name = "/dev/fb1"; |
192 | |
193 | // must set the layer up first to be able to use it |
194 | fd = open(layer_fb_name, O_RDWR); |
195 | if (fd == -1) { |
196 | fprintf(stderr, "%s: ", layer_fb_name); |
197 | perror("open"); |
198 | exit(1); |
199 | } |
200 | |
6469a8c4 |
201 | g_layer_x = 80, g_layer_y = 0; |
202 | g_layer_w = 640, g_layer_h = 480; |
203 | |
366631aa |
204 | ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h); |
69af03a2 |
205 | close(fd); |
206 | if (ret != 0) { |
207 | fprintf(stderr, "failed to set up layer, exiting.\n"); |
208 | exit(1); |
209 | } |
210 | |
3a321131 |
211 | xenv_init(NULL, "PCSX-ReARMed"); |
69af03a2 |
212 | |
213 | w = h = 0; |
214 | main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2); |
215 | if (main_fb == NULL) { |
216 | fprintf(stderr, "couldn't init fb: %s\n", main_fb_name); |
217 | exit(1); |
218 | } |
219 | |
220 | g_menuscreen_w = w; |
221 | g_menuscreen_h = h; |
222 | g_menuscreen_ptr = vout_fbdev_flip(main_fb); |
bb88ec28 |
223 | pl_rearmed_cbs.screen_w = w; |
224 | pl_rearmed_cbs.screen_h = h; |
69af03a2 |
225 | |
226 | w = 640; |
0b49a8f7 |
227 | h = 512; |
69af03a2 |
228 | layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3); |
229 | if (layer_fb == NULL) { |
230 | fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name); |
231 | goto fail0; |
232 | } |
233 | |
69af03a2 |
234 | return; |
235 | |
69af03a2 |
236 | fail0: |
237 | vout_fbdev_finish(main_fb); |
238 | exit(1); |
69af03a2 |
239 | } |
240 | |
ab423939 |
241 | void plat_omap_finish(void) |
bd6267e6 |
242 | { |
243 | omap_enable_layer(0); |
244 | vout_fbdev_finish(layer_fb); |
245 | vout_fbdev_finish(main_fb); |
0b49a8f7 |
246 | xenv_finish(); |
bd6267e6 |
247 | } |
248 | |