Re-add dirtyOnly to FrameSubscriber and document API change

This commit is contained in:
Heilig Benedek 2018-05-14 19:09:05 +02:00 committed by Samuel Attard
parent b9413fe59d
commit 60ba2013c4
4 changed files with 26 additions and 15 deletions

View file

@ -11,6 +11,7 @@
#include "content/browser/compositor/surface_utils.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/skbitmap_operations.h"
namespace atom {
@ -18,10 +19,12 @@ namespace api {
FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
content::WebContents* web_contents,
const FrameCaptureCallback& callback)
const FrameCaptureCallback& callback,
bool only_dirty)
: content::WebContentsObserver(web_contents),
isolate_(isolate),
callback_(callback) {}
callback_(callback),
only_dirty_(only_dirty) {}
FrameSubscriber::~FrameSubscriber() = default;
@ -70,7 +73,14 @@ void FrameSubscriber::Done(const gfx::Rect& damage, const SkBitmap& frame) {
const_cast<SkBitmap&>(frame).setAlphaType(kPremul_SkAlphaType);
v8::Local<v8::Value> damage_rect =
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