diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 710179015d0b..f27c37ab8919 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -18,9 +18,11 @@ #include "atom/browser/lib/bluetooth_chooser.h" #include "atom/browser/native_window.h" #include "atom/browser/net/atom_network_delegate.h" +#if defined(ENABLE_OSR) #include "atom/browser/osr/osr_output_device.h" #include "atom/browser/osr/osr_render_widget_host_view.h" #include "atom/browser/osr/osr_web_contents_view.h" +#endif #include "atom/browser/ui/drag_util.h" #include "atom/browser/web_contents_permission_helper.h" #include "atom/browser/web_contents_preferences.h" @@ -228,8 +230,10 @@ struct Converter { *out = Type::BROWSER_VIEW; } else if (type == "webview") { *out = Type::WEB_VIEW; +#if defined(ENABLE_OSR) } else if (type == "offscreen") { *out = Type::OFF_SCREEN; +#endif } else { return false; } @@ -314,8 +318,10 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) type_ = BACKGROUND_PAGE; else if (options.Get("isBrowserView", &b) && b) type_ = BROWSER_VIEW; +#if defined(ENABLE_OSR) else if (options.Get("offscreen", &b) && b) type_ = OFF_SCREEN; +#endif // Init embedder earlier options.Get("embedder", &embedder_); @@ -345,6 +351,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) guest_delegate_.reset(new WebViewGuestDelegate); params.guest_delegate = guest_delegate_.get(); +#if defined(ENABLE_OSR) if (embedder_ && embedder_->IsOffScreen()) { auto* view = new OffScreenWebContentsView(false, base::Bind(&WebContents::OnPaint, base::Unretained(this))); @@ -354,7 +361,9 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) web_contents = content::WebContents::Create(params); view->SetWebContents(web_contents); } else { +#endif web_contents = content::WebContents::Create(params); +#if defined(ENABLE_OSR) } } else if (IsOffScreen()) { bool transparent = false; @@ -368,6 +377,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) web_contents = content::WebContents::Create(params); view->SetWebContents(web_contents); +#endif } else { content::WebContents::CreateParams params(session->browser_context()); web_contents = content::WebContents::Create(params); @@ -1563,7 +1573,11 @@ bool WebContents::IsGuest() const { } bool WebContents::IsOffScreen() const { +#if defined(ENABLE_OSR) return type_ == OFF_SCREEN; +#else + return false; +#endif } bool WebContents::IsOffScreenOrEmbedderOffscreen() const { @@ -1578,56 +1592,72 @@ void WebContents::StartPainting() { if (!IsOffScreen()) return; +#if defined(ENABLE_OSR) auto* osr_rwhv = static_cast( web_contents()->GetRenderWidgetHostView()); if (osr_rwhv) osr_rwhv->SetPainting(true); +#endif } void WebContents::StopPainting() { if (!IsOffScreen()) return; +#if defined(ENABLE_OSR) auto* osr_rwhv = static_cast( web_contents()->GetRenderWidgetHostView()); if (osr_rwhv) osr_rwhv->SetPainting(false); +#endif } bool WebContents::IsPainting() const { if (!IsOffScreen()) return false; +#if defined(ENABLE_OSR) const auto* osr_rwhv = static_cast( web_contents()->GetRenderWidgetHostView()); return osr_rwhv && osr_rwhv->IsPainting(); +#else + return false; +#endif } void WebContents::SetFrameRate(int frame_rate) { if (!IsOffScreen()) return; +#if defined(ENABLE_OSR) auto* osr_rwhv = static_cast( web_contents()->GetRenderWidgetHostView()); if (osr_rwhv) osr_rwhv->SetFrameRate(frame_rate); +#endif } int WebContents::GetFrameRate() const { if (!IsOffScreen()) return 0; +#if defined(ENABLE_OSR) const auto* osr_rwhv = static_cast( web_contents()->GetRenderWidgetHostView()); return osr_rwhv ? osr_rwhv->GetFrameRate() : 0; +#else + return 0; +#endif } void WebContents::Invalidate() { if (IsOffScreen()) { +#if defined(ENABLE_OSR) auto* osr_rwhv = static_cast( web_contents()->GetRenderWidgetHostView()); if (osr_rwhv) osr_rwhv->Invalidate(); +#endif } else { const auto window = owner_window(); if (window) @@ -1799,7 +1829,9 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("startDrag", &WebContents::StartDrag) .SetMethod("setSize", &WebContents::SetSize) .SetMethod("isGuest", &WebContents::IsGuest) +#if defined(ENABLE_OSR) .SetMethod("isOffscreen", &WebContents::IsOffScreen) +#endif .SetMethod("startPainting", &WebContents::StartPainting) .SetMethod("stopPainting", &WebContents::StopPainting) .SetMethod("isPainting", &WebContents::IsPainting) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index e566681b6fef..f48026ea9374 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -92,12 +92,14 @@ Window::Window(v8::Isolate* isolate, v8::Local wrapper, if (options.Get("transparent", &transparent)) web_preferences.Set("transparent", transparent); +#if defined(ENABLE_OSR) // Offscreen windows are always created frameless. bool offscreen; if (web_preferences.Get("offscreen", &offscreen) && offscreen) { auto window_options = const_cast(options); window_options.Set(options::kFrame, false); } +#endif // Creates the WebContents used by BrowserWindow. web_contents = WebContents::Create(isolate, web_preferences); diff --git a/atom/browser/ui/autofill_popup.cc b/atom/browser/ui/autofill_popup.cc index f58c0cf884a8..e38fdb523e84 100644 --- a/atom/browser/ui/autofill_popup.cc +++ b/atom/browser/ui/autofill_popup.cc @@ -6,8 +6,10 @@ #include #include +#if defined(ENABLE_OSR) #include "atom/browser/osr/osr_render_widget_host_view.h" #include "atom/browser/osr/osr_view_proxy.h" +#endif #include "atom/browser/ui/autofill_popup.h" #include "atom/common/api/api_messages.h" #include "ui/display/display.h" @@ -132,12 +134,14 @@ void AutofillPopup::CreateView( view_ = new AutofillPopupView(this, parent_widget); view_->Show(); +#if defined(ENABLE_OSR) if (offscreen) { auto* osr_rwhv = static_cast( frame_host_->GetView()); view_->view_proxy_.reset(new OffscreenViewProxy(view_)); osr_rwhv->AddViewProxy(view_->view_proxy_.get()); } +#endif } void AutofillPopup::Hide() { diff --git a/atom/browser/ui/views/autofill_popup_view.cc b/atom/browser/ui/views/autofill_popup_view.cc index e4999b30263f..5c333b2f57da 100644 --- a/atom/browser/ui/views/autofill_popup_view.cc +++ b/atom/browser/ui/views/autofill_popup_view.cc @@ -22,7 +22,9 @@ AutofillPopupView::AutofillPopupView( views::Widget* parent_widget) : popup_(popup), parent_widget_(parent_widget), +#if defined(ENABLE_OSR) view_proxy_(nullptr), +#endif weak_ptr_factory_(this) { CreateChildViews(); SetFocusBehavior(FocusBehavior::ALWAYS); @@ -39,9 +41,11 @@ AutofillPopupView::~AutofillPopupView() { RemoveObserver(); +#if defined(ENABLE_OSR) if (view_proxy_.get()) { view_proxy_->ResetView(); } +#endif if (GetWidget()) { GetWidget()->Close(); @@ -220,12 +224,14 @@ void AutofillPopupView::OnPaint(gfx::Canvas* canvas) { gfx::Canvas* draw_canvas = canvas; SkBitmap bitmap; +#if defined(ENABLE_OSR) if (view_proxy_.get()) { bitmap.allocN32Pixels(popup_->popup_bounds_in_view_.width(), popup_->popup_bounds_in_view_.height(), true); draw_canvas = new gfx::Canvas(new SkCanvas(bitmap), 1.0); } +#endif draw_canvas->DrawColor(GetNativeTheme()->GetSystemColor( ui::NativeTheme::kColorId_ResultsTableNormalBackground)); @@ -237,10 +243,12 @@ void AutofillPopupView::OnPaint(gfx::Canvas* canvas) { DrawAutofillEntry(draw_canvas, i, line_rect); } +#if defined(ENABLE_OSR) if (view_proxy_.get()) { view_proxy_->SetBounds(popup_->popup_bounds_in_view_); view_proxy_->SetBitmap(bitmap); } +#endif } void AutofillPopupView::GetAccessibleNodeData(ui::AXNodeData* node_data) { diff --git a/atom/browser/ui/views/autofill_popup_view.h b/atom/browser/ui/views/autofill_popup_view.h index 75d93184b06f..234b6e57d0e6 100644 --- a/atom/browser/ui/views/autofill_popup_view.h +++ b/atom/browser/ui/views/autofill_popup_view.h @@ -7,7 +7,9 @@ #include "atom/browser/ui/autofill_popup.h" +#if defined(ENABLE_OSR) #include "atom/browser/osr/osr_view_proxy.h" +#endif #include "base/optional.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/render_widget_host.h" @@ -138,7 +140,9 @@ class AutofillPopupView : public views::WidgetDelegateView, // The index of the currently selected line base::Optional selected_line_; +#if defined(ENABLE_OSR) std::unique_ptr view_proxy_; +#endif // The registered keypress callback, responsible for switching lines on // key presses diff --git a/electron.gyp b/electron.gyp index e290b535bcda..d0922e0ea0c6 100644 --- a/electron.gyp +++ b/electron.gyp @@ -8,6 +8,7 @@ 'js2c_input_dir': '<(SHARED_INTERMEDIATE_DIR)/js2c', }, 'includes': [ + 'features.gypi', 'filenames.gypi', 'vendor/native_mate/native_mate_files.gypi', ], @@ -22,6 +23,11 @@ '<(source_root)/external_binaries', ], }], + ['enable_osr==1', { + 'defines': [ + 'ENABLE_OSR', + ], + }], # enable_osr==1 ], }, 'targets': [ diff --git a/features.gypi b/features.gypi new file mode 100644 index 000000000000..f528452d48b7 --- /dev/null +++ b/features.gypi @@ -0,0 +1,9 @@ +{ + # If it looks stupid but it works it ain't stupid. + 'variables': { + 'variables': { + 'enable_osr%': 1, + }, + 'enable_osr%': '<(enable_osr)', + }, +} diff --git a/filenames.gypi b/filenames.gypi index bc72ebfee6e5..e90fe322ba15 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -240,16 +240,6 @@ 'atom/browser/native_window_mac.h', 'atom/browser/native_window_mac.mm', 'atom/browser/native_window_observer.h', - 'atom/browser/osr/osr_web_contents_view_mac.mm', - 'atom/browser/osr/osr_web_contents_view.cc', - 'atom/browser/osr/osr_web_contents_view.h', - 'atom/browser/osr/osr_output_device.cc', - 'atom/browser/osr/osr_output_device.h', - 'atom/browser/osr/osr_render_widget_host_view.cc', - 'atom/browser/osr/osr_render_widget_host_view.h', - 'atom/browser/osr/osr_render_widget_host_view_mac.mm', - 'atom/browser/osr/osr_view_proxy.cc', - 'atom/browser/osr/osr_view_proxy.h', 'atom/browser/net/about_protocol_handler.cc', 'atom/browser/net/about_protocol_handler.h', 'atom/browser/net/asar/asar_protocol_handler.cc', @@ -706,6 +696,20 @@ '<(libchromiumcontent_src_dir)/ui/resources/cursors/zoom_out.cur', ], }], # OS=="win" + ['enable_osr==1', { + 'lib_sources': [ + 'atom/browser/osr/osr_web_contents_view_mac.mm', + 'atom/browser/osr/osr_web_contents_view.cc', + 'atom/browser/osr/osr_web_contents_view.h', + 'atom/browser/osr/osr_output_device.cc', + 'atom/browser/osr/osr_output_device.h', + 'atom/browser/osr/osr_render_widget_host_view.cc', + 'atom/browser/osr/osr_render_widget_host_view.h', + 'atom/browser/osr/osr_render_widget_host_view_mac.mm', + 'atom/browser/osr/osr_view_proxy.cc', + 'atom/browser/osr/osr_view_proxy.h', + ], + }], # enable_osr==1 ], }, } diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index dad348599428..fba606f3a570 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -2555,6 +2555,16 @@ describe('BrowserWindow module', function () { }) describe('offscreen rendering', function () { + const isOffscreenRenderingDisabled = () => { + const contents = webContents.create({}) + const disabled = typeof contents.isOffscreen !== 'function' + contents.destroy() + return disabled + } + + // Offscreen rendering can be disabled in the build + if (isOffscreenRenderingDisabled()) return + beforeEach(function () { if (w != null) w.destroy() w = new BrowserWindow({