Commit graph

51 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
Sebastian Dröge
b44798d549 gl/cocoa: Handle NSView::renewGState() properly
Don't update the screen until we redraw, this prevents flickering during
scrolling, clipping, resizing, etc
2017-12-09 19:31:47 +00:00
Sebastian Dröge
b1a5ae7c0d gl/cocoa: Update viewport according to the current clipping
We have to update the GL viewport if the NSView is only partially
visible. Otherwise the content of the frame will be visibly offset.
2017-12-09 19:31:47 +00:00
Sebastian Dröge
7cf214796a gl/cocoa: NSView::drawRect() should call into reshape too
We a) need to render again because part of the window was
obscured and b) might need to reshape because of clipping
changes.
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
ec0d04acec gl/cocoa: Switch from our custom main loop to a GMainLoop
Simplifies code a lot and makes it more similar to the other backends.
2017-12-09 19:31:46 +00:00
Julien Isorce
2fed41dc30 gl: show internal cocoa window on top of others
Useful when your OSX terminal is fullscreen

https://bugzilla.gnome.org/show_bug.cgi?id=728127
2017-12-09 19:31:39 +00:00
Julien Isorce
2cd72a49ec gl/cocoa: pass a NSView to set_window_handle instead of a NSWindow
Fix backwards compatibility

https://bugzilla.gnome.org/show_bug.cgi?id=728451
2017-12-09 19:31:37 +00:00
Julien Isorce
9db9834128 gl/cocoa: only draw once the window has been resized
It avoids to draw the first frame with an incorrect view port.
2017-12-09 19:31:37 +00:00
Julien Isorce
9d396a2495 gl/cocoa: make gst_gl_window_cocoa_send_message_async re-entrant
Backends that use g_main_context_invoke are re-entrant.

Il allows to call two nested gst_gl_context_thread_add.
ex: init_upload / init_colorconvert
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
2026f60879 [862/906] window: remove set_need_lock
No-one is using it.  The only code that did was the x11 one which
doesn't need it anymore.
2017-12-09 19:31:33 +00:00
Julien Isorce
be87f6096b [839/906] cocoa: allow to call set_window_handle before to create glcontext
So that it actually make cocoa videooverlay example work again.

Fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=719758
2017-12-09 19:31:32 +00:00
Matthieu Bouron
32265d7e4e [837/906] cocoa: resize OpenGL view size each time the window is resized
Fixes glitches that can appear when the OpenGL view has not been resized
after a window resize.

https://bugzilla.gnome.org/show_bug.cgi?id=711672
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
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
Tonu Jaansoo
431ce49db3 [788/906] osx: Fix compilation 2017-12-09 19:31:30 +00:00
Sebastian Dröge
8efcecb98c [771/906] gl: Some less long/ulong/gulong usage 2017-12-09 19:31:30 +00:00
Sebastian Dröge
b2934152ce [752/906] glwindow: Add destroy notifies for the data of the callbacks
And actually call the close callback when the window is closed.
2017-12-09 19:31:29 +00:00
Sebastian Dröge
bd60dd7f22 [742/906] cocoa: Allow setting window handle before creating the context 2017-12-09 19:31:29 +00:00
Sebastian Dröge
f7998a2e98 [733/906] gl: Major header and include cleanup 2017-12-09 19:31:29 +00:00
Julien Isorce
d4a8451c11 [731/906] cocoa: fix build when GNUSTEP is not defined 2017-12-09 19:31:29 +00:00
Matthew Waters
ac1a2297f5 [726/906] window: don't call a NULL destroy function 2017-12-09 19:31:29 +00:00
Matthew Waters
7d4d1f50d4 [669/906] window: seperate object creation and context creation 2017-12-09 19:31:27 +00:00
Matthew Waters
c3526080aa [629/906] window: add GError for error handling of context creation 2017-12-09 19:31:26 +00:00
Matthew Waters
0be301af24 [621/906] GstGLRendererAPI => GstGLAPI and get GstGLAPI from a window 2017-12-09 19:31:26 +00:00