From 50485a28d316220e4e61bf2b4170c263d036f2e5 Mon Sep 17 00:00:00 2001 From: gellert Date: Wed, 3 Aug 2016 13:28:19 +0200 Subject: [PATCH] fixes buffer size and adds pixel size to paint event --- atom/browser/api/atom_api_web_contents.cc | 12 ++++++++++-- atom/browser/api/atom_api_web_contents.h | 1 + atom/browser/osr/osr_output_device.cc | 2 +- atom/browser/osr/osr_output_device.h | 4 ++-- atom/browser/osr/osr_render_widget_host_view.cc | 5 +++-- atom/browser/osr/osr_render_widget_host_view.h | 1 + docs/api/web-contents.md | 3 ++- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d94779028cf..561d75eeb63 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1345,11 +1345,19 @@ bool WebContents::IsOffScreen() const { void WebContents::OnPaint(const gfx::Rect& dirty_rect, const gfx::Size& bitmap_size, + const int pixel_size, void* bitmap_pixels) { v8::MaybeLocal buffer = node::Buffer::New( - isolate(), reinterpret_cast(bitmap_pixels), sizeof(bitmap_pixels)); + isolate(), reinterpret_cast(bitmap_pixels), + pixel_size * dirty_rect.width() * dirty_rect.height()); + + mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate()); + dict.Set("width", bitmap_size.width()); + dict.Set("height", bitmap_size.height()); + dict.Set("pixel", pixel_size); + if (!buffer.IsEmpty()) - Emit("paint", dirty_rect, buffer.ToLocalChecked(), bitmap_size); + Emit("paint", dirty_rect, buffer.ToLocalChecked(), dict); } void WebContents::StartPainting() { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index e2e08192ccf..6a5bc8e47c6 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -160,6 +160,7 @@ class WebContents : public mate::TrackableObject, bool IsOffScreen() const; void OnPaint(const gfx::Rect& dirty_rect, const gfx::Size& bitmap_size, + const int pixel_size, void* bitmap_pixels); void StartPainting(); void StopPainting(); diff --git a/atom/browser/osr/osr_output_device.cc b/atom/browser/osr/osr_output_device.cc index 9e84ff23f6e..3b3b9ffe949 100644 --- a/atom/browser/osr/osr_output_device.cc +++ b/atom/browser/osr/osr_output_device.cc @@ -87,7 +87,7 @@ void OffScreenOutputDevice::OnPaint(const gfx::Rect& damage_rect) { SkAutoLockPixels bitmap_pixels_lock(*bitmap_); callback_.Run(rect, gfx::Size(bitmap_->width(), bitmap_->height()), - bitmap_->getPixels()); + bitmap_->bytesPerPixel(), bitmap_->getPixels()); } } // namespace atom diff --git a/atom/browser/osr/osr_output_device.h b/atom/browser/osr/osr_output_device.h index 1cec55037fe..2cae0273307 100644 --- a/atom/browser/osr/osr_output_device.h +++ b/atom/browser/osr/osr_output_device.h @@ -12,8 +12,8 @@ namespace atom { -typedef base::Callback OnPaintCallback; +typedef base::Callback OnPaintCallback; class OffScreenOutputDevice : public cc::SoftwareOutputDevice { public: diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 2467e789118..4ae3a578a8e 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -262,7 +262,7 @@ class AtomCopyFrameGenerator { std::unique_ptr bitmap_pixels_lock) { view_->OnPaint(damage_rect, gfx::Size(bitmap.width(), bitmap.height()), - bitmap.getPixels()); + bitmap.bytesPerPixel(), bitmap.getPixels()); if (frame_retry_count_ > 0) frame_retry_count_ = 0; @@ -791,11 +791,12 @@ void OffScreenRenderWidgetHostView::SetPaintCallback( void OffScreenRenderWidgetHostView::OnPaint( const gfx::Rect& damage_rect, const gfx::Size& bitmap_size, + const int pixel_size, void* bitmap_pixels) { TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint"); 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) { diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index 9c1fc64024a..65e1cec58e0 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -192,6 +192,7 @@ class OffScreenRenderWidgetHostView void SetPaintCallback(const OnPaintCallback& callback); void OnPaint(const gfx::Rect& damage_rect, const gfx::Size& bitmap_size, + const int pixel_size, void* bitmap_pixels); void SetPainting(bool painting); diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index c27237b1c70..a7428e38223 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -352,7 +352,7 @@ Emitted when the cursor's type changes. The `type` parameter can be `default`, `not-allowed`, `zoom-in`, `zoom-out`, `grab`, `grabbing`, `custom`. If the `type` parameter is `custom`, the `image` parameter will hold the custom -cursor image in a `NativeImage`, and `scale`, `size` and `hotspot` will hold +cursor image in a `NativeImage`, and `scale`, `size` and `hotspot` will hold additional information about the custom cursor. #### Event: 'context-menu' @@ -471,6 +471,7 @@ Returns: * `bitmapSize` Object * `width` Number - the width of the whole bitmap * `height` Number - the height of the whole bitmap + * `pixel` Number - The number of bytes per pixel Emitted when a new frame is generated. Only the dirty area is passed in the buffer.