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/bind.h" | 7 #include "base/bind.h" |
8 #include "cc/output/copy_output_request.h" | 8 #include "cc/output/copy_output_request.h" |
9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
10 #include "ui/base/android/view_android.h" | 10 #include "ui/base/android/view_android.h" |
11 #include "ui/base/android/window_android.h" | 11 #include "ui/base/android/window_android.h" |
12 #include "ui/base/android/window_android_compositor.h" | 12 #include "ui/base/android/window_android_compositor.h" |
13 #include "ui/gfx/display.h" | 13 #include "ui/gfx/display.h" |
| 14 #include "ui/gfx/geometry/point_conversions.h" |
14 #include "ui/gfx/geometry/rect_conversions.h" | 15 #include "ui/gfx/geometry/rect_conversions.h" |
15 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
16 #include "ui/snapshot/snapshot_async.h" | 17 #include "ui/snapshot/snapshot_async.h" |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
19 | 20 |
20 bool GrabViewSnapshot(gfx::NativeView view, | 21 bool GrabViewSnapshot(gfx::NativeView view, |
21 std::vector<unsigned char>* png_representation, | 22 std::vector<unsigned char>* png_representation, |
22 const gfx::Rect& snapshot_bounds) { | 23 const gfx::Rect& snapshot_bounds) { |
23 return GrabWindowSnapshot( | 24 return GrabWindowSnapshot( |
(...skipping 13 matching lines...) Expand all Loading... |
37 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { | 38 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { |
38 scoped_ptr<cc::CopyOutputRequest> request = | 39 scoped_ptr<cc::CopyOutputRequest> request = |
39 cc::CopyOutputRequest::CreateBitmapRequest(callback); | 40 cc::CopyOutputRequest::CreateBitmapRequest(callback); |
40 | 41 |
41 const gfx::Display& display = | 42 const gfx::Display& display = |
42 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 43 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
43 float device_scale_factor = display.device_scale_factor(); | 44 float device_scale_factor = display.device_scale_factor(); |
44 gfx::Rect source_rect_in_pixel = | 45 gfx::Rect source_rect_in_pixel = |
45 gfx::ToEnclosingRect(gfx::ScaleRect(source_rect, device_scale_factor)); | 46 gfx::ToEnclosingRect(gfx::ScaleRect(source_rect, device_scale_factor)); |
46 | 47 |
47 request->set_area(source_rect_in_pixel); | 48 // Account for the toolbar offset. |
| 49 gfx::Vector2dF offset = window->content_offset(); |
| 50 gfx::Rect adjusted_source_rect(gfx::ToRoundedPoint( |
| 51 gfx::PointF(source_rect_in_pixel.x() + offset.x(), |
| 52 source_rect_in_pixel.y() + offset.y())), |
| 53 source_rect_in_pixel.size()); |
| 54 |
| 55 request->set_area(adjusted_source_rect); |
48 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(request.Pass()); | 56 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(request.Pass()); |
49 } | 57 } |
50 | 58 |
51 void GrabWindowSnapshotAndScaleAsync( | 59 void GrabWindowSnapshotAndScaleAsync( |
52 gfx::NativeWindow window, | 60 gfx::NativeWindow window, |
53 const gfx::Rect& source_rect, | 61 const gfx::Rect& source_rect, |
54 const gfx::Size& target_size, | 62 const gfx::Size& target_size, |
55 scoped_refptr<base::TaskRunner> background_task_runner, | 63 scoped_refptr<base::TaskRunner> background_task_runner, |
56 const GrabWindowSnapshotAsyncCallback& callback) { | 64 const GrabWindowSnapshotAsyncCallback& callback) { |
57 MakeAsyncCopyRequest(window, | 65 MakeAsyncCopyRequest(window, |
(...skipping 19 matching lines...) Expand all Loading... |
77 void GrabViewSnapshotAsync( | 85 void GrabViewSnapshotAsync( |
78 gfx::NativeView view, | 86 gfx::NativeView view, |
79 const gfx::Rect& source_rect, | 87 const gfx::Rect& source_rect, |
80 scoped_refptr<base::TaskRunner> background_task_runner, | 88 scoped_refptr<base::TaskRunner> background_task_runner, |
81 const GrabWindowSnapshotAsyncPNGCallback& callback) { | 89 const GrabWindowSnapshotAsyncPNGCallback& callback) { |
82 GrabWindowSnapshotAsync( | 90 GrabWindowSnapshotAsync( |
83 view->GetWindowAndroid(), source_rect, background_task_runner, callback); | 91 view->GetWindowAndroid(), source_rect, background_task_runner, callback); |
84 } | 92 } |
85 | 93 |
86 } // namespace ui | 94 } // namespace ui |
OLD | NEW |