Skip to content

Commit

Permalink
fix: enable osr (backport: 3-0-x) (#14219)
Browse files Browse the repository at this point in the history
* fix: re-enable osr

* fix: add changes from CEF to add MouseWheelPhaseHandler

* fix: re-enable surface synchronization by applying fix from cef

* update method call and enable AsyncWheelEvents var

* fix: make BrowserCompositorMacGetGutterColor behave like chromium

* fix: HANDLE only exists on windows

* fix: pass correct params to mouse_wheel_phase_handler_

* fix variable accessing

* revert: revert the workaround for disableHardwareAcceleration crash

* fix: remove GuestViewCrossProcessFrames from the disabled features list

* revert: remove check from BrowserChildProcessLaunchedAndConnected
  • Loading branch information
trop[bot] authored and codebytere committed Aug 20, 2018
1 parent 058c03f commit 5d17e48
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 36 deletions.
99 changes: 76 additions & 23 deletions atom/browser/osr/osr_render_widget_host_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
size_(native_window->GetSize()),
painting_(painting),
is_showing_(!render_widget_host_->is_hidden()),
mouse_wheel_phase_handler_(render_widget_host_, this),
weak_ptr_factory_(this) {
DCHECK(render_widget_host_);
bool is_guest_view_hack = parent_host_view_ != nullptr;
Expand All @@ -279,10 +280,8 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(

local_surface_id_ = local_surface_id_allocator_.GenerateId();

// Surface synchronization is not supported with OSR.
DCHECK(!features::IsSurfaceSynchronizationEnabled());

#if defined(OS_MACOSX)
last_frame_root_background_color_ = SK_ColorTRANSPARENT;
CreatePlatformWidget(is_guest_view_hack);
#else
// On macOS the ui::Compositor is created/owned by the platform view.
Expand All @@ -303,7 +302,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(

native_window_->AddObserver(this);

ResizeRootLayer();
ResizeRootLayer(false);
render_widget_host_->SetView(this);
InstallTransparency();
}
Expand Down Expand Up @@ -385,7 +384,7 @@ void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) {
parent_host_view_->set_child_host_view(this);
parent_host_view_->Hide();

ResizeRootLayer();
ResizeRootLayer(false);
Show();
}

Expand Down Expand Up @@ -514,6 +513,10 @@ void OffScreenRenderWidgetHostView::SubmitCompositorFrame(
TRACE_EVENT0("electron",
"OffScreenRenderWidgetHostView::SubmitCompositorFrame");

#if defined(OS_MACOSX)
last_frame_root_background_color_ = frame.metadata.root_background_color;
#endif

if (frame.metadata.root_scroll_offset != last_scroll_offset_) {
last_scroll_offset_ = frame.metadata.root_scroll_offset;
}
Expand Down Expand Up @@ -579,7 +582,7 @@ void OffScreenRenderWidgetHostView::InitAsPopup(

popup_position_ = pos;

ResizeRootLayer();
ResizeRootLayer(false);
Show();
}

Expand Down Expand Up @@ -743,10 +746,6 @@ OffScreenRenderWidgetHostView::DelegatedFrameHostCreateResizeLock() {
return std::make_unique<content::CompositorResizeLock>(this, desired_size);
}

viz::LocalSurfaceId OffScreenRenderWidgetHostView::GetLocalSurfaceId() const {
return local_surface_id_;
}

void OffScreenRenderWidgetHostView::OnFirstSurfaceActivation(
const viz::SurfaceInfo& surface_info) {}

Expand Down Expand Up @@ -774,8 +773,26 @@ bool OffScreenRenderWidgetHostView::IsAutoResizeEnabled() const {
return render_widget_host_->auto_resize_enabled();
}

viz::LocalSurfaceId OffScreenRenderWidgetHostView::GetLocalSurfaceId() const {
return local_surface_id_;
}

#endif // !defined(OS_MACOSX)

viz::FrameSinkId OffScreenRenderWidgetHostView::GetFrameSinkId() {
return GetDelegatedFrameHost()->frame_sink_id();
}

void OffScreenRenderWidgetHostView::DidNavigate() {
ResizeRootLayer(true);
#if defined(OS_MACOSX)
browser_compositor_->DidNavigate();
#else
if (delegated_frame_host_)
delegated_frame_host_->DidNavigate();
#endif
}

bool OffScreenRenderWidgetHostView::TransformPointToLocalCoordSpace(
const gfx::PointF& point,
const viz::SurfaceId& original_surface,
Expand Down Expand Up @@ -882,7 +899,7 @@ OffScreenRenderWidgetHostView::CreateSoftwareOutputDevice(
DCHECK(!copy_frame_generator_);
DCHECK(!software_output_device_);

ResizeRootLayer();
ResizeRootLayer(false);

software_output_device_ = new OffScreenOutputDevice(
transparent_, base::Bind(&OffScreenRenderWidgetHostView::OnPaint,
Expand Down Expand Up @@ -1034,7 +1051,7 @@ void OffScreenRenderWidgetHostView::WasResized() {
return;
}

ResizeRootLayer();
ResizeRootLayer(false);
if (render_widget_host_)
render_widget_host_->WasResized();
GetDelegatedFrameHost()->WasResized(local_surface_id_, size_,
Expand Down Expand Up @@ -1096,18 +1113,29 @@ void OffScreenRenderWidgetHostView::SendMouseWheelEvent(
return;
}
}

blink::WebMouseWheelEvent mouse_wheel_event(event);

mouse_wheel_phase_handler_.SendWheelEndIfNeeded();
mouse_wheel_phase_handler_.AddPhaseIfNeededAndScheduleEndEvent(
mouse_wheel_event, false);

if (!IsPopupWidget()) {
if (popup_host_view_) {
if (popup_host_view_->popup_position_.Contains(
event.PositionInWidget().x, event.PositionInWidget().y)) {
blink::WebMouseWheelEvent popup_event(event);
popup_event.SetPositionInWidget(
popup_event.PositionInWidget().x -
mouse_wheel_event.PositionInWidget().x,
mouse_wheel_event.PositionInWidget().y)) {
blink::WebMouseWheelEvent popup_mouse_wheel_event(mouse_wheel_event);
popup_mouse_wheel_event.SetPositionInWidget(
mouse_wheel_event.PositionInWidget().x -
popup_host_view_->popup_position_.x(),
popup_event.PositionInWidget().y -
mouse_wheel_event.PositionInWidget().y -
popup_host_view_->popup_position_.y());
popup_host_view_->ProcessMouseWheelEvent(popup_event,
ui::LatencyInfo());
popup_mouse_wheel_event.SetPositionInScreen(
popup_mouse_wheel_event.PositionInWidget().x,
popup_mouse_wheel_event.PositionInWidget().y);

popup_host_view_->SendMouseWheelEvent(popup_mouse_wheel_event);
return;
} else {
// Scrolling outside of the popup widget so destroy it.
Expand All @@ -1118,6 +1146,28 @@ void OffScreenRenderWidgetHostView::SendMouseWheelEvent(
base::BindOnce(&OffScreenRenderWidgetHostView::CancelWidget,
popup_host_view_->weak_ptr_factory_.GetWeakPtr()));
}
} else if (!guest_host_views_.empty()) {
for (auto guest_host_view : guest_host_views_) {
if (!guest_host_view->render_widget_host_ ||
!guest_host_view->render_widget_host_->GetView()) {
continue;
}
const gfx::Rect& guest_bounds =
guest_host_view->render_widget_host_->GetView()->GetViewBounds();
if (guest_bounds.Contains(mouse_wheel_event.PositionInWidget().x,
mouse_wheel_event.PositionInWidget().y)) {
blink::WebMouseWheelEvent guest_mouse_wheel_event(mouse_wheel_event);
guest_mouse_wheel_event.SetPositionInWidget(
mouse_wheel_event.PositionInWidget().x - guest_bounds.x(),
mouse_wheel_event.PositionInWidget().y - guest_bounds.y());
guest_mouse_wheel_event.SetPositionInScreen(
guest_mouse_wheel_event.PositionInWidget().x,
guest_mouse_wheel_event.PositionInWidget().y);

guest_host_view->SendMouseWheelEvent(guest_mouse_wheel_event);
return;
}
}
}
}
if (!render_widget_host_)
Expand Down Expand Up @@ -1183,8 +1233,10 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {

frame_rate_threshold_us_ = 1000000 / frame_rate_;

GetCompositor()->SetAuthoritativeVSyncInterval(
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
if (GetCompositor()) {
GetCompositor()->SetAuthoritativeVSyncInterval(
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
}

if (copy_frame_generator_.get()) {
copy_frame_generator_->set_frame_rate_threshold_us(
Expand Down Expand Up @@ -1213,7 +1265,7 @@ void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) {
}
}

void OffScreenRenderWidgetHostView::ResizeRootLayer() {
void OffScreenRenderWidgetHostView::ResizeRootLayer(bool force) {
SetupFrameRate(false);

const float compositorScaleFactor = GetCompositor()->device_scale_factor();
Expand All @@ -1225,7 +1277,8 @@ void OffScreenRenderWidgetHostView::ResizeRootLayer() {
else
size = popup_position_.size();

if (!scaleFactorDidChange && size == GetRootLayer()->bounds().size())
if (!force && !scaleFactorDidChange &&
size == GetRootLayer()->bounds().size())
return;

const gfx::Size& size_in_pixels =
Expand Down
20 changes: 15 additions & 5 deletions atom/browser/osr/osr_render_widget_host_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "content/browser/frame_host/render_widget_host_view_guest.h"
#include "content/browser/renderer_host/compositor_resize_lock.h"
#include "content/browser/renderer_host/delegated_frame_host.h"
#include "content/browser/renderer_host/input/mouse_wheel_phase_handler.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/web_contents/web_contents_view.h"
Expand Down Expand Up @@ -108,12 +109,12 @@ class OffScreenRenderWidgetHostView
void SetNeedsBeginFrames(bool needs_begin_frames) override;
void SetWantsAnimateOnlyBeginFrames() override;
#if defined(OS_MACOSX)
ui::AcceleratedWidgetMac* GetAcceleratedWidgetMac() const override;
void SetActive(bool active) override;
void ShowDefinitionForSelection() override;
bool SupportsSpeech() const override;
void SpeakSelection() override;
bool IsSpeaking() const override;
bool ShouldContinueToPauseForFrame() override;
void StopSpeaking() override;
#endif // defined(OS_MACOSX)

Expand Down Expand Up @@ -169,7 +170,6 @@ class OffScreenRenderWidgetHostView
bool DelegatedFrameCanCreateResizeLock() const override;
std::unique_ptr<content::CompositorResizeLock>
DelegatedFrameHostCreateResizeLock() override;
viz::LocalSurfaceId GetLocalSurfaceId() const override;
void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override;
void OnBeginFrame(base::TimeTicks frame_time) override;
void OnFrameTokenChanged(uint32_t frame_token) override;
Expand All @@ -181,6 +181,11 @@ class OffScreenRenderWidgetHostView
bool IsAutoResizeEnabled() const override;
#endif // !defined(OS_MACOSX)

viz::LocalSurfaceId GetLocalSurfaceId() const override;
viz::FrameSinkId GetFrameSinkId() override;

void DidNavigate() override;

bool TransformPointToLocalCoordSpace(const gfx::PointF& point,
const viz::SurfaceId& original_surface,
gfx::PointF* transformed_point) override;
Expand All @@ -205,6 +210,9 @@ class OffScreenRenderWidgetHostView
#if defined(OS_MACOSX)
void CreatePlatformWidget(bool is_guest_view_hack);
void DestroyPlatformWidget();
SkColor last_frame_root_background_color() const {
return last_frame_root_background_color_;
}
#endif

void CancelWidget();
Expand Down Expand Up @@ -260,11 +268,9 @@ class OffScreenRenderWidgetHostView
child_host_view_ = child_view;
}

viz::LocalSurfaceId local_surface_id() const { return local_surface_id_; }

private:
void SetupFrameRate(bool force);
void ResizeRootLayer();
void ResizeRootLayer(bool force);

viz::FrameSinkId AllocateFrameSinkId(bool is_guest_view_hack);

Expand Down Expand Up @@ -325,6 +331,8 @@ class OffScreenRenderWidgetHostView
#if defined(OS_MACOSX)
std::unique_ptr<content::BrowserCompositorMac> browser_compositor_;

SkColor last_frame_root_background_color_;

// Can not be managed by smart pointer because its header can not be included
// in the file that has the destructor.
MacHelper* mac_helper_;
Expand All @@ -333,6 +341,8 @@ class OffScreenRenderWidgetHostView
std::string selected_text_;
#endif

content::MouseWheelPhaseHandler mouse_wheel_phase_handler_;

viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink_ =
nullptr;

Expand Down
10 changes: 7 additions & 3 deletions atom/browser/osr/osr_render_widget_host_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ explicit MacHelper(OffScreenRenderWidgetHostView* view) : view_(view) {
virtual ~MacHelper() {}

// content::BrowserCompositorMacClient:
SkColor BrowserCompositorMacGetGutterColor(SkColor color) const override {
SkColor BrowserCompositorMacGetGutterColor() const override {
// When making an element on the page fullscreen the element's background
// may not match the page's, so use black as the gutter color to avoid
// flashes of brighter colors during the transition.
if (view_->render_widget_host()->delegate() &&
view_->render_widget_host()->delegate()->IsFullscreenForCurrentTab()) {
return SK_ColorBLACK;
}
return color;
return view_->last_frame_root_background_color();
}

void BrowserCompositorMacOnBeginFrame() override {}
Expand Down Expand Up @@ -81,7 +81,7 @@ void DestroyCompositorForShutdown() override {}

void OffScreenRenderWidgetHostView::StopSpeaking() {}

bool CefRenderWidgetHostViewOSR::ShouldContinueToPauseForFrame() {
bool OffScreenRenderWidgetHostView::ShouldContinueToPauseForFrame() {
return browser_compositor_->ShouldContinueToPauseForFrame();
}

Expand All @@ -98,6 +98,10 @@ void DestroyCompositorForShutdown() override {}
delete mac_helper_;
}

viz::LocalSurfaceId OffScreenRenderWidgetHostView::GetLocalSurfaceId() const {
return browser_compositor_->GetRendererLocalSurfaceId();
}

ui::Compositor* OffScreenRenderWidgetHostView::GetCompositor() const {
return browser_compositor_->GetCompositor();
}
Expand Down
4 changes: 0 additions & 4 deletions brightray/browser/browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ void BrowserMainParts::InitializeFeatureList() {
cmd_line->GetSwitchValueASCII(switches::kEnableFeatures);
auto disable_features =
cmd_line->GetSwitchValueASCII(switches::kDisableFeatures);

// Disable surface synchronization and async wheel events to make OSR work.
disable_features += ",SurfaceSynchronization,AsyncWheelEvents";

auto feature_list = std::make_unique<base::FeatureList>();
feature_list->InitializeFromCommandLine(enable_features, disable_features);
base::FeatureList::SetInstance(std::move(feature_list));
Expand Down
2 changes: 1 addition & 1 deletion features.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'variables': {
'variables': {
'enable_desktop_capturer%': 1,
'enable_osr%': 0, # FIXME(alexeykuzmin)
'enable_osr%': 1,
'enable_pdf_viewer%': 0, # FIXME(deepak1556)
'enable_run_as_node%': 1,
'enable_view_api%': 0,
Expand Down

0 comments on commit 5d17e48

Please sign in to comment.