I'm trying to get CEF3 (Chromium Embedded Framework: https://bitbucket.org/chromiumembedded/cef) to work in conjunction with SDL (Simple DirectMedia Layer: https://www.libsdl.org/).
My intended use of these two libraries is to use SDL to open a window, receive events from it and render OpenGL graphics (in conjunction with other libraries such as GLEW). I want to use CEF3 to render graphical elements for the user interface off screen and then display them on the screen via OpenGL textures. All of this works, I can open SDL windows, handle events, I can draw OpenGL textures and get OpenGL compatible data from an off screen render in CEF3.
The problem is that if I run SDL and CEF3 together in a test environment CEF3 spawns multiple additional windows.
This is the code I use for CEF3.
void Example::webTest()
{
//Args
CefMainArgs cefArgs;
//Settings
CefSettings cefSettings;
cefSettings.pack_loading_disabled = true;
cefSettings.windowless_rendering_enabled = true;
//Initialize
CefInitialize(cefArgs, cefSettings, nullptr, nullptr);
//Render Handler
renderHandler = new InterfaceRenderHandler();
//Window Info
CefWindowInfo cefWindowInfo;
//cefWindowInfo.SetAsWindowless(0, true);
cefWindowInfo.windowless_rendering_enabled = true;
cefWindowInfo.transparent_painting_enabled = true;
//Interface Browser
CefRefPtr<InterfaceBrowserClient> cefClient;
cefClient = new InterfaceBrowserClient(renderHandler);
//Browser
CefBrowserSettings cefBrowserSettings;
cefBrowserSettings.windowless_frame_rate = 60;
CefBrowserHost::CreateBrowser(cefWindowInfo, cefClient.get(), "http://www.stackoverflow.com", cefBrowserSettings, nullptr);
//Threaded Loops
thread renderThread(renderLoop);
thread sdlThread(sdlLoop);
//Main Loop
CefRunMessageLoop();
//Unthread
renderThread.join();
sdlThread.join();
//Shutdown
CefShutdown();
}
A few notes on this code:
- The function renderLoop is intended to collect the finished textures but currently doesn't do anything.
- The function sdlLoop simply polls the SDL window for events and then discards them.
- CefRunMessageLoop locks the program. (I presume there's a loop inside it somewhere).
- CefRunMessageLoop needs to be run for the page render to occur, and it doesn't seem to behave correctly when not run in the main thread.
- InterfaceBrowserClient is a class I implemented based on CefClient that simply returns the renderHandler when called it was created with and does nothing else.
- InterfaceRenderHandler is a class I implemented based on CefRenderHandler. It provides the dimensions of the intended render area to CEF3 and receives the finished image data from CEF3.
- I've put the code for the classes here http://pastebin.com/sBm9AAQZ in case anyone needs to see them.
If I initialize an SDL window prior to running this code, two extra windows appear, one appears at new InterfaceBrowserClient(renderHandler); and the other appears when CefRunMessageLoop(); is reached. These windows are the same dimensions as the SDL window and have the same title and the same content (pure white). Then even sit at exactly the same position on the screen, such that only the top one is visible. However while the original window is responsive, Windows considers these windows unresponsive, as though they don't have event loops running. I have tried changing the render size to be different to the window size (this is done inside InterfaceRenderHandler) and I am certain that it is the size of the SDL window they are copying, not the size of the render area.
If I don't initialize an SDL window, no windows appear at all (except the command prompt of course) and the render proceeds as normal (this can be identified from the console printing out warnings as it loads the page).
Does anyone who knows more about the windowing system understand why this is occurring and more importantly, how do I get rid of these additional windows? I have not tested this on any other OSes because I don't know much about Linux C++ compilation but I'll attempt it if this problem persists.
Thanks.
CefExecuteProcess(cefArgs, nullptr, nullptr);before the call to CefInitialize, no changes to the behavior, the render still completes fine (as it did before, I managed to extract an image file and the render is indeed working as intended) and the windows still appear. - user573949