Commit graph

94 commits

Author SHA1 Message Date
Matthew Waters 63bbe9406a glwindow: add API to request a resize event on the next draw
- glimagesink needs to be able to resize the viewport on aspect ratio
  changes resulting from either caps changes or 3d output mode changes.
- Performing a glViewport outside the GstGLWindow::resize callback
  will not have the winsys' stack of viewports required to correctly
  place the output frame.

Provide a function to request a resize on the next draw event from the
winsys.

Also track size changes inside the base GstGLWindow class rather
than in each subclass.

https://bugzilla.gnome.org/show_bug.cgi?id=755111
2017-12-09 19:32:08 +00:00
Matthew Waters 0ac95e3243 gl/cocoa: fix definition of gst_gl_context_new
gstglcontext_cocoa.m:75:1: error: conflicting types for 'gst_gl_context_cocoa_new'
2017-12-09 19:32:07 +00:00
Matthew Waters 6ccaafc0f3 glwindow: pass display to implementation's _new()
So they have to opportunity to fail if they cannot handle the
display connection.

https://bugzilla.gnome.org/show_bug.cgi?id=752743
2017-12-09 19:32:07 +00:00
Matthew Waters 9587eb477d glcontext: pass display to implentation's _new()
This allows the context to fail creation based on incompatible
display type's. e.g. glx context with an wayland display handle.

https://bugzilla.gnome.org/show_bug.cgi?id=752743
2017-12-09 19:32:06 +00:00
Matthew Waters 66407b9877 glcontext: fix get_current_gl_api on x11/nvidia drivers
They require to get_proc_address some functions through the
platform specific {glX,egl}GetProcAddress rather than the default
GL library symbol lookup.
2017-12-09 19:32:05 +00:00
Julien Isorce 9ac4280052 glwindow_cocoa: use parent default implementation
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=750337
2017-12-09 19:32:03 +00:00
Matthew Waters eba6f6b80f gl/calayer: provide the exact GL api version for the wrapped context
Otherwise we could end up being mistaken for the diference between a
gl3 and a gl2 context resulting in a failure getting the list of
extensions from the wrapped context due to the difference between
glGetString and glGetStringi for the GL_EXTENSIONS token.

https://bugzilla.gnome.org/show_bug.cgi?id=749728
2017-12-09 19:32:02 +00:00
Matthew Waters e8e84cf6b3 gl/calayer: provide a current wrapped GstGLContext for callbacks
So that the draw and resize callbacks can get the current GstGLContext.
2017-12-09 19:32:01 +00:00
Matthew Waters 5d8841c8e7 glcontext/cocoa: implement GL3 core context selection 2017-12-09 19:32:01 +00:00
Julien Isorce 63366be8ad gl: add GstGLDisplayCocoa
https://bugzilla.gnome.org/show_bug.cgi?id=746012
2017-12-09 19:31:58 +00:00
Julien Isorce d3b3887c52 gl/cocoa: do not terminate loop in gst_gl_window_cocoa_close
It is now done in _finalize.

Fix regression introduced by
"gl/window: create the main loop/context on init/finalize"
bc7a7259f3
2017-12-09 19:31:58 +00:00
Matthew Waters 35476a4cb4 gl/cocoa: avoid deadlock when creating context on the main thread.
Make window/view creation async so that it is possible to
gst_gl_context_create from the main thread.
2017-12-09 19:31:57 +00:00
Matthew Waters 5b8f3e7870 gl/window: create the main loop/context on init/finalize
Avoids races setting the window handle from the main thread.

https://bugzilla.gnome.org/show_bug.cgi?id=745633
2017-12-09 19:31:56 +00:00
Julien Isorce befc24469c gl/cocoa: register only one custom nsapp loop
Otherwise the pipeline stalls when running
more than one glimagesink with gst-launch.

Also only register the custom nsapp loop
when setting up the nsapp from gstgl.
2017-12-09 19:31:56 +00:00
Julien Isorce 075a4ffaff gl/cocoa: instead of class_init use g_once to setup nsapp 2017-12-09 19:31:56 +00:00
Julien Isorce 9599b46416 gl/cocoa: check for deprecated constants prior to OSX 10.10 2017-12-09 19:31:56 +00:00
Matthew Waters 1cf843292b gl/calayer: don't use the async callback to render
not until we can provide equivalent functionality for other window
implementations.
2017-12-09 19:31:55 +00:00
Julien Isorce 0ad168a258 gl/cocoa: reduce custom main loop latency
This fix a very slow rendering rate regression that only
happens when using gst-launch, i.e. in the case where
the main thread does not run any NSApp loop.

Git bisect reported it has been introduced by the commit
e10d2417e2fe7aa4733c076984339b0d61caa169:
"move to CGL and CAOpenGLLayer for rendering".

