Mercurial > sdl-ios-xcode
annotate src/video/ps2gs/SDL_gsyuv.c @ 1145:d31afac94eff
Patch from Martin Lange (mala-sdl at hotmail.com) to unregister SDL's win32
windowclass when shutting down the video subsystem...this allows you to
safely unload/reload the SDL shared library on Windows between
initializations.
Discussion is here:
http://www.devolution.com/pipermail/sdl/2005-February/067424.html
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 27 Sep 2005 09:00:42 +0000 |
parents | 522e5202014d |
children | c9b51268668f |
rev | line source |
---|---|
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
1 /* |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
4 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
9 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
13 Library General Public License for more details. |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
14 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
18 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
19 Sam Lantinga |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
136
diff
changeset
|
20 slouken@libsdl.org |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
21 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
22 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
23 #ifdef SAVE_RCSID |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
24 static char rcsid = |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
25 "@(#) $Id$"; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
26 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
27 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
28 /* This is the Playstation 2 implementation of YUV video overlays */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
29 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
30 #include <stdlib.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
31 #include <string.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
32 #include <fcntl.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
33 #include <unistd.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
34 #include <sys/ioctl.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
35 #include <sys/mman.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
36 #include <asm/page.h> /* For definition of PAGE_SIZE */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
37 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
38 #include "SDL_error.h" |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
39 #include "SDL_video.h" |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
40 #include "SDL_gsyuv_c.h" |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
41 #include "SDL_yuvfuncs.h" |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
42 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
43 /* The maximum number of 16x16 pixel block converted at once */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
44 #define MAX_MACROBLOCKS 1024 /* 2^10 macroblocks at once */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
45 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
46 /* The functions used to manipulate video overlays */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
47 static struct private_yuvhwfuncs gs_yuvfuncs = { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
48 GS_LockYUVOverlay, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
49 GS_UnlockYUVOverlay, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
50 GS_DisplayYUVOverlay, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
51 GS_FreeYUVOverlay |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
52 }; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
53 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
54 struct private_yuvhwdata { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
55 int ipu_fd; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
56 Uint8 *pixels; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
57 int macroblocks; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
58 int dma_len; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
59 caddr_t dma_mem; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
60 caddr_t ipu_imem; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
61 caddr_t ipu_omem; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
62 caddr_t dma_tags; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
63 unsigned long long *stretch_x1y1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
64 unsigned long long *stretch_x2y2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
65 struct ps2_plist plist; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
66 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
67 /* These are just so we don't have to allocate them separately */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
68 Uint16 pitches[3]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
69 Uint8 *planes[3]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
70 }; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
71 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
72 static int power_of_2(int value) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
73 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
74 int shift; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
75 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
76 for ( shift = 0; (1<<shift) < value; ++shift ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
77 /* Keep looking */ ; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
78 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
79 return(shift); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
80 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
81 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
82 SDL_Overlay *GS_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
83 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
84 SDL_Overlay *overlay; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
85 struct private_yuvhwdata *hwdata; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
86 int map_offset; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
87 unsigned long long *tags; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
88 caddr_t base; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
89 int bpp; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
90 int fbp, fbw, psm; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
91 int x, y, w, h; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
92 int pnum; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
93 struct ps2_packet *packet; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
94 struct ps2_packet tex_packet; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
95 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
96 /* We can only decode blocks of 16x16 pixels */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
97 if ( (width & 15) || (height & 15) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
98 SDL_SetError("Overlay width/height must be multiples of 16"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
99 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
100 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
101 /* Make sure the image isn't too large for a single DMA transfer */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
102 if ( ((width/16) * (height/16)) > MAX_MACROBLOCKS ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
103 SDL_SetError("Overlay too large (maximum size: %d pixels)", |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
104 MAX_MACROBLOCKS * 16 * 16); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
105 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
106 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
107 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
108 /* Double-check the requested format. For simplicity, we'll only |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
109 support planar YUV formats. |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
110 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
111 switch (format) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
112 case SDL_YV12_OVERLAY: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
113 case SDL_IYUV_OVERLAY: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
114 /* Supported planar YUV format */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
115 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
116 default: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
117 SDL_SetError("Unsupported YUV format"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
118 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
119 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
120 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
121 /* Create the overlay structure */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
122 overlay = (SDL_Overlay *)malloc(sizeof *overlay); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
123 if ( overlay == NULL ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
124 SDL_OutOfMemory(); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
125 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
126 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
127 memset(overlay, 0, (sizeof *overlay)); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
128 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
129 /* Fill in the basic members */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
130 overlay->format = format; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
131 overlay->w = width; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
132 overlay->h = height; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
133 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
134 /* Set up the YUV surface function structure */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
135 overlay->hwfuncs = &gs_yuvfuncs; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
136 overlay->hw_overlay = 1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
137 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
138 /* Create the pixel data */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
139 hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
140 overlay->hwdata = hwdata; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
141 if ( hwdata == NULL ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
142 SDL_FreeYUVOverlay(overlay); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
143 SDL_OutOfMemory(); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
144 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
145 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
146 hwdata->ipu_fd = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
147 hwdata->pixels = (Uint8 *)malloc(width*height*2); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
148 if ( hwdata->pixels == NULL ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
149 SDL_FreeYUVOverlay(overlay); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
150 SDL_OutOfMemory(); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
151 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
152 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
153 hwdata->macroblocks = (width/16) * (height/16); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
154 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
155 /* Find the pitch and offset values for the overlay */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
156 overlay->pitches = hwdata->pitches; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
157 overlay->pixels = hwdata->planes; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
158 switch (format) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
159 case SDL_YV12_OVERLAY: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
160 case SDL_IYUV_OVERLAY: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
161 overlay->pitches[0] = overlay->w; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
162 overlay->pitches[1] = overlay->pitches[0] / 2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
163 overlay->pitches[2] = overlay->pitches[0] / 2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
164 overlay->pixels[0] = hwdata->pixels; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
165 overlay->pixels[1] = overlay->pixels[0] + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
166 overlay->pitches[0] * overlay->h; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
167 overlay->pixels[2] = overlay->pixels[1] + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
168 overlay->pitches[1] * overlay->h / 2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
169 overlay->planes = 3; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
170 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
171 default: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
172 /* We should never get here (caught above) */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
173 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
174 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
175 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
176 /* Theoretically we could support several concurrent decode |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
177 streams queueing up on the same file descriptor, but for |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
178 simplicity we'll support only one. Opening the IPU more |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
179 than once will fail with EBUSY. |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
180 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
181 hwdata->ipu_fd = open("/dev/ps2ipu", O_RDWR); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
182 if ( hwdata->ipu_fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
183 SDL_FreeYUVOverlay(overlay); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
184 SDL_SetError("Playstation 2 IPU busy"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
185 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
186 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
187 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
188 /* Allocate a DMA area for pixel conversion */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
189 bpp = this->screen->format->BytesPerPixel; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
190 map_offset = (mapped_len + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
191 hwdata->dma_len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
192 width * height * bpp + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
193 hwdata->macroblocks * (16 * sizeof(long long)) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
194 12 * sizeof(long long); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
195 hwdata->dma_mem = mmap(0, hwdata->dma_len, PROT_READ|PROT_WRITE, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
196 MAP_SHARED, memory_fd, map_offset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
197 if ( hwdata->dma_mem == MAP_FAILED ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
198 hwdata->ipu_imem = (caddr_t)0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
199 SDL_FreeYUVOverlay(overlay); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
200 SDL_SetError("Unable to map %d bytes for DMA", hwdata->dma_len); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
201 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
202 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
203 hwdata->ipu_imem = hwdata->dma_mem; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
204 hwdata->ipu_omem = hwdata->ipu_imem + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
205 hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
206 hwdata->dma_tags = hwdata->ipu_omem + width * height * bpp; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
207 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
208 /* Allocate memory for the DMA packets */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
209 hwdata->plist.num = hwdata->macroblocks * 4 + 1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
210 hwdata->plist.packet = (struct ps2_packet *)malloc( |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
211 hwdata->plist.num*sizeof(struct ps2_packet)); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
212 if ( ! hwdata->plist.packet ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
213 SDL_FreeYUVOverlay(overlay); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
214 SDL_OutOfMemory(); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
215 return(NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
216 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
217 pnum = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
218 packet = hwdata->plist.packet; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
219 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
220 /* Set up the tags to send the image to the screen */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
221 tags = (unsigned long long *)hwdata->dma_tags; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
222 base = hwdata->ipu_omem; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
223 fbp = screen_image.fbp; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
224 fbw = screen_image.fbw; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
225 psm = screen_image.psm; |
136
717f739d6ec1
Added hardware stretching code to scale 640x480 to TV resolution
Sam Lantinga <slouken@libsdl.org>
parents:
70
diff
changeset
|
226 y = screen_image.y + screen_image.h; /* Offscreen video memory */ |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
227 for ( h=height/16; h; --h ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
228 x = 0; /* Visible video memory */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
229 for ( w=width/16; w; --w ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
230 /* The head tag */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
231 packet[pnum].ptr = &tags[0]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
232 packet[pnum].len = 10 * sizeof(*tags); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
233 ++pnum; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
234 tags[0] = 4 | (1LL << 60); /* GIFtag */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
235 tags[1] = 0x0e; /* A+D */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
236 tags[2] = ((unsigned long long)fbp << 32) | |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
237 ((unsigned long long)fbw << 48) | |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
238 ((unsigned long long)psm << 56); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
239 tags[3] = PS2_GS_BITBLTBUF; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
240 tags[4] = ((unsigned long long)x << 32) | |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
241 ((unsigned long long)y << 48); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
242 tags[5] = PS2_GS_TRXPOS; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
243 tags[6] = (unsigned long long)16 | |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
244 ((unsigned long long)16 << 32); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
245 tags[7] = PS2_GS_TRXREG; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
246 tags[8] = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
247 tags[9] = PS2_GS_TRXDIR; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
248 /* Now the actual image data */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
249 packet[pnum].ptr = &tags[10]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
250 packet[pnum].len = 2 * sizeof(*tags); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
251 ++pnum; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
252 tags[10] = ((16*16*bpp) >> 4) | (2LL << 58); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
253 tags[11] = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
254 packet[pnum].ptr = (void *)base; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
255 packet[pnum].len = 16 * 16 * bpp; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
256 ++pnum; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
257 packet[pnum].ptr = &tags[12]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
258 packet[pnum].len = 2 * sizeof(*tags); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
259 ++pnum; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
260 tags[12] = (0 >> 4) | (1 << 15) | (2LL << 58); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
261 tags[13] = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
262 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
263 tags += 16; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
264 base += 16 * 16 * bpp; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
265 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
266 x += 16; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
267 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
268 y += 16; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
269 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
270 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
271 /* Set up the texture memory area for the video */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
272 tex_packet.ptr = tags; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
273 tex_packet.len = 8 * sizeof(*tags); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
274 tags[0] = 3 | (1LL << 60); /* GIFtag */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
275 tags[1] = 0x0e; /* A+D */ |
136
717f739d6ec1
Added hardware stretching code to scale 640x480 to TV resolution
Sam Lantinga <slouken@libsdl.org>
parents:
70
diff
changeset
|
276 tags[2] = ((screen_image.y + screen_image.h) * screen_image.w) / 64 + |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
277 ((unsigned long long)fbw << 14) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
278 ((unsigned long long)psm << 20) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
279 ((unsigned long long)power_of_2(width) << 26) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
280 ((unsigned long long)power_of_2(height) << 30) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
281 ((unsigned long long)1 << 34) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
282 ((unsigned long long)1 << 35); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
283 tags[3] = PS2_GS_TEX0_1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
284 tags[4] = (1 << 5) + (1 << 6); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
285 tags[5] = PS2_GS_TEX1_1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
286 tags[6] = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
287 tags[7] = PS2_GS_TEXFLUSH; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
288 ioctl(console_fd, PS2IOC_SEND, &tex_packet); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
289 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
290 /* Set up the tags for scaling the image */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
291 packet[pnum].ptr = tags; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
292 packet[pnum].len = 12 * sizeof(*tags); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
293 ++pnum; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
294 tags[0] = 5 | (1LL << 60); /* GIFtag */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
295 tags[1] = 0x0e; /* A+D */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
296 tags[2] = 6 + (1 << 4) + (1 << 8); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
297 tags[3] = PS2_GS_PRIM; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
298 tags[4] = ((unsigned long long)0 * 16) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
299 (((unsigned long long)0 * 16) << 16); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
300 tags[5] = PS2_GS_UV; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
301 tags[6] = 0; /* X1, Y1 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
302 tags[7] = PS2_GS_XYZ2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
303 hwdata->stretch_x1y1 = &tags[6]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
304 tags[8] = ((unsigned long long)overlay->w * 16) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
305 (((unsigned long long)overlay->h * 16) << 16); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
306 tags[9] = PS2_GS_UV; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
307 tags[10] = 0; /* X2, Y2 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
308 tags[11] = PS2_GS_XYZ2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
309 hwdata->stretch_x2y2 = &tags[10]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
310 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
311 /* We're all done.. */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
312 return(overlay); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
313 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
314 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
315 int GS_LockYUVOverlay(_THIS, SDL_Overlay *overlay) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
316 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
317 return(0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
318 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
319 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
320 void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
321 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
322 return; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
323 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
324 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
325 int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
326 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
327 struct private_yuvhwdata *hwdata; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
328 __u32 cmd; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
329 struct ps2_packet packet; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
330 int h, w, i; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
331 Uint32 *lum, *Cr, *Cb; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
332 int lum_pitch; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
333 int crb_pitch; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
334 Uint32 *lum_src, *Cr_src, *Cb_src; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
335 Uint32 *src, *dst; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
336 unsigned int x, y; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
337 SDL_Surface *screen; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
338 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
339 /* Find out where the various portions of the image are */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
340 hwdata = overlay->hwdata; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
341 switch (overlay->format) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
342 case SDL_YV12_OVERLAY: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
343 lum = (Uint32 *)overlay->pixels[0]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
344 Cr = (Uint32 *)overlay->pixels[1]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
345 Cb = (Uint32 *)overlay->pixels[2]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
346 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
347 case SDL_IYUV_OVERLAY: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
348 lum = (Uint32 *)overlay->pixels[0]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
349 Cr = (Uint32 *)overlay->pixels[2]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
350 Cb = (Uint32 *)overlay->pixels[1]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
351 default: |
543
522e5202014d
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
352 SDL_SetError("Unsupported YUV format in blit (?)"); |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
353 return(-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
354 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
355 dst = (Uint32 *)hwdata->ipu_imem; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
356 lum_pitch = overlay->w/4; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
357 crb_pitch = (overlay->w/2)/4; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
358 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
359 /* Copy blocks of 16x16 pixels to the DMA area */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
360 for ( h=overlay->h/16; h; --h ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
361 lum_src = lum; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
362 Cr_src = Cr; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
363 Cb_src = Cb; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
364 for ( w=overlay->w/16; w; --w ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
365 src = lum_src; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
366 for ( i=0; i<16; ++i ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
367 dst[0] = src[0]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
368 dst[1] = src[1]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
369 dst[2] = src[2]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
370 dst[3] = src[3]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
371 src += lum_pitch; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
372 dst += 4; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
373 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
374 src = Cb_src; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
375 for ( i=0; i<8; ++i ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
376 dst[0] = src[0]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
377 dst[1] = src[1]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
378 src += crb_pitch; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
379 dst += 2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
380 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
381 src = Cr_src; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
382 for ( i=0; i<8; ++i ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
383 dst[0] = src[0]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
384 dst[1] = src[1]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
385 src += crb_pitch; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
386 dst += 2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
387 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
388 lum_src += 16 / 4; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
389 Cb_src += 8 / 4; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
390 Cr_src += 8 / 4; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
391 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
392 lum += lum_pitch * 16; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
393 Cr += crb_pitch * 8; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
394 Cb += crb_pitch * 8; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
395 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
396 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
397 /* Send the macroblock data to the IPU */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
398 #ifdef DEBUG_YUV |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
399 fprintf(stderr, "Sending data to IPU..\n"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
400 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
401 packet.ptr = hwdata->ipu_imem; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
402 packet.len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
403 ioctl(hwdata->ipu_fd, PS2IOC_SENDA, &packet); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
404 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
405 /* Trigger the DMA to the IPU for conversion */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
406 #ifdef DEBUG_YUV |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
407 fprintf(stderr, "Trigging conversion command\n"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
408 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
409 cmd = (7 << 28) + hwdata->macroblocks; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
410 if ( screen_image.psm == PS2_GS_PSMCT16 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
411 cmd += (1 << 27) + /* Output RGB 555 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
412 (1 << 26); /* Dither output */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
413 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
414 ioctl(hwdata->ipu_fd, PS2IOC_SIPUCMD, &cmd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
415 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
416 /* Retrieve the converted image from the IPU */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
417 #ifdef DEBUG_YUV |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
418 fprintf(stderr, "Retrieving data from IPU..\n"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
419 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
420 packet.ptr = hwdata->ipu_omem; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
421 packet.len = overlay->w * overlay->h * |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
422 this->screen->format->BytesPerPixel; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
423 ioctl(hwdata->ipu_fd, PS2IOC_RECV, &packet); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
424 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
425 #ifdef DEBUG_YUV |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
426 fprintf(stderr, "Copying image to screen..\n"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
427 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
428 /* Wait for previous DMA to complete */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
429 ioctl(console_fd, PS2IOC_SENDQCT, 1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
430 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
431 /* Send the current image to the screen and scale it */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
432 screen = this->screen; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
433 x = (unsigned int)dstrect->x; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
434 y = (unsigned int)dstrect->y; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
435 if ( screen->offset ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
436 x += (screen->offset % screen->pitch) / |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
437 screen->format->BytesPerPixel; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
438 y += (screen->offset / screen->pitch); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
439 } |
136
717f739d6ec1
Added hardware stretching code to scale 640x480 to TV resolution
Sam Lantinga <slouken@libsdl.org>
parents:
70
diff
changeset
|
440 y += screen_image.y; |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
441 *hwdata->stretch_x1y1 = (x * 16) + ((y * 16) << 16); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
442 x += (unsigned int)dstrect->w; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
443 y += (unsigned int)dstrect->h; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
444 *hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
445 return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
446 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
447 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
448 void GS_FreeYUVOverlay(_THIS, SDL_Overlay *overlay) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
449 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
450 struct private_yuvhwdata *hwdata; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
451 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
452 hwdata = overlay->hwdata; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
453 if ( hwdata ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
454 if ( hwdata->ipu_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
455 close(hwdata->ipu_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
456 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
457 if ( hwdata->dma_mem ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
458 munmap(hwdata->dma_mem, hwdata->dma_len); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
459 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
460 if ( hwdata->plist.packet ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
461 free(hwdata->plist.packet); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
462 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
463 if ( hwdata->pixels ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
464 free(hwdata->pixels); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
465 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
466 free(hwdata); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
467 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
468 } |