8000 Improve OSR API (1-7-x) by brenca · Pull Request #11730 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve OSR API (1-7-x) #11730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,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;

Expand Down Expand Up @@ -1597,10 +1597,10 @@ 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 = static_cast<content::WebContentsImpl*>(web_contents());
auto* osr_wcv = static_cast<OffScreenWebContentsView*>(wc_impl->GetView());
if (osr_wcv)
osr_wcv->SetPainting(true);
#endif
}

Expand All @@ -1609,10 +1609,10 @@ 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 = static_cast<content::WebContentsImpl*>(web_contents());
auto* osr_wcv = static_cast<OffScreenWebContentsView*>(wc_impl->GetView());
if (osr_wcv)
osr_wcv->SetPainting(false);
#endif
}

Expand All @@ -1621,9 +1621,10 @@ 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 = static_cast<content::WebContentsImpl*>(web_contents());
auto* osr_wcv = static_cast<OffScreenWebContentsView*>(wc_impl->GetView());

return osr_wcv && osr_wcv->IsPainting();
#else
return false;
#endif
Expand All @@ -1634,10 +1635,11 @@ 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 = static_cast<content::WebContentsImpl*>(web_contents());
auto* osr_wcv = static_cast<OffScreenWebContentsView*>(wc_impl->GetView());

if (osr_wcv)
osr_wcv->SetFrameRate(frame_rate);
#endif
}

Expand All @@ -1646,9 +1648,10 @@ 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 = static_cast<content::WebContentsImpl*>(web_contents());
auto* osr_wcv = static_cast<OffScreenWebContentsView*>(wc_impl->GetView());

return osr_wcv ? osr_wcv->GetFrameRate() : 0;
#else
return 0;
#endif
Expand Down
4 changes: 2 additions & 2 deletions atom/browser/osr/osr_output_device.cc
10000
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ void OffScreenOutputDevice::EndPaint() {
OnPaint(damage_rect_);
}

