annotate src/video/ps3/SDL_ps3video.c @ 4244:8fc98498e4f0 SDL-1.2

Fixed bug #806 Max Horn 2009-09-24 13:16:05 PDT Current SDL 1.2 SVN luckily builds on several systems now: 10.4 (PPC and 32bit intel), 10.5 (32 bit) and 10.6 (32 bit). However, it fails to build on 10.5 in 64 bit mode
author Sam Lantinga <slouken@libsdl.org>
date Sat, 26 Sep 2009 11:42:39 +0000
parents 3b8ac3d311a2
children
rev   line source
4165
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * SDL - Simple DirectMedia Layer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * CELL BE Support for PS3 Framebuffer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * Copyright (C) 2008, 2009 International Business Machines Corporation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or modify it
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 * under the terms of the GNU Lesser General Public License as published
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 * by the Free Software Foundation; either version 2.1 of the License, or
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 * (at your option) any later version.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful, but
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 * Lesser General Public License for more details.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 * USA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 * Martin Lowinski <lowinski [at] de [dot] ibm [ibm] com>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 * Dirk Herrendoerfer <d.herrendoerfer [at] de [dot] ibm [dot] com>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 * SPE code based on research by:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 * Rene Becker
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 * Thimo Emmerich
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "SDL_config.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "SDL_video.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include "../SDL_sysvideo.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include "SDL_ps3events_c.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include "SDL_ps3video.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include "SDL_ps3yuv_c.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include "spulibs/spu_common.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include <fcntl.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include <stdlib.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include <sys/ioctl.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include <linux/kd.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #include <sys/mman.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #include <linux/fb.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 #include <asm/ps3fb.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 #include <libspe2.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #include <malloc.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 /* SDL_VideoDevice functions */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 static int PS3_Available();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 static SDL_VideoDevice *PS3_CreateDevice(int devindex);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 static int PS3_VideoInit(_THIS, SDL_PixelFormat * vformat);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 static void PS3_VideoQuit(_THIS);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 static void PS3_DeleteDevice(SDL_VideoDevice * device);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 static SDL_Surface *PS3_SetVideoMode(_THIS, SDL_Surface * current, int width, int height, int bpp, Uint32 flags);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 static SDL_Rect **PS3_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 /* Hardware surface functions */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 static int PS3_AllocHWSurface(_THIS, SDL_Surface * surface);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 static void PS3_FreeHWSurface(_THIS, SDL_Surface * surface);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 static int PS3_LockHWSurface(_THIS, SDL_Surface * surface);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 static void PS3_UnlockHWSurface(_THIS, SDL_Surface * surface);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 static int PS3_FlipDoubleBuffer(_THIS, SDL_Surface * surface);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 static void PS3_DoubleBufferUpdate(_THIS, int numrects, SDL_Rect * rects);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 /* SPU specific functions */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 int SPE_Start(_THIS, spu_data_t * spe_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 int SPE_Stop(_THIS, spu_data_t * spe_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 int SPE_Boot(_THIS, spu_data_t * spe_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 int SPE_Shutdown(_THIS, spu_data_t * spe_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 int SPE_SendMsg(_THIS, spu_data_t * spe_data, unsigned int msg);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 int SPE_WaitForMsg(_THIS, spu_data_t * spe_data, unsigned int msg);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 void SPE_RunContext(void *thread_argp);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 /* Helpers */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 void enable_cursor(int enable);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 /* Stores the SPE executable name of fb_writer_spu */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 extern spe_program_handle_t fb_writer_spu;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 /* SDL PS3 bootstrap function for checking availability */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 static int PS3_Available()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 return 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 /* SDL PS3 bootstrap function for creating the device */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 static SDL_VideoDevice *PS3_CreateDevice(int devindex)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 SDL_VideoDevice *this;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 /* Initialise SDL_VideoDevice */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 this = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 if (this) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 memset(this, 0, sizeof *this);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 this->hidden = (struct SDL_PrivateVideoData *)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 SDL_malloc(sizeof(struct SDL_PrivateVideoData));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 /* Error handling */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 if ((this == NULL) || (this->hidden == NULL)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 if (this)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 SDL_free(this);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 memset(this->hidden, 0, sizeof(struct SDL_PrivateVideoData));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 /* Set the function pointers */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 this->VideoInit = PS3_VideoInit;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 this->ListModes = PS3_ListModes;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 this->SetVideoMode = PS3_SetVideoMode;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 this->SetColors = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 this->CreateYUVOverlay = PS3_CreateYUVOverlay;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 this->UpdateRects = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 this->VideoQuit = PS3_VideoQuit;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 this->AllocHWSurface = PS3_AllocHWSurface;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 this->CheckHWBlit = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 this->FillHWRect = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 this->SetHWColorKey = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 this->SetHWAlpha = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 this->LockHWSurface = PS3_LockHWSurface;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 this->UnlockHWSurface = PS3_UnlockHWSurface;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 this->FlipHWSurface = PS3_FlipDoubleBuffer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 this->FreeHWSurface = PS3_FreeHWSurface;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 this->SetCaption = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 this->SetIcon = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 this->IconifyWindow = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 this->GrabInput = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 this->GetWMInfo = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 this->InitOSKeymap = PS3_InitOSKeymap;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 this->PumpEvents = PS3_PumpEvents;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 this->free = PS3_DeleteDevice;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 return this;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 /* Bootstraping (see SDL_sysvideo.h) */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 VideoBootStrap PS3_bootstrap = {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 "ps3", "PS3 Cell SPU Driver",
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 PS3_Available, PS3_CreateDevice
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 /* Delete the device */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 static void PS3_DeleteDevice(SDL_VideoDevice * device)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 free(device->hidden);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 free(device);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 /* Initialise the PS3 video device */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 static int PS3_VideoInit(_THIS, SDL_PixelFormat * vformat)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 /* Hide the cursor */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 enable_cursor(0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 /* Create SPU fb_parms and thread structure */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 fb_parms = (struct fb_writer_parms_t *)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 memalign(16, sizeof(struct fb_writer_parms_t));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 fb_thread_data = (spu_data_t *) malloc(sizeof(spu_data_t));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 if (fb_parms == NULL || fb_thread_data == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 fb_thread_data->program = fb_writer_spu;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 fb_thread_data->program_name = "fb_writer_spu";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 fb_thread_data->argp = (void *)fb_parms;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 fb_thread_data->keepalive = 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 fb_thread_data->booted = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 SPE_Start(this, fb_thread_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 /* Open the device */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 fb_dev_fd = open(PS3_DEV_FB, O_RDWR);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 if (fb_dev_fd < 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 SDL_SetError("[PS3] Unable to open device %s", PS3_DEV_FB);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 /* Get vscreeninfo */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 SDL_SetError("[PS3] Can't get VSCREENINFO");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 if (fb_dev_fd >= 0)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 close(fb_dev_fd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 fb_dev_fd = -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 /* Fill in our hardware acceleration capabilities */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 this->info.current_w = fb_vinfo.xres;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 this->info.current_h = fb_vinfo.yres;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 this->info.wm_available = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 this->info.hw_available = 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 /* Backup the original vinfo to restore later */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 fb_orig_vinfo = fb_vinfo;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 /* 16 and 15 bpp is reported as 16 bpp */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 fb_bits_per_pixel = fb_vinfo.bits_per_pixel;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 if (fb_bits_per_pixel == 16)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 fb_bits_per_pixel =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 fb_vinfo.red.length + fb_vinfo.green.length +
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 fb_vinfo.blue.length;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 /* Set SDL_PixelFormat */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 vformat->BitsPerPixel = fb_vinfo.bits_per_pixel;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 fb_vinfo.xres_virtual = fb_vinfo.xres;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 fb_vinfo.yres_virtual = fb_vinfo.yres;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 /* Put vscreeninfo */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_vinfo)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 SDL_SetError("[PS3] Can't put VSCREENINFO");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 if (fb_dev_fd >= 0)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 close(fb_dev_fd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 fb_dev_fd = -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 s_fb_pixel_size = fb_vinfo.bits_per_pixel / 8;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 s_writeable_width = fb_vinfo.xres;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 s_writeable_height = fb_vinfo.yres;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 /* Get ps3 screeninfo */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 if (ioctl(fb_dev_fd, PS3FB_IOCTL_SCREENINFO, (unsigned long)&res) < 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 SDL_SetError("[PS3] PS3FB_IOCTL_SCREENINFO failed");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 deprintf(1, "[PS3] xres:%d yres:%d xoff:%d yoff:%d\n", res.xres, res.yres, res.xoff, res.yoff);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 /* Only use double buffering if enough fb memory is available */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 if (res.num_frames < 2) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 double_buffering = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 double_buffering = 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 real_width = res.xres;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 real_height = res.yres;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 * Take control of frame buffer from kernel, for details see
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 * http://felter.org/wesley/files/ps3/linux-20061110-docs/ApplicationProgrammingEnvironment.html
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 * kernel will no longer flip the screen itself
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 ioctl(fb_dev_fd, PS3FB_IOCTL_ON, 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 /* Unblank screen */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 ioctl(fb_dev_fd, FBIOBLANK, 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 /* List available PS3 resolutions */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 static SDL_Rect **PS3_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 /* A list of video resolutions that we query for (sorted largest to
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 * smallest)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 static SDL_Rect PS3_resolutions[] = {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 {0, 0, 1920, 1080}, // 1080p 16:9 HD
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 {0, 0, 1600, 1200}, // WUXGA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 {0, 0, 1280, 1024}, // SXGA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 {0, 0, 1280, 720}, // 720p 16:9 HD
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 {0, 0, 1024, 768}, // WXGA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 {0, 0, 1024, 576}, // 576p 16:9
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 {0, 0, 853, 480}, // 480p 16:9
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 {0, 0, 720, 576}, // 576p 4:3 (PAL)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 {0, 0, 720, 480}, // 480p 16:9 (NTSC)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 static SDL_Rect *PS3_modes[] = {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 &PS3_resolutions[0],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 &PS3_resolutions[1],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 &PS3_resolutions[2],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 &PS3_resolutions[3],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 &PS3_resolutions[4],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 &PS3_resolutions[5],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 &PS3_resolutions[6],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 &PS3_resolutions[7],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 &PS3_resolutions[8],
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 NULL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 SDL_Rect **modes = PS3_modes;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 return modes;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 /* Get a list of the available display modes */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 static SDL_Surface *PS3_SetVideoMode(_THIS, SDL_Surface * current, int width, int height, int bpp, Uint32 flags)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 s_bounded_input_width = width < s_writeable_width ? width : s_writeable_width;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 s_bounded_input_height = height < s_writeable_height ? height : s_writeable_height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 s_bounded_input_width_offset = (s_writeable_width - s_bounded_input_width) >> 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 s_bounded_input_height_offset = (s_writeable_height - s_bounded_input_height) >> 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 s_input_line_length = width * s_fb_pixel_size;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 current->flags |= flags;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 SDL_SetError("[PS3] Can't get fixed screeninfo");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 if (fb_finfo.type != FB_TYPE_PACKED_PIXELS) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 SDL_SetError("[PS3] type %s not supported",
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 fb_finfo.type);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 /* Note: on PS3, fb_finfo.smem_len is enough for double buffering */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 if ((frame_buffer =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 (uint8_t *) mmap(0, fb_finfo.smem_len,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 PROT_READ | PROT_WRITE, MAP_SHARED,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 fb_dev_fd, 0)) == (uint8_t *) - 1) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 SDL_SetError("[PS3] Can't mmap for %s", PS3_DEV_FB);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 current->flags |= SDL_DOUBLEBUF;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 if (!SDL_ReallocFormat(current, fb_bits_per_pixel, 0, 0, 0, 0)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 return (NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 /* Blank screen */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 memset(frame_buffer, 0x00, fb_finfo.smem_len);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 /* Centering */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 s_center[0] =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 frame_buffer + s_bounded_input_width_offset * s_fb_pixel_size +
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 s_bounded_input_height_offset * fb_finfo.line_length;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 s_center[1] = s_center[0] + real_height * fb_finfo.line_length;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 s_center_index = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 current->flags |= SDL_FULLSCREEN;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 current->w = width;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 current->h = height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 current->pitch = SDL_CalculatePitch(current);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 /* Alloc aligned mem for current->pixels */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 s_pixels = memalign(16, current->h * current->pitch);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 current->pixels = (void *)s_pixels;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 if (!current->pixels) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 /* Set the update rectangle function */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 this->UpdateRects = PS3_DoubleBufferUpdate;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 return current;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 /* Copy screen to framebuffer and flip */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 void PS3_DoubleBufferUpdate(_THIS, int numrects, SDL_Rect * rects)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 if (converter_thread_data && converter_thread_data->booted)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 SPE_WaitForMsg(this, converter_thread_data, SPU_FIN);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 /* Adjust centering */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 s_bounded_input_width_offset = (s_writeable_width - s_bounded_input_width) >> 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 s_bounded_input_height_offset = (s_writeable_height - s_bounded_input_height) >> 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 s_center[0] = frame_buffer + s_bounded_input_width_offset * s_fb_pixel_size +
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 s_bounded_input_height_offset * fb_finfo.line_length;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 s_center[1] = s_center[0] + real_height * fb_finfo.line_length;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 /* Set SPU parms for copying the surface to framebuffer */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 fb_parms->data = (unsigned char *)s_pixels;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 fb_parms->center = s_center[s_center_index];
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 fb_parms->out_line_stride = fb_finfo.line_length;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 fb_parms->in_line_stride = s_input_line_length;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 fb_parms->bounded_input_height = s_bounded_input_height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 fb_parms->bounded_input_width = s_bounded_input_width;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 fb_parms->fb_pixel_size = s_fb_pixel_size;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 deprintf(3, "[PS3->SPU] fb_thread_data->argp = 0x%x\n", fb_thread_data->argp);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 /* Copying.. */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 SPE_SendMsg(this, fb_thread_data, SPU_START);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 SPE_SendMsg(this, fb_thread_data, (unsigned int)fb_thread_data->argp);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 SPE_WaitForMsg(this, fb_thread_data, SPU_FIN);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 /* Flip the pages */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 if (double_buffering)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 s_center_index = s_center_index ^ 0x01;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 PS3_FlipDoubleBuffer(this, this->screen);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 /* Enable/Disable cursor */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 void enable_cursor(int enable)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 int fd = open("/dev/console", O_RDWR | O_NONBLOCK);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 if (fd >= 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 ioctl(fd, KDSETMODE, enable ? KD_TEXT : KD_GRAPHICS);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 close(fd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 static int PS3_AllocHWSurface(_THIS, SDL_Surface * surface)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 static void PS3_FreeHWSurface(_THIS, SDL_Surface * surface)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 return;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 static int PS3_LockHWSurface(_THIS, SDL_Surface * surface)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 static void PS3_UnlockHWSurface(_THIS, SDL_Surface * surface)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 return;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 /* Blit/Flip buffer to the screen. Must be called after each frame! */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 int PS3_FlipDoubleBuffer(_THIS, SDL_Surface * surface)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 unsigned long crt = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 /* Wait for vsync */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 deprintf(1, "[PS3] Wait for vsync\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 ioctl(fb_dev_fd, FBIO_WAITFORVSYNC, &crt);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 /* Page flip */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 deprintf(1, "[PS3] Page flip to buffer #%u 0x%x\n", s_center_index, s_center[s_center_index]);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 ioctl(fb_dev_fd, PS3FB_IOCTL_FSEL, (unsigned long)&s_center_index);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 return 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 /* Start the SPE thread */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 int SPE_Start(_THIS, spu_data_t * spe_data)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 deprintf(2, "[PS3->SPU] Start SPE: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 if (!(spe_data->booted))
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 SPE_Boot(this, spe_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 /* To allow re-running of context, spe_ctx_entry has to be set before each call */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 spe_data->entry = SPE_DEFAULT_ENTRY;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 spe_data->error_code = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 /* Create SPE thread and run */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 deprintf(2, "[PS3->SPU] Create Thread: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 if (pthread_create
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 (&spe_data->thread, NULL, (void *)&SPE_RunContext, (void *)spe_data)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 deprintf(2, "[PS3->SPU] Could not create pthread for spe: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 SDL_SetError("[PS3->SPU] Could not create pthread for spe");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 if (spe_data->keepalive)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 SPE_WaitForMsg(this, spe_data, SPU_READY);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 /* Stop the SPE thread */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 int SPE_Stop(_THIS, spu_data_t * spe_data)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 deprintf(2, "[PS3->SPU] Stop SPE: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 /* Wait for SPE thread to complete */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 deprintf(2, "[PS3->SPU] Wait for SPE thread to complete: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 if (pthread_join(spe_data->thread, NULL)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 deprintf(2, "[PS3->SPU] Failed joining the thread: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 SDL_SetError("[PS3->SPU] Failed joining the thread");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 /* Create SPE context and load program */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 int SPE_Boot(_THIS, spu_data_t * spe_data)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 /* Create SPE context */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 deprintf(2, "[PS3->SPU] Create SPE Context: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 spe_data->ctx = spe_context_create(0, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 if (spe_data->ctx == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 deprintf(2, "[PS3->SPU] Failed creating SPE context: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 SDL_SetError("[PS3->SPU] Failed creating SPE context");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 /* Load SPE object into SPE local store */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 deprintf(2, "[PS3->SPU] Load Program into SPE: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 if (spe_program_load(spe_data->ctx, &spe_data->program)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 deprintf(2, "[PS3->SPU] Failed loading program into SPE context: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 SDL_SetError
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 ("[PS3->SPU] Failed loading program into SPE context");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 spe_data->booted = 1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 deprintf(2, "[PS3->SPU] SPE boot successful\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 /* (Stop and) shutdown the SPE */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 int SPE_Shutdown(_THIS, spu_data_t * spe_data)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 if (spe_data->keepalive && spe_data->booted) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 SPE_SendMsg(this, spe_data, SPU_EXIT);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 SPE_Stop(this, spe_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 /* Destroy SPE context */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 deprintf(2, "[PS3->SPU] Destroy SPE context: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 if (spe_context_destroy(spe_data->ctx)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 deprintf(2, "[PS3->SPU] Failed destroying context: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 SDL_SetError("[PS3->SPU] Failed destroying context");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 deprintf(2, "[PS3->SPU] SPE shutdown successful: %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 /* Send message to the SPE via mailboxe */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 int SPE_SendMsg(_THIS, spu_data_t * spe_data, unsigned int msg)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 deprintf(2, "[PS3->SPU] Sending message %u to %s\n", msg, spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 /* Send one message, block until message was sent */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 unsigned int spe_in_mbox_msgs[1];
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 spe_in_mbox_msgs[0] = msg;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 int in_mbox_write = spe_in_mbox_write(spe_data->ctx, spe_in_mbox_msgs, 1, SPE_MBOX_ALL_BLOCKING);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 if (1 > in_mbox_write) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 deprintf(2, "[PS3->SPU] No message could be written to %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 SDL_SetError("[PS3->SPU] No message could be written");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 /* Read 1 message from SPE, block until at least 1 message was received */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 int SPE_WaitForMsg(_THIS, spu_data_t * spe_data, unsigned int msg)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 deprintf(2, "[PS3->SPU] Waiting for message from %s\n", spe_data->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 unsigned int out_messages[1];
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 while (!spe_out_mbox_status(spe_data->ctx));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 int mbox_read = spe_out_mbox_read(spe_data->ctx, out_messages, 1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 deprintf(2, "[PS3->SPU] Got message from %s, message was %u\n", spe_data->program_name, out_messages[0]);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 if (out_messages[0] == msg)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 else
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 /* Re-runnable invocation of the spe_context_run call */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 void SPE_RunContext(void *thread_argp)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 /* argp is the pointer to argument to be passed to the SPE program */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 spu_data_t *args = (spu_data_t *) thread_argp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 deprintf(3, "[PS3->SPU] void* argp=0x%x\n", (unsigned int)args->argp);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 /* Run it.. */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 deprintf(2, "[PS3->SPU] Run SPE program: %s\n", args->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 if (spe_context_run
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 (args->ctx, &args->entry, 0, (void *)args->argp, NULL,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 NULL) < 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 deprintf(2, "[PS3->SPU] Failed running SPE context: %s\n", args->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 SDL_SetError("[PS3->SPU] Failed running SPE context: %s", args->program_name);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 exit(1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 pthread_exit(NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 /* Quits the video driver */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 static void PS3_VideoQuit(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 if (fb_dev_fd > 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 /* Restore the original video mode */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_orig_vinfo))
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 SDL_SetError("[PS3] Can't restore original fb_var_screeninfo");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 /* Give control of frame buffer to kernel */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 ioctl(fb_dev_fd, PS3FB_IOCTL_OFF, 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 close(fb_dev_fd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 fb_dev_fd = -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 if (frame_buffer) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 munmap(frame_buffer, fb_finfo.smem_len);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 frame_buffer = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 if (fb_parms)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 free((void *)fb_parms);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 if (fb_thread_data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 SPE_Shutdown(this, fb_thread_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 free((void *)fb_thread_data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 if (this->screen) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 if (double_buffering && this->screen->pixels) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 free(this->screen->pixels);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 this->screen->pixels = NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 enable_cursor(1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 deprintf(1, "[PS3] VideoQuit\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621