annotate src/video/ps2gs/SDL_gsyuv.c @ 1389:ce65f014190a

Fixed X11 library detection Allow passing CFLAGS for the build in the environment
author Sam Lantinga <slouken@libsdl.org>
date Mon, 20 Feb 2006 11:30:29 +0000
parents 19418e4422cb
children d910939febfa
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
70
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
6 modify it under the terms of the GNU Lesser General Public
70
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
70
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
13 Lesser General Public License for more details.
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
70
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 /* 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
24
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 #include <fcntl.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <unistd.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include <sys/ioctl.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <sys/mman.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #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
30
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include "SDL_video.h"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include "SDL_gsyuv_c.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
33 #include "../SDL_yuvfuncs.h"
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 /* 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
36 #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
37
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 /* The functions used to manipulate video overlays */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 static struct private_yuvhwfuncs gs_yuvfuncs = {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 GS_LockYUVOverlay,
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 GS_UnlockYUVOverlay,
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 GS_DisplayYUVOverlay,
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 GS_FreeYUVOverlay
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 };
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 struct private_yuvhwdata {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 int ipu_fd;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 Uint8 *pixels;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 int macroblocks;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 int dma_len;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 caddr_t dma_mem;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 caddr_t ipu_imem;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 caddr_t ipu_omem;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 caddr_t dma_tags;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 unsigned long long *stretch_x1y1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 unsigned long long *stretch_x2y2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 struct ps2_plist plist;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 /* 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
60 Uint16 pitches[3];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 Uint8 *planes[3];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 };
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 static int power_of_2(int value)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 int shift;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 for ( shift = 0; (1<<shift) < value; ++shift ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 /* Keep looking */ ;
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 return(shift);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 }
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 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
75 {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 SDL_Overlay *overlay;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 struct private_yuvhwdata *hwdata;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 int map_offset;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 unsigned long long *tags;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 caddr_t base;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 int bpp;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 int fbp, fbw, psm;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 int x, y, w, h;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 int pnum;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 struct ps2_packet *packet;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 struct ps2_packet tex_packet;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 /* We can only decode blocks of 16x16 pixels */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 if ( (width & 15) || (height & 15) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 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
91 return(NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 /* 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
94 if ( ((width/16) * (height/16)) > MAX_MACROBLOCKS ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 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
96 MAX_MACROBLOCKS * 16 * 16);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 return(NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 /* 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
101 support planar YUV formats.
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103 switch (format) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 case SDL_YV12_OVERLAY:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 case SDL_IYUV_OVERLAY:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 /* Supported planar YUV format */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
108 default:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109 SDL_SetError("Unsupported YUV format");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 return(NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 /* Create the overlay structure */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
114 overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 if ( overlay == NULL ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 SDL_OutOfMemory();
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 return(NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
119 SDL_memset(overlay, 0, (sizeof *overlay));
70
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 /* Fill in the basic members */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 overlay->format = format;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 overlay->w = width;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 overlay->h = height;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126 /* Set up the YUV surface function structure */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 overlay->hwfuncs = &gs_yuvfuncs;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 overlay->hw_overlay = 1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 /* Create the pixel data */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
131 hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 overlay->hwdata = hwdata;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 if ( hwdata == NULL ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134 SDL_FreeYUVOverlay(overlay);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 SDL_OutOfMemory();
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 return(NULL);
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 hwdata->ipu_fd = -1;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
139 hwdata->pixels = (Uint8 *)SDL_malloc(width*height*2);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 if ( hwdata->pixels == NULL ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141 SDL_FreeYUVOverlay(overlay);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
142 SDL_OutOfMemory();
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 return(NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 hwdata->macroblocks = (width/16) * (height/16);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 /* 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
148 overlay->pitches = hwdata->pitches;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 overlay->pixels = hwdata->planes;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 switch (format) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 case SDL_YV12_OVERLAY:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 case SDL_IYUV_OVERLAY:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153 overlay->pitches[0] = overlay->w;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 overlay->pitches[1] = overlay->pitches[0] / 2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 overlay->pitches[2] = overlay->pitches[0] / 2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 overlay->pixels[0] = hwdata->pixels;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 overlay->pixels[1] = overlay->pixels[0] +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 overlay->pitches[0] * overlay->h;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 overlay->pixels[2] = overlay->pixels[1] +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 overlay->pitches[1] * overlay->h / 2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 overlay->planes = 3;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 default:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 /* We should never get here (caught above) */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168 /* Theoretically we could support several concurrent decode
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 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
170 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
171 than once will fail with EBUSY.
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 hwdata->ipu_fd = open("/dev/ps2ipu", O_RDWR);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 if ( hwdata->ipu_fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175 SDL_FreeYUVOverlay(overlay);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 SDL_SetError("Playstation 2 IPU busy");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 return(NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 /* Allocate a DMA area for pixel conversion */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 bpp = this->screen->format->BytesPerPixel;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182 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
183 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
184 width * height * bpp +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 hwdata->macroblocks * (16 * sizeof(long long)) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 12 * sizeof(long long);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 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
188 MAP_SHARED, memory_fd, map_offset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 if ( hwdata->dma_mem == MAP_FAILED ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 hwdata->ipu_imem = (caddr_t)0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 SDL_FreeYUVOverlay(overlay);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 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
193 return(NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 hwdata->ipu_imem = hwdata->dma_mem;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 hwdata->ipu_omem = hwdata->ipu_imem +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 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
199
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 /* Allocate memory for the DMA packets */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201 hwdata->plist.num = hwdata->macroblocks * 4 + 1;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
202 hwdata->plist.packet = (struct ps2_packet *)SDL_malloc(
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 hwdata->plist.num*sizeof(struct ps2_packet));
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 if ( ! hwdata->plist.packet ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 SDL_FreeYUVOverlay(overlay);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 SDL_OutOfMemory();
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 return(NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 pnum = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210 packet = hwdata->plist.packet;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 /* 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
213 tags = (unsigned long long *)hwdata->dma_tags;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 base = hwdata->ipu_omem;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 fbp = screen_image.fbp;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 fbw = screen_image.fbw;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 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
218 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
219 for ( h=height/16; h; --h ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 x = 0; /* Visible video memory */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 for ( w=width/16; w; --w ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 /* The head tag */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 packet[pnum].ptr = &tags[0];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 packet[pnum].len = 10 * sizeof(*tags);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 ++pnum;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 tags[0] = 4 | (1LL << 60); /* GIFtag */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 tags[1] = 0x0e; /* A+D */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 tags[2] = ((unsigned long long)fbp << 32) |
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 ((unsigned long long)fbw << 48) |
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 ((unsigned long long)psm << 56);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 tags[3] = PS2_GS_BITBLTBUF;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 tags[4] = ((unsigned long long)x << 32) |
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 ((unsigned long long)y << 48);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 tags[5] = PS2_GS_TRXPOS;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 tags[6] = (unsigned long long)16 |
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 ((unsigned long long)16 << 32);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 tags[7] = PS2_GS_TRXREG;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 tags[8] = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 tags[9] = PS2_GS_TRXDIR;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 /* Now the actual image data */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 packet[pnum].ptr = &tags[10];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 packet[pnum].len = 2 * sizeof(*tags);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 ++pnum;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 tags[10] = ((16*16*bpp) >> 4) | (2LL << 58);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 tags[11] = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 packet[pnum].ptr = (void *)base;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 packet[pnum].len = 16 * 16 * bpp;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 ++pnum;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 packet[pnum].ptr = &tags[12];
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[12] = (0 >> 4) | (1 << 15) | (2LL << 58);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 tags[13] = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255 tags += 16;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256 base += 16 * 16 * bpp;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
258 x += 16;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260 y += 16;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261 }
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 /* 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
264 tex_packet.ptr = tags;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 tex_packet.len = 8 * sizeof(*tags);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 tags[0] = 3 | (1LL << 60); /* GIFtag */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 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
268 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
269 ((unsigned long long)fbw << 14) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270 ((unsigned long long)psm << 20) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
271 ((unsigned long long)power_of_2(width) << 26) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 ((unsigned long long)power_of_2(height) << 30) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 ((unsigned long long)1 << 34) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 ((unsigned long long)1 << 35);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275 tags[3] = PS2_GS_TEX0_1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 tags[4] = (1 << 5) + (1 << 6);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 tags[5] = PS2_GS_TEX1_1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 tags[6] = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 tags[7] = PS2_GS_TEXFLUSH;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 ioctl(console_fd, PS2IOC_SEND, &tex_packet);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282 /* Set up the tags for scaling the image */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 packet[pnum].ptr = tags;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 packet[pnum].len = 12 * sizeof(*tags);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 ++pnum;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 tags[0] = 5 | (1LL << 60); /* GIFtag */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287 tags[1] = 0x0e; /* A+D */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
288 tags[2] = 6 + (1 << 4) + (1 << 8);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
289 tags[3] = PS2_GS_PRIM;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 tags[4] = ((unsigned long long)0 * 16) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
291 (((unsigned long long)0 * 16) << 16);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292 tags[5] = PS2_GS_UV;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293 tags[6] = 0; /* X1, Y1 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294 tags[7] = PS2_GS_XYZ2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
295 hwdata->stretch_x1y1 = &tags[6];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296 tags[8] = ((unsigned long long)overlay->w * 16) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 (((unsigned long long)overlay->h * 16) << 16);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 tags[9] = PS2_GS_UV;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 tags[10] = 0; /* X2, Y2 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 tags[11] = PS2_GS_XYZ2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301 hwdata->stretch_x2y2 = &tags[10];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303 /* We're all done.. */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 return(overlay);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 int GS_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 return(0);
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
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *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 return;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 }
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 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
318 {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 struct private_yuvhwdata *hwdata;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 __u32 cmd;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 struct ps2_packet packet;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 int h, w, i;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 Uint32 *lum, *Cr, *Cb;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 int lum_pitch;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 int crb_pitch;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 Uint32 *lum_src, *Cr_src, *Cb_src;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 Uint32 *src, *dst;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 unsigned int x, y;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 SDL_Surface *screen;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 /* 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
332 hwdata = overlay->hwdata;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 switch (overlay->format) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 case SDL_YV12_OVERLAY:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 lum = (Uint32 *)overlay->pixels[0];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 Cr = (Uint32 *)overlay->pixels[1];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 Cb = (Uint32 *)overlay->pixels[2];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 case SDL_IYUV_OVERLAY:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 lum = (Uint32 *)overlay->pixels[0];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 Cr = (Uint32 *)overlay->pixels[2];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 Cb = (Uint32 *)overlay->pixels[1];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 default:
543
522e5202014d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
344 SDL_SetError("Unsupported YUV format in blit (?)");
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 return(-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 dst = (Uint32 *)hwdata->ipu_imem;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 lum_pitch = overlay->w/4;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349 crb_pitch = (overlay->w/2)/4;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351 /* 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
352 for ( h=overlay->h/16; h; --h ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 lum_src = lum;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 Cr_src = Cr;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 Cb_src = Cb;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 for ( w=overlay->w/16; w; --w ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 src = lum_src;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 for ( i=0; i<16; ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 dst[0] = src[0];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 dst[1] = src[1];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 dst[2] = src[2];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 dst[3] = src[3];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363 src += lum_pitch;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
364 dst += 4;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 src = Cb_src;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 for ( i=0; i<8; ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368 dst[0] = src[0];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 dst[1] = src[1];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
370 src += crb_pitch;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 dst += 2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
372 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373 src = Cr_src;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
374 for ( i=0; i<8; ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 dst[0] = src[0];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376 dst[1] = src[1];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 src += crb_pitch;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378 dst += 2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 lum_src += 16 / 4;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 Cb_src += 8 / 4;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 Cr_src += 8 / 4;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 lum += lum_pitch * 16;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385 Cr += crb_pitch * 8;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 Cb += crb_pitch * 8;
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
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 /* Send the macroblock data to the IPU */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 #ifdef DEBUG_YUV
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 fprintf(stderr, "Sending data to IPU..\n");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 #endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 packet.ptr = hwdata->ipu_imem;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 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
395 ioctl(hwdata->ipu_fd, PS2IOC_SENDA, &packet);
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 /* Trigger the DMA to the IPU for conversion */
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, "Trigging conversion command\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 cmd = (7 << 28) + hwdata->macroblocks;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 if ( screen_image.psm == PS2_GS_PSMCT16 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 cmd += (1 << 27) + /* Output RGB 555 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 (1 << 26); /* Dither output */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 ioctl(hwdata->ipu_fd, PS2IOC_SIPUCMD, &cmd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 /* Retrieve the converted image from the IPU */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 #ifdef DEBUG_YUV
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410 fprintf(stderr, "Retrieving data from IPU..\n");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 #endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 packet.ptr = hwdata->ipu_omem;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413 packet.len = overlay->w * overlay->h *
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414 this->screen->format->BytesPerPixel;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 ioctl(hwdata->ipu_fd, PS2IOC_RECV, &packet);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
416
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, "Copying image to screen..\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 /* Wait for previous DMA to complete */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421 ioctl(console_fd, PS2IOC_SENDQCT, 1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
423 /* 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
424 screen = this->screen;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425 x = (unsigned int)dstrect->x;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
426 y = (unsigned int)dstrect->y;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
427 if ( screen->offset ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
428 x += (screen->offset % screen->pitch) /
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
429 screen->format->BytesPerPixel;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
430 y += (screen->offset / screen->pitch);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
431 }
136
717f739d6ec1 Added hardware stretching code to scale 640x480 to TV resolution
Sam Lantinga <slouken@libsdl.org>
parents: 70
diff changeset
432 y += screen_image.y;
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
433 *hwdata->stretch_x1y1 = (x * 16) + ((y * 16) << 16);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
434 x += (unsigned int)dstrect->w;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
435 y += (unsigned int)dstrect->h;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
436 *hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
437 return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
438 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
440 void GS_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
441 {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
442 struct private_yuvhwdata *hwdata;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
443
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
444 hwdata = overlay->hwdata;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445 if ( hwdata ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 if ( hwdata->ipu_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
447 close(hwdata->ipu_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
448 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
449 if ( hwdata->dma_mem ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 munmap(hwdata->dma_mem, hwdata->dma_len);
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 if ( hwdata->plist.packet ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
453 SDL_free(hwdata->plist.packet);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
454 }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
455 if ( hwdata->pixels ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
456 SDL_free(hwdata->pixels);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
457 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
458 SDL_free(hwdata);
70
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 }