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_uma_types.h" | 14 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
15 #include "content/common/gpu/client/gl_helper.h" | 15 #include "content/common/gpu/client/gl_helper.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 int color_v = clip_byte(((color_r * 112 + color_g * -94 + | 82 int color_v = clip_byte(((color_r * 112 + color_g * -94 + |
83 color_b * -18 + 128) >> 8) + 128); | 83 color_b * -18 + 128) >> 8) + 128); |
84 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); | 84 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); |
85 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); | 85 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 cursor_bitmap.unlockPixels(); | 89 cursor_bitmap.unlockPixels(); |
90 } | 90 } |
91 | 91 |
92 class DesktopVideoCaptureMachine | 92 void CopyOutputFinishedForVideo( |
93 : public VideoCaptureMachine, | 93 base::TimeTicks start_time, |
94 public aura::WindowObserver, | 94 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
95 public ui::CompositorObserver, | 95 const scoped_refptr<media::VideoFrame>& target, |
96 public base::SupportsWeakPtr<DesktopVideoCaptureMachine> { | 96 const SkBitmap& cursor_bitmap, |
97 public: | 97 const gfx::Point& cursor_position, |
98 DesktopVideoCaptureMachine(const DesktopMediaID& source); | 98 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
99 ~DesktopVideoCaptureMachine() override; | 99 bool result) { |
100 if (!cursor_bitmap.isNull()) | |
101 RenderCursorOnVideoFrame(target, cursor_bitmap, cursor_position); | |
102 release_callback->Run(0, false); | |
103 capture_frame_cb.Run(target, start_time, result); | |
104 } | |
100 | 105 |
101 // VideoCaptureFrameSource overrides. | 106 void RunSingleReleaseCallback(scoped_ptr<cc::SingleReleaseCallback> cb, |
102 bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 107 uint32 sync_point) { |
103 const media::VideoCaptureParams& params) override; | 108 cb->Run(sync_point, false); |
104 void Stop(const base::Closure& callback) override; | 109 } |
105 | 110 |
106 // Implements aura::WindowObserver. | 111 } // 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 | 112 |
115 // Implements ui::CompositorObserver. | 113 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), | 114 : desktop_window_(NULL), |
190 timer_(true, true), | 115 timer_(true, true), |
191 window_id_(source) {} | 116 screen_capture_(false) {} |
192 | 117 |
193 DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {} | 118 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
194 | 119 |
195 bool DesktopVideoCaptureMachine::Start( | 120 bool AuraWindowCaptureMachine::Start( |
196 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 121 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
197 const media::VideoCaptureParams& params) { | 122 const media::VideoCaptureParams& params) { |
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
199 | 124 DCHECK(desktop_window_); |
Sergey Ulanov
2015/03/04 22:07:42
window may be destroyed between SetWindow() and St
robert.bradford
2015/03/05 18:12:11
Done.
| |
200 desktop_window_ = content::DesktopMediaID::GetAuraWindowById(window_id_); | |
201 if (!desktop_window_) | |
202 return false; | |
203 | 125 |
204 // If the associated layer is already destroyed then return failure. | 126 // If the associated layer is already destroyed then return failure. |
205 ui::Layer* layer = desktop_window_->layer(); | 127 ui::Layer* layer = desktop_window_->layer(); |
206 if (!layer) | 128 if (!layer) |
207 return false; | 129 return false; |
208 | 130 |
209 DCHECK(oracle_proxy.get()); | 131 DCHECK(oracle_proxy.get()); |
210 oracle_proxy_ = oracle_proxy; | 132 oracle_proxy_ = oracle_proxy; |
211 capture_params_ = params; | 133 capture_params_ = params; |
212 | 134 |
213 // Update capture size. | 135 // Update capture size. |
214 UpdateCaptureSize(); | 136 UpdateCaptureSize(); |
215 | 137 |
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( | 138 power_save_blocker_.reset( |
224 PowerSaveBlocker::Create( | 139 PowerSaveBlocker::Create( |
225 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 140 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
226 PowerSaveBlocker::kReasonOther, | 141 PowerSaveBlocker::kReasonOther, |
227 "DesktopCaptureDevice is running").release()); | 142 "DesktopCaptureDevice is running").release()); |
228 | 143 |
229 // Starts timer. | 144 // Starts timer. |
230 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), | 145 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), |
231 base::Bind(&DesktopVideoCaptureMachine::Capture, AsWeakPtr(), | 146 base::Bind(&AuraWindowCaptureMachine::Capture, AsWeakPtr(), |
232 false)); | 147 false)); |
233 | 148 |
234 return true; | 149 return true; |
235 } | 150 } |
236 | 151 |
237 void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) { | 152 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { |
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
239 power_save_blocker_.reset(); | 154 power_save_blocker_.reset(); |
240 | 155 |
241 // Stop observing compositor and window events. | 156 // Stop observing compositor and window events. |
242 if (desktop_window_) { | 157 if (desktop_window_) { |
243 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); | 158 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); |
244 // In the host destructor the compositor is destroyed before the window. | 159 // In the host destructor the compositor is destroyed before the window. |
245 if (window_host && window_host->compositor()) | 160 if (window_host && window_host->compositor()) |
246 window_host->compositor()->RemoveObserver(this); | 161 window_host->compositor()->RemoveObserver(this); |
247 desktop_window_->RemoveObserver(this); | 162 desktop_window_->RemoveObserver(this); |
248 desktop_window_ = NULL; | 163 desktop_window_ = NULL; |
249 } | 164 } |
250 | 165 |
251 // Stop timer. | 166 // Stop timer. |
252 timer_.Stop(); | 167 timer_.Stop(); |
253 | 168 |
254 callback.Run(); | 169 callback.Run(); |
255 } | 170 } |
256 | 171 |
257 void DesktopVideoCaptureMachine::UpdateCaptureSize() { | 172 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { |
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
174 | |
175 DCHECK(!desktop_window_); | |
176 desktop_window_ = window; | |
177 | |
178 // Start observing window events. | |
179 desktop_window_->AddObserver(this); | |
180 | |
181 // Start observing compositor updates. | |
182 if (desktop_window_->GetHost()) | |
183 desktop_window_->GetHost()->compositor()->AddObserver(this); | |
Sergey Ulanov
2015/03/04 22:07:42
I think this should be kept in Start(). Otherwise
robert.bradford
2015/03/05 18:12:11
Done.
| |
184 | |
185 // We must store this for the UMA reporting in DidCopyOutput() as | |
186 // desktop_window_ might be destroyed at that point. | |
187 screen_capture_ = window->IsRootWindow(); | |
188 IncrementDesktopCaptureCounter(screen_capture_ ? SCREEN_CAPTURER_CREATED | |
189 : WINDOW_CAPTURER_CREATED); | |
190 } | |
191 | |
192 void AuraWindowCaptureMachine::UpdateCaptureSize() { | |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
259 if (oracle_proxy_.get() && desktop_window_) { | 194 if (oracle_proxy_.get() && desktop_window_) { |
260 ui::Layer* layer = desktop_window_->layer(); | 195 ui::Layer* layer = desktop_window_->layer(); |
261 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( | 196 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( |
262 layer, layer->bounds().size())); | 197 layer, layer->bounds().size())); |
263 } | 198 } |
264 ClearCursorState(); | 199 ClearCursorState(); |
265 } | 200 } |
266 | 201 |
267 void DesktopVideoCaptureMachine::Capture(bool dirty) { | 202 void AuraWindowCaptureMachine::Capture(bool dirty) { |
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
269 | 204 |
270 // Do not capture if the desktop window is already destroyed. | 205 // Do not capture if the desktop window is already destroyed. |
271 if (!desktop_window_) | 206 if (!desktop_window_) |
272 return; | 207 return; |
273 | 208 |
274 scoped_refptr<media::VideoFrame> frame; | 209 scoped_refptr<media::VideoFrame> frame; |
275 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 210 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
276 | 211 |
277 const base::TimeTicks start_time = base::TimeTicks::Now(); | 212 const base::TimeTicks start_time = base::TimeTicks::Now(); |
278 const VideoCaptureOracle::Event event = | 213 const VideoCaptureOracle::Event event = |
279 dirty ? VideoCaptureOracle::kCompositorUpdate | 214 dirty ? VideoCaptureOracle::kCompositorUpdate |
280 : VideoCaptureOracle::kTimerPoll; | 215 : VideoCaptureOracle::kTimerPoll; |
281 if (oracle_proxy_->ObserveEventAndDecideCapture( | 216 if (oracle_proxy_->ObserveEventAndDecideCapture( |
282 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { | 217 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
283 scoped_ptr<cc::CopyOutputRequest> request = | 218 scoped_ptr<cc::CopyOutputRequest> request = |
284 cc::CopyOutputRequest::CreateRequest( | 219 cc::CopyOutputRequest::CreateRequest( |
285 base::Bind(&DesktopVideoCaptureMachine::DidCopyOutput, | 220 base::Bind(&AuraWindowCaptureMachine::DidCopyOutput, |
286 AsWeakPtr(), frame, start_time, capture_frame_cb)); | 221 AsWeakPtr(), frame, start_time, capture_frame_cb)); |
287 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), | 222 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), |
288 desktop_window_->bounds().height()); | 223 desktop_window_->bounds().height()); |
289 request->set_area(window_rect); | 224 request->set_area(window_rect); |
290 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); | 225 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); |
291 } | 226 } |
292 } | 227 } |
293 | 228 |
294 void CopyOutputFinishedForVideo( | 229 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, | 230 scoped_refptr<media::VideoFrame> video_frame, |
315 base::TimeTicks start_time, | 231 base::TimeTicks start_time, |
316 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 232 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
317 scoped_ptr<cc::CopyOutputResult> result) { | 233 scoped_ptr<cc::CopyOutputResult> result) { |
318 static bool first_call = true; | 234 static bool first_call = true; |
319 | 235 |
320 bool succeeded = ProcessCopyOutputResponse( | 236 bool succeeded = ProcessCopyOutputResponse( |
321 video_frame, start_time, capture_frame_cb, result.Pass()); | 237 video_frame, start_time, capture_frame_cb, result.Pass()); |
322 | 238 |
323 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; | 239 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; |
324 | 240 |
325 // The two UMA_ blocks must be put in its own scope since it creates a static | 241 // The two UMA_ blocks must be put in its own scope since it creates a static |
326 // variable which expected constant histogram name. | 242 // variable which expected constant histogram name. |
327 if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { | 243 if (screen_capture_) { |
328 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); | 244 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); |
329 } else { | 245 } else { |
330 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); | 246 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); |
331 } | 247 } |
332 | 248 |
333 if (first_call) { | 249 if (first_call) { |
334 first_call = false; | 250 first_call = false; |
335 if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { | 251 if (screen_capture_) { |
336 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED | 252 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED |
337 : FIRST_SCREEN_CAPTURE_FAILED); | 253 : FIRST_SCREEN_CAPTURE_FAILED); |
338 } else { | 254 } else { |
339 IncrementDesktopCaptureCounter(succeeded | 255 IncrementDesktopCaptureCounter(succeeded |
340 ? FIRST_WINDOW_CAPTURE_SUCCEEDED | 256 ? FIRST_WINDOW_CAPTURE_SUCCEEDED |
341 : FIRST_WINDOW_CAPTURE_FAILED); | 257 : FIRST_WINDOW_CAPTURE_FAILED); |
342 } | 258 } |
343 } | 259 } |
344 } | 260 } |
345 | 261 |
346 bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse( | 262 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( |
347 scoped_refptr<media::VideoFrame> video_frame, | 263 scoped_refptr<media::VideoFrame> video_frame, |
348 base::TimeTicks start_time, | 264 base::TimeTicks start_time, |
349 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 265 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
350 scoped_ptr<cc::CopyOutputResult> result) { | 266 scoped_ptr<cc::CopyOutputResult> result) { |
351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
352 | 268 |
353 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) | 269 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) |
354 return false; | 270 return false; |
355 | 271 |
356 if (capture_params_.requested_format.pixel_format == | 272 if (capture_params_.requested_format.pixel_format == |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 base::Bind(&CopyOutputFinishedForVideo, | 341 base::Bind(&CopyOutputFinishedForVideo, |
426 start_time, | 342 start_time, |
427 capture_frame_cb, | 343 capture_frame_cb, |
428 video_frame, | 344 video_frame, |
429 scaled_cursor_bitmap_, | 345 scaled_cursor_bitmap_, |
430 cursor_position_in_frame, | 346 cursor_position_in_frame, |
431 base::Passed(&release_callback))); | 347 base::Passed(&release_callback))); |
432 return true; | 348 return true; |
433 } | 349 } |
434 | 350 |
435 gfx::Point DesktopVideoCaptureMachine::UpdateCursorState( | 351 gfx::Point AuraWindowCaptureMachine::UpdateCursorState( |
436 const gfx::Rect& region_in_frame) { | 352 const gfx::Rect& region_in_frame) { |
437 const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds(); | 353 const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds(); |
438 if (desktop_bounds.IsEmpty()) { | 354 if (desktop_bounds.IsEmpty()) { |
439 // Return early to prevent divide-by-zero in calculations below. | 355 // Return early to prevent divide-by-zero in calculations below. |
440 ClearCursorState(); | 356 ClearCursorState(); |
441 return gfx::Point(); | 357 return gfx::Point(); |
442 } | 358 } |
443 | 359 |
444 gfx::NativeCursor cursor = | 360 gfx::NativeCursor cursor = |
445 desktop_window_->GetHost()->last_cursor(); | 361 desktop_window_->GetHost()->last_cursor(); |
(...skipping 30 matching lines...) Expand all Loading... | |
476 desktop_window_->layer(), cursor_hot_point_); | 392 desktop_window_->layer(), cursor_hot_point_); |
477 cursor_position.Offset(-desktop_bounds.x() - hot_point_in_dip.x(), | 393 cursor_position.Offset(-desktop_bounds.x() - hot_point_in_dip.x(), |
478 -desktop_bounds.y() - hot_point_in_dip.y()); | 394 -desktop_bounds.y() - hot_point_in_dip.y()); |
479 return gfx::Point( | 395 return gfx::Point( |
480 region_in_frame.x() + cursor_position.x() * region_in_frame.width() / | 396 region_in_frame.x() + cursor_position.x() * region_in_frame.width() / |
481 desktop_bounds.width(), | 397 desktop_bounds.width(), |
482 region_in_frame.y() + cursor_position.y() * region_in_frame.height() / | 398 region_in_frame.y() + cursor_position.y() * region_in_frame.height() / |
483 desktop_bounds.height()); | 399 desktop_bounds.height()); |
484 } | 400 } |
485 | 401 |
486 void DesktopVideoCaptureMachine::ClearCursorState() { | 402 void AuraWindowCaptureMachine::ClearCursorState() { |
487 last_cursor_ = ui::Cursor(); | 403 last_cursor_ = ui::Cursor(); |
488 desktop_size_when_cursor_last_updated_ = gfx::Size(); | 404 desktop_size_when_cursor_last_updated_ = gfx::Size(); |
489 cursor_hot_point_ = gfx::Point(); | 405 cursor_hot_point_ = gfx::Point(); |
490 scaled_cursor_bitmap_.reset(); | 406 scaled_cursor_bitmap_.reset(); |
491 } | 407 } |
492 | 408 |
493 void DesktopVideoCaptureMachine::OnWindowBoundsChanged( | 409 void AuraWindowCaptureMachine::OnWindowBoundsChanged( |
494 aura::Window* window, | 410 aura::Window* window, |
495 const gfx::Rect& old_bounds, | 411 const gfx::Rect& old_bounds, |
496 const gfx::Rect& new_bounds) { | 412 const gfx::Rect& new_bounds) { |
497 DCHECK(desktop_window_ && window == desktop_window_); | 413 DCHECK(desktop_window_ && window == desktop_window_); |
498 | 414 |
499 // Post task to update capture size on UI thread. | 415 // Post task to update capture size on UI thread. |
500 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 416 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
501 &DesktopVideoCaptureMachine::UpdateCaptureSize, AsWeakPtr())); | 417 &AuraWindowCaptureMachine::UpdateCaptureSize, AsWeakPtr())); |
502 } | 418 } |
503 | 419 |
504 void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) { | 420 void AuraWindowCaptureMachine::OnWindowDestroyed(aura::Window* window) { |
505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
506 | 422 |
507 Stop(base::Bind(&base::DoNothing)); | 423 Stop(base::Bind(&base::DoNothing)); |
508 | 424 |
509 oracle_proxy_->ReportError("OnWindowDestroyed()"); | 425 oracle_proxy_->ReportError("OnWindowDestroyed()"); |
510 } | 426 } |
511 | 427 |
512 void DesktopVideoCaptureMachine::OnWindowAddedToRootWindow( | 428 void AuraWindowCaptureMachine::OnWindowAddedToRootWindow( |
513 aura::Window* window) { | 429 aura::Window* window) { |
514 DCHECK(window == desktop_window_); | 430 DCHECK(window == desktop_window_); |
515 window->GetHost()->compositor()->AddObserver(this); | 431 window->GetHost()->compositor()->AddObserver(this); |
516 } | 432 } |
517 | 433 |
518 void DesktopVideoCaptureMachine::OnWindowRemovingFromRootWindow( | 434 void AuraWindowCaptureMachine::OnWindowRemovingFromRootWindow( |
519 aura::Window* window, | 435 aura::Window* window, |
520 aura::Window* new_root) { | 436 aura::Window* new_root) { |
521 DCHECK(window == desktop_window_); | 437 DCHECK(window == desktop_window_); |
522 window->GetHost()->compositor()->RemoveObserver(this); | 438 window->GetHost()->compositor()->RemoveObserver(this); |
523 } | 439 } |
524 | 440 |
525 void DesktopVideoCaptureMachine::OnCompositingEnded( | 441 void AuraWindowCaptureMachine::OnCompositingEnded( |
526 ui::Compositor* compositor) { | 442 ui::Compositor* compositor) { |
527 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 443 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
528 &DesktopVideoCaptureMachine::Capture, AsWeakPtr(), true)); | 444 &AuraWindowCaptureMachine::Capture, AsWeakPtr(), true)); |
529 } | |
530 | |
531 } // namespace | |
532 | |
533 DesktopCaptureDeviceAura::DesktopCaptureDeviceAura( | |
534 const DesktopMediaID& source) | |
535 : core_(new ContentVideoCaptureDeviceCore(scoped_ptr<VideoCaptureMachine>( | |
536 new DesktopVideoCaptureMachine(source)))) {} | |
537 | |
538 DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { | |
539 DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; | |
540 } | |
541 | |
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 } | 445 } |
561 | 446 |
562 } // namespace content | 447 } // namespace content |
OLD | NEW |