1 Index: modules/gui/macosx/voutqt.m
2 ===================================================================
3 --- modules/gui/macosx/voutqt.m (revision 20403)
4 +++ modules/gui/macosx/voutqt.m (working copy)
9 +#include <vlc/libvlc_structures.h>
11 #define QT_MAX_DIRECTBUFFERS 10
12 #define VL_MAX_DISPLAYS 16
14 p_vout->pf_display = DisplayVideo;
15 p_vout->pf_control = ControlVideo;
17 - /* Are we embedded? If so, the drawable value will be a pointer to a
18 + /* Are we embedded? If so, the drawable value should be a pointer to a
19 * CGrafPtr that we're expected to use */
20 var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
21 - if( value_drawable.i_int != 0 )
22 + if( value_drawable.i_int != 0 ) {
23 + vlc_value_t value_drawable_type;
25 + var_Get( p_vout->p_libvlc, "macosx-drawable-type", &value_drawable_type );
26 + if( value_drawable_type.i_int != VLCDrawableCGrafPtr ) {
27 + msg_Err( p_vout, "QT interface requires a CGrafPtr when embedded" );
31 p_vout->p_sys->b_embedded = VLC_TRUE;
34 p_vout->p_sys->b_embedded = VLC_FALSE;
37 p_vout->p_sys->b_cpu_has_simd =
38 vlc_CPU() & (CPU_CAPABILITY_ALTIVEC|CPU_CAPABILITY_MMXEXT);
39 Index: modules/gui/macosx/voutgl.m
40 ===================================================================
41 --- modules/gui/macosx/voutgl.m (revision 20403)
42 +++ modules/gui/macosx/voutgl.m (working copy)
44 #include <string.h> /* strerror() */
47 +#include <vlc/libvlc_structures.h>
52 #include <OpenGL/gl.h>
55 +#include <Carbon/Carbon.h>
57 /*****************************************************************************
60 /* Mozilla plugin-related variables */
61 vlc_bool_t b_embedded;
63 - AGLDrawable agl_drawable;
65 int i_width, i_height;
67 WindowGroupRef winGroup;
68 vlc_bool_t b_clipped_out;
69 - Rect clipBounds, viewBounds;
70 + Rect clipBounds, viewBounds;
72 + libvlc_macosx_drawable_type_t drawable_type;
75 + ControlRef ControlRef;
79 /*****************************************************************************
81 static void aglReshape( vout_thread_t * p_vout );
82 static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
84 -static int aglInit( vout_thread_t * p_vout )
85 +/* returns the bounds of the drawable control/window */
86 +static Rect aglGetBounds( vout_thread_t * p_vout )
91 + switch( p_vout->p_sys->drawable_type ) {
92 + case VLCDrawableCGrafPtr:
93 + win = GetWindowFromPort( p_vout->p_sys->drawable.CGrafPtr );
94 + GetWindowPortBounds( win, &rect );
97 + case VLCDrawableControlRef:
98 + win = GetControlOwner( p_vout->p_sys->drawable.ControlRef );
99 + GetControlBounds( p_vout->p_sys->drawable.ControlRef, &rect );
106 +/* returns the window containing the drawable area */
107 +static WindowRef aglGetWindow( vout_thread_t * p_vout )
111 + switch( p_vout->p_sys->drawable_type ) {
112 + case VLCDrawableCGrafPtr:
113 + window = GetWindowFromPort( p_vout->p_sys->drawable.CGrafPtr );
116 + case VLCDrawableControlRef:
117 + window = GetControlOwner( p_vout->p_sys->drawable.ControlRef );
124 +/* gets the graphics port associated with our drawing area */
125 +static CGrafPtr aglGetPort( vout_thread_t * p_vout )
129 + switch( p_vout->p_sys->drawable_type ) {
130 + case VLCDrawableCGrafPtr:
131 + port = p_vout->p_sys->drawable.CGrafPtr;
134 + case VLCDrawableControlRef:
135 + port = GetWindowPort( GetControlOwner(
136 + p_vout->p_sys->drawable.ControlRef
144 +/* (re)process "drawable-*" and "macosx-drawable-type" variables. `drawable' is a
145 + parameter to allow it to be overridden (REPARENT) */
146 +static int aglProcessDrawable( vout_thread_t * p_vout, libvlc_drawable_t drawable )
149 + vlc_value_t val_type;
150 + AGLDrawable agl_drawable;
151 + Rect clipBounds,viewBounds;
156 - var_Get( p_vout->p_libvlc, "drawable", &val );
157 - p_vout->p_sys->agl_drawable = (AGLDrawable)val.i_int;
158 - aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
159 + var_Get( p_vout->p_libvlc, "macosx-drawable-type", &val_type );
161 + p_vout->p_sys->drawable_type = val_type.i_int;
162 + switch( val_type.i_int ) {
163 + case VLCDrawableCGrafPtr:
164 + p_vout->p_sys->drawable.CGrafPtr = (CGrafPtr)drawable;
167 + case VLCDrawableControlRef:
168 + p_vout->p_sys->drawable.ControlRef = (ControlRef)drawable;
172 + agl_drawable = (AGLDrawable)aglGetPort( p_vout );
173 + aglSetDrawable(p_vout->p_sys->agl_ctx, agl_drawable);
175 var_Get( p_vout->p_libvlc, "drawable-view-top", &val );
176 viewBounds.top = val.i_int;
177 var_Get( p_vout->p_libvlc, "drawable-view-left", &val );
178 @@ -481,15 +561,21 @@
179 viewBounds.bottom = val.i_int;
180 var_Get( p_vout->p_libvlc, "drawable-view-right", &val );
181 viewBounds.right = val.i_int;
182 - var_Get( p_vout->p_libvlc, "drawable-clip-top", &val );
183 - clipBounds.top = val.i_int;
184 - var_Get( p_vout->p_libvlc, "drawable-clip-left", &val );
185 - clipBounds.left = val.i_int;
186 - var_Get( p_vout->p_libvlc, "drawable-clip-bottom", &val );
187 - clipBounds.bottom = val.i_int;
188 - var_Get( p_vout->p_libvlc, "drawable-clip-right", &val );
189 - clipBounds.right = val.i_int;
191 + if( !viewBounds.top && !viewBounds.left && !viewBounds.right && !viewBounds.bottom ) {
192 + /* view bounds not set, use control/window bounds */
193 + clipBounds = viewBounds = aglGetBounds( p_vout );
195 + var_Get( p_vout->p_libvlc, "drawable-clip-top", &val );
196 + clipBounds.top = val.i_int;
197 + var_Get( p_vout->p_libvlc, "drawable-clip-left", &val );
198 + clipBounds.left = val.i_int;
199 + var_Get( p_vout->p_libvlc, "drawable-clip-bottom", &val );
200 + clipBounds.bottom = val.i_int;
201 + var_Get( p_vout->p_libvlc, "drawable-clip-right", &val );
202 + clipBounds.right = val.i_int;
205 p_vout->p_sys->b_clipped_out = (clipBounds.top == clipBounds.bottom)
206 || (clipBounds.left == clipBounds.right);
207 if( ! p_vout->p_sys->b_clipped_out )
210 p_vout->p_sys->clipBounds = clipBounds;
211 p_vout->p_sys->viewBounds = viewBounds;
214 +static int aglInit( vout_thread_t * p_vout )
218 + var_Get( p_vout->p_libvlc, "drawable", &val );
219 + aglProcessDrawable( p_vout, val.i_int );
226 static int aglManage( vout_thread_t * p_vout )
228 + if( p_vout->p_sys->drawable_type == VLCDrawableControlRef ) {
229 + /* auto-detect size changes in the control by polling */
230 + Rect clipBounds, viewBounds;
232 + clipBounds = viewBounds = aglGetBounds( p_vout );
234 + if( memcmp(&clipBounds, &(p_vout->p_sys->clipBounds), sizeof(clipBounds) )
235 + && memcmp(&viewBounds, &(p_vout->p_sys->viewBounds), sizeof(viewBounds)) )
237 + /* size has changed since last poll */
239 + p_vout->p_sys->clipBounds = clipBounds;
240 + p_vout->p_sys->viewBounds = viewBounds;
242 + aglSetViewport(p_vout, viewBounds, clipBounds);
243 + aglReshape( p_vout );
244 + aglUnlock( p_vout );
248 if( p_vout->i_changes & VOUT_ASPECT_CHANGE )
251 @@ -586,42 +700,28 @@
253 /* Close the fullscreen window and resume normal drawing */
258 var_Get( p_vout->p_libvlc, "drawable", &val );
259 - p_vout->p_sys->agl_drawable = (AGLDrawable)val.i_int;
260 - aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
261 + aglProcessDrawable( p_vout, val.i_int );
263 - var_Get( p_vout->p_libvlc, "drawable-view-top", &val );
264 - viewBounds.top = val.i_int;
265 - var_Get( p_vout->p_libvlc, "drawable-view-left", &val );
266 - viewBounds.left = val.i_int;
267 - var_Get( p_vout->p_libvlc, "drawable-view-bottom", &val );
268 - viewBounds.bottom = val.i_int;
269 - var_Get( p_vout->p_libvlc, "drawable-view-right", &val );
270 - viewBounds.right = val.i_int;
271 - var_Get( p_vout->p_libvlc, "drawable-clip-top", &val );
272 - clipBounds.top = val.i_int;
273 - var_Get( p_vout->p_libvlc, "drawable-clip-left", &val );
274 - clipBounds.left = val.i_int;
275 - var_Get( p_vout->p_libvlc, "drawable-clip-bottom", &val );
276 - clipBounds.bottom = val.i_int;
277 - var_Get( p_vout->p_libvlc, "drawable-clip-right", &val );
278 - clipBounds.right = val.i_int;
279 + /*the following was here, superfluous due to the same in aglLock?
280 + aglSetCurrentContext(p_vout->p_sys->agl_ctx);*/
282 - aglSetCurrentContext(p_vout->p_sys->agl_ctx);
283 - aglSetViewport(p_vout, viewBounds, clipBounds);
285 /* Most Carbon APIs are not thread-safe, therefore delagate some GUI visibilty update to the main thread */
286 sendEventToMainThread(GetWindowEventTarget(p_vout->p_sys->theWindow), kEventClassVLCPlugin, kEventVLCPluginHideFullscreen);
290 + CGDirectDisplayID displayID;
291 + CGRect displayBounds;
294 - GDHandle deviceHdl = GetMainDevice();
295 - deviceRect = (*deviceHdl)->gdRect;
296 + /* the main display has its origin at (0,0) */
297 + displayBounds = CGDisplayBounds( CGMainDisplayID() );
298 + deviceRect.left = 0;
299 + deviceRect.top = 0;
300 + deviceRect.right = displayBounds.size.width;
301 + deviceRect.bottom = displayBounds.size.height;
303 if( !p_vout->p_sys->theWindow )
306 SetWindowBounds(p_vout->p_sys->theWindow, kWindowContentRgn, &deviceRect);
308 glClear( GL_COLOR_BUFFER_BIT );
309 - p_vout->p_sys->agl_drawable = (AGLDrawable)GetWindowPort(p_vout->p_sys->theWindow);
310 - aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
311 + p_vout->p_sys->drawable_type = VLCDrawableCGrafPtr;
312 + p_vout->p_sys->drawable.CGrafPtr = GetWindowPort(p_vout->p_sys->theWindow);
313 + aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->drawable.CGrafPtr);
314 aglSetCurrentContext(p_vout->p_sys->agl_ctx);
315 aglSetViewport(p_vout, deviceRect, deviceRect);
316 //aglSetFullScreen(p_vout->p_sys->agl_ctx, device_width, device_height, 0, 0);
317 @@ -753,11 +854,10 @@
321 - AGLDrawable drawable = (AGLDrawable)va_arg( args, int);
322 - if( !p_vout->b_fullscreen && drawable != p_vout->p_sys->agl_drawable )
323 + libvlc_drawable_t drawable = (libvlc_drawable_t)va_arg( args, int);
324 + if( !p_vout->b_fullscreen )
326 - p_vout->p_sys->agl_drawable = drawable;
327 - aglSetDrawable(p_vout->p_sys->agl_ctx, drawable);
328 + aglProcessDrawable( p_vout, drawable );
334 if( ! p_vout->p_sys->b_clipped_out )
339 p_vout->p_sys->b_got_frame = VLC_TRUE;
340 aglSwapBuffers(p_vout->p_sys->agl_ctx);
342 + win = aglGetWindow( p_vout );
343 + rect = aglGetBounds( p_vout );
345 + InvalWindowRect( win, &rect );
349 @@ -788,12 +896,14 @@
350 // however AGL coordinates are based on window structure region
351 // and are vertically flipped
353 - CGrafPtr port = (CGrafPtr)p_vout->p_sys->agl_drawable;
355 Rect winBounds, clientBounds;
357 - GetWindowBounds(GetWindowFromPort(port),
358 + window = aglGetWindow( p_vout );
360 + GetWindowBounds(window,
361 kWindowStructureRgn, &winBounds);
362 - GetWindowBounds(GetWindowFromPort(port),
363 + GetWindowBounds(window,
364 kWindowContentRgn, &clientBounds);
366 /* update video clipping bounds in drawable */
367 Index: bindings/python/vlc_instance.c
368 ===================================================================
369 --- bindings/python/vlc_instance.c (revision 20403)
370 +++ bindings/python/vlc_instance.c (working copy)
375 +vlcInstance_video_set_macosx_parent_type( PyObject *self, PyObject *args )
377 + libvlc_exception_t ex;
378 + int i_drawable_type;
380 + if( !PyArg_ParseTuple( args, "i", &i_drawable_type ) )
383 + if( i_drawable_type != VLCDrawableCGrafPtr
384 + && i_drawable_type != VLCDrawableControlRef )
386 + PyErr_SetString( vlcInstance_Exception, "Invalid drawable type." );
391 + libvlc_video_set_macosx_parent_type( LIBVLC_INSTANCE->p_instance, (libvlc_macosx_drawable_type_t) i_drawable_type, &ex );
394 + Py_INCREF( Py_None );
399 vlcInstance_video_set_size( PyObject *self, PyObject *args )
401 libvlc_exception_t ex;
403 "playlist_get_input() -> object Return the current input"},
404 { "video_set_parent", vlcInstance_video_set_parent, METH_VARARGS,
405 "video_set_parent(xid=int) Set the parent xid or HWND"},
406 + { "video_set_macosx_parent_type", vlcInstance_video_set_macosx_parent_type, METH_VARARGS,
407 + "video_set_macosx_parent_type(drawabletype=int) Set the type of parent used on Mac OS/X (see the Drawable* constants)"},
408 { "video_set_size", vlcInstance_video_set_size, METH_VARARGS,
409 "video_set_size(width=int, height=int) Set the video width and height"},
410 { "audio_toggle_mute", vlcInstance_audio_toggle_mute, METH_VARARGS,
411 Index: bindings/python/vlc_module.c
412 ===================================================================
413 --- bindings/python/vlc_module.c (revision 20403)
414 +++ bindings/python/vlc_module.c (working copy)
416 mediacontrol_EndStatus );
417 PyModule_AddIntConstant( p_module, "UndefinedStatus",
418 mediacontrol_UndefinedStatus );
419 + PyModule_AddIntConstant( p_module, "DrawableCGrafPtr",
420 + VLCDrawableCGrafPtr );
421 + PyModule_AddIntConstant( p_module, "DrawableControlRef",
422 + VLCDrawableControlRef );
426 Index: src/control/video.c
427 ===================================================================
428 --- src/control/video.c (revision 20403)
429 +++ src/control/video.c (working copy)
432 /* global video settings */
434 +void libvlc_video_set_macosx_parent_type( libvlc_instance_t *p_instance, libvlc_macosx_drawable_type_t t,
435 + libvlc_exception_t *p_e )
437 + var_SetInteger(p_instance->p_libvlc_int, "macosx-drawable-type", (int)t);
440 +libvlc_macosx_drawable_type_t libvlc_video_get_macosx_parent_type( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
442 + libvlc_macosx_drawable_type_t result;
444 + result = var_GetInteger( p_instance->p_libvlc_int, "macosx-drawable-type" );
449 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
450 libvlc_exception_t *p_e )
452 Index: src/libvlc-common.c
453 ===================================================================
454 --- src/libvlc-common.c (revision 20403)
455 +++ src/libvlc-common.c (working copy)
457 var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
458 var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
461 + var_Create( p_libvlc, "macosx-drawable-type", VLC_VAR_INTEGER );
464 /* Create volume callback system. */
465 var_Create( p_libvlc, "volume-change", VLC_VAR_BOOL );
467 Index: include/vlc/libvlc.h
468 ===================================================================
469 --- include/vlc/libvlc.h (revision 20403)
470 +++ include/vlc/libvlc.h (working copy)
473 VLC_PUBLIC_API void libvlc_video_redraw_rectangle( libvlc_input_t *, const libvlc_rectangle_t *, libvlc_exception_t * );
475 +VLC_PUBLIC_API void libvlc_video_set_macosx_parent_type( libvlc_instance_t *, libvlc_macosx_drawable_type_t, libvlc_exception_t * );
477 +VLC_PUBLIC_API libvlc_macosx_drawable_type_t libvlc_video_get_macosx_parent_type( libvlc_instance_t *, libvlc_exception_t * );
480 * Set the default video output parent
481 * this settings will be used as default for all video outputs
482 Index: include/vlc/libvlc_structures.h
483 ===================================================================
484 --- include/vlc/libvlc_structures.h (revision 20403)
485 +++ include/vlc/libvlc_structures.h (working copy)
488 * Downcast to this general type as placeholder for a platform specific one, such as:
490 -* CGrafPort on MacOSX,
491 +* (libvlc_macosx_drawable_type_t) on MacOSX,
494 typedef int libvlc_drawable_t;
497 +* Type of libvlc_drawable_t on MaxOSX. Available types:
498 +* - VLCDrawableCGrafPtr
499 +* - VLCDrawableControlRef
502 + VLCDrawableCGrafPtr = 0,
503 + VLCDrawableControlRef,
504 +} libvlc_macosx_drawable_type_t;
507 * Rectangle type for video geometry