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"
|
27921
|
33
|
|
34 static const vo_info_t info =
|
|
35 {
|
|
36 "Direct3D 9 Renderer",
|
|
37 "direct3d",
|
|
38 "Georgi Petrov (gogothebee) <gogothebee@gmail.com>",
|
|
39 ""
|
|
40 };
|
|
41
|
|
42 /*
|
|
43 * Link essential libvo functions: preinit, config, control, draw_frame,
|
|
44 * draw_slice, draw_osd, flip_page, check_events, uninit and
|
|
45 * the structure info.
|
|
46 */
|
|
47 const LIBVO_EXTERN(direct3d)
|
|
48
|
|
49
|
27928
|
50 /* Global variables "priv" structure. I try to keep their count low.
|
27921
|
51 */
|
27928
|
52 static struct global_priv {
|
|
53 int is_paused; /**< 1 = Movie is paused,
|
|
54 0 = Movie is not paused */
|
|
55 RECT fs_movie_rect; /**< Rect (upscaled) of the movie when displayed
|
|
56 in fullscreen */
|
|
57 RECT fs_panscan_rect; /**< PanScan source surface cropping in
|
|
58 fullscreen */
|
|
59 int src_width; /**< Source (movie) width */
|
|
60 int src_height; /**< Source (movie) heigth */
|
27921
|
61
|
27928
|
62 D3DFORMAT movie_src_fmt; /**< Movie colorspace format (depends on
|
|
63 the movie's codec) */
|
|
64 D3DFORMAT desktop_fmt; /**< Desktop (screen) colorspace format.
|
|
65 Usually XRGB */
|
|
66 LPDIRECT3D9 d3d_handle; /**< Direct3D Handle */
|
|
67 LPDIRECT3DDEVICE9 d3d_device; /**< The Direct3D Adapter */
|
|
68 IDirect3DSurface9 *d3d_surface; /**< Offscreen Direct3D Surface. MPlayer
|
|
69 renders inside it. Uses colorspace
|
|
70 priv->movie_src_fmt */
|
|
71 IDirect3DSurface9 *d3d_backbuf; /**< Video card's back buffer (used to
|
|
72 display next frame) */
|
|
73 } *priv;
|
|
74
|
|
75 typedef struct {
|
|
76 const unsigned int mplayer_fmt; /**< Given by MPlayer */
|
|
77 const D3DFORMAT fourcc; /**< Required by D3D's test function */
|
|
78 } struct_fmt_table;
|
27921
|
79
|
|
80 /* Map table from reported MPlayer format to the required
|
27928
|
81 fourcc. This is needed to perform the format query. */
|
27921
|
82
|
27928
|
83 static const struct_fmt_table fmt_table[] = {
|
27921
|
84 {IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')},
|
|
85 {IMGFMT_I420, MAKEFOURCC('I','4','2','0')},
|
|
86 {IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')},
|
|
87 {IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')},
|
|
88 {IMGFMT_YUY2, MAKEFOURCC('Y','U','Y','2')},
|
27928
|
89 {IMGFMT_UYVY, MAKEFOURCC('U','Y','V','Y')},
|
27921
|
90 };
|
|
91
|
|
92 #define DISPLAY_FORMAT_TABLE_ENTRIES \
|
27928
|
93 (sizeof(fmt_table) / sizeof(fmt_table[0]))
|
27921
|
94
|
|
95 /****************************************************************************
|
|
96 * *
|
|
97 * *
|
|
98 * *
|
|
99 * Direct3D specific implementation functions *
|
|
100 * *
|
|
101 * *
|
|
102 * *
|
|
103 ****************************************************************************/
|
|
104
|
|
105 /** @brief Calculate scaled fullscreen movie rectangle with
|
|
106 * preserved aspect ratio.
|
|
107 */
|
27928
|
108 static void calc_fs_rect(void)
|
27921
|
109 {
|
27928
|
110 int scaled_height = 0;
|
|
111 int scaled_width = 0;
|
27921
|
112
|
27937
|
113 // set default values
|
|
114 priv->fs_movie_rect.left = 0;
|
|
115 priv->fs_movie_rect.right = vo_dwidth;
|
|
116 priv->fs_movie_rect.top = 0;
|
|
117 priv->fs_movie_rect.bottom = vo_dheight;
|
|
118 priv->fs_panscan_rect.left = 0;
|
|
119 priv->fs_panscan_rect.right = priv->src_width;
|
|
120 priv->fs_panscan_rect.top = 0;
|
|
121 priv->fs_panscan_rect.bottom = priv->src_height;
|
|
122 if (!vo_fs) return;
|
|
123
|
|
124 // adjust for fullscreen aspect and panscan
|
27928
|
125 aspect(&scaled_width, &scaled_height, A_ZOOM);
|
27937
|
126 panscan_calc();
|
|
127 scaled_width += vo_panscan_x;
|
|
128 scaled_height += vo_panscan_y;
|
27921
|
129
|
27937
|
130 // note: border is rounded to a multiple of two since at least
|
|
131 // ATI drivers can not handle odd values with YV12 input
|
|
132 if (scaled_width > vo_dwidth) {
|
|
133 int border = priv->src_width * (scaled_width - vo_dwidth) / scaled_width;
|
|
134 border = (border / 2 + 1) & ~1;
|
|
135 priv->fs_panscan_rect.left = border;
|
|
136 priv->fs_panscan_rect.right = priv->src_width - border;
|
|
137 } else {
|
|
138 priv->fs_movie_rect.left = (vo_dwidth - scaled_width) / 2;
|
|
139 priv->fs_movie_rect.right = priv->fs_movie_rect.left + scaled_width;
|
|
140 }
|
|
141 if (scaled_height > vo_dheight) {
|
|
142 int border = priv->src_height * (scaled_height - vo_dheight) / scaled_height;
|
|
143 border = (border / 2 + 1) & ~1;
|
|
144 priv->fs_panscan_rect.top = border;
|
|
145 priv->fs_panscan_rect.bottom = priv->src_height - border;
|
|
146 } else {
|
|
147 priv->fs_movie_rect.top = (vo_dheight - scaled_height) / 2;
|
|
148 priv->fs_movie_rect.bottom = priv->fs_movie_rect.top + scaled_height;
|
|
149 }
|
27921
|
150
|
|
151 mp_msg(MSGT_VO,MSGL_V,
|
|
152 "<vo_direct3d>Fullscreen Movie Rect: t: %ld, l: %ld, r: %ld, b:%ld\r\n",
|
27928
|
153 priv->fs_movie_rect.top, priv->fs_movie_rect.left,
|
|
154 priv->fs_movie_rect.right, priv->fs_movie_rect.bottom);
|
27921
|
155 }
|
|
156
|
|
157 /** @brief Destroy D3D Context related to the current window.
|
|
158 */
|
27928
|
159 static void destroy_d3d_context(void)
|
27921
|
160 {
|
27928
|
161 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>destroy_d3d_context called\r\n");
|
27921
|
162 /* Let's destroy the old (if any) D3D Content */
|
|
163
|
27928
|
164 if (priv->d3d_surface != NULL) {
|
|
165 IDirect3DSurface9_Release (priv->d3d_surface);
|
|
166 priv->d3d_surface = NULL;
|
27921
|
167 }
|
|
168
|
27928
|
169 if (priv->d3d_device != NULL) {
|
|
170 IDirect3DDevice9_Release (priv->d3d_device);
|
|
171 priv->d3d_device = NULL;
|
27921
|
172 }
|
|
173
|
27928
|
174 /* The following is not a memory leak. d3d_backbuf is not malloc'ed
|
27921
|
175 * but just holds a pointer to the back buffer. Nobody gets hurt from
|
|
176 * setting it to NULL.
|
|
177 */
|
27928
|
178 priv->d3d_backbuf = NULL;
|
27921
|
179 }
|
|
180
|
|
181
|
|
182 /** @brief (Re)Initialize Direct3D. Kill and recreate context.
|
|
183 * The first function called to initialize D3D context.
|
|
184 * @return 1 on success, 0 on failure
|
|
185 */
|
27928
|
186 static int reconfigure_d3d(void)
|
27921
|
187 {
|
27928
|
188 D3DPRESENT_PARAMETERS present_params;
|
|
189 D3DDISPLAYMODE disp_mode;
|
27921
|
190
|
27928
|
191 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d><INFO>reconfigure_d3d called \n");
|
27921
|
192
|
27928
|
193 destroy_d3d_context();
|
27921
|
194
|
|
195 /* Get the current desktop display mode, so we can set up a back buffer
|
|
196 * of the same format. */
|
27928
|
197 if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
|
|
198 D3DADAPTER_DEFAULT,
|
|
199 &disp_mode))) {
|
27921
|
200 mp_msg(MSGT_VO,MSGL_ERR,
|
|
201 "<vo_direct3d><INFO>Could not read adapter display mode.\n");
|
|
202 return 0;
|
|
203 }
|
|
204
|
|
205 /* Write current Desktop's colorspace format in the global storage. */
|
27928
|
206 priv->desktop_fmt = disp_mode.Format;
|
27921
|
207
|
|
208 /* Prepare Direct3D initialization parameters. */
|
27928
|
209 memset(&present_params, 0, sizeof(D3DPRESENT_PARAMETERS));
|
|
210 present_params.Windowed = TRUE;
|
|
211 present_params.SwapEffect = D3DSWAPEFFECT_COPY;
|
|
212 present_params.Flags = D3DPRESENTFLAG_VIDEO;
|
|
213 present_params.hDeviceWindow = vo_w32_window; /* w32_common var */
|
|
214 present_params.BackBufferWidth = 0; /* Fill up window Width */
|
|
215 present_params.BackBufferHeight = 0; /* Fill up window Height */
|
|
216 present_params.MultiSampleType = D3DMULTISAMPLE_NONE;
|
27921
|
217 /* D3DPRESENT_INTERVAL_ONE = vsync */
|
27928
|
218 present_params.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
|
219 present_params.BackBufferFormat = priv->desktop_fmt;
|
|
220 present_params.BackBufferCount = 1;
|
|
221 present_params.EnableAutoDepthStencil = FALSE;
|
27921
|
222
|
|
223 /* vo_w32_window is w32_common variable. It's a handle to the window. */
|
27928
|
224 if (FAILED(IDirect3D9_CreateDevice(priv->d3d_handle,
|
27921
|
225 D3DADAPTER_DEFAULT,
|
|
226 D3DDEVTYPE_HAL, vo_w32_window,
|
|
227 D3DCREATE_SOFTWARE_VERTEXPROCESSING,
|
27928
|
228 &present_params, &priv->d3d_device))) {
|
27921
|
229 mp_msg(MSGT_VO,MSGL_ERR,
|
|
230 "<vo_direct3d><INFO>Could not create the D3D device\n");
|
|
231 return 0;
|
|
232 }
|
|
233
|
|
234 mp_msg(MSGT_VO,MSGL_V,
|
|
235 "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n",
|
27928
|
236 present_params.BackBufferWidth, present_params.BackBufferHeight,
|
27921
|
237 vo_dwidth, vo_dheight);
|
|
238
|
27928
|
239 if (FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface(
|
|
240 priv->d3d_device, priv->src_width, priv->src_height,
|
|
241 priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL))) {
|
27921
|
242 mp_msg(MSGT_VO,MSGL_ERR,
|
|
243 "<vo_direct3d><INFO>IDirect3D9_CreateOffscreenPlainSurface Failed.\n");
|
|
244 return 0;
|
|
245 }
|
|
246
|
27928
|
247 if (FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0,
|
|
248 D3DBACKBUFFER_TYPE_MONO,
|
|
249 &(priv->d3d_backbuf)))) {
|
27921
|
250 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Back Buffer address get failed\n");
|
|
251 return 0;
|
|
252 }
|
|
253
|
|
254 /* Fill the Surface with black color. */
|
27928
|
255 IDirect3DDevice9_ColorFill(priv->d3d_device, priv->d3d_surface, NULL,
|
27921
|
256 D3DCOLOR_ARGB(0xFF, 0, 0, 0) );
|
|
257
|
27937
|
258 calc_fs_rect();
|
27921
|
259
|
|
260 return 1;
|
|
261 }
|
|
262
|
|
263 /** @brief Uninitialize Direct3D and close the window.
|
|
264 */
|
27928
|
265 static void uninit_d3d(void)
|
27921
|
266 {
|
27928
|
267 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>uninit_d3d called\r\n");
|
27921
|
268
|
|
269 /* Destroy D3D Context inside the window. */
|
27928
|
270 destroy_d3d_context();
|
27921
|
271
|
|
272 /* Stop the whole D3D. */
|
27928
|
273 if (NULL != priv->d3d_handle) {
|
27921
|
274 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Calling IDirect3D9_Release\r\n");
|
27928
|
275 IDirect3D9_Release(priv->d3d_handle);
|
27921
|
276 }
|
|
277 }
|
|
278
|
|
279 /** @brief Render a frame on the screen.
|
|
280 * @param mpi mpi structure with the decoded frame inside
|
|
281 * @return VO_TRUE on success, VO_ERROR on failure
|
|
282 */
|
27928
|
283 static uint32_t render_d3d_frame(mp_image_t *mpi)
|
27921
|
284 {
|
27928
|
285 D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order
|
27921
|
286 to copy MPlayer's frame inside it.*/
|
|
287
|
|
288 /* Uncomment when direct rendering is implemented.
|
|
289 * if (mpi->flags & MP_IMGFLAG_DIRECT) ...
|
|
290 */
|
|
291
|
|
292 if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
|
|
293 return VO_TRUE;
|
|
294
|
27928
|
295 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Copy a planar frame. */
|
27921
|
296 draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0);
|
|
297 return VO_TRUE;
|
|
298 }
|
|
299
|
|
300 /* If the previous if failed, we should draw a packed frame */
|
27928
|
301 if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) {
|
27921
|
302 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed\n");
|
|
303 return VO_ERROR;
|
|
304 }
|
|
305
|
27928
|
306 if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
|
|
307 &locked_rect, NULL, 0))) {
|
27921
|
308 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Surface lock failure\n");
|
|
309 return VO_ERROR;
|
|
310 }
|
|
311
|
27928
|
312 memcpy_pic(locked_rect.pBits, mpi->planes[0], mpi->stride[0],
|
|
313 mpi->height, locked_rect.Pitch, mpi->stride[0]);
|
27921
|
314
|
27928
|
315 if (FAILED(IDirect3DSurface9_UnlockRect(priv->d3d_surface))) {
|
27921
|
316 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface unlock failure\n");
|
|
317 return VO_ERROR;
|
|
318 }
|
|
319
|
27928
|
320 if (FAILED(IDirect3DDevice9_StretchRect(priv->d3d_device,
|
|
321 priv->d3d_surface,
|
27937
|
322 &priv->fs_panscan_rect,
|
27928
|
323 priv->d3d_backbuf,
|
27937
|
324 &priv->fs_movie_rect,
|
27928
|
325 D3DTEXF_LINEAR))) {
|
27921
|
326 mp_msg(MSGT_VO,MSGL_ERR,
|
|
327 "<vo_direct3d>Unable to copy the frame to the back buffer\n");
|
|
328 return VO_ERROR;
|
|
329 }
|
|
330
|
27928
|
331 if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) {
|
27921
|
332 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed\n");
|
|
333 return VO_ERROR;
|
|
334 }
|
|
335
|
|
336 return VO_TRUE;
|
|
337 }
|
|
338
|
|
339
|
|
340 /** @brief Query if movie colorspace is supported by the HW.
|
|
341 * @return 0 on failure, device capabilities (not probed
|
|
342 * currently) on success.
|
|
343 */
|
27928
|
344 static int query_format(uint32_t movie_fmt)
|
27921
|
345 {
|
|
346 int i;
|
27928
|
347 for (i=0; i < DISPLAY_FORMAT_TABLE_ENTRIES; i++) {
|
|
348 if (fmt_table[i].mplayer_fmt == movie_fmt) {
|
27921
|
349 /* Test conversion from Movie colorspace to
|
|
350 * display's target colorspace. */
|
27928
|
351 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(
|
|
352 priv->d3d_handle,
|
27921
|
353 D3DADAPTER_DEFAULT,
|
|
354 D3DDEVTYPE_HAL,
|
27928
|
355 fmt_table[i].fourcc,
|
|
356 priv->desktop_fmt))) {
|
|
357 mp_msg(MSGT_VO,MSGL_V,
|
|
358 "<vo_direct3d>Rejected image format: %s\n",
|
|
359 vo_format_name(fmt_table[i].mplayer_fmt));
|
|
360 return 0;
|
|
361 }
|
27921
|
362
|
27928
|
363 priv->movie_src_fmt = fmt_table[i].fourcc;
|
|
364 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Accepted image format: %s\n",
|
|
365 vo_format_name(fmt_table[i].mplayer_fmt));
|
27921
|
366 return (VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW
|
|
367 /*| VFCAP_OSD*/ | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN);
|
|
368
|
|
369 }
|
|
370 }
|
|
371
|
|
372 return 0;
|
|
373 }
|
|
374
|
|
375 /****************************************************************************
|
|
376 * *
|
|
377 * *
|
|
378 * *
|
|
379 * libvo Control / Callback functions *
|
|
380 * *
|
|
381 * *
|
|
382 * *
|
|
383 ****************************************************************************/
|
|
384
|
|
385
|
|
386
|
|
387
|
|
388 /** @brief libvo Callback: Preinitialize the video card.
|
|
389 * Preinit the hardware just enough to be queried about
|
|
390 * supported formats.
|
|
391 *
|
|
392 * @return 0 on success, -1 on failure
|
|
393 */
|
27928
|
394
|
27921
|
395 static int preinit(const char *arg)
|
|
396 {
|
27928
|
397 D3DDISPLAYMODE disp_mode;
|
|
398
|
27921
|
399 /* Set to zero all global variables. */
|
27928
|
400 priv = calloc(1, sizeof (struct global_priv));
|
|
401 if (!priv) {
|
|
402 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Not enough memory\r\n");
|
|
403 return -1;
|
|
404 }
|
27921
|
405
|
|
406 /* FIXME
|
|
407 > Please use subopt-helper.h for this, see vo_gl.c:preinit for
|
|
408 > an example of how to use it.
|
|
409 */
|
|
410
|
27928
|
411 priv->d3d_handle = Direct3DCreate9(D3D_SDK_VERSION);
|
|
412 if (!priv->d3d_handle) {
|
27921
|
413 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Unable to initialize Direct3D\n");
|
|
414 return -1;
|
|
415 }
|
|
416
|
27928
|
417 if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
|
|
418 D3DADAPTER_DEFAULT,
|
|
419 &disp_mode))) {
|
27921
|
420 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Could not read display mode\n");
|
|
421 return -1;
|
|
422 }
|
|
423
|
27928
|
424 /* Store in priv->desktop_fmt the user desktop's colorspace. Usually XRGB. */
|
|
425 priv->desktop_fmt = disp_mode.Format;
|
27921
|
426
|
27928
|
427 mp_msg(MSGT_VO,MSGL_V,"disp_mode.Width %d, disp_mode.Height %d\n",
|
|
428 disp_mode.Width, disp_mode.Height);
|
27921
|
429
|
|
430 /* w32_common framework call. Configures window on the screen, gets
|
|
431 * fullscreen dimensions and does other useful stuff.
|
|
432 */
|
27928
|
433 if (!vo_w32_init()) {
|
27921
|
434 mp_msg(MSGT_VO,MSGL_V,"Unable to configure onscreen window\r\n");
|
|
435 return -1;
|
|
436 }
|
|
437
|
|
438 return 0;
|
|
439 }
|
|
440
|
|
441
|
|
442
|
|
443 /** @brief libvo Callback: Handle control requests.
|
|
444 * @return VO_TRUE on success, VO_NOTIMPL when not implemented
|
|
445 */
|
|
446 static int control(uint32_t request, void *data, ...)
|
|
447 {
|
27928
|
448 switch (request) {
|
27921
|
449 case VOCTRL_QUERY_FORMAT:
|
27928
|
450 return query_format(*(uint32_t*) data);
|
27921
|
451 case VOCTRL_GET_IMAGE: /* Direct Rendering. Not implemented yet. */
|
|
452 mp_msg(MSGT_VO,MSGL_V,
|
|
453 "<vo_direct3d>Direct Rendering request. Not implemented yet\n");
|
|
454 return VO_NOTIMPL;
|
|
455 case VOCTRL_DRAW_IMAGE:
|
27928
|
456 return render_d3d_frame(data);
|
27921
|
457 case VOCTRL_FULLSCREEN:
|
|
458 vo_w32_fullscreen();
|
27928
|
459 reconfigure_d3d();
|
27921
|
460 return VO_TRUE;
|
|
461 case VOCTRL_RESET:
|
|
462 return VO_NOTIMPL;
|
|
463 case VOCTRL_PAUSE:
|
27928
|
464 priv->is_paused = 1;
|
27921
|
465 return VO_TRUE;
|
|
466 case VOCTRL_RESUME:
|
27928
|
467 priv->is_paused = 0;
|
27921
|
468 return VO_TRUE;
|
|
469 case VOCTRL_GUISUPPORT:
|
|
470 return VO_NOTIMPL;
|
|
471 case VOCTRL_SET_EQUALIZER:
|
|
472 return VO_NOTIMPL;
|
|
473 case VOCTRL_GET_EQUALIZER:
|
|
474 return VO_NOTIMPL;
|
|
475 case VOCTRL_ONTOP:
|
|
476 vo_w32_ontop();
|
|
477 return VO_TRUE;
|
|
478 case VOCTRL_BORDER:
|
|
479 vo_w32_border();
|
27928
|
480 reconfigure_d3d();
|
27921
|
481 return VO_TRUE;
|
|
482 case VOCTRL_UPDATE_SCREENINFO:
|
|
483 w32_update_xinerama_info();
|
|
484 return VO_TRUE;
|
|
485 case VOCTRL_SET_PANSCAN:
|
27937
|
486 calc_fs_rect ();
|
27921
|
487 return VO_TRUE;
|
|
488 case VOCTRL_GET_PANSCAN:
|
|
489 return VO_TRUE;
|
|
490 }
|
|
491 return VO_FALSE;
|
|
492 }
|
|
493
|
|
494 /** @brief libvo Callback: Configre the Direct3D adapter.
|
|
495 * @param width Movie source width
|
|
496 * @param height Movie source height
|
|
497 * @param d_width Screen (destination) width
|
|
498 * @param d_height Screen (destination) height
|
|
499 * @param options Options bitmap
|
|
500 * @param title Window title
|
|
501 * @param format Movie colorspace format (using MPlayer's
|
|
502 * defines, e.g. IMGFMT_YUY2)
|
|
503 * @return 0 on success, VO_ERROR on failure
|
|
504 */
|
|
505 static int config(uint32_t width, uint32_t height, uint32_t d_width,
|
|
506 uint32_t d_height, uint32_t options, char *title,
|
|
507 uint32_t format)
|
|
508 {
|
27928
|
509
|
|
510 priv->src_width = width;
|
|
511 priv->src_height = height;
|
27921
|
512
|
|
513 /* w32_common framework call. Creates window on the screen with
|
|
514 * the given coordinates.
|
|
515 */
|
27928
|
516 if (!vo_w32_config(d_width, d_height, options)) {
|
27921
|
517 mp_msg(MSGT_VO,MSGL_V,"Unable to create onscreen window\r\n");
|
|
518 return VO_ERROR;
|
|
519 }
|
|
520
|
27966
|
521 if (!reconfigure_d3d())
|
|
522 return VO_ERROR;
|
|
523
|
27921
|
524 return 0; /* Success */
|
|
525 }
|
|
526
|
|
527 /** @brief libvo Callback: Flip next already drawn frame on the
|
|
528 * screen.
|
|
529 * @return N/A
|
|
530 */
|
|
531 static void flip_page(void)
|
|
532 {
|
27928
|
533 if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) {
|
27921
|
534 mp_msg(MSGT_VO,MSGL_V,
|
|
535 "<vo_direct3d>Video adapter became uncooperative.\n");
|
|
536 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Trying to reinitialize it...\n");
|
27928
|
537 if (!reconfigure_d3d()) {
|
27921
|
538 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Reinitialization Failed.\n");
|
|
539 return;
|
|
540 }
|
27928
|
541 if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) {
|
27921
|
542 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Reinitialization Failed.\n");
|
|
543 return;
|
|
544 }
|
|
545 else
|
|
546 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Video adapter reinitialized.\n");
|
|
547
|
|
548 }
|
27928
|
549 /*IDirect3DDevice9_Clear (priv->d3d_device, 0, NULL, D3DCLEAR_TARGET, 0, 0, 0);*/
|
27921
|
550 }
|
|
551
|
|
552 /** @brief libvo Callback: Draw OSD/Subtitles,
|
|
553 * @return N/A
|
|
554 */
|
|
555 static void draw_osd(void)
|
|
556 {
|
|
557 }
|
|
558
|
|
559 /** @brief libvo Callback: Uninitializes all pointers and closes
|
|
560 * all D3D related stuff,
|
|
561 * @return N/A
|
|
562 */
|
|
563 static void uninit(void)
|
|
564 {
|
|
565 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Uninitialization\r\n");
|
|
566
|
27928
|
567 uninit_d3d();
|
27921
|
568 vo_w32_uninit(); /* w32_common framework call */
|
27928
|
569 free (priv);
|
|
570 priv = NULL;
|
27921
|
571 }
|
|
572
|
|
573 /** @brief libvo Callback: Handles video window events.
|
|
574 * @return N/A
|
|
575 */
|
|
576 static void check_events(void)
|
|
577 {
|
|
578 int flags;
|
|
579 /* w32_common framework call. Handles video window events.
|
|
580 * Updates global libvo's vo_dwidth/vo_dheight upon resize
|
|
581 * with the new window width/height.
|
|
582 */
|
|
583 flags = vo_w32_check_events();
|
|
584 if (flags & VO_EVENT_RESIZE)
|
27928
|
585 reconfigure_d3d();
|
27921
|
586
|
27928
|
587 if ((flags & VO_EVENT_EXPOSE) && priv->is_paused)
|
27921
|
588 flip_page();
|
|
589 }
|
|
590
|
|
591 /** @brief libvo Callback: Draw slice
|
|
592 * @return 0 on success
|
|
593 */
|
|
594 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y )
|
|
595 {
|
27928
|
596 D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order
|
27921
|
597 to copy MPlayer's frame inside it.*/
|
|
598 char *Src; /**< Pointer to the source image */
|
|
599 char *Dst; /**< Pointer to the destination image */
|
|
600 int UVstride; /**< Stride of the U/V planes */
|
|
601
|
27928
|
602 if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) {
|
27921
|
603 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed\n");
|
|
604 return VO_ERROR;
|
|
605 }
|
|
606
|
27928
|
607 if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
|
|
608 &locked_rect, NULL, 0))) {
|
27921
|
609 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface lock failure\n");
|
|
610 return VO_FALSE;
|
|
611 }
|
|
612
|
27928
|
613 UVstride = locked_rect.Pitch / 2;
|
27921
|
614
|
|
615 /* Copy Y */
|
27928
|
616 Dst = locked_rect.pBits;
|
|
617 Dst = Dst + locked_rect.Pitch * y + x;
|
27921
|
618 Src=src[0];
|
27928
|
619 memcpy_pic(Dst, Src, w, h, locked_rect.Pitch, stride[0]);
|
27921
|
620
|
|
621 w/=2;h/=2;x/=2;y/=2;
|
|
622
|
|
623 /* Copy U */
|
27928
|
624 Dst = locked_rect.pBits;
|
|
625 Dst = Dst + locked_rect.Pitch * priv->src_height
|
27921
|
626 + UVstride * y + x;
|
27928
|
627 if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2'))
|
27921
|
628 Src=src[2];
|
|
629 else
|
|
630 Src=src[1];
|
|
631
|
|
632 memcpy_pic(Dst, Src, w, h, UVstride, stride[1]);
|
|
633
|
|
634 /* Copy V */
|
27928
|
635 Dst = locked_rect.pBits;
|
|
636 Dst = Dst + locked_rect.Pitch * priv->src_height
|
|
637 + UVstride * (priv->src_height / 2) + UVstride * y + x;
|
|
638 if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2'))
|
27921
|
639 Src=src[1];
|
|
640 else
|
|
641 Src=src[2];
|
|
642
|
|
643 memcpy_pic(Dst, Src, w, h, UVstride, stride[2]);
|
|
644
|
27928
|
645 if (FAILED(IDirect3DSurface9_UnlockRect(priv->d3d_surface))) {
|
27921
|
646 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface unlock failure\n");
|
|
647 return VO_ERROR;
|
|
648 }
|
|
649
|
27928
|
650 if (FAILED(IDirect3DDevice9_StretchRect(priv->d3d_device,
|
|
651 priv->d3d_surface,
|
27937
|
652 &priv->fs_panscan_rect,
|
27928
|
653 priv->d3d_backbuf,
|
27937
|
654 &priv->fs_movie_rect,
|
27928
|
655 D3DTEXF_LINEAR))) {
|
27921
|
656 mp_msg(MSGT_VO,MSGL_V,
|
|
657 "<vo_direct3d>Unable to copy the frame to the back buffer\n");
|
|
658 return VO_ERROR;
|
|
659 }
|
|
660
|
27928
|
661 if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) {
|
27921
|
662 mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed\n");
|
|
663 return VO_ERROR;
|
|
664 }
|
|
665
|
|
666 return 0; /* Success */
|
|
667 }
|
|
668
|
|
669 /** @brief libvo Callback: Unused function
|
|
670 * @return N/A
|
|
671 */
|
|
672 static int draw_frame(uint8_t *src[])
|
|
673 {
|
|
674 mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>draw_frame called\n");
|
|
675 return VO_FALSE;
|
|
676 }
|