|
@@ -5,36 +5,35 @@
|
|
|
|
|
|
|
|
using namespace WallpaperEngine::Render;
|
|
using namespace WallpaperEngine::Render;
|
|
|
|
|
|
|
|
-CWeb::CWeb (Core::CWeb* web, CRenderContext& context, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode) :
|
|
|
|
|
|
|
+CWeb::CWeb (Core::CWeb* web, CRenderContext& context, CAudioContext& audioContext,
|
|
|
|
|
+ const CWallpaperState::TextureUVsScaling& scalingMode) :
|
|
|
CWallpaper (web, Type, context, audioContext, scalingMode),
|
|
CWallpaper (web, Type, context, audioContext, scalingMode),
|
|
|
m_width (context.getOutput ().getFullWidth ()),
|
|
m_width (context.getOutput ().getFullWidth ()),
|
|
|
m_height (context.getOutput ().getFullHeight ()),
|
|
m_height (context.getOutput ().getFullHeight ()),
|
|
|
- m_browser(),
|
|
|
|
|
- m_client()
|
|
|
|
|
-{
|
|
|
|
|
|
|
+ m_browser (),
|
|
|
|
|
+ m_client () {
|
|
|
// setup framebuffers
|
|
// setup framebuffers
|
|
|
- this->setupFramebuffers();
|
|
|
|
|
|
|
+ this->setupFramebuffers ();
|
|
|
|
|
|
|
|
CefWindowInfo window_info;
|
|
CefWindowInfo window_info;
|
|
|
- window_info.SetAsWindowless(0);
|
|
|
|
|
|
|
+ window_info.SetAsWindowless (0);
|
|
|
|
|
|
|
|
- this->m_render_handler = new RenderHandler(this);
|
|
|
|
|
|
|
+ this->m_render_handler = new RenderHandler (this);
|
|
|
|
|
|
|
|
CefBrowserSettings browserSettings;
|
|
CefBrowserSettings browserSettings;
|
|
|
- //Documentaion says that 60 fps is maximum value
|
|
|
|
|
- browserSettings.windowless_frame_rate = std::max(60,context.getApp().getContext().settings.render.maximumFPS);
|
|
|
|
|
-
|
|
|
|
|
- m_client = new BrowserClient(m_render_handler);
|
|
|
|
|
- std::filesystem::path htmlpath = this->getWeb ()->getProject ().getContainer ()->resolveRealFile (this->getWeb ()->getFilename ());
|
|
|
|
|
- //To open local file in browser URL must be "file:///path/to/file.html"
|
|
|
|
|
- const std::string htmlURL = std::string("file:///") + htmlpath.c_str();
|
|
|
|
|
- m_browser = CefBrowserHost::CreateBrowserSync(window_info, m_client.get(),
|
|
|
|
|
- htmlURL, browserSettings,
|
|
|
|
|
- nullptr, nullptr);
|
|
|
|
|
|
|
+ // Documentaion says that 60 fps is maximum value
|
|
|
|
|
+ browserSettings.windowless_frame_rate = std::max (60, context.getApp ().getContext ().settings.render.maximumFPS);
|
|
|
|
|
+
|
|
|
|
|
+ m_client = new BrowserClient (m_render_handler);
|
|
|
|
|
+ std::filesystem::path htmlpath =
|
|
|
|
|
+ this->getWeb ()->getProject ().getContainer ()->resolveRealFile (this->getWeb ()->getFilename ());
|
|
|
|
|
+ // To open local file in browser URL must be "file:///path/to/file.html"
|
|
|
|
|
+ const std::string htmlURL = std::string ("file:///") + htmlpath.c_str ();
|
|
|
|
|
+ m_browser =
|
|
|
|
|
+ CefBrowserHost::CreateBrowserSync (window_info, m_client.get (), htmlURL, browserSettings, nullptr, nullptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void CWeb::setSize (int64_t width, int64_t height)
|
|
|
|
|
-{
|
|
|
|
|
|
|
+void CWeb::setSize (int64_t width, int64_t height) {
|
|
|
this->m_width = width > 0 ? width : this->m_width;
|
|
this->m_width = width > 0 ? width : this->m_width;
|
|
|
this->m_height = height > 0 ? height : this->m_height;
|
|
this->m_height = height > 0 ? height : this->m_height;
|
|
|
|
|
|
|
@@ -43,73 +42,67 @@ void CWeb::setSize (int64_t width, int64_t height)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
// reconfigure the texture
|
|
// reconfigure the texture
|
|
|
- glBindTexture (GL_TEXTURE_2D, this->getWallpaperTexture());
|
|
|
|
|
- glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, this->getWidth(), this->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
|
|
|
|
|
|
+ glBindTexture (GL_TEXTURE_2D, this->getWallpaperTexture ());
|
|
|
|
|
+ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, this->getWidth (), this->getHeight (), 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
|
+ nullptr);
|
|
|
|
|
|
|
|
// Notify cef that it was resized(maybe it's not even needed)
|
|
// Notify cef that it was resized(maybe it's not even needed)
|
|
|
- m_browser->GetHost()->WasResized();
|
|
|
|
|
|
|
+ m_browser->GetHost ()->WasResized ();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void CWeb::renderFrame (glm::ivec4 viewport)
|
|
|
|
|
-{
|
|
|
|
|
|
|
+void CWeb::renderFrame (glm::ivec4 viewport) {
|
|
|
// ensure the virtual mouse position is up to date
|
|
// ensure the virtual mouse position is up to date
|
|
|
this->updateMouse (viewport);
|
|
this->updateMouse (viewport);
|
|
|
// use the scene's framebuffer by default
|
|
// use the scene's framebuffer by default
|
|
|
- glBindFramebuffer (GL_FRAMEBUFFER, this->getWallpaperFramebuffer());
|
|
|
|
|
|
|
+ glBindFramebuffer (GL_FRAMEBUFFER, this->getWallpaperFramebuffer ());
|
|
|
// ensure we render over the whole framebuffer
|
|
// ensure we render over the whole framebuffer
|
|
|
glViewport (0, 0, this->getWidth (), this->getHeight ());
|
|
glViewport (0, 0, this->getWidth (), this->getHeight ());
|
|
|
|
|
|
|
|
- //Cef processes all messages, including OnPaint, which renders frame
|
|
|
|
|
- //If there is no OnPaint in message loop, we will not update(render) frame
|
|
|
|
|
- // This means some frames will not have OnPaint call in cef messageLoop
|
|
|
|
|
- // Because of that glClear will result in flickering on higher fps
|
|
|
|
|
- // Do not use glClear until some method to control rendering with cef is supported
|
|
|
|
|
- //We might actually try to use cef to execute javascript, and not using off-screen rendering at all
|
|
|
|
|
- //But for now let it be like this
|
|
|
|
|
- // glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
- CefDoMessageLoopWork();
|
|
|
|
|
|
|
+ // Cef processes all messages, including OnPaint, which renders frame
|
|
|
|
|
+ // If there is no OnPaint in message loop, we will not update(render) frame
|
|
|
|
|
+ // This means some frames will not have OnPaint call in cef messageLoop
|
|
|
|
|
+ // Because of that glClear will result in flickering on higher fps
|
|
|
|
|
+ // Do not use glClear until some method to control rendering with cef is supported
|
|
|
|
|
+ // We might actually try to use cef to execute javascript, and not using off-screen rendering at all
|
|
|
|
|
+ // But for now let it be like this
|
|
|
|
|
+ // glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
+ CefDoMessageLoopWork ();
|
|
|
}
|
|
}
|
|
|
-void CWeb::updateMouse (glm::ivec4 viewport)
|
|
|
|
|
-{
|
|
|
|
|
|
|
+
|
|
|
|
|
+void CWeb::updateMouse (glm::ivec4 viewport) {
|
|
|
// update virtual mouse position first
|
|
// update virtual mouse position first
|
|
|
- glm::dvec2 position = this->getContext ().getInputContext ().getMouseInput ().position();
|
|
|
|
|
|
|
+ glm::dvec2 position = this->getContext ().getInputContext ().getMouseInput ().position ();
|
|
|
|
|
|
|
|
CefMouseEvent evt;
|
|
CefMouseEvent evt;
|
|
|
// Set mouse current position. Maybe clamps are not needed
|
|
// Set mouse current position. Maybe clamps are not needed
|
|
|
- evt.x = std::clamp(int(position.x - viewport.x),0,viewport.z);
|
|
|
|
|
- evt.y = std::clamp(int(position.y - viewport.y),0,viewport.w);
|
|
|
|
|
|
|
+ evt.x = std::clamp (int (position.x - viewport.x), 0, viewport.z);
|
|
|
|
|
+ evt.y = std::clamp (int (position.y - viewport.y), 0, viewport.w);
|
|
|
// Send mouse position to cef
|
|
// Send mouse position to cef
|
|
|
- m_browser->GetHost()->SendMouseMoveEvent(evt, false);
|
|
|
|
|
|
|
+ m_browser->GetHost ()->SendMouseMoveEvent (evt, false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-CWeb::~CWeb(){
|
|
|
|
|
- CefDoMessageLoopWork();
|
|
|
|
|
- m_browser->GetHost()->CloseBrowser(true);
|
|
|
|
|
|
|
+CWeb::~CWeb () {
|
|
|
|
|
+ CefDoMessageLoopWork ();
|
|
|
|
|
+ m_browser->GetHost ()->CloseBrowser (true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+CWeb::RenderHandler::RenderHandler (CWeb* webdata) : m_webdata (webdata) {}
|
|
|
|
|
|
|
|
-CWeb::RenderHandler::RenderHandler(CWeb* webdata):
|
|
|
|
|
- m_webdata(webdata)
|
|
|
|
|
-{
|
|
|
|
|
-}
|
|
|
|
|
-CWeb::RenderHandler::~RenderHandler(){
|
|
|
|
|
-}
|
|
|
|
|
-//Required by CEF
|
|
|
|
|
-void CWeb::RenderHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
|
|
|
|
|
-{
|
|
|
|
|
- rect = CefRect(0, 0, this->m_webdata->getWidth(), this->m_webdata->getHeight());
|
|
|
|
|
|
|
+CWeb::RenderHandler::~RenderHandler () {}
|
|
|
|
|
+
|
|
|
|
|
+// Required by CEF
|
|
|
|
|
+void CWeb::RenderHandler::GetViewRect (CefRefPtr<CefBrowser> browser, CefRect& rect) {
|
|
|
|
|
+ rect = CefRect (0, 0, this->m_webdata->getWidth (), this->m_webdata->getHeight ());
|
|
|
}
|
|
}
|
|
|
-//Will be executed in CEF message loop
|
|
|
|
|
-void CWeb::RenderHandler::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type,
|
|
|
|
|
- const RectList &dirtyRects, const void *buffer,
|
|
|
|
|
- int width, int height)
|
|
|
|
|
-{
|
|
|
|
|
- //sLog.debug("BrowserView::RenderHandler::OnPaint");
|
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, this->texture());
|
|
|
|
|
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA_EXT,
|
|
|
|
|
- GL_UNSIGNED_BYTE, (unsigned char*)buffer);
|
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
+
|
|
|
|
|
+// Will be executed in CEF message loop
|
|
|
|
|
+void CWeb::RenderHandler::OnPaint (CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList& dirtyRects,
|
|
|
|
|
+ const void* buffer, int width, int height) {
|
|
|
|
|
+ // sLog.debug("BrowserView::RenderHandler::OnPaint");
|
|
|
|
|
+ glActiveTexture (GL_TEXTURE0);
|
|
|
|
|
+ glBindTexture (GL_TEXTURE_2D, this->texture ());
|
|
|
|
|
+ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, (unsigned char*) buffer);
|
|
|
|
|
+ glBindTexture (GL_TEXTURE_2D, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const std::string CWeb::Type = "web";
|
|
const std::string CWeb::Type = "web";
|