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