Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: ui/snapshot/snapshot_android.cc

Issue 2219823002: Move content offset to ViewAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/android/window_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Sync versions are not supported in Android. Callers should fall back
25 // to the async version.
24 bool GrabViewSnapshot(gfx::NativeView view, 26 bool GrabViewSnapshot(gfx::NativeView view,
25 std::vector<unsigned char>* png_representation, 27 std::vector<unsigned char>* png_representation,
26 const gfx::Rect& snapshot_bounds) { 28 const gfx::Rect& snapshot_bounds) {
27 return GrabWindowSnapshot( 29 return GrabWindowSnapshot(
28 view->GetWindowAndroid(), png_representation, snapshot_bounds); 30 view->GetWindowAndroid(), png_representation, snapshot_bounds);
29 } 31 }
30 32
31 bool GrabWindowSnapshot(gfx::NativeWindow window, 33 bool GrabWindowSnapshot(gfx::NativeWindow window,
32 std::vector<unsigned char>* png_representation, 34 std::vector<unsigned char>* png_representation,
33 const gfx::Rect& snapshot_bounds) { 35 const gfx::Rect& snapshot_bounds) {
34 // Not supported in Android. Callers should fall back to the async version.
35 return false; 36 return false;
36 } 37 }
37 38
38 static void MakeAsyncCopyRequest( 39 static void MakeAsyncCopyRequest(
39 gfx::NativeWindow window, 40 gfx::NativeWindow window,
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()->GetDisplayNearestWindow(window); 47 display::Screen::GetScreen()->GetDisplayNearestWindow(window);
47 float device_scale_factor = display.device_scale_factor(); 48 float scale = display.device_scale_factor();
48 gfx::Rect source_rect_in_pixel = 49 request->set_area(gfx::ScaleToEnclosingRect(source_rect, scale));
49 gfx::ScaleToEnclosingRect(source_rect, device_scale_factor);
50
51 // Account for the toolbar offset.
52 gfx::Vector2dF offset_in_pixel =
53 gfx::ScaleVector2d(window->content_offset(), device_scale_factor);
54 gfx::Rect adjusted_source_rect(
55 gfx::ToRoundedPoint(
56 gfx::PointF(source_rect_in_pixel.x() + offset_in_pixel.x(),
57 source_rect_in_pixel.y() + offset_in_pixel.y())),
58 source_rect_in_pixel.size());
59
60 request->set_area(adjusted_source_rect);
61 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(std::move(request)); 50 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(std::move(request));
62 } 51 }
63 52
64 void GrabWindowSnapshotAndScaleAsync( 53 void GrabWindowSnapshotAndScaleAsync(
65 gfx::NativeWindow window, 54 gfx::NativeWindow window,
66 const gfx::Rect& source_rect, 55 const gfx::Rect& source_rect,
67 const gfx::Size& target_size, 56 const gfx::Size& target_size,
68 scoped_refptr<base::TaskRunner> background_task_runner, 57 scoped_refptr<base::TaskRunner> background_task_runner,
69 const GrabWindowSnapshotAsyncCallback& callback) { 58 const GrabWindowSnapshotAsyncCallback& callback) {
70 MakeAsyncCopyRequest(window, 59 MakeAsyncCopyRequest(window,
(...skipping 14 matching lines...) Expand all
85 base::Bind(&SnapshotAsync::EncodeCopyOutputResult, 74 base::Bind(&SnapshotAsync::EncodeCopyOutputResult,
86 callback, 75 callback,
87 background_task_runner)); 76 background_task_runner));
88 } 77 }
89 78
90 void GrabViewSnapshotAsync( 79 void GrabViewSnapshotAsync(
91 gfx::NativeView view, 80 gfx::NativeView view,
92 const gfx::Rect& source_rect, 81 const gfx::Rect& source_rect,
93 scoped_refptr<base::TaskRunner> background_task_runner, 82 scoped_refptr<base::TaskRunner> background_task_runner,
94 const GrabWindowSnapshotAsyncPNGCallback& callback) { 83 const GrabWindowSnapshotAsyncPNGCallback& callback) {
95 GrabWindowSnapshotAsync( 84 MakeAsyncCopyRequest(view->GetWindowAndroid(),
96 view->GetWindowAndroid(), source_rect, background_task_runner, callback); 85 source_rect,
86 base::Bind(&SnapshotAsync::EncodeCopyOutputResult,
87 callback,
88 background_task_runner));
97 } 89 }
98 90
99 } // namespace ui 91 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/window_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698