Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offscreen rendering enhancements #8839

Merged
merged 24 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
20d2ab2
Add support for child and popup windows in OSR
brenca Mar 4, 2017
c9fa71b
lint fix
brenca Mar 5, 2017
8f54631
add popup window bounds to damage_rect
brenca Mar 5, 2017
bccc251
fix mouse wheel event sending typo
brenca Mar 5, 2017
062b1ed
moves createviewfordwidget method to osrrwhv
gerhardberger Mar 14, 2017
ff053bb
call InvalidateBounds when popup updates
brenca Apr 8, 2017
6b33564
adds ipc send to disable external popups on macos
gerhardberger Apr 9, 2017
155fef9
adds offscreen renderer ipc message to disable external popups
gerhardberger Apr 11, 2017
2f32311
fix black bars around popups and scaled images when using gpu rendering
brenca Apr 12, 2017
704fde1
port CEF pr that speeds up and simplifies GPU rendering
brenca Apr 12, 2017
89277dd
fix leaking of NativeImage instances
brenca Apr 12, 2017
1fcf6ea
add size hints to NativeImages to make node GC aware of the high amou…
brenca Apr 12, 2017
c54f7f2
use bounds instead of bounds_in_pixel
brenca Apr 12, 2017
3b94d26
lint fix :memo:
brenca Apr 12, 2017
f03dcca
use white gutter color and paint damage rects over when paint starts …
brenca Apr 12, 2017
aa89bc0
use outer webcontents for popups
gerhardberger Apr 14, 2017
92cc674
resolve errors introduced during rebase
brenca May 2, 2017
576b702
update native_mate and use the MarkHighMemoryUsage API to speed up ga…
brenca May 2, 2017
5c690ea
don't store isolate_ in NativeImage and tune size hints
brenca May 2, 2017
8d1c17e
remove GetSizeForNewRenderView
brenca May 2, 2017
6f80379
use computeSize64 instead of getSize
brenca May 2, 2017
b1095fa
minor fix for macos
gerhardberger May 2, 2017
a76a4dd
:art: lint fix
brenca May 10, 2017
bf58373
fix NativeImage size hint crashing when image is created from path
brenca May 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "content/browser/frame_host/navigation_entry_impl.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_impl.h"
#include "content/common/view_messages.h"
#include "content/public/browser/favicon_status.h"
Expand Down Expand Up @@ -315,6 +316,9 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
else if (options.Get("offscreen", &b) && b)
type_ = OFF_SCREEN;

// Init embedder earlier
options.Get("embedder", &embedder_);

// Whether to enable DevTools.
options.Get("devTools", &enable_devtools_);

Expand All @@ -339,7 +343,18 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
session->browser_context(), site_instance);
guest_delegate_.reset(new WebViewGuestDelegate);
params.guest_delegate = guest_delegate_.get();
web_contents = content::WebContents::Create(params);