Then the commit 7d463576271e5a4cc1070780ba1a69c971e8be1d:
"gstglwindow_cocoa: fix slow render rate" attempted to fix
the slow rendering rate problem when using gst-launch.

At least for me it does not work. I tried several
combinations, for example to flush CA transactions in the
custom app loop, as mentioned in the doc, but the only solution
that fixes the slow rendering is by reducing the loop latency.
From what I tested, no need to put less than 60ms, even if the
framerate has an interval much lower (16.6ms for 60 fps).
2017-12-09 19:31:55 +00:00
Matthew Waters 3f32b45769 gl/cocoa: don't deadlock if the dispatch_sync is called from the main thread
Provide a helper function to check whether we are being called from
the main thread and act appropriately.
2017-12-09 19:31:55 +00:00
Matthew Waters 9938fe7fa9 gl/calayer: only start drawing if the parent gl context is ready
otherwise we may try to use GstGLFuncs * that hasn't been set yet
2017-12-09 19:31:54 +00:00
Matthew Waters 742e4a10a2 gl/cocoa: small refactor of layer/view creation into the window 2017-12-09 19:31:54 +00:00
Alessandro Decina 0c459222f8 gstglwindow_cocoa: fix slow render rate
In gst_gl_window_cocoa_draw we used to just call setNeedsDisplay:YES. That was
creating an implicit CA transaction which was getting committed at the next
runloop iteration. Since we don't know how often the main runloop is running,
and when we run it implicitly (from gst_gl_window_cocoa_nsapp_iteration) we only
do so every 200ms, use an explicit CA transaction instead and commit it
immediately. CA transactions nest and debounce automatically so this will never
result in extra work.
2017-12-09 19:31:54 +00:00
Matthew Waters f3beaecfa0 gstglcaopengllayer: use the correct rectangle type for iOS and OS X 2017-12-09 19:31:54 +00:00
Alessandro Decina 1c1084881b Revert "libgstgl: gstglcaopengllayer: set the layer as opaque"
This reverts commit 6f152d381c.

The layer shouldn't be always opaque, it should be made a property.
2017-12-09 19:31:54 +00:00
Alessandro Decina 9f2f3fec17 libgstgl: gstglcaopengllayer: set the layer as opaque 2017-12-09 19:31:54 +00:00
Matthew Waters 598715fc4b glwindow: make showing a window explicit
Also fixes the cgl context always displaying a window to render to for
every GstGLContextCocoa created
2017-12-09 19:31:53 +00:00
Matthew Waters 200842b3f8 gl/calayer: add resize callback based on the bounds rectangle 2017-12-09 19:31:53 +00:00
Matthew Waters e8878507cb gl/caopengllayer: draw asynchronously
This essentially makes the CAOpenGLLayer draw every refresh cycle.
2017-12-09 19:31:53 +00:00
Matthew Waters c5bc8663ae gl/cocoa: don't segfault if we have a NULL draw/resize/close callback 2017-12-09 19:31:53 +00:00
Matthew Waters 698f1236a4 cgl/calayer: use a callback instead of hardcoding the draw functionality 2017-12-09 19:31:53 +00:00
Matthew Waters 0cfeddbd05 cgl: install the gl context and gl layer headers 2017-12-09 19:31:53 +00:00
Matthew Waters e57fb35bc0 cgl: add a header for the CAOpenGLLayer support 2017-12-09 19:31:53 +00:00
Matthew Waters 019367c128 glwindow: remove width/height from _draw()
Depending on the platform, it was only ever implemented to 1) set a
default surface size, 2) resize based on the video frame or 3) nothing.
Instead, provide a set_preferred_size () that elements/applications
can use to request a certain size which may be ignored for
videooverlay/other cases.
2017-12-09 19:31:53 +00:00
Matthew Waters 01248b1864 glcontext/cocoa: avoid destroying a possibly 0 GSource id 2017-12-09 19:31:53 +00:00
Matthew Waters 0e835bc374 gl/cocoa: move to CGL and CAOpenGLLayer for rendering
Removes the use of NSOpenGL* variety and functions.  Any Cocoa
specific functions that took/returned a NSOpenGL* object now
take/return the CGL equivalents.
2017-12-09 19:31:53 +00:00
Matthew Waters 971e9e3128 glcontext/cocoa: add debug category 2017-12-09 19:31:53 +00:00
Sebastian Dröge 50a11e4a77 gl/cocoa: Disable hack for NSApp iteration with a special #define
The hack causes deadlocks and other interesting problems and it really
can only be fixed properly inside GLib. We will include a patch for
GLib in our builds for now that handles this, and hopefully at some
point GLib will also merge a proper solution.

A proper solution would first require to refactor the polling in
GMainContext to only provide a single fd, e.g. via epoll/kqueue
or a thread like the one added by our patch. Then this single
fd could be retrieved from the GMainContext and directly integrated
into a NSRunLoop.

