Merge pull request #9857 from alexeykuzmin/add-enable-osr-flag

[WIP] Add enable_osr flag
This commit is contained in:
Kevin Sawicki 2017-06-29 12:30:44 -07:00 committed by GitHub
commit 1c1cf0d1f2
9 changed files with 89 additions and 10 deletions

View file

@ -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<atom::api::WebContents::Type> {
*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<OffScreenRenderWidgetHostView*>(
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<OffScreenRenderWidgetHostView*>(
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<OffScreenRenderWidgetHostView*>(
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<OffScreenRenderWidgetHostView*>(
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<OffScreenRenderWidgetHostView*>(
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<OffScreenRenderWidgetHostView*>(
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)

View file

@ -92,12 +92,14 @@ Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> 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<mate::Dictionary&>(options);
window_options.Set(options::kFrame, false);
}
#endif
// Creates the WebContents used by BrowserWindow.
web_contents = WebContents::Create(isolate, web_preferences);

View file

@ -6,8 +6,10 @@
#include <utility>
#include <vector>
#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<OffScreenRenderWidgetHostView*>(
frame_host_->GetView());
view_->view_proxy_.reset(new OffscreenViewProxy(view_));
osr_rwhv->AddViewProxy(view_->view_proxy_.get());
}
#endif
}
void AutofillPopup::Hide() {

View file

@ -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) {

View file

@ -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<int> selected_line_;
#if defined(ENABLE_OSR)
std::unique_ptr<OffscreenViewProxy> view_proxy_;
#endif
// The registered keypress callback, responsible for switching lines on
// key presses

View file

@ -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': [

9
features.gypi Normal file
View file

@ -0,0 +1,9 @@
{
# If it looks stupid but it works it ain't stupid.
'variables': {
'variables': {
'enable_osr%': 1,
},
'enable_osr%': '<(enable_osr)',
},
}

View file

@ -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
],
},
}

View file

@ -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({