Commit graph

40 commits

Author SHA1 Message Date
Tim-Philipp Müller
d736bfc855 gl: Update for g_type_class_add_private() deprecation in recent GLib
https://gitlab.gnome.org/GNOME/glib/merge_requests/7
2018-06-23 22:58:44 +02:00
Matthew Waters
d75eb628d6 gl/cocoa: keep refs over async operations
Avoids dereferencing dead objects

What happens in the autovideosink case is that context 1 is created and
destroyed before all the async operations hae executed on the associated
window.  When the delayed operations execute, they then reference dead
objects and crash.

We fix this by keeping refs over all async operations so the object
cannot be deleted while async operations are in flight.

https://bugzilla.gnome.org/show_bug.cgi?id=782379
2017-12-09 19:32:29 +00:00
Matthew Waters
4c75bab70d glcontext: add public swap_buffers function
That simply calls the implementation
2017-12-09 19:32:28 +00:00
Sebastian Dröge
a9a05c01a9 gst: Clear floating flag in constructor of all GstObject subclasses that are not owned by any parent
https://bugzilla.gnome.org/show_bug.cgi?id=743062
2017-12-09 19:32:28 +00:00
Nick Kallen
7b42f26b80 applemedia/gl: Update code to use ARC
All code interacting with Objective-C objects should now use Automated
Reference Counting rather than manual memory management or Garbage
Collection. Because ARC prohibits C-structs from containing
references to Objective-C objects, all such fields are now typed
'gpointer'. Setting and gettings Objective-C fields on such a
struct now uses explicit __bridge_* calls to tell ARC about
object lifetimes.

https://bugzilla.gnome.org/show_bug.cgi?id=777847
2017-12-09 19:32:27 +00:00
Matthew Waters
6e409db6e0 glcontext/cocoa: implement empty swap_buffers
Fixes some GL tests on OS X.
2017-12-09 19:32:24 +00:00
Matthew Waters
18ac98c58b gl: GST_GL_TYPE -> GST_TYPE_GL
Some deprecated symbols are kept for backwards compatibility
2017-12-09 19:32:23 +00:00
Sebastian Dröge
95415270f0 Revert "libgstgl: cocoa, eagl: don't marshal GL calls to the context thread"
This reverts commit 797d6415df.

We're frozen for 1.8.0 release and this change might have bigger impact.
2017-12-09 19:32:17 +00:00
Alessandro Decina
90889bc73f libgstgl: cocoa, eagl: don't marshal GL calls to the context thread
Execute GL calls without marshalling them to the context thread. In the cocoa
and eagl backends calling gst_gl_context_activate is cheap and therefore calling
it on the current thread and serializing GL calls with a per-context lock is
more efficient (faster and has less overhead) than marshalling everything to the
context thread.

This optimization cuts a large overhead in g_poll (continuously waking up the
context thread) and in g_mutex_*/g_cond_* (waiting for results from the context
thread).
2017-12-09 19:32:17 +00:00
Alessandro Decina
610f965be8 libgstgl: gstglcontext_cocoa: kCGLPFAStereo has been deprecated in 10.11
Also since the version scheme has changed (to include the micro number) since
10.10, use the MAC_OS_X_VERSION_* macro to avoid confusion.
2017-12-09 19:32:12 +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
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
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
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
e10d2417e2:
"move to CGL and CAOpenGLLayer for rendering".

Then the commit 7d46357627:
"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
742e4a10a2 gl/cocoa: small refactor of layer/view creation into the window 2017-12-09 19:31:54 +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
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
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
9ff86a3c54 gl/cocoa: Improve the NSApplication initialization
This is only for non-Cocoa apps but previously caused a 2 second
waiting during startup for Cocoa apps. This is unacceptable.

Instead we now check a bit more extensive if something actually
runs on the GLib default main context, and if not don't even
bother waiting for something to happen from there.
2017-12-09 19:31:47 +00:00
Sebastian Dröge
32b23a340e gl/cocoa: Call UI related API from the application main thread 2017-12-09 19:31:47 +00:00
Sebastian Dröge
02b3e26854 gl/cocoa: Switch to a plain NSView subclass instead of NSOpenGLView
We don't and can't use NSOpenGLView as it's supposed to be used and
it gets into our way by being to clever in various situations.
2017-12-09 19:31:47 +00:00
Sebastian Dröge
6c8f7f9dd5 gl/cocoa: Clear the current GL context when it should happen 2017-12-09 19:31:46 +00:00
Julien Isorce
62ac6db6a0 glcocoa: initalize NSApp asap when using gst-launch
See https://bugzilla.gnome.org/show_bug.cgi?id=732661
2017-12-09 19:31:44 +00:00
Julien Isorce
545bed3c7a gl/cocoa: set the view to use for drawing by the context
It avoids to draw to an invalid buffer.
Withtout this the default frame buffer is undefined:
glBindFramebuffer (GL_FRAMEBUFFER, 0)

Visually you could see some white frames at the beginning
when lunching videotestsrc ! glimagesink

With OpenGL Profiler from XCode you could see some
GL_INVALID_FRAMEBUFFER_OPERATION for the first frames
2017-12-09 19:31:37 +00:00
Julien Isorce
3819fbef46 gl/cocoa: fix NSAutoreleasePool initialization 2017-12-09 19:31:36 +00:00
Julien Isorce
08cce2cd5b gl/cocoa: ensure to call NSApplication:sharedApplication in the main thread
"(NSApplication *)sharedApplication This method also makes a connection
to the window server and completes other initialization"
The implicit thing which is not mentioned is that it required
to be called in the main thread.

Fix a regression introduces by 82b7c915bb
When using with gst-launch, it was not possible to click on the close
cross of the window anymore which is a bit anoying and also because
it's was possible before.

Prior to this commit the GstGLContextCocoaClass was initialized
in the main thread because gst_gl_context_new was called in the
state change function from going from ready to paused.

From this commit this call is done from the streaming thread.
So that the call to [NSApplication sharedApplication];
was not done in the main thread anymore.

We now ensure that by assuming there is a GMainLoop running.
It's for debugging purpose so that's ok to do that. Also
note we already do this assumtion to run app itereations.

The regression had no consequence on the cocoa/videooverlay example
(that should be moved from gst-plugins-gl to -bad) because the
application is responsible for that necessary call.
2017-12-09 19:31:36 +00:00
Edward Hervey
3ab0b67318 gl/cocoa: Fix debug statements and platform 2017-12-09 19:31:34 +00:00
Matthew Waters
97f6bc0bfc [891/906] context: add support for wrapping external contexts 2017-12-09 19:31:33 +00:00
Matthieu Bouron
cc0b1f3e05 [836/906] cocoa: only use GSRegisterCurrentThread with GNUStep environment 2017-12-09 19:31:32 +00:00
Matthew Waters
3b1ec77cf8 [818/906] window: add send_message_async vmethod
- provide a default synchronous send_message
- make context creation threadsafe again
2017-12-09 19:31:31 +00:00
Matthew Waters
48cd6ac353 [801/906] context: Reimplement GL context sharing
https://bugzilla.gnome.org/show_bug.cgi?id=704806
2017-12-09 19:31:31 +00:00
Matthew Waters
9cbb652b66 [794/906] context: add subclasses for the different platforms (egl, glx, wgl, etc)
- most code taken from the Window subclasses
- tested combinations: xEGL, GLX, Wayland+EGL, Cocoa (under GNUStep), WGL (Wine)
2017-12-09 19:31:30 +00:00