2869
|
1 /*
|
|
2 * vesa_lvo.c
|
|
3 *
|
|
4 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - Oct 2001
|
|
5 *
|
|
6 * You can redistribute this file under terms and conditions
|
|
7 * of GNU General Public licence v2.
|
|
8 *
|
|
9 * This file contains vo_vesa interface to Linux Video Overlay.
|
|
10 * (Partly based on vo_mga.c from mplayer's package)
|
|
11 */
|
|
12
|
|
13 #include <inttypes.h>
|
|
14 #include <sys/ioctl.h>
|
|
15 #include <unistd.h>
|
|
16 #include <fcntl.h>
|
|
17 #include <sys/mman.h>
|
|
18 #include <stdio.h>
|
|
19 #include <stdlib.h>
|
|
20 #include <string.h>
|
|
21
|
|
22 #include "vesa_lvo.h"
|
|
23 #include "img_format.h"
|
|
24 #include "../drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */
|
|
25 #include "fastmemcpy.h"
|
|
26 #include "../mmx_defs.h"
|
|
27
|
|
28 #define WIDTH_ALIGN 32 /* should be 16 for radeons */
|
|
29 #define NUM_FRAMES 2
|
|
30 static uint8_t *frames[NUM_FRAMES];
|
|
31
|
|
32 static int lvo_handler = -1;
|
|
33 static uint8_t *lvo_mem = NULL;
|
|
34 static uint8_t next_frame;
|
|
35 static mga_vid_config_t mga_vid_config;
|
|
36 static unsigned image_bpp,image_height,image_width;
|
2952
|
37 extern int verbose;
|
2869
|
38
|
|
39 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8)
|
|
40 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) )
|
|
41 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size))
|
|
42
|
|
43 int vlvo_init(const char *drvname,unsigned src_width,unsigned src_height,
|
|
44 unsigned x_org,unsigned y_org,unsigned dst_width,
|
|
45 unsigned dst_height,unsigned format,unsigned dest_bpp)
|
|
46 {
|
|
47 size_t i,awidth;
|
|
48 lvo_handler = open(drvname,O_RDWR);
|
|
49 if(lvo_handler == -1)
|
|
50 {
|
|
51 printf("Couldn't open %s\n",drvname);
|
|
52 return -1;
|
|
53 }
|
|
54 image_width = src_width;
|
|
55 image_height = src_height;
|
|
56 mga_vid_config.version=MGA_VID_VERSION;
|
|
57 mga_vid_config.format=format;
|
|
58 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
|
|
59 switch(format){
|
|
60 case IMGFMT_YV12:
|
|
61 case IMGFMT_I420:
|
|
62 case IMGFMT_IYUV:
|
|
63 image_bpp=16;
|
|
64 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2;
|
|
65 break;
|
|
66 case IMGFMT_YUY2:
|
|
67 case IMGFMT_UYVY:
|
|
68 image_bpp=16;
|
|
69 mga_vid_config.frame_size = awidth*src_height*2;
|
|
70 break;
|
|
71 case IMGFMT_RGB15:
|
|
72 case IMGFMT_BGR15:
|
|
73 case IMGFMT_RGB16:
|
|
74 case IMGFMT_BGR16:
|
|
75 image_bpp=16;
|
|
76 mga_vid_config.frame_size = awidth*src_height*2;
|
|
77 break;
|
|
78 case IMGFMT_RGB24:
|
|
79 case IMGFMT_BGR24:
|
|
80 image_bpp=24;
|
|
81 mga_vid_config.frame_size = awidth*src_height*3;
|
|
82 break;
|
|
83 case IMGFMT_RGB32:
|
|
84 case IMGFMT_BGR32:
|
|
85 image_bpp=32;
|
|
86 mga_vid_config.frame_size = awidth*src_height*4;
|
|
87 break;
|
|
88 default:
|
|
89 printf("vesa_lvo: invalid output format %s(%0X)\n",vo_format_name(format),format);
|
|
90 return -1;
|
|
91 }
|
|
92 mga_vid_config.colkey_on=0;
|
|
93 mga_vid_config.src_width = src_width;
|
|
94 mga_vid_config.src_height= src_height;
|
|
95 mga_vid_config.dest_width = dst_width;
|
|
96 mga_vid_config.dest_height= dst_height;
|
|
97 mga_vid_config.x_org=x_org;
|
|
98 mga_vid_config.y_org=y_org;
|
|
99 mga_vid_config.num_frames=NUM_FRAMES;
|
|
100 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config))
|
|
101 {
|
|
102 perror("Error in mga_vid_config ioctl()");
|
|
103 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n");
|
|
104 return -1;
|
|
105 }
|
|
106 ioctl(lvo_handler,MGA_VID_ON,0);
|
|
107
|
|
108 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0);
|
|
109 for(i=1;i<NUM_FRAMES;i++)
|
|
110 frames[i] = frames[i-1] + mga_vid_config.frame_size;
|
|
111 next_frame = 0;
|
|
112 lvo_mem = frames[next_frame];
|
|
113
|
|
114 /*clear the buffer*/
|
|
115 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames);
|
|
116 return 0;
|
|
117 }
|
|
118
|
|
119 void vlvo_term( void )
|
|
120 {
|
|
121 ioctl( lvo_handler,MGA_VID_OFF,0 );
|
|
122 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames);
|
|
123 if(lvo_handler != -1) close(lvo_handler);
|
|
124 }
|
|
125
|
|
126 uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
|
|
127 {
|
2924
|
128 #if 0
|
|
129 /* original vo_mga stuff */
|
2869
|
130 uint8_t *src;
|
|
131 uint8_t *dest;
|
2924
|
132 uint32_t bespitch,bespitch2,srcpitch;
|
2869
|
133 int i;
|
|
134
|
|
135 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
|
|
136 bespitch2 = bespitch/2;
|
|
137
|
|
138 dest = lvo_mem + bespitch * y + x;
|
|
139 src = image[0];
|
|
140 for(i=0;i<h;i++){
|
|
141 memcpy(dest,src,w);
|
|
142 src+=stride[0];
|
|
143 dest += bespitch;
|
|
144 }
|
|
145
|
|
146 w/=2;h/=2;x/=2;y/=2;
|
|
147
|
|
148 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x;
|
|
149 src = image[1];
|
|
150 for(i=0;i<h;i++){
|
|
151 memcpy(dest,src,w);
|
|
152 src+=stride[1];
|
|
153 dest += bespitch2;
|
|
154 }
|
|
155
|
|
156 dest = lvo_mem + bespitch*mga_vid_config.src_height
|
|
157 + bespitch*mga_vid_config.src_height / 4
|
|
158 + bespitch2 * y + x;
|
|
159 src = image[2];
|
|
160 for(i=0;i<h;i++){
|
|
161 memcpy(dest,src,w);
|
|
162 src+=stride[2];
|
|
163 dest += bespitch2;
|
|
164 }
|
2952
|
165 #elsif 0
|
2924
|
166 /* vo_xv stuff: slightly better for YV12 on radeon_vid */
|
|
167 uint8_t *src;
|
|
168 uint8_t *dst;
|
|
169 int i;
|
2869
|
170
|
2924
|
171 dst = lvo_mem + image_width * y + x;
|
|
172 src = image[0];
|
|
173 if(w==stride[0] && w==image_width) memcpy(dst,src,w*h);
|
|
174 else
|
|
175 for(i=0;i<h;i++)
|
|
176 {
|
|
177 memcpy(dst,src,w);
|
|
178 src+=stride[0];
|
|
179 dst+=image_width;
|
|
180 }
|
|
181
|
|
182 x/=2;y/=2;w/=2;h/=2;
|
|
183
|
|
184 dst = lvo_mem + image_width * image_height + image_width/2 * y + x;
|
|
185 src = image[2];
|
|
186 if(w==stride[2] && w==image_width/2) memcpy(dst,src,w*h);
|
|
187 else
|
|
188 for(i=0;i<h;i++)
|
|
189 {
|
|
190 memcpy(dst,src,w);
|
|
191 src+=stride[2];
|
|
192 dst+=image_width/2;
|
|
193 }
|
|
194 dst = lvo_mem + image_width * image_height * 5 / 4 + image_width/2 * y + x;
|
|
195 src = image[1];
|
|
196 if(w==stride[1] && w==image_width/2) memcpy(dst,src,w*h);
|
|
197 else
|
|
198 for(i=0;i<h;i++)
|
|
199 {
|
|
200 memcpy(dst,src,w);
|
|
201 src+=stride[1];
|
|
202 dst+=image_width/2;
|
|
203 }
|
2952
|
204 #else
|
|
205 uint8_t *src;
|
|
206 uint8_t *dst;
|
|
207 dst = lvo_mem + image_width * y + x;
|
|
208 src = image[0];
|
|
209 w <<= 1;
|
|
210 while(h--) {
|
|
211 memcpy(dst, src, w);
|
|
212 src += stride[0];
|
|
213 dst += stride[0];
|
|
214 }
|
|
215
|
2924
|
216 #endif
|
|
217 return 0;
|
2869
|
218 }
|
|
219
|
|
220 uint32_t vlvo_draw_frame(uint8_t *src[])
|
|
221 {
|
|
222 size_t i, ssize;
|
|
223 uint8_t *dest;
|
|
224 const uint8_t *sptr;
|
|
225 ssize = IMAGE_LINE_SIZE((image_bpp+7)/8);
|
|
226 dest = lvo_mem;
|
|
227 sptr = src[0];
|
|
228 for(i=0;i<image_height;i++)
|
|
229 {
|
|
230 memcpy(dest,sptr,ssize);
|
|
231 sptr += ssize;
|
|
232 dest += ssize;
|
|
233 }
|
|
234 }
|
|
235
|
|
236 void vlvo_flip_page(void)
|
|
237 {
|
|
238 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame);
|
|
239 next_frame=(next_frame+1)%mga_vid_config.num_frames;
|
|
240 lvo_mem=frames[next_frame];
|
|
241 }
|
|
242
|
|
243 void vlvo_draw_osd(void)
|
|
244 {
|
|
245 /* TODO: hw support */
|
|
246 }
|
|
247
|
|
248 uint32_t vlvo_query_info(uint32_t format)
|
|
249 {
|
2952
|
250 if(verbose) printf("vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format));
|
2869
|
251 return 1;
|
|
252 }
|