Commit Graph

2441 Commits

Author SHA1 Message Date
Akemi c824a023c4 cocoa: fix dragging out of focus window
fffab30 introduced a small regression where the cursor couldn't be
unhidden after refocusing. the problem is that no mouseUp event was
reported in our events_view. work around this with a separate event
monitor. this also fixes another regression when the window is being
dragged from the title bar.

#4174
2017-02-21 19:26:33 +01:00
wm4 eae12bf963 vo: fix subtleties in the redrawing logic
This fixes a race condition created by the previous commit, and possibly
others. Sometimes interpolated frames weren't redrawn as uninterpolated
ones.

The problem is that redrawing/drawing a frame can't reset the VO
want_redraw flags, because logically these have to happen after the core
acknowledged and explicitly reissued a redraw. The core needs to be
involved because the OSD text and drawings could depend on the playback
or window state.

Change it such that it always goes through the core.

Also, VOs inconsistently called vo_wakeup() when setting want_redraw,
which is also taken care of by this commit.
2017-02-21 15:39:44 +01:00
wm4 3cd29ca031 player: reduce blocking on VO when switching pause
When pausing, we sent BOCTRL_PAUSE and VOCTRL_RESTORE_SCREENSAVER. These
essentially wait until the video frame has been rendered. This is a
problem with the opengl-cb, if GL rendering is done in the same thread
as libmpv uses. Unfortunately, it's allowed to use opengl-cb this way.

Logically speaking, it's a deadlock situation, which is resolved with a
timeout. This can lead to quite ugly effects, like the on-pause frame
not being rendered until the timeout has passed. It has been interpreted
as video continuing to play.

Resolve this by simply not blocking on pause. Make the screensaver
controls async, and handle sending VOCTRL_PAUSE in the VO thread.

(All this could be avoided by redoing the internal VO API.)

Also see #4152.
2017-02-21 15:39:40 +01:00
Akemi fffab30a3e cocoa: only report mouse movements when window is not being dragged
even though the mouse doesn’t move relative to the window itself, when
the window is being dragged, some outliers are still reported and
trigger the OSC.
2017-02-20 17:26:56 +01:00
Akemi bdd096db9a cocoa: make window draggable on init
fixes the case when mpv is opened and the cursor is within the window
bounds without moving the mouse. previously the window could only be
dragged around after the first mouse movement.
2017-02-20 17:25:42 +01:00
rr- 326920a9bf vo_tct: check ioctl result 2017-02-20 14:19:57 +01:00
wm4 79272e1469 Fix two typos
They're unrelated. Sue me.
2017-02-20 08:47:17 +01:00
wm4 6e2d3d9919 vo_opengl: remove dxva2 dummy hwdec backend
This was a hack to let libmpv API users pass a d3d device to mpv. It's
not needed anymore for 2 reasons:

1. ANGLE does not have this problem
2. Even native GL via nVidia (where this failed) seems to not require
   this anymore
2017-02-20 08:39:08 +01:00
Akemi 4f74b93546 cocoa: fix cursor hiding at the top of the screen in fullscreen
even before the recent refactor the cursor was hidden when moving it to
the top of the screen in fullscreen and placing it on top of the now
visible menu bar.

we need to know when the menu bar is hidden so we don’t create a
‘dead zone’ at the top of the screen where the cursor can’t be hidden.
to determine when the menu bar is visible, and with that the title bar,
we get the height of the menu bar. the height is always 0 when hidden.

furthermore there is no way to get the title bar directly and with that
its height. so we calculate the frame rect of a NSWindowStyleMaskTitled
window from a CGRectZero content frame. the resulting height is the
height of a title bar.

with that we can exclude the top area for the cursor hiding and can be
certain when the menu bar is not hidden.
2017-02-19 17:54:06 +01:00
Akemi d45074455a cocoa: fix cursor hiding in the Dock area of the screen
the cursor couldn’t be hidden when the cursor was at the same position
as the Dock, even if the cursor was next to it. this is especially
annoying in fullscreen since the Dock isn’t actually hidden but is still
reported as being visible. this basically made the part of the screen,
where the Dock resides, a ‘dead zone’. so instead of using the
visibleFrame we will just use the normal frame. there is no problem at
the top area of the screen, since a window can’t be placed above the
menu bar and in fullscreen the menu bar is always reported as not being
on screen.

