Emit NativeImage objects in paint event

This commit is contained in:
Cheng Zhao 2016-08-04 13:47:52 +09:00
parent 3be68ba136
commit 8c4ebdc88e
3 changed files with 24 additions and 42 deletions

View file

@ -1337,15 +1337,10 @@ bool WebContents::IsOffScreen() const {
return type_ == OFF_SCREEN; return type_ == OFF_SCREEN;
} }
void WebContents::OnPaint(const gfx::Rect& dirty_rect, void WebContents::OnPaint(const gfx::Rect& dirty_rect, const SkBitmap& bitmap) {
const SkBitmap& bitmap) { mate::Handle<NativeImage> image =
v8::MaybeLocal<v8::Object> buffer = node::Buffer::Copy( NativeImage::Create(isolate(), gfx::Image::CreateFrom1xBitmap(bitmap));
isolate(), Emit("paint", dirty_rect, image);
reinterpret_cast<char*>(bitmap.getPixels()), bitmap.getSize());
if (!buffer.IsEmpty()) {
Emit("paint", dirty_rect, buffer.ToLocalChecked(),
gfx::Size(bitmap.width(), bitmap.height()));
}
} }
void WebContents::StartPainting() { void WebContents::StartPainting() {

View file

@ -463,33 +463,21 @@ Returns:
* `event` Event * `event` Event
* `dirtyRect` Object * `dirtyRect` Object
* `x` Number - the x coordinate on the bitmap * `x` Integer - The x coordinate on the image.
* `y` Number - the y coordinate on the bitmap * `y` Integer - The y coordinate on the image.
* `width` Number - the width of the dirty area * `width` Integer - The width of the dirty area.
* `height` Number - the height of the dirty area * `height` Integer - The height of the dirty area.
* `data` Buffer - the bitmap data of the dirty rect * `image` [NativeImage](native-image.md) - The image data of the dirty rect
* `bitmapSize` Object
* `width` Number - the width of the whole bitmap
* `height` Number - the height of the whole 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.
```javascript ```javascript
const {BrowserWindow} = require('electron') let win = new BrowserWindow({webPreferences: {offscreen: true}})
win.webContents.on('paint', (event, dirty, image) => {
let win = new BrowserWindow({ fs.writeSync('frame.png', image.toPNG())
width: 800,
height: 1500,
webPreferences: {
offscreen: true
}
}) })
win.loadURL('http://github.com') win.loadURL('http://github.com')
win.webContents.on('paint', (event, dirty, data) => {
// updateBitmap(dirty, data)
})
``` ```
### Instance Methods ### Instance Methods

View file

@ -37,19 +37,18 @@ const {app, BrowserWindow} = require('electron')
app.disableHardwareAcceleration() app.disableHardwareAcceleration()
let win = new BrowserWindow({ let win
width: 800, app.once('ready', () => {
height: 1500, win = new BrowserWindow({
webPreferences: { webPreferences: {
offscreen: true offscreen: true
} }
}) })
win.loadURL('http://github.com') win.loadURL('http://github.com')
win.webContents.on('paint', (event, dirty, image) => {
win.webContents.setFrameRate(30) fs.writeSync('frame.png', image.toPNG())
})
win.webContents.on('paint', (event, dirty, data) => { win.webContents.setFrameRate(30)
// updateBitmap(dirty, data)
}) })
``` ```