added onpaint to software path

This commit is contained in:
Heilig Benedek 2016-07-27 19:19:53 +02:00
parent 783c9d9218
commit 221714e141
7 changed files with 227 additions and 201 deletions

View file

@ -281,7 +281,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
private: private:
AtomBrowserContext* GetBrowserContext() const; AtomBrowserContext* GetBrowserContext() const;
OffScreenWindow::OnPaintCallback paint_callback_; atom::OnPaintCallback paint_callback_;
uint32_t GetNextRequestId() { uint32_t GetNextRequestId() {
return ++request_id_; return ++request_id_;

View file

@ -8,7 +8,7 @@
namespace atom { namespace atom {
OffScreenOutputDevice::OffScreenOutputDevice() { OffScreenOutputDevice::OffScreenOutputDevice() : callback_(nullptr) {
std::cout << "OffScreenOutputDevice" << std::endl; std::cout << "OffScreenOutputDevice" << std::endl;
} }
@ -16,6 +16,10 @@ OffScreenOutputDevice::~OffScreenOutputDevice() {
std::cout << "~OffScreenOutputDevice" << std::endl; std::cout << "~OffScreenOutputDevice" << std::endl;
} }
void OffScreenOutputDevice::SetPaintCallback(const OnPaintCallback* callback) {
callback_.reset(callback);
}
void OffScreenOutputDevice::Resize( void OffScreenOutputDevice::Resize(
const gfx::Size& pixel_size, float scale_factor) { const gfx::Size& pixel_size, float scale_factor) {
std::cout << "Resize" << std::endl; std::cout << "Resize" << std::endl;
@ -43,7 +47,7 @@ void OffScreenOutputDevice::Resize(
} }
SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) { SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) {
std::cout << "BeginPaint" << std::endl; // std::cout << "BeginPaint" << std::endl;
DCHECK(canvas_.get()); DCHECK(canvas_.get());
DCHECK(bitmap_.get()); DCHECK(bitmap_.get());
@ -53,7 +57,7 @@ SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) {
} }
void OffScreenOutputDevice::EndPaint() { void OffScreenOutputDevice::EndPaint() {
std::cout << "EndPaint" << std::endl; // std::cout << "EndPaint" << std::endl;
DCHECK(canvas_.get()); DCHECK(canvas_.get());
DCHECK(bitmap_.get()); DCHECK(bitmap_.get());
@ -62,14 +66,35 @@ void OffScreenOutputDevice::EndPaint() {
cc::SoftwareOutputDevice::EndPaint(); cc::SoftwareOutputDevice::EndPaint();
SkAutoLockPixels bitmap_pixels_lock(*bitmap_.get()); OnPaint(damage_rect_);
//saveSkBitmapToBMPFile(*(bitmap_.get()), "test.bmp");
uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap_->getPixels()); // SkAutoLockPixels bitmap_pixels_lock(*bitmap_.get());
for (int i = 0; i<16; i++) { // saveSkBitmapToBMPFile(*(bitmap_.get()), "test.bmp");
int x = static_cast<int>(pixels[i]);
std::cout << std::hex << x << std::dec << std::endl; // uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap_->getPixels());
// for (int i = 0; i<16; i++) {
// int x = static_cast<int>(pixels[i]);
// std::cout << std::hex << x << std::dec << std::endl;
// }
}
void OffScreenOutputDevice::OnPaint(const gfx::Rect& damage_rect) {
gfx::Rect rect = damage_rect;
if (!pending_damage_rect_.IsEmpty()) {
rect.Union(pending_damage_rect_);
pending_damage_rect_.SetRect(0, 0, 0, 0);
} }
rect.Intersect(gfx::Rect(viewport_pixel_size_));
if (rect.IsEmpty())
return;
SkAutoLockPixels bitmap_pixels_lock(*bitmap_.get());
// std::cout << "Paint" << std::endl;
if (callback_.get())
callback_->Run(rect, bitmap_->width(), bitmap_->height(),
bitmap_->getPixels());
} }
} // namespace atom } // namespace atom

View file

@ -8,15 +8,20 @@
#include "cc/output/software_output_device.h" #include "cc/output/software_output_device.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "base/callback.h"
#include "content/browser/web_contents/web_contents_view.h" #include "content/browser/web_contents/web_contents_view.h"
namespace atom { namespace atom {
typedef base::Callback<void(const gfx::Rect&,int,int,void*)> OnPaintCallback;
class OffScreenOutputDevice : public cc::SoftwareOutputDevice { class OffScreenOutputDevice : public cc::SoftwareOutputDevice {
public: public:
OffScreenOutputDevice(); OffScreenOutputDevice();
~OffScreenOutputDevice(); ~OffScreenOutputDevice();
void SetPaintCallback(const OnPaintCallback*);
// void saveSkBitmapToBMPFile(const SkBitmap& skBitmap, const char* path); // void saveSkBitmapToBMPFile(const SkBitmap& skBitmap, const char* path);
void Resize(const gfx::Size& pixel_size, float scale_factor) override; void Resize(const gfx::Size& pixel_size, float scale_factor) override;
@ -24,11 +29,15 @@ public:
SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override; SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override;
void EndPaint() override; void EndPaint() override;
void OnPaint(const gfx::Rect& damage_rect);
private: private:
std::unique_ptr<SkCanvas> canvas_; std::unique_ptr<SkCanvas> canvas_;
std::unique_ptr<SkBitmap> bitmap_; std::unique_ptr<SkBitmap> bitmap_;
gfx::Rect pending_damage_rect_; gfx::Rect pending_damage_rect_;
std::unique_ptr<const atom::OnPaintCallback> callback_;
DISALLOW_COPY_AND_ASSIGN(OffScreenOutputDevice); DISALLOW_COPY_AND_ASSIGN(OffScreenOutputDevice);
}; };

View file

@ -487,8 +487,10 @@ void OffScreenWindow::SendBeginFrame(base::TimeTicks frame_time,
// std::cout << "sent begin frame" << std::endl; // std::cout << "sent begin frame" << std::endl;
} }
void OffScreenWindow::SetPaintCallback(const OnPaintCallback *callback) { void OffScreenWindow::SetPaintCallback(const OnPaintCallback* callback) {
paintCallback.reset(callback); paintCallback.reset(callback);
if (software_output_device_)
software_output_device_->SetPaintCallback(paintCallback.get());
} }
OffScreenWindow::~OffScreenWindow() { OffScreenWindow::~OffScreenWindow() {
@ -551,13 +553,7 @@ gfx::Vector2dF OffScreenWindow::GetLastScrollOffset() const {
gfx::NativeView OffScreenWindow::GetNativeView() const { gfx::NativeView OffScreenWindow::GetNativeView() const {
// std::cout << "GetNativeView" << std::endl; // std::cout << "GetNativeView" << std::endl;
#if defined(OS_MACOSX)
return gfx::NativeView(); return gfx::NativeView();
#elif
auto widget = views::Widget::GetWidgetForNativeWindow(
native_window_->GetNativeWindow());
return widget->GetNativeView();
#endif
} }
gfx::NativeViewAccessible OffScreenWindow::GetNativeViewAccessible() { gfx::NativeViewAccessible OffScreenWindow::GetNativeViewAccessible() {

View file

@ -65,9 +65,6 @@ class OffScreenWindow
public ui::CompositorDelegate, public ui::CompositorDelegate,
public content::DelegatedFrameHostClient { public content::DelegatedFrameHostClient {
public: public:
typedef base::Callback<void(const gfx::Rect&,int,int,void*)>
OnPaintCallback;
OffScreenWindow(content::RenderWidgetHost*, NativeWindow*); OffScreenWindow(content::RenderWidgetHost*, NativeWindow*);
~OffScreenWindow(); ~OffScreenWindow();
@ -190,8 +187,8 @@ public:
void SendBeginFrame(base::TimeTicks frame_time, void SendBeginFrame(base::TimeTicks frame_time,
base::TimeDelta vsync_period); base::TimeDelta vsync_period);
std::unique_ptr<const OnPaintCallback> paintCallback; std::unique_ptr<const atom::OnPaintCallback> paintCallback;
void SetPaintCallback(const OnPaintCallback*); void SetPaintCallback(const atom::OnPaintCallback*);
private: private:
void SetFrameRate(); void SetFrameRate();

View file

@ -46,7 +46,7 @@ exports.load = (appUrl) => {
end1 = +new Date(); end1 = +new Date();
const d = end1 - start1 const d = end1 - start1
// console.log(`browser #1: ${d < 10 ? ` ${d}` : d} ms`) console.log(`browser #1: ${d < 10 ? ` ${d}` : d} ms`)
start1 = end1 start1 = end1
}) })
@ -62,7 +62,6 @@ exports.load = (appUrl) => {
});*/ });*/
mainWindow2 = new BrowserWindow({ mainWindow2 = new BrowserWindow({
//disableGPU: false,
width: 800, width: 800,
height: 600, height: 600,
autoHideMenuBar: true, autoHideMenuBar: true,
@ -72,7 +71,7 @@ exports.load = (appUrl) => {
nodeIntegration: false nodeIntegration: false
} }
}) })
mainWindow2.loadURL('http://mrdoob.com/lab/javascript/requestanimationframe/') mainWindow2.loadURL(appUrl)
mainWindow2.focus() mainWindow2.focus()
mainWindow2.webContents.on('dom-ready', () => { mainWindow2.webContents.on('dom-ready', () => {
mainWindow2.webContents.beginFrameSubscription(() => { mainWindow2.webContents.beginFrameSubscription(() => {
@ -86,183 +85,183 @@ exports.load = (appUrl) => {
end2 = +new Date(); end2 = +new Date();
const d = end2 - start2 const d = end2 - start2
// console.log(`browser #2: ${d < 10 ? ` ${d}` : d} ms`) console.log(`browser #2: ${d < 10 ? ` ${d}` : d} ms`)
start2 = end2 start2 = end2
}) })
//
// mainWindow3 = new BrowserWindow({ mainWindow3 = new BrowserWindow({
// width: 800, width: 800,
// height: 600, height: 600,
// autoHideMenuBar: true, autoHideMenuBar: true,
// backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
// useContentSize: true, useContentSize: true,
// webPreferences: { webPreferences: {
// nodeIntegration: false nodeIntegration: false
// } }
// }) })
// mainWindow3.loadURL(appUrl) mainWindow3.loadURL(appUrl)
// mainWindow3.focus() mainWindow3.focus()
// mainWindow3.webContents.on('dom-ready', () => { mainWindow3.webContents.on('dom-ready', () => {
// mainWindow3.webContents.beginFrameSubscription(() => { mainWindow3.webContents.beginFrameSubscription(() => {
// console.log("asd") console.log("asd")
// }) })
// }) })
//
// var start3, end3 var start3, end3
// start3 = +new Date(); start3 = +new Date();
// mainWindow3.webContents.on('paint', (e, rect, w, h, data) => { mainWindow3.webContents.on('paint', (e, rect, w, h, data) => {
// end3 = +new Date(); end3 = +new Date();
//
// const d = end3 - start3 const d = end3 - start3
// console.log(`browser #3: ${d < 10 ? ` ${d}` : d} ms`) console.log(`browser #3: ${d < 10 ? ` ${d}` : d} ms`)
//
// start3 = end3 start3 = end3
// }) })
//
// mainWindow4 = new BrowserWindow({ mainWindow4 = new BrowserWindow({
// width: 800, width: 800,
// height: 600, height: 600,
// autoHideMenuBar: true, autoHideMenuBar: true,
// backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
// useContentSize: true, useContentSize: true,
// webPreferences: { webPreferences: {
// nodeIntegration: false nodeIntegration: false
// } }
// }) })
// mainWindow4.loadURL(appUrl) mainWindow4.loadURL(appUrl)
// mainWindow4.focus() mainWindow4.focus()
// mainWindow4.webContents.on('dom-ready', () => { mainWindow4.webContents.on('dom-ready', () => {
// mainWindow4.webContents.beginFrameSubscription(() => { mainWindow4.webContents.beginFrameSubscription(() => {
// console.log("asd") console.log("asd")
// }) })
// }) })
//
// var start4, end4 var start4, end4
// start4 = +new Date(); start4 = +new Date();
// mainWindow4.webContents.on('paint', (e, rect, w, h, data) => { mainWindow4.webContents.on('paint', (e, rect, w, h, data) => {
// end4 = +new Date(); end4 = +new Date();
//
// const d = end4 - start4 const d = end4 - start4
// console.log(`browser #4: ${d < 10 ? ` ${d}` : d} ms`) console.log(`browser #4: ${d < 10 ? ` ${d}` : d} ms`)
//
// start4 = end4 start4 = end4
// }) })
// mainWindow5 = new BrowserWindow({ mainWindow5 = new BrowserWindow({
// width: 800, width: 800,
// height: 600, height: 600,
// autoHideMenuBar: true, autoHideMenuBar: true,
// backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
// useContentSize: true, useContentSize: true,
// webPreferences: { webPreferences: {
// nodeIntegration: false nodeIntegration: false
// } }
// }) })
// mainWindow5.loadURL(appUrl) mainWindow5.loadURL(appUrl)
// mainWindow5.focus() mainWindow5.focus()
// mainWindow5.webContents.on('dom-ready', () => { mainWindow5.webContents.on('dom-ready', () => {
// mainWindow5.webContents.beginFrameSubscription(() => { mainWindow5.webContents.beginFrameSubscription(() => {
// console.log("asd") console.log("asd")
// }) })
// }) })
//
// var start5, end5 var start5, end5
// start5 = +new Date(); start5 = +new Date();
// mainWindow5.webContents.on('paint', (e, rect, w, h, data) => { mainWindow5.webContents.on('paint', (e, rect, w, h, data) => {
// end5 = +new Date(); end5 = +new Date();
//
// const d = end5 - start5 const d = end5 - start5
// console.log(`browser #5: ${d < 10 ? ` ${d}` : d} ms`) console.log(`browser #5: ${d < 10 ? ` ${d}` : d} ms`)
//
// start5 = end5 start5 = end5
// }) })
//
// mainWindow6 = new BrowserWindow({ mainWindow6 = new BrowserWindow({
// width: 800, width: 800,
// height: 600, height: 600,
// autoHideMenuBar: true, autoHideMenuBar: true,
// backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
// useContentSize: true, useContentSize: true,
// webPreferences: { webPreferences: {
// nodeIntegration: false nodeIntegration: false
// } }
// }) })
// mainWindow6.loadURL(appUrl) mainWindow6.loadURL(appUrl)
// mainWindow6.focus() mainWindow6.focus()
// mainWindow6.webContents.on('dom-ready', () => { mainWindow6.webContents.on('dom-ready', () => {
// mainWindow6.webContents.beginFrameSubscription(() => { mainWindow6.webContents.beginFrameSubscription(() => {
// console.log("asd") console.log("asd")
// }) })
// }) })
//
// var start6, end6 var start6, end6
// start6 = +new Date(); start6 = +new Date();
// mainWindow6.webContents.on('paint', (e, rect, w, h, data) => { mainWindow6.webContents.on('paint', (e, rect, w, h, data) => {
// end6 = +new Date(); end6 = +new Date();
//
// const d = end6 - start6 const d = end6 - start6
// console.log(`browser #6: ${d < 10 ? ` ${d}` : d} ms`) console.log(`browser #6: ${d < 10 ? ` ${d}` : d} ms`)
//
// start6 = end6 start6 = end6
// }) })
//
// mainWindow7 = new BrowserWindow({ mainWindow7 = new BrowserWindow({
// width: 800, width: 800,
// height: 600, height: 600,
// autoHideMenuBar: true, autoHideMenuBar: true,
// backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
// useContentSize: true, useContentSize: true,
// webPreferences: { webPreferences: {
// nodeIntegration: false nodeIntegration: false
// } }
// }) })
// mainWindow7.loadURL(appUrl) mainWindow7.loadURL(appUrl)
// mainWindow7.focus() mainWindow7.focus()
// mainWindow7.webContents.on('dom-ready', () => { mainWindow7.webContents.on('dom-ready', () => {
// mainWindow7.webContents.beginFrameSubscription(() => { mainWindow7.webContents.beginFrameSubscription(() => {
// console.log("asd") console.log("asd")
// }) })
// }) })
//
// var start7, end7 var start7, end7
// start7 = +new Date(); start7 = +new Date();
// mainWindow7.webContents.on('paint', (e, rect, w, h, data) => { mainWindow7.webContents.on('paint', (e, rect, w, h, data) => {
// end7 = +new Date(); end7 = +new Date();
//
// const d = end7 - start7 const d = end7 - start7
// console.log(`browser #7: ${d < 10 ? ` ${d}` : d} ms`) console.log(`browser #7: ${d < 10 ? ` ${d}` : d} ms`)
//
// start7 = end7 start7 = end7
// }) })
//
// mainWindow8 = new BrowserWindow({ mainWindow8 = new BrowserWindow({
// width: 800, width: 800,
// height: 600, height: 600,
// autoHideMenuBar: true, autoHideMenuBar: true,
// backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
// useContentSize: true, useContentSize: true,
// webPreferences: { webPreferences: {
// nodeIntegration: false nodeIntegration: false
// } }
// }) })
// mainWindow8.loadURL(appUrl) mainWindow8.loadURL(appUrl)
// mainWindow8.focus() mainWindow8.focus()
// mainWindow8.webContents.on('dom-ready', () => { mainWindow8.webContents.on('dom-ready', () => {
// mainWindow8.webContents.beginFrameSubscription(() => { mainWindow8.webContents.beginFrameSubscription(() => {
// console.log("asd") console.log("asd")
// }) })
// }) })
//
// var start8, end8 var start8, end8
// start8 = +new Date(); start8 = +new Date();
// mainWindow8.webContents.on('paint', (e, rect, w, h, data) => { mainWindow8.webContents.on('paint', (e, rect, w, h, data) => {
// end8 = +new Date(); end8 = +new Date();
//
// const d = end8 - start8 const d = end8 - start8
// console.log(`browser #8: ${d < 10 ? ` ${d}` : d} ms`) console.log(`browser #8: ${d < 10 ? ` ${d}` : d} ms`)
//
// start8 = end8 start8 = end8
// }) })
}) })
} }

View file

@ -329,6 +329,6 @@ if (option.file && !option.webdriver) {
startRepl() startRepl()
} else { } else {
const indexPath = path.join(__dirname, '/index.html') const indexPath = path.join(__dirname, '/index.html')
loadApplicationByUrl(`http://www.e-try.com/black.htm`) //loadApplicationByUrl(`http://www.e-try.com/black.htm`)
//loadApplicationByUrl(`http://mrdoob.com/lab/javascript/requestanimationframe/`) loadApplicationByUrl(`http://mrdoob.com/lab/javascript/requestanimationframe/`)
} }