OSD: support displaying fractional part of current position
[mplayer/greg.git] / libvo / vesa_lvo.c
blobf5cbab4757a4956ec987b7e6d8ed1c6f10e35962
1 /*
2 * vo_vesa interface to Linux Video Overlay
3 * (partly based on vo_mga.c)
5 * copyright (C) 2001 Nick Kurshev <nickols_k@mail.ru>
7 * This file is part of MPlayer.
9 * MPlayer is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * MPlayer is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <inttypes.h>
25 #include <sys/ioctl.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <sys/mman.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #include "config.h"
34 #include "mp_msg.h"
36 #include "vesa_lvo.h"
37 #include "libmpcodecs/img_format.h"
38 #include "drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */
39 #include "fastmemcpy.h"
40 #include "osd.h"
41 #include "video_out.h"
42 #include "sub/sub.h"
43 #include "libmpcodecs/vfcap.h"
45 #define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */
46 #define NUM_FRAMES 10
48 static uint8_t *frames[NUM_FRAMES];
50 static int lvo_handler = -1;
51 static uint8_t *lvo_mem = NULL;
52 static uint8_t next_frame;
53 static mga_vid_config_t mga_vid_config;
54 static unsigned image_bpp,image_height,image_width,src_format;
55 int vlvo_control(uint32_t request, void *data);
57 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8)
58 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) )
59 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size))
61 int vlvo_init(unsigned src_width,unsigned src_height,
62 unsigned x_org,unsigned y_org,unsigned dst_width,
63 unsigned dst_height,unsigned format,unsigned dest_bpp)
65 size_t i,awidth;
66 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVO] This branch is no longer supported.\n[VESA_LVO] Please use -vo vesa:vidix instead.\n");
67 return -1;
68 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
69 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_init() was called\n");}
70 image_width = src_width;
71 image_height = src_height;
72 mga_vid_config.version=MGA_VID_VERSION;
73 src_format = mga_vid_config.format=format;
74 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
75 switch(format){
76 case IMGFMT_YV12:
77 case IMGFMT_I420:
78 case IMGFMT_IYUV:
79 image_bpp=16;
80 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2;
81 break;
82 case IMGFMT_YUY2:
83 case IMGFMT_UYVY:
84 image_bpp=16;
85 mga_vid_config.frame_size = awidth*src_height*2;
86 break;
87 case IMGFMT_RGB15:
88 case IMGFMT_BGR15:
89 case IMGFMT_RGB16:
90 case IMGFMT_BGR16:
91 image_bpp=16;
92 mga_vid_config.frame_size = awidth*src_height*2;
93 break;
94 case IMGFMT_RGB24:
95 case IMGFMT_BGR24:
96 image_bpp=24;
97 mga_vid_config.frame_size = awidth*src_height*3;
98 break;
99 case IMGFMT_RGB32:
100 case IMGFMT_BGR32:
101 image_bpp=32;
102 mga_vid_config.frame_size = awidth*src_height*4;
103 break;
104 default:
105 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVI] Invalid output format: %s(%0X)\n",vo_format_name(format),format);
106 return -1;
108 mga_vid_config.colkey_on=0;
109 mga_vid_config.src_width = src_width;
110 mga_vid_config.src_height= src_height;
111 mga_vid_config.dest_width = dst_width;
112 mga_vid_config.dest_height= dst_height;
113 mga_vid_config.x_org=x_org;
114 mga_vid_config.y_org=y_org;
115 mga_vid_config.num_frames=NUM_FRAMES;
116 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config))
118 perror("vesa_lvo: Error in mga_vid_config ioctl()");
119 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVO] Your fb_vid driver version is incompatible with this MPlayer version!\n");
120 return -1;
122 ioctl(lvo_handler,MGA_VID_ON,0);
124 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0);
125 for(i=1;i<NUM_FRAMES;i++)
126 frames[i] = frames[i-1] + mga_vid_config.frame_size;
127 next_frame = 0;
128 lvo_mem = frames[next_frame];
130 /*clear the buffer*/
131 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames);
132 return 0;
135 void vlvo_term( void )
137 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
138 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_term() was called\n");}
139 ioctl( lvo_handler,MGA_VID_OFF,0 );
140 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames);
141 if(lvo_handler != -1) close(lvo_handler);
144 static int vlvo_draw_slice_420(uint8_t *image[], int stride[],
145 int w, int h, int x, int y)
147 uint8_t *src;
148 uint8_t *dest;
149 uint32_t bespitch,bespitch2;
150 int i;
152 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
153 bespitch2 = bespitch/2;
155 dest = lvo_mem + bespitch * y + x;
156 src = image[0];
157 for(i=0;i<h;i++){
158 fast_memcpy(dest,src,w);
159 src+=stride[0];
160 dest += bespitch;
163 w/=2;h/=2;x/=2;y/=2;
165 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x;
166 src = image[1];
167 for(i=0;i<h;i++){
168 fast_memcpy(dest,src,w);
169 src+=stride[1];
170 dest += bespitch2;
173 dest = lvo_mem + bespitch*mga_vid_config.src_height
174 + bespitch*mga_vid_config.src_height / 4
175 + bespitch2 * y + x;
176 src = image[2];
177 for(i=0;i<h;i++){
178 fast_memcpy(dest,src,w);
179 src+=stride[2];
180 dest += bespitch2;
182 return 0;
185 static int vlvo_draw_slice(uint8_t *image[], int stride[],
186 int w,int h,int x,int y)
188 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
189 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_draw_slice() was called\n");}
190 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV)
191 vlvo_draw_slice_420(image,stride,w,h,x,y);
192 else
194 uint8_t *dst;
195 uint8_t bytpp;
196 bytpp = (image_bpp+7)/8;
197 dst = lvo_mem + (image_width * y + x)*bytpp;
198 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */
199 fast_memcpy(dst,image[0],mga_vid_config.frame_size);
201 return 0;
204 static int vlvo_draw_frame(uint8_t *image[])
206 /* Note it's very strange but sometime for YUY2 draw_frame is called */
207 fast_memcpy(lvo_mem,image[0],mga_vid_config.frame_size);
208 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
209 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_flip_page() was called\n");}
210 return 0;
213 static void vlvo_flip_page(void)
215 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
216 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_draw_osd() was called\n");}
217 if(vo_doublebuffering)
219 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame);
220 next_frame=(next_frame+1)%mga_vid_config.num_frames;
221 lvo_mem=frames[next_frame];
225 #if 0
226 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
230 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
232 uint32_t bespitch = /*(*/mga_vid_config.src_width;// + 15) & ~15;
233 switch(mga_vid_config.format){
234 case IMGFMT_BGR15:
235 case IMGFMT_RGB15:
236 vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch);
237 break;
238 case IMGFMT_BGR16:
239 case IMGFMT_RGB16:
240 vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch);
241 break;
242 case IMGFMT_BGR24:
243 case IMGFMT_RGB24:
244 vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+3*(y0*bespitch+x0),3*bespitch);
245 break;
246 case IMGFMT_BGR32:
247 case IMGFMT_RGB32:
248 vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+4*(y0*bespitch+x0),4*bespitch);
249 break;
250 case IMGFMT_YV12:
251 case IMGFMT_IYUV:
252 case IMGFMT_I420:
253 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch);
254 break;
255 case IMGFMT_YUY2:
256 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),bespitch);
257 break;
258 case IMGFMT_UYVY:
259 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,bespitch);
260 break;
261 default:
262 draw_alpha_null(x0,y0,w,h,src,srca,stride);
265 #endif
267 static void vlvo_draw_osd(void)
269 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
270 mp_msg(MSGT_VO,MSGL_DBG2,"vesa_lvo: vlvo_draw_osd() was called\n"); }
271 /* TODO: hw support */
272 #if 0
273 /* disable this stuff until new fbvid.h interface will be implemented
274 because in different fourcc radeon_vid and rage128_vid have different
275 width alignment */
276 vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha);
277 #endif
280 extern struct vo_old_functions video_out_vesa;
282 int vlvo_preinit(const char *drvname)
284 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVO] This branch is no longer supported.\n[VESA_LVO] Please use -vo vesa:vidix instead.\n");
285 return -1;
286 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
287 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_preinit(%s) was called\n",drvname);}
288 lvo_handler = open(drvname,O_RDWR);
289 if(lvo_handler == -1)
291 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVO] Couldn't open: '%s'\n",drvname);
292 return -1;
294 /* we are able to tune up this stuff depend on fourcc format */
295 video_out_vesa.draw_slice=vlvo_draw_slice;
296 video_out_vesa.draw_frame=vlvo_draw_frame;
297 video_out_vesa.flip_page=vlvo_flip_page;
298 video_out_vesa.draw_osd=vlvo_draw_osd;
299 video_out_vesa.control=vlvo_control;
300 return 0;
303 static uint32_t vlvo_query_info(uint32_t format)
305 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
306 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); }
307 return VFCAP_CSP_SUPPORTED;
310 int vlvo_control(uint32_t request, void *data)
312 switch (request) {
313 case VOCTRL_QUERY_FORMAT:
314 return vlvo_query_info(*((uint32_t*)data));
316 return VO_NOTIMPL;