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

View file

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

View file

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