damaged -> dirty rename, fixed misc issues, changed signature, updated docs and added tests

This commit is contained in:
Heilig Benedek 2016-06-25 18:23:40 +02:00
parent 3c92825e2a
commit 5118def724
6 changed files with 65 additions and 31 deletions

View file

@ -1197,16 +1197,18 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
void WebContents::BeginFrameSubscription(
mate::Arguments* args) {
FrameSubscriber::FrameCaptureCallback callback;
if (!args->GetNext(&callback))
return;
bool only_dirty = false;
bool only_damaged = false;
args->GetNext(&only_damaged);
if (!args->GetNext(&callback)) {
args->GetNext(&only_dirty);
if (!args->GetNext(&callback))
args->ThrowTypeError("'callback' must be defined");
}
const auto view = web_contents()->GetRenderWidgetHostView();
if (view) {
std::unique_ptr<FrameSubscriber> frame_subscriber(new FrameSubscriber(
isolate(), view, callback, only_damaged));
isolate(), view, callback, only_dirty));
view->BeginFrameSubscription(std::move(frame_subscriber));
}
}

View file

@ -16,13 +16,13 @@ namespace api {
FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
content::RenderWidgetHostView* view,
const FrameCaptureCallback& callback,
const bool& only_damaged)
bool only_dirty)
: isolate_(isolate), view_(view), callback_(callback),
only_damaged_(only_damaged), weak_factory_(this) {
only_dirty_(only_dirty), weak_factory_(this) {
}
bool FrameSubscriber::ShouldCaptureFrame(
const gfx::Rect& damage_rect,
const gfx::Rect& dirty_rect,
base::TimeTicks present_time,
scoped_refptr<media::VideoFrame>* storage,
DeliverFrameCallback* callback) {
@ -30,12 +30,12 @@ bool FrameSubscriber::ShouldCaptureFrame(
if (!view_ || !host)
return false;
if (damage_rect.width() == 0 || damage_rect.height() == 0)
if (dirty_rect.IsEmpty())
return false;
gfx::Rect rect = gfx::Rect(view_->GetVisibleViewportSize());
if (only_damaged_)
rect = damage_rect;
if (only_dirty_)
rect = dirty_rect;
host->CopyFromBackingStore(
rect,

View file

@ -26,7 +26,7 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
FrameSubscriber(v8::Isolate* isolate,
content::RenderWidgetHostView* view,
const FrameCaptureCallback& callback,
const bool& only_damaged);
bool only_dirty);
bool ShouldCaptureFrame(const gfx::Rect& damage_rect,
base::TimeTicks present_time,
@ -41,7 +41,7 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
v8::Isolate* isolate_;
content::RenderWidgetHostView* view_;
FrameCaptureCallback callback_;
bool only_damaged_;
bool only_dirty_;
base::WeakPtrFactory<FrameSubscriber> weak_factory_;