SDL 导致 CEF3 产生额外的 windows
SDL causes CEF3 to spawn additional windows
我正在尝试获取 CEF3(Chromium 嵌入式框架:https://bitbucket.org/chromiumembedded/cef) to work in conjunction with SDL (Simple DirectMedia Layer: https://www.libsdl.org/)。
我对这两个库的预期用途是使用 SDL 打开一个 window,从中接收事件并渲染 OpenGL 图形(与 GLEW 等其他库一起使用)。我想使用 CEF3 在屏幕外渲染用户界面的图形元素,然后通过 OpenGL 纹理将它们显示在屏幕上。所有这些都有效,我可以打开 SDL windows,处理事件,我可以绘制 OpenGL 纹理并从 CEF3 中的离屏渲染中获取 OpenGL 兼容数据。
问题是,如果我 运行 SDL 和 CEF3 在测试环境中一起使用,CEF3 会产生多个额外的 windows。
这是我用于 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.whosebug.com", cefBrowserSettings, nullptr);
//Threaded Loops
thread renderThread(renderLoop);
thread sdlThread(sdlLoop);
//Main Loop
CefRunMessageLoop();
//Unthread
renderThread.join();
sdlThread.join();
//Shutdown
CefShutdown();
}
关于这段代码的几点说明:
- 函数 renderLoop 旨在收集完成的纹理,但目前没有做任何事情。
- 函数 sdlLoop 简单地轮询 SDL window 事件然后丢弃它们。
- CefRunMessageLoop 锁定程序。 (我假设里面某处有一个循环)。
- CefRunMessageLoop 需要 运行 才能进行页面呈现,当主线程中没有 运行 时,它似乎无法正常运行。
- InterfaceBrowserClient 是一个 class 我基于 CefClient 实现的,只是 returns renderHandler 在被调用时是用它创建的,什么都不做。
- InterfaceRenderHandler是我class基于CefRenderHandler实现的。它向 CEF3 提供预期渲染区域的尺寸,并从 CEF3 接收完成的图像数据。
- 我已将 classes 的代码放在这里 http://pastebin.com/sBm9AAQZ 以防有人需要查看它们。
如果我在 运行 执行此代码之前初始化 SDL window,则会出现两个额外的 windows,一个出现在 new InterfaceBrowserClient(renderHandler);
,另一个出现在 CefRunMessageLoop();
到达。这些 windows 与 SDL window 具有相同的尺寸并且具有相同的标题和相同的内容(纯白色)。然后甚至坐在屏幕上完全相同的位置,这样只有最上面的一个是可见的。然而,虽然原始的 window 是有响应的,但 Windows 认为这些 windows 没有响应,就好像它们没有事件循环 运行ning 一样。我已经尝试将渲染大小更改为不同于 window 大小(这是在 InterfaceRenderHandler 内部完成的)并且我确定它是他们正在复制的 SDL window 的大小,而不是渲染区域。
如果我不初始化 SDL window,则根本不会出现 windows(当然除了命令提示符)并且渲染会正常进行(这可以从控制台识别在加载页面时打印出警告)。
对 windowing 系统有更多了解的人是否了解为什么会发生这种情况,更重要的是,我如何摆脱这些额外的 windows?我没有在任何其他操作系统上测试过这个,因为我不太了解 Linux C++ 编译,但如果这个问题仍然存在,我会尝试它。
谢谢。
多个 windows 可能 CEF
产生它的子进程,GPU
、Render
等
在子流程的情况下,您只需调用 CefExecuteProcess
和 return 它的退出代码。这必须在您的其他代码执行之前发生。您可以在 cefsimple
应用程序中看到一个工作示例。
// CEF applications have multiple sub-processes (render, plugin, GPU, etc)
// that share the same executable. This function checks the command-line and,
// if this is a sub-process, executes the appropriate logic.
int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
if (exit_code >= 0) {
// The sub-process has completed so return here.
return exit_code;
}
我正在尝试获取 CEF3(Chromium 嵌入式框架:https://bitbucket.org/chromiumembedded/cef) to work in conjunction with SDL (Simple DirectMedia Layer: https://www.libsdl.org/)。
我对这两个库的预期用途是使用 SDL 打开一个 window,从中接收事件并渲染 OpenGL 图形(与 GLEW 等其他库一起使用)。我想使用 CEF3 在屏幕外渲染用户界面的图形元素,然后通过 OpenGL 纹理将它们显示在屏幕上。所有这些都有效,我可以打开 SDL windows,处理事件,我可以绘制 OpenGL 纹理并从 CEF3 中的离屏渲染中获取 OpenGL 兼容数据。
问题是,如果我 运行 SDL 和 CEF3 在测试环境中一起使用,CEF3 会产生多个额外的 windows。
这是我用于 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.whosebug.com", cefBrowserSettings, nullptr);
//Threaded Loops
thread renderThread(renderLoop);
thread sdlThread(sdlLoop);
//Main Loop
CefRunMessageLoop();
//Unthread
renderThread.join();
sdlThread.join();
//Shutdown
CefShutdown();
}
关于这段代码的几点说明:
- 函数 renderLoop 旨在收集完成的纹理,但目前没有做任何事情。
- 函数 sdlLoop 简单地轮询 SDL window 事件然后丢弃它们。
- CefRunMessageLoop 锁定程序。 (我假设里面某处有一个循环)。
- CefRunMessageLoop 需要 运行 才能进行页面呈现,当主线程中没有 运行 时,它似乎无法正常运行。
- InterfaceBrowserClient 是一个 class 我基于 CefClient 实现的,只是 returns renderHandler 在被调用时是用它创建的,什么都不做。
- InterfaceRenderHandler是我class基于CefRenderHandler实现的。它向 CEF3 提供预期渲染区域的尺寸,并从 CEF3 接收完成的图像数据。
- 我已将 classes 的代码放在这里 http://pastebin.com/sBm9AAQZ 以防有人需要查看它们。
如果我在 运行 执行此代码之前初始化 SDL window,则会出现两个额外的 windows,一个出现在 new InterfaceBrowserClient(renderHandler);
,另一个出现在 CefRunMessageLoop();
到达。这些 windows 与 SDL window 具有相同的尺寸并且具有相同的标题和相同的内容(纯白色)。然后甚至坐在屏幕上完全相同的位置,这样只有最上面的一个是可见的。然而,虽然原始的 window 是有响应的,但 Windows 认为这些 windows 没有响应,就好像它们没有事件循环 运行ning 一样。我已经尝试将渲染大小更改为不同于 window 大小(这是在 InterfaceRenderHandler 内部完成的)并且我确定它是他们正在复制的 SDL window 的大小,而不是渲染区域。
如果我不初始化 SDL window,则根本不会出现 windows(当然除了命令提示符)并且渲染会正常进行(这可以从控制台识别在加载页面时打印出警告)。
对 windowing 系统有更多了解的人是否了解为什么会发生这种情况,更重要的是,我如何摆脱这些额外的 windows?我没有在任何其他操作系统上测试过这个,因为我不太了解 Linux C++ 编译,但如果这个问题仍然存在,我会尝试它。
谢谢。
多个 windows 可能 CEF
产生它的子进程,GPU
、Render
等
在子流程的情况下,您只需调用 CefExecuteProcess
和 return 它的退出代码。这必须在您的其他代码执行之前发生。您可以在 cefsimple
应用程序中看到一个工作示例。
// CEF applications have multiple sub-processes (render, plugin, GPU, etc)
// that share the same executable. This function checks the command-line and,
// if this is a sub-process, executes the appropriate logic.
int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
if (exit_code >= 0) {
// The sub-process has completed so return here.
return exit_code;
}