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

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

Issue 2739113002: Simplify calls for scale factor (Closed)
Patch Set: nit Created 3 years, 9 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/snapshot/DEPS ('k') | ui/views/cocoa/bridged_native_widget.mm » ('j') | 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 "base/task_runner.h" 11 #include "base/task_runner.h"
12 #include "cc/output/copy_output_request.h" 12 #include "cc/output/copy_output_request.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/android/view_android.h" 14 #include "ui/android/view_android.h"
15 #include "ui/android/window_android.h" 15 #include "ui/android/window_android.h"
16 #include "ui/android/window_android_compositor.h" 16 #include "ui/android/window_android_compositor.h"
17 #include "ui/display/display.h" 17 #include "ui/base/layout.h"
18 #include "ui/display/screen.h"
19 #include "ui/gfx/geometry/point_conversions.h" 18 #include "ui/gfx/geometry/point_conversions.h"
20 #include "ui/gfx/geometry/rect_conversions.h" 19 #include "ui/gfx/geometry/rect_conversions.h"
21 #include "ui/snapshot/snapshot_async.h" 20 #include "ui/snapshot/snapshot_async.h"
22 21
23 namespace ui { 22 namespace ui {
24 23
25 // Sync versions are not supported in Android. Callers should fall back 24 // Sync versions are not supported in Android. Callers should fall back
26 // to the async version. 25 // to the async version.
27 bool GrabViewSnapshot(gfx::NativeView view, 26 bool GrabViewSnapshot(gfx::NativeView view,
28 const gfx::Rect& snapshot_bounds, 27 const gfx::Rect& snapshot_bounds,
29 gfx::Image* image) { 28 gfx::Image* image) {
30 return GrabWindowSnapshot(view->GetWindowAndroid(), snapshot_bounds, image); 29 return GrabWindowSnapshot(view->GetWindowAndroid(), snapshot_bounds, image);
31 } 30 }
32 31
33 bool GrabWindowSnapshot(gfx::NativeWindow window, 32 bool GrabWindowSnapshot(gfx::NativeWindow window,
34 const gfx::Rect& snapshot_bounds, 33 const gfx::Rect& snapshot_bounds,
35 gfx::Image* image) { 34 gfx::Image* image) {
36 return false; 35 return false;
37 } 36 }
38 37
39 static void MakeAsyncCopyRequest( 38 static void MakeAsyncCopyRequest(
40 gfx::NativeWindow window, 39 gfx::NativeWindow window,
41 const gfx::Rect& source_rect, 40 const gfx::Rect& source_rect,
42 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { 41 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) {
43 std::unique_ptr<cc::CopyOutputRequest> request = 42 std::unique_ptr<cc::CopyOutputRequest> request =
44 cc::CopyOutputRequest::CreateBitmapRequest(callback); 43 cc::CopyOutputRequest::CreateBitmapRequest(callback);
45 44
46 const display::Display& display = 45 float scale = ui::GetScaleFactorForNativeView(window);
47 display::Screen::GetScreen()->GetDisplayNearestWindow(window);
48 float scale = display.device_scale_factor();
49 request->set_area(gfx::ScaleToEnclosingRect(source_rect, scale)); 46 request->set_area(gfx::ScaleToEnclosingRect(source_rect, scale));
50 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(std::move(request)); 47 window->GetCompositor()->RequestCopyOfOutputOnRootLayer(std::move(request));
51 } 48 }
52 49
53 void GrabWindowSnapshotAndScaleAsync( 50 void GrabWindowSnapshotAndScaleAsync(
54 gfx::NativeWindow window, 51 gfx::NativeWindow window,
55 const gfx::Rect& source_rect, 52 const gfx::Rect& source_rect,
56 const gfx::Size& target_size, 53 const gfx::Size& target_size,
57 scoped_refptr<base::TaskRunner> background_task_runner, 54 scoped_refptr<base::TaskRunner> background_task_runner,
58 const GrabWindowSnapshotAsyncCallback& callback) { 55 const GrabWindowSnapshotAsyncCallback& callback) {
(...skipping 15 matching lines...) Expand all
74 71
75 void GrabViewSnapshotAsync(gfx::NativeView view, 72 void GrabViewSnapshotAsync(gfx::NativeView view,
76 const gfx::Rect& source_rect, 73 const gfx::Rect& source_rect,
77 const GrabWindowSnapshotAsyncCallback& callback) { 74 const GrabWindowSnapshotAsyncCallback& callback) {
78 MakeAsyncCopyRequest( 75 MakeAsyncCopyRequest(
79 view->GetWindowAndroid(), source_rect, 76 view->GetWindowAndroid(), source_rect,
80 base::Bind(&SnapshotAsync::RunCallbackWithCopyOutputResult, callback)); 77 base::Bind(&SnapshotAsync::RunCallbackWithCopyOutputResult, callback));
81 } 78 }
82 79
83 } // namespace ui 80 } // namespace ui
OLDNEW
« no previous file with comments | « ui/snapshot/DEPS ('k') | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698