Skip to content

Commit da36bdf

Browse files
committed
Add enable_osr build flag
1 parent ab174f5 commit da36bdf

8 files changed

+79
-10
lines changed

atom/browser/api/atom_api_web_contents.cc

+32
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#include "atom/browser/lib/bluetooth_chooser.h"
1919
#include "atom/browser/native_window.h"
2020
#include "atom/browser/net/atom_network_delegate.h"
21+
#if defined(ENABLE_OSR)
2122
#include "atom/browser/osr/osr_output_device.h"
2223
#include "atom/browser/osr/osr_render_widget_host_view.h"
2324
#include "atom/browser/osr/osr_web_contents_view.h"
25+
#endif
2426
#include "atom/browser/ui/drag_util.h"
2527
#include "atom/browser/web_contents_permission_helper.h"
2628
#include "atom/browser/web_contents_preferences.h"
@@ -228,8 +230,10 @@ struct Converter<atom::api::WebContents::Type> {
228230
*out = Type::BROWSER_VIEW;
229231
} else if (type == "webview") {
230232
*out = Type::WEB_VIEW;
233+
#if defined(ENABLE_OSR)
231234
} else if (type == "offscreen") {
232235
*out = Type::OFF_SCREEN;
236+
#endif
233237
} else {
234238
return false;
235239
}
@@ -314,8 +318,10 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
314318
type_ = BACKGROUND_PAGE;
315319
else if (options.Get("isBrowserView", &b) && b)
316320
type_ = BROWSER_VIEW;
321+
#if defined(ENABLE_OSR)
317322
else if (options.Get("offscreen", &b) && b)
318323
type_ = OFF_SCREEN;
324+
#endif
319325

320326
// Init embedder earlier
321327
options.Get("embedder", &embedder_);
@@ -345,6 +351,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
345351
guest_delegate_.reset(new WebViewGuestDelegate);
346352
params.guest_delegate = guest_delegate_.get();
347353

354+
#if defined(ENABLE_OSR)
348355
if (embedder_ && embedder_->IsOffScreen()) {
349356
auto* view = new OffScreenWebContentsView(false,
350357
base::Bind(&WebContents::OnPaint, base::Unretained(this)));
@@ -354,7 +361,9 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
354361
web_contents = content::WebContents::Create(params);
355362
view->SetWebContents(web_contents);
356363
} else {
364+
#endif
357365
web_contents = content::WebContents::Create(params);
366+
#if defined(ENABLE_OSR)
358367
}
359368
} else if (IsOffScreen()) {
360369
bool transparent = false;
@@ -368,6 +377,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
368377

369378
web_contents = content::WebContents::Create(params);
370379
view->SetWebContents(web_contents);
380+
#endif
371381
} else {
372382
content::WebContents::CreateParams params(session->browser_context());
373383
web_contents = content::WebContents::Create(params);
@@ -1558,7 +1568,11 @@ bool WebContents::IsGuest() const {
15581568
}
15591569

15601570
bool WebContents::IsOffScreen() const {
1571+
#if defined(ENABLE_OSR)
15611572
return type_ == OFF_SCREEN;
1573+
#else
1574+
return false;
1575+
#endif
15621576
}
15631577

15641578
bool WebContents::IsOffScreenOrEmbedderOffscreen() const {
@@ -1573,56 +1587,72 @@ void WebContents::StartPainting() {
15731587
if (!IsOffScreen())
15741588
return;
15751589

1590+
#if defined(ENABLE_OSR)
15761591
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
15771592
web_contents()->GetRenderWidgetHostView());
15781593
if (osr_rwhv)
15791594
osr_rwhv->SetPainting(true);
1595+
#endif
15801596
}
15811597

15821598
void WebContents::StopPainting() {
15831599
if (!IsOffScreen())
15841600
return;
15851601

1602+
#if defined(ENABLE_OSR)
15861603
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
15871604
web_contents()->GetRenderWidgetHostView());
15881605
if (osr_rwhv)
15891606
osr_rwhv->SetPainting(false);
1607+
#endif
15901608
}
15911609

15921610
bool WebContents::IsPainting() const {
15931611
if (!IsOffScreen())
15941612
return false;
15951613

1614+
#if defined(ENABLE_OSR)
15961615
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
15971616
web_contents()->GetRenderWidgetHostView());
15981617
return osr_rwhv && osr_rwhv->IsPainting();
1618+
#else
1619+
return false;
1620+
#endif
15991621
}
16001622

16011623
void WebContents::SetFrameRate(int frame_rate) {
16021624
if (!IsOffScreen())
16031625
return;
16041626

1627+
#if defined(ENABLE_OSR)
16051628
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
16061629
web_contents()->GetRenderWidgetHostView());
16071630
if (osr_rwhv)
16081631
osr_rwhv->SetFrameRate(frame_rate);
1632+
#endif
16091633
}
16101634

