demux: ts: only seek on pcr for current program
[vlc.git] / modules / video_output / macosx.m
blobc285948f0775441d0909dc1fefdeee6ca2f79872
1 /*****************************************************************************
2  * macosx.m: MacOS X OpenGL provider
3  *****************************************************************************
4  * Copyright (C) 2001-2013 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
8  *          Eric Petit <titer@m0k.org>
9  *          Benjamin Pracht <bigben at videolan dot org>
10  *          Damien Fouilleul <damienf at videolan dot org>
11  *          Pierre d'Herbemont <pdherbemont at videolan dot org>
12  *          Felix Paul Kühne <fkuehne at videolan dot org>
13  *          David Fuhrmann <david dot fuhrmann at googlemail dot com>
14  *          Rémi Denis-Courmont
15  *          Juho Vähä-Herttua <juhovh at iki dot fi>
16  *          Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
17  *
18  * This program is free software; you can redistribute it and/or modify it
19  * under the terms of the GNU Lesser General Public License as published by
20  * the Free Software Foundation; either version 2.1 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU Lesser General Public License for more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License
29  * along with this program; if not, write to the Free Software Foundation,
30  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
31  *****************************************************************************/
33 /*****************************************************************************
34  * Preamble
35  *****************************************************************************/
37 #import <Cocoa/Cocoa.h>
38 #import <OpenGL/OpenGL.h>
39 #import <dlfcn.h>
41 #ifdef HAVE_CONFIG_H
42 # include "config.h"
43 #endif
45 #include <vlc_common.h>
46 #include <vlc_plugin.h>
47 #include <vlc_vout_display.h>
48 #include <vlc_opengl.h>
49 #include <vlc_dialog.h>
50 #include "opengl/vout_helper.h"
52 /**
53  * Forward declarations
54  */
55 static int Open (vlc_object_t *);
56 static void Close (vlc_object_t *);
58 static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count);
59 static void PictureRender (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture);
60 static void PictureDisplay (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture);
61 static int Control (vout_display_t *vd, int query, va_list ap);
63 static void *OurGetProcAddress(vlc_gl_t *, const char *);
65 static int OpenglLock (vlc_gl_t *gl);
66 static void OpenglUnlock (vlc_gl_t *gl);
67 static void OpenglSwap (vlc_gl_t *gl);
69 /**
70  * Module declaration
71  */
72 vlc_module_begin ()
73     /* Will be loaded even without interface module. see voutgl.m */
74     set_shortname ("Mac OS X")
75     set_description (N_("Mac OS X OpenGL video output"))
76     set_category (CAT_VIDEO)
77     set_subcategory (SUBCAT_VIDEO_VOUT)
78     set_capability ("vout display", 300)
79     set_callbacks (Open, Close)
80     add_shortcut ("macosx", "vout_macosx")
81     add_glconv ()
82 vlc_module_end ()
84 /**
85  * Obj-C protocol declaration that drawable-nsobject should follow
86  */
87 @protocol VLCOpenGLVideoViewEmbedding <NSObject>
88 - (void)addVoutSubview:(NSView *)view;
89 - (void)removeVoutSubview:(NSView *)view;
90 @end
92 @interface VLCOpenGLVideoView : NSOpenGLView
94     vout_display_t *vd;
95     BOOL _hasPendingReshape;
97 - (void)setVoutDisplay:(vout_display_t *)vd;
98 - (void)setVoutFlushing:(BOOL)flushing;
99 @end
102 struct vout_display_sys_t
104     VLCOpenGLVideoView *glView;
105     id<VLCOpenGLVideoViewEmbedding> container;
107     vout_window_t *embed;
108     vlc_gl_t *gl;
109     vout_display_opengl_t *vgl;
111     picture_pool_t *pool;
112     picture_t *current;
113     bool has_first_frame;
115     vout_display_place_t place;
118 struct gl_sys
120     CGLContextObj locked_ctx;
121     VLCOpenGLVideoView *glView;
124 static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
126     VLC_UNUSED(gl);
128     return dlsym(RTLD_DEFAULT, name);
131 static int Open (vlc_object_t *this)
133     vout_display_t *vd = (vout_display_t *)this;
134     vout_display_sys_t *sys = calloc (1, sizeof(*sys));
136     if (!sys)
137         return VLC_ENOMEM;
139     @autoreleasepool {
140         if (!CGDisplayUsesOpenGLAcceleration (kCGDirectMainDisplay))
141             msg_Err (this, "no OpenGL hardware acceleration found. this can lead to slow output and unexpected results");
143         vd->sys = sys;
144         sys->pool = NULL;
145         sys->embed = NULL;
146         sys->vgl = NULL;
147         sys->gl = NULL;
149         var_Create(vd->obj.parent, "macosx-glcontext", VLC_VAR_ADDRESS);
151         /* Get the drawable object */
152         id container = var_CreateGetAddress (vd, "drawable-nsobject");
153         if (container)
154             vout_display_DeleteWindow (vd, NULL);
155         else {
156             sys->embed = vout_display_NewWindow (vd, VOUT_WINDOW_TYPE_NSOBJECT);
157             if (sys->embed)
158                 container = sys->embed->handle.nsobject;
160             if (!container) {
161                 msg_Err(vd, "No drawable-nsobject nor vout_window_t found, passing over.");
162                 goto error;
163             }
164         }
166         /* This will be released in Close(), on
167          * main thread, after we are done using it. */
168         sys->container = [container retain];
170         /* Get our main view*/
171         [VLCOpenGLVideoView performSelectorOnMainThread:@selector(getNewView:)
172                                              withObject:[NSValue valueWithPointer:&sys->glView]
173                                           waitUntilDone:YES];
174         if (!sys->glView) {
175             msg_Err(vd, "Initialization of open gl view failed");
176             goto error;
177         }
179         [sys->glView setVoutDisplay:vd];
181         /* We don't wait, that means that we'll have to be careful about releasing
182          * container.
183          * That's why we'll release on main thread in Close(). */
184         if ([(id)container respondsToSelector:@selector(addVoutSubview:)])
185             [(id)container performSelectorOnMainThread:@selector(addVoutSubview:)
186                                             withObject:sys->glView
187                                          waitUntilDone:NO];
188         else if ([container isKindOfClass:[NSView class]]) {
189             NSView *parentView = container;
190             [parentView performSelectorOnMainThread:@selector(addSubview:)
191                                          withObject:sys->glView
192                                       waitUntilDone:NO];
193             [sys->glView performSelectorOnMainThread:@selector(setFrameToBoundsOfView:)
194                                           withObject:[NSValue valueWithPointer:parentView]
195                                        waitUntilDone:NO];
196         } else {
197             msg_Err(vd, "Invalid drawable-nsobject object. drawable-nsobject must either be an NSView or comply to the @protocol VLCOpenGLVideoViewEmbedding.");
198             goto error;
199         }
201         /* Initialize common OpenGL video display */
202         sys->gl = vlc_object_create(this, sizeof(*sys->gl));
204         if( unlikely( !sys->gl ) )
205             goto error;
207         struct gl_sys *glsys = sys->gl->sys = malloc(sizeof(struct gl_sys));
208         if( unlikely( !sys->gl->sys ) )
209         {
210             vlc_object_release(sys->gl);
211             goto error;
212         }
213         glsys->locked_ctx = NULL;
214         glsys->glView = sys->glView;
215         sys->gl->makeCurrent = OpenglLock;
216         sys->gl->releaseCurrent = OpenglUnlock;
217         sys->gl->swap = OpenglSwap;
218         sys->gl->getProcAddress = OurGetProcAddress;
220         var_SetAddress(vd->obj.parent, "macosx-glcontext",
221                        [[sys->glView openGLContext] CGLContextObj]);
223         const vlc_fourcc_t *subpicture_chromas;
225         if (vlc_gl_MakeCurrent(sys->gl) != VLC_SUCCESS)
226         {
227             msg_Err(vd, "Can't attach gl context");
228             goto error;
229         }
230         sys->vgl = vout_display_opengl_New (&vd->fmt, &subpicture_chromas, sys->gl,
231                                             &vd->cfg->viewpoint);
232         vlc_gl_ReleaseCurrent(sys->gl);
233         if (!sys->vgl) {
234             msg_Err(vd, "Error while initializing opengl display.");
235             goto error;
236         }
238         /* */
239         vout_display_info_t info = vd->info;
240         info.has_pictures_invalid = false;
241         info.subpicture_chromas = subpicture_chromas;
243         /* Setup vout_display_t once everything is fine */
244         vd->info = info;
245         
246         vd->pool = Pool;
247         vd->prepare = PictureRender;
248         vd->display = PictureDisplay;
249         vd->control = Control;
250         
251         /* */
252         vout_display_SendEventDisplaySize (vd, vd->fmt.i_visible_width, vd->fmt.i_visible_height);
253         
254         return VLC_SUCCESS;
255         
256     error:
257         Close(this);
258         return VLC_EGENERIC;
259     }
262 void Close (vlc_object_t *this)
264     vout_display_t *vd = (vout_display_t *)this;
265     vout_display_sys_t *sys = vd->sys;
267     @autoreleasepool {
268         [sys->glView setVoutDisplay:nil];
270         var_Destroy (vd, "drawable-nsobject");
271         if ([(id)sys->container respondsToSelector:@selector(removeVoutSubview:)])
272         /* This will retain sys->glView */
273             [(id)sys->container performSelectorOnMainThread:@selector(removeVoutSubview:)
274                                                  withObject:sys->glView
275                                               waitUntilDone:NO];
277         /* release on main thread as explained in Open() */
278         [(id)sys->container performSelectorOnMainThread:@selector(release)
279                                              withObject:nil
280                                           waitUntilDone:NO];
281         [sys->glView performSelectorOnMainThread:@selector(removeFromSuperview)
282                                       withObject:nil
283                                    waitUntilDone:NO];
285         var_Destroy(vd->obj.parent, "macosx-glcontext");
286         if (sys->vgl != NULL)
287         {
288             vlc_gl_MakeCurrent(sys->gl);
289             vout_display_opengl_Delete (sys->vgl);
290             vlc_gl_ReleaseCurrent(sys->gl);
291         }
293         if (sys->gl != NULL)
294         {
295             assert(((struct gl_sys *)sys->gl->sys)->locked_ctx == NULL);
296             free(sys->gl->sys);
297             vlc_object_release(sys->gl);
298         }
300         [sys->glView release];
302         if (sys->embed)
303             vout_display_DeleteWindow (vd, sys->embed);
304         free (sys);
305     }
308 /*****************************************************************************
309  * vout display callbacks
310  *****************************************************************************/
312 static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
314     vout_display_sys_t *sys = vd->sys;
316     if (!sys->pool && vlc_gl_MakeCurrent(sys->gl) == VLC_SUCCESS)
317     {
318         sys->pool = vout_display_opengl_GetPool (sys->vgl, requested_count);
319         vlc_gl_ReleaseCurrent(sys->gl);
320     }
321     return sys->pool;
324 static void PictureRender (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
327     vout_display_sys_t *sys = vd->sys;
329     if (vlc_gl_MakeCurrent(sys->gl) == VLC_SUCCESS)
330     {
331         vout_display_opengl_Prepare (sys->vgl, pic, subpicture);
332         vlc_gl_ReleaseCurrent(sys->gl);
333     }
336 static void PictureDisplay (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
338     vout_display_sys_t *sys = vd->sys;
339     [sys->glView setVoutFlushing:YES];
340     if (vlc_gl_MakeCurrent(sys->gl) == VLC_SUCCESS)
341     {
342         vout_display_opengl_Display (sys->vgl, &vd->source);
343         vlc_gl_ReleaseCurrent(sys->gl);
344     }
345     [sys->glView setVoutFlushing:NO];
346     picture_Release (pic);
347     sys->has_first_frame = true;
349     if (subpicture)
350         subpicture_Delete(subpicture);
353 static int Control (vout_display_t *vd, int query, va_list ap)
355     vout_display_sys_t *sys = vd->sys;
357     if (!vd->sys)
358         return VLC_EGENERIC;
360     if (!sys->embed)
361         return VLC_EGENERIC;
363     @autoreleasepool {
364         switch (query)
365         {
366             case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
367             case VOUT_DISPLAY_CHANGE_ZOOM:
368             case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
369             case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
370             case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
371             {
373                 id o_window = [sys->glView window];
374                 if (!o_window) {
375                     return VLC_SUCCESS; // this is okay, since the event will occur again when we have a window
376                 }
378                 NSSize windowMinSize = [o_window minSize];
380                 const vout_display_cfg_t *cfg;
382                 if (query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT || query == VOUT_DISPLAY_CHANGE_SOURCE_CROP) {
383                     cfg = vd->cfg;
384                 } else {
385                     cfg = (const vout_display_cfg_t*)va_arg (ap, const vout_display_cfg_t *);
386                 }
388                 /* we always use our current frame here, because we have some size constraints
389                  in the ui vout provider */
390                 vout_display_cfg_t cfg_tmp = *cfg;
391                 /* on HiDPI displays, the point bounds don't equal the actual pixel based bounds */
392                 NSRect bounds = [sys->glView convertRectToBacking:[sys->glView bounds]];
393                 cfg_tmp.display.width = bounds.size.width;
394                 cfg_tmp.display.height = bounds.size.height;
396                 /* Reverse vertical alignment as the GL tex are Y inverted */
397                 if (cfg_tmp.align.vertical == VOUT_DISPLAY_ALIGN_TOP)
398                     cfg_tmp.align.vertical = VOUT_DISPLAY_ALIGN_BOTTOM;
399                 else if (cfg_tmp.align.vertical == VOUT_DISPLAY_ALIGN_BOTTOM)
400                     cfg_tmp.align.vertical = VOUT_DISPLAY_ALIGN_TOP;
402                 vout_display_place_t place;
403                 vout_display_PlacePicture (&place, &vd->source, &cfg_tmp, false);
404                 @synchronized (sys->glView) {
405                     sys->place = place;
406                 }
408                 if (vlc_gl_MakeCurrent (sys->gl) != VLC_SUCCESS)
409                     return VLC_EGENERIC;
410                 vout_display_opengl_SetWindowAspectRatio(sys->vgl, (float)place.width / place.height);
412                 /* For resize, we call glViewport in reshape and not here.
413                  This has the positive side effect that we avoid erratic sizing as we animate every resize. */
414                 if (query != VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
415                     // x / y are top left corner, but we need the lower left one
416                     glViewport (place.x, cfg_tmp.display.height - (place.y + place.height), place.width, place.height);
417                 vlc_gl_ReleaseCurrent (sys->gl);
419                 return VLC_SUCCESS;
420             }
422             case VOUT_DISPLAY_CHANGE_VIEWPOINT:
423                 return vout_display_opengl_SetViewpoint (sys->vgl,
424                     &va_arg (ap, const vout_display_cfg_t* )->viewpoint);
426             case VOUT_DISPLAY_RESET_PICTURES:
427                 vlc_assert_unreachable ();
428             default:
429                 msg_Err (vd, "Unknown request in Mac OS X vout display");
430                 return VLC_EGENERIC;
431         }
432     }
435 /*****************************************************************************
436  * vout opengl callbacks
437  *****************************************************************************/
438 static int OpenglLock (vlc_gl_t *gl)
440     struct gl_sys *sys = gl->sys;
441     if (![sys->glView respondsToSelector:@selector(openGLContext)])
442         return 1;
444     assert(sys->locked_ctx == NULL);
446     NSOpenGLContext *context = [sys->glView openGLContext];
447     CGLContextObj cglcntx = [context CGLContextObj];
449     CGLError err = CGLLockContext (cglcntx);
450     if (kCGLNoError == err) {
451         sys->locked_ctx = cglcntx;
452         [context makeCurrentContext];
453         return 0;
454     }
455     return 1;
458 static void OpenglUnlock (vlc_gl_t *gl)
460     struct gl_sys *sys = gl->sys;
461     CGLUnlockContext (sys->locked_ctx);
462     sys->locked_ctx = NULL;
465 static void OpenglSwap (vlc_gl_t *gl)
467     struct gl_sys *sys = gl->sys;
468     [[sys->glView openGLContext] flushBuffer];
471 /*****************************************************************************
472  * Our NSView object
473  *****************************************************************************/
474 @implementation VLCOpenGLVideoView
476 #define VLCAssertMainThread() assert([[NSThread currentThread] isMainThread])
479 + (void)getNewView:(NSValue *)value
481     id *ret = [value pointerValue];
482     *ret = [[self alloc] init];
486  * Gets called by the Open() method.
487  */
488 - (id)init
490     VLCAssertMainThread();
492     /* Warning - this may be called on non main thread */
494     NSOpenGLPixelFormatAttribute attribs[] =
495     {
496         NSOpenGLPFADoubleBuffer,
497         NSOpenGLPFAAccelerated,
498         NSOpenGLPFANoRecovery,
499         NSOpenGLPFAColorSize, 24,
500         NSOpenGLPFAAlphaSize, 8,
501         NSOpenGLPFADepthSize, 24,
502         NSOpenGLPFAWindow,
503         NSOpenGLPFAAllowOfflineRenderers,
504         0
505     };
507     NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
509     if (!fmt)
510         return nil;
512     self = [super initWithFrame:NSMakeRect(0,0,10,10) pixelFormat:fmt];
513     [fmt release];
515     if (!self)
516         return nil;
518     /* enable HiDPI support */
519     [self setWantsBestResolutionOpenGLSurface:YES];
521     /* request our screen's HDR mode (introduced in OS X 10.11) */
522 #pragma clang diagnostic push
523 #pragma clang diagnostic ignored "-Wpartial-availability"
524     if ([self respondsToSelector:@selector(setWantsExtendedDynamicRangeOpenGLSurface:)]) {
525         [self setWantsExtendedDynamicRangeOpenGLSurface:YES];
526     }
527 #pragma clang diagnostic pop
529     /* Swap buffers only during the vertical retrace of the monitor.
530      http://developer.apple.com/documentation/GraphicsImaging/
531      Conceptual/OpenGL/chap5/chapter_5_section_44.html */
532     GLint params[] = { 1 };
533     CGLSetParameter ([[self openGLContext] CGLContextObj], kCGLCPSwapInterval, params);
535     [[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationDidChangeScreenParametersNotification
536                                                       object:[NSApplication sharedApplication]
537                                                        queue:nil
538                                                   usingBlock:^(NSNotification *notification) {
539                                                       [self performSelectorOnMainThread:@selector(reshape)
540                                                                              withObject:nil
541                                                                           waitUntilDone:NO];
542                                                   }];
544     [self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
545     return self;
548 - (void)dealloc
550     [[NSNotificationCenter defaultCenter] removeObserver:self];
551     [super dealloc];
555  * Gets called by the Open() method.
556  */
557 - (void)setFrameToBoundsOfView:(NSValue *)value
559     NSView *parentView = [value pointerValue];
560     [self setFrame:[parentView bounds]];
564  * Gets called by the Close and Open methods.
565  * (Non main thread).
566  */
567 - (void)setVoutDisplay:(vout_display_t *)aVd
569     @synchronized(self) {
570         vd = aVd;
571     }
575  * Gets called when the vout will aquire the lock and flush.
576  * (Non main thread).
577  */
578 - (void)setVoutFlushing:(BOOL)flushing
580     if (!flushing)
581         return;
582     @synchronized(self) {
583         _hasPendingReshape = NO;
584     }
588  * Can -drawRect skip rendering?.
589  */
590 - (BOOL)canSkipRendering
592     VLCAssertMainThread();
594     @synchronized(self) {
595         BOOL hasFirstFrame = vd && vd->sys->has_first_frame;
596         return !_hasPendingReshape && hasFirstFrame;
597     }
602  * Local method that locks the gl context.
603  */
604 - (BOOL)lockgl
606     VLCAssertMainThread();
607     NSOpenGLContext *context = [self openGLContext];
608     CGLError err = CGLLockContext ([context CGLContextObj]);
609     if (err == kCGLNoError)
610         [context makeCurrentContext];
611     return err == kCGLNoError;
615  * Local method that unlocks the gl context.
616  */
617 - (void)unlockgl
619     VLCAssertMainThread();
620     CGLUnlockContext ([[self openGLContext] CGLContextObj]);
624  * Local method that force a rendering of a frame.
625  * This will get called if Cocoa forces us to redraw (via -drawRect).
626  */
627 - (void)render
629     VLCAssertMainThread();
631     // We may have taken some times to take the opengl Lock.
632     // Check here to see if we can just skip the frame as well.
633     if ([self canSkipRendering])
634         return;
636     BOOL hasFirstFrame;
637     @synchronized(self) { // vd can be accessed from multiple threads
638         hasFirstFrame = vd && vd->sys->has_first_frame;
639     }
641     if (hasFirstFrame)
642         // This will lock gl.
643         vout_display_opengl_Display (vd->sys->vgl, &vd->source);
644     else
645         glClear (GL_COLOR_BUFFER_BIT);
649  * Method called by Cocoa when the view is resized.
650  */
651 - (void)reshape
653     VLCAssertMainThread();
655     /* on HiDPI displays, the point bounds don't equal the actual pixel based bounds */
656     NSRect bounds = [self convertRectToBacking:[self bounds]];
657     vout_display_place_t place;
659     @synchronized(self) {
660         if (vd) {
661             vout_display_cfg_t cfg_tmp = *(vd->cfg);
662             cfg_tmp.display.width  = bounds.size.width;
663             cfg_tmp.display.height = bounds.size.height;
665             vout_display_PlacePicture (&place, &vd->source, &cfg_tmp, false);
666             vd->sys->place = place;
667             vout_display_SendEventDisplaySize (vd, bounds.size.width, bounds.size.height);
668         }
669     }
671     if ([self lockgl]) {
672         // x / y are top left corner, but we need the lower left one
673         glViewport (place.x, bounds.size.height - (place.y + place.height), place.width, place.height);
675         @synchronized(self) {
676             // This may be cleared before -drawRect is being called,
677             // in this case we'll skip the rendering.
678             // This will save us for rendering two frames (or more) for nothing
679             // (one by the vout, one (or more) by drawRect)
680             _hasPendingReshape = YES;
681         }
683         [self unlockgl];
685         [super reshape];
686     }
690  * Method called by Cocoa when the view is resized or the location has changed.
691  * We just need to make sure we are locking here.
692  */
693 - (void)update
695     VLCAssertMainThread();
696     BOOL success = [self lockgl];
697     if (!success)
698         return;
700     [super update];
702     [self unlockgl];
706  * Method called by Cocoa to force redraw.
707  */
708 - (void)drawRect:(NSRect) rect
710     VLCAssertMainThread();
712     if ([self canSkipRendering])
713         return;
715     BOOL success = [self lockgl];
716     if (!success)
717         return;
719     [self render];
721     [self unlockgl];
724 - (void)renewGState
726     NSWindow *window = [self window];
728     // Remove flashes with splitter view.
729     if ([window respondsToSelector:@selector(disableScreenUpdatesUntilFlush)])
730         [window disableScreenUpdatesUntilFlush];
732     [super renewGState];
735 - (BOOL)isOpaque
737     return YES;
740 #pragma mark -
741 #pragma mark Mouse handling
743 - (void)mouseDown:(NSEvent *)o_event
745     @synchronized (self) {
746         if (vd) {
747             if ([o_event type] == NSLeftMouseDown && !([o_event modifierFlags] &  NSControlKeyMask)) {
748                 if ([o_event clickCount] <= 1)
749                     vout_display_SendEventMousePressed (vd, MOUSE_BUTTON_LEFT);
750             }
751         }
752     }
754     [super mouseDown:o_event];
757 - (void)otherMouseDown:(NSEvent *)o_event
759     @synchronized (self) {
760         if (vd)
761             vout_display_SendEventMousePressed (vd, MOUSE_BUTTON_CENTER);
762     }
764     [super otherMouseDown: o_event];
767 - (void)mouseUp:(NSEvent *)o_event
769     @synchronized (self) {
770         if (vd) {
771             if ([o_event type] == NSLeftMouseUp)
772                 vout_display_SendEventMouseReleased (vd, MOUSE_BUTTON_LEFT);
773         }
774     }
776     [super mouseUp: o_event];
779 - (void)otherMouseUp:(NSEvent *)o_event
781     @synchronized (self) {
782         if (vd)
783             vout_display_SendEventMouseReleased (vd, MOUSE_BUTTON_CENTER);
784     }
786     [super otherMouseUp: o_event];
789 - (void)mouseMoved:(NSEvent *)o_event
791     /* on HiDPI displays, the point bounds don't equal the actual pixel based bounds */
792     NSPoint ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
793     NSRect videoRect = [self bounds];
794     BOOL b_inside = [self mouse: ml inRect: videoRect];
796     ml = [self convertPointToBacking: ml];
797     videoRect = [self convertRectToBacking: videoRect];
799     if (b_inside) {
800         @synchronized (self) {
801             if (vd) {
802                 vout_display_SendMouseMovedDisplayCoordinates(vd, ORIENT_NORMAL,
803                                                               (int)ml.x, videoRect.size.height - (int)ml.y,
804                                                               &vd->sys->place);
805             }
806         }
807     }
809     [super mouseMoved: o_event];
812 - (void)mouseDragged:(NSEvent *)o_event
814     [self mouseMoved: o_event];
815     [super mouseDragged: o_event];
818 - (void)otherMouseDragged:(NSEvent *)o_event
820     [self mouseMoved: o_event];
821     [super otherMouseDragged: o_event];
824 - (void)rightMouseDragged:(NSEvent *)o_event
826     [self mouseMoved: o_event];
827     [super rightMouseDragged: o_event];
830 - (BOOL)acceptsFirstResponder
832     return YES;
835 - (BOOL)mouseDownCanMoveWindow
837     return YES;
840 @end