Skip to content

Commit

Permalink
Don't paint sources that are invisible
Browse files Browse the repository at this point in the history
  • Loading branch information
zavitax authored and OsirisNL committed Mar 17, 2018
1 parent c2aa136 commit bbb8641
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
74 changes: 74 additions & 0 deletions obs-browser/browser-manager-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ int BrowserManager::CreateBrowser(
return pimpl->CreateBrowser(browserSettings, browserListener);
}

CefBrowserHost* BrowserManager::GetBrowserHost(int browserIdentifier)
{
return pimpl->GetBrowserHost(browserIdentifier);
}

CefBrowser* BrowserManager::GetBrowser(int browserIdentifier)
{
return pimpl->GetBrowser(browserIdentifier);
}

void BrowserManager::LoadURL(int browserIdentifier, CefString& url)
{
return pimpl->LoadURL(browserIdentifier, url);
}

bool BrowserManager::IsValidBrowserIdentifier(int browserIdentifier)
{
return pimpl->IsValidBrowserIdentifier(browserIdentifier);
Expand Down Expand Up @@ -184,6 +199,65 @@ int BrowserManager::Impl::CreateBrowser(
return browserIdentifier;
}

CefBrowserHost* BrowserManager::Impl::GetBrowserHost(int browserIdentifier)
{
CefBrowserHost* result = NULL;

os_event_t* complete_event;
os_event_init(&complete_event, OS_EVENT_TYPE_AUTO);

CefPostTask(TID_UI, BrowserTask::newTask(
[&]
{
result = browserMap[browserIdentifier]->GetHost();

os_event_signal(complete_event);
}));

os_event_wait(complete_event);
os_event_destroy(complete_event);

return result;
}

CefBrowser* BrowserManager::Impl::GetBrowser(int browserIdentifier)
{
CefBrowser* result = NULL;

os_event_t* complete_event;
os_event_init(&complete_event, OS_EVENT_TYPE_AUTO);

CefPostTask(TID_UI, BrowserTask::newTask(
[&]
{
result = browserMap[browserIdentifier];

os_event_signal(complete_event);
}));

os_event_wait(complete_event);
os_event_destroy(complete_event);

return result;
}

void BrowserManager::Impl::LoadURL(int browserIdentifier, CefString& url)
{
os_event_t* complete_event;
os_event_init(&complete_event, OS_EVENT_TYPE_AUTO);

CefPostTask(TID_UI, BrowserTask::newTask(
[&]
{
browserMap[browserIdentifier]->GetMainFrame()->LoadURL(url);

os_event_signal(complete_event);
}));

os_event_wait(complete_event);
os_event_destroy(complete_event);
}

bool BrowserManager::Impl::IsValidBrowserIdentifier(int browserIdentifier)
{
return browserIdentifier >= 0 && browserMap.count(browserIdentifier) > 0;
Expand Down
4 changes: 4 additions & 0 deletions obs-browser/browser-manager-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class BrowserManager::Impl
const BrowserSettings &browserSettings,
const std::shared_ptr<BrowserListener> &browserListener);

CefBrowserHost* GetBrowserHost(int browserIdentifier);
CefBrowser* GetBrowser(int browserIdentifier);
void LoadURL(int browserIdentifier, CefString& url);

bool IsValidBrowserIdentifier(int browserIdentifier);
void DestroyBrowser(int browserIdentifier);
void TickBrowser(int browserIdentifier);
Expand Down
29 changes: 28 additions & 1 deletion obs-browser/main-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,30 @@ static void browser_source_show(void *data)
else {
bs->ExecuteVisiblityJSCallback(true);
}

// Start animation
BrowserManager::Instance()->GetBrowser(bs->GetBrowserIdentifier())->GetHost()->WasHidden(false);

#ifdef APPLE
BrowserManager::Instance()->GetBrowser(bs->GetBrowserIdentifier())->GetHost()->SetWindowVisibility(true);
#endif

// Repaint the view
BrowserManager::Instance()->GetBrowser(bs->GetBrowserIdentifier())->GetHost()->Invalidate(PET_VIEW);
}

// Called when the source is no longer visible
static void browser_source_hide(void *data)
{
BrowserSource *bs = static_cast<BrowserSource *>(data);

// Stop animation
BrowserManager::Instance()->GetBrowser(bs->GetBrowserIdentifier())->GetHost()->WasHidden(true);

#ifdef APPLE
BrowserManager::Instance()->GetBrowser(bs->GetBrowserIdentifier())->GetHost()->SetWindowVisibility(false);
#endif

if (bs->GetShutdown()) {
BrowserManager::Instance()->DestroyBrowser(bs->GetBrowserIdentifier());
}
Expand All @@ -196,7 +213,17 @@ static void *browser_source_create(obs_data_t *settings, obs_source_t *source)
BrowserSource *browserSource = new BrowserSource(settings, source);

if (browserSource->GetShutdown() && !obs_source_showing(source))
{
BrowserManager::Instance()->DestroyBrowser(browserSource->GetBrowserIdentifier());
}
else
{
if (!obs_source_showing(source))
{
// Stop animation
BrowserManager::Instance()->GetBrowser(browserSource->GetBrowserIdentifier())->GetHost()->WasHidden(true);
}
}

return browserSource;
}
Expand Down Expand Up @@ -295,4 +322,4 @@ create_browser_source_info()


return browser_source_info;
}
}
6 changes: 6 additions & 0 deletions shared/browser-manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <memory>
#include <jansson.h>
#include <include/cef_base.h>
#include <include/cef_client.h>

class BrowserListener;
struct BrowserSettings;
Expand All @@ -42,6 +44,10 @@ class BrowserManager {
const std::shared_ptr<BrowserListener>
&browserListener);

CefBrowserHost* GetBrowserHost(int browserIdentifier);
CefBrowser* GetBrowser(int browserIdentifier);
void LoadURL(int browserIdentifier, CefString& url);

bool IsValidBrowserIdentifier(int browserIdentifier);

void DestroyBrowser(int browserIdentifier);
Expand Down

0 comments on commit bbb8641

Please sign in to comment.