CEF3 on win32 + gtk

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.

CEF3 on win32 + gtk

Postby PolesApart » Wed Dec 10, 2014 8:29 am

Hi,

I'm currently integrating cef3 in an existing application written in gtk3 on win32 (yes, I know ...).
It's actually working pretty well, except for quite a high cpu usage on idle, because gtk runs on the main thread and I had to add a g_idle_add() call to a function that periodically calls CefDoMessageLoopWork().

I tried using CefRunMessageLoop approach but couldn't figure out a way to integrate gtk to it's message system.

I also tried leaving the gtk event loop on main thread and setting settings.multi_threaded_message_loop = 1 before CefInitialize, but cef won't render then.

The multithread approach IMHO would be better as this app may run on battery powered devices, I'd rather have threads sleeping when nothing is being done than have a polling of some sort.

Any thoughts?
PolesApart
Mentor
 
Posts: 73
Joined: Fri Dec 05, 2014 1:24 pm

Re: CEF3 on win32 + gtk

Postby magreenblatt » Wed Dec 10, 2014 8:41 am

What CEF3 version? Are you using windowed or off-screen rendering?
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 on win32 + gtk

Postby PolesApart » Wed Dec 10, 2014 1:04 pm

I made multithreaded message loop work. I started my coding using an example that used CreateBrowserSync instead of CreateBrowser (btw I couldn't figure out the difference between then). I've just changed to the latter, removed the g_idle_add hook that called CefDoMessageLoopWork, and it's working as a breeze now.
I'm using 3.2171.1949 on windows32, with windowed rendering.

The code I've used to hook a GtkDrawingArea to cef was this, if anyone else is crazy enough to run a gtk app on windows:
Code: Select all
static void setAsChild(GtkWidget *widget, CefWindowInfo &info) {
  gtk_widget_realize(widget);
  GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(widget));
  if (!gdk_window_ensure_native(gdk_window)) {
    g_error("gdk_window_ensure_native failed...");
  }
  HWND hWnd = gdk_win32_window_get_impl_hwnd(gdk_window);
  RECT rect;
  printf("rect: %ld %ld %ld %ld\n", rect.bottom, rect.left, rect.right, rect.top);
  GetClientRect(hWnd, &rect);
  info.SetAsChild(hWnd, rect);
}


This is the callback to inform cef's window that the widget was resized:
Code: Select all
extern "C" {

  void __declspec(dllexport) on_area_size_allocate(GtkWidget *widget,
          GdkRectangle *allocation,
          gpointer user_data) {
    CefRefPtr<CefBrowser> browser = NULL;
    if (g_handler) {
      browser = g_handler->GetBrowser();
    }
    if (browser) {
      HWND hWnd = browser->GetHost()->GetWindowHandle();
      HDWP hdwp = BeginDeferWindowPos(1);
      hdwp = DeferWindowPos(hdwp, hWnd, NULL, 0, 0,
              allocation->width, allocation->height, SWP_NOZORDER);
      EndDeferWindowPos(hdwp);
    } else {
      // At least the first time gtk generates this event, there's no native window realized.
      // It'll call it again with a realized window and we catch that then.
      //printf("Had no window to hook to.\n");
    }
  }
}
PolesApart
Mentor
 
Posts: 73
Joined: Fri Dec 05, 2014 1:24 pm

Re: CEF3 on win32 + gtk

Postby magreenblatt » Wed Dec 10, 2014 2:04 pm

If you're moving only a single window you can just use SetWindowPos instead of the defer functions.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 on win32 + gtk

Postby PolesApart » Wed Dec 10, 2014 2:37 pm

magreenblatt wrote:If you're moving only a single window you can just use SetWindowPos instead of the defer functions.

Thanks!
PolesApart
Mentor
 
Posts: 73
Joined: Fri Dec 05, 2014 1:24 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 36 guests