16111635
int WebContents::GetFrameRate() const {
16121636
if (!IsOffScreen())
16131637
return 0;
16141638

1639+
#if defined(ENABLE_OSR)
16151640
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
16161641
web_contents()->GetRenderWidgetHostView());
16171642
return osr_rwhv ? osr_rwhv->GetFrameRate() : 0;
1643+
#else
1644+
return 0;
1645+
#endif
16181646
}
16191647

16201648
void WebContents::Invalidate() {
16211649
if (IsOffScreen()) {
1650+
#if defined(ENABLE_OSR)
16221651
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
16231652
web_contents()->GetRenderWidgetHostView());
16241653
if (osr_rwhv)
16251654
osr_rwhv->Invalidate();
1655+
#endif
16261656
} else {
16271657
const auto window = owner_window();
16281658
if (window)
@@ -1795,7 +1825,9 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
17951825
.SetMethod("startDrag", &WebContents::StartDrag)
17961826
.SetMethod("setSize", &WebContents::SetSize)
17971827
.SetMethod("isGuest", &WebContents::IsGuest)
1828+
#if defined(ENABLE_OSR)
17981829
.SetMethod("isOffscreen", &WebContents::IsOffScreen)
1830+
#endif
17991831
.SetMethod("startPainting", &WebContents::StartPainting)
18001832
.SetMethod("stopPainting", &WebContents::StopPainting)
18011833
.SetMethod("isPainting", &WebContents::IsPainting)

atom/browser/api/atom_api_window.cc

+2
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
9292
if (options.Get("transparent", &transparent))
9393
web_preferences.Set("transparent", transparent);
9494

95+
#if defined(ENABLE_OSR)
9596
// Offscreen windows are always created frameless.
9697
bool offscreen;
9798
if (web_preferences.Get("offscreen", &offscreen) && offscreen) {
9899
auto window_options = const_cast<mate::Dictionary&>(options);
99100
window_options.Set(options::kFrame, false);
100101
}
102+
#endif
101103

102104
// Creates the WebContents used by BrowserWindow.
103105
web_contents = WebContents::Create(isolate, web_preferences);

atom/browser/ui/autofill_popup.cc

+4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#include <utility>
77
#include <vector>
88

9+
#if defined(ENABLE_OSR)
910
#include "atom/browser/osr/osr_render_widget_host_view.h"
1011
#include "atom/browser/osr/osr_view_proxy.h"
12+
#endif
1113
#include "atom/browser/ui/autofill_popup.h"
1214
#include "atom/common/api/api_messages.h"
1315
#include "ui/display/display.h"
@@ -132,12 +134,14 @@ void AutofillPopup::CreateView(
132134
view_ = new AutofillPopupView(this, parent_widget);
133135
view_->Show();
134136

137+
#if defined(ENABLE_OSR)
135138
if (offscreen) {
136139
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
137140
frame_host_->GetView());
138141
view_->view_proxy_.reset(new OffscreenViewProxy(view_));
139142
osr_rwhv->AddViewProxy(view_->view_proxy_.get());
140143
}
144+
#endif
141145
}
142146

