Frame subscriber bugfix + added only_damaged option
This commit is contained in:
parent
a35915ee9f
commit
3529f8a40a
4 changed files with 38 additions and 16 deletions
|
@ -1195,11 +1195,18 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
|
|||
}
|
||||
|
||||
void WebContents::BeginFrameSubscription(
|
||||
const FrameSubscriber::FrameCaptureCallback& callback) {
|
||||
mate::Arguments* args) {
|
||||
FrameSubscriber::FrameCaptureCallback callback;
|
||||
if (!args->GetNext(&callback))
|
||||
return;
|
||||
|
||||
bool only_damaged = false;
|
||||
args->GetNext(&only_damaged);
|
||||
|
||||
const auto view = web_contents()->GetRenderWidgetHostView();
|
||||
if (view) {
|
||||
std::unique_ptr<FrameSubscriber> frame_subscriber(new FrameSubscriber(
|
||||
isolate(), view, callback));
|
||||
isolate(), view, callback, only_damaged));
|
||||
view->BeginFrameSubscription(std::move(frame_subscriber));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,8 +139,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
void SendInputEvent(v8::Isolate* isolate, v8::Local<v8::Value> input_event);
|
||||
|
||||
// Subscribe to the frame updates.
|
||||
void BeginFrameSubscription(
|
||||
const FrameSubscriber::FrameCaptureCallback& callback);
|
||||
void BeginFrameSubscription(mate::Arguments* args);
|
||||
void EndFrameSubscription();
|
||||
|
||||
// Methods for creating <webview>.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "base/bind.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
|
||||
namespace atom {
|
||||
|
@ -14,8 +15,10 @@ namespace api {
|
|||
|
||||
FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
||||
content::RenderWidgetHostView* view,
|
||||
const FrameCaptureCallback& callback)
|
||||
: isolate_(isolate), view_(view), callback_(callback), weak_factory_(this) {
|
||||
const FrameCaptureCallback& callback,
|
||||
const bool& only_damaged)
|
||||
: isolate_(isolate), view_(view), only_damaged_(only_damaged),
|
||||
callback_(callback), weak_factory_(this) {
|
||||
}
|
||||
|
||||
bool FrameSubscriber::ShouldCaptureFrame(
|
||||
|
@ -27,21 +30,27 @@ bool FrameSubscriber::ShouldCaptureFrame(
|
|||
if (!view_ || !host)
|
||||
return false;
|
||||
|
||||
const auto size = view_->GetVisibleViewportSize();
|
||||
if (damage_rect.width() == 0 || damage_rect.height() == 0)
|
||||
return false;
|
||||
|
||||
gfx::Rect rect = gfx::Rect(view_->GetVisibleViewportSize());
|
||||
if (only_damaged_)
|
||||
rect = damage_rect;
|
||||
|
||||
host->CopyFromBackingStore(
|
||||
gfx::Rect(size),
|
||||
size,
|
||||
rect,
|
||||
rect.size(),
|
||||
base::Bind(&FrameSubscriber::OnFrameDelivered,
|
||||
weak_factory_.GetWeakPtr(), callback_),
|
||||
weak_factory_.GetWeakPtr(), callback_, rect),
|
||||
kBGRA_8888_SkColorType);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||
const SkBitmap& bitmap, content::ReadbackResponse response) {
|
||||
if (bitmap.computeSize64() == 0)
|
||||
const gfx::Rect& damage_rect, const SkBitmap& bitmap,
|
||||
content::ReadbackResponse response) {
|
||||
if (response != content::ReadbackResponse::READBACK_SUCCESS)
|
||||
return;
|
||||
|
||||
v8::Locker locker(isolate_);
|
||||
|
@ -57,7 +66,10 @@ void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
|
|||
reinterpret_cast<uint8_t*>(node::Buffer::Data(buffer.ToLocalChecked())),
|
||||
rgb_arr_size);
|
||||
|
||||
callback_.Run(buffer.ToLocalChecked());
|
||||
v8::Local<v8::Value> damage =
|
||||
mate::Converter<gfx::Rect>::ToV8(isolate_, damage_rect);
|
||||
|
||||
callback_.Run(buffer.ToLocalChecked(), damage);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
|
|
@ -20,11 +20,13 @@ namespace api {
|
|||
|
||||
class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
|
||||
public:
|
||||
using FrameCaptureCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||
using FrameCaptureCallback =
|
||||
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
|
||||
|
||||
FrameSubscriber(v8::Isolate* isolate,
|
||||
content::RenderWidgetHostView* view,
|
||||
const FrameCaptureCallback& callback);
|
||||
const FrameCaptureCallback& callback,
|
||||
const bool& only_damaged);
|
||||
|
||||
bool ShouldCaptureFrame(const gfx::Rect& damage_rect,
|
||||
base::TimeTicks present_time,
|
||||
|
@ -33,11 +35,13 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
|
|||
|
||||
private:
|
||||
void OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||
const SkBitmap& bitmap, content::ReadbackResponse response);
|
||||
const gfx::Rect& damage_rect, const SkBitmap& bitmap,
|
||||
content::ReadbackResponse response);
|
||||
|
||||
v8::Isolate* isolate_;
|
||||
content::RenderWidgetHostView* view_;
|
||||
FrameCaptureCallback callback_;
|
||||
bool only_damaged_;
|
||||
|
||||
base::WeakPtrFactory<FrameSubscriber> weak_factory_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue