changeset 56:cdb2e30be421

mga_vid fixes, code cleanup
author arpi_esp
date Thu, 08 Mar 2001 01:06:03 +0000
parents 91fa9f06657a
children baa0a12438eb
files libvo/mga_common.c libvo/video_out.c libvo/vo_mga.c libvo/vo_xmga.c
diffstat 4 files changed, 50 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/mga_common.c	Wed Mar 07 20:42:22 2001 +0000
+++ b/libvo/mga_common.c	Thu Mar 08 01:06:03 2001 +0000
@@ -1,7 +1,12 @@
 
 // mga_vid drawing functions
 
-extern int mga_next_frame;
+static int mga_next_frame=0;
+
+static mga_vid_config_t mga_vid_config;
+static uint8_t *vid_data, *frames[4];
+static int f;
+
 
 static void
 write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
@@ -161,7 +166,7 @@
 
 #if 1
 	ioctl(f,MGA_VID_FSEL,&mga_next_frame);
-	mga_next_frame=(mga_next_frame+1)&3;
+	mga_next_frame=(mga_next_frame+1)%mga_vid_config.num_frames;
 	vid_data=frames[mga_next_frame];
 #endif
 
@@ -218,3 +223,29 @@
     return 0;
 }
 
+static int mga_init(){
+	char *frame_mem;
+
+	mga_vid_config.num_frames=4;
+	mga_vid_config.version=MGA_VID_VERSION;
+	if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config))
+	{
+		perror("Error in mga_vid_config ioctl");
+		return -1;
+	}
+	ioctl(f,MGA_VID_ON,0);
+
+	frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0);
+	frames[1] = frames[0] + 1*mga_vid_config.frame_size;
+	frames[2] = frames[0] + 2*mga_vid_config.frame_size;
+	frames[3] = frames[0] + 3*mga_vid_config.frame_size;
+	mga_next_frame = 0;
+	vid_data = frames[mga_next_frame];
+
+	//clear the buffer
+	memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames);
+
+  return 0;
+
+}
+
--- a/libvo/video_out.c	Wed Mar 07 20:42:22 2001 +0000
+++ b/libvo/video_out.c	Thu Mar 08 01:06:03 2001 +0000
@@ -35,8 +35,6 @@
 // Externally visible list of all vo drivers
 //
 
-int mga_next_frame=0;
-
 extern vo_functions_t video_out_mga;
 extern vo_functions_t video_out_xmga;
 extern vo_functions_t video_out_x11;
--- a/libvo/vo_mga.c	Wed Mar 07 20:42:22 2001 +0000
+++ b/libvo/vo_mga.c	Thu Mar 08 01:06:03 2001 +0000
@@ -49,20 +49,14 @@
 	""
 };
 
-static mga_vid_config_t mga_vid_config;
-static uint8_t *vid_data, *frames[4];
-static int f;
 
 #include "mga_common.c"
 
 static uint32_t
 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
 {
-	char *frame_mem;
-	uint32_t frame_size;
 
 	f = open("/dev/mga_vid",O_RDWR);
-
 	if(f == -1)
 	{
 		fprintf(stderr,"Couldn't open /dev/mga_vid\n"); 
@@ -71,8 +65,10 @@
 
         switch(format){
         case IMGFMT_YV12:
+	    mga_vid_config.frame_size = ((width + 31) & ~31) * height + (((width + 31) & ~31) * height) / 2;
             mga_vid_config.format=MGA_VID_FORMAT_YV12; break;
         case IMGFMT_YUY2:
+	    mga_vid_config.frame_size = ((width + 31) & ~31) * height * 2;
             mga_vid_config.format=MGA_VID_FORMAT_YUY2; break;
         default: 
             fprintf(stderr,"mga: invalid output format %0X\n",format);
@@ -81,34 +77,14 @@
 
 	mga_vid_config.src_width = width;
 	mga_vid_config.src_height= height;
-//	mga_vid_config.dest_width = width;
-//	mga_vid_config.dest_height= height;
 	mga_vid_config.dest_width = d_width;
-//        (width<704)?704:width;   // HACK
 	mga_vid_config.dest_height= d_height;
-//        (height<576)?576:height; // HACK
 	mga_vid_config.x_org= 0; // (720-mga_vid_config.dest_width)/2;
 	mga_vid_config.y_org= 0; // (576-mga_vid_config.dest_height)/2;
-
-	if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config))
-	{
-		perror("Error in mga_vid_config ioctl");
-	}
-	ioctl(f,MGA_VID_ON,0);
+	
+	mga_vid_config.version=MGA_VID_VERSION;
 
-	frame_size = ((width + 31) & ~31) * height + (((width + 31) & ~31) * height) / 2;
-	frame_mem = (char*)mmap(0,frame_size*4,PROT_WRITE,MAP_SHARED,f,0);
-	frames[0] = frame_mem;
-	frames[1] = frame_mem + 1*frame_size;
-	frames[2] = frame_mem + 2*frame_size;
-	frames[3] = frame_mem + 3*frame_size;
-	mga_next_frame = 0;
-	vid_data = frames[mga_next_frame];
-
-	//clear the buffer
-	memset(frame_mem,0x80,frame_size*4);
-
-  return 0;
+  return mga_init();
 }
 
 static const vo_info_t*
