Page 1 of 1

Mac OSX off-screen rendering thread

PostPosted: Fri Mar 12, 2021 1:05 pm
by phronmophobic
For offscreen rendering on OSX, are cef_* calls required to be on the main thread (ie. thread 1) or is it enough to ensure that all cef_* calls originate from the same thread?

Re: Mac OSX off-screen rendering thread

PostPosted: Fri Mar 12, 2021 2:03 pm
by magreenblatt
It depends on the function. Check the documentation.

Re: Mac OSX off-screen rendering thread

PostPosted: Fri Mar 12, 2021 5:34 pm
by phronmophobic
I can't find anywhere in the documentation where it distinguishes between "a" main thread vs "the" main thread (ie. the Mac OSX thread 1).

I find several terms in the comments, but I can't find anywhere that specifies which, if any, refer to the special thread 1 on Mac OSX.
- browser process main thread
- main thread
- render process main thread
- main thread (TID_RENDERER)
- UI thread
- browser process UI thread

In addition to the source code comments, the guides don't seem to distinguish between the two either:

https://bitbucket.org/chromiumembedded/ ... er-threads
It defines the main thread is the thread that cef_initialize is called on, but does not say whether it must be thread 1 on Mac OSX.

The comment for cef_initialize says "This function should be called on the main application thread to initialize", but does not specify whether it should be thread 1.

According to https://developer.apple.com/library/arc ... mmary.html, most everything can be used from "a" main thread (ie. not thread 1) except for NSView and event handling. It seems like that should allow for an application that uses offscreen rendering to run everything on "a" main thread, but it would be great to have a clearer answer.

Thanks,

Re: Mac OSX off-screen rendering thread

PostPosted: Fri Mar 12, 2021 5:51 pm
by magreenblatt
The "main thread" is the thread that main() is called on. That is probably also "thread 1" in most cases. The main thread will also be the UI thread, except when CefSettings.multi_threaded_message_loop is set to true (this setting is not supported on MacOS).

I don't know what multiple "main threads" would mean on MacOS. Do you gave a specific system API in mind?

Re: Mac OSX off-screen rendering thread

PostPosted: Fri Mar 12, 2021 5:58 pm
by phronmophobic
The goal isn't to have multiple main threads. The goal would be to run all of the browser work off of thread 1 so that thread 1 can be free to do only tasks that must absolutely be run on thread 1.

All of the browser work would still only be called from a single thread, it just wouldn't be thread 1. It also allows applications to simply use cef_run_message_loop rather than integrating cef_do_message_loop_work/on_schedule_message_pump_work into their application.

Re: Mac OSX off-screen rendering thread

PostPosted: Fri Mar 12, 2021 6:32 pm
by magreenblatt
That’s not possible for the NSView and event handling reasons you mention above.

Re: Mac OSX off-screen rendering thread

PostPosted: Fri Mar 12, 2021 7:26 pm
by phronmophobic
In theory, it seems like those restrictions might not apply in the case of off-screen rendering. Initial tests haven't crashed when running cef off of thread 1.