OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/snapshot/snapshot.h" | 5 #include "ui/snapshot/snapshot.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/bind.h" |
| 8 #include "cc/output/copy_output_request.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "ui/base/android/view_android.h" | 10 #include "ui/base/android/view_android.h" |
9 #include "ui/base/android/window_android.h" | 11 #include "ui/base/android/window_android.h" |
10 #include "ui/gfx/display.h" | 12 #include "ui/base/android/window_android_compositor.h" |
11 #include "ui/gfx/image/image.h" | 13 #include "ui/snapshot/snapshot_async.h" |
12 #include "ui/gfx/rect.h" | |
13 #include "ui/gfx/screen.h" | |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 | 16 |
17 bool GrabViewSnapshot(gfx::NativeView view, | 17 bool GrabViewSnapshot(gfx::NativeView view, |
18 std::vector<unsigned char>* png_representation, | 18 std::vector<unsigned char>* png_representation, |
19 const gfx::Rect& snapshot_bounds) { | 19 const gfx::Rect& snapshot_bounds) { |
20 return GrabWindowSnapshot( | 20 return GrabWindowSnapshot( |
21 view->GetWindowAndroid(), png_representation, snapshot_bounds); | 21 view->GetWindowAndroid(), png_representation, snapshot_bounds); |
22 } | 22 } |
23 | 23 |
24 bool GrabWindowSnapshot(gfx::NativeWindow window, | 24 bool GrabWindowSnapshot(gfx::NativeWindow window, |
25 std::vector<unsigned char>* png_representation, | 25 std::vector<unsigned char>* png_representation, |
26 const gfx::Rect& snapshot_bounds) { | 26 const gfx::Rect& snapshot_bounds) { |
27 gfx::Display display = | 27 // Not supported in Android. Callers should fall back to the async version. |
28 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 28 return false; |
29 gfx::Rect scaled_bounds = | 29 } |
30 gfx::ScaleToEnclosingRect(snapshot_bounds, | 30 |
31 display.device_scale_factor()); | 31 static void MakeAsyncCopyRequest( |
32 return window->GrabSnapshot( | 32 gfx::NativeWindow window, |
33 scaled_bounds.x(), scaled_bounds.y(), scaled_bounds.width(), | 33 const gfx::Rect& source_rect, |
34 scaled_bounds.height(), png_representation); | 34 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { |
| 35 scoped_ptr<cc::CopyOutputRequest> request = |
| 36 cc::CopyOutputRequest::CreateBitmapRequest(callback); |
| 37 request->set_area(source_rect); |
| 38 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(request.Pass()); |
35 } | 39 } |
36 | 40 |
37 void GrabWindowSnapshotAndScaleAsync( | 41 void GrabWindowSnapshotAndScaleAsync( |
38 gfx::NativeWindow window, | 42 gfx::NativeWindow window, |
39 const gfx::Rect& snapshot_bounds, | 43 const gfx::Rect& source_rect, |
40 const gfx::Size& target_size, | 44 const gfx::Size& target_size, |
41 scoped_refptr<base::TaskRunner> background_task_runner, | 45 scoped_refptr<base::TaskRunner> background_task_runner, |
42 GrabWindowSnapshotAsyncCallback callback) { | 46 const GrabWindowSnapshotAsyncCallback& callback) { |
43 callback.Run(gfx::Image()); | 47 MakeAsyncCopyRequest(window, |
| 48 source_rect, |
| 49 base::Bind(&SnapshotAsync::ScaleCopyOutputResult, |
| 50 callback, |
| 51 target_size, |
| 52 background_task_runner)); |
| 53 } |
| 54 |
| 55 void GrabWindowSnapshotAsync( |
| 56 gfx::NativeWindow window, |
| 57 const gfx::Rect& source_rect, |
| 58 scoped_refptr<base::TaskRunner> background_task_runner, |
| 59 const GrabWindowSnapshotAsyncPNGCallback& callback) { |
| 60 MakeAsyncCopyRequest(window, |
| 61 source_rect, |
| 62 base::Bind(&SnapshotAsync::EncodeCopyOutputResult, |
| 63 callback, |
| 64 background_task_runner)); |
44 } | 65 } |
45 | 66 |
46 void GrabViewSnapshotAsync( | 67 void GrabViewSnapshotAsync( |
47 gfx::NativeView view, | 68 gfx::NativeView view, |
48 const gfx::Rect& source_rect, | 69 const gfx::Rect& source_rect, |
49 scoped_refptr<base::TaskRunner> background_task_runner, | 70 scoped_refptr<base::TaskRunner> background_task_runner, |
50 const GrabWindowSnapshotAsyncPNGCallback& callback) { | 71 const GrabWindowSnapshotAsyncPNGCallback& callback) { |
51 callback.Run(scoped_refptr<base::RefCountedBytes>()); | 72 GrabWindowSnapshotAsync( |
52 } | 73 view->GetWindowAndroid(), source_rect, background_task_runner, callback); |
53 | |
54 void GrabWindowSnapshotAsync( | |
55 gfx::NativeWindow window, | |
56 const gfx::Rect& source_rect, | |
57 scoped_refptr<base::TaskRunner> background_task_runner, | |
58 const GrabWindowSnapshotAsyncPNGCallback& callback) { | |
59 callback.Run(scoped_refptr<base::RefCountedBytes>()); | |
60 } | 74 } |
61 | 75 |
62 } // namespace ui | 76 } // namespace ui |
OLD | NEW |