i suspect this was done so the cursor wasn’t hidden when the it was
placed above the Dock when windowed. with the recent refactor this is
not needed any more.
2017-02-19 17:54:06 +01:00
Akemi 72d90f911a cocoa: simplify the cursor hiding code
we can simplify the code because we don't need to change the bool
pointer we were given by the VOCTRL_SET_CURSOR_VISIBILITY event. i
assume this was done to work around some bugs previously to the recent
cursor refactor. i kept that because i thought it was necessary, which
wasn't in the end. after the refactor it only caused some weirdnesses i
tried to work around. without it we can get rid of some special cases
and simplify the code quite a bit.
2017-02-19 17:54:06 +01:00
Akemi 3064bbe1dd cocoa: fix scroll wheel input with Shift modifier
holding shift swaps the scroll wheel axes and deltaY returned zero.
summing up deltaX and deltaY will always give us the right button.

Fixes #3506
2017-02-19 17:54:06 +01:00
Aman Gupta 53fab20c6d vo_opengl: implement videotoolbox hwdec on iOS
Implements --hwdec=videotoolbox on iOS. Similar to hwdec_osx.c, but
using CVPixelBuffer APIs available on iOS instead of the equivalent
IOSurface APIs in macOS.
2017-02-17 11:43:24 -08:00
wm4 f02752c0d5 vo_opengl: don't crash on unsupported formats
Regression from recent refactor.
2017-02-17 19:48:29 +01:00
wm4 d8bf000d29 vo_opengl: hwdec_vaegl: use new format setup function
Plus add a helper.
2017-02-17 17:26:01 +01:00
wm4 e59e917e71 vo_opengl: hwdec_osx: use new format setup function
We can drop the custom table.

For some reason, the interop does not accept GL_RGB_RAW_422_APPLE as
internal format for GL_RGB_422_APPLE, so switch the format table to use
GL_RGB (this way both interop and real textures work the same).

Another victim of the apparent requirement of exactly matching texture
formats is kCVPixelFormatType_32BGRA. vo_opengl wants to handle this as
normal RGBA texture, with a swizzle applied in the shader.
CGLTexImageIOSurface2D() rejects this, because it wants the exact
internal format. Just drop the format, because it's useless anyway.

(Maybe this is a bit too fragile...)
2017-02-17 17:08:37 +01:00
wm4 91a2ddfdd7 vo_opengl: hwdec_cuda: use new format setup function
Gives us automatically support for all formats vo_opengl supports.
2017-02-17 16:39:10 +01:00
wm4 eda69f5333 vo_opengl: move texture mapping of pixel formats to helper function
All supported pixel formats have a specific "mapping" of CPU data to
textures. This function determines the number and the formats of these
textures. Moving it to a helper will be useful for some hardware decode
interop backends, since they all need similar things.
2017-02-17 16:28:31 +01:00
wm4 9c54b224d8 vo_opengl: handle GL_LUMINANCE_ALPHA and integer textures differently
GL_LUMINANCE_ALPHA is the only reason why per-plane swizzles exist.
Remove per-plane swizzles (again), and regrettably handle them as
special cases (again). Carry along the logical texture format (called
gl_format in some parts of the code, including the new one).

We also don't need a use_integer flag, since the new gl_format member
implies whether it's an integer texture. (Yes, the there are separate
logical GL formats for integer textures. This aspect of the OpenGL API
is hysteric at best.)

This should change nothing about actual rendering logic and GL API
usage.
2017-02-17 16:28:31 +01:00
wm4 b5eb326dcb videotoolbox: fix RGB format
Wrong colors. This didn't matter for the OpenGL interop code, because
the CV format was mapped to the correct texture format.
2017-02-17 14:14:58 +01:00
wm4 2b5577901d videotoolbox: remove weird format-negotiation between VO and decoder
Originally, there was probably some sort of intention to restrict it to
formats supported by the interop, or something. But in the end it was
overcomplicated nonsense.

In the future, we could use mp_hwdec_ctx.supported_formats or other
mechanisms to handle this in a better way.

mp_hwdec_ctx.ctx is not set to a dummy pointer - hwdec_devices_load() is
only used to detect whether to vo_opengl interop is present, and the
common hwdec code expects that the .ctx field is not NULL.

