Multiple windows

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Multiple windows

Postby rjxray » Mon Jan 09, 2023 8:31 am

I'm doing some very basic experimentation on creating multiple Cef/Chromium windows.

This is my code
Code: Select all
   HWND hwndApp = ofGetWin32Window();

   CefWindowInfo window_info1;
   window_info1.SetAsPopup(hwndApp, "cefWindow1");
   window_info1.bounds = { 100, 100, 300, 300 };
   CefBrowserSettings browser_settings1;
   browser1 = CefBrowserHost::CreateBrowserSync(window_info1, nullptr, url, browser_settings1, nullptr, nullptr);

   CefWindowInfo window_info2;
   window_info2.SetAsPopup(hwndApp, "cefWindow2");
   window_info2.bounds = { 500, 100,  300, 300 };
   CefBrowserSettings browser_settings2;
   browser2 = CefBrowserHost::CreateBrowserSync(window_info2, nullptr, url, browser_settings2, nullptr, nullptr);



The two windows are created but they flicker constantly and Visual Studio is unresponsive until I close one of the windows.
I have a feeling I am doing this in the wrong way, so what's the best practice?

I'm using CEF 5060 under Windows 11
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Multiple windows

Postby rjxray » Mon Jan 09, 2023 9:52 am

We are running with an external message pump and it is never returning from the first CefDoMessageLoopWork() call
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Multiple windows

Postby rjxray » Tue Jan 10, 2023 8:41 am

I've found that I can run two separate browser windows with this code
Code: Select all
   browser1 = CefBrowserHost::CreateBrowserSync(window_info1, simpleHandler, url, browser_settings1, nullptr, nullptr);
   CefBrowserHost::CreateBrowser(window_info2, simpleHandler, url, browser_settings2, nullptr, nullptr);

But if I change to this
Code: Select all
   browser1 = CefBrowserHost::CreateBrowserSync(window_info1, simpleHandler, url, browser_settings1, nullptr, nullptr);
   browser2 = CefBrowserHost::CreateBrowserSync(window_info2, simpleHandler, url, browser_settings2, nullptr, nullptr);

Then I'm back to the flickering and non return from CefDoMessageLoopWork()

I've also tried setting the second browser as a child of the first one but then it is not displayed, even if I change the first not to be a popup.

Am I flogging a dead horse or is it possible in any way to have multiple browsers in separate windows and get a reference to the browser for each?

Alternately is it possible to tile multiple browsers in a single window - with the ability to dynamically create, delete, resize and reposition them? That would actually be my ideal scenario.

The background to my question is that the shared textures patch https://bitbucket.org/chromiumembedded/cef/issues/2575/viz-implementation-for-osr cannot be updated post Chromium 103 and I am investigating an alternative:
I can use the Windows Graphics Capture API to get the texture from a (Microsoft) window much much faster than I can copy pixels with off screen rendering. I've found it works well even with windows that are drawn off the visible screen so its looking like a viable scheme. But our app requires multiple browsers which we composite into a single frame buffer and I'm stuck on this aspect at the moment.

So any help would be very much appreciated.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Multiple windows

Postby magreenblatt » Tue Jan 10, 2023 9:44 am

You can create multiple browsers with CefBrowserHost::CreateBrowser and get the CefBrowser pointer in OnAfterCreated. This is the usage pattern demoed by the CEF sample apps.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Multiple windows

Postby rjxray » Tue Jan 10, 2023 11:25 am

Thanks.
Is it possible to tile multiple browsers in a single window?
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Multiple windows

Postby magreenblatt » Tue Jan 10, 2023 1:20 pm

rjxray wrote:Thanks.
Is it possible to tile multiple browsers in a single window?

Yes, you can specify the same parent HWND via CefWindowInfo. You will need to give the browsers non-overlapping bounds and manage the resize behavior yourself.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Multiple windows

Postby rjxray » Tue Mar 28, 2023 7:46 am

I've been working for some time with two cef browser windows, the first created with CreateBrowserSync and the second with CreateBrowser.
I had assumed that the first browser window had to be created with CreateBrowserSync which did something extra to setup rendering and then I could add any number of additional browser windows with CreateBrowser.

However I have found that is not the case.

I'm now trying to add a third browser and after the third OnAfterCreated callback I am back to my original problem.
My openFrameworks app stops running and the browser windows flicker constantly as though they are updating at maximum rate.
CPU usage goes up to near maximum.
All other apps running on machine go unresponsive, I can bring windows to the foreground but I can't interact with them.

I've tried using CreateBrowser for all windows, also CreateBrowserSync for all windows but the issue remains.
Using SetAsPopup, SetAsChild or neither makes no difference.

Is there something I need to do in OnAfterCreated to throttle the windows updates?
What exactly does CreateBrowserSync do that CreateBrowser does not?

I've looked at cefclient and the New Window test runs perfectly but I can't see anything relevant in the code.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Multiple windows

Postby rjxray » Wed Mar 29, 2023 3:32 am

I could manually minimise the flickering windows and then on restoring them everything worked fine.
So I experimented a bit to reproduce this programmatically.
I tried toggling WasHidden but that had no effect.

I've found that if I can make everything work fine if I create the browser window minimised (windowInfo.style = WS_MINIMIZE) and then after OnAfterCreated wait for the next call to CefDoMessageLoopWork then show the window.
Then I can use CreateBrowser or CreateBrowserSync for every browser, they both seem to work the same.

I would still be interested to know if CreateBrowserSync internally does anything different to CreateBrowser.
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 49 guests