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/renderer_host/media/desktop_capture_device_aura.h" | 5 #include "content/browser/renderer_host/media/desktop_capture_device_aura.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
9 #include "cc/output/copy_output_request.h" | 9 #include "cc/output/copy_output_request.h" |
10 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 // The window associated with the desktop. | 76 // The window associated with the desktop. |
77 aura::Window* desktop_window_; | 77 aura::Window* desktop_window_; |
78 | 78 |
79 // The layer associated with the desktop. | 79 // The layer associated with the desktop. |
80 ui::Layer* desktop_layer_; | 80 ui::Layer* desktop_layer_; |
81 | 81 |
82 // The timer that kicks off period captures. | 82 // The timer that kicks off period captures. |
83 base::Timer timer_; | 83 base::Timer timer_; |
84 | 84 |
85 // The desktop id. | 85 // The id of the window being captured. |
86 DesktopMediaID desktop_id_; | 86 DesktopMediaID window_id_; |
87 | 87 |
88 // Makes all the decisions about which frames to copy, and how. | 88 // Makes all the decisions about which frames to copy, and how. |
89 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; | 89 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; |
90 | 90 |
91 // YUV readback pipeline. | 91 // YUV readback pipeline. |
92 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; | 92 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(DesktopVideoCaptureMachine); | 94 DISALLOW_COPY_AND_ASSIGN(DesktopVideoCaptureMachine); |
95 }; | 95 }; |
96 | 96 |
97 DesktopVideoCaptureMachine::DesktopVideoCaptureMachine( | 97 DesktopVideoCaptureMachine::DesktopVideoCaptureMachine( |
98 const DesktopMediaID& source) | 98 const DesktopMediaID& source) |
99 : desktop_window_(NULL), | 99 : desktop_window_(NULL), |
100 desktop_layer_(NULL), | 100 desktop_layer_(NULL), |
101 timer_(true, true), | 101 timer_(true, true), |
102 desktop_id_(source) {} | 102 window_id_(source) {} |
103 | 103 |
104 DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {} | 104 DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {} |
105 | 105 |
106 bool DesktopVideoCaptureMachine::Start( | 106 bool DesktopVideoCaptureMachine::Start( |
107 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy) { | 107 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy) { |
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
109 | 109 |
110 // TODO(hshi): get the correct display specified by |desktop_id_|. | 110 desktop_window_ = content::DesktopMediaID::GetAuraWindowById(window_id_); |
111 const gfx::Display& primary_display = | |
112 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
113 desktop_window_ = gfx::Screen::GetNativeScreen()->GetWindowAtScreenPoint( | |
114 primary_display.bounds().CenterPoint())->GetRootWindow(); | |
115 if (!desktop_window_) | 111 if (!desktop_window_) |
116 return false; | 112 return false; |
117 | 113 |
118 // If the desktop layer is already destroyed then return failure. | 114 // If the desktop layer is already destroyed then return failure. |
119 desktop_layer_ = desktop_window_->layer(); | 115 desktop_layer_ = desktop_window_->layer(); |
120 if (!desktop_layer_) | 116 if (!desktop_layer_) |
121 return false; | 117 return false; |
122 | 118 |
123 DCHECK(oracle_proxy.get()); | 119 DCHECK(oracle_proxy.get()); |
124 oracle_proxy_ = oracle_proxy; | 120 oracle_proxy_ = oracle_proxy; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 const base::Time start_time = base::Time::Now(); | 182 const base::Time start_time = base::Time::Now(); |
187 const VideoCaptureOracle::Event event = | 183 const VideoCaptureOracle::Event event = |
188 dirty ? VideoCaptureOracle::kCompositorUpdate | 184 dirty ? VideoCaptureOracle::kCompositorUpdate |
189 : VideoCaptureOracle::kTimerPoll; | 185 : VideoCaptureOracle::kTimerPoll; |
190 if (oracle_proxy_->ObserveEventAndDecideCapture( | 186 if (oracle_proxy_->ObserveEventAndDecideCapture( |
191 event, start_time, &frame, &capture_frame_cb)) { | 187 event, start_time, &frame, &capture_frame_cb)) { |
192 scoped_ptr<cc::CopyOutputRequest> request = | 188 scoped_ptr<cc::CopyOutputRequest> request = |
193 cc::CopyOutputRequest::CreateRequest( | 189 cc::CopyOutputRequest::CreateRequest( |
194 base::Bind(&DesktopVideoCaptureMachine::DidCopyOutput, | 190 base::Bind(&DesktopVideoCaptureMachine::DidCopyOutput, |
195 AsWeakPtr(), frame, start_time, capture_frame_cb)); | 191 AsWeakPtr(), frame, start_time, capture_frame_cb)); |
196 gfx::Rect desktop_size = ui::ConvertRectToPixel( | 192 gfx::Rect window_rect = |
197 desktop_layer_, desktop_layer_->bounds()); | 193 ui::ConvertRectToPixel(desktop_window_->layer(), |
198 request->set_area(desktop_size); | 194 gfx::Rect(desktop_window_->bounds().width(), |
| 195 desktop_window_->bounds().height())); |
| 196 request->set_area(window_rect); |
199 desktop_layer_->RequestCopyOfOutput(request.Pass()); | 197 desktop_layer_->RequestCopyOfOutput(request.Pass()); |
200 } | 198 } |
201 } | 199 } |
202 | 200 |
203 static void CopyOutputFinishedForVideo( | 201 static void CopyOutputFinishedForVideo( |
204 base::Time start_time, | 202 base::Time start_time, |
205 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 203 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
206 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 204 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
207 bool result) { | 205 bool result) { |
208 release_callback->Run(0, false); | 206 release_callback->Run(0, false); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 : impl_(new VideoCaptureDeviceImpl(scoped_ptr<VideoCaptureMachine>( | 297 : impl_(new VideoCaptureDeviceImpl(scoped_ptr<VideoCaptureMachine>( |
300 new DesktopVideoCaptureMachine(source)))) {} | 298 new DesktopVideoCaptureMachine(source)))) {} |
301 | 299 |
302 DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { | 300 DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { |
303 DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; | 301 DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; |
304 } | 302 } |
305 | 303 |
306 // static | 304 // static |
307 media::VideoCaptureDevice* DesktopCaptureDeviceAura::Create( | 305 media::VideoCaptureDevice* DesktopCaptureDeviceAura::Create( |
308 const DesktopMediaID& source) { | 306 const DesktopMediaID& source) { |
309 // This implementation only supports screen capture. | |
310 if (source.type != DesktopMediaID::TYPE_SCREEN) | |
311 return NULL; | |
312 | |
313 return new DesktopCaptureDeviceAura(source); | 307 return new DesktopCaptureDeviceAura(source); |
314 } | 308 } |
315 | 309 |
316 void DesktopCaptureDeviceAura::AllocateAndStart( | 310 void DesktopCaptureDeviceAura::AllocateAndStart( |
317 const media::VideoCaptureParams& params, | 311 const media::VideoCaptureParams& params, |
318 scoped_ptr<Client> client) { | 312 scoped_ptr<Client> client) { |
319 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); | 313 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); |
320 impl_->AllocateAndStart(params, client.Pass()); | 314 impl_->AllocateAndStart(params, client.Pass()); |
321 } | 315 } |
322 | 316 |
323 void DesktopCaptureDeviceAura::StopAndDeAllocate() { | 317 void DesktopCaptureDeviceAura::StopAndDeAllocate() { |
324 impl_->StopAndDeAllocate(); | 318 impl_->StopAndDeAllocate(); |
325 } | 319 } |
326 | 320 |
327 } // namespace content | 321 } // namespace content |
OLD | NEW |