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/desktop_capture_device_aura.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" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 } | 88 } |
89 cursor_bitmap.unlockPixels(); | 89 cursor_bitmap.unlockPixels(); |
90 } | 90 } |
91 | 91 |
92 class DesktopVideoCaptureMachine | 92 class DesktopVideoCaptureMachine |
93 : public VideoCaptureMachine, | 93 : public VideoCaptureMachine, |
94 public aura::WindowObserver, | 94 public aura::WindowObserver, |
95 public ui::CompositorObserver, | 95 public ui::CompositorObserver, |
96 public base::SupportsWeakPtr<DesktopVideoCaptureMachine> { | 96 public base::SupportsWeakPtr<DesktopVideoCaptureMachine> { |
97 public: | 97 public: |
98 DesktopVideoCaptureMachine(const DesktopMediaID& source); | 98 DesktopVideoCaptureMachine(aura::Window* window); |
99 ~DesktopVideoCaptureMachine() override; | 99 ~DesktopVideoCaptureMachine() override; |
100 | 100 |
101 // VideoCaptureFrameSource overrides. | 101 // VideoCaptureFrameSource overrides. |
102 bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 102 bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
103 const media::VideoCaptureParams& params) override; | 103 const media::VideoCaptureParams& params) override; |
104 void Stop(const base::Closure& callback) override; | 104 void Stop(const base::Closure& callback) override; |
105 | 105 |
106 // Implements aura::WindowObserver. | 106 // Implements aura::WindowObserver. |
107 void OnWindowBoundsChanged(aura::Window* window, | 107 void OnWindowBoundsChanged(aura::Window* window, |
108 const gfx::Rect& old_bounds, | 108 const gfx::Rect& old_bounds, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 | 151 |
152 // Clears cursor state. | 152 // Clears cursor state. |
153 void ClearCursorState(); | 153 void ClearCursorState(); |
154 | 154 |
155 // The window associated with the desktop. | 155 // The window associated with the desktop. |
156 aura::Window* desktop_window_; | 156 aura::Window* desktop_window_; |
157 | 157 |
158 // The timer that kicks off period captures. | 158 // The timer that kicks off period captures. |
159 base::Timer timer_; | 159 base::Timer timer_; |
160 | 160 |
161 // The id of the window being captured. | |
162 DesktopMediaID window_id_; | |
163 | |
164 // Makes all the decisions about which frames to copy, and how. | 161 // Makes all the decisions about which frames to copy, and how. |
165 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; | 162 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; |
166 | 163 |
167 // The capture parameters for this capture. | 164 // The capture parameters for this capture. |
168 media::VideoCaptureParams capture_params_; | 165 media::VideoCaptureParams capture_params_; |
169 | 166 |
170 // YUV readback pipeline. | 167 // YUV readback pipeline. |
171 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; | 168 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; |
172 | 169 |
173 // Cursor state. | 170 // Cursor state. |
174 ui::Cursor last_cursor_; | 171 ui::Cursor last_cursor_; |
175 gfx::Point cursor_hot_point_; | 172 gfx::Point cursor_hot_point_; |
176 SkBitmap scaled_cursor_bitmap_; | 173 SkBitmap scaled_cursor_bitmap_; |
177 | 174 |
178 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the | 175 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the |
179 // screen from sleeping for the drive-by web. | 176 // screen from sleeping for the drive-by web. |
180 scoped_ptr<PowerSaveBlocker> power_save_blocker_; | 177 scoped_ptr<PowerSaveBlocker> power_save_blocker_; |
181 | 178 |
182 DISALLOW_COPY_AND_ASSIGN(DesktopVideoCaptureMachine); | 179 DISALLOW_COPY_AND_ASSIGN(DesktopVideoCaptureMachine); |
183 }; | 180 }; |
184 | 181 |
185 DesktopVideoCaptureMachine::DesktopVideoCaptureMachine( | 182 DesktopVideoCaptureMachine::DesktopVideoCaptureMachine(aura::Window* window) |
186 const DesktopMediaID& source) | 183 : desktop_window_(window), |
187 : desktop_window_(NULL), | 184 timer_(true, true) { |
188 timer_(true, true), | 185 IncrementDesktopCaptureCounter(window->IsRootWindow() |
189 window_id_(source) {} | 186 ? SCREEN_CAPTURER_CREATED |
187 : WINDOW_CAPTURER_CREATED); | |
188 } | |
190 | 189 |
191 DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {} | 190 DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {} |
192 | 191 |
193 bool DesktopVideoCaptureMachine::Start( | 192 bool DesktopVideoCaptureMachine::Start( |
194 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 193 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
195 const media::VideoCaptureParams& params) { | 194 const media::VideoCaptureParams& params) { |
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
197 | 196 |
198 desktop_window_ = content::DesktopMediaID::GetAuraWindowById(window_id_); | |
199 if (!desktop_window_) | |
200 return false; | |
201 | |
202 // If the associated layer is already destroyed then return failure. | 197 // If the associated layer is already destroyed then return failure. |
203 ui::Layer* layer = desktop_window_->layer(); | 198 ui::Layer* layer = desktop_window_->layer(); |
204 if (!layer) | 199 if (!layer) |
205 return false; | 200 return false; |
206 | 201 |
207 DCHECK(oracle_proxy.get()); | 202 DCHECK(oracle_proxy.get()); |
208 oracle_proxy_ = oracle_proxy; | 203 oracle_proxy_ = oracle_proxy; |
209 capture_params_ = params; | 204 capture_params_ = params; |
210 | 205 |
211 // Update capture size. | 206 // Update capture size. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 scoped_ptr<cc::CopyOutputResult> result) { | 310 scoped_ptr<cc::CopyOutputResult> result) { |
316 static bool first_call = true; | 311 static bool first_call = true; |
317 | 312 |
318 bool succeeded = ProcessCopyOutputResponse( | 313 bool succeeded = ProcessCopyOutputResponse( |
319 video_frame, start_time, capture_frame_cb, result.Pass()); | 314 video_frame, start_time, capture_frame_cb, result.Pass()); |
320 | 315 |
321 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; | 316 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; |
322 | 317 |
323 // The two UMA_ blocks must be put in its own scope since it creates a static | 318 // The two UMA_ blocks must be put in its own scope since it creates a static |
324 // variable which expected constant histogram name. | 319 // variable which expected constant histogram name. |
325 if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { | 320 if (desktop_window_->IsRootWindow()) { |
326 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); | 321 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); |
327 } else { | 322 } else { |
328 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); | 323 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); |
329 } | 324 } |
330 | 325 |
331 if (first_call) { | 326 if (first_call) { |
332 first_call = false; | 327 first_call = false; |
333 if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { | 328 if (desktop_window_->IsRootWindow()) { |
334 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED | 329 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED |
335 : FIRST_SCREEN_CAPTURE_FAILED); | 330 : FIRST_SCREEN_CAPTURE_FAILED); |
336 } else { | 331 } else { |
337 IncrementDesktopCaptureCounter(succeeded | 332 IncrementDesktopCaptureCounter(succeeded |
338 ? FIRST_WINDOW_CAPTURE_SUCCEEDED | 333 ? FIRST_WINDOW_CAPTURE_SUCCEEDED |
339 : FIRST_WINDOW_CAPTURE_FAILED); | 334 : FIRST_WINDOW_CAPTURE_FAILED); |
340 } | 335 } |
341 } | 336 } |
342 } | 337 } |
343 | 338 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 } | 498 } |
504 | 499 |
505 void DesktopVideoCaptureMachine::OnCompositingEnded( | 500 void DesktopVideoCaptureMachine::OnCompositingEnded( |
506 ui::Compositor* compositor) { | 501 ui::Compositor* compositor) { |
507 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 502 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
508 &DesktopVideoCaptureMachine::Capture, AsWeakPtr(), true)); | 503 &DesktopVideoCaptureMachine::Capture, AsWeakPtr(), true)); |
509 } | 504 } |
510 | 505 |
511 } // namespace | 506 } // namespace |
512 | 507 |
513 DesktopCaptureDeviceAura::DesktopCaptureDeviceAura( | 508 DesktopCaptureDeviceAura::DesktopCaptureDeviceAura(aura::Window* window) |
514 const DesktopMediaID& source) | |
515 : core_(new ContentVideoCaptureDeviceCore(scoped_ptr<VideoCaptureMachine>( | 509 : core_(new ContentVideoCaptureDeviceCore(scoped_ptr<VideoCaptureMachine>( |
516 new DesktopVideoCaptureMachine(source)))) {} | 510 new DesktopVideoCaptureMachine(window)))) {} |
517 | 511 |
518 DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { | 512 DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { |
519 DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; | 513 DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; |
520 } | 514 } |
521 | 515 |
522 // static | 516 // static |
523 media::VideoCaptureDevice* DesktopCaptureDeviceAura::Create( | 517 media::VideoCaptureDevice* DesktopCaptureDeviceAura::Create( |
524 const DesktopMediaID& source) { | 518 const DesktopMediaID& source) { |
525 IncrementDesktopCaptureCounter(source.type == DesktopMediaID::TYPE_SCREEN | 519 aura::Window* window = content::DesktopMediaID::GetAuraWindowById(source); |
Sergey Ulanov
2015/03/02 21:58:58
DesktopMediaID::GetAuraWindowById() is not thread-
| |
526 ? SCREEN_CAPTURER_CREATED | 520 return new DesktopCaptureDeviceAura(window); |
527 : WINDOW_CAPTURER_CREATED); | |
528 return new DesktopCaptureDeviceAura(source); | |
529 } | 521 } |
530 | 522 |
531 void DesktopCaptureDeviceAura::AllocateAndStart( | 523 void DesktopCaptureDeviceAura::AllocateAndStart( |
532 const media::VideoCaptureParams& params, | 524 const media::VideoCaptureParams& params, |
533 scoped_ptr<Client> client) { | 525 scoped_ptr<Client> client) { |
534 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); | 526 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); |
535 core_->AllocateAndStart(params, client.Pass()); | 527 core_->AllocateAndStart(params, client.Pass()); |
536 } | 528 } |
537 | 529 |
538 void DesktopCaptureDeviceAura::StopAndDeAllocate() { | 530 void DesktopCaptureDeviceAura::StopAndDeAllocate() { |
539 core_->StopAndDeAllocate(); | 531 core_->StopAndDeAllocate(); |
540 } | 532 } |
541 | 533 |
542 } // namespace content | 534 } // namespace content |
OLD | NEW |