Re-add dirtyOnly to FrameSubscriber and document API change
This commit is contained in:
parent
b9413fe59d
commit
60ba2013c4
4 changed files with 26 additions and 15 deletions
|
@ -1637,15 +1637,17 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::BeginFrameSubscription(mate::Arguments* args) {
|
void WebContents::BeginFrameSubscription(mate::Arguments* args) {
|
||||||
|
bool only_dirty = false;
|
||||||
FrameSubscriber::FrameCaptureCallback callback;
|
FrameSubscriber::FrameCaptureCallback callback;
|
||||||
|
|
||||||
|
args->GetNext(&only_dirty);
|
||||||
if (!args->GetNext(&callback)) {
|
if (!args->GetNext(&callback)) {
|
||||||
args->ThrowError();
|
args->ThrowError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame_subscriber_.reset(
|
frame_subscriber_.reset(
|
||||||
new FrameSubscriber(isolate(), web_contents(), callback));
|
new FrameSubscriber(isolate(), web_contents(), callback, only_dirty));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::EndFrameSubscription() {
|
void WebContents::EndFrameSubscription() {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "content/browser/compositor/surface_utils.h"
|
#include "content/browser/compositor/surface_utils.h"
|
||||||
#include "content/browser/renderer_host/render_widget_host_view_base.h"
|
#include "content/browser/renderer_host/render_widget_host_view_base.h"
|
||||||
#include "ui/gfx/geometry/rect_conversions.h"
|
#include "ui/gfx/geometry/rect_conversions.h"
|
||||||
|
#include "ui/gfx/skbitmap_operations.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -18,10 +19,12 @@ namespace api {
|
||||||
|
|
||||||
FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
const FrameCaptureCallback& callback)
|
const FrameCaptureCallback& callback,
|
||||||
|
bool only_dirty)
|
||||||
: content::WebContentsObserver(web_contents),
|
: content::WebContentsObserver(web_contents),
|
||||||
isolate_(isolate),
|
isolate_(isolate),
|
||||||
callback_(callback) {}
|
callback_(callback),
|
||||||
|
only_dirty_(only_dirty) {}
|
||||||
|
|
||||||
FrameSubscriber::~FrameSubscriber() = default;
|
FrameSubscriber::~FrameSubscriber() = default;
|
||||||
|
|
||||||
|
@ -70,7 +73,14 @@ void FrameSubscriber::Done(const gfx::Rect& damage, const SkBitmap& frame) {
|
||||||
const_cast<SkBitmap&>(frame).setAlphaType(kPremul_SkAlphaType);
|
const_cast<SkBitmap&>(frame).setAlphaType(kPremul_SkAlphaType);
|
||||||
v8::Local<v8::Value> damage_rect =
|
v8::Local<v8::Value> damage_rect =
|
||||||
mate::Converter<gfx::Rect>::ToV8(isolate_, damage);
|
mate::Converter<gfx::Rect>::ToV8(isolate_, damage);
|
||||||
callback_.Run(gfx::Image::CreateFrom1xBitmap(frame), damage_rect);
|
|
||||||
|
if (only_dirty_) {
|
||||||
|
const SkBitmap& damageFrame = SkBitmapOperations::CreateTiledBitmap(
|
||||||
|
frame, damage.x(), damage.y(), damage.width(), damage.height());
|
||||||
|
callback_.Run(gfx::Image::CreateFrom1xBitmap(damageFrame), damage_rect);
|
||||||
|
} else {
|
||||||
|
callback_.Run(gfx::Image::CreateFrom1xBitmap(frame), damage_rect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
|
@ -26,7 +26,8 @@ class FrameSubscriber : public content::WebContentsObserver {
|
||||||
|
|
||||||
FrameSubscriber(v8::Isolate* isolate,
|
FrameSubscriber(v8::Isolate* isolate,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
const FrameCaptureCallback& callback);
|
const FrameCaptureCallback& callback,
|
||||||
|
bool only_dirty);
|
||||||
~FrameSubscriber();
|
~FrameSubscriber();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -36,6 +37,7 @@ class FrameSubscriber : public content::WebContentsObserver {
|
||||||
|
|
||||||
v8::Isolate* isolate_;
|
v8::Isolate* isolate_;
|
||||||
FrameCaptureCallback callback_;
|
FrameCaptureCallback callback_;
|
||||||
|
bool only_dirty_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
|
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1322,23 +1322,20 @@ For the `mouseWheel` event, the `event` object also have following properties:
|
||||||
|
|
||||||
* `onlyDirty` Boolean (optional) - Defaults to `false`.
|
* `onlyDirty` Boolean (optional) - Defaults to `false`.
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
* `frameBuffer` Buffer
|
* `image` [NativeImage](native-image.md)
|
||||||
* `dirtyRect` [Rectangle](structures/rectangle.md)
|
* `dirtyRect` [Rectangle](structures/rectangle.md)
|
||||||
|
|
||||||
Begin subscribing for presentation events and captured frames, the `callback`
|
Begin subscribing for presentation events and captured frames, the `callback`
|
||||||
will be called with `callback(frameBuffer, dirtyRect)` when there is a
|
will be called with `callback(image, dirtyRect)` when there is a presentation
|
||||||
presentation event.
|
event.
|
||||||
|
|
||||||
The `frameBuffer` is a `Buffer` that contains raw pixel data. On most machines,
|
The `image` is an instance of [NativeImage](native-image.md) that stores the
|
||||||
the pixel data is effectively stored in 32bit BGRA format, but the actual
|
captured frame.
|
||||||
representation depends on the endianness of the processor (most modern
|
|
||||||
processors are little-endian, on machines with big-endian processors the data
|
|
||||||
is in 32bit ARGB format).
|
|
||||||
|
|
||||||
The `dirtyRect` is an object with `x, y, width, height` properties that
|
The `dirtyRect` is an object with `x, y, width, height` properties that
|
||||||
describes which part of the page was repainted. If `onlyDirty` is set to
|
describes which part of the page was repainted. If `onlyDirty` is set to
|
||||||
`true`, `frameBuffer` will only contain the repainted area. `onlyDirty`
|
`true`, `image` will only contain the repainted area. `onlyDirty` defaults to
|
||||||
defaults to `false`.
|
`false`.
|
||||||
|
|
||||||
#### `contents.endFrameSubscription()`
|
#### `contents.endFrameSubscription()`
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue