summaryrefslogtreecommitdiffstats
path: root/video/out/cocoa_common.m
Commit message (Collapse)AuthorAgeFilesLines
* cocoa: redo synchronizationwm42015-05-131-155/+147
| | | | | | | | | | | | | | | | | | | | | Before this change, Cocoa state was accessed from both the VO and the Cocoa main thread. This was probably not a good idea. There was some locking as well as implicit synchronization using the dispatch mechanism, but it wasn't watertight. Change this completely. Now Cocoa things are always accessed from the main thread only. The old mutex falls away, as well as the vo_cocoa_set_current_context() function, which implicitly used the lock to coordinate VO accesses. With the new code, the VO thread generally has to wait for the main thread, while the main thread never waits for the VO and rarely accesses it. Fortunately, this is rather straight forward, and most of this is achieved by making vo_cocoa_control() run on the main thread. The logic of the code does generally not change. Some aspects are trickier. Apparently we can't access the NSOpenGLContext from the VO thread, because this object is not thread- safe. We use some CGLContextObj functions instead, such as for making the context current and swapping the buffers.
* cocoa: make live-resizing as fast as beforewm42015-05-121-1/+3
| | | | | | | | | | | Interrupt video timing. This means the Cocoa event loop does not have to up to 2 video frame durations until redrawing the frame finally has finished. We abuse the VO event flags for this. Eventually this should use wait_vo() or so in the video timing wait function, but for now the interaction this would require with the code of other VOs/backends would cause too much of a mess.
* cocoa: handle live-resizing differentlywm42015-05-121-31/+41
| | | | | | | | | | | | | | | | | | Instead of requiring a complicated mechanism to share the entire OpenGL and renderer state between VO and Cocoa thread just to do the redrawing during live-resize on the Cocoa thread, let the Cocoa thread wait on the VO thread. This wil allow some major simplifications and cleanups in the future. One problem with this is that it can enter a deadlock whenever the VO tries to sync with the Cocoa thread. To deal with this, the Cocoa thread waits with a timeout. This can probably be improved later, though in general this situation can always happen, unless the Cocoa thread waits in a reentrant way. Some other details aren't completely clean either. For example, pending_events should be accessed atomically. This will also be fixed later.
* cocoa: add missing break statements in switchwm42015-05-111-0/+2
| | | | | The first one (for VOCTRL_GET_DISPLAY_FPS) could have led to undefined behavior if the FPS was unknown. The second is for general symmetry.
* cocoa: remove unused macrowm42015-05-111-1/+0
|
* cocoa: remove an unused parameterwm42015-05-061-1/+1
|
* cocoa: lock cocoa main thread on uninitwm42015-05-061-1/+9
| | | | | | | | | | | | | | | | | | This should fix some crashes due to dangling pointers. The problem was that with_cocoa_lock_on_main_thread() is asynchronous. It will not wait until it is finished. In the uninit case, this means the VO could be deallocated and destroyed while cocoa was still running uninit code. So simply wait until it is done by using dispatch_sync(). There were concerns that this could introduce a deadlock by the main thread trying to wait for something on the VO thread. But from what I can see, this never happens, and even if it does, it would crash anyway since the VO is already gone. One remaining worry is the video_resize_redraw_callback. From what I can see, it still can mess things up, and will need a more elaborate fix.
* cocoa: always compile OSX application code with cocoawm42015-05-021-6/+2
| | | | | | | | | | | | | | This unbreaks compiling command line player and libmpv at the same time. The problem was that doing so silently disabled the OSX application thing - but the command line player can not use the vo_opengl Cocoa backend without it. The OSX application code is basically dead in libmpv, but it's not that much code anyway. If you want a mpv binary that does not create an OSX application singleton (and creates a menu etc.), you must disable cocoa completely, as cocoa can't be used anyway in this case.
* cocoa: don't accidentally drop initial screen drawingwm42015-05-011-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | With --idle --force-window, or when started from the bundle, the cocoa code dropped the first frame. This resulted in a black frame on start sometimes. The reason was that the live resizing/redrawing code was invoked, which simply set skip_swap_buffer to false, blocking redrawing whatever was going to be rendered next. Normally this is done so that the following works: 1. vo_opengl draw a frame, releases GL lock 2. live resizing kicks in, redraw the frame 3. vo_opengl wants to call SwapBuffers, drawing a stale buffer overwritten by the live resizing code This is solved by setting skip_swap_buffer in 2., and querying it in 3. Fix this by resetting the skip_swap_buffer at a known good point: when vo_opengl starts drawing a new frame. The start_frame function returns bool, so that it can be merged with is_active in a following commit.
* cocoa: signal VO_EVENT_WIN_STATE on fps changeStefano Pigozzi2015-03-141-0/+2
| | | | Fixes #1686
* cocoa: fix minimized state getterStefano Pigozzi2015-03-091-5/+2
|
* cocoa: support the "window-minimized" propertyJaime Marquínez Ferrándiz2015-03-081-0/+22
| | | | Signed-off-by: Stefano Pigozzi <stefano.pigozzi@gmail.com>
* cocoa: fix autohide in fullscreenStefano Pigozzi2015-03-081-1/+21
|
* cocoa: fix mouse hiding with launchpad and dock foldersStefano Pigozzi2015-03-081-1/+7
| | | | | | | | | | | | Some UI elements in OS X – like Launchpad and Dock folders – are implemented using borderless windows in background demonized applications. When we use these elements, mpv doesn't stop to be the active application, but the mpv window leaves keyWindow state while we use the OS controls. This commit just keeps track of window state to update the cursor visibility accordingly. Fixes #513
* cocoa: update mouse coordinates when window is initialized.torque2015-03-071-1/+3
| | | | | | Make MpvEventsView -signalMousePosition a public method so it can be called without a compiler warning. Previously, the mouse position would be reported as (0,0) until the cursor was moved.
* cocoa: don't uninit light sensor if not presentStefano Pigozzi2015-03-071-2/+4
|
* cocoa: remove possible use after freeStefano Pigozzi2015-03-071-5/+5
|
* cocoa: fix some crashes caused by async uninitStefano Pigozzi2015-03-071-31/+15
| | | | | | | Always keep around our private state and destroy it when we are really done in the async uninit callback. Fixes #1657
* cocoa: add support for querying ambient lightingStefano Pigozzi2015-03-041-0/+94
| | | | | | | | | This will be pretty useful to let mpv automatically change VO parameters based on ambient lighting conditions. The conversion code and polinomial equation from Apple LMU values to Lux is taken from Firefox: their license, MPL is GPL compatible and allows relicensing to GPL (MPL is more liberal).
* cocoa: remove the setNextKeyView hackStefano Pigozzi2015-02-281-4/+0
| | | | | | Just use makeFirstResponder on the mpv events view from client code if you need the built in keyboard events (this is easier for dealing with view nesting).
* cocoa: improve refresh rate fallback codeStefano Pigozzi2015-02-031-9/+14
| | | | | | | | Apparently CoreGraphics reports the actual refresh rate. DisplayLink can also query the nominal refresh rate of the display so we use that as fallback instead of the fugly 60fps hardcode added in aeb1fca0d. Props to people on https://github.com/glfw/glfw/issues/137
* cocoa: automatically fetch display-fps from the monitorStefano Pigozzi2015-02-031-0/+26
| | | | | | | | | | | | Comment explains why I have been so doubtful at adding this. The Apple docs say CGDisplayModeGetRefreshRate is supposed to work only for CRTs, but it doesn't, and actually works for LCD TVs connected over HDMI and external displays (at least that's what I'm told, I don't have the hardware to test). Maybe Apple docs are incorrect. Since AFAIK Apple doesn't want to give us a better API – maybe in the fear we might be able to actually write some useful software instead of "apps" – I decided not to care as well and commit this.
* video/out: cosmetics: rename VO_EVENT_ICC_PROFILE_PATH_CHANGEDwm42015-01-261-3/+3
| | | | | Remove the "PATH" bit, because VOCTRL_GET_ICC_PROFILE returns an in- memory profile, and not a path. (This was changed a while ago.)
* cocoa: fix fullscreen handlingwm42015-01-171-2/+3
| | | | Fixes #1483, if it even compiles.
* command: unify handling of fullscreen and other VO flagswm42015-01-161-0/+2
| | | | | | | | The "ontop" and "border" properties already used a common mp_property_vo_flag() function, and the corresponding VOCTRLs used the same conventions. "fullscreen" is pretty similar, but was handled slightly similar. Change how VOCTRL_FULLSCREEN behaves, and use the same helper function for "fullscreen" as the other flags.
* cocoa: don't set application icon in libmpvStefano Pigozzi2015-01-161-2/+4
|
* vo_opengl: add support for in memory icc profilesStefano Pigozzi2015-01-071-111/+11
| | | | | | | | | | | Previously we just forced loading a profile from file, but that has poor integration for querying the OS / display server for an ICC profile, and generating profiles on the fly (which we might use in the future for creating preset 3dluts). Also changed the previous icc-profile-auto code to use this mechanism, and moved gl_lcms to be an opaque type with state instead of just providing pure functions.
* cocoa: fix uninitialization while in fullscreenStefano Pigozzi2015-01-011-2/+23
| | | | | | | | This is only needed for switching video track with `_`, since Cocoa automatically handles cleaning up the application's presentation options when quitting the process. Fixes #1399
* cocoa: move the gl function loader to gl_cocoa.cStefano Pigozzi2014-12-281-14/+0
|
* cocoa: mark window for redraw after title changeStefano Pigozzi2014-12-201-1/+3
| | | | | | | This used to work correctly without the call to displayIfNeeded. I think this may only be needed for Yosemite. Fixes #1330
* cocoa: fix crashStefano Pigozzi2014-12-081-5/+0
| | | | | | fixes #1323 Doesn't leak unless we switch video tracks on and off while in fullscreen.
* cocoa: fix view leak in uninit when fullscreenStefano Pigozzi2014-12-061-1/+9
|
* cocoa: use --idle when running inside bundleStefano Pigozzi2014-12-061-4/+1
| | | | | Previously when using the bundle we used a custom bizarro thing to wait for events. Just use `--idle` and greatly simplify the code.
* cocoa: don't change app activation policy in libmpvStefano Pigozzi2014-12-061-3/+4
| | | /cc @mpv-player/stable
* cocoa: don't create Dock icon for audio only filesStefano Pigozzi2014-12-051-0/+21
| | | | fixes #635
* cocoa: don't async redraw when waiting for VO redrawStefano Pigozzi2014-12-041-1/+3
| | | | | This fixes the very annoying glitch where the black bars disappear for a single frame when going fullscreen.
* vda: use implicit current GL contextStefano Pigozzi2014-12-031-11/+0
| | | | Removes the dependency from the Cocoa backend in case we are not using it but still wanna use VDA GL introp.
* cocoa: allow to black out other display when going fsStefano Pigozzi2014-12-011-0/+5
| | | fixes #1302
* cocoa: don’t hand over view memory ownership to libmpv clientsStefano Pigozzi2014-11-251-1/+1
|
* cocoa: fix fullscreen delay when pausedStefano Pigozzi2014-11-011-2/+2
| | | | | | NSDisableScreenUpdates came to hunt me in the end and when mpv was paused, it did wait for a frame that never came (because of interaction with the live resizing code)!
* build: remove bundle support from wafStefano Pigozzi2014-11-011-0/+1
| | | | Use TOOLS/osxbundle.py instead. It's just better and less hacky.
* cocoa: fix small leakStefano Pigozzi2014-10-271-0/+1
|
* libmpv: cocoa: fix view leak on uninitStefano Pigozzi2014-10-271-4/+6
| | | | | The code was lacking a -removeFromSuperview call which resulted in a leak on our part if the parent view in the client was not released.
* cocoa: perform VOCTRL_SET_UNFS_WINDOW_SIZE asyncronouslyStefano Pigozzi2014-10-241-3/+6
| | | | | | | | Apparently if resizing a NSWindow from a secondary thread Cocoa will automatically protect itself using NSViewHierarchyLock and in our case, cause a deadlock. Fixes #1210
* cocoa: reintroduce async resizeStefano Pigozzi2014-10-181-7/+39
| | | | | | | After removing synchronous libdispatch calls, this looks like it doesn't deadlock anymore. I also experimented with pthread_mutex_trylock liek wm4 suggested, but it leads to some annoying black flickering. I will fallback to that only if some new deadlocks are discovered.
* Revert "cocoa: perform init and uninit synchronously"Stefano Pigozzi2014-10-181-1/+3
| | | | This reverts commit a0ac8b6331d345748d415cf71affbe7a90e336a6.
* cocoa: allow mouse events to bubble up with no-input-cursorStefano Pigozzi2014-10-171-10/+13
| | | | | Previously we didn't report events to the core, but still prevented the events to travel on the responder chain.
* cocoa: perform init and uninit synchronouslyStefano Pigozzi2014-10-161-3/+1
| | | | | This is slightly safer and without the resize redraw, should not cause any deadlock.
* libmpv/cocoa: allow clients to use mpv event systemStefano Pigozzi2014-10-121-25/+27
| | | | | | | | | | This allows mpv's view to take key and send events to mpv's core. To set key status correctly, clients must call -[NSWindow selectNextKeyView:] during reconfig on the main thread. All is 'documented' in the cocoabasic example. If someone knows a better way to handle giving key to the embedded view, let me know!
* cocoa: post keydown and keyup events without event monitorStefano Pigozzi2014-10-091-0/+5
| | | | | Our code worked under the assumption that the event monitor is always active and we did remove the keydown and keyup overrides from our cocoa view.
* cocoa: fix 'uninitalized' accessStefano Pigozzi2014-10-091-9/+7
| | | | | I think this doesn't make a difference, since in Objective-C nil responds as a NullObject, but better not depend on this crappy language feature.
* cocoa: allow to embed into an arbitrary NSViewStefano Pigozzi2014-10-081-12/+27
| | | | | Basically add if guards on all the problematic features. I'm still thinking about a better way to handle this, but for the time being, this will do.
* cocoa: try to fix sizing bugs on retina displaysStefano Pigozzi2014-10-061-2/+2
| | | | untested, no hardware.
* cocoa: separate video view and events viewStefano Pigozzi2014-10-051-7/+16
|
* cocoa: fix fullscreen with bundleStefano Pigozzi2014-10-051-1/+1
|
* cocoa: readd some function callsStefano Pigozzi2014-10-051-1/+3
|
* cocoa: actually reset the event flagsStefano Pigozzi2014-10-051-0/+1
|
* cocoa: remove some useless flagsStefano Pigozzi2014-10-051-19/+10
|
* cocoa: disable some features when embedding in another windowStefano Pigozzi2014-10-051-23/+25
| | | | ontop, fullscreen and window title change to be precise
* cocoa: remove --fs-missioncontrolStefano Pigozzi2014-10-051-15/+2
| | | | | | | This is the first of a series of commits that will change the Cocoa way in a way that is easily embeddable inside parent views. To reach that point common code must avoid referencing the parent NSWindow since that could be the host application's window.
* cocoa: fix some pointer casts to be 32bit safeStefano Pigozzi2014-10-051-1/+1
| | | | credits: wm4
* cocoa/libmpv: allow to embed mpv GL view in another windowStefano Pigozzi2014-10-051-25/+67
| | | | | | | | | | | | | | | | | | | This is just temporary code but is a good base for future work (and baby steps are required for these changes). The 'final destination' is embedding the video view into any NSView but that requires some more work (the mechanism will be the same: pass the view's pointer casted to int64_t through -wid). For instance we will need to remove as much usage of the window instance as possible, and use nil guards where not possible. For this reason I will remove stuff like the mission control fullscreen feature (it's a cute feature but annoying to support and quite limited, go make your GUIs), and a way to lookup the current screen directly from the NSView absolute coordinates (this is needed for ICC detection mostly, and reporting back the screen to mpv's core). Moreover the current view.m will need to be separated into 2 views: the actual video view that will be embedded, and a parent view that will not be embedded and will be responsibile for tracking events.
* cocoa: simplify the config code and run it on the main threadStefano Pigozzi2014-10-051-9/+1
| | | | | | This could be dangerous because we initialize the window asynchronously and return immediately from config, but since the OpenGL context is already created, this seems to work correctly and doesn't cause weird deadlock cases.
* cocoa: don't reset presentation options on uninitStefano Pigozzi2014-10-041-1/+0
| | | | | | This doesn't look to be needed anymore. Fullscreening with both the NSView and the NSWindow API works correctly. I guess this was forgotten in from older code which changed presentation options directly for going fullscreen.
* cocoa: make fullscreening look like an atomic operationStefano Pigozzi2014-10-041-0/+16
| | | | | | | | | | | At the moment when you fullscreen mpv there is a very small time interval where the fullscreen windows is semi-transparent. Apparently whem moving the view to another parent it's better to make Cocoa not draw anything globally. An Apple engineer said it, so it must be correct: http://www.cocoabuilder.com/archive/cocoa/142020-preventing-flicker-on-moving-nsview-to-different-superview.html I know I will regret this in the future.
* cocoa: make resizing wake the vo threadStefano Pigozzi2014-10-041-0/+1
|
* cocoa: remove dead codeStefano Pigozzi2014-10-041-11/+0
|
* cocoa: move to a simpler threading modelStefano Pigozzi2014-10-041-87/+33
| | | | | | | | | | | | | | Unfortunately using dispatch_sync for synchronization turned out to be really bad for us. It caused a wide array of race conditions, deadlocks, etc. Moving to a very simple mutex. It's not clear to me how to do liveresizing with this, for now it just flickers with is unacceptable (maybe I'll draw black instead). This should fix all the threading cocoa bugs. Reopen if it's not the case! Fixes #751 Fixes #1129
*