osdep: Remove cruft
[mplayer.git] / libvo / vesa_lvo.c
blobfc1573325bfd7fb1b2dfb4ecad620992e7a62b9f
1 /*
2 * vesa_lvo.c
4 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - Oct 2001
6 * You can redistribute this file under terms and conditions
7 * of GNU General Public licence v2 or later.
9 * This file contains vo_vesa interface to Linux Video Overlay.
10 * (Partly based on vo_mga.c from mplayer's package)
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>
22 #include "config.h"
23 #include "mp_msg.h"
24 #include "help_mp.h"
26 #include "vesa_lvo.h"
27 #include "libmpcodecs/img_format.h"
28 #include "drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */
29 #include "fastmemcpy.h"
30 #include "osd.h"
31 #include "video_out.h"
32 #include "sub.h"
33 #include "libmpcodecs/vfcap.h"
35 #define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */
36 #define NUM_FRAMES 10
37 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */
39 static uint8_t *frames[NUM_FRAMES];
41 static int lvo_handler = -1;
42 static uint8_t *lvo_mem = NULL;
43 static uint8_t next_frame;
44 static mga_vid_config_t mga_vid_config;
45 static unsigned image_bpp,image_height,image_width,src_format;
46 int vlvo_control(uint32_t request, void *data);
48 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8)
49 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) )
50 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size))
52 extern struct vo_old_functions video_out_vesa;
54 int vlvo_preinit(const char *drvname)
56 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_ThisBranchIsNoLongerSupported);
57 return -1;
58 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
59 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_preinit(%s) was called\n",drvname);}
60 lvo_handler = open(drvname,O_RDWR);
61 if(lvo_handler == -1)
63 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_CouldntOpen,drvname);
64 return -1;
66 /* we are able to tune up this stuff depend on fourcc format */
67 video_out_vesa.draw_slice=vlvo_draw_slice;
68 video_out_vesa.draw_frame=vlvo_draw_frame;
69 video_out_vesa.flip_page=vlvo_flip_page;
70 video_out_vesa.draw_osd=vlvo_draw_osd;
71 video_out_vesa.control=vlvo_control;
72 return 0;
75 int vlvo_init(unsigned src_width,unsigned src_height,
76 unsigned x_org,unsigned y_org,unsigned dst_width,
77 unsigned dst_height,unsigned format,unsigned dest_bpp)
79 size_t i,awidth;
80 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_ThisBranchIsNoLongerSupported);
81 return -1;
82 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
83 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_init() was called\n");}
84 image_width = src_width;
85 image_height = src_height;
86 mga_vid_config.version=MGA_VID_VERSION;
87 src_format = mga_vid_config.format=format;
88 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
89 switch(format){
90 case IMGFMT_YV12:
91 case IMGFMT_I420:
92 case IMGFMT_IYUV:
93 image_bpp=16;
94 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2;
95 break;
96 case IMGFMT_YUY2:
97 case IMGFMT_UYVY:
98 image_bpp=16;
99 mga_vid_config.frame_size = awidth*src_height*2;
100 break;
101 case IMGFMT_RGB15:
102 case IMGFMT_BGR15:
103 case IMGFMT_RGB16:
104 case IMGFMT_BGR16:
105 image_bpp=16;
106 mga_vid_config.frame_size = awidth*src_height*2;
107 break;
108 case IMGFMT_RGB24:
109 case IMGFMT_BGR24:
110 image_bpp=24;
111 mga_vid_config.frame_size = awidth*src_height*3;
112 break;
113 case IMGFMT_RGB32:
114 case IMGFMT_BGR32:
115 image_bpp=32;
116 mga_vid_config.frame_size = awidth*src_height*4;
117 break;
118 default:
119 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_InvalidOutputFormat,vo_format_name(format),format);
120 return -1;
122 mga_vid_config.colkey_on=0;
123 mga_vid_config.src_width = src_width;
124 mga_vid_config.src_height= src_height;
125 mga_vid_config.dest_width = dst_width;
126 mga_vid_config.dest_height= dst_height;
127 mga_vid_config.x_org=x_org;
128 mga_vid_config.y_org=y_org;
129 mga_vid_config.num_frames=NUM_FRAMES;
130 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config))
132 perror("vesa_lvo: Error in mga_vid_config ioctl()");
133 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_IncompatibleDriverVersion);
134 return -1;
136 ioctl(lvo_handler,MGA_VID_ON,0);
138 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0);
139 for(i=1;i<NUM_FRAMES;i++)
140 frames[i] = frames[i-1] + mga_vid_config.frame_size;
141 next_frame = 0;
142 lvo_mem = frames[next_frame];
144 /*clear the buffer*/
145 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames);
146 return 0;
149 void vlvo_term( void )
151 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
152 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_term() was called\n");}
153 ioctl( lvo_handler,MGA_VID_OFF,0 );
154 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames);
155 if(lvo_handler != -1) close(lvo_handler);
158 int vlvo_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y)
160 uint8_t *src;
161 uint8_t *dest;
162 uint32_t bespitch,bespitch2;
163 int i;
165 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
166 bespitch2 = bespitch/2;
168 dest = lvo_mem + bespitch * y + x;
169 src = image[0];
170 for(i=0;i<h;i++){
171 fast_memcpy(dest,src,w);
172 src+=stride[0];
173 dest += bespitch;
176 w/=2;h/=2;x/=2;y/=2;
178 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x;
179 src = image[1];
180 for(i=0;i<h;i++){
181 fast_memcpy(dest,src,w);
182 src+=stride[1];
183 dest += bespitch2;
186 dest = lvo_mem + bespitch*mga_vid_config.src_height
187 + bespitch*mga_vid_config.src_height / 4
188 + bespitch2 * y + x;
189 src = image[2];
190 for(i=0;i<h;i++){
191 fast_memcpy(dest,src,w);
192 src+=stride[2];
193 dest += bespitch2;
195 return 0;
198 int vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
200 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
201 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_draw_slice() was called\n");}
202 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV)
203 vlvo_draw_slice_420(image,stride,w,h,x,y);
204 else
206 uint8_t *dst;
207 uint8_t bytpp;
208 bytpp = (image_bpp+7)/8;
209 dst = lvo_mem + (image_width * y + x)*bytpp;
210 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */
211 fast_memcpy(dst,image[0],mga_vid_config.frame_size);
213 return 0;
216 int vlvo_draw_frame(uint8_t *image[])
218 /* Note it's very strange but sometime for YUY2 draw_frame is called */
219 fast_memcpy(lvo_mem,image[0],mga_vid_config.frame_size);
220 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
221 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_flip_page() was called\n");}
222 return 0;
225 void vlvo_flip_page(void)
227 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
228 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_draw_osd() was called\n");}
229 if(vo_doublebuffering)
231 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame);
232 next_frame=(next_frame+1)%mga_vid_config.num_frames;
233 lvo_mem=frames[next_frame];
237 #if 0
238 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
240 UNUSED(x0);
241 UNUSED(y0);
242 UNUSED(w);
243 UNUSED(h);
244 UNUSED(src);
245 UNUSED(srca);
246 UNUSED(stride);
249 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
251 uint32_t bespitch = /*(*/mga_vid_config.src_width;// + 15) & ~15;
252 switch(mga_vid_config.format){
253 case IMGFMT_BGR15:
254 case IMGFMT_RGB15:
255 vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch);
256 break;
257 case IMGFMT_BGR16:
258 case IMGFMT_RGB16:
259 vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch);
260 break;
261 case IMGFMT_BGR24:
262 case IMGFMT_RGB24:
263 vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+3*(y0*bespitch+x0),3*bespitch);
264 break;
265 case IMGFMT_BGR32:
266 case IMGFMT_RGB32:
267 vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+4*(y0*bespitch+x0),4*bespitch);
268 break;
269 case IMGFMT_YV12:
270 case IMGFMT_IYUV:
271 case IMGFMT_I420:
272 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch);
273 break;
274 case IMGFMT_YUY2:
275 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),bespitch);
276 break;
277 case IMGFMT_UYVY:
278 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,bespitch);
279 break;
280 default:
281 draw_alpha_null(x0,y0,w,h,src,srca,stride);
284 #endif
286 void vlvo_draw_osd(void)
288 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
289 mp_msg(MSGT_VO,MSGL_DBG2,"vesa_lvo: vlvo_draw_osd() was called\n"); }
290 /* TODO: hw support */
291 #if 0
292 /* disable this stuff until new fbvid.h interface will be implemented
293 because in different fourcc radeon_vid and rage128_vid have different
294 width alignment */
295 vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha);
296 #endif
299 uint32_t vlvo_query_info(uint32_t format)
301 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
302 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); }
303 return VFCAP_CSP_SUPPORTED;
306 int vlvo_control(uint32_t request, void *data)
308 switch (request) {
309 case VOCTRL_QUERY_FORMAT:
310 return vlvo_query_info(*((uint32_t*)data));
312 return VO_NOTIMPL;