Avoid extra copy of data in capturePage

This commit is contained in:
Cheng Zhao 2015-03-20 10:26:22 +08:00
parent 24d615d428
commit 9bae54f917
3 changed files with 5 additions and 10 deletions

View file

@ -53,10 +53,10 @@ namespace {
void OnCapturePageDone( void OnCapturePageDone(
v8::Isolate* isolate, v8::Isolate* isolate,
const base::Callback<void(const gfx::Image&)>& callback, const base::Callback<void(const gfx::Image&)>& callback,
const std::vector<unsigned char>& data) { const SkBitmap& bitmap) {
v8::Locker locker(isolate); v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
callback.Run(gfx::Image::CreateFrom1xPNGBytes(&data.front(), data.size())); callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap));
} }
} // namespace } // namespace

View file

@ -322,7 +322,7 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
RenderWidgetHostView* const view = contents->GetRenderWidgetHostView(); RenderWidgetHostView* const view = contents->GetRenderWidgetHostView();
RenderWidgetHost* const host = view ? view->GetRenderWidgetHost() : nullptr; RenderWidgetHost* const host = view ? view->GetRenderWidgetHost() : nullptr;
if (!view || !host) { if (!view || !host) {
callback.Run(std::vector<unsigned char>()); callback.Run(SkBitmap());
return; return;
} }
@ -781,11 +781,7 @@ void NativeWindow::NotifyWindowUnresponsive() {
void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
const SkBitmap& bitmap, const SkBitmap& bitmap,
content::ReadbackResponse response) { content::ReadbackResponse response) {
SkAutoLockPixels screen_capture_lock(bitmap); callback.Run(bitmap);
std::vector<unsigned char> data;
if (response == content::READBACK_SUCCESS)
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &data);
callback.Run(data);
} }
void NativeWindow::CallDevToolsFunction(const std::string& function_name, void NativeWindow::CallDevToolsFunction(const std::string& function_name,

View file

@ -59,8 +59,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
public content::WebContentsObserver, public content::WebContentsObserver,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
typedef base::Callback<void(const std::vector<unsigned char>& buffer)> typedef base::Callback<void(const SkBitmap& bitmap)> CapturePageCallback;
CapturePageCallback;
class DialogScope { class DialogScope {
public: public: