Chromium Code Reviews| Index: ui/snapshot/snapshot_android.cc |
| diff --git a/ui/snapshot/snapshot_android.cc b/ui/snapshot/snapshot_android.cc |
| index 837c13c8d4f1578446fa1b1a1c0529f629868e7a..4f74453406900e480fb5fa720db705387f638190 100644 |
| --- a/ui/snapshot/snapshot_android.cc |
| +++ b/ui/snapshot/snapshot_android.cc |
| @@ -4,13 +4,14 @@ |
| #include "ui/snapshot/snapshot.h" |
| -#include "base/callback.h" |
| +#include "base/bind.h" |
| +#include "cc/output/copy_output_request.h" |
| +#include "cc/resources/single_release_callback.h" |
|
Ted C
2014/05/14 01:13:18
Do we need this include or the following one?
danakj
2014/05/14 14:33:20
Yeh, it doesn't compile otherwise because the copy
|
| +#include "third_party/skia/include/core/SkBitmap.h" |
| #include "ui/base/android/view_android.h" |
| #include "ui/base/android/window_android.h" |
| -#include "ui/gfx/display.h" |
| -#include "ui/gfx/image/image.h" |
| -#include "ui/gfx/rect.h" |
| -#include "ui/gfx/screen.h" |
| +#include "ui/base/android/window_android_compositor.h" |
| +#include "ui/snapshot/snapshot_async.h" |
| namespace ui { |
| @@ -24,39 +25,53 @@ bool GrabViewSnapshot(gfx::NativeView view, |
| bool GrabWindowSnapshot(gfx::NativeWindow window, |
| std::vector<unsigned char>* png_representation, |
| const gfx::Rect& snapshot_bounds) { |
| - gfx::Display display = |
| - gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| - gfx::Rect scaled_bounds = |
| - gfx::ScaleToEnclosingRect(snapshot_bounds, |
| - display.device_scale_factor()); |
| - return window->GrabSnapshot( |
| - scaled_bounds.x(), scaled_bounds.y(), scaled_bounds.width(), |
| - scaled_bounds.height(), png_representation); |
| + // Not supported in Android. Callers should fall back to the async version. |
| + return false; |
| +} |
| + |
| +static void MakeAsyncCopyRequest( |
| + gfx::NativeWindow window, |
| + const gfx::Rect& source_rect, |
| + const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { |
| + scoped_ptr<cc::CopyOutputRequest> request = |
| + cc::CopyOutputRequest::CreateBitmapRequest(callback); |
| + request->set_area(source_rect); |
| + window->GetCompositor()->RequestCopyOfOutputOnRootLayer(request.Pass()); |
| } |
| void GrabWindowSnapshotAndScaleAsync( |
| gfx::NativeWindow window, |
| - const gfx::Rect& snapshot_bounds, |
| + const gfx::Rect& source_rect, |
| const gfx::Size& target_size, |
| scoped_refptr<base::TaskRunner> background_task_runner, |
| - GrabWindowSnapshotAsyncCallback callback) { |
| - callback.Run(gfx::Image()); |
| + const GrabWindowSnapshotAsyncCallback& callback) { |
| + MakeAsyncCopyRequest(window, |
| + source_rect, |
| + base::Bind(&SnapshotAsync::ScaleCopyOutputResult, |
| + callback, |
| + target_size, |
| + background_task_runner)); |
| } |
| -void GrabViewSnapshotAsync( |
| - gfx::NativeView view, |
| +void GrabWindowSnapshotAsync( |
| + gfx::NativeWindow window, |
| const gfx::Rect& source_rect, |
| scoped_refptr<base::TaskRunner> background_task_runner, |
| const GrabWindowSnapshotAsyncPNGCallback& callback) { |
| - callback.Run(scoped_refptr<base::RefCountedBytes>()); |
| + MakeAsyncCopyRequest(window, |
| + source_rect, |
| + base::Bind(&SnapshotAsync::EncodeCopyOutputResult, |
| + callback, |
| + background_task_runner)); |
| } |
| -void GrabWindowSnapshotAsync( |
| - gfx::NativeWindow window, |
| +void GrabViewSnapshotAsync( |
| + gfx::NativeView view, |
| const gfx::Rect& source_rect, |
| scoped_refptr<base::TaskRunner> background_task_runner, |
| const GrabWindowSnapshotAsyncPNGCallback& callback) { |
| - callback.Run(scoped_refptr<base::RefCountedBytes>()); |
| + GrabWindowSnapshotAsync( |
| + view->GetWindowAndroid(), source_rect, background_task_runner, callback); |
| } |
| } // namespace ui |