diff options
Diffstat (limited to 'libvo')
-rw-r--r-- | libvo/gl_common.h | 3 | ||||
-rw-r--r-- | libvo/mga_common.c | 6 | ||||
-rw-r--r-- | libvo/vo_direct3d.c | 326 | ||||
-rw-r--r-- | libvo/vo_gl.c | 64 | ||||
-rw-r--r-- | libvo/vo_macosx.m | 4 | ||||
-rw-r--r-- | libvo/vo_png.c | 11 | ||||
-rw-r--r-- | libvo/vo_quartz.c | 1 |
7 files changed, 355 insertions, 60 deletions
diff --git a/libvo/gl_common.h b/libvo/gl_common.h index 2fcb8568ad..1662c7a5d3 100644 --- a/libvo/gl_common.h +++ b/libvo/gl_common.h @@ -225,6 +225,9 @@ #ifndef GL_FLOAT_RGB32_NV #define GL_FLOAT_RGB32_NV 0x8889 #endif +#ifndef GL_UNPACK_CLIENT_STORAGE_APPLE +#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 +#endif #ifndef GL_FRAGMENT_PROGRAM #define GL_FRAGMENT_PROGRAM 0x8804 #endif diff --git a/libvo/mga_common.c b/libvo/mga_common.c index 34eee958e3..ef2240ac15 100644 --- a/libvo/mga_common.c +++ b/libvo/mga_common.c @@ -381,7 +381,7 @@ static int mga_init(int width,int height,unsigned int format){ if(width > 1024 && height > 1024) { - mp_msg(MSGT_VO,MSGL_ERR, MGSTR_LIBVO_MGA_ResolutionTooHigh); + mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_MGA_ResolutionTooHigh); return -1; } else if(height <= 1024) { @@ -392,7 +392,7 @@ static int mga_init(int width,int height,unsigned int format){ if(mga_vid_config.card_type != MGA_G550) { // we don't have a G550, so our resolution is too high - mp_msg(MSGT_VO,MSGL_ERR, MGSTR_LIBVO_MGA_ResolutionTooHigh); + mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_MGA_ResolutionTooHigh); return -1; } else { // there is a deeper problem @@ -463,7 +463,7 @@ static int preinit(const char *vo_subdevice) ioctl(f,MGA_VID_GET_VERSION,&ver); if(MGA_VID_VERSION != ver) { - mp_msg(MSGT_VO, MSGL_ERR, MGSTR_LIBVO_MGA_mgavidVersionMismatch, ver, MGA_VID_VERSION); + mp_msg(MSGT_VO, MSGL_ERR, MSGTR_LIBVO_MGA_mgavidVersionMismatch, ver, MGA_VID_VERSION); return -1; } diff --git a/libvo/vo_direct3d.c b/libvo/vo_direct3d.c index b631f22f14..c32cdc663a 100644 --- a/libvo/vo_direct3d.c +++ b/libvo/vo_direct3d.c @@ -30,6 +30,8 @@ #include "aspect.h" #include "w32_common.h" #include "libavutil/common.h" +#include "font_load.h" +#include "sub.h" static const vo_info_t info = { @@ -71,8 +73,25 @@ static struct global_priv { IDirect3DSurface9 *d3d_surface; /**< Offscreen Direct3D Surface. MPlayer renders inside it. Uses colorspace priv->movie_src_fmt */ + IDirect3DTexture9 *d3d_texture_osd; /**< Direct3D Texture. Uses RGBA */ + IDirect3DTexture9 *d3d_texture_system; /**< Direct3D Texture. System memory + cannot lock a normal texture. Uses RGBA */ IDirect3DSurface9 *d3d_backbuf; /**< Video card's back buffer (used to display next frame) */ + int is_osd_populated; /**< 1 = OSD texture has something to display, + 0 = OSD texture is clear */ + int device_caps_power2_only; /**< 1 = texture sizes have to be power 2 + 0 = texture sizes can be anything */ + int device_caps_square_only; /**< 1 = textures have to be square + 0 = textures do not have to be square */ + int device_texture_sys; /**< 1 = device can texture from system memory + 0 = device requires shadow */ + int max_texture_width; /**< from the device capabilities */ + int max_texture_height; /**< from the device capabilities */ + int osd_width; /**< current width of the OSD */ + int osd_height; /**< current height of the OSD */ + int osd_texture_width; /**< current width of the OSD texture */ + int osd_texture_height; /**< current height of the OSD texture */ } *priv; typedef struct { @@ -100,6 +119,13 @@ static const struct_fmt_table fmt_table[] = { #define DISPLAY_FORMAT_TABLE_ENTRIES (sizeof(fmt_table) / sizeof(fmt_table[0])) +#define D3DFVF_MY_VERTEX (D3DFVF_XYZ | D3DFVF_TEX1) + +typedef struct { + float x, y, z; /* Position of vertex in 3D space */ + float tu, tv; /* Texture coordinates */ +} struct_vertex; + /**************************************************************************** * * * * @@ -127,7 +153,8 @@ static void calc_fs_rect(void) priv->fs_panscan_rect.right = priv->src_width; priv->fs_panscan_rect.top = 0; priv->fs_panscan_rect.bottom = priv->src_height; - if (!vo_fs) return; + if (!vo_fs) + return; // adjust for fullscreen aspect and panscan aspect(&scaled_width, &scaled_height, A_ZOOM); @@ -175,20 +202,26 @@ static void destroy_d3d_surfaces(void) mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>destroy_d3d_surfaces called\r\n"); /* Let's destroy the old (if any) D3D Surfaces */ - if (priv->locked_rect.pBits) { + if (priv->locked_rect.pBits) IDirect3DSurface9_UnlockRect(priv->d3d_surface); - priv->locked_rect.pBits = NULL; - } + priv->locked_rect.pBits = NULL; - if (priv->d3d_surface) { + if (priv->d3d_surface) IDirect3DSurface9_Release(priv->d3d_surface); - priv->d3d_surface = NULL; - } + priv->d3d_surface = NULL; - if (priv->d3d_backbuf) { + /* kill the OSD texture and its shadow copy */ + if (priv->d3d_texture_osd) + IDirect3DTexture9_Release(priv->d3d_texture_osd); + priv->d3d_texture_osd = NULL; + + if (priv->d3d_texture_system) + IDirect3DTexture9_Release(priv->d3d_texture_system); + priv->d3d_texture_system = NULL; + + if (priv->d3d_backbuf) IDirect3DSurface9_Release(priv->d3d_backbuf); - priv->d3d_backbuf = NULL; - } + priv->d3d_backbuf = NULL; } /** @brief Create D3D Offscreen and Backbuffer surfaces. @@ -196,6 +229,8 @@ static void destroy_d3d_surfaces(void) */ static int create_d3d_surfaces(void) { + int osd_width = vo_dwidth, osd_height = vo_dheight; + int tex_width = osd_width, tex_height = osd_height; mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>create_d3d_surfaces called.\n"); if (FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface( @@ -213,6 +248,77 @@ static int create_d3d_surfaces(void) return 0; } + /* calculate the best size for the OSD depending on the factors from the device */ + if (priv->device_caps_power2_only) { + tex_width = 1; + tex_height = 1; + while (tex_width < osd_width ) tex_width <<= 1; + while (tex_height < osd_height) tex_height <<= 1; + } + if (priv->device_caps_square_only) + /* device only supports square textures */ + tex_width = tex_height = tex_width > tex_height ? tex_width : tex_height; + // better round up to a multiple of 16 + tex_width = (tex_width + 15) & ~15; + tex_height = (tex_height + 15) & ~15; + + // make sure we respect the size limits without breaking aspect or pow2-requirements + while (tex_width > priv->max_texture_width || tex_height > priv->max_texture_height) { + osd_width >>= 1; + osd_height >>= 1; + tex_width >>= 1; + tex_height >>= 1; + } + + priv->osd_width = osd_width; + priv->osd_height = osd_height; + priv->osd_texture_width = tex_width; + priv->osd_texture_height = tex_height; + + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>surface (%d, %d) requested = (%d, %d)\n", + vo_dwidth, vo_dheight, priv->osd_texture_width, priv->osd_texture_height); + + /* create OSD */ + if (FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, + priv->osd_texture_width, + priv->osd_texture_height, + 1, + D3DUSAGE_DYNAMIC, + D3DFMT_A8L8, + D3DPOOL_SYSTEMMEM, + &priv->d3d_texture_system, + NULL))) { + mp_msg(MSGT_VO,MSGL_ERR, + "<vo_direct3d><INFO>IDirect3DDevice9_CreateTexture Failed (d3d_texture_system).\n"); + return 0; + } + + if (!priv->device_texture_sys) { + /* only create if we need a shadow version on the external device */ + if (FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, + priv->osd_texture_width, + priv->osd_texture_height, + 1, + D3DUSAGE_DYNAMIC, + D3DFMT_A8L8, + D3DPOOL_DEFAULT, + &priv->d3d_texture_osd, + NULL))) { + mp_msg(MSGT_VO,MSGL_ERR, + "<vo_direct3d><INFO>IDirect3DDevice9_CreateTexture Failed (d3d_texture_osd).\n"); + return 0; + } + } + + /* setup default renderstate */ + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_SRCBLEND, D3DBLEND_ONE); + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHAFUNC, D3DCMP_GREATER); + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHAREF, (DWORD)0x0); + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_LIGHTING, FALSE); + IDirect3DDevice9_SetSamplerState(priv->d3d_device, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + IDirect3DDevice9_SetSamplerState(priv->d3d_device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + return 1; } @@ -298,10 +404,9 @@ static int reconfigure_d3d(void) destroy_d3d_surfaces(); /* Destroy the D3D Device */ - if (priv->d3d_device) { + if (priv->d3d_device) IDirect3DDevice9_Release(priv->d3d_device); - priv->d3d_device = NULL; - } + priv->d3d_device = NULL; /* Stop the whole Direct3D */ IDirect3D9_Release(priv->d3d_handle); @@ -352,6 +457,13 @@ static int resize_d3d(void) calc_fs_rect(); +#ifdef CONFIG_FREETYPE + // font needs to be adjusted + force_load_font = 1; +#endif + // OSD needs to be drawn fresh for new size + vo_osd_changed(OSDTYPE_OSD); + return 1; } @@ -364,16 +476,16 @@ static void uninit_d3d(void) destroy_d3d_surfaces(); /* Destroy the D3D Device */ - if (priv->d3d_device) { + if (priv->d3d_device) IDirect3DDevice9_Release(priv->d3d_device); - priv->d3d_device = NULL; - } + priv->d3d_device = NULL; /* Stop the whole D3D. */ if (priv->d3d_handle) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Calling IDirect3D9_Release\r\n"); IDirect3D9_Release(priv->d3d_handle); } + priv->d3d_handle = NULL; } /** @brief Render a frame on the screen. @@ -470,7 +582,7 @@ static int query_format(uint32_t movie_fmt) mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Accepted image format: %s\n", vo_format_name(fmt_table[i].mplayer_fmt)); return (VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW - /*| VFCAP_OSD*/ | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN); + | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN); } } @@ -501,6 +613,9 @@ static int query_format(uint32_t movie_fmt) static int preinit(const char *arg) { D3DDISPLAYMODE disp_mode; + D3DCAPS9 disp_caps; + DWORD texture_caps; + DWORD dev_caps; /* Set to zero all global variables. */ priv = calloc(1, sizeof(struct global_priv)); @@ -533,6 +648,31 @@ static int preinit(const char *arg) mp_msg(MSGT_VO, MSGL_V, "disp_mode.Width %d, disp_mode.Height %d\n", disp_mode.Width, disp_mode.Height); + if (FAILED(IDirect3D9_GetDeviceCaps(priv->d3d_handle, + D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, + &disp_caps))) { + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Could not read display capabilities\n"); + return -1; + } + + /* Store relevant information reguarding caps of device */ + texture_caps = disp_caps.TextureCaps; + dev_caps = disp_caps.DevCaps; + priv->device_caps_power2_only = (texture_caps & D3DPTEXTURECAPS_POW2) && + !(texture_caps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL); + priv->device_caps_square_only = texture_caps & D3DPTEXTURECAPS_SQUAREONLY; + priv->device_texture_sys = dev_caps & D3DDEVCAPS_TEXTURESYSTEMMEMORY; + priv->max_texture_width = disp_caps.MaxTextureWidth; + priv->max_texture_height = disp_caps.MaxTextureHeight; + + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>device_caps_power2_only %d, device_caps_square_only %d\n" + "<vo_direct3d>device_texture_sys %d\n" + "<vo_direct3d>max_texture_width %d, max_texture_height %d\n", + priv->device_caps_power2_only, priv->device_caps_square_only, + priv->device_texture_sys, priv->max_texture_width, + priv->max_texture_height); + /* w32_common framework call. Configures window on the screen, gets * fullscreen dimensions and does other useful stuff. */ @@ -632,10 +772,9 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, destroy_d3d_surfaces(); /* Destroy the D3D Device */ - if (priv->d3d_device) { + if (priv->d3d_device) IDirect3DDevice9_Release(priv->d3d_device); - priv->d3d_device = NULL; - } + priv->d3d_device = NULL; if (!configure_d3d()) return VO_ERROR; @@ -645,7 +784,6 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, /** @brief libvo Callback: Flip next already drawn frame on the * screen. - * @return N/A */ static void flip_page(void) { @@ -667,16 +805,8 @@ static void flip_page(void) } } -/** @brief libvo Callback: Draw OSD/Subtitles, - * @return N/A - */ -static void draw_osd(void) -{ -} - /** @brief libvo Callback: Uninitializes all pointers and closes * all D3D related stuff, - * @return N/A */ static void uninit(void) { @@ -689,7 +819,6 @@ static void uninit(void) } /** @brief libvo Callback: Handles video window events. - * @return N/A */ static void check_events(void) { @@ -763,10 +892,145 @@ static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y ) } /** @brief libvo Callback: Unused function - * @return N/A */ static int draw_frame(uint8_t *src[]) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>draw_frame called\n"); return VO_FALSE; } + +/** @brief Maps MPlayer alpha to D3D + * 0x0 -> transparent and discarded by alpha test + * 0x1 -> 0xFF to become opaque + * other alpha values are inverted +1 (2 = -2) + * These values are then inverted again with + the texture filter D3DBLEND_INVSRCALPHA + */ +void vo_draw_alpha_l8a8(int w, int h, unsigned char* src, unsigned char *srca, + int srcstride, unsigned char* dstbase, int dststride) +{ + int y; + for (y = 0; y < h; y++) { + unsigned short *dst = (unsigned short*)dstbase; + int x; + for (x = 0; x < w; x++) { + dst[x] = (-srca[x] << 8) | src[x]; + } + src += srcstride; + srca += srcstride; + dstbase += dststride; + } +} + +/** @brief Callback function to render the OSD to the texture + */ +static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, + unsigned char *srca, int stride) +{ + D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order + to copy MPlayer's frame inside it.*/ + + if (FAILED(IDirect3DTexture9_LockRect(priv->d3d_texture_system, 0, + &locked_rect, NULL, 0))) { + mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>IDirect3DTexture9_LockRect failure.\n"); + return; + } + + vo_draw_alpha_l8a8(w, h, src, srca, stride, + (unsigned char *)locked_rect.pBits + locked_rect.Pitch*y0 + 2*x0, locked_rect.Pitch); + + /* this unlock is used for both slice_draw path and D3DRenderFrame path */ + if (FAILED(IDirect3DTexture9_UnlockRect(priv->d3d_texture_system, 0))) { + mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>IDirect3DTexture9_UnlockRect failure.\n"); + return; + } + + priv->is_osd_populated = 1; +} + +/** @brief libvo Callback: Draw OSD/Subtitles, + */ +static void draw_osd(void) +{ + if (vo_osd_changed(0)) { + D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order + to copy MPlayer's frame inside it.*/ + + /* clear the OSD */ + if (FAILED(IDirect3DTexture9_LockRect(priv->d3d_texture_system, 0, + &locked_rect, NULL, 0))) { + mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>IDirect3DTexture9_LockRect failure.\n"); + return; + } + + /* clear the whole texture to avoid issues due to interpolation */ + memset(locked_rect.pBits, 0, locked_rect.Pitch * priv->osd_texture_height); + + /* this unlock is used for both slice_draw path and D3DRenderFrame path */ + if (FAILED(IDirect3DTexture9_UnlockRect(priv->d3d_texture_system, 0))) { + mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>IDirect3DTexture9_UnlockRect failure.\n"); + return; + } + + priv->is_osd_populated = 0; + /* required for if subs are in the boarder region */ + priv->is_clear_needed = 1; + + vo_draw_text(priv->osd_width, priv->osd_height, draw_alpha); + + if (!priv->device_texture_sys) + { + /* only DMA to the shadow if its required */ + if (FAILED(IDirect3DDevice9_UpdateTexture(priv->d3d_device, + (IDirect3DBaseTexture9 *)priv->d3d_texture_system, + (IDirect3DBaseTexture9 *)priv->d3d_texture_osd))) { + mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>IDirect3DDevice9_UpdateTexture failure.\n"); + return; + } + } + } + + /* update OSD */ + + if (priv->is_osd_populated) { + + struct_vertex osd_quad_vb[] = { + {-1.0f, 1.0f, 0.0f, 0, 0 }, + { 1.0f, 1.0f, 0.0f, 1, 0 }, + {-1.0f,-1.0f, 0.0f, 0, 1 }, + { 1.0f,-1.0f, 0.0f, 1, 1 } + }; + + /* calculate the texture coordinates */ + osd_quad_vb[1].tu = + osd_quad_vb[3].tu = (float)priv->osd_width / priv->osd_texture_width; + osd_quad_vb[2].tv = + osd_quad_vb[3].tv = (float)priv->osd_height / priv->osd_texture_height; + + if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) { + mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed\n"); + return; + } + + /* turn on alpha test */ + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHABLENDENABLE, TRUE); + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHATESTENABLE, TRUE); + + /* need to use a texture here (done here as we may be able to texture from system memory) */ + IDirect3DDevice9_SetTexture(priv->d3d_device, 0, + (IDirect3DBaseTexture9 *)(priv->device_texture_sys + ? priv->d3d_texture_system : priv->d3d_texture_osd)); + + IDirect3DDevice9_SetFVF(priv->d3d_device, D3DFVF_MY_VERTEX); + IDirect3DDevice9_DrawPrimitiveUP(priv->d3d_device, D3DPT_TRIANGLESTRIP, 2, osd_quad_vb, sizeof(struct_vertex)); + + /* turn off alpha test */ + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHATESTENABLE, FALSE); + IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHABLENDENABLE, FALSE); + + if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) { + mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed\n"); + return; + } + } +} diff --git a/libvo/vo_gl.c b/libvo/vo_gl.c index a9a2690756..7ad0189a63 100644 --- a/libvo/vo_gl.c +++ b/libvo/vo_gl.c @@ -177,7 +177,8 @@ static void texSize(int w, int h, int *texw, int *texh) { while (*texh < h) *texh *= 2; } - if (ati_hack) *texw = (*texw + 511) & ~511; + if (mesa_buffer) *texw = (*texw + 63) & ~63; + else if (ati_hack) *texw = (*texw + 511) & ~511; } //! maximum size of custom fragment program @@ -400,11 +401,21 @@ static void uninitGl(void) { err_shown = 0; } +static void autodetectGlExtensions(void) { + const char *extensions = glGetString(GL_EXTENSIONS); + const char *vendor = glGetString(GL_VENDOR); + int is_ati = strstr(vendor, "ATI") != NULL; + if (ati_hack == -1) ati_hack = is_ati; + if (force_pbo == -1) force_pbo = strstr(extensions, "_pixel_buffer_object") ? is_ati : 0; + if (use_rectangle == -1) use_rectangle = strstr(extensions, "_texture_non_power_of_two") ? 2 : 0; +} + /** * \brief Initialize a (new or reused) OpenGL context. * set global gl-related variables to their default values */ static int initGl(uint32_t d_width, uint32_t d_height) { + autodetectGlExtensions(); texSize(image_width, image_height, &texture_width, &texture_height); glDisable(GL_BLEND); @@ -698,7 +709,8 @@ static uint32_t get_image(mp_image_t *mpi) { return VO_FALSE; } if (mpi->flags & MP_IMGFLAG_READABLE) return VO_FALSE; - if (ati_hack) { + if (mesa_buffer) mpi->width = texture_width; + else if (ati_hack) { mpi->width = texture_width; mpi->height = texture_height; } @@ -744,7 +756,7 @@ static uint32_t get_image(mp_image_t *mpi) { mpi->stride[1] = mpi->width >> 1; mpi->planes[2] = mpi->planes[1] + mpi->stride[1] * (mpi->height >> 1); mpi->stride[2] = mpi->width >> 1; - if (ati_hack) { + if (ati_hack && !mesa_buffer) { mpi->flags &= ~MP_IMGFLAG_COMMON_PLANE; if (!gl_buffer_uv[0]) GenBuffers(2, gl_buffer_uv); if (mpi->stride[1] * mpi->height > gl_buffersize_uv) { @@ -776,7 +788,6 @@ static uint32_t draw_image(mp_image_t *mpi) { unsigned char *planes[3]; mp_image_t mpi2 = *mpi; int w = mpi->w, h = mpi->h; - if (ati_hack) { w = texture_width; h = texture_height; } if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) goto skip_upload; mpi2.flags = 0; mpi2.type = MP_IMGTYPE_TEMP; @@ -793,21 +804,26 @@ static uint32_t draw_image(mp_image_t *mpi) { stride[0] = mpi->stride[0]; stride[1] = mpi->stride[1]; stride[2] = mpi->stride[2]; planes[0] = mpi->planes[0]; planes[1] = mpi->planes[1]; planes[2] = mpi->planes[2]; mpi_flipped = stride[0] < 0; - if (!mesa_buffer && mpi->flags & MP_IMGFLAG_DIRECT) { - intptr_t base = (intptr_t)planes[0]; - if (mpi_flipped) - base += (mpi->h - 1) * stride[0]; - planes[0] -= base; - planes[1] -= base; - planes[2] -= base; - BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer); - UnmapBuffer(GL_PIXEL_UNPACK_BUFFER); - gl_bufferptr = NULL; - if (!(mpi->flags & MP_IMGFLAG_COMMON_PLANE)) - planes[0] = planes[1] = planes[2] = NULL; - } - if (mpi->flags & MP_IMGFLAG_DIRECT) + if (mpi->flags & MP_IMGFLAG_DIRECT) { + if (mesa_buffer) { + glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1); + w = texture_width; + } else { + intptr_t base = (intptr_t)planes[0]; + if (ati_hack) { w = texture_width; h = texture_height; } + if (mpi_flipped) + base += (mpi->h - 1) * stride[0]; + planes[0] -= base; + planes[1] -= base; + planes[2] -= base; + BindBuffer(GL_PIXEL_UNPACK_BUFFER, gl_buffer); + UnmapBuffer(GL_PIXEL_UNPACK_BUFFER); + gl_bufferptr = NULL; + if (!(mpi->flags & MP_IMGFLAG_COMMON_PLANE)) + planes[0] = planes[1] = planes[2] = NULL; + } slice = 0; // always "upload" full texture + } glUploadTex(gl_target, gl_format, gl_type, planes[0], stride[0], mpi->x, mpi->y, w, h, slice); if (mpi->imgfmt == IMGFMT_YV12) { @@ -829,8 +845,10 @@ static uint32_t draw_image(mp_image_t *mpi) { mpi->x / 2, mpi->y / 2, w / 2, h / 2, slice); ActiveTexture(GL_TEXTURE0); } - if (!mesa_buffer && mpi->flags & MP_IMGFLAG_DIRECT) - BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + if (mpi->flags & MP_IMGFLAG_DIRECT) { + if (mesa_buffer) glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 0); + else BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + } skip_upload: if (vo_doublebuffering) do_render(); return VO_TRUE; @@ -917,10 +935,10 @@ static int preinit(const char *arg) lscale = 0; cscale = 0; filter_strength = 0.5; - use_rectangle = 0; + use_rectangle = -1; use_glFinish = 0; - ati_hack = 0; - force_pbo = 0; + ati_hack = -1; + force_pbo = -1; mesa_buffer = 0; swap_interval = 1; slice_height = 0; diff --git a/libvo/vo_macosx.m b/libvo/vo_macosx.m index daede69573..24ffdc1e1f 100644 --- a/libvo/vo_macosx.m +++ b/libvo/vo_macosx.m @@ -10,6 +10,7 @@ #include <sys/types.h> #include <sys/ipc.h> #include <sys/mman.h> +#include <unistd.h> #include <CoreServices/CoreServices.h> //special workaround for Apple bug #6267445 //(OSServices Power API disabled in OSServices.h for 64bit systems) @@ -25,6 +26,8 @@ #include "aspect.h" #include "mp_msg.h" #include "m_option.h" +#include "mp_fifo.h" +#include "libvo/sub.h" #include "input/input.h" #include "input/mouse.h" @@ -729,7 +732,6 @@ static int control(uint32_t request, void *data) - (void) render { int curTime; - static int lastTime = 0; glClear(GL_COLOR_BUFFER_BIT); diff --git a/libvo/vo_png.c b/libvo/vo_png.c index ac0e99587e..c1a93c26f0 100644 --- a/libvo/vo_png.c +++ b/libvo/vo_png.c @@ -34,6 +34,7 @@ const LIBVO_EXTERN (png) static int z_compression = Z_NO_COMPRESSION; static int framenum = 0; +static int use_alpha; struct pngdata { FILE * fp; @@ -111,7 +112,7 @@ static struct pngdata create_png (char * fname, int image_width, int image_heigh bit_depth, color_type, interlace_type, compression_type, filter_type)*/ png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height, - 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, + 8, use_alpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write Info\n"); @@ -190,10 +191,14 @@ static int draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) static int query_format(uint32_t format) { + const int supported_flags = VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; switch(format){ case IMGFMT_RGB24: case IMGFMT_BGR24: - return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; + return use_alpha ? 0 : supported_flags; + case IMGFMT_RGBA: + case IMGFMT_BGRA: + return use_alpha ? supported_flags : 0; } return 0; } @@ -210,6 +215,7 @@ static int int_zero_to_nine(int *sh) } static opt_t subopts[] = { + {"alpha", OPT_ARG_BOOL, &use_alpha, NULL, 0}, {"z", OPT_ARG_INT, &z_compression, (opt_test_f)int_zero_to_nine}, {NULL} }; @@ -217,6 +223,7 @@ static opt_t subopts[] = { static int preinit(const char *arg) { z_compression = 0; + use_alpha = 0; if (subopt_parse(arg, subopts) != 0) { return -1; } diff --git a/libvo/vo_quartz.c b/libvo/vo_quartz.c index cc7cdb922b..f8b760e097 100644 --- a/libvo/vo_quartz.c +++ b/libvo/vo_quartz.c @@ -30,6 +30,7 @@ #include "m_option.h" #include "mp_fifo.h" #include "mpbswap.h" +#include "libvo/sub.h" #include "input/input.h" #include "input/mouse.h" |