# HG changeset patch # User ulion # Date 1196396438 0 # Node ID 48fe4b6e3bab98e2783724ed54d86c487516ac64 # Parent 6e8b40d412f021f776912e24863fff6da1002bfd Support double buffering, fix osd flicker. diff -r 6e8b40d412f0 -r 48fe4b6e3bab libvo/vo_macosx.h --- a/libvo/vo_macosx.h Fri Nov 30 00:03:01 2007 +0000 +++ b/libvo/vo_macosx.h Fri Nov 30 04:20:38 2007 +0000 @@ -32,7 +32,7 @@ NSEvent *event; //CoreVideo - CVPixelBufferRef currentFrameBuffer; + CVPixelBufferRef frameBuffers[2]; CVOpenGLTextureCacheRef textureCache; CVOpenGLTextureRef texture; NSRect textureFrame; diff -r 6e8b40d412f0 -r 48fe4b6e3bab libvo/vo_macosx.m --- a/libvo/vo_macosx.m Fri Nov 30 00:03:01 2007 +0000 +++ b/libvo/vo_macosx.m Fri Nov 30 04:20:38 2007 +0000 @@ -46,6 +46,10 @@ //image unsigned char *image_data; +// For double buffering +static uint8_t image_page = 0; +static unsigned char *image_datas[2]; + static uint32_t image_width; static uint32_t image_height; static uint32_t image_depth; @@ -126,6 +130,10 @@ if(!shared_buffer) { image_data = malloc(image_width*image_height*image_bytes); + image_datas[0] = image_data; + if (vo_doublebuffering) + image_datas[1] = malloc(image_width*image_height*image_bytes); + image_page = 0; monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height; @@ -196,6 +204,10 @@ else { [mpGLView setCurrentTexture]; [mpGLView render]; + if (vo_doublebuffering) { + image_page = 1 - image_page; + image_data = image_datas[image_page]; + } } } @@ -270,7 +282,11 @@ } if (!shared_buffer) { - free(image_data); + free(image_datas[0]); + if (vo_doublebuffering) + free(image_datas[1]); + image_datas[0] = NULL; + image_datas[1] = NULL; image_data = NULL; } } @@ -404,15 +420,20 @@ [glContext setView:self]; [glContext makeCurrentContext]; - error = CVPixelBufferCreateWithBytes( NULL, image_width, image_height, pixelFormat, image_data, image_width*image_bytes, NULL, NULL, NULL, ¤tFrameBuffer); + error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]); if(error != kCVReturnSuccess) mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error); + if (vo_doublebuffering) { + error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]); + if(error != kCVReturnSuccess) + mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Double Buffer(%d)\n", error); + } error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache); if(error != kCVReturnSuccess) mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error); - error = CVOpenGLTextureCacheCreateTextureFromImage( NULL, textureCache, currentFrameBuffer, 0, &texture); + error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); if(error != kCVReturnSuccess) mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); @@ -761,7 +782,7 @@ { CVReturn error = kCVReturnSuccess; - error = CVOpenGLTextureCacheCreateTextureFromImage (NULL, textureCache, currentFrameBuffer, 0, &texture); + error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); if(error != kCVReturnSuccess) mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error);