annotate libvo/vo_direct3d.c @ 28029:07ae7bc7487b

Cosmetics: Remove unnecessary ()
author reimar
date Tue, 02 Dec 2008 09:46:08 +0000
parents 62ccb6c80212
children fd628452e165
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"
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
33
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
34 static const vo_info_t info =
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
35 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
36 "Direct3D 9 Renderer",
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
37 "direct3d",
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
38 "Georgi Petrov (gogothebee) <gogothebee@gmail.com>",
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
39 ""
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
40 };
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 * Link essential libvo functions: preinit, config, control, draw_frame,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
44 * draw_slice, draw_osd, flip_page, check_events, uninit and
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
45 * the structure info.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
46 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
47 const LIBVO_EXTERN(direct3d)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
48
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
49
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
50 /* Global variables "priv" structure. I try to keep their count low.
27921
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 static struct global_priv {
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
53 int is_paused; /**< 1 = Movie is paused,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
54 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
55 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
56 0 = (default) Don't clear it */
27968
1081658aa871 Move locked_rect from stack to priv struct in preparation for following patch.
reimar
parents: 27967
diff changeset
57 D3DLOCKED_RECT locked_rect; /**< The locked Offscreen surface */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
58 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
59 in fullscreen */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
60 RECT fs_panscan_rect; /**< PanScan source surface cropping in
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
61 fullscreen */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
62 int src_width; /**< Source (movie) width */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
63 int src_height; /**< Source (movie) heigth */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
64
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
65 D3DFORMAT movie_src_fmt; /**< Movie colorspace format (depends on
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
66 the movie's codec) */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
67 D3DFORMAT desktop_fmt; /**< Desktop (screen) colorspace format.
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
68 Usually XRGB */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
69 LPDIRECT3D9 d3d_handle; /**< Direct3D Handle */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
70 LPDIRECT3DDEVICE9 d3d_device; /**< The Direct3D Adapter */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
71 IDirect3DSurface9 *d3d_surface; /**< Offscreen Direct3D Surface. MPlayer
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
72 renders inside it. Uses colorspace
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
73 priv->movie_src_fmt */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
74 IDirect3DSurface9 *d3d_backbuf; /**< Video card's back buffer (used to
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
75 display next frame) */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
76 } *priv;
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
77
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
78 typedef struct {
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
79 const unsigned int mplayer_fmt; /**< Given by MPlayer */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
80 const D3DFORMAT fourcc; /**< Required by D3D's test function */
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
81 } struct_fmt_table;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
82
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
83 /* Map table from reported MPlayer format to the required
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
84 fourcc. This is needed to perform the format query. */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
85
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
86 static const struct_fmt_table fmt_table[] = {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
87 {IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')},
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
88 {IMGFMT_I420, MAKEFOURCC('I','4','2','0')},
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
89 {IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')},
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
90 {IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')},
28007
16b39ef63bb5 Use D3DFMT_ constants where possible instead of MAKEFOURCC
reimar
parents: 28006
diff changeset
91 {IMGFMT_YUY2, D3DFMT_YUY2},
16b39ef63bb5 Use D3DFMT_ constants where possible instead of MAKEFOURCC
reimar
parents: 28006
diff changeset
92 {IMGFMT_UYVY, D3DFMT_UYVY},
28006
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
93 {IMGFMT_BGR32, D3DFMT_X8R8G8B8},
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
94 {IMGFMT_RGB32, D3DFMT_X8B8G8R8},
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
95 {IMGFMT_BGR24, D3DFMT_R8G8B8}, //untested
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
96 {IMGFMT_BGR16, D3DFMT_R5G6B5},
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
97 {IMGFMT_BGR15, D3DFMT_X1R5G5B5},
c06e8f1eec97 Add support for RGB formats to vo_direct3d
reimar
parents: 27985
diff changeset
98 {IMGFMT_BGR8 , D3DFMT_R3G3B2}, //untested
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
99 };
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
100
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
101 #define DISPLAY_FORMAT_TABLE_ENTRIES (sizeof(fmt_table) / sizeof(fmt_table[0]))
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
102
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
103 /****************************************************************************
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
104 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
105 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
106 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
107 * Direct3D specific implementation functions *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
108 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
109 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
110 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
111 ****************************************************************************/
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
112
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
113 /** @brief Calculate scaled fullscreen movie rectangle with
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
114 * preserved aspect ratio.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
115 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
116 static void calc_fs_rect(void)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
117 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
118 int scaled_height = 0;
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
119 int scaled_width = 0;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
120
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
121 // set default values
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
122 priv->fs_movie_rect.left = 0;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
123 priv->fs_movie_rect.right = vo_dwidth;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
124 priv->fs_movie_rect.top = 0;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
125 priv->fs_movie_rect.bottom = vo_dheight;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
126 priv->fs_panscan_rect.left = 0;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
127 priv->fs_panscan_rect.right = priv->src_width;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
128 priv->fs_panscan_rect.top = 0;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
129 priv->fs_panscan_rect.bottom = priv->src_height;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
130 if (!vo_fs) return;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
131
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
132 // adjust for fullscreen aspect and panscan
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
133 aspect(&scaled_width, &scaled_height, A_ZOOM);
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
134 panscan_calc();
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
135 scaled_width += vo_panscan_x;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
136 scaled_height += vo_panscan_y;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
137
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
138 // note: border is rounded to a multiple of two since at least
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
139 // ATI drivers can not handle odd values with YV12 input
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
140 if (scaled_width > vo_dwidth) {
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
141 int border = priv->src_width * (scaled_width - vo_dwidth) / scaled_width;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
142 border = (border / 2 + 1) & ~1;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
143 priv->fs_panscan_rect.left = border;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
144 priv->fs_panscan_rect.right = priv->src_width - border;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
145 } else {
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
146 priv->fs_movie_rect.left = (vo_dwidth - scaled_width) / 2;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
147 priv->fs_movie_rect.right = priv->fs_movie_rect.left + scaled_width;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
148 }
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
149 if (scaled_height > vo_dheight) {
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
150 int border = priv->src_height * (scaled_height - vo_dheight) / scaled_height;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
151 border = (border / 2 + 1) & ~1;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
152 priv->fs_panscan_rect.top = border;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
153 priv->fs_panscan_rect.bottom = priv->src_height - border;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
154 } else {
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
155 priv->fs_movie_rect.top = (vo_dheight - scaled_height) / 2;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
156 priv->fs_movie_rect.bottom = priv->fs_movie_rect.top + scaled_height;
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
157 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
158
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
159 mp_msg(MSGT_VO, MSGL_V,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
160 "<vo_direct3d>Fullscreen Movie Rect: t: %ld, l: %ld, r: %ld, b:%ld\r\n",
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
161 priv->fs_movie_rect.top, priv->fs_movie_rect.left,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
162 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
163
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
164 /* 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
165 * 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
166 * 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
167 * previous frame will be left. */
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
168 priv->is_clear_needed = 1;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
169 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
170
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
171 /** @brief Destroy D3D Offscreen and Backbuffer surfaces.
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
172 */
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
173 static void destroy_d3d_surfaces(void)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
174 {
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
175 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>destroy_d3d_surfaces called\r\n");
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
176 /* Let's destroy the old (if any) D3D Surfaces */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
177
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
178 if (priv->locked_rect.pBits) {
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
179 IDirect3DSurface9_UnlockRect(priv->d3d_surface);
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
180 priv->locked_rect.pBits = NULL;
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
181 }
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
182
28028
62ccb6c80212 Consistency cosmetics: do not compare against NULL in ifs
reimar
parents: 28027
diff changeset
183 if (priv->d3d_surface) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
184 IDirect3DSurface9_Release(priv->d3d_surface);
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
185 priv->d3d_surface = NULL;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
186 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
187
28028
62ccb6c80212 Consistency cosmetics: do not compare against NULL in ifs
reimar
parents: 28027
diff changeset
188 if (priv->d3d_backbuf) {
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
189 IDirect3DSurface9_Release(priv->d3d_backbuf);
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
190 priv->d3d_backbuf = NULL;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
191 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
192 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
193
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
194 /** @brief Create D3D Offscreen and Backbuffer surfaces.
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
195 * @return 1 on success, 0 on failure
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
196 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
197 static int create_d3d_surfaces(void)
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
198 {
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
199 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>create_d3d_surfaces called.\n");
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
200
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
201 if (FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface(
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
202 priv->d3d_device, priv->src_width, priv->src_height,
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
203 priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL))) {
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
204 mp_msg(MSGT_VO, MSGL_ERR,
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
205 "<vo_direct3d><INFO>IDirect3D9_CreateOffscreenPlainSurface Failed.\n");
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
206 return 0;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
207 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
208
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
209 if (FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0,
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
210 D3DBACKBUFFER_TYPE_MONO,
28029
07ae7bc7487b Cosmetics: Remove unnecessary ()
reimar
parents: 28028
diff changeset
211 &priv->d3d_backbuf))) {
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
212 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Back Buffer address get failed\n");
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
213 return 0;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
214 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
215
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
216 return 1;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
217 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
218
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
219 /** @brief Fill D3D Presentation parameters
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
220 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
221 static void fill_d3d_presentparams(D3DPRESENT_PARAMETERS *present_params)
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
222 {
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
223 /* Prepare Direct3D initialization parameters. */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
224 memset(present_params, 0, sizeof(D3DPRESENT_PARAMETERS));
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
225 present_params->Windowed = TRUE;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
226 present_params->SwapEffect = D3DSWAPEFFECT_COPY;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
227 present_params->Flags = D3DPRESENTFLAG_VIDEO;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
228 present_params->hDeviceWindow = vo_w32_window; /* w32_common var */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
229 present_params->BackBufferWidth = 0; /* Fill up window Width */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
230 present_params->BackBufferHeight = 0; /* Fill up window Height */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
231 present_params->MultiSampleType = D3DMULTISAMPLE_NONE;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
232 /* D3DPRESENT_INTERVAL_ONE = vsync */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
233 present_params->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
234 present_params->BackBufferFormat = priv->desktop_fmt;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
235 present_params->BackBufferCount = 1;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
236 present_params->EnableAutoDepthStencil = FALSE;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
237 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
238
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
239 /** @brief Configure initial Direct3D context. The first
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
240 * function called to initialize the D3D context.
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
241 * @return 1 on success, 0 on failure
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
242 */
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
243 static int configure_d3d(void)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
244 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
245 D3DPRESENT_PARAMETERS present_params;
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
246 D3DDISPLAYMODE disp_mode;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
247
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
248 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>configure_d3d called\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
249
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
250 /* Get the current desktop display mode, so we can set up a back buffer
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
251 * of the same format. */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
252 if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
253 D3DADAPTER_DEFAULT,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
254 &disp_mode))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
255 mp_msg(MSGT_VO, MSGL_ERR,
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
256 "<vo_direct3d><INFO>Could not read adapter display mode.\n");
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
257 return 0;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
258 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
259
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
260 /* 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
261 priv->desktop_fmt = disp_mode.Format;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
262
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
263 fill_d3d_presentparams(&present_params);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
264
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
265 /* vo_w32_window is w32_common variable. It's a handle to the window. */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
266 if (FAILED(IDirect3D9_CreateDevice(priv->d3d_handle,
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
267 D3DADAPTER_DEFAULT,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
268 D3DDEVTYPE_HAL, vo_w32_window,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
269 D3DCREATE_SOFTWARE_VERTEXPROCESSING,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
270 &present_params, &priv->d3d_device))) {
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
271 mp_msg(MSGT_VO, MSGL_ERR,
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
272 "<vo_direct3d><INFO>Could not create the D3D device\n");
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
273 return 0;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
274 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
275
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
276 if (!create_d3d_surfaces())
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
277 return 0;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
278
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
279 mp_msg(MSGT_VO, MSGL_V,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
280 "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n",
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
281 present_params.BackBufferWidth, present_params.BackBufferHeight,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
282 vo_dwidth, vo_dheight);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
283
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
284 calc_fs_rect();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
285
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
286 return 1;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
287 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
288
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
289 /** @brief Reconfigure the whole Direct3D. Called only
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
290 * when the video adapter becomes uncooperative.
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
291 * @return 1 on success, 0 on failure
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
292 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
293 static int reconfigure_d3d(void)
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
294 {
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
295 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>reconfigure_d3d called.\n");
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
296
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
297 /* Destroy the Offscreen and Backbuffer surfaces */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
298 destroy_d3d_surfaces();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
299
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
300 /* Destroy the D3D Device */
28028
62ccb6c80212 Consistency cosmetics: do not compare against NULL in ifs
reimar
parents: 28027
diff changeset
301 if (priv->d3d_device) {
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
302 IDirect3DDevice9_Release(priv->d3d_device);
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
303 priv->d3d_device = NULL;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
304 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
305
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
306 /* Stop the whole Direct3D */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
307 IDirect3D9_Release(priv->d3d_handle);
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
308
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
309 /* Initialize Direct3D from the beginning */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
310 priv->d3d_handle = Direct3DCreate9(D3D_SDK_VERSION);
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
311 if (!priv->d3d_handle) {
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
312 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to initialize Direct3D\n");
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
313 return -1;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
314 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
315
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
316 /* Configure Direct3D */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
317 if (!configure_d3d())
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
318 return 0;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
319
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
320 return 1;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
321 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
322
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
323
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
324 /** @brief Resize Direct3D context on window resize.
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
325 * @return 1 on success, 0 on failure
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
326 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
327 static int resize_d3d(void)
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
328 {
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
329 D3DPRESENT_PARAMETERS present_params;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
330
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
331 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>resize_d3d called.\n");
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
332
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
333
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
334 check_events();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
335
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
336 destroy_d3d_surfaces();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
337
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
338 /* Reset the D3D Device with all parameters the same except the new
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
339 * width/height.
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
340 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
341 fill_d3d_presentparams(&present_params);
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
342 if (FAILED(IDirect3DDevice9_Reset(priv->d3d_device, &present_params))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
343 mp_msg(MSGT_VO, MSGL_ERR,
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
344 "<vo_direct3d><INFO>Could not reset the D3D device\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
345 return 0;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
346 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
347
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
348 if (!create_d3d_surfaces())
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
349 return 0;
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
350
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
351 mp_msg(MSGT_VO, MSGL_V,
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
352 "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n",
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
353 present_params.BackBufferWidth, present_params.BackBufferHeight,
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
354 vo_dwidth, vo_dheight);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
355
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
356 calc_fs_rect();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
357
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
358 return 1;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
359 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
360
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
361 /** @brief Uninitialize Direct3D and close the window.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
362 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
363 static void uninit_d3d(void)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
364 {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
365 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>uninit_d3d called\r\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
366
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
367 destroy_d3d_surfaces();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
368
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
369 /* Destroy the D3D Device */
28028
62ccb6c80212 Consistency cosmetics: do not compare against NULL in ifs
reimar
parents: 28027
diff changeset
370 if (priv->d3d_device) {
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
371 IDirect3DDevice9_Release(priv->d3d_device);
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
372 priv->d3d_device = NULL;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
373 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
374
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
375 /* Stop the whole D3D. */
28028
62ccb6c80212 Consistency cosmetics: do not compare against NULL in ifs
reimar
parents: 28027
diff changeset
376 if (priv->d3d_handle) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
377 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Calling IDirect3D9_Release\r\n");
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
378 IDirect3D9_Release(priv->d3d_handle);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
379 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
380 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
381
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
382 /** @brief Render a frame on the screen.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
383 * @param mpi mpi structure with the decoded frame inside
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
384 * @return VO_TRUE on success, VO_ERROR on failure
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
385 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
386 static uint32_t render_d3d_frame(mp_image_t *mpi)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
387 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
388 /* Uncomment when direct rendering is implemented.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
389 * if (mpi->flags & MP_IMGFLAG_DIRECT) ...
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
390 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
391
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
392 resize_d3d();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
393
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
394 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
395 goto skip_upload;
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 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Copy a planar frame. */
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
398 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
399 goto skip_upload;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
400 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
401
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
402 /* 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
403 if (!priv->locked_rect.pBits) {
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
404 if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
405 &priv->locked_rect, NULL, 0))) {
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
406 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Surface lock failure\n");
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
407 return VO_ERROR;
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
408 }
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
409 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
410
27968
1081658aa871 Move locked_rect from stack to priv struct in preparation for following patch.
reimar
parents: 27967
diff changeset
411 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
412 mpi->height, priv->locked_rect.Pitch, mpi->stride[0]);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
413
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
414 skip_upload:
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
415 /* 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
416 if (FAILED(IDirect3DSurface9_UnlockRect(priv->d3d_surface))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
417 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Surface unlock failure\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
418 return VO_ERROR;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
419 }
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
420 priv->locked_rect.pBits = NULL;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
421
27967
ad71ce76c6ce Move the StretchRect call from draw_slices to render_d3d_frame.
reimar
parents: 27966
diff changeset
422 if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
423 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>BeginScene failed\n");
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
424 return VO_ERROR;
27967
ad71ce76c6ce Move the StretchRect call from draw_slices to render_d3d_frame.
reimar
parents: 27966
diff changeset
425 }
ad71ce76c6ce Move the StretchRect call from draw_slices to render_d3d_frame.
reimar
parents: 27966
diff changeset
426
27984
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
427 if (priv->is_clear_needed) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
428 IDirect3DDevice9_Clear(priv->d3d_device, 0, NULL,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
429 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
430 priv->is_clear_needed = 0;
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
431 }
21221fd6d994 Make sure the backbuffer is cleared when the border size might have changed.
reimar
parents: 27971
diff changeset
432
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
433 if (FAILED(IDirect3DDevice9_StretchRect(priv->d3d_device,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
434 priv->d3d_surface,
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
435 &priv->fs_panscan_rect,
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
436 priv->d3d_backbuf,
27937
1b333a631c10 Fix and enable panscan handling for vo_direct3d
reimar
parents: 27928
diff changeset
437 &priv->fs_movie_rect,
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
438 D3DTEXF_LINEAR))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
439 mp_msg(MSGT_VO, MSGL_ERR,
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
440 "<vo_direct3d>Unable to copy the frame to the back buffer\n");
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
441 return VO_ERROR;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
442 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
443
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
444 if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
445 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>EndScene failed\n");
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
446 return VO_ERROR;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
447 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
448
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
449 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
450 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
451
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
452
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
453 /** @brief Query if movie colorspace is supported by the HW.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
454 * @return 0 on failure, device capabilities (not probed
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
455 * currently) on success.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
456 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
457 static int query_format(uint32_t movie_fmt)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
458 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
459 int i;
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
460 for (i = 0; i < DISPLAY_FORMAT_TABLE_ENTRIES; i++) {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
461 if (fmt_table[i].mplayer_fmt == movie_fmt) {
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
462 /* Test conversion from Movie colorspace to
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
463 * display's target colorspace. */
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
464 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(priv->d3d_handle,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
465 D3DADAPTER_DEFAULT,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
466 D3DDEVTYPE_HAL,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
467 fmt_table[i].fourcc,
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
468 priv->desktop_fmt))) {
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
469 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Rejected image format: %s\n",
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
470 vo_format_name(fmt_table[i].mplayer_fmt));
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
471 return 0;
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
472 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
473
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
474 priv->movie_src_fmt = fmt_table[i].fourcc;
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
475 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
476 vo_format_name(fmt_table[i].mplayer_fmt));
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
477 return (VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
478 /*| VFCAP_OSD*/ | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN);
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
479
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
480 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
481 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
482
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
483 return 0;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
484 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
485
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
486 /****************************************************************************
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
487 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
488 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
489 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
490 * libvo Control / Callback functions *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
491 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
492 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
493 * *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
494 ****************************************************************************/
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
495
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
496
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
497
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
498
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
499 /** @brief libvo Callback: Preinitialize the video card.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
500 * Preinit the hardware just enough to be queried about
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
501 * supported formats.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
502 *
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
503 * @return 0 on success, -1 on failure
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
504 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
505
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
506 static int preinit(const char *arg)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
507 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
508 D3DDISPLAYMODE disp_mode;
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
509
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
510 /* Set to zero all global variables. */
28027
f210d48c4396 Cosmetics: remove spaces before argument (
reimar
parents: 28026
diff changeset
511 priv = calloc(1, sizeof(struct global_priv));
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
512 if (!priv) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
513 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Not enough memory\r\n");
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
514 return -1;
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
515 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
516
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
517 /* FIXME
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
518 > Please use subopt-helper.h for this, see vo_gl.c:preinit for
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
519 > an example of how to use it.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
520 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
521
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
522 priv->d3d_handle = Direct3DCreate9(D3D_SDK_VERSION);
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
523 if (!priv->d3d_handle) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
524 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to initialize Direct3D\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
525 return -1;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
526 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
527
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
528 if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
529 D3DADAPTER_DEFAULT,
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
530 &disp_mode))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
531 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Could not read display mode\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
532 return -1;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
533 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
534
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
535 /* 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
536 priv->desktop_fmt = disp_mode.Format;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
537
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
538 mp_msg(MSGT_VO, MSGL_V, "disp_mode.Width %d, disp_mode.Height %d\n",
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
539 disp_mode.Width, disp_mode.Height);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
540
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
541 /* w32_common framework call. Configures window on the screen, gets
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
542 * fullscreen dimensions and does other useful stuff.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
543 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
544 if (!vo_w32_init()) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
545 mp_msg(MSGT_VO, MSGL_V, "Unable to configure onscreen window\r\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
546 return -1;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
547 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
548
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
549 return 0;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
550 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
551
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
552
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
553
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
554 /** @brief libvo Callback: Handle control requests.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
555 * @return VO_TRUE on success, VO_NOTIMPL when not implemented
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
556 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
557 static int control(uint32_t request, void *data, ...)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
558 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
559 switch (request) {
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
560 case VOCTRL_QUERY_FORMAT:
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
561 return query_format(*(uint32_t*) data);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
562 case VOCTRL_GET_IMAGE: /* Direct Rendering. Not implemented yet. */
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
563 mp_msg(MSGT_VO, MSGL_V,
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
564 "<vo_direct3d>Direct Rendering request. Not implemented yet\n");
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
565 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
566 case VOCTRL_DRAW_IMAGE:
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
567 return render_d3d_frame(data);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
568 case VOCTRL_FULLSCREEN:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
569 vo_w32_fullscreen();
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
570 resize_d3d();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
571 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
572 case VOCTRL_RESET:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
573 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
574 case VOCTRL_PAUSE:
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
575 priv->is_paused = 1;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
576 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
577 case VOCTRL_RESUME:
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
578 priv->is_paused = 0;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
579 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
580 case VOCTRL_GUISUPPORT:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
581 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
582 case VOCTRL_SET_EQUALIZER:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
583 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
584 case VOCTRL_GET_EQUALIZER:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
585 return VO_NOTIMPL;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
586 case VOCTRL_ONTOP:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
587 vo_w32_ontop();
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
588 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
589 case VOCTRL_BORDER:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
590 vo_w32_border();
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
591 resize_d3d();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
592 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
593 case VOCTRL_UPDATE_SCREENINFO:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
594 w32_update_xinerama_info();
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
595 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
596 case VOCTRL_SET_PANSCAN:
28027
f210d48c4396 Cosmetics: remove spaces before argument (
reimar
parents: 28026
diff changeset
597 calc_fs_rect();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
598 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
599 case VOCTRL_GET_PANSCAN:
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
600 return VO_TRUE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
601 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
602 return VO_FALSE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
603 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
604
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
605 /** @brief libvo Callback: Configre the Direct3D adapter.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
606 * @param width Movie source width
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
607 * @param height Movie source height
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
608 * @param d_width Screen (destination) width
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
609 * @param d_height Screen (destination) height
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
610 * @param options Options bitmap
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
611 * @param title Window title
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
612 * @param format Movie colorspace format (using MPlayer's
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
613 * defines, e.g. IMGFMT_YUY2)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
614 * @return 0 on success, VO_ERROR on failure
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
615 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
616 static int config(uint32_t width, uint32_t height, uint32_t d_width,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
617 uint32_t d_height, uint32_t options, char *title,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
618 uint32_t format)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
619 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
620
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
621 priv->src_width = width;
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
622 priv->src_height = height;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
623
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
624 /* w32_common framework call. Creates window on the screen with
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
625 * the given coordinates.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
626 */
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
627 if (!vo_w32_config(d_width, d_height, options)) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
628 mp_msg(MSGT_VO, MSGL_V, "Unable to create onscreen window\r\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
629 return VO_ERROR;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
630 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
631
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
632 /* "config" may be called several times, so if this is not the first
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
633 * call, we should destroy Direct3D adapter and surfaces before
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
634 * calling configure_d3d, which will create them again.
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
635 */
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
636
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
637 destroy_d3d_surfaces();
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
638
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
639 /* Destroy the D3D Device */
28028
62ccb6c80212 Consistency cosmetics: do not compare against NULL in ifs
reimar
parents: 28027
diff changeset
640 if (priv->d3d_device) {
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
641 IDirect3DDevice9_Release(priv->d3d_device);
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
642 priv->d3d_device = NULL;
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
643 }
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
644
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
645 if (!configure_d3d())
27966
2a7bdb921eee Remove pointless is_cfG_finished variable.
reimar
parents: 27937
diff changeset
646 return VO_ERROR;
2a7bdb921eee Remove pointless is_cfG_finished variable.
reimar
parents: 27937
diff changeset
647
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
648 return 0; /* Success */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
649 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
650
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
651 /** @brief libvo Callback: Flip next already drawn frame on the
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
652 * screen.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
653 * @return N/A
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
654 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
655 static void flip_page(void)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
656 {
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
657 if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
658 mp_msg(MSGT_VO, MSGL_V,
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
659 "<vo_direct3d>Video adapter became uncooperative.\n");
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
660 mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Trying to reinitialize it...\n");
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
661 if (!reconfigure_d3d()) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
662 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Reinitialization Failed.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
663 return;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
664 }
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
665 if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
666 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Reinitialization Failed.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
667 return;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
668 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
669 else
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
670 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Video adapter reinitialized.\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
671
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
672 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
673 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
674
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
675 /** @brief libvo Callback: Draw OSD/Subtitles,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
676 * @return N/A
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
677 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
678 static void draw_osd(void)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
679 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
680 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
681
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
682 /** @brief libvo Callback: Uninitializes all pointers and closes
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
683 * all D3D related stuff,
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
684 * @return N/A
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
685 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
686 static void uninit(void)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
687 {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
688 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Uninitialization\r\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
689
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
690 uninit_d3d();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
691 vo_w32_uninit(); /* w32_common framework call */
28027
f210d48c4396 Cosmetics: remove spaces before argument (
reimar
parents: 28026
diff changeset
692 free(priv);
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
693 priv = NULL;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
694 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
695
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
696 /** @brief libvo Callback: Handles video window events.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
697 * @return N/A
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
698 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
699 static void check_events(void)
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
700 {
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
701 int flags;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
702 /* w32_common framework call. Handles video window events.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
703 * Updates global libvo's vo_dwidth/vo_dheight upon resize
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
704 * with the new window width/height.
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
705 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
706 flags = vo_w32_check_events();
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
707 if (flags & VO_EVENT_RESIZE)
28026
ace2f84df2bd Reorganize Direct3D initialization code.
reimar
parents: 28011
diff changeset
708 resize_d3d();
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
709
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
710 if ((flags & VO_EVENT_EXPOSE) && priv->is_paused)
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
711 flip_page();
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
712 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
713
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
714 /** @brief libvo Callback: Draw slice
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
715 * @return 0 on success
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
716 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
717 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
718 {
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
719 char *my_src; /**< Pointer to the source image */
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
720 char *dst; /**< Pointer to the destination image */
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
721 int uv_stride; /**< Stride of the U/V planes */
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
722
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
723 /* 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
724 if (!priv->locked_rect.pBits) {
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
725 if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
726 &priv->locked_rect, NULL, 0))) {
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
727 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Surface lock failure\n");
27970
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
728 return VO_FALSE;
2b6952476210 Fix indentation
reimar
parents: 27969
diff changeset
729 }
27969
7ddd69cf214f Lock/unlock surface only once even when drawing many slices.
reimar
parents: 27968
diff changeset
730 }
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
731
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
732 uv_stride = priv->locked_rect.Pitch / 2;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
733
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
734 /* Copy Y */
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
735 dst = priv->locked_rect.pBits;
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
736 dst = dst + priv->locked_rect.Pitch * y + x;
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
737 my_src = src[0];
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
738 memcpy_pic(dst, my_src, w, h, priv->locked_rect.Pitch, stride[0]);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
739
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
740 w /= 2;
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
741 h /= 2;
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
742 x /= 2;
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
743 y /= 2;
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
744
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
745 /* Copy U */
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
746 dst = priv->locked_rect.pBits;
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
747 dst = dst + priv->locked_rect.Pitch * priv->src_height
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
748 + uv_stride * y + x;
27928
6bc5182d635c Cosmetics: rename variables etc. in vo_direct3d.c
reimar
parents: 27925
diff changeset
749 if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2'))
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
750 my_src = src[2];
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
751 else
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
752 my_src = src[1];
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
753
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
754 memcpy_pic(dst, my_src, w, h, uv_stride, stride[1]);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
755
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
756 /* Copy V */
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
757 dst = priv->locked_rect.pBits;
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
758 dst = dst + priv->locked_rect.Pitch * priv->src_height
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
759 + 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
760 if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2'))
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
761 my_src=src[1];
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
762 else
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
763 my_src=src[2];
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
764
27971
916445fad12a Patch to improve/consistify coding style.
reimar
parents: 27970
diff changeset
765 memcpy_pic(dst, my_src, w, h, uv_stride, stride[2]);
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
766
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
767 return 0; /* Success */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
768 }
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
769
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
770 /** @brief libvo Callback: Unused function
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
771 * @return N/A
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
772 */
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
773 static int draw_frame(uint8_t *src[])
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
774 {
28011
7f7ffa0eb45a whitespace cosmetics: prettyprinting and indentation
diego
parents: 28007
diff changeset
775 mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>draw_frame called\n");
27921
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
776 return VO_FALSE;
327a98d2b55d Direct3D based video_out module.
reimar
parents:
diff changeset
777 }