This also changes videotoolbox-copy to use --videotoolbox-format,
instead of the FFmpeg-set default.
2017-02-17 14:14:22 +01:00
wm4 1e4fd996bb videotoolbox: factor some duplicated code
The code for copying a videotoolbox surface to mp_image was duplicated
(with some minor differences - I picked the hw_videotoolbox.c version,
because it was "better"). mp_imgfmt_from_cvpixelformat() is somewhat
duplicated with the vt_formats[] table, but this will be fixed in a
later commit, and moving the function to shared code is preparation.
2017-02-17 13:32:27 +01:00
Akemi 9ac05a575c cocoa: refactor mouse events and cursor visibility
we reported some unnecessary mouse movements and not all mouse enter
and leave events. that lead to wrongly reported activity on hover areas
like on the OSC or comparable lua scripts. sometimes menu items were
shown that shouldn't be shown or they didn't vanish because of the
missing mouse leave event.

this incorporates @torque's fix for mouse leave events that weren't
triggered during a transition, like going to fullscreen. the
tracking area was updated but the mouse never left that area because
it was never over it.

besides some known cursor visibility bugs the aforementioned changes
also revealed some other bugs that weren't reproducible before because
of the missbehavior.
known issues, in some cases the cursor doesn't show or hide properly.
for example when switching spaces, switching Apps via CMD+Tab or a
system notification. former two could be fixed while keeping our current
blank cursor approach. though the notification case couldn't. there is
no event or similar to detect a notification and the cursor visibility
couldn't be recovered in any way.

new issues, i noticed that our event view isn't initialised yet when the
first VOCTRL_SET_CURSOR_VISIBILITY event gets dispatched, which depends
on the event view to be initialised. so the mouse cursor couldn't be
hidden when mpv was opened and the cursor was within the window bounds.
this wasn't noticeable before because of various bugs and unwanted
behavior that have been fixed with this. now, in case the event view
isn't ready yet, we set the visibility at a later point when the event
view is ready and a helper flag is set.

Fixes #1817 #3856 #4147
2017-02-16 22:22:11 +01:00
wm4 3e474f4654 vo_opengl: hwdec_vaegl: fix potentially undefined memory access 2017-02-14 13:30:48 +01:00
Akemi 9a45932984 cocoa: fix black edges on live resize
this fixes a small bug with black edges on live resize, due to the
synchronisation with the DisplayLink. we just pause the DisplayLink for
the duration of the live resize. i also added some convenience functions
for reoccurring calls and simplified some DisplayLink related screen
info.
2017-02-13 22:52:47 +01:00
Akemi 64b0d81c32 cocoa: add --ontop-level option for modifying ontop window level
since there are different views on what ontop is, we make the ontop
window level modifiable. at the moment only support for macOS was added.
the default for macOS was changed from 'system' to 'window' since this
fixes an unwanted behaviour in fullscreen and in general causes less
issues with expected behaviour.

Fixes #2376 #3974
2017-02-13 22:49:11 +01:00
pavelxdd 3739d1318f win32: update the fullscreen state on restoring
If a maximized window restored from fullscreen,
the fullscreen state needs to be updated manually.
2017-02-12 02:49:25 +11:00
James Ross-Gowan 8bc335e3db vo_opengl: angle: log the device/surface implementation
This should be useful for debugging, since otherwise it's hard to tell
which implementation has been auto-detected or if any failed to init.
2017-02-12 02:40:49 +11:00
James Ross-Gowan 061b752217 vo_opengl: egl_helpers: fix for non-Windows
Whoops. Fixes #4119
2017-02-08 01:27:17 +11:00
James Ross-Gowan e0250b9604 vo_opengl: angle: rewrite with custom swap chain
This replaces the old backend that exclusively used EGL windowing with
one that can also use ANGLE's ability to render to directly to a
texture. The advantage of this is that it allows mpv to create the swap
chain itself and this allows mpv to use a flip-mode swap chain on a HWND
(which avoids problems with DirectComposition) and to use a longer swap
chain that has six backbuffers by default (which reportedly fixes
problems with rendering 24fps video on 24Hz monitors.)

Also, "screenshot window" should now work on DXGI 1.2 and up (Windows 8
and up.)
2017-02-07 22:45:07 +11:00
Akemi d11c03faee cocoa: fix color profile retrieval
when the color profile was changed it used the right NSScreen but with
the old colorSpace. this was optimised out by a previous commit because
of a wrong assumption. we need to update the screen so we can get the
new colorSpace. this adds a bit of redundancy since on screen change it
will update screen pointer twice.
2017-02-02 16:31:28 +01:00
Akemi 5f10a415d7 cocoa: fix dropping of files and URLs
the problem here is that dropped files can also be treated as
NSURLPboardType instead of just NSFilenamesPboardType. the 'else if'
could never be reached and was dead code.

