Mercurial > mplayer.hg
annotate vidix/drivers/nvidia_vid.c @ 11169:9a100ec9135f
gamma weight patch by (Alexander Stege <mplayer at legale-software dot com>)
author | michael |
---|---|
date | Sat, 18 Oct 2003 23:02:30 +0000 |
parents | e1c3f72da3d1 |
children | 60288914167b |
rev | line source |
---|---|
10954 | 1 /* |
2 nvidia_vid - VIDIX based video driver for NVIDIA chips | |
3 Copyrights 2003 Sascha Sommer. This file is based on sources from | |
4 RIVATV (rivatv.sf.net) | |
5 Licence: GPL | |
11159 | 6 WARNING: THIS DRIVER IS IN BETA STAGE |
10954 | 7 |
11086 | 8 multi buffer support and TNT2 fixes by Dmitry Baryshkov |
10954 | 9 */ |
10 | |
11 | |
12 #include <errno.h> | |
13 #include <stdio.h> | |
14 #include <stdlib.h> | |
15 #include <string.h> | |
16 #include <inttypes.h> | |
17 #include <unistd.h> | |
18 | |
19 | |
20 #include "../vidix.h" | |
21 #include "../fourcc.h" | |
22 #include "../../libdha/libdha.h" | |
23 #include "../../libdha/pci_ids.h" | |
24 #include "../../libdha/pci_names.h" | |
25 #include "../../config.h" | |
26 #include "../../bswap.h" | |
27 | |
28 | |
29 pciinfo_t pci_info; | |
30 | |
31 | |
32 #define MAX_FRAMES 3 | |
33 #define NV04_BES_SIZE 1024*2000*4 | |
34 | |
35 | |
36 static vidix_capability_t nvidia_cap = { | |
37 "NVIDIA RIVA OVERLAY DRIVER", | |
38 "Sascha Sommer <saschasommer@freenet.de>", | |
39 TYPE_OUTPUT, | |
40 { 0, 0, 0, 0 }, | |
10957
4d4d0c1c7142
according to xfree cvs maximum overlay size is only 2046x2046
atmos4
parents:
10954
diff
changeset
|
41 2046, |
4d4d0c1c7142
according to xfree cvs maximum overlay size is only 2046x2046
atmos4
parents:
10954
diff
changeset
|
42 2046, |
10954 | 43 4, |
44 4, | |
45 -1, | |
46 FLAG_UPSCALER|FLAG_DOWNSCALER, | |
47 VENDOR_NVIDIA2, | |
48 -1, | |
49 { 0, 0, 0, 0 } | |
50 }; | |
51 | |
52 | |
53 unsigned int vixGetVersion(void){ | |
54 return(VIDIX_VERSION); | |
55 } | |
56 | |
57 | |
58 #define NV_ARCH_03 0x03 | |
59 #define NV_ARCH_04 0x04 | |
60 #define NV_ARCH_10 0x10 | |
61 #define NV_ARCH_20 0x20 | |
62 #define NV_ARCH_30 0x30 | |
63 | |
64 struct nvidia_cards { | |
65 unsigned short chip_id; | |
66 unsigned short arch; | |
67 }; | |
68 | |
69 | |
70 static struct nvidia_cards nvidia_card_ids[] = { | |
11073 | 71 /*NV03*/ |
10954 | 72 {DEVICE_NVIDIA2_RIVA128, NV_ARCH_03}, |
11073 | 73 {DEVICE_NVIDIA2_RIVA128ZX,NV_ARCH_03}, |
74 /*NV04*/ | |
75 {DEVICE_NVIDIA_NV4_RIVA_TNT,NV_ARCH_04}, | |
76 {DEVICE_NVIDIA_NV5_RIVA_TNT2,NV_ARCH_04}, | |
77 {DEVICE_NVIDIA_NV5_RIVA_TNT22,NV_ARCH_04}, | |
78 {DEVICE_NVIDIA_NV5_RIVA_TNT23,NV_ARCH_04}, | |
79 {DEVICE_NVIDIA_NV5_RIVA_TNT24,NV_ARCH_04}, | |
80 {DEVICE_NVIDIA_NV6_VANTA,NV_ARCH_04}, | |
10954 | 81 {DEVICE_NVIDIA_RIVA_TNT2_MODEL,NV_ARCH_04}, |
11073 | 82 {DEVICE_NVIDIA_NV6_VANTA2,NV_ARCH_04}, |
83 {DEVICE_NVIDIA_NV6_VANTA3,NV_ARCH_04}, | |
84 {DEVICE_NVIDIA_NV5_RIVA_TNT25,NV_ARCH_04}, | |
10954 | 85 {DEVICE_NVIDIA2_TNT,NV_ARCH_04}, |
11073 | 86 {DEVICE_NVIDIA2_TNT2,NV_ARCH_04}, |
87 {DEVICE_NVIDIA2_VTNT2,NV_ARCH_04}, | |
10954 | 88 {DEVICE_NVIDIA2_UTNT2 ,NV_ARCH_04}, |
89 {DEVICE_NVIDIA2_ITNT2,NV_ARCH_04}, | |
11073 | 90 /*NV10*/ |
91 {DEVICE_NVIDIA_NV10_GEFORCE_256,NV_ARCH_10}, | |
92 {DEVICE_NVIDIA_NV10_GEFORCE_2562,NV_ARCH_10}, | |
93 {DEVICE_NVIDIA_NV11_GEFORCE2_MX,NV_ARCH_10}, | |
94 {DEVICE_NVIDIA_NV11_GEFORCE2_MX2,NV_ARCH_10}, | |
95 {DEVICE_NVIDIA_NV11_GEFORCE2_GO,NV_ARCH_10}, | |
96 {DEVICE_NVIDIA_NV11_GEFORCE2_MXR ,NV_ARCH_10}, | |
97 {DEVICE_NVIDIA_NV15_GEFORCE2_GTS,NV_ARCH_10}, | |
98 {DEVICE_NVIDIA_NV15_GEFORCE2_TI,NV_ARCH_10}, | |
99 {DEVICE_NVIDIA_NV15_GEFORCE2_ULTRA,NV_ARCH_10}, | |
100 {DEVICE_NVIDIA_NV17_GEFORCE4_MX460,NV_ARCH_10}, | |
101 {DEVICE_NVIDIA_NV17_GEFORCE4_MX440,NV_ARCH_10}, | |
102 {DEVICE_NVIDIA_NV17_GEFORCE4_MX420,NV_ARCH_10}, | |
103 {DEVICE_NVIDIA_NV17_GEFORCE4_440,NV_ARCH_10}, | |
104 {DEVICE_NVIDIA_NV17_GEFORCE4_420,NV_ARCH_10}, | |
105 {DEVICE_NVIDIA_NV17_GEFORCE4_4202,NV_ARCH_10}, | |
106 {DEVICE_NVIDIA_NV17_GEFORCE4_4402,NV_ARCH_10}, | |
107 {DEVICE_NVIDIA_NV18_GEFORCE4_MX440,NV_ARCH_10}, | |
108 {DEVICE_NVIDIA_NV15_GEFORCE2,NV_ARCH_10}, | |
109 /*NV20*/ | |
110 {DEVICE_NVIDIA_NV20_GEFORCE3,NV_ARCH_20}, | |
111 {DEVICE_NVIDIA_NV20_GEFORCE3_TI200,NV_ARCH_20}, | |
112 {DEVICE_NVIDIA_NV20_GEFORCE3_TI500,NV_ARCH_20}, | |
113 {DEVICE_NVIDIA_NV25_GEFORCE4_TI4600,NV_ARCH_20}, | |
114 {DEVICE_NVIDIA_NV25_GEFORCE4_TI4400,NV_ARCH_20}, | |
115 {DEVICE_NVIDIA_NV25_GEFORCE4_TI4200,NV_ARCH_20}, | |
10954 | 116 }; |
117 | |
118 | |
119 static int find_chip(unsigned chip_id){ | |
120 unsigned i; | |
121 for(i = 0;i < sizeof(nvidia_card_ids)/sizeof(struct nvidia_cards);i++) | |
122 { | |
123 if(chip_id == nvidia_card_ids[i].chip_id)return i; | |
124 } | |
125 return -1; | |
126 } | |
127 | |
128 int vixProbe(int verbose, int force){ | |
129 pciinfo_t lst[MAX_PCI_DEVICES]; | |
130 unsigned i,num_pci; | |
131 int err; | |
132 | |
133 if (force) | |
134 printf("[nvidia_vid]: warning: forcing not supported yet!\n"); | |
135 err = pci_scan(lst,&num_pci); | |
136 if(err){ | |
137 printf("[nvidia_vid] Error occured during pci scan: %s\n",strerror(err)); | |
138 return err; | |
139 } | |
140 else { | |
141 err = ENXIO; | |
142 for(i=0; i < num_pci; i++){ | |
143 if(lst[i].vendor == VENDOR_NVIDIA2 || lst[i].vendor == VENDOR_NVIDIA){ | |
144 int idx; | |
145 const char *dname; | |
146 idx = find_chip(lst[i].device); | |
147 if(idx == -1) | |
148 continue; | |
149 dname = pci_device_name(lst[i].vendor, lst[i].device); | |
150 dname = dname ? dname : "Unknown chip"; | |
151 printf("[nvidia_vid] Found chip: %s\n", dname); | |
152 if ((lst[i].command & PCI_COMMAND_IO) == 0){ | |
153 printf("[nvidia_vid] Device is disabled, ignoring\n"); | |
154 continue; | |
155 } | |
156 nvidia_cap.device_id = lst[i].device; | |
157 err = 0; | |
158 memcpy(&pci_info, &lst[i], sizeof(pciinfo_t)); | |
159 break; | |
160 } | |
161 } | |
162 } | |
163 if(err && verbose) printf("[nvidia_vid] Can't find chip\n"); | |
164 return err; | |
165 } | |
166 | |
167 | |
168 | |
169 | |
170 /* | |
171 * PCI-Memory IO access macros. | |
172 */ | |
173 #define VID_WR08(p,i,val) (((uint8_t *)(p))[(i)]=(val)) | |
174 #define VID_RD08(p,i) (((uint8_t *)(p))[(i)]) | |
175 | |
176 #define VID_WR32(p,i,val) (((uint32_t *)(p))[(i)/4]=(val)) | |
177 #define VID_RD32(p,i) (((uint32_t *)(p))[(i)/4]) | |
178 | |
179 #ifndef USE_RMW_CYCLES | |
180 /* | |
181 * Can be used to inhibit READ-MODIFY-WRITE cycles. On by default. | |
182 */ | |
183 | |
184 #define MEM_BARRIER() __asm__ __volatile__ ("" : : : "memory") | |
185 | |
186 #undef VID_WR08 | |
187 #define VID_WR08(p,i,val) ({ MEM_BARRIER(); ((uint8_t *)(p))[(i)]=(val); }) | |
188 #undef VID_RD08 | |
189 #define VID_RD08(p,i) ({ MEM_BARRIER(); ((uint8_t *)(p))[(i)]; }) | |
190 | |
191 #undef VID_WR32 | |
192 #define VID_WR32(p,i,val) ({ MEM_BARRIER(); ((uint32_t *)(p))[(i)/4]=(val); }) | |
193 #undef VID_RD32 | |
194 #define VID_RD32(p,i) ({ MEM_BARRIER(); ((uint32_t *)(p))[(i)/4]; }) | |
195 #endif /* USE_RMW_CYCLES */ | |
196 | |
197 #define VID_AND32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)&(val)) | |
198 #define VID_OR32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)|(val)) | |
199 #define VID_XOR32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)^(val)) | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 struct rivatv_chip { | |
207 volatile uint32_t *PMC; /* general control */ | |
208 volatile uint32_t *PME; /* multimedia port */ | |
209 volatile uint32_t *PFB; /* framebuffer control */ | |
210 volatile uint32_t *PVIDEO; /* overlay control */ | |
211 volatile uint8_t *PCIO; /* SVGA (CRTC, ATTR) registers */ | |
212 volatile uint8_t *PVIO; /* SVGA (MISC, GRAPH, SEQ) registers */ | |
213 volatile uint32_t *PRAMIN; /* instance memory */ | |
214 volatile uint32_t *PRAMHT; /* hash table */ | |
215 volatile uint32_t *PRAMFC; /* fifo context table */ | |
216 volatile uint32_t *PRAMRO; /* fifo runout table */ | |
217 volatile uint32_t *PFIFO; /* fifo control region */ | |
218 volatile uint32_t *FIFO; /* fifo channels (USER) */ | |
219 volatile uint32_t *PGRAPH; /* graphics engine */ | |
220 | |
221 unsigned long fbsize; /* framebuffer size */ | |
222 int arch; /* compatible NV_ARCH_XX define */ | |
223 int realarch; /* real architecture */ | |
224 void (* lock) (struct rivatv_chip *, int); | |
225 }; | |
226 typedef struct rivatv_chip rivatv_chip; | |
227 | |
228 | |
11086 | 229 struct rivatv_info { |
230 unsigned int use_colorkey; | |
10954 | 231 unsigned int colorkey; /* saved xv colorkey*/ |
232 unsigned int vidixcolorkey; /*currently used colorkey*/ | |
233 unsigned int depth; | |
234 unsigned int format; | |
235 unsigned int pitch; | |
236 unsigned int width,height; | |
237 unsigned int d_width,d_height; /*scaled width && height*/ | |
238 unsigned int wx,wy; /*window x && y*/ | |
239 unsigned int screen_x; /*screen width*/ | |
11085 | 240 unsigned int screen_y; /*screen height*/ |
10954 | 241 unsigned long buffer_size; /* size of the image buffer */ |
242 struct rivatv_chip chip; /* NV architecture structure */ | |
243 void* video_base; /* virtual address of control region */ | |
244 void* control_base; /* virtual address of fb region */ | |
245 unsigned long picture_base; /* direct pointer to video picture */ | |
246 unsigned long picture_offset; /* offset of video picture in frame buffer */ | |
247 // struct rivatv_dma dma; /* DMA structure */ | |
248 unsigned int next_frame; | |
249 unsigned int num_frames; /* number of buffers */ | |
250 }; | |
251 typedef struct rivatv_info rivatv_info; | |
252 | |
253 //framebuffer size funcs | |
254 static unsigned long rivatv_fbsize_nv03 (struct rivatv_chip *chip){ | |
255 if (VID_RD32 (chip->PFB, 0) & 0x00000020) { | |
256 if (((VID_RD32 (chip->PMC, 0) & 0xF0) == 0x20) | |
257 && ((VID_RD32 (chip->PMC, 0) & 0x0F) >= 0x02)) { | |
258 /* SDRAM 128 ZX. */ | |
259 return ((1 << (VID_RD32 (chip->PFB, 0) & 0x03)) * 1024 * 1024); | |
260 } | |
261 else { | |
262 return 1024 * 1024 * 8; | |
263 } | |
264 } | |
265 else { | |
266 /* SGRAM 128. */ | |
267 switch (chip->PFB[0x00000000] & 0x00000003) { | |
268 case 0: | |
269 return 1024 * 1024 * 8; | |
270 break; | |
271 case 2: | |
272 return 1024 * 1024 * 4; | |
273 break; | |
274 default: | |
275 return 1024 * 1024 * 2; | |
276 break; | |
277 } | |
278 } | |
279 } | |
280 static unsigned long rivatv_fbsize_nv04 (struct rivatv_chip *chip){ | |
281 if (VID_RD32 (chip->PFB, 0) & 0x00000100) { | |
282 return ((VID_RD32 (chip->PFB, 0) >> 12) & 0x0F) * 1024 * 1024 * 2 | |
283 + 1024 * 1024 * 2; | |
284 } else { | |
285 switch (VID_RD32 (chip->PFB, 0) & 0x00000003) { | |
286 case 0: | |
287 return 1024 * 1024 * 32; | |
288 break; | |
289 case 1: | |
290 return 1024 * 1024 * 4; | |
291 break; | |
292 case 2: | |
293 return 1024 * 1024 * 8; | |
294 break; | |
295 case 3: | |
296 default: | |
297 return 1024 * 1024 * 16; | |
298 break; | |
299 } | |
300 } | |
301 } | |
302 | |
303 static unsigned long rivatv_fbsize_nv10 (struct rivatv_chip *chip){ | |
304 return ((VID_RD32 (chip->PFB, 0x20C) >> 20) & 0x000000FF) * 1024 * 1024; | |
305 } | |
306 | |
307 //lock funcs | |
308 static void rivatv_lock_nv03 (struct rivatv_chip *chip, int LockUnlock){ | |
309 VID_WR08 (chip->PVIO, 0x3C4, 0x06); | |
310 VID_WR08 (chip->PVIO, 0x3C5, LockUnlock ? 0x99 : 0x57); | |
311 } | |
312 | |
313 static void rivatv_lock_nv04 (struct rivatv_chip *chip, int LockUnlock){ | |
314 VID_WR08 (chip->PCIO, 0x3C4, 0x06); | |
315 VID_WR08 (chip->PCIO, 0x3C5, LockUnlock ? 0x99 : 0x57); | |
316 VID_WR08 (chip->PCIO, 0x3D4, 0x1F); | |
317 VID_WR08 (chip->PCIO, 0x3D5, LockUnlock ? 0x99 : 0x57); | |
318 } | |
319 | |
320 | |
321 | |
322 | |
323 /* Enable PFB (Framebuffer), PVIDEO (Overlay unit) and PME (Mediaport) if neccessary. */ | |
324 static void rivatv_enable_PMEDIA (struct rivatv_info *info){ | |
325 uint32_t reg; | |
326 | |
327 /* switch off interrupts once for a while */ | |
328 // VID_WR32 (info->chip.PME, 0x200140, 0x00); | |
329 // VID_WR32 (info->chip.PMC, 0x000140, 0x00); | |
330 | |
331 reg = VID_RD32 (info->chip.PMC, 0x000200); | |
332 | |
333 /* NV3 (0x10100010): NV03_PMC_ENABLE_PMEDIA, NV03_PMC_ENABLE_PFB, NV03_PMC_ENABLE_PVIDEO */ | |
334 | |
335 if ((reg & 0x10100010) != 0x10100010) { | |
336 printf("PVIDEO and PFB disabled, enabling...\n"); | |
337 VID_OR32 (info->chip.PMC, 0x000200, 0x10100010); | |
338 } | |
339 | |
340 /* save the current colorkey */ | |
341 switch (info->chip.arch ) { | |
342 case NV_ARCH_10: | |
343 case NV_ARCH_20: | |
344 case NV_ARCH_30: | |
345 /* NV_PVIDEO_COLOR_KEY */ | |
346 info->colorkey = VID_RD32 (info->chip.PVIDEO, 0xB00); | |
347 break; | |
348 case NV_ARCH_03: | |
349 case NV_ARCH_04: | |
350 /* NV_PVIDEO_KEY */ | |
351 info->colorkey = VID_RD32 (info->chip.PVIDEO, 0x240); | |
352 break; | |
353 } | |
354 | |
355 | |
356 /* re-enable interrupts again */ | |
357 // VID_WR32 (info->chip.PMC, 0x000140, 0x01); | |
358 // VID_WR32 (info->chip.PME, 0x200140, 0x01); | |
359 } | |
360 | |
361 /* Stop overlay video. */ | |
362 void rivatv_overlay_stop (struct rivatv_info *info) { | |
363 switch (info->chip.arch ) { | |
364 case NV_ARCH_10: | |
365 case NV_ARCH_20: | |
366 case NV_ARCH_30: | |
367 /* NV_PVIDEO_COLOR_KEY */ | |
368 /* Xv-Extension-Hack: Restore previously saved value. */ | |
369 VID_WR32 (info->chip.PVIDEO, 0xB00, info->colorkey); | |
370 /* NV_PVIDEO_STOP */ | |
371 VID_OR32 (info->chip.PVIDEO, 0x704, 0x11); | |
372 /* NV_PVIDEO_BUFFER */ | |
373 VID_AND32 (info->chip.PVIDEO, 0x700, ~0x11); | |
374 /* NV_PVIDEO_INTR_EN_BUFFER */ | |
11086 | 375 // VID_AND32 (info->chip.PVIDEO, 0x140, ~0x11); |
10954 | 376 break; |
377 case NV_ARCH_03: | |
378 case NV_ARCH_04: | |
379 /* NV_PVIDEO_KEY */ | |
380 VID_WR32 (info->chip.PVIDEO, 0x240, info->colorkey); | |
381 /* NV_PVIDEO_OVERLAY_VIDEO_OFF */ | |
382 VID_AND32 (info->chip.PVIDEO, 0x244, ~0x01); | |
383 /* NV_PVIDEO_INTR_EN_0_NOTIFY */ | |
11086 | 384 // VID_AND32 (info->chip.PVIDEO, 0x140, ~0x01); |
10954 | 385 /* NV_PVIDEO_OE_STATE */ |
386 VID_WR32 (info->chip.PVIDEO, 0x224, 0); | |
387 /* NV_PVIDEO_SU_STATE */ | |
388 VID_WR32 (info->chip.PVIDEO, 0x228, 0); | |
389 /* NV_PVIDEO_RM_STATE */ | |
390 VID_WR32 (info->chip.PVIDEO, 0x22C, 0); | |
391 break; | |
392 } | |
393 } | |
394 | |
395 /* Get pan offset of the physical screen. */ | |
396 static uint32_t rivatv_overlay_pan (struct rivatv_info *info){ | |
397 uint32_t pan; | |
398 info->chip.lock (&info->chip, 0); | |
399 VID_WR08 (info->chip.PCIO, 0x3D4, 0x0D); | |
400 pan = VID_RD08 (info->chip.PCIO, 0x3D5); | |
401 VID_WR08 (info->chip.PCIO, 0x3D4, 0x0C); | |
402 pan |= VID_RD08 (info->chip.PCIO, 0x3D5) << 8; | |
403 VID_WR08 (info->chip.PCIO, 0x3D4, 0x19); | |
404 pan |= (VID_RD08 (info->chip.PCIO, 0x3D5) & 0x1F) << 16; | |
405 VID_WR08 (info->chip.PCIO, 0x3D4, 0x2D); | |
406 pan |= (VID_RD08 (info->chip.PCIO, 0x3D5) & 0x60) << 16; | |
407 return pan << 2; | |
408 } | |
409 | |
410 /* Compute and set colorkey depending on the colour depth. */ | |
411 static void rivatv_overlay_colorkey (rivatv_info* info, unsigned int chromakey){ | |
412 uint32_t r, g, b, key = 0; | |
11159 | 413 |
10954 | 414 r = (chromakey & 0x00FF0000) >> 16; |
415 g = (chromakey & 0x0000FF00) >> 8; | |
416 b = chromakey & 0x000000FF; | |
417 switch (info->depth) { | |
418 case 15: | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
419 key = ((r >> 3) << 10) | ((g >> 3) << 5) | ((b >> 3)); |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
420 #ifndef WIN32 |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
421 key = key | 0x00008000; |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
422 #endif |
10954 | 423 break; |
11118
344052fdfc4a
Fix colorkey for xvidix, tested on Riva128 4MB X@15/16/24bpp (aka 15/15/32 in nvidia_vid)
atmos4
parents:
11086
diff
changeset
|
424 case 16: // XXX unchecked |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
425 key = ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3)); |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
426 #ifndef WIN32 |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
427 key = key | 0x00008000; |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
428 #endif |
10954 | 429 break; |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
430 case 24: // XXX unchecked, maybe swap order of masking - FIXME Can the card be in 24 bit mode anyway? |
11118
344052fdfc4a
Fix colorkey for xvidix, tested on Riva128 4MB X@15/16/24bpp (aka 15/15/32 in nvidia_vid)
atmos4
parents:
11086
diff
changeset
|
431 key = (chromakey & 0x00FFFFFF) | 0x00800000; |
10954 | 432 break; |
433 case 32: | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
434 key = chromakey; |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
435 #ifndef WIN32 |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
436 key = key | 0x80000000; |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
437 #endif |
10954 | 438 break; |
439 } | |
11118
344052fdfc4a
Fix colorkey for xvidix, tested on Riva128 4MB X@15/16/24bpp (aka 15/15/32 in nvidia_vid)
atmos4
parents:
11086
diff
changeset
|
440 //printf("[nvidia_vid] depth=%d %08X \n", info->depth, chromakey); |
10954 | 441 switch (info->chip.arch) { |
442 case NV_ARCH_10: | |
443 case NV_ARCH_20: | |
444 case NV_ARCH_30: | |
445 VID_WR32 (info->chip.PVIDEO, 0xB00, key); | |
446 break; | |
447 case NV_ARCH_03: | |
448 case NV_ARCH_04: | |
449 VID_WR32 (info->chip.PVIDEO, 0x240, key); | |
450 break; | |
451 } | |
452 } | |
453 | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
454 static void nv_waitidle(struct rivatv_info *info ){ |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
455 while (info->chip.PGRAPH[0x1C0] & 1) {} |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
456 } |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
457 |
11085 | 458 static void nv_getscreenproperties(struct rivatv_info *info){ |
459 uint32_t bpp=0; | |
460 info->chip.lock(&info->chip, 0); | |
461 /*get screen depth*/ | |
462 VID_WR08(info->chip.PCIO, 0x03D4,0x28); | |
463 bpp = VID_RD08(info->chip.PCIO,0x03D5); | |
464 if(bpp==3)bpp=4; | |
465 if((bpp == 2) && (info->chip.PVIDEO[0x00000600/4] & 0x00001000) == 0x0)info->depth=15; | |
466 else info->depth = bpp*8; | |
467 /*get screen width*/ | |
468 VID_WR08(info->chip.PCIO, 0x03D4, 0x1); | |
469 info->screen_x = (1 + VID_RD08(info->chip.PCIO, 0x3D5)) * 8; | |
470 /*get screen height*/ | |
471 /* get first 8 bits in VT_DISPLAY_END*/ | |
472 VID_WR08(info->chip.PCIO, 0x03D4, 0x12); | |
473 info->screen_y = VID_RD08(info->chip.PCIO,0x03D5); | |
474 VID_WR08(info->chip.PCIO,0x03D4,0x07); | |
475 /* get 9th bit in CRTC_OVERFLOW*/ | |
476 info->screen_y |= (VID_RD08(info->chip.PCIO,0x03D5) &0x02)<<7; | |
477 /* and the 10th in CRTC_OVERFLOW*/ | |
478 info->screen_y |=(VID_RD08(info->chip.PCIO,0x03D5) &0x40)<<3; | |
479 ++info->screen_y; | |
480 } | |
481 | |
482 | |
483 | |
10954 | 484 |
485 /* Start overlay video. */ | |
486 void rivatv_overlay_start (struct rivatv_info *info,int bufno){ | |
11085 | 487 uint32_t base, size, offset, xscale, yscale, pan; |
11086 | 488 uint32_t value; |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
489 int x=8, y=8; |
10954 | 490 int lwidth=info->d_width, lheight=info->d_height; |
491 int bps; | |
492 | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
493 size = info->buffer_size; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
494 base = info->picture_offset; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
495 offset = bufno*size; |
10954 | 496 /*update depth & dimensions here because it may change with vo vesa or vo fbdev*/ |
11085 | 497 nv_getscreenproperties(info); |
498 | |
499 if(info->depth){ | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
500 bps = info->screen_x * ((info->depth+1)/8); |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
501 /* get pan offset of the physical screen */ |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
502 pan = rivatv_overlay_pan (info); |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
503 /* adjust window position depending on the pan offset */ |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
504 x = info->wx - (pan % bps) * 8 / info->depth; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
505 y = info->wy - (pan / bps); |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
506 /* adjust negative output window variables */ |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
507 if (x < 0) { |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
508 lwidth = info->d_width + x; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
509 offset += (-x * info->width / info->d_width) << 1; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
510 // offset += (-window->x * port->vld_width / window->width) << 1; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
511 x = 0; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
512 } |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
513 if (y < 0) { |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
514 lheight = info->d_height + y; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
515 offset += (-y * info->height / info->d_height * info->width) << 1; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
516 // offset += (-window->y * port->vld_height / window->height * port->org_width) << 1; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
517 y = 0; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
518 } |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
519 } |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
520 |
10954 | 521 switch (info->chip.arch) { |
522 case NV_ARCH_10: | |
523 case NV_ARCH_20: | |
524 case NV_ARCH_30: | |
525 | |
526 /* NV_PVIDEO_BASE */ | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
527 VID_WR32 (info->chip.PVIDEO, 0x900 + 0, base + offset); |
10954 | 528 //VID_WR32 (info->chip.PVIDEO, 0x900 + 4, base); |
529 /* NV_PVIDEO_LIMIT */ | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
530 VID_WR32 (info->chip.PVIDEO, 0x908 + 0, base + offset + size - 1); |
10954 | 531 //VID_WR32 (info->chip.PVIDEO, 0x908 + 4, base + size - 1); |
532 | |
533 /* extra code for NV20 && NV30 architectures */ | |
534 if (info->chip.arch == NV_ARCH_20 || info->chip.arch == NV_ARCH_30) { | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
535 VID_WR32 (info->chip.PVIDEO, 0x800 + 0, base + offset); |
10954 | 536 //VID_WR32 (info->chip.PVIDEO, 0x800 + 4, base); |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
537 VID_WR32 (info->chip.PVIDEO, 0x808 + 0, base + offset + size - 1); |
10954 | 538 //VID_WR32 (info->chip.PVIDEO, 0x808 + 4, base + size - 1); |
539 } | |
540 | |
541 /* NV_PVIDEO_LUMINANCE */ | |
542 VID_WR32 (info->chip.PVIDEO, 0x910 + 0, 0x00001000); | |
543 //VID_WR32 (info->chip.PVIDEO, 0x910 + 4, 0x00001000); | |
544 /* NV_PVIDEO_CHROMINANCE */ | |
545 VID_WR32 (info->chip.PVIDEO, 0x918 + 0, 0x00001000); | |
546 //VID_WR32 (info->chip.PVIDEO, 0x918 + 4, 0x00001000); | |
547 | |
548 /* NV_PVIDEO_OFFSET */ | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
549 VID_WR32 (info->chip.PVIDEO, 0x920 + 0, 0x0); |
10954 | 550 //VID_WR32 (info->chip.PVIDEO, 0x920 + 4, offset + pitch); |
551 /* NV_PVIDEO_SIZE_IN */ | |
552 VID_WR32 (info->chip.PVIDEO, 0x928 + 0, ((info->height) << 16) | info->width); | |
553 //VID_WR32 (info->chip.PVIDEO, 0x928 + 4, ((port->org_height/2) << 16) | port->org_width); | |
554 /* NV_PVIDEO_POINT_IN */ | |
555 VID_WR32 (info->chip.PVIDEO, 0x930 + 0, 0x00000000); | |
556 //VID_WR32 (info->chip.PVIDEO, 0x930 + 4, 0x00000000); | |
557 /* NV_PVIDEO_DS_DX_RATIO */ | |
558 VID_WR32 (info->chip.PVIDEO, 0x938 + 0, (info->width << 20) / info->d_width); | |
559 //VID_WR32 (info->chip.PVIDEO, 0x938 + 4, (port->org_width << 20) / window->width); | |
560 /* NV_PVIDEO_DT_DY_RATIO */ | |
561 VID_WR32 (info->chip.PVIDEO, 0x940 + 0, ((info->height) << 20) / info->d_height); | |
562 //VID_WR32 (info->chip.PVIDEO, 0x940 + 4, ((port->org_height/2) << 20) / window->height); | |
563 | |
564 /* NV_PVIDEO_POINT_OUT */ | |
565 VID_WR32 (info->chip.PVIDEO, 0x948 + 0, ((y + 0) << 16) | x); | |
566 //VID_WR32 (info->chip.PVIDEO, 0x948 + 4, ((y + 0) << 16) | x); | |
567 /* NV_PVIDEO_SIZE_OUT */ | |
568 VID_WR32 (info->chip.PVIDEO, 0x950 + 0, (lheight << 16) | lwidth); | |
569 //VID_WR32 (info->chip.PVIDEO, 0x950 + 4, (height << 16) | width); | |
570 | |
571 /* NV_PVIDEO_FORMAT */ | |
11086 | 572 value = info->pitch; |
573 if(info->use_colorkey)value |= 1 << 20; | |
574 if(info->format == IMGFMT_YUY2)value |= 1 << 16; | |
575 VID_WR32 (info->chip.PVIDEO, 0x958 + 0, value); | |
576 //VID_WR32 (info->chip.PVIDEO, 0x958 + 4, (pitch << 1) | 0x00100000); | |
10954 | 577 |
578 /* NV_PVIDEO_INTR_EN_BUFFER */ | |
11086 | 579 // VID_OR32 (info->chip.PVIDEO, 0x140, 0x01/*0x11*/); |
10954 | 580 /* NV_PVIDEO_STOP */ |
11086 | 581 VID_WR32 (info->chip.PVIDEO, 0x704,0x0); |
10954 | 582 /* NV_PVIDEO_BUFFER */ |
11086 | 583 VID_WR32 (info->chip.PVIDEO, 0x700, 0x01/*0x11*/); |
10954 | 584 break; |
585 | |
586 case NV_ARCH_03: | |
587 case NV_ARCH_04: | |
588 | |
589 | |
590 /* NV_PVIDEO_OE_STATE */ | |
591 VID_WR32 (info->chip.PVIDEO, 0x224, 0); | |
592 /* NV_PVIDEO_SU_STATE */ | |
593 VID_WR32 (info->chip.PVIDEO, 0x228, 0); | |
594 /* NV_PVIDEO_RM_STATE */ | |
595 VID_WR32 (info->chip.PVIDEO, 0x22C, 0); | |
596 | |
597 /* NV_PVIDEO_BUFF0_START_ADDRESS */ | |
598 VID_WR32 (info->chip.PVIDEO, 0x20C + 0, base + offset + 0); | |
599 VID_WR32 (info->chip.PVIDEO, 0x20C + 4, base + offset + 0); | |
600 /* NV_PVIDEO_BUFF0_PITCH_LENGTH */ | |
601 VID_WR32 (info->chip.PVIDEO, 0x214 + 0, info->pitch); | |
602 VID_WR32 (info->chip.PVIDEO, 0x214 + 4, info->pitch); | |
603 | |
604 /* NV_PVIDEO_WINDOW_START */ | |
605 VID_WR32 (info->chip.PVIDEO, 0x230, (y << 16) | x); | |
606 /* NV_PVIDEO_WINDOW_SIZE */ | |
607 VID_WR32 (info->chip.PVIDEO, 0x234, (lheight << 16) | lwidth); | |
608 /* NV_PVIDEO_STEP_SIZE */ | |
609 yscale = ((info->height - 1) << 11) / (info->d_height - 1); | |
610 xscale = ((info->width - 1) << 11) / (info->d_width - 1); | |
611 VID_WR32 (info->chip.PVIDEO, 0x200, (yscale << 16) | xscale); | |
612 | |
613 /* NV_PVIDEO_RED_CSC_OFFSET */ | |
614 VID_WR32 (info->chip.PVIDEO, 0x280, 0x69); | |
615 /* NV_PVIDEO_GREEN_CSC_OFFSET */ | |
616 VID_WR32 (info->chip.PVIDEO, 0x284, 0x3e); | |
617 /* NV_PVIDEO_BLUE_CSC_OFFSET */ | |
618 VID_WR32 (info->chip.PVIDEO, 0x288, 0x89); | |
619 /* NV_PVIDEO_CSC_ADJUST */ | |
620 VID_WR32 (info->chip.PVIDEO, 0x28C, 0x00000); /* No colour correction! */ | |
621 | |
622 /* NV_PVIDEO_CONTROL_Y (BLUR_ON, LINE_HALF) */ | |
623 VID_WR32 (info->chip.PVIDEO, 0x204, 0x001); | |
624 /* NV_PVIDEO_CONTROL_X (WEIGHT_HEAVY, SHARPENING_ON, SMOOTHING_ON) */ | |
11086 | 625 VID_WR32 (info->chip.PVIDEO, 0x208, 0x111); /*directx overlay 0x110 */ |
10954 | 626 |
627 /* NV_PVIDEO_FIFO_BURST_LENGTH */ | |
628 VID_WR32 (info->chip.PVIDEO, 0x23C, 0x03); | |
629 /* NV_PVIDEO_FIFO_THRES_SIZE */ | |
630 VID_WR32 (info->chip.PVIDEO, 0x238, 0x38); /*windows uses 0x40*/ | |
631 | |
632 /* NV_PVIDEO_BUFF0_OFFSET */ | |
633 VID_WR32 (info->chip.PVIDEO, 0x21C + 0, 0); | |
634 VID_WR32 (info->chip.PVIDEO, 0x21C + 4, 0); | |
635 | |
636 /* NV_PVIDEO_INTR_EN_0_NOTIFY_ENABLED */ | |
637 // VID_OR32 (info->chip.PVIDEO, 0x140, 0x01); | |
11086 | 638 |
10954 | 639 /* NV_PVIDEO_OVERLAY (KEY_ON, VIDEO_ON, FORMAT_CCIR) */ |
11086 | 640 value = 0x1; /*video on*/ |
641 if(info->format==IMGFMT_YUY2)value |= 0x100; | |
642 if(info->use_colorkey)value |=0x10; | |
643 VID_WR32 (info->chip.PVIDEO, 0x244, value); | |
644 | |
10954 | 645 /* NV_PVIDEO_SU_STATE */ |
646 VID_XOR32 (info->chip.PVIDEO, 0x228, 1 << 16); | |
647 break; | |
648 } | |
649 /*set colorkey*/ | |
650 rivatv_overlay_colorkey(info,info->vidixcolorkey); | |
651 | |
652 } | |
653 | |
654 | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
655 |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
656 |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
657 |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
658 |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
659 |
10954 | 660 static rivatv_info* info; |
661 | |
662 | |
663 | |
664 | |
665 int vixInit(void){ | |
666 int mtrr; | |
667 info = (rivatv_info*)calloc(1,sizeof(rivatv_info)); | |
668 info->control_base = map_phys_mem(pci_info.base0, 0x00C00000 + 0x00008000); | |
669 info->chip.arch = nvidia_card_ids[find_chip(pci_info.device)].arch; | |
670 printf("[nvidia_vid] arch %x register base %x\n",info->chip.arch,(unsigned int)info->control_base); | |
671 info->chip.PFIFO = (uint32_t *) (info->control_base + 0x00002000); | |
672 info->chip.FIFO = (uint32_t *) (info->control_base + 0x00800000); | |
673 info->chip.PMC = (uint32_t *) (info->control_base + 0x00000000); | |
674 info->chip.PFB = (uint32_t *) (info->control_base + 0x00100000); | |
675 info->chip.PME = (uint32_t *) (info->control_base + 0x00000000); | |
676 info->chip.PCIO = (uint8_t *) (info->control_base + 0x00601000); | |
677 info->chip.PVIO = (uint8_t *) (info->control_base + 0x000C0000); | |
678 info->chip.PGRAPH = (uint32_t *) (info->control_base + 0x00400000); | |
679 /* setup chip specific functions */ | |
680 switch (info->chip.arch) { | |
681 case NV_ARCH_03: | |
682 info->chip.lock = rivatv_lock_nv03; | |
683 info->chip.fbsize = rivatv_fbsize_nv03 (&info->chip); | |
684 info->chip.PVIDEO = (uint32_t *) (info->control_base + 0x00680000); | |
685 break; | |
686 case NV_ARCH_04: | |
687 info->chip.lock = rivatv_lock_nv04; | |
688 info->chip.fbsize = rivatv_fbsize_nv04 (&info->chip); | |
689 info->chip.PRAMIN = (uint32_t *) (info->control_base + 0x00700000); | |
690 info->chip.PVIDEO = (uint32_t *) (info->control_base + 0x00680000); | |
691 break; | |
692 case NV_ARCH_10: | |
693 case NV_ARCH_20: | |
694 case NV_ARCH_30: | |
695 info->chip.lock = rivatv_lock_nv04; | |
696 info->chip.fbsize = rivatv_fbsize_nv10 (&info->chip); | |
697 info->chip.PRAMIN = (uint32_t *) (info->control_base + 0x00700000); | |
698 info->chip.PVIDEO = (uint32_t *) (info->control_base + 0x00008000); | |
699 break; | |
700 } | |
701 switch (info->chip.arch) { | |
702 case NV_ARCH_03: | |
703 { | |
704 /* This maps framebuffer @6MB, thus 2MB are left for video. */ | |
705 info->video_base = map_phys_mem(pci_info.base1, info->chip.fbsize); | |
706 /* This may trash your screen for resolutions greater than 1024x768, sorry. */ | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
707 info->picture_offset = 1024*768* 4 * ((info->chip.fbsize > 4194304)?2:1); |
10954 | 708 info->picture_base = (uint32_t) info->video_base + info->picture_offset; |
709 info->chip.PRAMIN = (uint32_t *) (info->video_base + 0x00C00000); | |
710 break; | |
711 } | |
712 case NV_ARCH_04: | |
713 case NV_ARCH_10: | |
714 case NV_ARCH_20: | |
715 case NV_ARCH_30: | |
716 { | |
717 info->video_base = map_phys_mem(pci_info.base1, info->chip.fbsize); | |
718 info->picture_offset = info->chip.fbsize - NV04_BES_SIZE; | |
719 // info->picture_base = (unsigned long)map_phys_mem(pci_info.base1+info->picture_offset,NV04_BES_SIZE); | |
720 info->picture_base = (uint32_t) info->video_base + info->picture_offset; | |
721 break; | |
722 } | |
723 } | |
724 | |
725 printf("[nvidia_vid] detected memory size %u MB\n",(uint32_t)(info->chip.fbsize /1024/1024)); | |
726 | |
727 if ((mtrr = mtrr_set_type(pci_info.base1, info->chip.fbsize, MTRR_TYPE_WRCOMB))!= 0) | |
11085 | 728 printf("[nvidia_vid] unable to setup MTRR: %s\n", strerror(mtrr)); |
10954 | 729 else |
11085 | 730 printf("[nvidia_vid] MTRR set up\n"); |
10954 | 731 |
11085 | 732 nv_getscreenproperties(info); |
733 if(!info->depth)printf("[nvidia_vid] text mode: %ux%u\n",info->screen_x,info->screen_y); | |
734 else printf("[nvidia_vid] video mode: %ux%u@%u\n",info->screen_x,info->screen_y, info->depth); | |
735 | |
10954 | 736 |
737 rivatv_enable_PMEDIA(info); | |
738 info->next_frame = 0; | |
11159 | 739 info->use_colorkey = 0; |
10954 | 740 return 0; |
741 } | |
742 | |
743 void vixDestroy(void){ | |
744 unmap_phys_mem(info->control_base ,0x00C00000 + 0x00008000); | |
745 unmap_phys_mem(info->video_base, info->chip.fbsize); | |
746 free(info); | |
747 } | |
748 | |
749 int vixGetCapability(vidix_capability_t *to){ | |
750 memcpy(to, &nvidia_cap, sizeof(vidix_capability_t)); | |
751 return 0; | |
752 } | |
753 | |
754 inline static int is_supported_fourcc(uint32_t fourcc) | |
755 { | |
11086 | 756 if (fourcc == IMGFMT_UYVY || fourcc == IMGFMT_YUY2) |
10954 | 757 return 1; |
758 else | |
759 return 0; | |
760 } | |
761 | |
762 int vixQueryFourcc(vidix_fourcc_t *to){ | |
763 if(is_supported_fourcc(to->fourcc)){ | |
764 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
765 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
766 VID_DEPTH_12BPP| VID_DEPTH_15BPP| | |
767 VID_DEPTH_16BPP| VID_DEPTH_24BPP| | |
768 VID_DEPTH_32BPP; | |
769 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; | |
770 return 0; | |
771 } | |
772 else to->depth = to->flags = 0; | |
773 return ENOSYS; | |
774 } | |
775 | |
776 int vixConfigPlayback(vidix_playback_t *vinfo){ | |
777 uint32_t i; | |
778 printf("called %s\n", __FUNCTION__); | |
779 if (! is_supported_fourcc(vinfo->fourcc)) | |
780 return ENOSYS; | |
781 | |
782 info->width = vinfo->src.w; | |
783 info->height = vinfo->src.h; | |
784 | |
785 info->d_width = vinfo->dest.w; | |
786 info->d_height = vinfo->dest.h; | |
787 info->wx = vinfo->dest.x; | |
788 info->wy = vinfo->dest.y; | |
789 info->format = vinfo->fourcc; | |
790 | |
791 printf("[nvidia_vid] setting up a %dx%d-%dx%d video window (src %dx%d), format 0x%X\n", | |
792 info->d_width, info->d_height, info->wx, info->wy, info->width, info->height, vinfo->fourcc); | |
793 | |
794 | |
795 vinfo->dga_addr=(void*)(info->picture_base); | |
796 | |
797 switch (vinfo->fourcc) | |
798 { | |
799 case IMGFMT_YUY2: | |
800 case IMGFMT_UYVY: | |
801 | |
11086 | 802 vinfo->dest.pitch.y = 16; |
10954 | 803 vinfo->dest.pitch.u = 0; |
804 vinfo->dest.pitch.v = 0; | |
805 | |
806 vinfo->offset.y = 0; | |
807 vinfo->offset.v = 0; | |
808 vinfo->offset.u = 0; | |
809 | |
810 info->pitch = info->width << 1; | |
811 vinfo->frame_size = info->pitch * info->height; | |
812 break; | |
813 case IMGFMT_YV12: | |
814 vinfo->dest.pitch.y = 1; | |
815 vinfo->dest.pitch.u = 1; | |
816 vinfo->dest.pitch.v = 1; | |
817 | |
818 vinfo->offset.y = 0; | |
819 vinfo->offset.v = (info->width) * info->height; | |
820 vinfo->offset.u = vinfo->offset.v * 5 / 4; | |
821 | |
822 info->pitch = info->width + (info->width >> 1); | |
823 vinfo->frame_size = info->pitch * info->height; | |
824 break; | |
825 } | |
826 info->buffer_size = vinfo->frame_size; | |
827 info->num_frames = vinfo->num_frames= (info->chip.fbsize - info->picture_offset)/vinfo->frame_size; | |
828 if(vinfo->num_frames > MAX_FRAMES)vinfo->num_frames = MAX_FRAMES; | |
829 // vinfo->num_frames = 1; | |
830 // printf("[nvidia_vid] Number of frames %i\n",vinfo->num_frames); | |
831 for(i=0;i <vinfo->num_frames;i++)vinfo->offsets[i] = vinfo->frame_size*i; | |
832 return 0; | |
833 } | |
834 | |
835 int vixPlaybackOn(void){ | |
836 rivatv_overlay_start(info,info->next_frame); | |
837 return 0; | |
838 } | |
839 | |
840 int vixPlaybackOff(void){ | |
841 rivatv_overlay_stop(info); | |
842 return 0; | |
843 } | |
844 | |
845 int vixSetGrKeys( const vidix_grkey_t * grkey){ | |
11159 | 846 if (grkey->ckey.op == CKEY_FALSE) |
847 { | |
848 info->use_colorkey = 0; | |
849 printf("[nvidia_vid] colorkeying disabled\n"); | |
850 } | |
11165 | 851 else { |
11159 | 852 info->use_colorkey = 1; |
10954 | 853 info->vidixcolorkey = ((grkey->ckey.red<<16)|(grkey->ckey.green<<8)|grkey->ckey.blue); |
854 printf("[nvidia_vid] set colorkey 0x%x\n",info->vidixcolorkey); | |
11165 | 855 } |
856 rivatv_overlay_start(info,0); | |
10954 | 857 return 0; |
858 } | |
859 | |
860 int vixPlaybackFrameSelect(unsigned int frame){ | |
861 // printf("selecting buffer %d\n", frame); | |
862 rivatv_overlay_start(info, frame); | |
863 if (info->num_frames >= 1) | |
864 info->next_frame = (frame+1)%info->num_frames; | |
865 return 0; | |
866 } |