https://bugzilla.gnome.org/show_bug.cgi?id=741450
https://bugzilla.gnome.org/show_bug.cgi?id=704374
2017-12-09 19:31:52 +00:00
Sebastian Dröge c3f86ece48 gl/cocoa: Don't init and clear static GMutex / GCond
We would potentially use it from the main loop later in
gst_gl_window_cocoa_init_nsapp() if it timed out before.
2017-12-09 19:31:52 +00:00
Sebastian Dröge 8f5faa3872 gl/cocoa: Only use convertRectToBacking on OSX >= 10.7
It does not exist before and older versions also don't have
support for HiDPI displays anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=740201
2017-12-09 19:31:50 +00:00
Sebastian Dröge 3fe5be7c9a gl/cocoa: Don't override the application delegate
Otherwise interesting things will happen in Cocoa applications, like
infinite event loops that block the NSApplication loop forever.

This was only needed for GNUStep and thus can safely be removed now.
2017-12-09 19:31:50 +00:00
Sebastian Dröge 673b0190af gl/cocoa: Remove GNUStep support
Until gcc and GNUStep properly support Objective-C blocks and other
"new" features of Objective-C we can't properly support them without
making the code much more ugly.

https://bugzilla.gnome.org/show_bug.cgi?id=739152
2017-12-09 19:31:50 +00:00
Julien Isorce f1365f1051 gl/cocoa: use NSAutoreleasePool to free resize data
Otherwise when resizing the window you will also get messages like:
class NSConcreteMapTable autoreleased with no pool in place - just leaking
class NSConcreteValue autoreleased with no pool in place - just leaking
class NSConcreteValue autoreleased with no pool in place - just leaking
class __NSCFDictionary autoreleased with no pool in place - just leaking
2017-12-09 19:31:49 +00:00
Julien Isorce f44b430bc7 gl/cocoa: make sure to turn on frame rectangle changes notifications
Default value of property postsFrameChangedNotifications is YES
but it is worth to explicitly enable it.
2017-12-09 19:31:49 +00:00
Julien Isorce 4a736caded gl/cocoa: fix uncaught exception 'unrecognized selector sent to instance'
Need to set the ':' as the reshape method now takes one parameter.
For the story, the GstGLNSView was previously inheriting from
NSOpenGLView which has a reshape function without any parameter.
Now the GstGLNSView inherits from NSView and we re-use the reshape
function manually.
2017-12-09 19:31:49 +00:00
Julien Isorce a581d479ff gl/cocoa: fix compiler warning
Use the reshape function after being defined. The other way
would have been to declare the reshape function in the header.

gstglwindow_cocoa.m: In function '-[GstGLNSView drawRect:]':
gstglwindow_cocoa.m:555: warning: 'GstGLNSView' may not respond to '-reshape'
gstglwindow_cocoa.m:555: warning: (Messages without a matching method signature
gstglwindow_cocoa.m:555: warning: will be assumed to return 'id' and accept
gstglwindow_cocoa.m:555: warning: '...' as arguments.)
2017-12-09 19:31:49 +00:00
Matthew Waters be5d0d81e4 glcontext: add api for retreiving the current context and api
that is current in the calling thread.
2017-12-09 19:31:48 +00:00
Sebastian Dröge 3d7a6c8db6 gl/cocoa: Fix compiler warning
gstglwindow_cocoa.m: In function '-[GstGLNSView drawRect:]':
gstglwindow_cocoa.m:555: warning: 'GstGLNSView' may not respond to '-reshape'
gstglwindow_cocoa.m:555: warning: (Messages without a matching method signature
gstglwindow_cocoa.m:555: warning: will be assumed to return 'id' and accept
gstglwindow_cocoa.m:555: warning: '...' as arguments.)
2017-12-09 19:31:48 +00:00
Brion Vibber 02a0b92d9d gl/cocoa: Fix for building on Mac OS X 10.10
Using NSApp directly seems to confuse something, as the compiler
was expecting an id<NSFileManagerDelegate>. Switched to using
[NSApplication sharedApplication], and specified the delegate
protocol on the window class as well.

https://bugzilla.gnome.org/show_bug.cgi?id=738740
2017-12-09 19:31:48 +00:00
Sebastian Dröge 6d273084eb gl/cocoa: Add support for HiDPI displays
Without this our GL surface would be upscaled after rendering
by Cocoa, which would reduce image quality.
2017-12-09 19:31:48 +00:00
Sebastian Dröge 435810b238 gl/cocoa: Always update our viewport if Cocoa tells us something has changed
The visible rect and bounds might be the same as before, but Cocoa
might've changed our viewport without us nothing. This happens if
you hide the view and show it again.
2017-12-09 19:31:47 +00:00