Conflicts:
	atom/browser/api/atom_api_window.h
	atom/browser/native_window.cc
This commit is contained in:
Heilig Benedek 2015-08-31 18:46:29 +02:00
commit 3dd3fd9200
5 changed files with 56 additions and 16 deletions

View file

@ -332,6 +332,29 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
kBGRA_8888_SkColorType);
}
void NativeWindow::SetOffscreenRender(bool isOffscreen) {
if (!isOffscreen && !offscreen_) return;
const auto view = web_contents()->GetRenderWidgetHostView();
if (view) {
if (isOffscreen) {
scoped_ptr<content::RenderWidgetHostViewFrameSubscriber> subscriber(
new RenderSubscriber(
view->GetVisibleViewportSize(),
base::Bind(&NativeWindow::OnFrameReceived, base::Unretained(this))
)
);
view->BeginFrameSubscription(subscriber.Pass());
} else {
view->EndFrameSubscription();
}
offscreen_ = isOffscreen;
}
}
void NativeWindow::RequestToClosePage() {
bool prevent_default = false;
FOR_EACH_OBSERVER(NativeWindowObserver,
@ -608,16 +631,7 @@ void NativeWindow::SendMouseWheelEvent(int modifiers, int x, int y, bool precise
}
void NativeWindow::DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) {
const auto view = web_contents()->GetRenderWidgetHostView();
const auto host = view ? view->GetRenderWidgetHost() : nullptr;
if(offscreen_){
scoped_ptr<content::RenderWidgetHostViewFrameSubscriber> subscriber(new RenderSubscriber(
view->GetVisibleViewportSize(), base::Bind(&NativeWindow::OnFrameReceived, base::Unretained(this))
));
view->BeginFrameSubscription(subscriber.Pass());
}
SetOffscreenRender(offscreen_);
}
void NativeWindow::RenderViewCreated(
@ -697,11 +711,12 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
callback.Run(bitmap);
}
void NativeWindow::OnFrameReceived(bool result, scoped_refptr<media::VideoFrame> frame) {
if(result){
void NativeWindow::OnFrameReceived(bool result,
scoped_refptr<media::VideoFrame> frame) {
if (result) {
gfx::Rect rect = frame->visible_rect();
const int rgb_arr_size = rect.width()*rect.height()*4;
const int rgb_arr_size = rect.width() * rect.height() * 4;
scoped_ptr<uint8[]> rgb_bytes(new uint8[rgb_arr_size]);
// Convert a frame of YUV to 32 bit ARGB.
@ -712,7 +727,7 @@ void NativeWindow::OnFrameReceived(bool result, scoped_refptr<media::VideoFrame>
rect.width(), rect.height(),
frame->stride(media::VideoFrame::kYPlane),
frame->stride(media::VideoFrame::kUVPlane),
rect.width()*4,
rect.width() * 4,
media::YV12);
FOR_EACH_OBSERVER(NativeWindowObserver,
@ -721,7 +736,8 @@ void NativeWindow::OnFrameReceived(bool result, scoped_refptr<media::VideoFrame>
}
}
bool RenderSubscriber::ShouldCaptureFrame(const gfx::Rect& damage_rect,
bool RenderSubscriber::ShouldCaptureFrame(
const gfx::Rect& damage_rect,
base::TimeTicks present_time,
scoped_refptr<media::VideoFrame>* storage,
DeliverFrameCallback* callback) {