annotate libvo/vo_direct3d.c @ 36182:8587ae275646

Rename HAVE_CMOV to HAVE_I686 for FFmpeg. Keep the cmov name in configure since it is less confusing, since cmov is what we test for and also since for example VIA C3 sometimes is considered i686 that does not implement the optional CMOV instruction.
author reimar
date Fri, 17 May 2013 15:59:38 +0000
parents a6a1c973de4e
children 5d3f93051de9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
1 /*
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
2 * Copyright (c) 2008 Georgi Petrov (gogothebee) <gogothebee@gmail.com>
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
3 *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
4 * This file is part of MPlayer.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
5 *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
9 * (at your option) any later version.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
10 *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
14 * GNU General Public License for more details.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
15 *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
19 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
20
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
21 #include <windows.h>
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
22 #include <errno.h>
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
23 #include <stdio.h>
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
24 #include <d3d9.h>
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
25 #include "config.h"
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
26 #include "video_out.h"
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
27 #include "video_out_internal.h"
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
28 #include "fastmemcpy.h"
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
29 #include "mp_msg.h"
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
30 #include "aspect.h"
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
31 #include "w32_common.h"
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
32 #include "libavutil/common.h"
32466
9e627a1793b1 Move font_load.[ch], font_load_ft.c and osd_font.h from libvo to sub.
cigaes
parents: 30149
diff changeset
33 #include "sub/font_load.h"
32467
fbe5c829c69b Move libvo/sub.[ch] from libvo to sub.
cigaes
parents: 32466
diff changeset
34 #include "sub/sub.h"
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
35
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
36 static const vo_info_t info =
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
37 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
38 "Direct3D 9 Renderer",
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
39 "direct3d",
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
40 "Georgi Petrov (gogothebee) <gogothebee@gmail.com>",
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
41 ""
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
42 };
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
43
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
44 /*
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
45 * Link essential libvo functions: preinit, config, control, draw_frame,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
46 * draw_slice, draw_osd, flip_page, check_events, uninit and
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
47 * the structure info.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
48 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
49 const LIBVO_EXTERN(direct3d)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
50
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
51
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
52 /* Global variables "priv" structure. I try to keep their count low.
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
53 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
54 static struct global_priv {
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
55 int is_paused; /**< 1 = Movie is paused,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
56 0 = Movie is not paused */
27984
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
57 int is_clear_needed; /**< 1 = Clear the backbuffer before StretchRect
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
58 0 = (default) Don't clear it */
28418
2e77aca35aaf Whitespace/comment typo cosmetics.
reimar
parents: 28417
diff changeset
59 D3DLOCKED_RECT locked_rect; /**< The locked offscreen surface */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
60 RECT fs_movie_rect; /**< Rect (upscaled) of the movie when displayed
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
61 in fullscreen */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
62 RECT fs_panscan_rect; /**< PanScan source surface cropping in
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
63 fullscreen */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
64 int src_width; /**< Source (movie) width */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
65 int src_height; /**< Source (movie) heigth */
28598
4172d83194f2 Extend calc_src_dst_rects to also calculate the border values needed for
reimar
parents: 28511
diff changeset
66 int border_x; /**< horizontal border value for OSD */
4172d83194f2 Extend calc_src_dst_rects to also calculate the border values needed for
reimar
parents: 28511
diff changeset
67 int border_y; /**< vertical border value for OSD */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
68
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
69 D3DFORMAT movie_src_fmt; /**< Movie colorspace format (depends on
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
70 the movie's codec) */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
71 D3DFORMAT desktop_fmt; /**< Desktop (screen) colorspace format.
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
72 Usually XRGB */
30148
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
73
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
74 HANDLE d3d9_dll; /**< d3d9 Library HANDLE */
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
75 IDirect3D9 * (WINAPI *pDirect3DCreate9)(UINT); /**< pointer to Direct3DCreate9 function */
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
76
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
77 LPDIRECT3D9 d3d_handle; /**< Direct3D Handle */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
78 LPDIRECT3DDEVICE9 d3d_device; /**< The Direct3D Adapter */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
79 IDirect3DSurface9 *d3d_surface; /**< Offscreen Direct3D Surface. MPlayer
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
80 renders inside it. Uses colorspace
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
81 priv->movie_src_fmt */
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
82 IDirect3DTexture9 *d3d_texture_osd; /**< Direct3D Texture. Uses RGBA */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
83 IDirect3DTexture9 *d3d_texture_system; /**< Direct3D Texture. System memory
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
84 cannot lock a normal texture. Uses RGBA */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
85 IDirect3DSurface9 *d3d_backbuf; /**< Video card's back buffer (used to
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
86 display next frame) */
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
87 int cur_backbuf_width; /**< Current backbuffer width */
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
88 int cur_backbuf_height; /**< Current backbuffer height */
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
89 int is_osd_populated; /**< 1 = OSD texture has something to display,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
90 0 = OSD texture is clear */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
91 int device_caps_power2_only; /**< 1 = texture sizes have to be power 2
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
92 0 = texture sizes can be anything */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
93 int device_caps_square_only; /**< 1 = textures have to be square
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
94 0 = textures do not have to be square */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
95 int device_texture_sys; /**< 1 = device can texture from system memory
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
96 0 = device requires shadow */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
97 int max_texture_width; /**< from the device capabilities */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
98 int max_texture_height; /**< from the device capabilities */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
99 int osd_width; /**< current width of the OSD */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
100 int osd_height; /**< current height of the OSD */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
101 int osd_texture_width; /**< current width of the OSD texture */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
102 int osd_texture_height; /**< current height of the OSD texture */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
103 } *priv;
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
104
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
105 typedef struct {
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
106 const unsigned int mplayer_fmt; /**< Given by MPlayer */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
107 const D3DFORMAT fourcc; /**< Required by D3D's test function */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
108 } struct_fmt_table;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
109
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
110 /* Map table from reported MPlayer format to the required
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
111 fourcc. This is needed to perform the format query. */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
112
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
113 static const struct_fmt_table fmt_table[] = {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
114 {IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')},
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
115 {IMGFMT_I420, MAKEFOURCC('I','4','2','0')},
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
116 {IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')},
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
117 {IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')},
28007
16b39ef63bb5 Use D3DFMT_ constants where possible instead of MAKEFOURCC
reimar
parents: 28006
diff changeset
118 {IMGFMT_YUY2, D3DFMT_YUY2},
16b39ef63bb5 Use D3DFMT_ constants where possible instead of MAKEFOURCC
reimar
parents: 28006
diff changeset
119 {IMGFMT_UYVY, D3DFMT_UYVY},
28006
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
120 {IMGFMT_BGR32, D3DFMT_X8R8G8B8},
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
121 {IMGFMT_RGB32, D3DFMT_X8B8G8R8},
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
122 {IMGFMT_BGR24, D3DFMT_R8G8B8}, //untested
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
123 {IMGFMT_BGR16, D3DFMT_R5G6B5},
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
124 {IMGFMT_BGR15, D3DFMT_X1R5G5B5},
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
125 {IMGFMT_BGR8 , D3DFMT_R3G3B2}, //untested
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
126 };
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
127
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
128 #define DISPLAY_FORMAT_TABLE_ENTRIES (sizeof(fmt_table) / sizeof(fmt_table[0]))
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
129
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
130 #define D3DFVF_MY_VERTEX (D3DFVF_XYZ | D3DFVF_TEX1)
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
131
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
132 typedef struct {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
133 float x, y, z; /* Position of vertex in 3D space */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
134 float tu, tv; /* Texture coordinates */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
135 } struct_vertex;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
136
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
137 typedef enum back_buffer_action {
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
138 BACKBUFFER_CREATE,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
139 BACKBUFFER_RESET
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
140 } back_buffer_action_e;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
141 /****************************************************************************
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
142 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
143 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
144 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
145 * Direct3D specific implementation functions *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
146 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
147 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
148 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
149 ****************************************************************************/
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
150
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
151 /** @brief Calculate scaled fullscreen movie rectangle with
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
152 * preserved aspect ratio.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
153 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
154 static void calc_fs_rect(void)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
155 {
28511
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
156 struct vo_rect src_rect;
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
157 struct vo_rect dst_rect;
28598
4172d83194f2 Extend calc_src_dst_rects to also calculate the border values needed for
reimar
parents: 28511
diff changeset
158 struct vo_rect borders;
4172d83194f2 Extend calc_src_dst_rects to also calculate the border values needed for
reimar
parents: 28511
diff changeset
159 calc_src_dst_rects(priv->src_width, priv->src_height, &src_rect, &dst_rect, &borders, NULL);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
160
28511
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
161 priv->fs_movie_rect.left = dst_rect.left;
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
162 priv->fs_movie_rect.right = dst_rect.right;
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
163 priv->fs_movie_rect.top = dst_rect.top;
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
164 priv->fs_movie_rect.bottom = dst_rect.bottom;
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
165 priv->fs_panscan_rect.left = src_rect.left;
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
166 priv->fs_panscan_rect.right = src_rect.right;
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
167 priv->fs_panscan_rect.top = src_rect.top;
db19e31a2c7c Add a calc_src_dst_rects that calculates from window size, panscan etc.
reimar
parents: 28434
diff changeset
168 priv->fs_panscan_rect.bottom = src_rect.bottom;
28598
4172d83194f2 Extend calc_src_dst_rects to also calculate the border values needed for
reimar
parents: 28511
diff changeset
169 priv->border_x = borders.left;
4172d83194f2 Extend calc_src_dst_rects to also calculate the border values needed for
reimar
parents: 28511
diff changeset
170 priv->border_y = borders.top;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
171
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
172 mp_msg(MSGT_VO, MSGL_V,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
173 "<vo_direct3d>Fullscreen movie rectangle: t: %ld, l: %ld, r: %ld, b:%ld\n",
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
174 priv->fs_movie_rect.top, priv->fs_movie_rect.left,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
175 priv->fs_movie_rect.right, priv->fs_movie_rect.bottom);
27984
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
176
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
177 /* The backbuffer should be cleared before next StretchRect. This is
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
178 * necessary because our new draw area could be smaller than the
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
179 * previous one used by StretchRect and without it, leftovers from the
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
180 * previous frame will be left. */
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
181 priv->is_clear_needed = 1;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
182 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
183
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
184 /** @brief Destroy D3D Offscreen and Backbuffer surfaces.
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
185 */
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
186 static void destroy_d3d_surfaces(void)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
187 {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
188 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>destroy_d3d_surfaces called.\n");
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
189 /* Let's destroy the old (if any) D3D Surfaces */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
190
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
191 if (priv->locked_rect.pBits)
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
192 IDirect3DSurface9_UnlockRect(priv->d3d_surface);
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
193 priv->locked_rect.pBits = NULL;
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
194
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
195 if (priv->d3d_surface)
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
196 IDirect3DSurface9_Release(priv->d3d_surface);
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
197 priv->d3d_surface = NULL;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
198
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
199 /* kill the OSD texture and its shadow copy */
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
200 if (priv->d3d_texture_osd)
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
201 IDirect3DTexture9_Release(priv->d3d_texture_osd);
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
202 priv->d3d_texture_osd = NULL;
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
203
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
204 if (priv->d3d_texture_system)
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
205 IDirect3DTexture9_Release(priv->d3d_texture_system);
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
206 priv->d3d_texture_system = NULL;
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
207
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
208 if (priv->d3d_backbuf)
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
209 IDirect3DSurface9_Release(priv->d3d_backbuf);
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
210 priv->d3d_backbuf = NULL;
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
211 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
212
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
213 /** @brief Create D3D Offscreen and Backbuffer surfaces. Each
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
214 * surface is created only if it's not already present.
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
215 * @return 1 on success, 0 on failure
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
216 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
217 static int create_d3d_surfaces(void)
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
218 {
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
219 int osd_width = vo_dwidth, osd_height = vo_dheight;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
220 int tex_width = osd_width, tex_height = osd_height;
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
221 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>create_d3d_surfaces called.\n");
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
222
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
223 if (!priv->d3d_surface &&
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
224 FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface(
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
225 priv->d3d_device, priv->src_width, priv->src_height,
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
226 priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL))) {
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
227 mp_msg(MSGT_VO, MSGL_ERR,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
228 "<vo_direct3d>Allocating offscreen surface failed.\n");
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
229 return 0;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
230 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
231
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
232 if (!priv->d3d_backbuf &&
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
233 FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0,
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
234 D3DBACKBUFFER_TYPE_MONO,
28029
07ae7bc7487b Cosmetics: Remove unnecessary ()
reimar
parents: 28028
diff changeset
235 &priv->d3d_backbuf))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
236 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Allocating backbuffer failed.\n");
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
237 return 0;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
238 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
239
34266
a6a1c973de4e vo direct3d: fix crash in osd drawing code
al
parents: 33411
diff changeset
240 if (!tex_width || !tex_height) {
a6a1c973de4e vo direct3d: fix crash in osd drawing code
al
parents: 33411
diff changeset
241 mp_msg(MSGT_VO, MSGL_V,
a6a1c973de4e vo direct3d: fix crash in osd drawing code
al
parents: 33411
diff changeset
242 "<vo_direct3d>Deferring surface creation because width or height is 0.\n");
a6a1c973de4e vo direct3d: fix crash in osd drawing code
al
parents: 33411
diff changeset
243 return 0;
a6a1c973de4e vo direct3d: fix crash in osd drawing code
al
parents: 33411
diff changeset
244 }
a6a1c973de4e vo direct3d: fix crash in osd drawing code
al
parents: 33411
diff changeset
245
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
246 /* calculate the best size for the OSD depending on the factors from the device */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
247 if (priv->device_caps_power2_only) {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
248 tex_width = 1;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
249 tex_height = 1;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
250 while (tex_width < osd_width ) tex_width <<= 1;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
251 while (tex_height < osd_height) tex_height <<= 1;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
252 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
253 if (priv->device_caps_square_only)
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
254 /* device only supports square textures */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
255 tex_width = tex_height = tex_width > tex_height ? tex_width : tex_height;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
256 // better round up to a multiple of 16
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
257 tex_width = (tex_width + 15) & ~15;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
258 tex_height = (tex_height + 15) & ~15;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
259
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
260 // make sure we respect the size limits without breaking aspect or pow2-requirements
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
261 while (tex_width > priv->max_texture_width || tex_height > priv->max_texture_height) {
28418
2e77aca35aaf Whitespace/comment typo cosmetics.
reimar
parents: 28417
diff changeset
262 osd_width >>= 1;
2e77aca35aaf Whitespace/comment typo cosmetics.
reimar
parents: 28417
diff changeset
263 osd_height >>= 1;
2e77aca35aaf Whitespace/comment typo cosmetics.
reimar
parents: 28417
diff changeset
264 tex_width >>= 1;
2e77aca35aaf Whitespace/comment typo cosmetics.
reimar
parents: 28417
diff changeset
265 tex_height >>= 1;
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
266 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
267
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
268 priv->osd_width = osd_width;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
269 priv->osd_height = osd_height;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
270 priv->osd_texture_width = tex_width;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
271 priv->osd_texture_height = tex_height;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
272
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
273 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>OSD texture size (%dx%d), requested (%dx%d).\n",
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
274 vo_dwidth, vo_dheight, priv->osd_texture_width, priv->osd_texture_height);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
275
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
276 /* create OSD */
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
277 if (!priv->d3d_texture_system &&
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
278 FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device,
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
279 priv->osd_texture_width,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
280 priv->osd_texture_height,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
281 1,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
282 D3DUSAGE_DYNAMIC,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
283 D3DFMT_A8L8,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
284 D3DPOOL_SYSTEMMEM,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
285 &priv->d3d_texture_system,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
286 NULL))) {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
287 mp_msg(MSGT_VO,MSGL_ERR,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
288 "<vo_direct3d>Allocating OSD texture in system RAM failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
289 return 0;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
290 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
291
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
292 if (!priv->device_texture_sys) {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
293 /* only create if we need a shadow version on the external device */
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
294 if (!priv->d3d_texture_osd &&
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
295 FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device,
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
296 priv->osd_texture_width,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
297 priv->osd_texture_height,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
298 1,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
299 D3DUSAGE_DYNAMIC,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
300 D3DFMT_A8L8,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
301 D3DPOOL_DEFAULT,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
302 &priv->d3d_texture_osd,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
303 NULL))) {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
304 mp_msg(MSGT_VO,MSGL_ERR,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
305 "<vo_direct3d>Allocating OSD texture in video RAM failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
306 return 0;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
307 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
308 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
309
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
310 /* setup default renderstate */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
311 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_SRCBLEND, D3DBLEND_ONE);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
312 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
313 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHAFUNC, D3DCMP_GREATER);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
314 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHAREF, (DWORD)0x0);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
315 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_LIGHTING, FALSE);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
316 IDirect3DDevice9_SetSamplerState(priv->d3d_device, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
317 IDirect3DDevice9_SetSamplerState(priv->d3d_device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
318
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
319 return 1;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
320 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
321
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
322 /** @brief Fill D3D Presentation parameters
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
323 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
324 static void fill_d3d_presentparams(D3DPRESENT_PARAMETERS *present_params)
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
325 {
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
326 /* Prepare Direct3D initialization parameters. */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
327 memset(present_params, 0, sizeof(D3DPRESENT_PARAMETERS));
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
328 present_params->Windowed = TRUE;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
329 present_params->SwapEffect = D3DSWAPEFFECT_COPY;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
330 present_params->Flags = D3DPRESENTFLAG_VIDEO;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
331 present_params->hDeviceWindow = vo_w32_window; /* w32_common var */
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
332 present_params->BackBufferWidth = priv->cur_backbuf_width;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
333 present_params->BackBufferHeight = priv->cur_backbuf_height;
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
334 present_params->MultiSampleType = D3DMULTISAMPLE_NONE;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
335 present_params->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
336 present_params->BackBufferFormat = priv->desktop_fmt;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
337 present_params->BackBufferCount = 1;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
338 present_params->EnableAutoDepthStencil = FALSE;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
339 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
340
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
341
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
342 /** @brief Create a new backbuffer. Create or Reset the D3D
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
343 * device.
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
344 * @return 1 on success, 0 on failure
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
345 */
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
346 static int change_d3d_backbuffer(back_buffer_action_e action)
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
347 {
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
348 D3DPRESENT_PARAMETERS present_params;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
349
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
350 destroy_d3d_surfaces();
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
351
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
352 /* Grow the backbuffer in the required dimension. */
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
353 if (vo_dwidth > priv->cur_backbuf_width)
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
354 priv->cur_backbuf_width = vo_dwidth;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
355
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
356 if (vo_dheight > priv->cur_backbuf_height)
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
357 priv->cur_backbuf_height = vo_dheight;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
358
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
359 /* The grown backbuffer dimensions are ready and fill_d3d_presentparams
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
360 * will use them, so we can reset the device.
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
361 */
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
362 fill_d3d_presentparams(&present_params);
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
363
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
364 /* vo_w32_window is w32_common variable. It's a handle to the window. */
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
365 if (action == BACKBUFFER_CREATE &&
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
366 FAILED(IDirect3D9_CreateDevice(priv->d3d_handle,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
367 D3DADAPTER_DEFAULT,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
368 D3DDEVTYPE_HAL, vo_w32_window,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
369 D3DCREATE_SOFTWARE_VERTEXPROCESSING,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
370 &present_params, &priv->d3d_device))) {
28434
6d926d2693ec Avoid message spam during video adapter uncooperative state.
gogothebee
parents: 28433
diff changeset
371 mp_msg(MSGT_VO, MSGL_V,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
372 "<vo_direct3d>Creating Direct3D device failed.\n");
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
373 return 0;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
374 }
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
375
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
376 if (action == BACKBUFFER_RESET &&
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
377 FAILED(IDirect3DDevice9_Reset(priv->d3d_device, &present_params))) {
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
378 mp_msg(MSGT_VO, MSGL_ERR,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
379 "<vo_direct3d>Reseting Direct3D device failed.\n");
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
380 return 0;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
381 }
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
382
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
383 mp_msg(MSGT_VO, MSGL_V,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
384 "<vo_direct3d>New backbuffer (%dx%d), VO (%dx%d)\n",
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
385 present_params.BackBufferWidth, present_params.BackBufferHeight,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
386 vo_dwidth, vo_dheight);
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
387
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
388 return 1;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
389 }
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
390
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
391 /** @brief Configure initial Direct3D context. The first
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
392 * function called to initialize the D3D context.
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
393 * @return 1 on success, 0 on failure
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
394 */
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
395 static int configure_d3d(void)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
396 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
397 D3DDISPLAYMODE disp_mode;
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
398 D3DVIEWPORT9 vp = {0, 0, vo_dwidth, vo_dheight, 0, 1};
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
399
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
400 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>configure_d3d called.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
401
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
402 destroy_d3d_surfaces();
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
403
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
404 /* Get the current desktop display mode, so we can set up a back buffer
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
405 * of the same format. */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
406 if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
407 D3DADAPTER_DEFAULT,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
408 &disp_mode))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
409 mp_msg(MSGT_VO, MSGL_ERR,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
410 "<vo_direct3d>Reading adapter display mode failed.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
411 return 0;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
412 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
413
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
414 /* Write current Desktop's colorspace format in the global storage. */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
415 priv->desktop_fmt = disp_mode.Format;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
416
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
417 if (!change_d3d_backbuffer(BACKBUFFER_CREATE))
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
418 return 0;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
419
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
420 if (!create_d3d_surfaces())
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
421 return 0;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
422
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
423 if (FAILED(IDirect3DDevice9_SetViewport(priv->d3d_device,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
424 &vp))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
425 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Setting viewport failed.\n");
28416
0e24a99d51f5 Fix several return values
reimar
parents: 28344
diff changeset
426 return 0;
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
427 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
428
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
429 calc_fs_rect();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
430
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
431 return 1;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
432 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
433
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
434 /** @brief Reconfigure the whole Direct3D. Called only
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
435 * when the video adapter becomes uncooperative.
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
436 * @return 1 on success, 0 on failure
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
437 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
438 static int reconfigure_d3d(void)
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
439 {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
440 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>reconfigure_d3d called.\n");
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
441
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
442 /* Destroy the offscreen, OSD and backbuffer surfaces */
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
443 destroy_d3d_surfaces();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
444
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
445 /* Destroy the D3D Device */
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
446 if (priv->d3d_device)
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
447 IDirect3DDevice9_Release(priv->d3d_device);
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
448 priv->d3d_device = NULL;
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
449
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
450 /* Stop the whole Direct3D */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
451 IDirect3D9_Release(priv->d3d_handle);
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
452
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
453 /* Initialize Direct3D from the beginning */
30148
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
454 priv->d3d_handle = priv->pDirect3DCreate9(D3D_SDK_VERSION);
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
455 if (!priv->d3d_handle) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
456 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Initializing Direct3D failed.\n");
28416
0e24a99d51f5 Fix several return values
reimar
parents: 28344
diff changeset
457 return 0;
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
458 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
459
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
460 /* Configure Direct3D */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
461 if (!configure_d3d())
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
462 return 0;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
463
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
464 return 1;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
465 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
466
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
467 /** @brief Resize Direct3D context on window resize.
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
468 * @return 1 on success, 0 on failure
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
469 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
470 static int resize_d3d(void)
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
471 {
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
472 D3DVIEWPORT9 vp = {0, 0, vo_dwidth, vo_dheight, 0, 1};
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
473
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
474 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>resize_d3d called.\n");
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
475
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
476 /* Make sure that backbuffer is large enough to accomodate the new
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
477 viewport dimensions. Grow it if necessary. */
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
478
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
479 if (vo_dwidth > priv->cur_backbuf_width ||
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
480 vo_dheight > priv->cur_backbuf_height) {
28417
ca1c277b7d7e Check for change_d3d_backbuffer failure.
reimar
parents: 28416
diff changeset
481 if (!change_d3d_backbuffer(BACKBUFFER_RESET))
ca1c277b7d7e Check for change_d3d_backbuffer failure.
reimar
parents: 28416
diff changeset
482 return 0;
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
483 }
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
484
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
485 /* Destroy the OSD textures. They should always match the new dimensions
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
486 * of the onscreen window, so on each resize we need new OSD dimensions.
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
487 */
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
488
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
489 if (priv->d3d_texture_osd)
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
490 IDirect3DTexture9_Release(priv->d3d_texture_osd);
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
491 priv->d3d_texture_osd = NULL;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
492
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
493 if (priv->d3d_texture_system)
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
494 IDirect3DTexture9_Release(priv->d3d_texture_system);
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
495 priv->d3d_texture_system = NULL;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
496
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
497
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
498 /* Recreate the OSD. The function will observe that the offscreen plain
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
499 * surface and the backbuffer are not destroyed and will skip their creation,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
500 * effectively recreating only the OSD.
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
501 */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
502
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
503 if (!create_d3d_surfaces())
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
504 return 0;
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
505
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
506 if (FAILED(IDirect3DDevice9_SetViewport(priv->d3d_device,
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
507 &vp))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
508 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Setting viewport failed.\n");
28416
0e24a99d51f5 Fix several return values
reimar
parents: 28344
diff changeset
509 return 0;
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
510 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
511
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
512 calc_fs_rect();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
513
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
514 #ifdef CONFIG_FREETYPE
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
515 // font needs to be adjusted
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
516 force_load_font = 1;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
517 #endif
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
518 // OSD needs to be drawn fresh for new size
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
519 vo_osd_changed(OSDTYPE_OSD);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
520
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
521 return 1;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
522 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
523
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
524 /** @brief Uninitialize Direct3D and close the window.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
525 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
526 static void uninit_d3d(void)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
527 {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
528 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>uninit_d3d called.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
529
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
530 destroy_d3d_surfaces();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
531
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
532 /* Destroy the D3D Device */
28086
39902ce08dc5 Forgotten part of previous cosmetics commit
reimar
parents: 28085
diff changeset
533 if (priv->d3d_device)
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
534 IDirect3DDevice9_Release(priv->d3d_device);
28086
39902ce08dc5 Forgotten part of previous cosmetics commit
reimar
parents: 28085
diff changeset
535 priv->d3d_device = NULL;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
536
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
537 /* Stop the whole D3D. */
28028
62ccb6c80212 Consistency cosmetics: do not compare against NULL in ifs
reimar
parents: 28027
diff changeset
538 if (priv->d3d_handle) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
539 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Stopping Direct3D.\n");
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
540 IDirect3D9_Release(priv->d3d_handle);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
541 }
28087
46d015b2f8a3 Set d3d_handle to NULL after release.
reimar
parents: 28086
diff changeset
542 priv->d3d_handle = NULL;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
543 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
544
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
545 /** @brief Render a frame on the screen.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
546 * @param mpi mpi structure with the decoded frame inside
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
547 * @return VO_TRUE on success, VO_ERROR on failure
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
548 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
549 static uint32_t render_d3d_frame(mp_image_t *mpi)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
550 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
551 /* Uncomment when direct rendering is implemented.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
552 * if (mpi->flags & MP_IMGFLAG_DIRECT) ...
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
553 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
554
28422
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
555 /* If the D3D device is uncooperative (not initialized), return success.
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
556 The device will be probed for reinitialization in the next flip_page() */
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
557 if (!priv->d3d_device)
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
558 return VO_TRUE;
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
559
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
560 if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
27967
ad71ce76c6ce Move the StretchRect call from draw_slices to render_d3d_frame.
reimar
parents: 27966
diff changeset
561 goto skip_upload;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
562
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
563 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Copy a planar frame. */
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
564 draw_slice(mpi->planes, mpi->stride, mpi->w, mpi->h, 0, 0);
27967
ad71ce76c6ce Move the StretchRect call from draw_slices to render_d3d_frame.
reimar
parents: 27966
diff changeset
565 goto skip_upload;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
566 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
567
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
568 /* If we're here, then we should lock the rect and copy a packed frame */
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
569 if (!priv->locked_rect.pBits) {
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
570 if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
571 &priv->locked_rect, NULL, 0))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
572 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Surface lock failed.\n");
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
573 return VO_ERROR;
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
574 }
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
575 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
576
27968
1081658aa871 Move locked_rect from stack to priv struct in preparation for following patch.
reimar
parents: 27967
diff changeset
577 memcpy_pic(priv->locked_rect.pBits, mpi->planes[0], mpi->stride[0],
1081658aa871 Move locked_rect from stack to priv struct in preparation for following patch.
reimar
parents: 27967
diff changeset
578 mpi->height, priv->locked_rect.Pitch, mpi->stride[0]);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
579
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
580 skip_upload:
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
581 /* This unlock is used for both slice_draw path and render_d3d_frame path. */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
582 if (FAILED(IDirect3DSurface9_UnlockRect(priv->d3d_surface))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
583 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Surface unlock failed.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
584 return VO_ERROR;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
585 }
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
586 priv->locked_rect.pBits = NULL;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
587
27967
ad71ce76c6ce Move the StretchRect call from draw_slices to render_d3d_frame.
reimar
parents: 27966
diff changeset
588 if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
589 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>BeginScene failed.\n");
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
590 return VO_ERROR;
27967
ad71ce76c6ce Move the StretchRect call from draw_slices to render_d3d_frame.
reimar
parents: 27966
diff changeset
591 }
ad71ce76c6ce Move the StretchRect call from draw_slices to render_d3d_frame.
reimar
parents: 27966
diff changeset
592
27984
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
593 if (priv->is_clear_needed) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
594 IDirect3DDevice9_Clear(priv->d3d_device, 0, NULL,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
595 D3DCLEAR_TARGET, 0, 0, 0);
27984
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
596 priv->is_clear_needed = 0;
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
597 }
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
598
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
599 if (FAILED(IDirect3DDevice9_StretchRect(priv->d3d_device,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
600 priv->d3d_surface,
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
601 &priv->fs_panscan_rect,
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
602 priv->d3d_backbuf,
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
603 &priv->fs_movie_rect,
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
604 D3DTEXF_LINEAR))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
605 mp_msg(MSGT_VO, MSGL_ERR,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
606 "<vo_direct3d>Copying frame to the backbuffer failed.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
607 return VO_ERROR;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
608 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
609
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
610 if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
611 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>EndScene failed.\n");
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
612 return VO_ERROR;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
613 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
614
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
615 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
616 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
617
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
618
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
619 /** @brief Query if movie colorspace is supported by the HW.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
620 * @return 0 on failure, device capabilities (not probed
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
621 * currently) on success.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
622 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
623 static int query_format(uint32_t movie_fmt)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
624 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
625 int i;
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
626 for (i = 0; i < DISPLAY_FORMAT_TABLE_ENTRIES; i++) {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
627 if (fmt_table[i].mplayer_fmt == movie_fmt) {
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
628 /* Test conversion from Movie colorspace to
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
629 * display's target colorspace. */
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
630 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(priv->d3d_handle,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
631 D3DADAPTER_DEFAULT,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
632 D3DDEVTYPE_HAL,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
633 fmt_table[i].fourcc,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
634 priv->desktop_fmt))) {
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
635 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Rejected image format: %s\n",
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
636 vo_format_name(fmt_table[i].mplayer_fmt));
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
637 return 0;
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
638 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
639
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
640 priv->movie_src_fmt = fmt_table[i].fourcc;
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
641 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Accepted image format: %s\n",
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
642 vo_format_name(fmt_table[i].mplayer_fmt));
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
643 return (VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
644 | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
645
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
646 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
647 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
648
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
649 return 0;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
650 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
651
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
652 /****************************************************************************
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
653 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
654 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
655 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
656 * libvo Control / Callback functions *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
657 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
658 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
659 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
660 ****************************************************************************/
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
661
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
662
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
663
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
664
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
665 /** @brief libvo Callback: Preinitialize the video card.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
666 * Preinit the hardware just enough to be queried about
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
667 * supported formats.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
668 *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
669 * @return 0 on success, -1 on failure
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
670 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
671
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
672 static int preinit(const char *arg)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
673 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
674 D3DDISPLAYMODE disp_mode;
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
675 D3DCAPS9 disp_caps;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
676 DWORD texture_caps;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
677 DWORD dev_caps;
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
678
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
679 /* Set to zero all global variables. */
28027
f210d48c4396 Cosmetics: remove spaces before argument (
reimar
parents: 28026
diff changeset
680 priv = calloc(1, sizeof(struct global_priv));
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
681 if (!priv) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
682 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Allocating private memory failed.\n");
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
683 goto err_out;
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
684 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
685
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
686 /* FIXME
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
687 > Please use subopt-helper.h for this, see vo_gl.c:preinit for
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
688 > an example of how to use it.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
689 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
690
30148
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
691 priv->d3d9_dll = LoadLibraryA("d3d9.dll");
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
692 if (!priv->d3d9_dll) {
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
693 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to dynamically load d3d9.dll\n");
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
694 goto err_out;
30148
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
695 }
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
696
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
697 priv->pDirect3DCreate9 = (void *)GetProcAddress(priv->d3d9_dll, "Direct3DCreate9");
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
698 if (!priv->pDirect3DCreate9) {
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
699 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to find entry point of Direct3DCreate9\n");
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
700 goto err_out;
30148
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
701 }
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
702
517a800e940e Modify -vo direct3d so we do not have to link against d3d9.dll, it might
reimar
parents: 28598
diff changeset
703 priv->d3d_handle = priv->pDirect3DCreate9(D3D_SDK_VERSION);
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
704 if (!priv->d3d_handle) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
705 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Initializing Direct3D failed.\n");
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
706 goto err_out;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
707 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
708
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
709 if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
710 D3DADAPTER_DEFAULT,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
711 &disp_mode))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
712 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Reading display mode failed.\n");
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
713 goto err_out;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
714 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
715
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
716 /* Store in priv->desktop_fmt the user desktop's colorspace. Usually XRGB. */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
717 priv->desktop_fmt = disp_mode.Format;
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
718 priv->cur_backbuf_width = disp_mode.Width;
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
719 priv->cur_backbuf_height = disp_mode.Height;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
720
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
721 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Setting backbuffer dimensions to (%dx%d).\n",
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
722 disp_mode.Width, disp_mode.Height);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
723
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
724 if (FAILED(IDirect3D9_GetDeviceCaps(priv->d3d_handle,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
725 D3DADAPTER_DEFAULT,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
726 D3DDEVTYPE_HAL,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
727 &disp_caps))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
728 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Reading display capabilities failed.\n");
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
729 goto err_out;
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
730 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
731
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
732 /* Store relevant information reguarding caps of device */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
733 texture_caps = disp_caps.TextureCaps;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
734 dev_caps = disp_caps.DevCaps;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
735 priv->device_caps_power2_only = (texture_caps & D3DPTEXTURECAPS_POW2) &&
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
736 !(texture_caps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
737 priv->device_caps_square_only = texture_caps & D3DPTEXTURECAPS_SQUAREONLY;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
738 priv->device_texture_sys = dev_caps & D3DDEVCAPS_TEXTURESYSTEMMEMORY;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
739 priv->max_texture_width = disp_caps.MaxTextureWidth;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
740 priv->max_texture_height = disp_caps.MaxTextureHeight;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
741
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
742 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>device_caps_power2_only %d, device_caps_square_only %d\n"
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
743 "<vo_direct3d>device_texture_sys %d\n"
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
744 "<vo_direct3d>max_texture_width %d, max_texture_height %d\n",
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
745 priv->device_caps_power2_only, priv->device_caps_square_only,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
746 priv->device_texture_sys, priv->max_texture_width,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
747 priv->max_texture_height);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
748
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
749 /* w32_common framework call. Configures window on the screen, gets
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
750 * fullscreen dimensions and does other useful stuff.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
751 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
752 if (!vo_w32_init()) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
753 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Configuring onscreen window failed.\n");
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
754 goto err_out;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
755 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
756
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
757 return 0;
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
758
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
759 err_out:
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
760 uninit();
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
761 return -1;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
762 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
763
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
764
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
765
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
766 /** @brief libvo Callback: Handle control requests.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
767 * @return VO_TRUE on success, VO_NOTIMPL when not implemented
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
768 */
33305
ddb45e9443ec Remove the variable arguments from the libvo control() functions.
iive
parents: 32467
diff changeset
769 static int control(uint32_t request, void *data)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
770 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
771 switch (request) {
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
772 case VOCTRL_QUERY_FORMAT:
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
773 return query_format(*(uint32_t*) data);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
774 case VOCTRL_GET_IMAGE: /* Direct Rendering. Not implemented yet. */
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
775 mp_msg(MSGT_VO, MSGL_V,
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
776 "<vo_direct3d>Direct Rendering request. Not implemented yet.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
777 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
778 case VOCTRL_DRAW_IMAGE:
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
779 return render_d3d_frame(data);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
780 case VOCTRL_FULLSCREEN:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
781 vo_w32_fullscreen();
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
782 resize_d3d();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
783 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
784 case VOCTRL_RESET:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
785 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
786 case VOCTRL_PAUSE:
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
787 priv->is_paused = 1;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
788 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
789 case VOCTRL_RESUME:
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
790 priv->is_paused = 0;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
791 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
792 case VOCTRL_GUISUPPORT:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
793 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
794 case VOCTRL_SET_EQUALIZER:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
795 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
796 case VOCTRL_GET_EQUALIZER:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
797 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
798 case VOCTRL_ONTOP:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
799 vo_w32_ontop();
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
800 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
801 case VOCTRL_BORDER:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
802 vo_w32_border();
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
803 resize_d3d();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
804 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
805 case VOCTRL_UPDATE_SCREENINFO:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
806 w32_update_xinerama_info();
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
807 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
808 case VOCTRL_SET_PANSCAN:
28027
f210d48c4396 Cosmetics: remove spaces before argument (
reimar
parents: 28026
diff changeset
809 calc_fs_rect();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
810 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
811 case VOCTRL_GET_PANSCAN:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
812 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
813 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
814 return VO_FALSE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
815 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
816
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
817 /** @brief libvo Callback: Configre the Direct3D adapter.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
818 * @param width Movie source width
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
819 * @param height Movie source height
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
820 * @param d_width Screen (destination) width
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
821 * @param d_height Screen (destination) height
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
822 * @param options Options bitmap
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
823 * @param title Window title
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
824 * @param format Movie colorspace format (using MPlayer's
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
825 * defines, e.g. IMGFMT_YUY2)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
826 * @return 0 on success, VO_ERROR on failure
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
827 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
828 static int config(uint32_t width, uint32_t height, uint32_t d_width,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
829 uint32_t d_height, uint32_t options, char *title,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
830 uint32_t format)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
831 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
832
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
833 priv->src_width = width;
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
834 priv->src_height = height;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
835
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
836 /* w32_common framework call. Creates window on the screen with
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
837 * the given coordinates.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
838 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
839 if (!vo_w32_config(d_width, d_height, options)) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
840 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Creating onscreen window failed.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
841 return VO_ERROR;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
842 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
843
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
844 /* "config" may be called several times, so if this is not the first
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
845 * call, we should destroy Direct3D adapter and surfaces before
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
846 * calling configure_d3d, which will create them again.
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
847 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
848
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
849 destroy_d3d_surfaces();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
850
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
851 /* Destroy the D3D Device */
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
852 if (priv->d3d_device)
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
853 IDirect3DDevice9_Release(priv->d3d_device);
28085
f2606c3433ef Slightly simplify the conditional release/free code
reimar
parents: 28084
diff changeset
854 priv->d3d_device = NULL;
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
855
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
856 if (!configure_d3d())
27966
2a7bdb921eee Remove pointless is_cfG_finished variable.
reimar
parents: 27937
diff changeset
857 return VO_ERROR;
2a7bdb921eee Remove pointless is_cfG_finished variable.
reimar
parents: 27937
diff changeset
858
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
859 return 0; /* Success */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
860 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
861
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
862 /** @brief libvo Callback: Flip next already drawn frame on the
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
863 * screen.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
864 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
865 static void flip_page(void)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
866 {
28344
a69d51cd4ee3 Allocate a larger backbuffer to allow resizing without reinit.
reimar
parents: 28087
diff changeset
867 RECT rect = {0, 0, vo_dwidth, vo_dheight};
28422
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
868 if (!priv->d3d_device ||
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
869 FAILED(IDirect3DDevice9_Present(priv->d3d_device, &rect, 0, 0, 0))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
870 mp_msg(MSGT_VO, MSGL_V,
28419
d4fbeeaa1c76 Cosmetics: remove empty line, improve some messages.
reimar
parents: 28418
diff changeset
871 "<vo_direct3d>Trying to reinitialize uncooperative video adapter.\n");
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
872 if (!reconfigure_d3d()) {
28419
d4fbeeaa1c76 Cosmetics: remove empty line, improve some messages.
reimar
parents: 28418
diff changeset
873 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Reinitialization failed.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
874 return;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
875 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
876 else
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
877 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Video adapter reinitialized.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
878 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
879 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
880
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
881 /** @brief libvo Callback: Uninitializes all pointers and closes
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
882 * all D3D related stuff,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
883 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
884 static void uninit(void)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
885 {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
886 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>uninit called.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
887
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
888 uninit_d3d();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
889 vo_w32_uninit(); /* w32_common framework call */
30149
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
890 if (priv->d3d9_dll)
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
891 FreeLibrary(priv->d3d9_dll);
5f8cbd711a04 Avoid memleaks when vo_direct3d initialization fails.
reimar
parents: 30148
diff changeset
892 priv->d3d9_dll = NULL;
28027
f210d48c4396 Cosmetics: remove spaces before argument (
reimar
parents: 28026
diff changeset
893 free(priv);
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
894 priv = NULL;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
895 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
896
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
897 /** @brief libvo Callback: Handles video window events.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
898 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
899 static void check_events(void)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
900 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
901 int flags;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
902 /* w32_common framework call. Handles video window events.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
903 * Updates global libvo's vo_dwidth/vo_dheight upon resize
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
904 * with the new window width/height.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
905 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
906 flags = vo_w32_check_events();
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
907 if (flags & VO_EVENT_RESIZE)
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
908 resize_d3d();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
909
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
910 if ((flags & VO_EVENT_EXPOSE) && priv->is_paused)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
911 flip_page();
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
912 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
913
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
914 /** @brief libvo Callback: Draw slice
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
915 * @return 0 on success
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
916 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
917 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y )
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
918 {
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
919 char *my_src; /**< Pointer to the source image */
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
920 char *dst; /**< Pointer to the destination image */
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
921 int uv_stride; /**< Stride of the U/V planes */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
922
28422
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
923 /* If the D3D device is uncooperative (not initialized), return success.
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
924 The device will be probed for reinitialization in the next flip_page() */
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
925 if (!priv->d3d_device)
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
926 return 0;
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
927
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
928 /* Lock the offscreen surface if it's not already locked. */
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
929 if (!priv->locked_rect.pBits) {
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
930 if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
931 &priv->locked_rect, NULL, 0))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
932 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Surface lock failure.\n");
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
933 return VO_FALSE;
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
934 }
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
935 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
936
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
937 uv_stride = priv->locked_rect.Pitch / 2;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
938
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
939 /* Copy Y */
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
940 dst = priv->locked_rect.pBits;
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
941 dst = dst + priv->locked_rect.Pitch * y + x;
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
942 my_src = src[0];
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
943 memcpy_pic(dst, my_src, w, h, priv->locked_rect.Pitch, stride[0]);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
944
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
945 w /= 2;
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
946 h /= 2;
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
947 x /= 2;
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
948 y /= 2;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
949
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
950 /* Copy U */
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
951 dst = priv->locked_rect.pBits;
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
952 dst = dst + priv->locked_rect.Pitch * priv->src_height
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
953 + uv_stride * y + x;
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
954 if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2'))
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
955 my_src = src[2];
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
956 else
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
957 my_src = src[1];
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
958
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
959 memcpy_pic(dst, my_src, w, h, uv_stride, stride[1]);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
960
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
961 /* Copy V */
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
962 dst = priv->locked_rect.pBits;
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
963 dst = dst + priv->locked_rect.Pitch * priv->src_height
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
964 + uv_stride * (priv->src_height / 2) + uv_stride * y + x;
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
965 if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2'))
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
966 my_src=src[1];
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
967 else
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
968 my_src=src[2];
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
969
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
970 memcpy_pic(dst, my_src, w, h, uv_stride, stride[2]);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
971
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
972 return 0; /* Success */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
973 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
974
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
975 /** @brief libvo Callback: Unused function
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
976 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
977 static int draw_frame(uint8_t *src[])
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
978 {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
979 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>draw_frame called.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
980 return VO_FALSE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
981 }
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
982
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
983 /** @brief Maps MPlayer alpha to D3D
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
984 * 0x0 -> transparent and discarded by alpha test
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
985 * 0x1 -> 0xFF to become opaque
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
986 * other alpha values are inverted +1 (2 = -2)
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
987 * These values are then inverted again with
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
988 the texture filter D3DBLEND_INVSRCALPHA
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
989 */
33411
320890c90a8a vo_direct3d: Mark function only used within the file as static.
diego
parents: 33305
diff changeset
990 static void vo_draw_alpha_l8a8(int w, int h, unsigned char* src,
320890c90a8a vo_direct3d: Mark function only used within the file as static.
diego
parents: 33305
diff changeset
991 unsigned char *srca, int srcstride,
320890c90a8a vo_direct3d: Mark function only used within the file as static.
diego
parents: 33305
diff changeset
992 unsigned char* dstbase, int dststride)
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
993 {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
994 int y;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
995 for (y = 0; y < h; y++) {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
996 unsigned short *dst = (unsigned short*)dstbase;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
997 int x;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
998 for (x = 0; x < w; x++) {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
999 dst[x] = (-srca[x] << 8) | src[x];
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1000 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1001 src += srcstride;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1002 srca += srcstride;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1003 dstbase += dststride;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1004 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1005 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1006
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1007 /** @brief Callback function to render the OSD to the texture
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1008 */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1009 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1010 unsigned char *srca, int stride)
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1011 {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1012 D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1013 to copy MPlayer's frame inside it.*/
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1014
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1015 if (FAILED(IDirect3DTexture9_LockRect(priv->d3d_texture_system, 0,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1016 &locked_rect, NULL, 0))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
1017 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>OSD texture lock failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1018 return;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1019 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1020
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1021 vo_draw_alpha_l8a8(w, h, src, srca, stride,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1022 (unsigned char *)locked_rect.pBits + locked_rect.Pitch*y0 + 2*x0, locked_rect.Pitch);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1023
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1024 /* this unlock is used for both slice_draw path and D3DRenderFrame path */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1025 if (FAILED(IDirect3DTexture9_UnlockRect(priv->d3d_texture_system, 0))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
1026 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>OSD texture unlock failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1027 return;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1028 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1029
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1030 priv->is_osd_populated = 1;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1031 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1032
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1033 /** @brief libvo Callback: Draw OSD/Subtitles,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1034 */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1035 static void draw_osd(void)
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1036 {
28422
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
1037 // we can not render OSD if we lost the device e.g. because it was uncooperative
34266
a6a1c973de4e vo direct3d: fix crash in osd drawing code
al
parents: 33411
diff changeset
1038 // or if the OSD textures are not allocated (e.g. the window is minimized)
a6a1c973de4e vo direct3d: fix crash in osd drawing code
al
parents: 33411
diff changeset
1039 if (!priv->d3d_device || !priv->d3d_texture_osd)
28422
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
1040 return;
f7ba65621809 Add checks that a D3D device is available before attempting rendering.
reimar
parents: 28421
diff changeset
1041
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1042 if (vo_osd_changed(0)) {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1043 D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1044 to copy MPlayer's frame inside it.*/
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1045
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1046 /* clear the OSD */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1047 if (FAILED(IDirect3DTexture9_LockRect(priv->d3d_texture_system, 0,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1048 &locked_rect, NULL, 0))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
1049 mp_msg(MSGT_VO,MSGL_ERR, "<vo_direct3d>OSD texture lock failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1050 return;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1051 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1052
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1053 /* clear the whole texture to avoid issues due to interpolation */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1054 memset(locked_rect.pBits, 0, locked_rect.Pitch * priv->osd_texture_height);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1055
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1056 /* this unlock is used for both slice_draw path and D3DRenderFrame path */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1057 if (FAILED(IDirect3DTexture9_UnlockRect(priv->d3d_texture_system, 0))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
1058 mp_msg(MSGT_VO,MSGL_ERR, "<vo_direct3d>OSD texture unlock failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1059 return;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1060 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1061
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1062 priv->is_osd_populated = 0;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1063 /* required for if subs are in the boarder region */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1064 priv->is_clear_needed = 1;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1065
28598
4172d83194f2 Extend calc_src_dst_rects to also calculate the border values needed for
reimar
parents: 28511
diff changeset
1066 vo_draw_text_ext(priv->osd_width, priv->osd_height, priv->border_x, priv->border_y,
4172d83194f2 Extend calc_src_dst_rects to also calculate the border values needed for
reimar
parents: 28511
diff changeset
1067 priv->border_x, priv->border_y, priv->src_width, priv->src_height, draw_alpha);
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1068
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1069 if (!priv->device_texture_sys)
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1070 {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1071 /* only DMA to the shadow if its required */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1072 if (FAILED(IDirect3DDevice9_UpdateTexture(priv->d3d_device,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1073 (IDirect3DBaseTexture9 *)priv->d3d_texture_system,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1074 (IDirect3DBaseTexture9 *)priv->d3d_texture_osd))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
1075 mp_msg(MSGT_VO,MSGL_ERR, "<vo_direct3d>OSD texture transfer failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1076 return;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1077 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1078 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1079 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1080
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1081 /* update OSD */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1082
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1083 if (priv->is_osd_populated) {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1085 struct_vertex osd_quad_vb[] = {
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1086 {-1.0f, 1.0f, 0.0f, 0, 0 },
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1087 { 1.0f, 1.0f, 0.0f, 1, 0 },
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1088 {-1.0f,-1.0f, 0.0f, 0, 1 },
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1089 { 1.0f,-1.0f, 0.0f, 1, 1 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1090 };
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1091
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1092 /* calculate the texture coordinates */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1093 osd_quad_vb[1].tu =
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1094 osd_quad_vb[3].tu = (float)priv->osd_width / priv->osd_texture_width;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1095 osd_quad_vb[2].tv =
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1096 osd_quad_vb[3].tv = (float)priv->osd_height / priv->osd_texture_height;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1097
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1098 if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
1099 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1100 return;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1101 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1102
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1103 /* turn on alpha test */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1104 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHABLENDENABLE, TRUE);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1105 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHATESTENABLE, TRUE);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1106
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1107 /* need to use a texture here (done here as we may be able to texture from system memory) */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1108 IDirect3DDevice9_SetTexture(priv->d3d_device, 0,
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1109 (IDirect3DBaseTexture9 *)(priv->device_texture_sys
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1110 ? priv->d3d_texture_system : priv->d3d_texture_osd));
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1111
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1112 IDirect3DDevice9_SetFVF(priv->d3d_device, D3DFVF_MY_VERTEX);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1113 IDirect3DDevice9_DrawPrimitiveUP(priv->d3d_device, D3DPT_TRIANGLESTRIP, 2, osd_quad_vb, sizeof(struct_vertex));
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1114
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1115 /* turn off alpha test */
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1116 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHATESTENABLE, FALSE);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1117 IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHABLENDENABLE, FALSE);
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1118
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1119 if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) {
28433
701150ac1b54 Unify info/error messages to a common style:
gogothebee
parents: 28422
diff changeset
1120 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed.\n");
28084
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1121 return;
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1122 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1123 }
f38929a49c2f First version of OSD support for vo_direct3d
reimar
parents: 28079
diff changeset
1124 }