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_aura.h" | 5 #include "ui/snapshot/snapshot_aura.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace ui { | 22 namespace ui { |
23 | 23 |
24 bool GrabWindowSnapshotAura(aura::Window* window, | 24 bool GrabWindowSnapshotAura(aura::Window* window, |
25 const gfx::Rect& snapshot_bounds, | 25 const gfx::Rect& snapshot_bounds, |
26 gfx::Image* image) { | 26 gfx::Image* image) { |
27 // Not supported in Aura. Callers should fall back to the async version. | 27 // Not supported in Aura. Callers should fall back to the async version. |
28 return false; | 28 return false; |
29 } | 29 } |
30 | 30 |
31 static void MakeAsyncCopyRequest( | 31 static void MakeAsyncCopyRequest( |
32 aura::Window* window, | 32 Layer* layer, |
33 const gfx::Rect& source_rect, | 33 const gfx::Rect& source_rect, |
34 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { | 34 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { |
35 std::unique_ptr<cc::CopyOutputRequest> request = | 35 std::unique_ptr<cc::CopyOutputRequest> request = |
36 cc::CopyOutputRequest::CreateBitmapRequest(callback); | 36 cc::CopyOutputRequest::CreateBitmapRequest(callback); |
37 request->set_area(source_rect); | 37 request->set_area(source_rect); |
38 window->layer()->RequestCopyOfOutput(std::move(request)); | 38 layer->RequestCopyOfOutput(std::move(request)); |
39 } | 39 } |
40 | 40 |
41 static void FinishedAsyncCopyRequest( | 41 static void FinishedAsyncCopyRequest( |
42 std::unique_ptr<aura::WindowTracker> tracker, | 42 std::unique_ptr<aura::WindowTracker> tracker, |
43 const gfx::Rect& source_rect, | 43 const gfx::Rect& source_rect, |
44 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback, | 44 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback, |
45 int retry_count, | 45 int retry_count, |
46 std::unique_ptr<cc::CopyOutputResult> result) { | 46 std::unique_ptr<cc::CopyOutputResult> result) { |
47 static const int kMaxRetries = 5; | 47 static const int kMaxRetries = 5; |
48 // Retry the copy request if the previous one failed for some reason. | 48 // Retry the copy request if the previous one failed for some reason. |
49 if (!tracker->windows().empty() && (retry_count < kMaxRetries) && | 49 if (!tracker->windows().empty() && (retry_count < kMaxRetries) && |
50 result->IsEmpty()) { | 50 result->IsEmpty()) { |
51 // Look up window before calling MakeAsyncRequest. Otherwise, due | 51 // Look up window before calling MakeAsyncRequest. Otherwise, due |
52 // to undefined (favorably right to left) argument evaluation | 52 // to undefined (favorably right to left) argument evaluation |
53 // order, the tracker might have been passed and set to NULL | 53 // order, the tracker might have been passed and set to NULL |
54 // before the window is looked up which results in a NULL pointer | 54 // before the window is looked up which results in a NULL pointer |
55 // dereference. | 55 // dereference. |
56 aura::Window* window = tracker->windows()[0]; | 56 aura::Window* window = tracker->windows()[0]; |
57 MakeAsyncCopyRequest( | 57 MakeAsyncCopyRequest( |
58 window, source_rect, | 58 window->layer(), source_rect, |
59 base::Bind(&FinishedAsyncCopyRequest, base::Passed(&tracker), | 59 base::Bind(&FinishedAsyncCopyRequest, base::Passed(&tracker), |
60 source_rect, callback, retry_count + 1)); | 60 source_rect, callback, retry_count + 1)); |
61 return; | 61 return; |
62 } | 62 } |
63 | 63 |
64 callback.Run(std::move(result)); | 64 callback.Run(std::move(result)); |
65 } | 65 } |
66 | 66 |
67 static void MakeInitialAsyncCopyRequest( | 67 static void MakeInitialAsyncCopyRequest( |
68 aura::Window* window, | 68 aura::Window* window, |
69 const gfx::Rect& source_rect, | 69 const gfx::Rect& source_rect, |
70 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { | 70 const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) { |
71 auto tracker = base::MakeUnique<aura::WindowTracker>(); | 71 auto tracker = base::MakeUnique<aura::WindowTracker>(); |
72 tracker->Add(window); | 72 tracker->Add(window); |
73 MakeAsyncCopyRequest( | 73 MakeAsyncCopyRequest( |
74 window, source_rect, | 74 window->layer(), source_rect, |
75 base::Bind(&FinishedAsyncCopyRequest, base::Passed(&tracker), source_rect, | 75 base::Bind(&FinishedAsyncCopyRequest, base::Passed(&tracker), source_rect, |
76 callback, 0)); | 76 callback, 0)); |
77 } | 77 } |
78 | 78 |
79 void GrabWindowSnapshotAndScaleAsyncAura( | 79 void GrabWindowSnapshotAndScaleAsyncAura( |
80 aura::Window* window, | 80 aura::Window* window, |
81 const gfx::Rect& source_rect, | 81 const gfx::Rect& source_rect, |
82 const gfx::Size& target_size, | 82 const gfx::Size& target_size, |
83 scoped_refptr<base::TaskRunner> background_task_runner, | 83 scoped_refptr<base::TaskRunner> background_task_runner, |
84 const GrabWindowSnapshotAsyncCallback& callback) { | 84 const GrabWindowSnapshotAsyncCallback& callback) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 const GrabWindowSnapshotAsyncCallback& callback) { | 126 const GrabWindowSnapshotAsyncCallback& callback) { |
127 GrabWindowSnapshotAsyncAura(window, source_rect, callback); | 127 GrabWindowSnapshotAsyncAura(window, source_rect, callback); |
128 } | 128 } |
129 | 129 |
130 void GrabViewSnapshotAsync(gfx::NativeView view, | 130 void GrabViewSnapshotAsync(gfx::NativeView view, |
131 const gfx::Rect& source_rect, | 131 const gfx::Rect& source_rect, |
132 const GrabWindowSnapshotAsyncCallback& callback) { | 132 const GrabWindowSnapshotAsyncCallback& callback) { |
133 GrabWindowSnapshotAsyncAura(view, source_rect, callback); | 133 GrabWindowSnapshotAsyncAura(view, source_rect, callback); |
134 } | 134 } |
135 | 135 |
| 136 void GrabLayerSnapshotAsync(ui::Layer* layer, |
| 137 const gfx::Rect& source_rect, |
| 138 const GrabLayerOwnerSnapshotCallback& callback) { |
| 139 MakeAsyncCopyRequest( |
| 140 layer, source_rect, |
| 141 base::Bind(&SnapshotAsync::RunCallbackWithCopyOutputResult, callback)); |
| 142 } |
| 143 |
136 #endif | 144 #endif |
137 | 145 |
138 } // namespace ui | 146 } // namespace ui |
OLD | NEW |