| 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" | |
| 14 #include "ui/gfx/geometry/point_conversions.h" | 13 #include "ui/gfx/geometry/point_conversions.h" |
| 15 #include "ui/gfx/geometry/rect_conversions.h" | |
| 16 #include "ui/gfx/screen.h" | |
| 17 #include "ui/snapshot/snapshot_async.h" | 14 #include "ui/snapshot/snapshot_async.h" |
| 18 | 15 |
| 19 namespace ui { | 16 namespace ui { |
| 20 | 17 |
| 21 bool GrabViewSnapshot(gfx::NativeView view, | 18 bool GrabViewSnapshot(gfx::NativeView view, |
| 22 std::vector<unsigned char>* png_representation, | 19 std::vector<unsigned char>* png_representation, |
| 23 const gfx::Rect& snapshot_bounds) { | 20 const gfx::Rect& snapshot_bounds) { |
| 24 return GrabWindowSnapshot( | 21 return GrabWindowSnapshot( |
| 25 view->GetWindowAndroid(), png_representation, snapshot_bounds); | 22 view->GetWindowAndroid(), png_representation, snapshot_bounds); |
| 26 } | 23 } |
| 27 | 24 |
| 28 bool GrabWindowSnapshot(gfx::NativeWindow window, | 25 bool GrabWindowSnapshot(gfx::NativeWindow window, |
| 29 std::vector<unsigned char>* png_representation, | 26 std::vector<unsigned char>* png_representation, |
| 30 const gfx::Rect& snapshot_bounds) { | 27 const gfx::Rect& snapshot_bounds) { |
| 31 // Not supported in Android. Callers should fall back to the async version. | 28 // Not supported in Android. Callers should fall back to the async version. |
| 32 return false; | 29 return false; |
| 33 } | 30 } |
| 34 | 31 |
| 35 static void MakeAsyncCopyRequest( | 32 static void MakeAsyncCopyRequest( |
| 36 gfx::NativeWindow window, | 33 gfx::NativeWindow window, |
| 37 const gfx::Rect& source_rect, | 34 const gfx::Rect& source_rect, |
| 38 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { | 35 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { |
| 39 scoped_ptr<cc::CopyOutputRequest> request = | 36 scoped_ptr<cc::CopyOutputRequest> request = |
| 40 cc::CopyOutputRequest::CreateBitmapRequest(callback); | 37 cc::CopyOutputRequest::CreateBitmapRequest(callback); |
| 41 | 38 |
| 42 const gfx::Display& display = | |
| 43 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
| 44 float device_scale_factor = display.device_scale_factor(); | |
| 45 gfx::Rect source_rect_in_pixel = | |
| 46 gfx::ToEnclosingRect(gfx::ScaleRect(source_rect, device_scale_factor)); | |
| 47 | |
| 48 // Account for the toolbar offset. | 39 // Account for the toolbar offset. |
| 49 gfx::Vector2dF offset = window->content_offset(); | 40 gfx::Vector2dF offset = window->content_offset(); |
| 50 gfx::Rect adjusted_source_rect(gfx::ToRoundedPoint( | 41 gfx::Rect adjusted_source_rect( |
| 51 gfx::PointF(source_rect_in_pixel.x() + offset.x(), | 42 gfx::ToRoundedPoint(gfx::PointF(source_rect.x() + offset.x(), |
| 52 source_rect_in_pixel.y() + offset.y())), | 43 source_rect.y() + offset.y())), |
| 53 source_rect_in_pixel.size()); | 44 source_rect.size()); |
| 54 | 45 |
| 55 request->set_area(adjusted_source_rect); | 46 request->set_area(adjusted_source_rect); |
| 56 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(request.Pass()); | 47 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(request.Pass()); |
| 57 } | 48 } |
| 58 | 49 |
| 59 void GrabWindowSnapshotAndScaleAsync( | 50 void GrabWindowSnapshotAndScaleAsync( |
| 60 gfx::NativeWindow window, | 51 gfx::NativeWindow window, |
| 61 const gfx::Rect& source_rect, | 52 const gfx::Rect& source_rect, |
| 62 const gfx::Size& target_size, | 53 const gfx::Size& target_size, |
| 63 scoped_refptr<base::TaskRunner> background_task_runner, | 54 scoped_refptr<base::TaskRunner> background_task_runner, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 85 void GrabViewSnapshotAsync( | 76 void GrabViewSnapshotAsync( |
| 86 gfx::NativeView view, | 77 gfx::NativeView view, |
| 87 const gfx::Rect& source_rect, | 78 const gfx::Rect& source_rect, |
| 88 scoped_refptr<base::TaskRunner> background_task_runner, | 79 scoped_refptr<base::TaskRunner> background_task_runner, |
| 89 const GrabWindowSnapshotAsyncPNGCallback& callback) { | 80 const GrabWindowSnapshotAsyncPNGCallback& callback) { |
| 90 GrabWindowSnapshotAsync( | 81 GrabWindowSnapshotAsync( |
| 91 view->GetWindowAndroid(), source_rect, background_task_runner, callback); | 82 view->GetWindowAndroid(), source_rect, background_task_runner, callback); |
| 92 } | 83 } |
| 93 | 84 |
| 94 } // namespace ui | 85 } // namespace ui |
| OLD | NEW |