this basically reverts ed695ce which tried to fix multiple dropped
URLs, or rather files, and moves the filename check infront of the URL
check. the filename path can handle multiple dropped files, whereas the
URL path can only handle one dropped URL. this assumes that only one URL
can be dropped at a time. it also reverts a603543 because it's not
needed any more.

this also fixes a problem where dropped URLs from Chrome don't conform
to the NSURL class and the readObjectsForClasses method always returned
an empty URL.

Fixes #4036
2017-02-02 16:25:44 +01:00
Akemi 6da224b1dd cocoa: optimise screen event handling
this optimises two things and fix a minor bug.

1. we always updated the display refresh rate on any mode change whether
it was the current screen or not. now we only update the refresh rate
when the mode changed happened on the current screen.
2. the windowDidChangeScreen event doesn't exclusively trigger on screen
changes so we updated the display refresh rate in cases where it wasn't
needed at all. since we manually keep track of the current screen, we
can easily test if the screen really changed.
3. weirdly on initWithContentRect accessing the screen of the window
always returned the main screen instead of the screen the window is
created on. since we already use the window init method with the screen
as argument, overwrite that method instead and use the screen argument.
2017-02-02 16:22:27 +01:00
Akemi f39a1cb1b0 cocoa: fix displaylink refresh rate retrieval
we are dealing with several problems here, which weren't apparent
because we always initialised a new displaylink for the display refresh
rate retrieval, previously to commit 449eb20 and bug 9490b62.

just changing the display with CVDisplayLinkSetCurrentCGDisplay
can cause inconsistent refresh rates and discontinuity in timestamps.
this can either lead to bogus values for the Actual display refresh rate
or retrieving the refresh rate of the previous display if we immediately
try to get a new value. since the Actual refresh rate is computed i
assume that it at least needs one refresh period to actual return
something useful.

furthermore when changing the screen and updating the displaylink, it
seems that the retrieved refresh rates for the screen mpv wasn't opened
on are being estimated in a sub-optimal way. as an example, when moving
my window to my second screen the Actual refresh rate was always a
constant 60Hz, even though it is supposed to fluctuate a little bit.
though if mpv was started on the secondary screen the Actual refresh
rate fluctuated around 59.94Hz like expected. in that case my primary
screen always reported a constant 60Hz instead.

for the first problem we moved the actual retrieval of the refresh rate
to the very last moment when mpv actual requests a new value and not
when the refresh rate changed. we only update the displaylink itself
when a possible refresh rate change is detected. this gives the
displaylink some time to calculate the new refresh rate. for the second
problem, instead of setting the new display we completely uninitialise
the old dislaylink and create a new one for the new screen. this gives
us properly estimated refresh rates.

additionally we also optimised the display refresh rate fallback
heuristic. it will never be 0 anymore and we prevent it from returning
bogus values with a simple threshold for the difference of the Actual
and Nominal refresh rate.
2017-02-02 16:22:27 +01:00
Akemi 954625c165 cocoa: fix unwanted behavior with window level other than the default
setting a window level other than NSNormalWindowLevel always sets
NSWindowCollectionBehaviorTransient, which prevents certain things to
work properly. examples are automatic switching to the active Space when
mpv is made active and (de-)miniaturizing. latter always lead to a
vanishing window.

Fixes #1757 #1884
2017-01-29 19:46:53 +01:00
James Ross-Gowan bed94df521 vo_opengl: dxinterop: use the new SAFE_RELEASE macro 2017-01-30 00:22:30 +11:00
wm4 443d3a91d3 vaapi: remove central lock around vaapi API calls
The lock was disabled recently. This commit gets rid of the dummied out
calls. The main reason for removing it is that there is no apparent need
for it anymore, and the new FFmpeg vaapi code does not use or provide
such a lock (there are some places which we cannot control and which do
vaapi API calls, like frame destructors).
2017-01-28 18:27:30 +01:00
pavelxdd 9c90c902c1 win32: snap to screen edges
Disabled by default. The snap sensitivity value depends on
the screen DPI. The default value is 16px on a 96 DPI screen.

Fixes #2248
2017-01-27 12:00:32 +01:00
wm4 9980b11058 vo_opengl: egl_helpers: fix variable name
It was basically inverted. Not sure how this even happened. Hopefully
it's more an "I don't know what I was doing" instead of an "I don't know
what I am doing" case.
2017-01-26 11:33:58 +01:00
wm4 fd203ff16a options: refacactor how --opengl-dwmflush is declared
Same deal as previous commit, except this time we just readd it as lone
global option, and read it directly.
2017-01-20 14:03:34 +01:00
wm4 d890e0731c options: refactor how --opengl-dcomposition is declared
vo_opengl used to have it as sub-option, which made it very hard to pass
down option values to backends in a generic way (even if these options
were completely backend-specific). For --opengl-dcomposition we used a
VOFLAG to deal with this. Fortunately, sub-options are gone, and we can
just add it as global option.

