OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/media/capture/desktop_capture_device_aura.h" | 5 #include "content/browser/media/capture/aura_window_capture_machine.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
11 #include "cc/output/copy_output_result.h" | 11 #include "cc/output/copy_output_result.h" |
12 #include "content/browser/compositor/image_transport_factory.h" | 12 #include "content/browser/compositor/image_transport_factory.h" |
13 #include "content/browser/media/capture/content_video_capture_device_core.h" | 13 #include "content/browser/media/capture/content_video_capture_device_core.h" |
14 #include "content/browser/media/capture/desktop_capture_device_aura.h" | |
14 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" | 15 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
15 #include "content/common/gpu/client/gl_helper.h" | 16 #include "content/common/gpu/client/gl_helper.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/power_save_blocker.h" | 18 #include "content/public/browser/power_save_blocker.h" |
18 #include "media/base/video_capture_types.h" | 19 #include "media/base/video_capture_types.h" |
19 #include "media/base/video_util.h" | 20 #include "media/base/video_util.h" |
20 #include "skia/ext/image_operations.h" | 21 #include "skia/ext/image_operations.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
22 #include "ui/aura/client/screen_position_client.h" | 23 #include "ui/aura/client/screen_position_client.h" |
23 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 int color_v = clip_byte(((color_r * 112 + color_g * -94 + | 83 int color_v = clip_byte(((color_r * 112 + color_g * -94 + |
83 color_b * -18 + 128) >> 8) + 128); | 84 color_b * -18 + 128) >> 8) + 128); |
84 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); | 85 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); |
85 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); | 86 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); |
86 } | 87 } |
87 } | 88 } |
88 } | 89 } |
89 cursor_bitmap.unlockPixels(); | 90 cursor_bitmap.unlockPixels(); |
90 } | 91 } |
91 | 92 |
92 class DesktopVideoCaptureMachine | 93 void CopyOutputFinishedForVideo( |
93 : public VideoCaptureMachine, | 94 base::TimeTicks start_time, |
94 public aura::WindowObserver, | 95 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
95 public ui::CompositorObserver, | 96 const scoped_refptr<media::VideoFrame>& target, |
96 public base::SupportsWeakPtr<DesktopVideoCaptureMachine> { | 97 const SkBitmap& cursor_bitmap, |
97 public: | 98 const gfx::Point& cursor_position, |
98 DesktopVideoCaptureMachine(const DesktopMediaID& source); | 99 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
99 ~DesktopVideoCaptureMachine() override; | 100 bool result) { |
101 if (!cursor_bitmap.isNull()) | |
102 RenderCursorOnVideoFrame(target, cursor_bitmap, cursor_position); | |
103 release_callback->Run(0, false); | |
104 capture_frame_cb.Run(target, start_time, result); | |
105 } | |
100 | 106 |
101 // VideoCaptureFrameSource overrides. | 107 void RunSingleReleaseCallback(scoped_ptr<cc::SingleReleaseCallback> cb, |
102 bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 108 uint32 sync_point) { |
103 const media::VideoCaptureParams& params) override; | 109 cb->Run(sync_point, false); |
104 void Stop(const base::Closure& callback) override; | 110 } |
105 | 111 |
106 // Implements aura::WindowObserver. | 112 } // namespace |
107 void OnWindowBoundsChanged(aura::Window* window, | |
108 const gfx::Rect& old_bounds, | |
109 const gfx::Rect& new_bounds) override; | |
110 void OnWindowDestroyed(aura::Window* window) override; | |
111 void OnWindowAddedToRootWindow(aura::Window* window) override; | |
112 void OnWindowRemovingFromRootWindow(aura::Window* window, | |
113 aura::Window* new_root) override; | |
114 | 113 |
115 // Implements ui::CompositorObserver. | 114 AuraWindowCaptureMachine::AuraWindowCaptureMachine() |
116 void OnCompositingDidCommit(ui::Compositor* compositor) override {} | |
117 void OnCompositingStarted(ui::Compositor* compositor, | |
118 base::TimeTicks start_time) override {} | |
119 void OnCompositingEnded(ui::Compositor* compositor) override; | |
120 void OnCompositingAborted(ui::Compositor* compositor) override {} | |
121 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {} | |
122 void OnCompositingShuttingDown(ui::Compositor* compositor) override {} | |
123 | |
124 private: | |
125 // Captures a frame. | |
126 // |dirty| is false for timer polls and true for compositor updates. | |
127 void Capture(bool dirty); | |
128 | |
129 // Update capture size. Must be called on the UI thread. | |
130 void UpdateCaptureSize(); | |
131 | |
132 // Response callback for cc::Layer::RequestCopyOfOutput(). | |
133 void DidCopyOutput( | |
134 scoped_refptr<media::VideoFrame> video_frame, | |
135 base::TimeTicks start_time, | |
136 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | |
137 scoped_ptr<cc::CopyOutputResult> result); | |
138 | |
139 // A helper which does the real work for DidCopyOutput. Returns true if | |
140 // succeeded. | |
141 bool ProcessCopyOutputResponse( | |
142 scoped_refptr<media::VideoFrame> video_frame, | |
143 base::TimeTicks start_time, | |
144 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | |
145 scoped_ptr<cc::CopyOutputResult> result); | |
146 | |
147 // Helper function to update cursor state. | |
148 // |region_in_frame| defines where the desktop is rendered in the captured | |
149 // frame. | |
150 // Returns the current cursor position in captured frame. | |
151 gfx::Point UpdateCursorState(const gfx::Rect& region_in_frame); | |
152 | |
153 // Clears cursor state. | |
154 void ClearCursorState(); | |
155 | |
156 // The window associated with the desktop. | |
157 aura::Window* desktop_window_; | |
158 | |
159 // The timer that kicks off period captures. | |
160 base::Timer timer_; | |
161 | |
162 // The id of the window being captured. | |
163 DesktopMediaID window_id_; | |
164 | |
165 // Makes all the decisions about which frames to copy, and how. | |
166 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; | |
167 | |
168 // The capture parameters for this capture. | |
169 media::VideoCaptureParams capture_params_; | |
170 | |
171 // YUV readback pipeline. | |
172 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; | |
173 | |
174 // Cursor state. | |
175 ui::Cursor last_cursor_; | |
176 gfx::Size desktop_size_when_cursor_last_updated_; | |
177 gfx::Point cursor_hot_point_; | |
178 SkBitmap scaled_cursor_bitmap_; | |
179 | |
180 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the | |
181 // screen from sleeping for the drive-by web. | |
182 scoped_ptr<PowerSaveBlocker> power_save_blocker_; | |
183 | |
184 DISALLOW_COPY_AND_ASSIGN(DesktopVideoCaptureMachine); | |
185 }; | |
186 | |
187 DesktopVideoCaptureMachine::DesktopVideoCaptureMachine( | |
188 const DesktopMediaID& source) | |
189 : desktop_window_(NULL), | 115 : desktop_window_(NULL), |
190 timer_(true, true), | 116 timer_(true, true), |
191 window_id_(source) {} | 117 screen_capture_(false) {} |
192 | 118 |
193 DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {} | 119 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
194 | 120 |
195 bool DesktopVideoCaptureMachine::Start( | 121 bool AuraWindowCaptureMachine::Start( |
196 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 122 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
197 const media::VideoCaptureParams& params) { | 123 const media::VideoCaptureParams& params) { |
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
199 | 125 DCHECK(desktop_window_); |
200 desktop_window_ = content::DesktopMediaID::GetAuraWindowById(window_id_); | |
201 if (!desktop_window_) | |
202 return false; | |
203 | 126 |
204 // If the associated layer is already destroyed then return failure. | 127 // If the associated layer is already destroyed then return failure. |
205 ui::Layer* layer = desktop_window_->layer(); | 128 ui::Layer* layer = desktop_window_->layer(); |
206 if (!layer) | 129 if (!layer) |
207 return false; | 130 return false; |
208 | 131 |
209 DCHECK(oracle_proxy.get()); | 132 DCHECK(oracle_proxy.get()); |
210 oracle_proxy_ = oracle_proxy; | 133 oracle_proxy_ = oracle_proxy; |
211 capture_params_ = params; | 134 capture_params_ = params; |
212 | 135 |
213 // Update capture size. | 136 // Update capture size. |
214 UpdateCaptureSize(); | 137 UpdateCaptureSize(); |
215 | 138 |
216 // Start observing window events. | |
217 desktop_window_->AddObserver(this); | |
218 | |
219 // Start observing compositor updates. | |
220 if (desktop_window_->GetHost()) | |
221 desktop_window_->GetHost()->compositor()->AddObserver(this); | |
222 | |
223 power_save_blocker_.reset( | 139 power_save_blocker_.reset( |
224 PowerSaveBlocker::Create( | 140 PowerSaveBlocker::Create( |
225 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 141 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
226 PowerSaveBlocker::kReasonOther, | 142 PowerSaveBlocker::kReasonOther, |
227 "DesktopCaptureDevice is running").release()); | 143 "DesktopCaptureDevice is running").release()); |
228 | 144 |
229 // Starts timer. | 145 // Starts timer. |
230 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), | 146 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), |
231 base::Bind(&DesktopVideoCaptureMachine::Capture, AsWeakPtr(), | 147 base::Bind(&AuraWindowCaptureMachine::Capture, AsWeakPtr(), |
232 false)); | 148 false)); |
233 | 149 |
234 return true; | 150 return true; |
235 } | 151 } |
236 | 152 |
237 void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) { | 153 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { |
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
239 power_save_blocker_.reset(); | 155 power_save_blocker_.reset(); |
240 | 156 |
241 // Stop observing compositor and window events. | 157 // Stop observing compositor and window events. |
242 if (desktop_window_) { | 158 if (desktop_window_) { |
243 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); | 159 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); |
244 // In the host destructor the compositor is destroyed before the window. | 160 // In the host destructor the compositor is destroyed before the window. |
245 if (window_host && window_host->compositor()) | 161 if (window_host && window_host->compositor()) |
246 window_host->compositor()->RemoveObserver(this); | 162 window_host->compositor()->RemoveObserver(this); |
247 desktop_window_->RemoveObserver(this); | 163 desktop_window_->RemoveObserver(this); |
248 desktop_window_ = NULL; | 164 desktop_window_ = NULL; |
249 } | 165 } |
250 | 166 |
251 // Stop timer. | 167 // Stop timer. |
252 timer_.Stop(); | 168 timer_.Stop(); |
253 | 169 |
254 callback.Run(); | 170 callback.Run(); |
255 } | 171 } |
256 | 172 |
257 void DesktopVideoCaptureMachine::UpdateCaptureSize() { | 173 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { |
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
175 | |
176 DCHECK(!desktop_window_); | |
177 desktop_window_ = window; | |
178 | |
179 // Start observing window events. | |
180 desktop_window_->AddObserver(this); | |
181 | |
182 // Start observing compositor updates. | |
183 if (desktop_window_->GetHost()) | |
184 desktop_window_->GetHost()->compositor()->AddObserver(this); | |
185 | |
186 // We must store this for the UMA reporting in DidCopyOutput() as | |
187 // desktop_window_ might be destroyed at that point. | |
188 screen_capture_ = window->IsRootWindow(); | |
189 IncrementDesktopCaptureCounter(screen_capture_ ? SCREEN_CAPTURER_CREATED | |
190 : WINDOW_CAPTURER_CREATED); | |
191 } | |
192 | |
193 void AuraWindowCaptureMachine::UpdateCaptureSize() { | |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
259 if (oracle_proxy_.get() && desktop_window_) { | 195 if (oracle_proxy_.get() && desktop_window_) { |
260 ui::Layer* layer = desktop_window_->layer(); | 196 ui::Layer* layer = desktop_window_->layer(); |
261 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( | 197 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( |
262 layer, layer->bounds().size())); | 198 layer, layer->bounds().size())); |
263 } | 199 } |
264 ClearCursorState(); | 200 ClearCursorState(); |
265 } | 201 } |
266 | 202 |
267 void DesktopVideoCaptureMachine::Capture(bool dirty) { | 203 void AuraWindowCaptureMachine::Capture(bool dirty) { |
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
269 | 205 |
270 // Do not capture if the desktop window is already destroyed. | 206 // Do not capture if the desktop window is already destroyed. |
271 if (!desktop_window_) | 207 if (!desktop_window_) |
272 return; | 208 return; |
273 | 209 |
274 scoped_refptr<media::VideoFrame> frame; | 210 scoped_refptr<media::VideoFrame> frame; |
275 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 211 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
276 | 212 |
277 const base::TimeTicks start_time = base::TimeTicks::Now(); | 213 const base::TimeTicks start_time = base::TimeTicks::Now(); |
278 const VideoCaptureOracle::Event event = | 214 const VideoCaptureOracle::Event event = |
279 dirty ? VideoCaptureOracle::kCompositorUpdate | 215 dirty ? VideoCaptureOracle::kCompositorUpdate |
280 : VideoCaptureOracle::kTimerPoll; | 216 : VideoCaptureOracle::kTimerPoll; |
281 if (oracle_proxy_->ObserveEventAndDecideCapture( | 217 if (oracle_proxy_->ObserveEventAndDecideCapture( |
282 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { | 218 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
283 scoped_ptr<cc::CopyOutputRequest> request = | 219 scoped_ptr<cc::CopyOutputRequest> request = |
284 cc::CopyOutputRequest::CreateRequest( | 220 cc::CopyOutputRequest::CreateRequest( |
285 base::Bind(&DesktopVideoCaptureMachine::DidCopyOutput, | 221 base::Bind(&AuraWindowCaptureMachine::DidCopyOutput, |
286 AsWeakPtr(), frame, start_time, capture_frame_cb)); | 222 AsWeakPtr(), frame, start_time, capture_frame_cb)); |
287 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), | 223 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), |
288 desktop_window_->bounds().height()); | 224 desktop_window_->bounds().height()); |
289 request->set_area(window_rect); | 225 request->set_area(window_rect); |
290 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); | 226 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); |
291 } | 227 } |
292 } | 228 } |
293 | 229 |
294 void CopyOutputFinishedForVideo( | 230 void AuraWindowCaptureMachine::DidCopyOutput( |
295 base::TimeTicks start_time, | |
296 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | |
297 const scoped_refptr<media::VideoFrame>& target, | |
298 const SkBitmap& cursor_bitmap, | |
299 const gfx::Point& cursor_position, | |
300 scoped_ptr<cc::SingleReleaseCallback> release_callback, | |
301 bool result) { | |
302 if (!cursor_bitmap.isNull()) | |
303 RenderCursorOnVideoFrame(target, cursor_bitmap, cursor_position); | |
304 release_callback->Run(0, false); | |
305 capture_frame_cb.Run(target, start_time, result); | |
306 } | |
307 | |
308 void RunSingleReleaseCallback(scoped_ptr<cc::SingleReleaseCallback> cb, | |
309 uint32 sync_point) { | |
310 cb->Run(sync_point, false); | |
311 } | |
312 | |
313 void DesktopVideoCaptureMachine::DidCopyOutput( | |
314 scoped_refptr<media::VideoFrame> video_frame, | 231 scoped_refptr<media::VideoFrame> video_frame, |
315 base::TimeTicks start_time, | 232 base::TimeTicks start_time, |
316 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 233 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
317 scoped_ptr<cc::CopyOutputResult> result) { | 234 scoped_ptr<cc::CopyOutputResult> result) { |
318 static bool first_call = true; | 235 static bool first_call = true; |
319 | 236 |
320 bool succeeded = ProcessCopyOutputResponse( | 237 bool succeeded = ProcessCopyOutputResponse( |
321 video_frame, start_time, capture_frame_cb, result.Pass()); | 238 video_frame, start_time, capture_frame_cb, result.Pass()); |
322 | 239 |
323 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; | 240 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; |
324 | 241 |
325 // The two UMA_ blocks must be put in its own scope since it creates a static | 242 // The two UMA_ blocks must be put in its own scope since it creates a static |
326 // variable which expected constant histogram name. | 243 // variable which expected constant histogram name. |
327 if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { | 244 if (screen_capture_) { |
328 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); | 245 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); |
329 } else { | 246 } else { |
330 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); | 247 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); |
331 } | 248 } |
332 | 249 |
333 if (first_call) { | 250 if (first_call) { |
334 first_call = false; | 251 first_call = false; |
335 if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { | 252 if (screen_capture_) { |
336 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED | 253 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED |
337 : FIRST_SCREEN_CAPTURE_FAILED); | 254 : FIRST_SCREEN_CAPTURE_FAILED); |
338 } else { | 255 } else { |
339 IncrementDesktopCaptureCounter(succeeded | 256 IncrementDesktopCaptureCounter(succeeded |
340 ? FIRST_WINDOW_CAPTURE_SUCCEEDED | 257 ? FIRST_WINDOW_CAPTURE_SUCCEEDED |
341 : FIRST_WINDOW_CAPTURE_FAILED); | 258 : FIRST_WINDOW_CAPTURE_FAILED); |
342 } | 259 } |
343 } | 260 } |
344 } | 261 } |
345 | 262 |
346 bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse( | 263 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( |
347 scoped_refptr<media::VideoFrame> video_frame, | 264 scoped_refptr<media::VideoFrame> video_frame, |
348 base::TimeTicks start_time, | 265 base::TimeTicks start_time, |
349 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 266 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
350 scoped_ptr<cc::CopyOutputResult> result) { | 267 scoped_ptr<cc::CopyOutputResult> result) { |
351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
352 | 269 |
353 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) | 270 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) |
354 return false; | 271 return false; |
355 | 272 |
356 if (capture_params_.requested_format.pixel_format == | 273 if (capture_params_.requested_format.pixel_format == |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 base::Bind(&CopyOutputFinishedForVideo, | 342 base::Bind(&CopyOutputFinishedForVideo, |
426 start_time, | 343 start_time, |
427 capture_frame_cb, | 344 capture_frame_cb, |
428 video_frame, | 345 video_frame, |
429 scaled_cursor_bitmap_, | 346 scaled_cursor_bitmap_, |
430 cursor_position_in_frame, | 347 cursor_position_in_frame, |
431 base::Passed(&release_callback))); | 348 base::Passed(&release_callback))); |
432 return true; | 349 return true; |
433 } | 350 } |
434 | 351 |
435 gfx::Point DesktopVideoCaptureMachine::UpdateCursorState( | 352 gfx::Point AuraWindowCaptureMachine::UpdateCursorState( |
436 const gfx::Rect& region_in_frame) { | 353 const gfx::Rect& region_in_frame) { |
437 const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds(); | 354 const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds(); |
438 if (desktop_bounds.IsEmpty()) { | 355 if (desktop_bounds.IsEmpty()) { |
439 // Return early to prevent divide-by-zero in calculations below. | 356 // Return early to prevent divide-by-zero in calculations below. |
440 ClearCursorState(); | 357 ClearCursorState(); |
441 return gfx::Point(); | 358 return gfx::Point(); |
442 } | 359 } |
443 | 360 |
444 gfx::NativeCursor cursor = | 361 gfx::NativeCursor cursor = |
445 desktop_window_->GetHost()->last_cursor(); | 362 desktop_window_->GetHost()->last_cursor(); |
(...skipping 30 matching lines...) Expand all Loading... | |
476 desktop_window_->layer(), cursor_hot_point_); | 393 desktop_window_->layer(), cursor_hot_point_); |
477 cursor_position.Offset(-desktop_bounds.x() - hot_point_in_dip.x(), | 394 cursor_position.Offset(-desktop_bounds.x() - hot_point_in_dip.x(), |
478 -desktop_bounds.y() - hot_point_in_dip.y()); | 395 -desktop_bounds.y() - hot_point_in_dip.y()); |
479 return gfx::Point( | 396 return gfx::Point( |
480 region_in_frame.x() + cursor_position.x() * region_in_frame.width() / | 397 region_in_frame.x() + cursor_position.x() * region_in_frame.width() / |
481 desktop_bounds.width(), | 398 desktop_bounds.width(), |
482 region_in_frame.y() + cursor_position.y() * region_in_frame.height() / | 399 region_in_frame.y() + cursor_position.y() * region_in_frame.height() / |
483 desktop_bounds.height()); | 400 desktop_bounds.height()); |
484 } | 401 } |
485 | 402 |
486 void DesktopVideoCaptureMachine::ClearCursorState() { | 403 void AuraWindowCaptureMachine::ClearCursorState() { |
487 last_cursor_ = ui::Cursor(); | 404 last_cursor_ = ui::Cursor(); |
488 desktop_size_when_cursor_last_updated_ = gfx::Size(); | 405 desktop_size_when_cursor_last_updated_ = gfx::Size(); |
489 cursor_hot_point_ = gfx::Point(); | 406 cursor_hot_point_ = gfx::Point(); |
490 scaled_cursor_bitmap_.reset(); | 407 scaled_cursor_bitmap_.reset(); |
491 } | 408 } |
492 | 409 |
493 void DesktopVideoCaptureMachine::OnWindowBoundsChanged( | 410 void AuraWindowCaptureMachine::OnWindowBoundsChanged( |
494 aura::Window* window, | 411 aura::Window* window, |
495 const gfx::Rect& old_bounds, | 412 const gfx::Rect& old_bounds, |
496 const gfx::Rect& new_bounds) { | 413 const gfx::Rect& new_bounds) { |
497 DCHECK(desktop_window_ && window == desktop_window_); | 414 DCHECK(desktop_window_ && window == desktop_window_); |
498 | 415 |
499 // Post task to update capture size on UI thread. | 416 // Post task to update capture size on UI thread. |
500 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 417 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
501 &DesktopVideoCaptureMachine::UpdateCaptureSize, AsWeakPtr())); | 418 &AuraWindowCaptureMachine::UpdateCaptureSize, AsWeakPtr())); |
502 } | 419 } |
503 | 420 |
504 void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) { | 421 void AuraWindowCaptureMachine::OnWindowDestroyed(aura::Window* window) { |
505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
506 | 423 |
507 Stop(base::Bind(&base::DoNothing)); | 424 Stop(base::Bind(&base::DoNothing)); |
508 | 425 |
509 oracle_proxy_->ReportError("OnWindowDestroyed()"); | 426 oracle_proxy_->ReportError("OnWindowDestroyed()"); |
510 } | 427 } |
511 | 428 |
512 void DesktopVideoCaptureMachine::OnWindowAddedToRootWindow( | 429 void AuraWindowCaptureMachine::OnWindowAddedToRootWindow( |
513 aura::Window* window) { | 430 aura::Window* window) { |
514 DCHECK(window == desktop_window_); | 431 DCHECK(window == desktop_window_); |
515 window->GetHost()->compositor()->AddObserver(this); | 432 window->GetHost()->compositor()->AddObserver(this); |
516 } | 433 } |
517 | 434 |
518 void DesktopVideoCaptureMachine::OnWindowRemovingFromRootWindow( | 435 void AuraWindowCaptureMachine::OnWindowRemovingFromRootWindow( |
519 aura::Window* window, | 436 aura::Window* window, |
520 aura::Window* new_root) { | 437 aura::Window* new_root) { |
521 DCHECK(window == desktop_window_); | 438 DCHECK(window == desktop_window_); |
522 window->GetHost()->compositor()->RemoveObserver(this); | 439 window->GetHost()->compositor()->RemoveObserver(this); |
523 } | 440 } |
524 | 441 |
525 void DesktopVideoCaptureMachine::OnCompositingEnded( | 442 void AuraWindowCaptureMachine::OnCompositingEnded( |
526 ui::Compositor* compositor) { | 443 ui::Compositor* compositor) { |
527 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 444 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
528 &DesktopVideoCaptureMachine::Capture, AsWeakPtr(), true)); | 445 &AuraWindowCaptureMachine::Capture, AsWeakPtr(), true)); |
529 } | 446 } |
530 | 447 |
531 } // namespace | 448 DesktopCaptureDeviceAura::DesktopCaptureDeviceAura() |
Sergey Ulanov
2015/03/04 18:48:58
Move this to desktop_capture_device_aura.cc?
robert.bradford
2015/03/04 21:05:10
Oops. I messed that up when I was doing the rebase
| |
532 | 449 : machine_(new AuraWindowCaptureMachine()), |
533 DesktopCaptureDeviceAura::DesktopCaptureDeviceAura( | 450 core_(new ContentVideoCaptureDeviceCore( |
534 const DesktopMediaID& source) | 451 scoped_ptr<VideoCaptureMachine>(machine_))) { |
535 : core_(new ContentVideoCaptureDeviceCore(scoped_ptr<VideoCaptureMachine>( | 452 } |
536 new DesktopVideoCaptureMachine(source)))) {} | |
537 | 453 |
538 DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { | 454 DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { |
Sergey Ulanov
2015/03/04 18:48:58
Move this to desktop_capture_device_aura.cc
robert.bradford
2015/03/04 21:05:10
Done.
| |
539 DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; | 455 DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; |
540 } | 456 } |
541 | 457 |
542 // static | |
543 media::VideoCaptureDevice* DesktopCaptureDeviceAura::Create( | |
544 const DesktopMediaID& source) { | |
545 IncrementDesktopCaptureCounter(source.type == DesktopMediaID::TYPE_SCREEN | |
546 ? SCREEN_CAPTURER_CREATED | |
547 : WINDOW_CAPTURER_CREATED); | |
548 return new DesktopCaptureDeviceAura(source); | |
549 } | |
550 | |
551 void DesktopCaptureDeviceAura::AllocateAndStart( | |
552 const media::VideoCaptureParams& params, | |
553 scoped_ptr<Client> client) { | |
554 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); | |
555 core_->AllocateAndStart(params, client.Pass()); | |
556 } | |
557 | |
558 void DesktopCaptureDeviceAura::StopAndDeAllocate() { | |
559 core_->StopAndDeAllocate(); | |
560 } | |
561 | |
562 } // namespace content | 458 } // namespace content |
OLD | NEW |