Merge pull request #6713 from MaxWhere/offscreen-rendering-fixes
Fixes buffer size in offscreen mode
This commit is contained in:
commit
32d9382417
7 changed files with 20 additions and 9 deletions
|
@ -1345,11 +1345,18 @@ bool WebContents::IsOffScreen() const {
|
||||||
|
|
||||||
void WebContents::OnPaint(const gfx::Rect& dirty_rect,
|
void WebContents::OnPaint(const gfx::Rect& dirty_rect,
|
||||||
const gfx::Size& bitmap_size,
|
const gfx::Size& bitmap_size,
|
||||||
|
int pixel_size,
|
||||||
void* bitmap_pixels) {
|
void* bitmap_pixels) {
|
||||||
v8::MaybeLocal<v8::Object> buffer = node::Buffer::New(
|
v8::MaybeLocal<v8::Object> buffer = node::Buffer::Copy(
|
||||||
isolate(), reinterpret_cast<char*>(bitmap_pixels), sizeof(bitmap_pixels));
|
isolate(), reinterpret_cast<char*>(bitmap_pixels),
|
||||||
|
pixel_size * bitmap_size.width() * bitmap_size.height());
|
||||||
|
|
||||||
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate());
|
||||||
|
dict.Set("width", bitmap_size.width());
|
||||||
|
dict.Set("height", bitmap_size.height());
|
||||||
|
|
||||||
if (!buffer.IsEmpty())
|
if (!buffer.IsEmpty())
|
||||||
Emit("paint", dirty_rect, buffer.ToLocalChecked(), bitmap_size);
|
Emit("paint", dirty_rect, buffer.ToLocalChecked(), dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::StartPainting() {
|
void WebContents::StartPainting() {
|
||||||
|
@ -1359,8 +1366,8 @@ void WebContents::StartPainting() {
|
||||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||||
web_contents()->GetRenderWidgetHostView());
|
web_contents()->GetRenderWidgetHostView());
|
||||||
if (osr_rwhv) {
|
if (osr_rwhv) {
|
||||||
osr_rwhv->SetPainting(true);
|
|
||||||
osr_rwhv->Show();
|
osr_rwhv->Show();
|
||||||
|
osr_rwhv->SetPainting(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
bool IsOffScreen() const;
|
bool IsOffScreen() const;
|
||||||
void OnPaint(const gfx::Rect& dirty_rect,
|
void OnPaint(const gfx::Rect& dirty_rect,
|
||||||
const gfx::Size& bitmap_size,
|
const gfx::Size& bitmap_size,
|
||||||
|
const int pixel_size,
|
||||||
void* bitmap_pixels);
|
void* bitmap_pixels);
|
||||||
void StartPainting();
|
void StartPainting();
|
||||||
void StopPainting();
|
void StopPainting();
|
||||||
|
|
|
@ -87,7 +87,7 @@ void OffScreenOutputDevice::OnPaint(const gfx::Rect& damage_rect) {
|
||||||
|
|
||||||
SkAutoLockPixels bitmap_pixels_lock(*bitmap_);
|
SkAutoLockPixels bitmap_pixels_lock(*bitmap_);
|
||||||
callback_.Run(rect, gfx::Size(bitmap_->width(), bitmap_->height()),
|
callback_.Run(rect, gfx::Size(bitmap_->width(), bitmap_->height()),
|
||||||
bitmap_->getPixels());
|
bitmap_->bytesPerPixel(), bitmap_->getPixels());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
typedef base::Callback<void(const gfx::Rect&,
|
typedef base::Callback<void(const gfx::Rect&, const gfx::Size&,
|
||||||
const gfx::Size&, void*)> OnPaintCallback;
|
const int, void*)> OnPaintCallback;
|
||||||
|
|
||||||
class OffScreenOutputDevice : public cc::SoftwareOutputDevice {
|
class OffScreenOutputDevice : public cc::SoftwareOutputDevice {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -262,7 +262,7 @@ class AtomCopyFrameGenerator {
|
||||||
std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock) {
|
std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock) {
|
||||||
view_->OnPaint(damage_rect,
|
view_->OnPaint(damage_rect,
|
||||||
gfx::Size(bitmap.width(), bitmap.height()),
|
gfx::Size(bitmap.width(), bitmap.height()),
|
||||||
bitmap.getPixels());
|
bitmap.bytesPerPixel(), bitmap.getPixels());
|
||||||
|
|
||||||
if (frame_retry_count_ > 0)
|
if (frame_retry_count_ > 0)
|
||||||
frame_retry_count_ = 0;
|
frame_retry_count_ = 0;
|
||||||
|
@ -791,11 +791,12 @@ void OffScreenRenderWidgetHostView::SetPaintCallback(
|
||||||
void OffScreenRenderWidgetHostView::OnPaint(
|
void OffScreenRenderWidgetHostView::OnPaint(
|
||||||
const gfx::Rect& damage_rect,
|
const gfx::Rect& damage_rect,
|
||||||
const gfx::Size& bitmap_size,
|
const gfx::Size& bitmap_size,
|
||||||
|
const int pixel_size,
|
||||||
void* bitmap_pixels) {
|
void* bitmap_pixels) {
|
||||||
TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint");
|
TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint");
|
||||||
|
|
||||||
if (!callback_.is_null())
|
if (!callback_.is_null())
|
||||||
callback_.Run(damage_rect, bitmap_size, bitmap_pixels);
|
callback_.Run(damage_rect, bitmap_size, pixel_size, bitmap_pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffScreenRenderWidgetHostView::SetPainting(bool painting) {
|
void OffScreenRenderWidgetHostView::SetPainting(bool painting) {
|
||||||
|
|
|
@ -192,6 +192,7 @@ class OffScreenRenderWidgetHostView
|
||||||
void SetPaintCallback(const OnPaintCallback& callback);
|
void SetPaintCallback(const OnPaintCallback& callback);
|
||||||
void OnPaint(const gfx::Rect& damage_rect,
|
void OnPaint(const gfx::Rect& damage_rect,
|
||||||
const gfx::Size& bitmap_size,
|
const gfx::Size& bitmap_size,
|
||||||
|
const int pixel_size,
|
||||||
void* bitmap_pixels);
|
void* bitmap_pixels);
|
||||||
|
|
||||||
void SetPainting(bool painting);
|
void SetPainting(bool painting);
|
||||||
|
|
|
@ -471,6 +471,7 @@ Returns:
|
||||||
* `bitmapSize` Object
|
* `bitmapSize` Object
|
||||||
* `width` Number - the width of the whole bitmap
|
* `width` Number - the width of the whole bitmap
|
||||||
* `height` Number - the height of the whole bitmap
|
* `height` Number - the height of the whole bitmap
|
||||||
|
* `bytesPerPixel` Number - The number of bytes per pixel in the bitmap
|
||||||
|
|
||||||
Emitted when a new frame is generated. Only the dirty area is passed in the
|
Emitted when a new frame is generated. Only the dirty area is passed in the
|
||||||
buffer.
|
buffer.
|
||||||
|
|
Loading…
Reference in a new issue