Move the option to context_angle.c and add it as global option. I
thought about adding a mechanism to let backends declare options, which
would get magically picked up my m_config instead of having to add them
to the global option list manually (similar to VO vo_driver.options),
but decided against this complexity just for 1 or 2 backends. Likewise,
it could have been added as a single option to avoid the boilerplate of
an option struct, but then again there are probably going to be more
angle suboptions, and it's cleaner.
2017-01-20 13:40:59 +01:00
wm4 a35a5bb5f3 x11: pseudo HiDPI scaling
Scale the window by the assumed DPI scaling factor, using 96 DPI as
base. For example, a screen that reports 192 DPI is assumed to have a
DPI scale factor 2. The window will then be created with twice the size.

For robustness reasons, we accept only integer DPI scales between 1 and
9. We also error out if the X and Y scales are very different, as this
most likely indicates a multiscreen system with botched size reporting.

I'm not sure if reading the X server's DPI is such a good idea - maybe
the Xrdb "Xft.dpi" value should be used instead. The current method
follows what xdpyinfo does.

This can be disabled with --hidpi-window-scale=no.
2017-01-19 16:31:54 +01:00
Akemi 717ee3ddba cocoa: don't constrain window frame for fullscreen
our constrainFrameRect prevents our window from positioning itself ontop
of the menubar, which is unwanted for a fullscreen window. this always
positioned our window vertically at -22/-23pt when going into fullscreen
because of the menubar. this bug doesn't show on newer versions of OS X
since the various flags we set force the window position. on OS X 10.9
though the fullscreen window was shifted 22pt downwards. even though
this bug doesn't show on newer OS X versions, it should still be fixed
for a possible behaviour changes in future version.

Fixes #4044
2017-01-19 14:59:51 +01:00
Akemi 9490b628c5 cocoa: don't init displaylink on reconfig
everytime we switched to a new video file a new displaylink was
initialised and started, but the old one was not stopped and released
beforehand. this lead to several displaylink callback calls per swap,
depending on how many files were switched beforehand. moving the
displaylink init call to the cocoa init functions will ever only init
one displaylink.

Fixes #4031
2017-01-19 14:58:15 +01:00
Akemi fe02e5023c cocoa: move updateBorder method to the protocol
we are calling the method on a NSWindow object that may not respond to
that call, since its a method of MpvVideoWindow. add the method to our
protocol and rename that protocol to reflect the change.
2017-01-19 14:54:22 +01:00
Akemi 202f9b218a cocoa: properly recover from toggleFullscreen fail
in some circumstances cocoa isn't able to enter or exit fullscreen but
we still set window sizes and flags accordingly. this leaves us in a
hanging state between fullscreen and window. it also prevents the
toggleFullscreen method and its events to work properly afterwards. in
that state it's impossible to enter or exit this 'semi-fullscreen'.
add a proper fallback to recover from this state.

Fixes #4035
2017-01-19 14:52:51 +01:00
Akemi 4fe45fb3a1 cocoa: fix window size in certain circumstances
a combination of starting from bundle and fullscreen used the standard
window size (960x480) from the pseudo GUI instead of the wanted video
size.
2017-01-19 14:51:11 +01:00
wm4 e7d902bdc0 vo: log timings around flipping/waiting
Found those useful.
2017-01-18 12:14:26 +01:00
wm4 9d68d8fb0f vo_opengl, vo_opengl_cb: better hwdec interop backend selection
Introduce the --opengl-hwdec-interop option, which replaces
--hwdec-preload. The new option allows explicit selection of the interop
backend.

This is relatively complex, and I would have preferred not to add this,
but it's probably useful to debug certain problems. In exchange, the
"new" option documents that pretty much any but the simplest use of it
will not be forward compatible.
2017-01-17 15:48:56 +01:00
wm4 e94890a5d6 vo_opengl_cb: cleanup messy option synchronization
Replace the old code, that played games to evade thread-safety issues,
with newer thread-safe option access functions.

This also means mp_opengl_create() doesn't need to cache the hwdec
settings anymore. (They're applied in mpv_opengl_cb_init_gl() instead.)
2017-01-17 15:48:56 +01:00