diff --git a/.gitignore b/.gitignore index fffb942..159cc0a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ output CMakeLists.txt.user out __pycache__ -obj/ \ No newline at end of file +obj/ +.agent/ +AGENTS.md \ No newline at end of file diff --git a/src/CCefView/capi/CefBrowser_c.cpp b/src/CCefView/capi/CefBrowser_c.cpp index d5e79be..794b701 100644 --- a/src/CCefView/capi/CefBrowser_c.cpp +++ b/src/CCefView/capi/CefBrowser_c.cpp @@ -103,6 +103,10 @@ void CCefBrowser_setWindowlessFrameRate(ccefbrowser_class * thiz, int rate) { thiz->setWindowlessFrameRate(rate); } +void CCefBrowser_sendExternalBeginFrame(ccefbrowser_class * thiz) { + thiz->sendExternalBeginFrame(); +} + void CCefBrowser_setFocus(ccefbrowser_class * thiz, bool focused) { thiz->setFocus(focused); } diff --git a/src/CCefView/capi/CefBrowser_c.h b/src/CCefView/capi/CefBrowser_c.h index e4a341d..730c419 100644 --- a/src/CCefView/capi/CefBrowser_c.h +++ b/src/CCefView/capi/CefBrowser_c.h @@ -54,6 +54,7 @@ extern "C" CCEFVIEW_EXPORT void CCefBrowser_setDisablePopupContextMenu(ccefbrowser_class * thiz, bool disable); CCEFVIEW_EXPORT bool CCefBrowser_isPopupContextMenuDisabled(ccefbrowser_class * thiz); CCEFVIEW_EXPORT void CCefBrowser_setWindowlessFrameRate(ccefbrowser_class * thiz, int rate); + CCEFVIEW_EXPORT void CCefBrowser_sendExternalBeginFrame(ccefbrowser_class * thiz); CCEFVIEW_EXPORT void CCefBrowser_setFocus(ccefbrowser_class * thiz, bool focused); CCEFVIEW_EXPORT void CCefBrowser_wasResized(ccefbrowser_class * thiz); CCEFVIEW_EXPORT void CCefBrowser_wasHidden(ccefbrowser_class * thiz, bool hidden); diff --git a/src/CCefView/include/CefBrowser.h b/src/CCefView/include/CefBrowser.h index 305c3dc..986d2e6 100644 --- a/src/CCefView/include/CefBrowser.h +++ b/src/CCefView/include/CefBrowser.h @@ -1,4 +1,4 @@ -#ifndef CCEFVIEW_H +#ifndef CCEFVIEW_H #define CCEFVIEW_H #pragma once @@ -228,6 +228,7 @@ class CCefBrowser #pragma region Control CEF void setWindowlessFrameRate(int rate); + void sendExternalBeginFrame(); void setFocus(bool focused); void wasResized(); void wasHidden(bool hidden); diff --git a/src/CCefView/source/CefBrowser.cpp b/src/CCefView/source/CefBrowser.cpp index 24d3dc7..bcecc41 100644 --- a/src/CCefView/source/CefBrowser.cpp +++ b/src/CCefView/source/CefBrowser.cpp @@ -1,4 +1,4 @@ -#include "CefBrowser.h" +#include "CefBrowser.h" #pragma region cef_headers #include @@ -33,10 +33,18 @@ CCefBrowser::CCefBrowser(CefBrowserCallback callback, const std::string& url, co CefBrowserSettings browserSettings; CCefSetting::CopyToCefBrowserSettings(setting, browserSettings); - // Set window info + // Set window info based on configured rendering mode. CefWindowInfo window_info; - window_info.SetAsWindowless(0); - window_info.shared_texture_enabled = (setting && setting->hardwareAcceleration_); + bool windowlessRenderingEnabled = false; + if (pContext && pContext->cefConfig()) { + windowlessRenderingEnabled = pContext->cefConfig()->windowlessRendering(); + } + + if (windowlessRenderingEnabled) { + window_info.SetAsWindowless(0); + window_info.shared_texture_enabled = (setting && setting->hardwareAcceleration_); + window_info.external_begin_frame_enabled = true; + } if (CefColorGetA(browserSettings.background_color) == 0) transparentPaintingEnabled_ = true; @@ -332,6 +340,19 @@ CCefBrowser::setWindowlessFrameRate(int rate) pCefBrowser_->GetHost()->SetWindowlessFrameRate(rate); } +void +CCefBrowser::sendExternalBeginFrame() +{ + if (!pCefBrowser_) + return; + + auto host = pCefBrowser_->GetHost(); + if (!host || !host->IsWindowRenderingDisabled()) + return; + + host->SendExternalBeginFrame(); +} + void CCefBrowser::setFocus(bool focused) { diff --git a/src/CCefView/source/CefContext.cpp b/src/CCefView/source/CefContext.cpp index 7eb1125..34ee963 100644 --- a/src/CCefView/source/CefContext.cpp +++ b/src/CCefView/source/CefContext.cpp @@ -1,10 +1,11 @@ -#include "CefContext.h" +#include "CefContext.h" #include CCefContext* CCefContext::instance_ = nullptr; CCefContext::CCefContext(const CCefConfig* config) + : config_(config) { instance_ = this; init(config); @@ -54,6 +55,9 @@ CCefContext::doCefMessageLoopWork() bool CCefContext::isSafeToShutdown() { + if (!pApp_) + return true; + return pApp_->IsSafeToExit(); } diff --git a/src/CCefView/source/win/CefContext_win.cpp b/src/CCefView/source/win/CefContext_win.cpp index 3701bfb..f1d98c8 100644 --- a/src/CCefView/source/win/CefContext_win.cpp +++ b/src/CCefView/source/win/CefContext_win.cpp @@ -1,4 +1,4 @@ -#include +#include #undef OS_WINDOWS #include @@ -15,6 +15,8 @@ bool CCefContext::init(const CCefConfig* config) { + config_ = config; + // get current dll handle HMODULE hCurrentModule = nullptr; ::GetModuleHandleEx( @@ -108,12 +110,15 @@ CCefContext::init(const CCefConfig* config) void CCefContext::uninit() { - if (!pApp_) + if (!pApp_) { + config_ = nullptr; return; + } pAppDelegate_ = nullptr; pApp_ = nullptr; // shutdown the cef CefShutdown(); + config_ = nullptr; } diff --git a/src/DNCefView/AutoGen/CefBrowser+AutoGen.cs b/src/DNCefView/AutoGen/CefBrowser+AutoGen.cs index f9e38fe..012dc1f 100644 --- a/src/DNCefView/AutoGen/CefBrowser+AutoGen.cs +++ b/src/DNCefView/AutoGen/CefBrowser+AutoGen.cs @@ -224,6 +224,14 @@ public void SetWindowlessFrameRate(int rate) CCefBrowser_setWindowlessFrameRate(_native, rate); } + // Source: void sendExternalBeginFrame() + [DllImport("CCefView")] + private static extern void CCefBrowser_sendExternalBeginFrame(IntPtr thiz); + public void SendExternalBeginFrame() + { + CCefBrowser_sendExternalBeginFrame(_native); + } + // Source: void setFocus(bool) [DllImport("CCefView")] private static extern void CCefBrowser_setFocus(IntPtr thiz, bool focused);