--- a/libvo/vo_xmga.c	Wed Mar 07 20:42:22 2001 +0000
+++ b/libvo/vo_xmga.c	Thu Mar 08 01:06:03 2001 +0000
@@ -53,11 +53,6 @@
  ""
 };
 
-static mga_vid_config_t       mga_vid_config;
-static uint8_t              * vid_data;
-static uint8_t              * frames[4];
-static int                    f;
-
 static Display              * mDisplay;
 static Window                 mWindow;
 static GC                     mGC;
@@ -142,7 +137,7 @@
 static uint32_t init( uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format )
 {
  char                 * frame_mem;
- uint32_t               frame_size;
+// uint32_t               frame_size;
  int                    mScreen;
  unsigned int           fg, bg;
  char                 * mTitle=(title == NULL) ? "XMGA render" : title;
@@ -163,8 +158,14 @@
 
  switch(format)
   {
-   case IMGFMT_YV12: mga_vid_config.format=MGA_VID_FORMAT_YV12; break;
-   case IMGFMT_YUY2: mga_vid_config.format=MGA_VID_FORMAT_YUY2; break;
+   case IMGFMT_YV12: 
+        mga_vid_config.format=MGA_VID_FORMAT_YV12;
+	mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2;
+        break;
+   case IMGFMT_YUY2:
+        mga_vid_config.format=MGA_VID_FORMAT_YUY2;
+	mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2;
+        break;
    default:          fprintf(stderr,"mga: invalid output format %0X\n",format); return (-1);
   }
 
@@ -253,10 +254,10 @@
 
  mga_vid_config.src_width=width;
  mga_vid_config.src_height=height;
+ mga_vid_config.dest_width=drwWidth;
+ mga_vid_config.dest_height=drwHeight;
  mga_vid_config.x_org=drwcX;
  mga_vid_config.y_org=drwcY;
- mga_vid_config.dest_width=drwWidth;
- mga_vid_config.dest_height=drwHeight;
 
  fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
 
@@ -265,30 +266,11 @@
  mga_vid_config.colkey_green=0;
  mga_vid_config.colkey_blue=255;
 
-#if 1
- if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
-  {
-   fprintf( stderr,"Error in mga_vid_config ioctl" );
-   return -1;
-  }
- ioctl( f,MGA_VID_ON,0 );
-#endif
-
- frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2;
- frame_mem=(char*)mmap( 0,frame_size*4,PROT_WRITE,MAP_SHARED,f,0 );
- frames[0] = frame_mem;
- frames[1] = frame_mem + 1*frame_size;
- frames[2] = frame_mem + 2*frame_size;
- frames[3] = frame_mem + 3*frame_size;
- mga_next_frame=0;
- vid_data=frames[mga_next_frame];
- memset( frame_mem,0x80,frame_size * 4 );
+ if(mga_init()) return -1;
 
  XFlush( mDisplay );
  XSync( mDisplay,False );
 
-// vo_initthread( mThread );
-
  return 0;
 }
 
@@ -302,6 +284,3 @@
  ioctl( f,MGA_VID_OFF,0 );
 printf("vo: uninit!\n");
 }
-
-
-