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