if (embedder_ && embedder_->IsOffScreen()) {
auto* view = new OffScreenWebContentsView(false,
base::Bind(&WebContents::OnPaint, base::Unretained(this)));
params.view = view;
params.delegate_view = view;

web_contents = content::WebContents::Create(params);
view->SetWebContents(web_contents);
} else {
web_contents = content::WebContents::Create(params);
}
} else if (IsOffScreen()) {
bool transparent = false;
options.Get("transparent", &transparent);
Expand Down Expand Up @@ -389,7 +404,7 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
guest_delegate_->Initialize(this);

NativeWindow* owner_window = nullptr;
if (options.Get("embedder", &embedder_) && embedder_) {
if (embedder_) {
// New WebContents's owner_window is the embedder's owner_window.
auto relay =
NativeWindowRelay::FromWebContents(embedder_->web_contents());
Expand Down Expand Up @@ -1402,18 +1417,16 @@ bool WebContents::SendIPCMessage(bool all_frames,

void WebContents::SendInputEvent(v8::Isolate* isolate,
v8::Local<v8::Value> input_event) {
const auto view = web_contents()->GetRenderWidgetHostView();
const auto view = static_cast<content::RenderWidgetHostViewBase*>(
web_contents()->GetRenderWidgetHostView());
if (!view)
return;
const auto host = view->GetRenderWidgetHost();
if (!host)
return;

int type = mate::GetWebInputEventType(isolate, input_event);
if (blink::WebInputEvent::isMouseEventType(type)) {
blink::WebMouseEvent mouse_event;
if (mate::ConvertFromV8(isolate, input_event, &mouse_event)) {
host->ForwardMouseEvent(mouse_event);
view->ProcessMouseEvent(mouse_event, ui::LatencyInfo());
return;
}
} else if (blink::WebInputEvent::isKeyboardEventType(type)) {
Expand All @@ -1422,13 +1435,13 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
blink::WebInputEvent::NoModifiers,
ui::EventTimeForNow());
if (mate::ConvertFromV8(isolate, input_event, &keyboard_event)) {
host->ForwardKeyboardEvent(keyboard_event);
view->ProcessKeyboardEvent(keyboard_event);
return;
}
} else if (type == blink::WebInputEvent::MouseWheel) {
blink::WebMouseWheelEvent mouse_wheel_event;
if (mate::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) {
host->ForwardWheelEvent(mouse_wheel_event);
view->ProcessMouseWheelEvent(mouse_wheel_event, ui::LatencyInfo());
return;
}
}
Expand Down Expand Up @@ -1565,9 +1578,7 @@ bool WebContents::IsOffScreen() const {
}

void WebContents::OnPaint(const gfx::Rect& dirty_rect, const SkBitmap& bitmap) {
mate::Handle<NativeImage> image =
NativeImage::Create(isolate(), gfx::Image::CreateFrom1xBitmap(bitmap));
Emit("paint", dirty_rect, image);
Emit("paint", dirty_rect, gfx::Image::CreateFrom1xBitmap(bitmap));
}

void WebContents::StartPainting() {
Expand Down
1 change: 1 addition & 0 deletions atom/browser/native_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class NativeWindow : public base::SupportsUserData,
virtual void SetMenu(AtomMenuModel* menu);
virtual void SetParentWindow(NativeWindow* parent);
virtual void SetBrowserView(NativeBrowserView* browser_view) = 0;
virtual gfx::NativeView GetNativeView() = 0;
virtual gfx::NativeWindow GetNativeWindow() = 0;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;

Expand Down
1 change: 1 addition & 0 deletions atom/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class NativeWindowMac : public NativeWindow,
void SetContentProtection(bool enable) override;
void SetBrowserView(NativeBrowserView* browser_view) override;
void SetParentWindow(NativeWindow* parent) override;
gfx::NativeView GetNativeView() override;
gfx::NativeWindow GetNativeWindow() override;
gfx::AcceleratedWidget GetAcceleratedWidget() override;
void SetProgressBar(double progress, const ProgressState state) override;
Expand Down
4 changes: 4 additions & 0 deletions atom/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,10 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
[parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove];
}

gfx::NativeView NativeWindowMac::GetNativeView() {
return inspectable_web_contents()->GetView()->GetNativeView();
}

gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
return window_;
}
Expand Down
4 changes: 4 additions & 0 deletions atom/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,10 @@ void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
#endif
}

gfx::NativeView NativeWindowViews::GetNativeView() {
return window_->GetNativeView();
}

gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
return window_->GetNativeWindow();
}
Expand Down
1 change: 1 addition & 0 deletions atom/browser/native_window_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class NativeWindowViews : public NativeWindow,
void SetMenu(AtomMenuModel* menu_model) override;
void SetBrowserView(NativeBrowserView* browser_view) override;
void SetParentWindow(NativeWindow* parent) override;
gfx::NativeView GetNativeView() override;
gfx::NativeWindow GetNativeWindow() override;
void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) override;
Expand Down
20 changes: 18 additions & 2 deletions atom/browser/osr/osr_output_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "atom/browser/osr/osr_output_device.h"

#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/src/core/SkDevice.h"
#include "ui/gfx/skia_util.h"

Expand Down Expand Up @@ -36,8 +38,11 @@ void OffScreenOutputDevice::Resize(
return;
}

if (transparent_)
bitmap_->eraseARGB(0, 0, 0, 0);
if (transparent_) {
bitmap_->eraseColor(SK_ColorTRANSPARENT);
} else {
bitmap_->eraseColor(SK_ColorWHITE);
}

canvas_.reset(new SkCanvas(*bitmap_));
}
Expand All @@ -47,6 +52,17 @@ SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) {
DCHECK(bitmap_.get());

damage_rect_ = damage_rect;
SkIRect damage = SkIRect::MakeXYWH(
damage_rect_.x(),
damage_rect_.y(),
damage_rect_.width(),
damage_rect_.height());

if (transparent_) {
bitmap_->erase(SK_ColorTRANSPARENT, damage);
} else {
bitmap_->erase(SK_ColorWHITE, damage);
}

return canvas_.get();
}
Expand Down
Loading