| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/test_runner/pixel_dump.h" | 5 #include "components/test_runner/pixel_dump.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 public: | 47 public: |
| 48 CaptureCallback(const base::Callback<void(const SkBitmap&)>& callback); | 48 CaptureCallback(const base::Callback<void(const SkBitmap&)>& callback); |
| 49 virtual ~CaptureCallback(); | 49 virtual ~CaptureCallback(); |
| 50 | 50 |
| 51 void set_wait_for_popup(bool wait) { wait_for_popup_ = wait; } | 51 void set_wait_for_popup(bool wait) { wait_for_popup_ = wait; } |
| 52 void set_popup_position(const gfx::Point& position) { | 52 void set_popup_position(const gfx::Point& position) { |
| 53 popup_position_ = position; | 53 popup_position_ = position; |
| 54 } | 54 } |
| 55 | 55 |
| 56 // WebCompositeAndReadbackAsyncCallback implementation. | 56 // WebCompositeAndReadbackAsyncCallback implementation. |
| 57 bool needsBitmap() const override; |
| 57 void didCompositeAndReadback(const SkBitmap& bitmap) override; | 58 void didCompositeAndReadback(const SkBitmap& bitmap) override; |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 base::Callback<void(const SkBitmap&)> callback_; | 61 base::Callback<void(const SkBitmap&)> callback_; |
| 61 SkBitmap main_bitmap_; | 62 SkBitmap main_bitmap_; |
| 62 bool wait_for_popup_; | 63 bool wait_for_popup_; |
| 63 gfx::Point popup_position_; | 64 gfx::Point popup_position_; |
| 64 }; | 65 }; |
| 65 | 66 |
| 66 void DrawSelectionRect(const PixelsDumpRequest& dump_request, | 67 void DrawSelectionRect(const PixelsDumpRequest& dump_request, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 const SkBitmap bitmap = skia::ReadPixels(canvas.get()); | 111 const SkBitmap bitmap = skia::ReadPixels(canvas.get()); |
| 111 dump_request->callback.Run(bitmap); | 112 dump_request->callback.Run(bitmap); |
| 112 } | 113 } |
| 113 | 114 |
| 114 CaptureCallback::CaptureCallback( | 115 CaptureCallback::CaptureCallback( |
| 115 const base::Callback<void(const SkBitmap&)>& callback) | 116 const base::Callback<void(const SkBitmap&)>& callback) |
| 116 : callback_(callback), wait_for_popup_(false) {} | 117 : callback_(callback), wait_for_popup_(false) {} |
| 117 | 118 |
| 118 CaptureCallback::~CaptureCallback() {} | 119 CaptureCallback::~CaptureCallback() {} |
| 119 | 120 |
| 121 bool CaptureCallback::needsBitmap() const { |
| 122 return true; |
| 123 } |
| 124 |
| 120 void CaptureCallback::didCompositeAndReadback(const SkBitmap& bitmap) { | 125 void CaptureCallback::didCompositeAndReadback(const SkBitmap& bitmap) { |
| 121 TRACE_EVENT2("shell", "CaptureCallback::didCompositeAndReadback", "x", | 126 TRACE_EVENT2("shell", "CaptureCallback::didCompositeAndReadback", "x", |
| 122 bitmap.info().width(), "y", bitmap.info().height()); | 127 bitmap.info().width(), "y", bitmap.info().height()); |
| 123 if (!wait_for_popup_) { | 128 if (!wait_for_popup_) { |
| 124 callback_.Run(bitmap); | 129 callback_.Run(bitmap); |
| 125 delete this; | 130 delete this; |
| 126 return; | 131 return; |
| 127 } | 132 } |
| 128 if (main_bitmap_.isNull()) { | 133 if (main_bitmap_.isNull()) { |
| 129 bitmap.deepCopyTo(&main_bitmap_); | 134 bitmap.deepCopyTo(&main_bitmap_); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 201 |
| 197 blink::WebImage image = static_cast<blink::WebMockClipboard*>( | 202 blink::WebImage image = static_cast<blink::WebMockClipboard*>( |
| 198 blink::Platform::current()->clipboard()) | 203 blink::Platform::current()->clipboard()) |
| 199 ->readRawImage(blink::WebClipboard::Buffer()); | 204 ->readRawImage(blink::WebClipboard::Buffer()); |
| 200 const SkBitmap& bitmap = image.getSkBitmap(); | 205 const SkBitmap& bitmap = image.getSkBitmap(); |
| 201 SkAutoLockPixels autoLock(bitmap); | 206 SkAutoLockPixels autoLock(bitmap); |
| 202 callback.Run(bitmap); | 207 callback.Run(bitmap); |
| 203 } | 208 } |
| 204 | 209 |
| 205 } // namespace test_runner | 210 } // namespace test_runner |
| OLD | NEW |