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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "cc/output/copy_output_request.h" | 11 #include "cc/output/copy_output_request.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "ui/android/view_android.h" | 13 #include "ui/android/view_android.h" |
14 #include "ui/android/window_android.h" | 14 #include "ui/android/window_android.h" |
15 #include "ui/android/window_android_compositor.h" | 15 #include "ui/android/window_android_compositor.h" |
16 #include "ui/gfx/display.h" | 16 #include "ui/display/display.h" |
| 17 #include "ui/display/screen.h" |
17 #include "ui/gfx/geometry/point_conversions.h" | 18 #include "ui/gfx/geometry/point_conversions.h" |
18 #include "ui/gfx/geometry/rect_conversions.h" | 19 #include "ui/gfx/geometry/rect_conversions.h" |
19 #include "ui/gfx/screen.h" | |
20 #include "ui/snapshot/snapshot_async.h" | 20 #include "ui/snapshot/snapshot_async.h" |
21 | 21 |
22 namespace ui { | 22 namespace ui { |
23 | 23 |
24 bool GrabViewSnapshot(gfx::NativeView view, | 24 bool GrabViewSnapshot(gfx::NativeView view, |
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 return GrabWindowSnapshot( | 27 return GrabWindowSnapshot( |
28 view->GetWindowAndroid(), png_representation, snapshot_bounds); | 28 view->GetWindowAndroid(), png_representation, snapshot_bounds); |
29 } | 29 } |
30 | 30 |
31 bool GrabWindowSnapshot(gfx::NativeWindow window, | 31 bool GrabWindowSnapshot(gfx::NativeWindow window, |
32 std::vector<unsigned char>* png_representation, | 32 std::vector<unsigned char>* png_representation, |
33 const gfx::Rect& snapshot_bounds) { | 33 const gfx::Rect& snapshot_bounds) { |
34 // Not supported in Android. Callers should fall back to the async version. | 34 // Not supported in Android. Callers should fall back to the async version. |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 static void MakeAsyncCopyRequest( | 38 static void MakeAsyncCopyRequest( |
39 gfx::NativeWindow window, | 39 gfx::NativeWindow window, |
40 const gfx::Rect& source_rect, | 40 const gfx::Rect& source_rect, |
41 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { | 41 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { |
42 std::unique_ptr<cc::CopyOutputRequest> request = | 42 std::unique_ptr<cc::CopyOutputRequest> request = |
43 cc::CopyOutputRequest::CreateBitmapRequest(callback); | 43 cc::CopyOutputRequest::CreateBitmapRequest(callback); |
44 | 44 |
45 const gfx::Display& display = gfx::Screen::GetScreen()->GetPrimaryDisplay(); | 45 const display::Display& display = |
| 46 display::Screen::GetScreen()->GetPrimaryDisplay(); |
46 float device_scale_factor = display.device_scale_factor(); | 47 float device_scale_factor = display.device_scale_factor(); |
47 gfx::Rect source_rect_in_pixel = | 48 gfx::Rect source_rect_in_pixel = |
48 gfx::ScaleToEnclosingRect(source_rect, device_scale_factor); | 49 gfx::ScaleToEnclosingRect(source_rect, device_scale_factor); |
49 | 50 |
50 // Account for the toolbar offset. | 51 // Account for the toolbar offset. |
51 gfx::Vector2dF offset = window->content_offset(); | 52 gfx::Vector2dF offset = window->content_offset(); |
52 gfx::Rect adjusted_source_rect(gfx::ToRoundedPoint( | 53 gfx::Rect adjusted_source_rect(gfx::ToRoundedPoint( |
53 gfx::PointF(source_rect_in_pixel.x() + offset.x(), | 54 gfx::PointF(source_rect_in_pixel.x() + offset.x(), |
54 source_rect_in_pixel.y() + offset.y())), | 55 source_rect_in_pixel.y() + offset.y())), |
55 source_rect_in_pixel.size()); | 56 source_rect_in_pixel.size()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 void GrabViewSnapshotAsync( | 88 void GrabViewSnapshotAsync( |
88 gfx::NativeView view, | 89 gfx::NativeView view, |
89 const gfx::Rect& source_rect, | 90 const gfx::Rect& source_rect, |
90 scoped_refptr<base::TaskRunner> background_task_runner, | 91 scoped_refptr<base::TaskRunner> background_task_runner, |
91 const GrabWindowSnapshotAsyncPNGCallback& callback) { | 92 const GrabWindowSnapshotAsyncPNGCallback& callback) { |
92 GrabWindowSnapshotAsync( | 93 GrabWindowSnapshotAsync( |
93 view->GetWindowAndroid(), source_rect, background_task_runner, callback); | 94 view->GetWindowAndroid(), source_rect, background_task_runner, callback); |
94 } | 95 } |
95 | 96 |
96 } // namespace ui | 97 } // namespace ui |
OLD | NEW |