Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.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/display/display.h" | 16 #include "ui/display/display.h" |
| 17 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
| 18 #include "ui/gfx/geometry/point_conversions.h" | 18 #include "ui/gfx/geometry/point_conversions.h" |
| 19 #include "ui/gfx/geometry/rect_conversions.h" | 19 #include "ui/gfx/geometry/rect_conversions.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( |
|
no sievers
2016/08/05 18:15:14
You can actually fix this too here and call GrabVi
Jinsuk Kim
2016/12/22 12:35:48
This is for synchronous version which is not prefe
| |
| 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::Vector2dF& offset, | |
| 40 const gfx::Rect& source_rect, | 41 const gfx::Rect& source_rect, |
| 41 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { | 42 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { |
| 42 std::unique_ptr<cc::CopyOutputRequest> request = | 43 std::unique_ptr<cc::CopyOutputRequest> request = |
| 43 cc::CopyOutputRequest::CreateBitmapRequest(callback); | 44 cc::CopyOutputRequest::CreateBitmapRequest(callback); |
| 44 | 45 |
| 45 const display::Display& display = | 46 const display::Display& display = |
| 46 display::Screen::GetScreen()->GetPrimaryDisplay(); | 47 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 47 float device_scale_factor = display.device_scale_factor(); | 48 float device_scale_factor = display.device_scale_factor(); |
| 48 gfx::Rect source_rect_in_pixel = | 49 gfx::Rect source_rect_in_pixel = |
| 49 gfx::ScaleToEnclosingRect(source_rect, device_scale_factor); | 50 gfx::ScaleToEnclosingRect(source_rect, device_scale_factor); |
| 50 | 51 |
| 51 // Account for the toolbar offset. | 52 // Account for the toolbar offset. |
| 52 gfx::Vector2dF offset = window->content_offset(); | |
| 53 gfx::Rect adjusted_source_rect(gfx::ToRoundedPoint( | 53 gfx::Rect adjusted_source_rect(gfx::ToRoundedPoint( |
| 54 gfx::PointF(source_rect_in_pixel.x() + offset.x(), | 54 gfx::PointF(source_rect_in_pixel.x() + offset.x(), |
| 55 source_rect_in_pixel.y() + offset.y())), | 55 source_rect_in_pixel.y() + offset.y())), |
|
no sievers
2016/08/05 19:32:12
Argh, this code makes no sense.
The caller passes
no sievers
2016/08/05 19:38:26
Ah sorry, I was slightly off:
gfx::Rect RenderWid
| |
| 56 source_rect_in_pixel.size()); | 56 source_rect_in_pixel.size()); |
| 57 | 57 |
| 58 request->set_area(adjusted_source_rect); | 58 request->set_area(adjusted_source_rect); |
| 59 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(std::move(request)); | 59 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(std::move(request)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void GrabWindowSnapshotAndScaleAsync( | 62 void GrabWindowSnapshotAndScaleAsync( |
| 63 gfx::NativeWindow window, | 63 gfx::NativeWindow window, |
| 64 const gfx::Rect& source_rect, | 64 const gfx::Rect& source_rect, |
| 65 const gfx::Size& target_size, | 65 const gfx::Size& target_size, |
| 66 scoped_refptr<base::TaskRunner> background_task_runner, | 66 scoped_refptr<base::TaskRunner> background_task_runner, |
| 67 const GrabWindowSnapshotAsyncCallback& callback) { | 67 const GrabWindowSnapshotAsyncCallback& callback) { |
| 68 MakeAsyncCopyRequest(window, | 68 MakeAsyncCopyRequest(window, |
| 69 window->content_offset(), | |
| 69 source_rect, | 70 source_rect, |
| 70 base::Bind(&SnapshotAsync::ScaleCopyOutputResult, | 71 base::Bind(&SnapshotAsync::ScaleCopyOutputResult, |
| 71 callback, | 72 callback, |
| 72 target_size, | 73 target_size, |
| 73 background_task_runner)); | 74 background_task_runner)); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void GrabWindowSnapshotAsync( | 77 void GrabWindowSnapshotAsync( |
| 77 gfx::NativeWindow window, | 78 gfx::NativeWindow window, |
| 78 const gfx::Rect& source_rect, | 79 const gfx::Rect& source_rect, |
| 79 scoped_refptr<base::TaskRunner> background_task_runner, | 80 scoped_refptr<base::TaskRunner> background_task_runner, |
| 80 const GrabWindowSnapshotAsyncPNGCallback& callback) { | 81 const GrabWindowSnapshotAsyncPNGCallback& callback) { |
| 81 MakeAsyncCopyRequest(window, | 82 MakeAsyncCopyRequest(window, |
| 83 window->content_offset(), | |
| 82 source_rect, | 84 source_rect, |
| 83 base::Bind(&SnapshotAsync::EncodeCopyOutputResult, | 85 base::Bind(&SnapshotAsync::EncodeCopyOutputResult, |
| 84 callback, | 86 callback, |
| 85 background_task_runner)); | 87 background_task_runner)); |
| 86 } | 88 } |
| 87 | 89 |
| 88 void GrabViewSnapshotAsync( | 90 void GrabViewSnapshotAsync( |
| 89 gfx::NativeView view, | 91 gfx::NativeView view, |
| 90 const gfx::Rect& source_rect, | 92 const gfx::Rect& source_rect, |
| 91 scoped_refptr<base::TaskRunner> background_task_runner, | 93 scoped_refptr<base::TaskRunner> background_task_runner, |
| 92 const GrabWindowSnapshotAsyncPNGCallback& callback) { | 94 const GrabWindowSnapshotAsyncPNGCallback& callback) { |
| 93 GrabWindowSnapshotAsync( | 95 MakeAsyncCopyRequest(view->GetWindowAndroid(), |
| 94 view->GetWindowAndroid(), source_rect, background_task_runner, callback); | 96 view->content_offset(), |
| 97 source_rect, | |
| 98 base::Bind(&SnapshotAsync::EncodeCopyOutputResult, | |
| 99 callback, | |
| 100 background_task_runner)); | |
| 95 } | 101 } |
| 96 | 102 |
| 97 } // namespace ui | 103 } // namespace ui |
| OLD | NEW |