Move BeginFrameSubscription to WebContents

This commit is contained in:
Cheng Zhao 2015-09-18 15:57:43 +08:00
parent 42863e4700
commit 86f523d3c1
10 changed files with 137 additions and 121 deletions

View file

@ -8,7 +8,6 @@
#include <utility>
#include <vector>
#include "media/base/yuv_convert.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/window_list.h"
@ -283,21 +282,6 @@ void NativeWindow::SetAspectRatio(double aspect_ratio,
aspect_ratio_extraSize_ = extra_size;
}
void NativeWindow::SetFrameSubscription(bool isOffscreen) {
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();
}
}
}
void NativeWindow::RequestToClosePage() {
bool prevent_default = false;
FOR_EACH_OBSERVER(NativeWindowObserver,
@ -517,44 +501,4 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
callback.Run(bitmap);
}
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;
scoped_ptr<uint8[]> rgb_bytes(new uint8[rgb_arr_size]);
// Convert a frame of YUV to 32 bit ARGB.
media::ConvertYUVToRGB32(frame->data(media::VideoFrame::kYPlane),
frame->data(media::VideoFrame::kUPlane),
frame->data(media::VideoFrame::kVPlane),
rgb_bytes.get(),
rect.width(), rect.height(),
frame->stride(media::VideoFrame::kYPlane),
frame->stride(media::VideoFrame::kUVPlane),
rect.width() * 4,
media::YV12);
FOR_EACH_OBSERVER(NativeWindowObserver,
observers_,
OnFrameRendered(rgb_bytes.Pass(), rgb_arr_size));
}
}
bool RenderSubscriber::ShouldCaptureFrame(
const gfx::Rect& damage_rect,
base::TimeTicks present_time,
scoped_refptr<media::VideoFrame>* storage,
DeliverFrameCallback* callback) {
last_present_time_ = present_time;
*storage = media::VideoFrame::CreateFrame(media::VideoFrame::YV12, size_,
gfx::Rect(size_), size_,
base::TimeDelta());
*callback =
base::Bind(&RenderSubscriber::CallbackMethod, callback_, *storage);
return true;
}
} // namespace atom