comparison src/video/ps3/SDL_ps3modes.c @ 3257:94fb40a4a9a7

Merged Martin's code changes from Google Summer of Code 2009
author Sam Lantinga <slouken@libsdl.org>
date Mon, 07 Sep 2009 04:51:29 +0000
parents
children 4b594623401b
comparison
equal deleted inserted replaced
3256:83c87f2b2aab 3257:94fb40a4a9a7
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23
24 #include "SDL_ps3video.h"
25
26 void
27 PS3_InitModes(_THIS)
28 {
29 deprintf(1, "+PS3_InitModes()\n");
30 SDL_VideoDisplay display;
31 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
32 SDL_DisplayMode mode;
33 PS3_DisplayModeData *modedata;
34 unsigned long vid = 0;
35
36 modedata = (PS3_DisplayModeData *) SDL_malloc(sizeof(*modedata));
37 if (!modedata) {
38 return;
39 }
40
41 /* Setting up the DisplayMode based on current settings */
42 struct ps3fb_ioctl_res res;
43 if (ioctl(data->fbdev, PS3FB_IOCTL_SCREENINFO, &res)) {
44 SDL_SetError("Can't get PS3FB_IOCTL_SCREENINFO");
45 }
46 mode.format = SDL_PIXELFORMAT_RGB888;
47 mode.refresh_rate = 0;
48 mode.w = res.xres;
49 mode.h = res.yres;
50
51 /* Setting up driver specific mode data,
52 * Get the current ps3 specific videmode number */
53 if (ioctl(data->fbdev, PS3FB_IOCTL_GETMODE, (unsigned long)&vid)) {
54 SDL_SetError("Can't get PS3FB_IOCTL_GETMODE");
55 }
56 deprintf(2, "PS3FB_IOCTL_GETMODE = %u\n", vid);
57 modedata->mode = vid;
58 mode.driverdata = modedata;
59
60 /* Set display's videomode and add it */
61 SDL_zero(display);
62 display.desktop_mode = mode;
63 display.current_mode = mode;
64
65 SDL_AddVideoDisplay(&display);
66 deprintf(1, "-PS3_InitModes()\n");
67 }
68
69 /* DisplayModes available on the PS3 */
70 static SDL_DisplayMode ps3fb_modedb[] = {
71 /* VESA */
72 {SDL_PIXELFORMAT_RGB888, 1280, 768, 0, NULL}, // WXGA
73 {SDL_PIXELFORMAT_RGB888, 1280, 1024, 0, NULL}, // SXGA
74 {SDL_PIXELFORMAT_RGB888, 1920, 1200, 0, NULL}, // WUXGA
75 /* Native resolutions (progressive, "fullscreen") */
76 {SDL_PIXELFORMAT_RGB888, 720, 480, 0, NULL}, // 480p
77 {SDL_PIXELFORMAT_RGB888, 1280, 720, 0, NULL}, // 720p
78 {SDL_PIXELFORMAT_RGB888, 1920, 1080, 0, NULL} // 1080p
79 };
80
81 /* PS3 videomode number according to ps3fb_modedb */
82 static PS3_DisplayModeData ps3fb_data[] = {
83 {11}, {12}, {13}, {130}, {131}, {133},
84 };
85
86 void
87 PS3_GetDisplayModes(_THIS) {
88 deprintf(1, "+PS3_GetDisplayModes()\n");
89 SDL_DisplayMode mode;
90 unsigned int nummodes;
91
92 nummodes = sizeof(ps3fb_modedb) / sizeof(SDL_DisplayMode);
93
94 int n;
95 for (n=0; n<nummodes; ++n) {
96 /* Get driver specific mode data */
97 ps3fb_modedb[n].driverdata = &ps3fb_data[n];
98
99 /* Add DisplayMode to list */
100 deprintf(2, "Adding resolution %u x %u\n", ps3fb_modedb[n].w, ps3fb_modedb[n].h);
101 SDL_AddDisplayMode(_this->current_display, &ps3fb_modedb[n]);
102 }
103 deprintf(1, "-PS3_GetDisplayModes()\n");
104 }
105
106 int
107 PS3_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
108 {
109 deprintf(1, "+PS3_SetDisplayMode()\n");
110 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
111 PS3_DisplayModeData *dispdata = (PS3_DisplayModeData *) mode->driverdata;
112
113 /* Set the new DisplayMode */
114 deprintf(2, "Setting PS3FB_MODE to %u\n", dispdata->mode);
115 if (ioctl(data->fbdev, PS3FB_IOCTL_SETMODE, (unsigned long)&dispdata->mode)) {
116 deprintf(2, "Could not set PS3FB_MODE\n");
117 SDL_SetError("Could not set PS3FB_MODE\n");
118 return -1;
119 }
120
121 deprintf(1, "-PS3_SetDisplayMode()\n");
122 return 0;
123 }
124
125 void
126 PS3_QuitModes(_THIS) {
127 deprintf(1, "+PS3_QuitModes()\n");
128
129 /* There was no mem allocated for driverdata */
130 int i, j;
131 for (i = _this->num_displays; i--;) {
132 SDL_VideoDisplay *display = &_this->displays[i];
133 for (j = display->num_display_modes; j--;) {
134 display->display_modes[j].driverdata = NULL;
135 }
136 }
137
138 deprintf(1, "-PS3_QuitModes()\n");
139 }
140
141 /* vi: set ts=4 sw=4 expandtab: */