void OffScreenOutputDevice::SetActive(bool active) {
void OffScreenOutputDevice::SetActive(bool active, bool paint) {
if (active == active_)
return;
active_ = active;

if (active_)
if (active_ && paint)
OnPaint(gfx::Rect(viewport_pixel_size_));
}

Expand Down
2 changes: 1 addition & 1 deletion atom/browser/osr/osr_output_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OffScreenOutputDevice : public cc::SoftwareOutputDevice {
SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override;
void EndPaint() override;

void SetActive(bool active);
void SetActive(bool active, bool paint);
void OnPaint(const gfx::Rect& damage_rect);

private:
Expand Down
33 changes: 20 additions & 13 deletions atom/browser/osr/osr_render_widget_host_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class AtomCopyFrameGenerator {
}

void GenerateCopyFrame(const gfx::Rect& damage_rect) {
if (!view_->render_widget_host())
if (!view_->render_widget_host() || !view_->IsPainting())
return;

std::unique_ptr<cc::CopyOutputRequest> request =
Expand Down Expand Up @@ -312,6 +312,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,
Expand All @@ -325,17 +327,18 @@ 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()),
hold_resize_(false),
pending_resize_(false),
paint_callback_running_(false),
weak_ptr_factory_(this) {
DCHECK(render_widget_host_);
bool is_guest_view_hack = parent_host_view_ != nullptr;
Expand All @@ -358,7 +361,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
new ui::Compositor(context_factory_private->AllocateFrameSinkId(),
content::GetContextFactory(), context_factory_private,
base::ThreadTaskRunnerHandle::Get()));
compositor_->SetAcceleratedWidget(native_window_->GetAcceleratedWidget());
compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
compositor_->SetRootLayer(root_layer_.get());
#endif
GetCompositor()->SetDelegate(this);
Expand Down Expand Up @@ -591,7 +594,7 @@ void OffScreenRenderWidgetHostView::OnSwapCompositorFrame(
if (!frame.render_pass_list.empty()) {
if (software_output_device_) {
if (!begin_frame_timer_.get() || IsPopupWidget()) {
software_output_device_->SetActive(painting_);
software_output_device_->SetActive(painting_, false);
}

// The compositor will draw directly to the SoftwareOutputDevice which
Expand Down Expand Up @@ -774,6 +777,8 @@ content::RenderWidgetHostViewBase*

return new OffScreenRenderWidgetHostView(
transparent_,
true,
embedder_host_view->GetFrameRate(),
callback_,
render_widget_host,
embedder_host_view,
Expand Down Expand Up @@ -972,12 +977,12 @@ bool OffScreenRenderWidgetHostView::IsAutoResizeEnabled() const {

void OffScreenRenderWidgetHostView::SetNeedsBeginFrames(
bool needs_begin_frames) {
SetupFrameRate(false);
SetupFrameRate(true);

begin_frame_timer_->SetActive(needs_begin_frames);

if (software_output_device_) {
software_output_device_->SetActive(needs_begin_frames && painting_);
software_output_device_->SetActive(needs_begin_frames && painting_, false);
}
}

Expand Down Expand Up @@ -1046,7 +1051,9 @@ void OffScreenRenderWidgetHostView::OnPaint(
}

damage.Intersect(GetViewBounds());
paint_callback_running_ = true;
callback_.Run(damage, bitmap);
paint_callback_running_ = false;

for (size_t i = 0; i < damages.size(); i++) {
CopyBitmapTo(bitmap, originals[i], damages[i]);
Expand Down Expand Up @@ -1190,7 +1197,7 @@ void OffScreenRenderWidgetHostView::SetPainting(bool painting) {
painting_ = painting;

if (software_output_device_) {
software_output_device_->SetActive(painting_);
software_output_device_->SetActive(painting_, !paint_callback_running_);
}
}

Expand All @@ -1207,16 +1214,16 @@ void OffScreenRenderWidgetHostView::SetFrameRate(int frame_rate) {
} else {
if (frame_rate <= 0)
frame_rate = 1;
if (frame_rate > 60)
frame_rate = 60;
if (frame_rate > 240)
frame_rate = 240;

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 {
Expand Down Expand Up @@ -1244,7 +1251,7 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {

frame_rate_threshold_us_ = 1000000 / frame_rate_;

GetCompositor()->vsync_manager()->SetAuthoritativeVSyncInterval(
GetCompositor()->SetAuthoritativeVSyncInterval(
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));

if (copy_frame_generator_.get()) {
Expand Down
4 changes: 4 additions & 0 deletions atom/browser/osr/osr_render_widget_host_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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,
Expand Down Expand Up @@ -305,6 +307,8 @@ class OffScreenRenderWidgetHostView
bool hold_resize_;
bool pending_resize_;

bool paint_callback_running_;

std::unique_ptr<ui::Layer> root_layer_;
std::unique_ptr<ui::Compositor> compositor_;
std::unique_ptr<content::DelegatedFrameHost> delegated_frame_host_;
Expand Down
42 changes: 42 additions & 0 deletions atom/browser/osr/osr_web_contents_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -103,6 +105,8 @@ content::RenderWidgetHostViewBase*
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
return new OffScreenRenderWidgetHostView(
transparent_,
painting_,
GetFrameRate(),
callback_,
render_widget_host,
nullptr,
Expand All @@ -125,6 +129,8 @@ content::RenderWidgetHostViewBase*

return new OffScreenRenderWidgetHostView(
transparent_,
true,
view->GetFrameRate(),
callback_,
render_widget_host,
view,
Expand Down Expand Up @@ -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*>(
Expand Down
7 changes: 7 additions & 0 deletions atom/browser/osr/osr_web_contents_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -78,6 +83,8 @@ class OffScreenWebContentsView : public content::WebContentsView,
OffScreenRenderWidgetHostView* GetView() const;

const bool transparent_;
bool painting_;
int frame_rate_;
OnPaintCallback callback_;

// Weak refs.
Expand Down
0