2008-11-18 12:23:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Georgi Petrov (gogothebee) <gogothebee@gmail.com>
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2008-11-18 12:23:42 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2008-11-18 12:23:42 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2008-11-18 12:23:42 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2008-11-18 12:23:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
2011-10-26 09:44:30 +00:00
|
|
|
#include <stdlib.h>
|
2011-11-01 01:38:17 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
2011-10-26 09:44:30 +00:00
|
|
|
#include <assert.h>
|
2008-11-18 12:23:42 +00:00
|
|
|
#include <d3d9.h>
|
2013-07-19 01:25:04 +00:00
|
|
|
#include <inttypes.h>
|
2016-08-14 19:45:27 +00:00
|
|
|
#include <limits.h>
|
2008-11-18 12:23:42 +00:00
|
|
|
#include "config.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
|
|
|
#include "options/m_option.h"
|
2020-05-13 20:50:31 +00:00
|
|
|
#include "sub/draw_bmp.h"
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "vo.h"
|
|
|
|
#include "video/csputils.h"
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "video/img_format.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2014-04-19 15:18:10 +00:00
|
|
|
#include "common/common.h"
|
2008-11-18 12:23:42 +00:00
|
|
|
#include "w32_common.h"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "sub/osd.h"
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2017-10-10 13:51:16 +00:00
|
|
|
#include "config.h"
|
|
|
|
#if !HAVE_GPL
|
|
|
|
#error GPL only
|
|
|
|
#endif
|
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
#define DEVTYPE D3DDEVTYPE_HAL
|
|
|
|
//#define DEVTYPE D3DDEVTYPE_REF
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
#define D3DFVF_OSD_VERTEX (D3DFVF_XYZ | D3DFVF_TEX1)
|
2011-10-26 09:44:30 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float x, y, z;
|
|
|
|
float tu, tv;
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
} vertex_osd;
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2011-11-01 01:38:17 +00:00
|
|
|
struct d3dtex {
|
|
|
|
// user-requested size
|
|
|
|
int w, h;
|
|
|
|
// allocated texture size
|
|
|
|
int tex_w, tex_h;
|
2011-11-04 10:32:19 +00:00
|
|
|
// D3DPOOL_SYSTEMMEM (or others) texture:
|
2011-11-01 01:38:17 +00:00
|
|
|
// - can be locked in order to write (and even read) data
|
|
|
|
// - can _not_ (probably) be used as texture for rendering
|
|
|
|
// This is always non-NULL if d3dtex_allocate succeeds.
|
|
|
|
IDirect3DTexture9 *system;
|
|
|
|
// D3DPOOL_DEFAULT texture:
|
|
|
|
// - can't be locked (Probably.)
|
|
|
|
// - must be used for rendering
|
2014-11-18 15:30:24 +00:00
|
|
|
// This can be NULL if the system one can be both locked and mapped.
|
2011-11-01 01:38:17 +00:00
|
|
|
IDirect3DTexture9 *device;
|
|
|
|
};
|
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
#define MAX_OSD_RECTS 64
|
2012-10-04 15:16:21 +00:00
|
|
|
|
2008-11-20 15:13:14 +00:00
|
|
|
/* Global variables "priv" structure. I try to keep their count low.
|
2008-11-18 12:23:42 +00:00
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
typedef struct d3d_priv {
|
2013-08-23 21:30:09 +00:00
|
|
|
struct mp_log *log;
|
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
int opt_disable_texture_align;
|
2011-11-04 10:32:19 +00:00
|
|
|
// debugging
|
2011-11-04 09:02:12 +00:00
|
|
|
int opt_force_power_of_2;
|
2011-11-04 10:32:19 +00:00
|
|
|
int opt_texture_memory;
|
|
|
|
int opt_swap_discard;
|
|
|
|
int opt_exact_backbuffer;
|
2011-11-01 22:20:38 +00:00
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
struct vo *vo;
|
|
|
|
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
bool have_image;
|
2014-06-15 18:46:57 +00:00
|
|
|
double osd_pts;
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
|
2009-02-03 10:17:14 +00:00
|
|
|
D3DLOCKED_RECT locked_rect; /**< The locked offscreen surface */
|
2008-11-20 15:13:14 +00:00
|
|
|
RECT fs_movie_rect; /**< Rect (upscaled) of the movie when displayed
|
|
|
|
in fullscreen */
|
|
|
|
RECT fs_panscan_rect; /**< PanScan source surface cropping in
|
|
|
|
fullscreen */
|
|
|
|
int src_width; /**< Source (movie) width */
|
2022-04-25 11:27:18 +00:00
|
|
|
int src_height; /**< Source (movie) height */
|
2012-10-27 20:10:32 +00:00
|
|
|
struct mp_osd_res osd_res;
|
2011-11-01 22:20:38 +00:00
|
|
|
int image_format; /**< mplayer image format */
|
2014-03-28 23:25:08 +00:00
|
|
|
struct mp_image_params params;
|
2008-11-20 15:13:14 +00:00
|
|
|
|
|
|
|
D3DFORMAT movie_src_fmt; /**< Movie colorspace format (depends on
|
|
|
|
the movie's codec) */
|
|
|
|
D3DFORMAT desktop_fmt; /**< Desktop (screen) colorspace format.
|
|
|
|
Usually XRGB */
|
2010-01-03 17:00:51 +00:00
|
|
|
|
|
|
|
HANDLE d3d9_dll; /**< d3d9 Library HANDLE */
|
|
|
|
IDirect3D9 * (WINAPI *pDirect3DCreate9)(UINT); /**< pointer to Direct3DCreate9 function */
|
|
|
|
|
2008-11-20 15:13:14 +00:00
|
|
|
LPDIRECT3D9 d3d_handle; /**< Direct3D Handle */
|
|
|
|
LPDIRECT3DDEVICE9 d3d_device; /**< The Direct3D Adapter */
|
2011-11-01 22:20:38 +00:00
|
|
|
bool d3d_in_scene; /**< BeginScene was called, EndScene not */
|
2008-11-20 15:13:14 +00:00
|
|
|
IDirect3DSurface9 *d3d_surface; /**< Offscreen Direct3D Surface. MPlayer
|
|
|
|
renders inside it. Uses colorspace
|
|
|
|
priv->movie_src_fmt */
|
|
|
|
IDirect3DSurface9 *d3d_backbuf; /**< Video card's back buffer (used to
|
|
|
|
display next frame) */
|
2009-01-27 10:02:47 +00:00
|
|
|
int cur_backbuf_width; /**< Current backbuffer width */
|
|
|
|
int cur_backbuf_height; /**< Current backbuffer height */
|
2008-12-09 18:31:52 +00:00
|
|
|
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 */
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
D3DMATRIX d3d_colormatrix;
|
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
struct mp_draw_sub_cache *osd_cache;
|
|
|
|
struct d3dtex osd_texture;
|
|
|
|
int osd_num_vertices;
|
|
|
|
vertex_osd osd_vertices[MAX_OSD_RECTS * 6];
|
2011-11-04 06:33:51 +00:00
|
|
|
} d3d_priv;
|
2008-11-20 15:13:14 +00:00
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
struct fmt_entry {
|
2008-11-20 15:13:14 +00:00
|
|
|
const unsigned int mplayer_fmt; /**< Given by MPlayer */
|
|
|
|
const D3DFORMAT fourcc; /**< Required by D3D's test function */
|
2011-11-01 22:20:38 +00:00
|
|
|
};
|
2008-11-18 12:23:42 +00:00
|
|
|
|
|
|
|
/* Map table from reported MPlayer format to the required
|
2008-11-20 15:13:14 +00:00
|
|
|
fourcc. This is needed to perform the format query. */
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
static const struct fmt_entry fmt_table[] = {
|
|
|
|
// planar YUV
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
{IMGFMT_420P, MAKEFOURCC('Y','V','1','2')},
|
|
|
|
{IMGFMT_420P, MAKEFOURCC('I','4','2','0')},
|
|
|
|
{IMGFMT_420P, MAKEFOURCC('I','Y','U','V')},
|
2014-10-26 00:36:15 +00:00
|
|
|
{IMGFMT_NV12, MAKEFOURCC('N','V','1','2')},
|
2011-11-01 22:20:38 +00:00
|
|
|
// packed YUV
|
2008-11-26 16:30:42 +00:00
|
|
|
{IMGFMT_UYVY, D3DFMT_UYVY},
|
2011-11-01 22:20:38 +00:00
|
|
|
// packed RGB
|
2020-05-11 17:37:16 +00:00
|
|
|
{IMGFMT_BGR0, D3DFMT_X8R8G8B8},
|
|
|
|
{IMGFMT_RGB0, D3DFMT_X8B8G8R8},
|
2008-11-26 16:27:39 +00:00
|
|
|
{IMGFMT_BGR24, D3DFMT_R8G8B8}, //untested
|
2014-06-14 08:03:04 +00:00
|
|
|
{IMGFMT_RGB565, D3DFMT_R5G6B5},
|
2011-11-01 22:20:38 +00:00
|
|
|
{0},
|
2008-11-18 12:23:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
static bool resize_d3d(d3d_priv *priv);
|
2011-11-04 06:33:51 +00:00
|
|
|
static void uninit(struct vo *vo);
|
|
|
|
static void flip_page(struct vo *vo);
|
2011-11-27 18:58:04 +00:00
|
|
|
static mp_image_t *get_window_screenshot(d3d_priv *priv);
|
2014-06-15 18:46:57 +00:00
|
|
|
static void draw_osd(struct vo *vo);
|
2015-01-21 19:56:34 +00:00
|
|
|
static bool change_d3d_backbuffer(d3d_priv *priv);
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
static void d3d_matrix_identity(D3DMATRIX *m)
|
|
|
|
{
|
|
|
|
memset(m, 0, sizeof(D3DMATRIX));
|
|
|
|
m->_11 = m->_22 = m->_33 = m->_44 = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d_matrix_ortho(D3DMATRIX *m, float left, float right,
|
|
|
|
float bottom, float top)
|
|
|
|
{
|
|
|
|
d3d_matrix_identity(m);
|
|
|
|
m->_11 = 2.0f / (right - left);
|
|
|
|
m->_22 = 2.0f / (top - bottom);
|
|
|
|
m->_33 = 1.0f;
|
|
|
|
m->_41 = -(right + left) / (right - left);
|
|
|
|
m->_42 = -(top + bottom) / (top - bottom);
|
|
|
|
m->_43 = 0;
|
|
|
|
m->_44 = 1.0f;
|
|
|
|
}
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* Direct3D specific implementation functions *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
static bool d3d_begin_scene(d3d_priv *priv)
|
2011-11-01 22:20:38 +00:00
|
|
|
{
|
|
|
|
if (!priv->d3d_in_scene) {
|
|
|
|
if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "BeginScene failed.\n");
|
2011-11-01 22:20:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
priv->d3d_in_scene = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
/** @brief Calculate scaled fullscreen movie rectangle with
|
|
|
|
* preserved aspect ratio.
|
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
static void calc_fs_rect(d3d_priv *priv)
|
2008-11-18 12:23:42 +00:00
|
|
|
{
|
2012-10-27 20:10:32 +00:00
|
|
|
struct mp_rect src_rect;
|
|
|
|
struct mp_rect dst_rect;
|
|
|
|
vo_get_src_dst_rects(priv->vo, &src_rect, &dst_rect, &priv->osd_res);
|
|
|
|
|
|
|
|
priv->fs_movie_rect.left = dst_rect.x0;
|
|
|
|
priv->fs_movie_rect.right = dst_rect.x1;
|
|
|
|
priv->fs_movie_rect.top = dst_rect.y0;
|
|
|
|
priv->fs_movie_rect.bottom = dst_rect.y1;
|
|
|
|
priv->fs_panscan_rect.left = src_rect.x0;
|
|
|
|
priv->fs_panscan_rect.right = src_rect.x1;
|
|
|
|
priv->fs_panscan_rect.top = src_rect.y0;
|
|
|
|
priv->fs_panscan_rect.bottom = src_rect.y1;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
2011-10-26 09:44:30 +00:00
|
|
|
// Adjust the texture size *width/*height to fit the requirements of the D3D
|
|
|
|
// device. The texture size is only increased.
|
2011-11-04 06:33:51 +00:00
|
|
|
static void d3d_fix_texture_size(d3d_priv *priv, int *width, int *height)
|
2011-10-26 09:44:30 +00:00
|
|
|
{
|
|
|
|
int tex_width = *width;
|
|
|
|
int tex_height = *height;
|
|
|
|
|
2011-11-01 01:38:17 +00:00
|
|
|
// avoid nasty special cases with 0-sized textures and texture sizes
|
2014-04-19 15:18:10 +00:00
|
|
|
tex_width = MPMAX(tex_width, 1);
|
|
|
|
tex_height = MPMAX(tex_height, 1);
|
2011-11-01 01:38:17 +00:00
|
|
|
|
2011-10-26 09:44:30 +00:00
|
|
|
if (priv->device_caps_power2_only) {
|
|
|
|
tex_width = 1;
|
|
|
|
tex_height = 1;
|
|
|
|
while (tex_width < *width) tex_width <<= 1;
|
|
|
|
while (tex_height < *height) tex_height <<= 1;
|
|
|
|
}
|
|
|
|
if (priv->device_caps_square_only)
|
|
|
|
/* device only supports square textures */
|
2014-04-19 15:18:10 +00:00
|
|
|
tex_width = tex_height = MPMAX(tex_width, tex_height);
|
2011-10-26 09:44:30 +00:00
|
|
|
// better round up to a multiple of 16
|
2011-11-01 22:20:38 +00:00
|
|
|
if (!priv->opt_disable_texture_align) {
|
|
|
|
tex_width = (tex_width + 15) & ~15;
|
|
|
|
tex_height = (tex_height + 15) & ~15;
|
|
|
|
}
|
2011-10-26 09:44:30 +00:00
|
|
|
|
|
|
|
*width = tex_width;
|
|
|
|
*height = tex_height;
|
2008-12-02 09:36:47 +00:00
|
|
|
}
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
static void d3dtex_release(d3d_priv *priv, struct d3dtex *tex)
|
2011-11-01 01:38:17 +00:00
|
|
|
{
|
|
|
|
if (tex->system)
|
|
|
|
IDirect3DTexture9_Release(tex->system);
|
|
|
|
tex->system = NULL;
|
|
|
|
|
|
|
|
if (tex->device)
|
|
|
|
IDirect3DTexture9_Release(tex->device);
|
|
|
|
tex->device = NULL;
|
|
|
|
|
|
|
|
tex->tex_w = tex->tex_h = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
static bool d3dtex_allocate(d3d_priv *priv, struct d3dtex *tex, D3DFORMAT fmt,
|
|
|
|
int w, int h)
|
2011-11-01 01:38:17 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
d3dtex_release(priv, tex);
|
2011-11-01 01:38:17 +00:00
|
|
|
|
|
|
|
tex->w = w;
|
|
|
|
tex->h = h;
|
|
|
|
|
|
|
|
int tw = w, th = h;
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_fix_texture_size(priv, &tw, &th);
|
2011-11-01 01:38:17 +00:00
|
|
|
|
2014-11-18 15:30:24 +00:00
|
|
|
bool use_sh = !priv->device_texture_sys;
|
2011-11-04 10:32:19 +00:00
|
|
|
int memtype = D3DPOOL_SYSTEMMEM;
|
|
|
|
switch (priv->opt_texture_memory) {
|
2014-11-18 15:30:24 +00:00
|
|
|
case 1: memtype = D3DPOOL_MANAGED; use_sh = false; break;
|
|
|
|
case 2: memtype = D3DPOOL_DEFAULT; use_sh = false; break;
|
|
|
|
case 3: memtype = D3DPOOL_DEFAULT; use_sh = true; break;
|
|
|
|
case 4: memtype = D3DPOOL_SCRATCH; use_sh = true; break;
|
2011-11-04 10:32:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 01:38:17 +00:00
|
|
|
if (FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, tw, th, 1,
|
2011-11-04 10:32:19 +00:00
|
|
|
D3DUSAGE_DYNAMIC, fmt, memtype, &tex->system, NULL)))
|
2011-11-01 01:38:17 +00:00
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Allocating %dx%d texture in system RAM failed.\n", w, h);
|
2011-11-01 01:38:17 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
2014-11-18 15:30:24 +00:00
|
|
|
if (use_sh) {
|
2011-11-01 01:38:17 +00:00
|
|
|
if (FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, tw, th, 1,
|
|
|
|
D3DUSAGE_DYNAMIC, fmt, D3DPOOL_DEFAULT, &tex->device, NULL)))
|
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Allocating %dx%d texture in video RAM failed.\n", w, h);
|
2011-11-01 01:38:17 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tex->tex_w = tw;
|
|
|
|
tex->tex_h = th;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error_exit:
|
2011-11-04 06:33:51 +00:00
|
|
|
d3dtex_release(priv, tex);
|
2011-11-01 01:38:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
static IDirect3DBaseTexture9 *d3dtex_get_render_texture(d3d_priv *priv,
|
|
|
|
struct d3dtex *tex)
|
2011-11-01 01:38:17 +00:00
|
|
|
{
|
2011-11-01 22:20:38 +00:00
|
|
|
return (IDirect3DBaseTexture9 *)(tex->device ? tex->device : tex->system);
|
2011-11-01 01:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy system texture contents to device texture.
|
2011-11-04 06:33:51 +00:00
|
|
|
static bool d3dtex_update(d3d_priv *priv, struct d3dtex *tex)
|
2011-11-01 01:38:17 +00:00
|
|
|
{
|
2011-11-01 22:20:38 +00:00
|
|
|
if (!tex->device)
|
2011-11-01 01:38:17 +00:00
|
|
|
return true;
|
|
|
|
return !FAILED(IDirect3DDevice9_UpdateTexture(priv->d3d_device,
|
|
|
|
(IDirect3DBaseTexture9 *)tex->system,
|
|
|
|
(IDirect3DBaseTexture9 *)tex->device));
|
|
|
|
}
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
static void d3d_unlock_video_objects(d3d_priv *priv)
|
2011-11-01 01:38:17 +00:00
|
|
|
{
|
2011-11-01 22:20:38 +00:00
|
|
|
if (priv->locked_rect.pBits) {
|
|
|
|
if (FAILED(IDirect3DSurface9_UnlockRect(priv->d3d_surface)))
|
2020-05-13 19:35:32 +00:00
|
|
|
MP_VERBOSE(priv, "Unlocking video objects failed.\n");
|
2011-11-01 22:20:38 +00:00
|
|
|
}
|
2011-11-01 01:38:17 +00:00
|
|
|
priv->locked_rect.pBits = NULL;
|
2011-11-01 22:20:38 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
// Free video surface/textures, etc.
|
2011-11-04 06:33:51 +00:00
|
|
|
static void d3d_destroy_video_objects(d3d_priv *priv)
|
2011-11-01 22:20:38 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_unlock_video_objects(priv);
|
2011-11-01 22:20:38 +00:00
|
|
|
|
2011-11-01 01:38:17 +00:00
|
|
|
if (priv->d3d_surface)
|
|
|
|
IDirect3DSurface9_Release(priv->d3d_surface);
|
|
|
|
priv->d3d_surface = NULL;
|
2011-11-01 22:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Destroy D3D Offscreen and Backbuffer surfaces.
|
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
static void destroy_d3d_surfaces(d3d_priv *priv)
|
2011-11-01 22:20:38 +00:00
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "destroy_d3d_surfaces called.\n");
|
2011-11-01 22:20:38 +00:00
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_destroy_video_objects(priv);
|
2020-05-13 20:50:31 +00:00
|
|
|
d3dtex_release(priv, &priv->osd_texture);
|
2011-11-01 01:38:17 +00:00
|
|
|
|
|
|
|
if (priv->d3d_backbuf)
|
|
|
|
IDirect3DSurface9_Release(priv->d3d_backbuf);
|
|
|
|
priv->d3d_backbuf = NULL;
|
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
priv->d3d_in_scene = false;
|
2011-11-01 01:38:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
// Allocate video surface.
|
2011-11-04 06:33:51 +00:00
|
|
|
static bool d3d_configure_video_objects(d3d_priv *priv)
|
2011-11-01 22:20:38 +00:00
|
|
|
{
|
|
|
|
assert(priv->image_format != 0);
|
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
if (!priv->d3d_surface &&
|
|
|
|
FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface(
|
|
|
|
priv->d3d_device, priv->src_width, priv->src_height,
|
|
|
|
priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL)))
|
|
|
|
{
|
|
|
|
MP_ERR(priv, "Allocating offscreen surface failed.\n");
|
|
|
|
return false;
|
2011-11-01 22:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
// Recreate and initialize D3D objects if necessary. The amount of work that
|
|
|
|
// needs to be done can be quite different: it could be that full initialization
|
|
|
|
// is required, or that some objects need to be created, or that nothing is
|
|
|
|
// done.
|
|
|
|
static bool create_d3d_surfaces(d3d_priv *priv)
|
2008-12-02 09:36:47 +00:00
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "create_d3d_surfaces called.\n");
|
2008-12-02 09:36:47 +00:00
|
|
|
|
2009-01-27 10:02:47 +00:00
|
|
|
if (!priv->d3d_backbuf &&
|
|
|
|
FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0,
|
2008-12-02 09:36:47 +00:00
|
|
|
D3DBACKBUFFER_TYPE_MONO,
|
2008-12-02 09:46:08 +00:00
|
|
|
&priv->d3d_backbuf))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Allocating backbuffer failed.\n");
|
2008-12-02 09:36:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
if (!d3d_configure_video_objects(priv))
|
2011-11-01 22:20:38 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-12-09 18:31:52 +00:00
|
|
|
/* setup default renderstate */
|
2011-11-04 06:33:51 +00:00
|
|
|
IDirect3DDevice9_SetRenderState(priv->d3d_device,
|
|
|
|
D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
|
|
|
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);
|
2011-11-01 22:20:38 +00:00
|
|
|
|
|
|
|
// we use up to 3 samplers for up to 3 YUV planes
|
2020-05-13 19:35:32 +00:00
|
|
|
// TODO
|
|
|
|
/*
|
2011-11-01 22:20:38 +00:00
|
|
|
for (int n = 0; n < 3; n++) {
|
|
|
|
IDirect3DDevice9_SetSamplerState(priv->d3d_device, n, D3DSAMP_MINFILTER,
|
|
|
|
D3DTEXF_LINEAR);
|
|
|
|
IDirect3DDevice9_SetSamplerState(priv->d3d_device, n, D3DSAMP_MAGFILTER,
|
|
|
|
D3DTEXF_LINEAR);
|
|
|
|
IDirect3DDevice9_SetSamplerState(priv->d3d_device, n, D3DSAMP_ADDRESSU,
|
|
|
|
D3DTADDRESS_CLAMP);
|
|
|
|
IDirect3DDevice9_SetSamplerState(priv->d3d_device, n, D3DSAMP_ADDRESSV,
|
|
|
|
D3DTADDRESS_CLAMP);
|
|
|
|
}
|
2020-05-13 19:35:32 +00:00
|
|
|
*/
|
2008-12-09 18:31:52 +00:00
|
|
|
|
2008-12-02 09:36:47 +00:00
|
|
|
return 1;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
static bool init_d3d(d3d_priv *priv)
|
|
|
|
{
|
|
|
|
D3DDISPLAYMODE disp_mode;
|
|
|
|
D3DCAPS9 disp_caps;
|
|
|
|
DWORD texture_caps;
|
|
|
|
DWORD dev_caps;
|
|
|
|
|
|
|
|
priv->d3d_handle = priv->pDirect3DCreate9(D3D_SDK_VERSION);
|
|
|
|
if (!priv->d3d_handle) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Initializing Direct3D failed.\n");
|
2011-11-04 09:02:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
|
|
|
|
D3DADAPTER_DEFAULT,
|
|
|
|
&disp_mode))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Reading display mode failed.\n");
|
2011-11-04 09:02:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->desktop_fmt = disp_mode.Format;
|
|
|
|
priv->cur_backbuf_width = disp_mode.Width;
|
|
|
|
priv->cur_backbuf_height = disp_mode.Height;
|
|
|
|
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "Setting backbuffer dimensions to (%dx%d).\n",
|
|
|
|
disp_mode.Width, disp_mode.Height);
|
2011-11-04 09:02:12 +00:00
|
|
|
|
|
|
|
if (FAILED(IDirect3D9_GetDeviceCaps(priv->d3d_handle,
|
|
|
|
D3DADAPTER_DEFAULT,
|
|
|
|
DEVTYPE,
|
|
|
|
&disp_caps)))
|
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Reading display capabilities failed.\n");
|
2011-11-04 09:02:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
if (priv->opt_force_power_of_2)
|
|
|
|
priv->device_caps_power2_only = 1;
|
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
if (FAILED(IDirect3D9_CheckDeviceFormat(priv->d3d_handle,
|
|
|
|
D3DADAPTER_DEFAULT,
|
|
|
|
DEVTYPE,
|
|
|
|
priv->desktop_fmt,
|
|
|
|
D3DUSAGE_DYNAMIC | D3DUSAGE_QUERY_FILTER,
|
|
|
|
D3DRTYPE_TEXTURE,
|
|
|
|
D3DFMT_A8R8G8B8)))
|
|
|
|
{
|
|
|
|
MP_ERR(priv, "OSD texture format not supported.\n");
|
|
|
|
return false;
|
2014-11-27 18:54:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-21 19:56:34 +00:00
|
|
|
if (!change_d3d_backbuffer(priv))
|
|
|
|
return false;
|
|
|
|
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "device_caps_power2_only %d, device_caps_square_only %d\n"
|
|
|
|
"device_texture_sys %d\n"
|
|
|
|
"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);
|
2011-11-04 09:02:12 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-02 09:36:47 +00:00
|
|
|
/** @brief Fill D3D Presentation parameters
|
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
static void fill_d3d_presentparams(d3d_priv *priv,
|
|
|
|
D3DPRESENT_PARAMETERS *present_params)
|
2008-12-02 09:36:47 +00:00
|
|
|
{
|
|
|
|
/* Prepare Direct3D initialization parameters. */
|
|
|
|
memset(present_params, 0, sizeof(D3DPRESENT_PARAMETERS));
|
|
|
|
present_params->Windowed = TRUE;
|
2011-11-04 10:32:19 +00:00
|
|
|
present_params->SwapEffect =
|
|
|
|
priv->opt_swap_discard ? D3DSWAPEFFECT_DISCARD : D3DSWAPEFFECT_COPY;
|
2008-12-02 09:36:47 +00:00
|
|
|
present_params->Flags = D3DPRESENTFLAG_VIDEO;
|
2014-07-26 18:27:03 +00:00
|
|
|
present_params->hDeviceWindow = vo_w32_hwnd(priv->vo);
|
2009-01-27 10:02:47 +00:00
|
|
|
present_params->BackBufferWidth = priv->cur_backbuf_width;
|
|
|
|
present_params->BackBufferHeight = priv->cur_backbuf_height;
|
2008-12-02 09:36:47 +00:00
|
|
|
present_params->MultiSampleType = D3DMULTISAMPLE_NONE;
|
|
|
|
present_params->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
|
|
|
present_params->BackBufferFormat = priv->desktop_fmt;
|
|
|
|
present_params->BackBufferCount = 1;
|
|
|
|
present_params->EnableAutoDepthStencil = FALSE;
|
|
|
|
}
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2009-01-27 10:02:47 +00:00
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
// Create a new backbuffer. Create or Reset the D3D device.
|
|
|
|
static bool change_d3d_backbuffer(d3d_priv *priv)
|
2009-01-27 10:02:47 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
int window_w = priv->vo->dwidth;
|
|
|
|
int window_h = priv->vo->dheight;
|
2009-01-27 10:02:47 +00:00
|
|
|
|
|
|
|
/* Grow the backbuffer in the required dimension. */
|
2011-11-04 06:33:51 +00:00
|
|
|
if (window_w > priv->cur_backbuf_width)
|
|
|
|
priv->cur_backbuf_width = window_w;
|
2009-01-27 10:02:47 +00:00
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
if (window_h > priv->cur_backbuf_height)
|
|
|
|
priv->cur_backbuf_height = window_h;
|
2009-01-27 10:02:47 +00:00
|
|
|
|
2011-11-04 10:32:19 +00:00
|
|
|
if (priv->opt_exact_backbuffer) {
|
|
|
|
priv->cur_backbuf_width = window_w;
|
|
|
|
priv->cur_backbuf_height = window_h;
|
|
|
|
}
|
|
|
|
|
2009-01-27 10:02:47 +00:00
|
|
|
/* The grown backbuffer dimensions are ready and fill_d3d_presentparams
|
|
|
|
* will use them, so we can reset the device.
|
|
|
|
*/
|
2015-01-21 19:56:34 +00:00
|
|
|
D3DPRESENT_PARAMETERS present_params;
|
2011-11-04 06:33:51 +00:00
|
|
|
fill_d3d_presentparams(priv, &present_params);
|
2009-01-27 10:02:47 +00:00
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
if (!priv->d3d_device) {
|
|
|
|
if (FAILED(IDirect3D9_CreateDevice(priv->d3d_handle,
|
|
|
|
D3DADAPTER_DEFAULT,
|
2014-07-26 18:27:03 +00:00
|
|
|
DEVTYPE, vo_w32_hwnd(priv->vo),
|
2011-12-26 23:26:48 +00:00
|
|
|
D3DCREATE_SOFTWARE_VERTEXPROCESSING
|
2015-07-30 19:26:42 +00:00
|
|
|
| D3DCREATE_FPU_PRESERVE
|
|
|
|
| D3DCREATE_MULTITHREADED,
|
2011-11-04 09:02:12 +00:00
|
|
|
&present_params, &priv->d3d_device)))
|
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "Creating Direct3D device failed.\n");
|
2011-11-04 09:02:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (FAILED(IDirect3DDevice9_Reset(priv->d3d_device, &present_params))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Reseting Direct3D device failed.\n");
|
2011-11-04 09:02:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-27 10:02:47 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "New backbuffer (%dx%d), VO (%dx%d)\n",
|
|
|
|
present_params.BackBufferWidth, present_params.BackBufferHeight,
|
|
|
|
window_w, window_h);
|
2009-01-27 10:02:47 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-01-21 20:09:46 +00:00
|
|
|
static void destroy_d3d(d3d_priv *priv)
|
|
|
|
{
|
|
|
|
destroy_d3d_surfaces(priv);
|
|
|
|
|
|
|
|
if (priv->d3d_device)
|
|
|
|
IDirect3DDevice9_Release(priv->d3d_device);
|
|
|
|
priv->d3d_device = NULL;
|
|
|
|
|
|
|
|
if (priv->d3d_handle) {
|
|
|
|
MP_VERBOSE(priv, "Stopping Direct3D.\n");
|
|
|
|
IDirect3D9_Release(priv->d3d_handle);
|
|
|
|
}
|
|
|
|
priv->d3d_handle = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-02 09:36:47 +00:00
|
|
|
/** @brief Reconfigure the whole Direct3D. Called only
|
2011-11-04 09:02:12 +00:00
|
|
|
* when the video adapter becomes uncooperative. ("Lost" devices)
|
2008-12-02 09:36:47 +00:00
|
|
|
* @return 1 on success, 0 on failure
|
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
static int reconfigure_d3d(d3d_priv *priv)
|
2008-12-02 09:36:47 +00:00
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "reconfigure_d3d called.\n");
|
2008-12-02 09:36:47 +00:00
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
// Force complete destruction of the D3D state.
|
|
|
|
// Note: this step could be omitted. The resize_d3d call below would detect
|
|
|
|
// that d3d_device is NULL, and would properly recreate it. I'm not sure why
|
|
|
|
// the following code to release and recreate the d3d_handle exists.
|
2015-01-21 20:09:46 +00:00
|
|
|
destroy_d3d(priv);
|
2011-11-04 09:02:12 +00:00
|
|
|
if (!init_d3d(priv))
|
2009-02-03 10:14:44 +00:00
|
|
|
return 0;
|
2008-12-02 09:36:47 +00:00
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
// Proper re-initialization.
|
|
|
|
if (!resize_d3d(priv))
|
2008-12-02 09:36:47 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
// Resize Direct3D context on window resize.
|
|
|
|
// This function also is called when major initializations need to be done.
|
|
|
|
static bool resize_d3d(d3d_priv *priv)
|
2008-12-02 09:36:47 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
D3DVIEWPORT9 vp = {0, 0, priv->vo->dwidth, priv->vo->dheight, 0, 1};
|
2008-12-02 09:36:47 +00:00
|
|
|
|
2014-08-06 18:00:26 +00:00
|
|
|
MP_VERBOSE(priv, "resize_d3d %dx%d called.\n",
|
|
|
|
priv->vo->dwidth, priv->vo->dheight);
|
2008-12-02 09:36:47 +00:00
|
|
|
|
2016-06-25 18:07:38 +00:00
|
|
|
/* Make sure that backbuffer is large enough to accommodate the new
|
2009-01-27 10:02:47 +00:00
|
|
|
viewport dimensions. Grow it if necessary. */
|
2008-12-02 09:36:47 +00:00
|
|
|
|
2011-11-04 10:32:19 +00:00
|
|
|
bool backbuf_resize = priv->vo->dwidth > priv->cur_backbuf_width ||
|
|
|
|
priv->vo->dheight > priv->cur_backbuf_height;
|
|
|
|
|
|
|
|
if (priv->opt_exact_backbuffer) {
|
|
|
|
backbuf_resize = priv->vo->dwidth != priv->cur_backbuf_width ||
|
|
|
|
priv->vo->dheight != priv->cur_backbuf_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backbuf_resize || !priv->d3d_device)
|
2011-11-04 06:33:51 +00:00
|
|
|
{
|
2011-11-04 09:02:12 +00:00
|
|
|
destroy_d3d_surfaces(priv);
|
|
|
|
if (!change_d3d_backbuffer(priv))
|
2009-02-03 10:16:03 +00:00
|
|
|
return 0;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 18:00:39 +00:00
|
|
|
if (!priv->d3d_device || !priv->image_format)
|
vo_direct3d: fix dealing with uncooperative devices
If the Direct3D device is "lost" (e,g, when minimizing mplayer, or when
another application uses Direct3D exclusive mode), we free it and try to
recrate the device. This can fail, and may fail for an extended period of
time, until D3D is available again and the device can be created. So we
basically have to provide all VO functionality while d3d_device is NULL.
Don't terminate if device creation fails, and re-add the NULL checks that
were removed in the commit "vo_direct3d: refactor D3D initialization and
reconfigure code".
If mplayer calls the VO's config() while the D3D device can not be
created, the VO will return an error and mplayer will terminate.
config() is typically called when new files are played, when ordered
chapter boundaries are crossed, or on other events.
2011-11-12 16:07:49 +00:00
|
|
|
return 1;
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
if (!create_d3d_surfaces(priv))
|
2008-11-18 12:23:42 +00:00
|
|
|
return 0;
|
2008-12-02 09:36:47 +00:00
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
if (FAILED(IDirect3DDevice9_SetViewport(priv->d3d_device, &vp))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Setting viewport failed.\n");
|
2009-02-03 10:14:44 +00:00
|
|
|
return 0;
|
2009-01-27 10:02:47 +00:00
|
|
|
}
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
// so that screen coordinates map to D3D ones
|
|
|
|
D3DMATRIX view;
|
|
|
|
d3d_matrix_ortho(&view, 0.5f, vp.Width + 0.5f, vp.Height + 0.5f, 0.5f);
|
|
|
|
IDirect3DDevice9_SetTransform(priv->d3d_device, D3DTS_VIEW, &view);
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
calc_fs_rect(priv);
|
|
|
|
priv->vo->want_redraw = true;
|
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Uninitialize Direct3D and close the window.
|
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
static void uninit_d3d(d3d_priv *priv)
|
2008-11-18 12:23:42 +00:00
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "uninit_d3d called.\n");
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2015-01-21 20:09:46 +00:00
|
|
|
destroy_d3d(priv);
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
static uint32_t d3d_draw_frame(d3d_priv *priv)
|
2011-10-26 13:19:58 +00:00
|
|
|
{
|
vo_direct3d: fix dealing with uncooperative devices
If the Direct3D device is "lost" (e,g, when minimizing mplayer, or when
another application uses Direct3D exclusive mode), we free it and try to
recrate the device. This can fail, and may fail for an extended period of
time, until D3D is available again and the device can be created. So we
basically have to provide all VO functionality while d3d_device is NULL.
Don't terminate if device creation fails, and re-add the NULL checks that
were removed in the commit "vo_direct3d: refactor D3D initialization and
reconfigure code".
If mplayer calls the VO's config() while the D3D device can not be
created, the VO will return an error and mplayer will terminate.
config() is typically called when new files are played, when ordered
chapter boundaries are crossed, or on other events.
2011-11-12 16:07:49 +00:00
|
|
|
if (!priv->d3d_device)
|
|
|
|
return VO_TRUE;
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
if (!d3d_begin_scene(priv))
|
2008-11-23 18:45:01 +00:00
|
|
|
return VO_ERROR;
|
2008-11-23 18:13:56 +00:00
|
|
|
|
2013-02-24 14:29:06 +00:00
|
|
|
IDirect3DDevice9_Clear(priv->d3d_device, 0, NULL, D3DCLEAR_TARGET, 0, 0, 0);
|
2008-11-24 09:44:33 +00:00
|
|
|
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
if (!priv->have_image)
|
2014-06-18 18:04:59 +00:00
|
|
|
goto render_osd;
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
|
2015-05-21 17:27:54 +00:00
|
|
|
RECT rm = priv->fs_movie_rect;
|
|
|
|
RECT rs = priv->fs_panscan_rect;
|
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
rs.left &= ~(ULONG)1;
|
|
|
|
rs.top &= ~(ULONG)1;
|
|
|
|
rs.right &= ~(ULONG)1;
|
|
|
|
rs.bottom &= ~(ULONG)1;
|
|
|
|
if (FAILED(IDirect3DDevice9_StretchRect(priv->d3d_device,
|
|
|
|
priv->d3d_surface,
|
|
|
|
&rs,
|
|
|
|
priv->d3d_backbuf,
|
|
|
|
&rm,
|
|
|
|
D3DTEXF_LINEAR))) {
|
|
|
|
MP_ERR(priv, "Copying frame to the backbuffer failed.\n");
|
|
|
|
return VO_ERROR;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 18:04:59 +00:00
|
|
|
render_osd:
|
|
|
|
|
2014-06-15 18:46:57 +00:00
|
|
|
draw_osd(priv->vo);
|
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
}
|
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
static D3DFORMAT check_format(d3d_priv *priv, uint32_t movie_fmt)
|
2008-11-18 12:23:42 +00:00
|
|
|
{
|
2011-11-01 22:20:38 +00:00
|
|
|
const struct fmt_entry *cur = &fmt_table[0];
|
|
|
|
|
|
|
|
while (cur->mplayer_fmt) {
|
|
|
|
if (cur->mplayer_fmt == movie_fmt) {
|
|
|
|
HRESULT res;
|
2020-05-13 19:35:32 +00:00
|
|
|
/* Test conversion from Movie colorspace to
|
|
|
|
* display's target colorspace. */
|
|
|
|
res = IDirect3D9_CheckDeviceFormatConversion(priv->d3d_handle,
|
|
|
|
D3DADAPTER_DEFAULT,
|
|
|
|
DEVTYPE,
|
|
|
|
cur->fourcc,
|
|
|
|
priv->desktop_fmt);
|
2011-11-01 22:20:38 +00:00
|
|
|
if (FAILED(res)) {
|
2020-05-13 19:35:32 +00:00
|
|
|
MP_VERBOSE(priv, "Rejected image format: %s\n",
|
|
|
|
vo_format_name(cur->mplayer_fmt));
|
2011-11-01 22:20:38 +00:00
|
|
|
return 0;
|
2008-11-20 15:13:14 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
MP_DBG(priv, "Accepted image format: %s\n",
|
|
|
|
vo_format_name(cur->mplayer_fmt));
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
return cur->fourcc;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
2011-11-01 22:20:38 +00:00
|
|
|
cur++;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
// Return if the image format can be used. If it can, decide which rendering
|
|
|
|
// and conversion mode to use.
|
|
|
|
// If initialize is true, actually setup all variables to use the picked
|
|
|
|
// rendering mode.
|
2011-11-04 06:33:51 +00:00
|
|
|
static bool init_rendering_mode(d3d_priv *priv, uint32_t fmt, bool initialize)
|
2011-11-01 22:20:38 +00:00
|
|
|
{
|
2020-05-13 19:35:32 +00:00
|
|
|
int blit_d3dfmt = check_format(priv, fmt);
|
|
|
|
|
|
|
|
if (!blit_d3dfmt)
|
2011-11-01 22:20:38 +00:00
|
|
|
return false;
|
|
|
|
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "Accepted rendering methods for "
|
2020-05-13 19:35:32 +00:00
|
|
|
"format='%s': StretchRect=%#x.\n",
|
|
|
|
vo_format_name(fmt), blit_d3dfmt);
|
2011-11-01 22:20:38 +00:00
|
|
|
|
|
|
|
if (!initialize)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// initialization doesn't fail beyond this point
|
|
|
|
|
|
|
|
priv->movie_src_fmt = 0;
|
|
|
|
priv->image_format = fmt;
|
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
priv->movie_src_fmt = blit_d3dfmt;
|
2011-11-01 22:20:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-10-22 21:44:27 +00:00
|
|
|
|
|
|
|
/** @brief Query if movie colorspace is supported by the HW.
|
|
|
|
* @return 0 on failure, device capabilities (not probed
|
|
|
|
* currently) on success.
|
|
|
|
*/
|
2015-01-21 21:08:24 +00:00
|
|
|
static int query_format(struct vo *vo, int movie_fmt)
|
2011-10-22 21:44:27 +00:00
|
|
|
{
|
2012-11-04 15:24:18 +00:00
|
|
|
d3d_priv *priv = vo->priv;
|
2011-11-04 06:33:51 +00:00
|
|
|
if (!init_rendering_mode(priv, movie_fmt, false))
|
2011-10-22 21:44:27 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-01-21 21:08:24 +00:00
|
|
|
return 1;
|
2011-10-22 21:44:27 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* libvo Control / Callback functions *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
/** @brief libvo Callback: Preinitialize the video card.
|
|
|
|
* Preinit the hardware just enough to be queried about
|
|
|
|
* supported formats.
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*/
|
2008-11-20 15:13:14 +00:00
|
|
|
|
2013-07-22 20:52:42 +00:00
|
|
|
static int preinit(struct vo *vo)
|
2008-11-18 12:23:42 +00:00
|
|
|
{
|
2013-07-21 23:34:48 +00:00
|
|
|
d3d_priv *priv = vo->priv;
|
|
|
|
priv->vo = vo;
|
2013-08-23 21:30:09 +00:00
|
|
|
priv->log = vo->log;
|
2011-11-01 22:20:38 +00:00
|
|
|
|
2010-01-03 17:00:51 +00:00
|
|
|
priv->d3d9_dll = LoadLibraryA("d3d9.dll");
|
|
|
|
if (!priv->d3d9_dll) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Unable to dynamically load d3d9.dll\n");
|
2010-01-03 17:04:04 +00:00
|
|
|
goto err_out;
|
2010-01-03 17:00:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
priv->pDirect3DCreate9 = (void *)GetProcAddress(priv->d3d9_dll,
|
|
|
|
"Direct3DCreate9");
|
2010-01-03 17:00:51 +00:00
|
|
|
if (!priv->pDirect3DCreate9) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Unable to find entry point of Direct3DCreate9\n");
|
2010-01-03 17:04:04 +00:00
|
|
|
goto err_out;
|
2010-01-03 17:00:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
/* w32_common framework call. Configures window on the screen, gets
|
|
|
|
* fullscreen dimensions and does other useful stuff.
|
|
|
|
*/
|
2012-04-14 11:39:53 +00:00
|
|
|
if (!vo_w32_init(vo)) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "Configuring onscreen window failed.\n");
|
2010-01-03 17:04:04 +00:00
|
|
|
goto err_out;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
2015-01-21 19:56:34 +00:00
|
|
|
if (!init_d3d(priv))
|
|
|
|
goto err_out;
|
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
return 0;
|
2010-01-03 17:04:04 +00:00
|
|
|
|
|
|
|
err_out:
|
2011-11-04 06:33:51 +00:00
|
|
|
uninit(vo);
|
2010-01-03 17:04:04 +00:00
|
|
|
return -1;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief libvo Callback: Handle control requests.
|
|
|
|
* @return VO_TRUE on success, VO_NOTIMPL when not implemented
|
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
static int control(struct vo *vo, uint32_t request, void *data)
|
2008-11-18 12:23:42 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_priv *priv = vo->priv;
|
|
|
|
|
2008-11-20 15:13:14 +00:00
|
|
|
switch (request) {
|
2011-10-26 13:19:58 +00:00
|
|
|
case VOCTRL_REDRAW_FRAME:
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_draw_frame(priv);
|
2011-10-26 13:19:58 +00:00
|
|
|
return VO_TRUE;
|
2008-11-18 12:23:42 +00:00
|
|
|
case VOCTRL_SET_PANSCAN:
|
vo_direct3d: fix dealing with uncooperative devices
If the Direct3D device is "lost" (e,g, when minimizing mplayer, or when
another application uses Direct3D exclusive mode), we free it and try to
recrate the device. This can fail, and may fail for an extended period of
time, until D3D is available again and the device can be created. So we
basically have to provide all VO functionality while d3d_device is NULL.
Don't terminate if device creation fails, and re-add the NULL checks that
were removed in the commit "vo_direct3d: refactor D3D initialization and
reconfigure code".
If mplayer calls the VO's config() while the D3D device can not be
created, the VO will return an error and mplayer will terminate.
config() is typically called when new files are played, when ordered
chapter boundaries are crossed, or on other events.
2011-11-12 16:07:49 +00:00
|
|
|
calc_fs_rect(priv);
|
2013-02-24 14:29:06 +00:00
|
|
|
priv->vo->want_redraw = true;
|
2008-11-18 12:23:42 +00:00
|
|
|
return VO_TRUE;
|
2015-01-23 21:06:12 +00:00
|
|
|
case VOCTRL_SCREENSHOT_WIN:
|
|
|
|
*(struct mp_image **)data = get_window_screenshot(priv);
|
|
|
|
return VO_TRUE;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
2013-05-16 12:07:41 +00:00
|
|
|
|
|
|
|
int events = 0;
|
|
|
|
int r = vo_w32_control(vo, &events, request, data);
|
|
|
|
|
|
|
|
if (events & VO_EVENT_RESIZE)
|
|
|
|
resize_d3d(priv);
|
|
|
|
|
|
|
|
if (events & VO_EVENT_EXPOSE)
|
|
|
|
vo->want_redraw = true;
|
|
|
|
|
2014-11-02 19:26:51 +00:00
|
|
|
vo_event(vo, events);
|
|
|
|
|
2013-05-16 12:07:41 +00:00
|
|
|
return r;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 16:20:16 +00:00
|
|
|
static int reconfig(struct vo *vo, struct mp_image_params *params)
|
2008-11-18 12:23:42 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_priv *priv = vo->priv;
|
|
|
|
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
priv->have_image = false;
|
|
|
|
|
2015-10-31 11:52:02 +00:00
|
|
|
vo_w32_config(vo);
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2014-01-24 20:22:25 +00:00
|
|
|
if ((priv->image_format != params->imgfmt)
|
|
|
|
|| (priv->src_width != params->w)
|
|
|
|
|| (priv->src_height != params->h))
|
2011-10-28 20:06:33 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_destroy_video_objects(priv);
|
2011-11-01 22:20:38 +00:00
|
|
|
|
2014-01-24 20:22:25 +00:00
|
|
|
priv->src_width = params->w;
|
|
|
|
priv->src_height = params->h;
|
2014-03-29 02:32:56 +00:00
|
|
|
priv->params = *params;
|
2014-01-24 20:22:25 +00:00
|
|
|
init_rendering_mode(priv, params->imgfmt, true);
|
2011-10-28 20:06:33 +00:00
|
|
|
}
|
2008-12-02 09:36:47 +00:00
|
|
|
|
2011-11-04 09:02:12 +00:00
|
|
|
if (!resize_d3d(priv))
|
|
|
|
return VO_ERROR;
|
2008-11-23 17:25:46 +00:00
|
|
|
|
2008-11-18 12:23:42 +00:00
|
|
|
return 0; /* Success */
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief libvo Callback: Flip next already drawn frame on the
|
|
|
|
* screen.
|
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
static void flip_page(struct vo *vo)
|
2008-11-18 12:23:42 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_priv *priv = vo->priv;
|
|
|
|
|
vo_direct3d: fix dealing with uncooperative devices
If the Direct3D device is "lost" (e,g, when minimizing mplayer, or when
another application uses Direct3D exclusive mode), we free it and try to
recrate the device. This can fail, and may fail for an extended period of
time, until D3D is available again and the device can be created. So we
basically have to provide all VO functionality while d3d_device is NULL.
Don't terminate if device creation fails, and re-add the NULL checks that
were removed in the commit "vo_direct3d: refactor D3D initialization and
reconfigure code".
If mplayer calls the VO's config() while the D3D device can not be
created, the VO will return an error and mplayer will terminate.
config() is typically called when new files are played, when ordered
chapter boundaries are crossed, or on other events.
2011-11-12 16:07:49 +00:00
|
|
|
if (priv->d3d_device && priv->d3d_in_scene) {
|
2011-11-01 22:20:38 +00:00
|
|
|
if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "EndScene failed.\n");
|
2011-11-01 22:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
vo_direct3d: fix dealing with uncooperative devices
If the Direct3D device is "lost" (e,g, when minimizing mplayer, or when
another application uses Direct3D exclusive mode), we free it and try to
recrate the device. This can fail, and may fail for an extended period of
time, until D3D is available again and the device can be created. So we
basically have to provide all VO functionality while d3d_device is NULL.
Don't terminate if device creation fails, and re-add the NULL checks that
were removed in the commit "vo_direct3d: refactor D3D initialization and
reconfigure code".
If mplayer calls the VO's config() while the D3D device can not be
created, the VO will return an error and mplayer will terminate.
config() is typically called when new files are played, when ordered
chapter boundaries are crossed, or on other events.
2011-11-12 16:07:49 +00:00
|
|
|
priv->d3d_in_scene = false;
|
2011-11-01 22:20:38 +00:00
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
RECT rect = {0, 0, vo->dwidth, vo->dheight};
|
2009-02-03 11:00:09 +00:00
|
|
|
if (!priv->d3d_device ||
|
|
|
|
FAILED(IDirect3DDevice9_Present(priv->d3d_device, &rect, 0, 0, 0))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "Trying to reinitialize uncooperative video adapter.\n");
|
2011-11-04 06:33:51 +00:00
|
|
|
if (!reconfigure_d3d(priv)) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "Reinitialization failed.\n");
|
2008-11-18 12:23:42 +00:00
|
|
|
return;
|
2011-11-04 06:33:51 +00:00
|
|
|
} else {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "Video adapter reinitialized.\n");
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief libvo Callback: Uninitializes all pointers and closes
|
|
|
|
* all D3D related stuff,
|
|
|
|
*/
|
2011-11-04 06:33:51 +00:00
|
|
|
static void uninit(struct vo *vo)
|
2008-11-18 12:23:42 +00:00
|
|
|
{
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_priv *priv = vo->priv;
|
|
|
|
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_VERBOSE(priv, "uninit called.\n");
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
uninit_d3d(priv);
|
2012-04-14 11:39:53 +00:00
|
|
|
vo_w32_uninit(vo);
|
2010-01-03 17:04:04 +00:00
|
|
|
if (priv->d3d9_dll)
|
|
|
|
FreeLibrary(priv->d3d9_dll);
|
|
|
|
priv->d3d9_dll = NULL;
|
2008-11-18 12:23:42 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 10:54:30 +00:00
|
|
|
// Lock buffers and fill out to point to them.
|
|
|
|
// Must call d3d_unlock_video_objects() to unlock the buffers again.
|
|
|
|
static bool get_video_buffer(d3d_priv *priv, struct mp_image *out)
|
2011-11-01 22:20:38 +00:00
|
|
|
{
|
2012-12-23 10:54:30 +00:00
|
|
|
*out = (struct mp_image) {0};
|
2012-11-10 01:02:24 +00:00
|
|
|
mp_image_set_size(out, priv->src_width, priv->src_height);
|
2012-12-23 10:54:30 +00:00
|
|
|
mp_image_setfmt(out, priv->image_format);
|
2011-11-04 06:33:51 +00:00
|
|
|
|
vo_direct3d: fix dealing with uncooperative devices
If the Direct3D device is "lost" (e,g, when minimizing mplayer, or when
another application uses Direct3D exclusive mode), we free it and try to
recrate the device. This can fail, and may fail for an extended period of
time, until D3D is available again and the device can be created. So we
basically have to provide all VO functionality while d3d_device is NULL.
Don't terminate if device creation fails, and re-add the NULL checks that
were removed in the commit "vo_direct3d: refactor D3D initialization and
reconfigure code".
If mplayer calls the VO's config() while the D3D device can not be
created, the VO will return an error and mplayer will terminate.
config() is typically called when new files are played, when ordered
chapter boundaries are crossed, or on other events.
2011-11-12 16:07:49 +00:00
|
|
|
if (!priv->d3d_device)
|
2012-12-23 10:54:30 +00:00
|
|
|
return false;
|
2008-11-18 12:23:42 +00:00
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
if (!priv->locked_rect.pBits) {
|
|
|
|
if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
|
|
|
|
&priv->locked_rect, NULL, 0)))
|
|
|
|
{
|
|
|
|
MP_ERR(priv, "Surface lock failed.\n");
|
2012-12-23 10:54:30 +00:00
|
|
|
return false;
|
2011-11-27 18:58:04 +00:00
|
|
|
}
|
2020-05-13 19:35:32 +00:00
|
|
|
}
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
uint8_t *base = priv->locked_rect.pBits;
|
|
|
|
size_t stride = priv->locked_rect.Pitch;
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
out->planes[0] = base;
|
|
|
|
out->stride[0] = stride;
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
if (out->num_planes == 2) {
|
|
|
|
// NV12, NV21
|
|
|
|
out->planes[1] = base + stride * out->h;
|
|
|
|
out->stride[1] = stride;
|
|
|
|
}
|
2014-10-26 00:36:15 +00:00
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
if (out->num_planes == 3) {
|
|
|
|
bool swap = priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2');
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
size_t uv_stride = stride / 2;
|
|
|
|
uint8_t *u = base + out->h * stride;
|
|
|
|
uint8_t *v = u + (out->h / 2) * uv_stride;
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
out->planes[1] = swap ? v : u;
|
|
|
|
out->planes[2] = swap ? u : v;
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2020-05-13 19:35:32 +00:00
|
|
|
out->stride[1] = out->stride[2] = uv_stride;
|
2011-11-27 18:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-23 10:54:30 +00:00
|
|
|
static void draw_image(struct vo *vo, mp_image_t *mpi)
|
2011-11-27 18:58:04 +00:00
|
|
|
{
|
2012-12-23 10:54:30 +00:00
|
|
|
d3d_priv *priv = vo->priv;
|
|
|
|
if (!priv->d3d_device)
|
2014-06-17 21:05:50 +00:00
|
|
|
goto done;
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2012-12-23 10:54:30 +00:00
|
|
|
struct mp_image buffer;
|
|
|
|
if (!get_video_buffer(priv, &buffer))
|
2014-06-17 21:05:50 +00:00
|
|
|
goto done;
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2012-12-22 20:46:22 +00:00
|
|
|
mp_image_copy(&buffer, mpi);
|
2011-11-27 18:58:04 +00:00
|
|
|
|
2012-12-23 10:54:30 +00:00
|
|
|
d3d_unlock_video_objects(priv);
|
2011-11-27 18:58:04 +00:00
|
|
|
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
priv->have_image = true;
|
2014-06-15 18:46:57 +00:00
|
|
|
priv->osd_pts = mpi->pts;
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
|
2012-12-23 10:54:30 +00:00
|
|
|
d3d_draw_frame(priv);
|
2014-06-17 21:05:50 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
talloc_free(mpi);
|
2011-11-27 18:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static mp_image_t *get_window_screenshot(d3d_priv *priv)
|
|
|
|
{
|
|
|
|
D3DDISPLAYMODE mode;
|
|
|
|
mp_image_t *image = NULL;
|
|
|
|
RECT window_rc;
|
|
|
|
RECT screen_rc;
|
|
|
|
RECT visible;
|
|
|
|
POINT pt;
|
|
|
|
D3DLOCKED_RECT locked_rect;
|
|
|
|
int width, height;
|
2016-11-17 12:05:17 +00:00
|
|
|
IDirect3DSurface9 *surface = NULL;
|
2011-11-27 18:58:04 +00:00
|
|
|
|
|
|
|
if (FAILED(IDirect3DDevice9_GetDisplayMode(priv->d3d_device, 0, &mode))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "GetDisplayMode failed.\n");
|
2011-11-27 18:58:04 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface(priv->d3d_device,
|
|
|
|
mode.Width, mode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface,
|
|
|
|
NULL)))
|
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Couldn't create surface.\n");
|
2011-11-27 18:58:04 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(IDirect3DDevice9_GetFrontBufferData(priv->d3d_device, 0,
|
|
|
|
surface)))
|
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "Couldn't copy frontbuffer.\n");
|
2011-11-27 18:58:04 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
2014-07-26 18:27:03 +00:00
|
|
|
GetClientRect(vo_w32_hwnd(priv->vo), &window_rc);
|
2011-11-27 18:58:04 +00:00
|
|
|
pt = (POINT) { 0, 0 };
|
2014-07-26 18:27:03 +00:00
|
|
|
ClientToScreen(vo_w32_hwnd(priv->vo), &pt);
|
2011-11-27 18:58:04 +00:00
|
|
|
window_rc.left = pt.x;
|
|
|
|
window_rc.top = pt.y;
|
|
|
|
window_rc.right += window_rc.left;
|
|
|
|
window_rc.bottom += window_rc.top;
|
|
|
|
|
|
|
|
screen_rc = (RECT) { 0, 0, mode.Width, mode.Height };
|
|
|
|
|
|
|
|
if (!IntersectRect(&visible, &screen_rc, &window_rc))
|
|
|
|
goto error_exit;
|
|
|
|
width = visible.right - visible.left;
|
|
|
|
height = visible.bottom - visible.top;
|
|
|
|
if (width < 1 || height < 1)
|
|
|
|
goto error_exit;
|
|
|
|
|
2015-04-07 09:43:03 +00:00
|
|
|
image = mp_image_alloc(IMGFMT_BGR0, width, height);
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
if (!image)
|
|
|
|
goto error_exit;
|
2011-11-27 18:58:04 +00:00
|
|
|
|
|
|
|
IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
|
|
|
|
|
|
|
|
memcpy_pic(image->planes[0], (char*)locked_rect.pBits + visible.top *
|
|
|
|
locked_rect.Pitch + visible.left * 4, width * 4, height,
|
|
|
|
image->stride[0], locked_rect.Pitch);
|
|
|
|
|
|
|
|
IDirect3DSurface9_UnlockRect(surface);
|
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
|
|
|
|
error_exit:
|
|
|
|
if (image)
|
2012-12-22 20:46:22 +00:00
|
|
|
talloc_free(image);
|
2011-11-27 18:58:04 +00:00
|
|
|
if (surface)
|
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
static void update_osd(d3d_priv *priv)
|
2016-07-01 18:21:15 +00:00
|
|
|
{
|
2020-05-13 20:50:31 +00:00
|
|
|
if (!priv->osd_cache)
|
|
|
|
priv->osd_cache = mp_draw_sub_alloc(priv, priv->vo->global);
|
2016-07-01 18:21:15 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
struct sub_bitmap_list *sbs = osd_render(priv->vo->osd, priv->osd_res,
|
|
|
|
priv->osd_pts, 0, mp_draw_sub_formats);
|
2016-07-01 18:21:15 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
struct mp_rect act_rc[MAX_OSD_RECTS], mod_rc[64];
|
|
|
|
int num_act_rc = 0, num_mod_rc = 0;
|
vo_direct3d: fix dealing with uncooperative devices
If the Direct3D device is "lost" (e,g, when minimizing mplayer, or when
another application uses Direct3D exclusive mode), we free it and try to
recrate the device. This can fail, and may fail for an extended period of
time, until D3D is available again and the device can be created. So we
basically have to provide all VO functionality while d3d_device is NULL.
Don't terminate if device creation fails, and re-add the NULL checks that
were removed in the commit "vo_direct3d: refactor D3D initialization and
reconfigure code".
If mplayer calls the VO's config() while the D3D device can not be
created, the VO will return an error and mplayer will terminate.
config() is typically called when new files are played, when ordered
chapter boundaries are crossed, or on other events.
2011-11-12 16:07:49 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
struct mp_image *osd = mp_draw_sub_overlay(priv->osd_cache, sbs,
|
|
|
|
act_rc, MP_ARRAY_SIZE(act_rc), &num_act_rc,
|
|
|
|
mod_rc, MP_ARRAY_SIZE(mod_rc), &num_mod_rc);
|
2008-12-09 18:31:52 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
talloc_free(sbs);
|
2008-12-09 18:31:52 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
if (!osd) {
|
|
|
|
MP_ERR(priv, "Failed to render OSD.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!num_mod_rc && priv->osd_texture.system)
|
|
|
|
return; // nothing changed
|
2008-12-09 18:31:52 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
priv->osd_num_vertices = 0;
|
|
|
|
|
|
|
|
if (osd->w > priv->osd_texture.tex_w || osd->h > priv->osd_texture.tex_h) {
|
|
|
|
int new_w = osd->w;
|
|
|
|
int new_h = osd->h;
|
2012-10-04 15:16:21 +00:00
|
|
|
d3d_fix_texture_size(priv, &new_w, &new_h);
|
2008-12-09 18:31:52 +00:00
|
|
|
|
2016-07-01 18:21:15 +00:00
|
|
|
MP_DBG(priv, "reallocate OSD surface to %dx%d.\n", new_w, new_h);
|
2011-11-01 02:11:46 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
d3dtex_release(priv, &priv->osd_texture);
|
|
|
|
if (!d3dtex_allocate(priv, &priv->osd_texture, D3DFMT_A8R8G8B8,
|
|
|
|
new_w, new_h))
|
|
|
|
return;
|
2008-12-09 18:31:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
// Lazy; could/should use the bounding rect, or perform multiple lock calls.
|
|
|
|
// The previous approach (fully packed texture) was more efficient.
|
|
|
|
RECT dirty_rc = { 0, 0, priv->osd_texture.w, priv->osd_texture.h };
|
2008-12-09 18:31:52 +00:00
|
|
|
|
2012-10-04 15:16:21 +00:00
|
|
|
D3DLOCKED_RECT locked_rect;
|
2008-12-09 18:31:52 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
if (FAILED(IDirect3DTexture9_LockRect(priv->osd_texture.system, 0, &locked_rect,
|
2012-10-04 15:16:21 +00:00
|
|
|
&dirty_rc, 0)))
|
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "OSD texture lock failed.\n");
|
2020-05-13 20:50:31 +00:00
|
|
|
return;
|
2012-10-04 15:16:21 +00:00
|
|
|
}
|
2008-12-09 18:31:52 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
for (int n = 0; n < num_mod_rc; n++) {
|
|
|
|
struct mp_rect rc = mod_rc[n];
|
|
|
|
int w = mp_rect_w(rc);
|
|
|
|
int h = mp_rect_h(rc);
|
|
|
|
void *src = mp_image_pixel_ptr(osd, 0, rc.x0, rc.y0);
|
|
|
|
void *dst = (char *)locked_rect.pBits + locked_rect.Pitch * rc.y0 +
|
|
|
|
rc.x0 * 4;
|
|
|
|
memcpy_pic(dst, src, w * 4, h, locked_rect.Pitch, osd->stride[0]);
|
|
|
|
}
|
2011-11-01 22:20:38 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
if (FAILED(IDirect3DTexture9_UnlockRect(priv->osd_texture.system, 0))) {
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(priv, "OSD texture unlock failed.\n");
|
2020-05-13 20:50:31 +00:00
|
|
|
return;
|
2008-12-09 18:31:52 +00:00
|
|
|
}
|
2012-10-04 15:16:21 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
if (!d3dtex_update(priv, &priv->osd_texture))
|
|
|
|
return;
|
2016-07-01 18:21:15 +00:00
|
|
|
|
|
|
|
// We need 2 primitives per quad which makes 6 vertices.
|
2020-05-13 20:50:31 +00:00
|
|
|
priv->osd_num_vertices = num_act_rc * 6;
|
2016-07-01 18:21:15 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
float tex_w = priv->osd_texture.tex_w;
|
|
|
|
float tex_h = priv->osd_texture.tex_h;
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
for (int n = 0; n < num_act_rc; n++) {
|
|
|
|
struct mp_rect rc = act_rc[n];
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
float tx0 = rc.x0 / tex_w;
|
|
|
|
float ty0 = rc.y0 / tex_h;
|
|
|
|
float tx1 = rc.x1 / tex_w;
|
|
|
|
float ty1 = rc.y1 / tex_h;
|
2011-11-01 01:38:17 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
vertex_osd *v = &priv->osd_vertices[n * 6];
|
|
|
|
v[0] = (vertex_osd) { rc.x0, rc.y0, 0, tx0, ty0 };
|
|
|
|
v[1] = (vertex_osd) { rc.x1, rc.y0, 0, tx1, ty0 };
|
|
|
|
v[2] = (vertex_osd) { rc.x0, rc.y1, 0, tx0, ty1 };
|
|
|
|
v[3] = (vertex_osd) { rc.x1, rc.y1, 0, tx1, ty1 };
|
|
|
|
v[4] = v[2];
|
|
|
|
v[5] = v[1];
|
|
|
|
}
|
2011-10-26 09:44:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
static void draw_osd(struct vo *vo)
|
2011-10-26 09:44:30 +00:00
|
|
|
{
|
2020-05-13 20:50:31 +00:00
|
|
|
d3d_priv *priv = vo->priv;
|
|
|
|
if (!priv->d3d_device)
|
|
|
|
return;
|
vo_direct3d: fix dealing with uncooperative devices
If the Direct3D device is "lost" (e,g, when minimizing mplayer, or when
another application uses Direct3D exclusive mode), we free it and try to
recrate the device. This can fail, and may fail for an extended period of
time, until D3D is available again and the device can be created. So we
basically have to provide all VO functionality while d3d_device is NULL.
Don't terminate if device creation fails, and re-add the NULL checks that
were removed in the commit "vo_direct3d: refactor D3D initialization and
reconfigure code".
If mplayer calls the VO's config() while the D3D device can not be
created, the VO will return an error and mplayer will terminate.
config() is typically called when new files are played, when ordered
chapter boundaries are crossed, or on other events.
2011-11-12 16:07:49 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
update_osd(priv);
|
|
|
|
|
|
|
|
if (!priv->osd_num_vertices)
|
2011-10-26 09:44:30 +00:00
|
|
|
return;
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
d3d_begin_scene(priv);
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
IDirect3DDevice9_SetRenderState(priv->d3d_device,
|
|
|
|
D3DRS_ALPHABLENDENABLE, TRUE);
|
2011-10-26 09:44:30 +00:00
|
|
|
|
|
|
|
IDirect3DDevice9_SetTexture(priv->d3d_device, 0,
|
2020-05-13 20:50:31 +00:00
|
|
|
d3dtex_get_render_texture(priv, &priv->osd_texture));
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2020-05-13 20:50:31 +00:00
|
|
|
IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_SRCBLEND,
|
|
|
|
D3DBLEND_ONE);
|
2011-10-26 09:44:30 +00:00
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
IDirect3DDevice9_SetFVF(priv->d3d_device, D3DFVF_OSD_VERTEX);
|
2011-10-26 09:44:30 +00:00
|
|
|
IDirect3DDevice9_DrawPrimitiveUP(priv->d3d_device, D3DPT_TRIANGLELIST,
|
2020-05-13 20:50:31 +00:00
|
|
|
priv->osd_num_vertices / 3,
|
|
|
|
priv->osd_vertices, sizeof(vertex_osd));
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2012-10-05 18:37:16 +00:00
|
|
|
IDirect3DDevice9_SetRenderState(priv->d3d_device,
|
|
|
|
D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
2011-10-26 09:44:30 +00:00
|
|
|
|
2011-11-01 22:20:38 +00:00
|
|
|
IDirect3DDevice9_SetTexture(priv->d3d_device, 0, NULL);
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
IDirect3DDevice9_SetRenderState(priv->d3d_device,
|
|
|
|
D3DRS_ALPHABLENDENABLE, FALSE);
|
2011-10-26 09:44:30 +00:00
|
|
|
}
|
2011-11-04 06:33:51 +00:00
|
|
|
|
2013-07-21 23:34:48 +00:00
|
|
|
#define OPT_BASE_STRUCT d3d_priv
|
|
|
|
|
|
|
|
static const struct m_option opts[] = {
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
{"force-power-of-2", OPT_FLAG(opt_force_power_of_2)},
|
|
|
|
{"disable-texture-align", OPT_FLAG(opt_disable_texture_align)},
|
|
|
|
{"texture-memory", OPT_CHOICE(opt_texture_memory,
|
|
|
|
{"default", 0},
|
|
|
|
{"managed", 1},
|
|
|
|
{"default-pool", 2},
|
|
|
|
{"default-pool-shadow", 3},
|
|
|
|
{"scratch", 4})},
|
|
|
|
{"swap-discard", OPT_FLAG(opt_swap_discard)},
|
|
|
|
{"exact-backbuffer", OPT_FLAG(opt_exact_backbuffer)},
|
2013-07-21 23:34:48 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2011-11-04 06:33:51 +00:00
|
|
|
const struct vo_driver video_out_direct3d = {
|
2013-10-23 17:06:14 +00:00
|
|
|
.description = "Direct3D 9 Renderer",
|
|
|
|
.name = "direct3d",
|
2013-07-21 23:34:48 +00:00
|
|
|
.preinit = preinit,
|
2012-11-04 15:24:18 +00:00
|
|
|
.query_format = query_format,
|
2014-01-24 20:22:25 +00:00
|
|
|
.reconfig = reconfig,
|
2011-11-04 07:39:20 +00:00
|
|
|
.control = control,
|
2012-11-04 14:56:04 +00:00
|
|
|
.draw_image = draw_image,
|
2011-11-04 07:39:20 +00:00
|
|
|
.flip_page = flip_page,
|
|
|
|
.uninit = uninit,
|
2013-07-21 23:34:48 +00:00
|
|
|
.priv_size = sizeof(d3d_priv),
|
|
|
|
.options = opts,
|
2016-11-25 20:00:39 +00:00
|
|
|
.options_prefix = "vo-direct3d",
|
2011-11-04 06:33:51 +00:00
|
|
|
};
|