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