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