143147
void AutofillPopup::Hide() {

atom/browser/ui/views/autofill_popup_view.cc

+8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ AutofillPopupView::AutofillPopupView(
2222
views::Widget* parent_widget)
2323
: popup_(popup),
2424
parent_widget_(parent_widget),
25+
#if defined(ENABLE_OSR)
2526
view_proxy_(nullptr),
27+
#endif
2628
weak_ptr_factory_(this) {
2729
CreateChildViews();
2830
SetFocusBehavior(FocusBehavior::ALWAYS);
@@ -39,9 +41,11 @@ AutofillPopupView::~AutofillPopupView() {
3941

4042
RemoveObserver();
4143

44+
#if defined(ENABLE_OSR)
4245
if (view_proxy_.get()) {
4346
view_proxy_->ResetView();
4447
}
48+
#endif
4549

4650
if (GetWidget()) {
4751
GetWidget()->Close();
@@ -220,12 +224,14 @@ void AutofillPopupView::OnPaint(gfx::Canvas* canvas) {
220224
gfx::Canvas* draw_canvas = canvas;
221225
SkBitmap bitmap;
222226

227+
#if defined(ENABLE_OSR)
223228
if (view_proxy_.get()) {
224229
bitmap.allocN32Pixels(popup_->popup_bounds_in_view_.width(),
225230
popup_->popup_bounds_in_view_.height(),
226231
true);
227232
draw_canvas = new gfx::Canvas(new SkCanvas(bitmap), 1.0);
228233
}
234+
#endif
229235

230236
draw_canvas->DrawColor(GetNativeTheme()->GetSystemColor(
231237
ui::NativeTheme::kColorId_ResultsTableNormalBackground));
@@ -237,10 +243,12 @@ void AutofillPopupView::OnPaint(gfx::Canvas* canvas) {
237243
DrawAutofillEntry(draw_canvas, i, line_rect);
238244
}
239245

246+
#if defined(ENABLE_OSR)
240247
if (view_proxy_.get()) {
241248
view_proxy_->SetBounds(popup_->popup_bounds_in_view_);
242249
view_proxy_->SetBitmap(bitmap);
243250
}
251+
#endif
244252
}
245253

246254
void AutofillPopupView::GetAccessibleNodeData(ui::AXNodeData* node_data) {

atom/browser/ui/views/autofill_popup_view.h

+4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#include "atom/browser/ui/autofill_popup.h"
99

10+
#if defined(ENABLE_OSR)
1011
#include "atom/browser/osr/osr_view_proxy.h"
12+
#endif
1113
#include "base/optional.h"
1214
#include "content/public/browser/native_web_keyboard_event.h"
1315
#include "content/public/browser/render_widget_host.h"
@@ -138,7 +140,9 @@ class AutofillPopupView : public views::WidgetDelegateView,
138140
// The index of the currently selected line
139141
base::Optional<int> selected_line_;
140142

143+
#if defined(ENABLE_OSR)
141144
std::unique_ptr<OffscreenViewProxy> view_proxy_;
145+
#endif
142146

143147
// The registered keypress callback, responsible for switching lines on
144148
// key presses

electron.gyp

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'js2c_input_dir': '<(SHARED_INTERMEDIATE_DIR)/js2c',
99
},
1010
'includes': [
11+
'features.gypi',
1112
'filenames.gypi',
1213
'vendor/native_mate/native_mate_files.gypi',
1314
],
@@ -22,6 +23,11 @@
2223
'<(source_root)/external_binaries',
2324
],
2425
}],
26+
['enable_osr==1', {
27+
'defines': [
28+
'ENABLE_OSR',
29+
],
30+
}], # enable_osr==1
2531
],
2632
},
2733
'targets': [

features.gypi

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
# If it looks stupid but it works it ain't stupid.
3+
'variables': {
4+
'variables': {
5+
'enable_osr%': 1,
6+
},
7+
'enable_osr%': '<(enable_osr)',
8+
},
9+
}

filenames.gypi

+14-10
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,6 @@
240240
'atom/browser/native_window_mac.h',
241241
'atom/browser/native_window_mac.mm',
242242
'atom/browser/native_window_observer.h',
243-
'atom/browser/osr/osr_web_contents_view_mac.mm',
244-
'atom/browser/osr/osr_web_contents_view.cc',
245-
'atom/browser/osr/osr_web_contents_view.h',
246-
'atom/browser/osr/osr_output_device.cc',
247-
'atom/browser/osr/osr_output_device.h',
248-
'atom/browser/osr/osr_render_widget_host_view.cc',
249-
'atom/browser/osr/osr_render_widget_host_view.h',
250-
'atom/browser/osr/osr_render_widget_host_view_mac.mm',
251-
'atom/browser/osr/osr_view_proxy.cc',
252-
'atom/browser/osr/osr_view_proxy.h',
253243
'atom/browser/net/about_protocol_handler.cc',
254244
'atom/browser/net/about_protocol_handler.h',
255245
'atom/browser/net/asar/asar_protocol_handler.cc',
@@ -706,6 +696,20 @@
706696
'<(libchromiumcontent_src_dir)/ui/resources/cursors/zoom_out.cur',
707697
],
708698
}], # OS=="win"
699+
['enable_osr==1', {
700+
'lib_sources': [
701+
'atom/browser/osr/osr_web_contents_view_mac.mm',
702+
'atom/browser/osr/osr_web_contents_view.cc',
703+
'atom/browser/osr/osr_web_contents_view.h',
704+
'atom/browser/osr/osr_output_device.cc',
705+
'atom/browser/osr/osr_output_device.h',
706+
'atom/browser/osr/osr_render_widget_host_view.cc',
707+
'atom/browser/osr/osr_render_widget_host_view.h',
708+
'atom/browser/osr/osr_render_widget_host_view_mac.mm',
709+
'atom/browser/osr/osr_view_proxy.cc',
710+
'atom/browser/osr/osr_view_proxy.h',
711+
],
712+
}], # enable_osr==1
709713
],
710714
},
711715
}

0 commit comments

Comments
 (0)