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