From 795753286b0e627ab7e2be3a218c34dd4fdd208f Mon Sep 17 00:00:00 2001 From: gellert Date: Fri, 5 Aug 2016 12:29:35 +0200 Subject: [PATCH 1/3] moves AcceleratedWidgetMacNSView to NativeWindowMac --- atom/browser/native_window_mac.h | 11 +++++- atom/browser/native_window_mac.mm | 13 +++++++ .../browser/osr/osr_render_widget_host_view.h | 13 ------- .../osr/osr_render_widget_host_view_mac.mm | 38 ++----------------- 4 files changed, 27 insertions(+), 48 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index ab5645cc080b..978a3036801f 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -12,6 +12,7 @@ #include "base/mac/scoped_nsobject.h" #include "atom/browser/native_window.h" +#include "ui/accelerated_widget_mac/accelerated_widget_mac.h" @class AtomNSWindow; @class AtomNSWindowDelegate; @@ -19,7 +20,9 @@ namespace atom { -class NativeWindowMac : public NativeWindow { +class NativeWindowMac + : public NativeWindow, + public ui::AcceleratedWidgetMacNSView { public: NativeWindowMac(brightray::InspectableWebContents* inspectable_web_contents, const mate::Dictionary& options, @@ -90,6 +93,12 @@ class NativeWindowMac : public NativeWindow { void SetVisibleOnAllWorkspaces(bool visible) override; bool IsVisibleOnAllWorkspaces() override; + // ui::AcceleratedWidgetMacNSView: + NSView* AcceleratedWidgetGetNSView() const override; + void AcceleratedWidgetGetVSyncParameters( + base::TimeTicks* timebase, base::TimeDelta* interval) const override; + void AcceleratedWidgetSwapCompleted() override; + // Refresh the DraggableRegion views. void UpdateDraggableRegionViews() { UpdateDraggableRegionViews(draggable_regions_); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 97f24efcaace..a49701185003 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1197,6 +1197,19 @@ void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) { SetMaximizable(was_maximizable); } +NSView* atom::NativeWindowMac::AcceleratedWidgetGetNSView() const { + return [window_ contentView]; +} + +void atom::NativeWindowMac::AcceleratedWidgetGetVSyncParameters( + base::TimeTicks* timebase, base::TimeDelta* interval) const { + *timebase = base::TimeTicks(); + *interval = base::TimeDelta(); +} + +void atom::NativeWindowMac::AcceleratedWidgetSwapCompleted() { +} + // static NativeWindow* NativeWindow::Create( brightray::InspectableWebContents* inspectable_web_contents, diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index 74da984363ab..bb7b01ed3a21 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -56,9 +56,6 @@ class AtomBeginFrameTimer; class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase, -#if defined(OS_MACOSX) - public ui::AcceleratedWidgetMacNSView, -#endif public ui::CompositorDelegate, public content::DelegatedFrameHostClient { public: @@ -173,14 +170,6 @@ class OffScreenRenderWidgetHostView bool IsAutoResizeEnabled() const; void OnSetNeedsBeginFrames(bool enabled); -#if defined(OS_MACOSX) - // ui::AcceleratedWidgetMacNSView: - NSView* AcceleratedWidgetGetNSView() const override; - void AcceleratedWidgetGetVSyncParameters( - base::TimeTicks* timebase, base::TimeDelta* interval) const override; - void AcceleratedWidgetSwapCompleted() override; -#endif // defined(OS_MACOSX) - void OnBeginFrameTimerTick(); void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period); @@ -233,8 +222,6 @@ class OffScreenRenderWidgetHostView std::unique_ptr begin_frame_timer_; #if defined(OS_MACOSX) - NSWindow* window_; - CALayer* background_layer_; std::unique_ptr browser_compositor_; // Selected text on the renderer. diff --git a/atom/browser/osr/osr_render_widget_host_view_mac.mm b/atom/browser/osr/osr_render_widget_host_view_mac.mm index 511012f5db23..8af2ce6168d5 100644 --- a/atom/browser/osr/osr_render_widget_host_view_mac.mm +++ b/atom/browser/osr/osr_render_widget_host_view_mac.mm @@ -6,8 +6,9 @@ #import +#include "atom/browser/native_window_mac.h" + #include "base/strings/utf_string_conversions.h" -#include "ui/accelerated_widget_mac/accelerated_widget_mac.h" ui::AcceleratedWidgetMac* atom::OffScreenRenderWidgetHostView::GetAcceleratedWidgetMac() const { @@ -16,20 +17,6 @@ atom::OffScreenRenderWidgetHostView::GetAcceleratedWidgetMac() const { return nullptr; } -NSView* atom::OffScreenRenderWidgetHostView::AcceleratedWidgetGetNSView() - const { - return [window_ contentView]; -} - -void atom::OffScreenRenderWidgetHostView::AcceleratedWidgetGetVSyncParameters( - base::TimeTicks* timebase, base::TimeDelta* interval) const { - *timebase = base::TimeTicks(); - *interval = base::TimeDelta(); -} - -void atom::OffScreenRenderWidgetHostView::AcceleratedWidgetSwapCompleted() { -} - void atom::OffScreenRenderWidgetHostView::SetActive(bool active) { } @@ -72,22 +59,12 @@ void atom::OffScreenRenderWidgetHostView::SelectionChanged( } void atom::OffScreenRenderWidgetHostView::CreatePlatformWidget() { - window_ = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1) - styleMask:NSBorderlessWindowMask - backing:NSBackingStoreBuffered - defer:NO]; - - background_layer_ = [[[CALayer alloc] init] retain]; - [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorClear)]; - NSView* content_view = [window_ contentView]; - [content_view setLayer:background_layer_]; - [content_view setWantsLayer:YES]; - browser_compositor_ = content::BrowserCompositorMac::Create(); compositor_.reset(browser_compositor_->compositor()); compositor_->SetRootLayer(root_layer_.get()); - browser_compositor_->accelerated_widget_mac()->SetNSView(this); + browser_compositor_->accelerated_widget_mac()->SetNSView( + static_cast(native_window_)); browser_compositor_->compositor()->SetVisible(true); compositor_->SetLocksWillTimeOut(true); @@ -95,16 +72,9 @@ void atom::OffScreenRenderWidgetHostView::CreatePlatformWidget() { } void atom::OffScreenRenderWidgetHostView::DestroyPlatformWidget() { - DCHECK(window_); - ui::Compositor* compositor = compositor_.release(); ALLOW_UNUSED_LOCAL(compositor); - [window_ close]; - window_ = nil; - [background_layer_ release]; - background_layer_ = nil; - browser_compositor_->accelerated_widget_mac()->ResetNSView(); browser_compositor_->compositor()->SetVisible(false); browser_compositor_->compositor()->SetScaleAndSize(1.0, gfx::Size(0, 0)); From f29dc3402ba444893af8d5a39895f97c5727caca Mon Sep 17 00:00:00 2001 From: gellert Date: Fri, 5 Aug 2016 14:13:34 +0200 Subject: [PATCH 2/3] reverts AcceleratedWidgetMacNSView into offscreen class --- atom/browser/native_window_mac.h | 11 +---------- atom/browser/native_window_mac.mm | 13 ------------- atom/browser/osr/osr_render_widget_host_view.h | 13 +++++++++++++ .../osr/osr_render_widget_host_view_mac.mm | 18 ++++++++++++++---- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 978a3036801f..ab5645cc080b 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -12,7 +12,6 @@ #include "base/mac/scoped_nsobject.h" #include "atom/browser/native_window.h" -#include "ui/accelerated_widget_mac/accelerated_widget_mac.h" @class AtomNSWindow; @class AtomNSWindowDelegate; @@ -20,9 +19,7 @@ namespace atom { -class NativeWindowMac - : public NativeWindow, - public ui::AcceleratedWidgetMacNSView { +class NativeWindowMac : public NativeWindow { public: NativeWindowMac(brightray::InspectableWebContents* inspectable_web_contents, const mate::Dictionary& options, @@ -93,12 +90,6 @@ class NativeWindowMac void SetVisibleOnAllWorkspaces(bool visible) override; bool IsVisibleOnAllWorkspaces() override; - // ui::AcceleratedWidgetMacNSView: - NSView* AcceleratedWidgetGetNSView() const override; - void AcceleratedWidgetGetVSyncParameters( - base::TimeTicks* timebase, base::TimeDelta* interval) const override; - void AcceleratedWidgetSwapCompleted() override; - // Refresh the DraggableRegion views. void UpdateDraggableRegionViews() { UpdateDraggableRegionViews(draggable_regions_); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index a49701185003..97f24efcaace 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1197,19 +1197,6 @@ void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) { SetMaximizable(was_maximizable); } -NSView* atom::NativeWindowMac::AcceleratedWidgetGetNSView() const { - return [window_ contentView]; -} - -void atom::NativeWindowMac::AcceleratedWidgetGetVSyncParameters( - base::TimeTicks* timebase, base::TimeDelta* interval) const { - *timebase = base::TimeTicks(); - *interval = base::TimeDelta(); -} - -void atom::NativeWindowMac::AcceleratedWidgetSwapCompleted() { -} - // static NativeWindow* NativeWindow::Create( brightray::InspectableWebContents* inspectable_web_contents, diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index bb7b01ed3a21..4bd652a0867b 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -56,6 +56,9 @@ class AtomBeginFrameTimer; class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase, +#if defined(OS_MACOSX) + public ui::AcceleratedWidgetMacNSView, +#endif public ui::CompositorDelegate, public content::DelegatedFrameHostClient { public: @@ -170,6 +173,14 @@ class OffScreenRenderWidgetHostView bool IsAutoResizeEnabled() const; void OnSetNeedsBeginFrames(bool enabled); +#if defined(OS_MACOSX) + // ui::AcceleratedWidgetMacNSView: + NSView* AcceleratedWidgetGetNSView() const override; + void AcceleratedWidgetGetVSyncParameters( + base::TimeTicks* timebase, base::TimeDelta* interval) const override; + void AcceleratedWidgetSwapCompleted() override; +#endif // defined(OS_MACOSX) + void OnBeginFrameTimerTick(); void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period); @@ -222,6 +233,8 @@ class OffScreenRenderWidgetHostView std::unique_ptr begin_frame_timer_; #if defined(OS_MACOSX) + NSWindow* window_; + CALayer* background_layer_; std::unique_ptr browser_compositor_; // Selected text on the renderer. diff --git a/atom/browser/osr/osr_render_widget_host_view_mac.mm b/atom/browser/osr/osr_render_widget_host_view_mac.mm index 8af2ce6168d5..83869f2541b7 100644 --- a/atom/browser/osr/osr_render_widget_host_view_mac.mm +++ b/atom/browser/osr/osr_render_widget_host_view_mac.mm @@ -6,8 +6,6 @@ #import -#include "atom/browser/native_window_mac.h" - #include "base/strings/utf_string_conversions.h" ui::AcceleratedWidgetMac* @@ -17,6 +15,19 @@ atom::OffScreenRenderWidgetHostView::GetAcceleratedWidgetMac() const { return nullptr; } +NSView* atom::OffScreenRenderWidgetHostView::AcceleratedWidgetGetNSView() const { + return [native_window_->GetNativeWindow() contentView]; +} + +void atom::OffScreenRenderWidgetHostView::AcceleratedWidgetGetVSyncParameters( + base::TimeTicks* timebase, base::TimeDelta* interval) const { + *timebase = base::TimeTicks(); + *interval = base::TimeDelta(); +} + +void atom::OffScreenRenderWidgetHostView::AcceleratedWidgetSwapCompleted() { +} + void atom::OffScreenRenderWidgetHostView::SetActive(bool active) { } @@ -63,8 +74,7 @@ void atom::OffScreenRenderWidgetHostView::CreatePlatformWidget() { compositor_.reset(browser_compositor_->compositor()); compositor_->SetRootLayer(root_layer_.get()); - browser_compositor_->accelerated_widget_mac()->SetNSView( - static_cast(native_window_)); + browser_compositor_->accelerated_widget_mac()->SetNSView(this); browser_compositor_->compositor()->SetVisible(true); compositor_->SetLocksWillTimeOut(true); From 541116ff2440b64c50d125bea3c25c7c12c304d2 Mon Sep 17 00:00:00 2001 From: gellert Date: Sat, 6 Aug 2016 00:00:32 +0200 Subject: [PATCH 3/3] removes recycling of compositors on mac --- atom/browser/osr/osr_render_widget_host_view_mac.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/atom/browser/osr/osr_render_widget_host_view_mac.mm b/atom/browser/osr/osr_render_widget_host_view_mac.mm index 83869f2541b7..06650b7bbb24 100644 --- a/atom/browser/osr/osr_render_widget_host_view_mac.mm +++ b/atom/browser/osr/osr_render_widget_host_view_mac.mm @@ -89,5 +89,4 @@ void atom::OffScreenRenderWidgetHostView::DestroyPlatformWidget() { browser_compositor_->compositor()->SetVisible(false); browser_compositor_->compositor()->SetScaleAndSize(1.0, gfx::Size(0, 0)); browser_compositor_->compositor()->SetRootLayer(NULL); - content::BrowserCompositorMac::Recycle(std::move(browser_compositor_)); }