Move OSR api to OsrWCV to allow api calls to take effect sooner
This commit is contained in:
parent
1a8916ed47
commit
406f171c88
6 changed files with 105 additions and 25 deletions
|
@ -378,8 +378,8 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
|
|||
options.Get("transparent", &transparent);
|
||||
|
||||
content::WebContents::CreateParams params(session->browser_context());
|
||||
auto* view = new OffScreenWebContentsView(
|
||||
transparent, base::Bind(&WebContents::OnPaint, base::Unretained(this)));
|
||||
auto* view = new OffScreenWebContentsView(transparent,
|
||||
base::Bind(&WebContents::OnPaint, base::Unretained(this)));
|
||||
params.view = view;
|
||||
params.delegate_view = view;
|
||||
|
||||
|
@ -1652,10 +1652,14 @@ void WebContents::StartPainting() {
|
|||
return;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->SetPainting(true);
|
||||
const auto* wc_impl = web_contents_impl();
|
||||
if (!wc_impl)
|
||||
return;
|
||||
|
||||
auto* osr_wcv = static_cast<OffScreenWebContentsView*>(
|
||||
wc_impl->GetView());
|
||||
if (osr_wcv)
|
||||
osr_wcv->SetPainting(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1664,10 +1668,14 @@ void WebContents::StopPainting() {
|
|||
return;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->SetPainting(false);
|
||||
const auto* wc_impl = web_contents_impl();
|
||||
if (!wc_impl)
|
||||
return;
|
||||
|
||||
auto* osr_wcv = static_cast<OffScreenWebContentsView*>(
|
||||
wc_impl->GetView());
|
||||
if (osr_wcv)
|
||||
osr_wcv->SetPainting(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1676,9 +1684,13 @@ bool WebContents::IsPainting() const {
|
|||
return false;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
return osr_rwhv && osr_rwhv->IsPainting();
|
||||
const auto* wc_impl = web_contents_impl();
|
||||
if (!wc_impl)
|
||||
return false;
|
||||
|
||||
const auto* osr_wcv = static_cast<OffScreenWebContentsView*>(
|
||||
wc_impl->GetView());
|
||||
return osr_wcv && osr_wcv->IsPainting();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
@ -1689,10 +1701,14 @@ void WebContents::SetFrameRate(int frame_rate) {
|
|||
return;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->SetFrameRate(frame_rate);
|
||||
const auto* wc_impl = web_contents_impl();
|
||||
if (!wc_impl)
|
||||
return;
|
||||
|
||||
auto* osr_wcv = static_cast<OffScreenWebContentsView*>(
|
||||
wc_impl->GetView());
|
||||
if (osr_wcv)
|
||||
osr_wcv->SetFrameRate(frame_rate);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1701,9 +1717,13 @@ int WebContents::GetFrameRate() const {
|
|||
return 0;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
return osr_rwhv ? osr_rwhv->GetFrameRate() : 0;
|
||||
const auto* wc_impl = web_contents_impl();
|
||||
if (!wc_impl)
|
||||
return 0;
|
||||
|
||||
const auto* osr_wcv = static_cast<OffScreenWebContentsView*>(
|
||||
wc_impl->GetView());
|
||||
return osr_wcv ? osr_wcv->GetFrameRate() : 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/common_web_contents_delegate.h"
|
||||
#include "atom/browser/ui/autofill_popup.h"
|
||||
#include "content/browser/web_contents/web_contents_impl.h"
|
||||
#include "content/common/cursors/webcursor.h"
|
||||
#include "content/public/browser/keyboard_event_processing_result.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
@ -373,6 +374,10 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
return ++request_id_;
|
||||
}
|
||||
|
||||
content::WebContentsImpl* web_contents_impl() const {
|
||||
return static_cast<content::WebContentsImpl*>(web_contents());
|
||||
}
|
||||
|
||||
// Called when we receive a CursorChange message from chromium.
|
||||
void OnCursorChange(const content::WebCursor& cursor);
|
||||
|
||||
|
|
|
@ -255,6 +255,8 @@ class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient {
|
|||
|
||||
OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
||||
bool transparent,
|
||||
bool painting,
|
||||
int frame_rate,
|
||||
const OnPaintCallback& callback,
|
||||
content::RenderWidgetHost* host,
|
||||
OffScreenRenderWidgetHostView* parent_host_view,
|
||||
|
@ -268,12 +270,12 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
|||
transparent_(transparent),
|
||||
callback_(callback),
|
||||
parent_callback_(nullptr),
|
||||
frame_rate_(60),
|
||||
frame_rate_(frame_rate),
|
||||
frame_rate_threshold_us_(0),
|
||||
last_time_(base::Time::Now()),
|
||||
scale_factor_(kDefaultScaleFactor),
|
||||
size_(native_window->GetSize()),
|
||||
painting_(true),
|
||||
painting_(painting),
|
||||
is_showing_(!render_widget_host_->is_hidden()),
|
||||
is_destroyed_(false),
|
||||
popup_position_(gfx::Rect()),
|
||||
|
@ -738,6 +740,8 @@ content::RenderWidgetHostViewBase*
|
|||
|
||||
return new OffScreenRenderWidgetHostView(
|
||||
transparent_,
|
||||
true,
|
||||
embedder_host_view->GetFrameRate(),
|
||||
callback_,
|
||||
render_widget_host,
|
||||
embedder_host_view,
|
||||
|
@ -929,7 +933,7 @@ bool OffScreenRenderWidgetHostView::IsAutoResizeEnabled() const {
|
|||
|
||||
void OffScreenRenderWidgetHostView::SetNeedsBeginFrames(
|
||||
bool needs_begin_frames) {
|
||||
SetupFrameRate(false);
|
||||
SetupFrameRate(true);
|
||||
|
||||
begin_frame_timer_->SetActive(needs_begin_frames);
|
||||
|
||||
|
@ -1173,10 +1177,10 @@ void OffScreenRenderWidgetHostView::SetFrameRate(int frame_rate) {
|
|||
frame_rate_ = frame_rate;
|
||||
}
|
||||
|
||||
SetupFrameRate(true);
|
||||
|
||||
for (auto guest_host_view : guest_host_views_)
|
||||
guest_host_view->SetFrameRate(frame_rate);
|
||||
|
||||
SetupFrameRate(true);
|
||||
}
|
||||
|
||||
int OffScreenRenderWidgetHostView::GetFrameRate() const {
|
||||
|
|
|
@ -74,6 +74,8 @@ class OffScreenRenderWidgetHostView
|
|||
public OffscreenViewProxyObserver {
|
||||
public:
|
||||
OffScreenRenderWidgetHostView(bool transparent,
|
||||
bool painting,
|
||||
int frame_rate,
|
||||
const OnPaintCallback& callback,
|
||||
content::RenderWidgetHost* render_widget_host,
|
||||
OffScreenRenderWidgetHostView* parent_host_view,
|
||||
|
|
|
@ -15,6 +15,8 @@ namespace atom {
|
|||
OffScreenWebContentsView::OffScreenWebContentsView(
|
||||
bool transparent, const OnPaintCallback& callback)
|
||||
: transparent_(transparent),
|
||||
painting_(true),
|
||||
frame_rate_(60),
|
||||
callback_(callback),
|
||||
web_contents_(nullptr) {
|
||||
#if defined(OS_MACOSX)
|
||||
|
@ -103,6 +105,8 @@ content::RenderWidgetHostViewBase*
|
|||
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
|
||||
return new OffScreenRenderWidgetHostView(
|
||||
transparent_,
|
||||
painting_,
|
||||
GetFrameRate(),
|
||||
callback_,
|
||||
render_widget_host,
|
||||
nullptr,
|
||||
|
@ -125,6 +129,8 @@ content::RenderWidgetHostViewBase*
|
|||
|
||||
return new OffScreenRenderWidgetHostView(
|
||||
transparent_,
|
||||
true,
|
||||
view->GetFrameRate(),
|
||||
callback_,
|
||||
render_widget_host,
|
||||
view,
|
||||
|
@ -202,6 +208,42 @@ void OffScreenWebContentsView::UpdateDragCursor(
|
|||
blink::WebDragOperation operation) {
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::SetPainting(bool painting) {
|
||||
auto* view = GetView();
|
||||
if (view != nullptr) {
|
||||
view->SetPainting(painting);
|
||||
} else {
|
||||
painting_ = painting;
|
||||
}
|
||||
}
|
||||
|
||||
bool OffScreenWebContentsView::IsPainting() const {
|
||||
auto* view = GetView();
|
||||
if (view != nullptr) {
|
||||
return view->IsPainting();
|
||||
} else {
|
||||
return painting_;
|
||||
}
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::SetFrameRate(int frame_rate) {
|
||||
auto* view = GetView();
|
||||
if (view != nullptr) {
|
||||
view->SetFrameRate(frame_rate);
|
||||
} else {
|
||||
frame_rate_ = frame_rate;
|
||||
}
|
||||
}
|
||||
|
||||
int OffScreenWebContentsView::GetFrameRate() const {
|
||||
auto* view = GetView();
|
||||
if (view != nullptr) {
|
||||
return view->GetFrameRate();
|
||||
} else {
|
||||
return frame_rate_;
|
||||
}
|
||||
}
|
||||
|
||||
OffScreenRenderWidgetHostView* OffScreenWebContentsView::GetView() const {
|
||||
if (web_contents_) {
|
||||
return static_cast<OffScreenRenderWidgetHostView*>(
|
||||
|
|
|
@ -69,6 +69,11 @@ class OffScreenWebContentsView : public content::WebContentsView,
|
|||
content::RenderWidgetHostImpl* source_rwh) override;
|
||||
void UpdateDragCursor(blink::WebDragOperation operation) override;
|
||||
|
||||
void SetPainting(bool painting);
|
||||
bool IsPainting() const;
|
||||
void SetFrameRate(int frame_rate);
|
||||
int GetFrameRate() const;
|
||||
|
||||
private:
|
||||
#if defined(OS_MACOSX)
|
||||
void PlatformCreate();
|
||||
|
@ -78,6 +83,8 @@ class OffScreenWebContentsView : public content::WebContentsView,
|
|||
OffScreenRenderWidgetHostView* GetView() const;
|
||||
|
||||
const bool transparent_;
|
||||
bool painting_;
|
||||
int frame_rate_;
|
||||
OnPaintCallback callback_;
|
||||
|
||||
// Weak refs.
|
||||
|
|
Loading…
Reference in a new issue