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/aura_window_capture_machine.h" | 5 #include "content/browser/media/capture/aura_window_capture_machine.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 | 192 |
193 void AuraWindowCaptureMachine::DidCopyOutput( | 193 void AuraWindowCaptureMachine::DidCopyOutput( |
194 scoped_refptr<media::VideoFrame> video_frame, | 194 scoped_refptr<media::VideoFrame> video_frame, |
195 base::TimeTicks start_time, | 195 base::TimeTicks start_time, |
196 const CaptureFrameCallback& capture_frame_cb, | 196 const CaptureFrameCallback& capture_frame_cb, |
197 std::unique_ptr<cc::CopyOutputResult> result) { | 197 std::unique_ptr<cc::CopyOutputResult> result) { |
198 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 198 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
199 | 199 |
200 static bool first_call = true; | 200 static bool first_call = true; |
201 | 201 |
202 bool succeeded = ProcessCopyOutputResponse( | 202 const bool succeeded = ProcessCopyOutputResponse( |
203 video_frame, start_time, capture_frame_cb, std::move(result)); | 203 video_frame, start_time, capture_frame_cb, std::move(result)); |
204 | 204 |
205 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; | 205 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; |
206 | 206 |
207 // The two UMA_ blocks must be put in its own scope since it creates a static | 207 // The two UMA_ blocks must be put in its own scope since it creates a static |
208 // variable which expected constant histogram name. | 208 // variable which expected constant histogram name. |
209 if (screen_capture_) { | 209 if (screen_capture_) { |
210 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); | 210 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); |
211 } else { | 211 } else { |
212 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); | 212 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); |
213 } | 213 } |
214 | 214 |
215 if (first_call) { | 215 if (first_call) { |
216 first_call = false; | 216 first_call = false; |
217 if (screen_capture_) { | 217 if (screen_capture_) { |
218 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED | 218 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED |
219 : FIRST_SCREEN_CAPTURE_FAILED); | 219 : FIRST_SCREEN_CAPTURE_FAILED); |
220 } else { | 220 } else { |
221 IncrementDesktopCaptureCounter(succeeded | 221 IncrementDesktopCaptureCounter(succeeded |
222 ? FIRST_WINDOW_CAPTURE_SUCCEEDED | 222 ? FIRST_WINDOW_CAPTURE_SUCCEEDED |
223 : FIRST_WINDOW_CAPTURE_FAILED); | 223 : FIRST_WINDOW_CAPTURE_FAILED); |
224 } | 224 } |
225 } | 225 } |
226 | |
227 // If ProcessCopyOutputResponse() failed, it will not run |capture_frame_cb|, | |
228 // so do that now. | |
229 if (!succeeded) | |
230 capture_frame_cb.Run(video_frame, start_time, false); | |
GeorgeZ
2016/04/23 18:47:15
There is one more loop hole in
https://code.googl
miu
2016/04/26 02:27:58
Done. Good catch.
| |
226 } | 231 } |
227 | 232 |
228 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( | 233 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( |
229 scoped_refptr<media::VideoFrame> video_frame, | 234 scoped_refptr<media::VideoFrame> video_frame, |
230 base::TimeTicks start_time, | 235 base::TimeTicks start_time, |
231 const CaptureFrameCallback& capture_frame_cb, | 236 const CaptureFrameCallback& capture_frame_cb, |
232 std::unique_ptr<cc::CopyOutputResult> result) { | 237 std::unique_ptr<cc::CopyOutputResult> result) { |
233 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 238 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
234 | 239 |
235 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) | 240 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 308 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
304 | 309 |
305 release_callback->Run(gpu::SyncToken(), false); | 310 release_callback->Run(gpu::SyncToken(), false); |
306 | 311 |
307 // Render the cursor and deliver the captured frame if the | 312 // Render the cursor and deliver the captured frame if the |
308 // AuraWindowCaptureMachine has not been stopped (i.e., the WeakPtr is | 313 // AuraWindowCaptureMachine has not been stopped (i.e., the WeakPtr is |
309 // still valid). | 314 // still valid). |
310 if (machine) { | 315 if (machine) { |
311 if (machine->cursor_renderer_ && result) | 316 if (machine->cursor_renderer_ && result) |
312 machine->cursor_renderer_->RenderOnVideoFrame(target); | 317 machine->cursor_renderer_->RenderOnVideoFrame(target); |
313 capture_frame_cb.Run(target, start_time, result); | 318 } else { |
319 result = false; | |
314 } | 320 } |
321 | |
322 capture_frame_cb.Run(target, start_time, result); | |
GeorgeZ
2016/04/23 18:47:15
You may add a check for result (bool success) in v
miu
2016/04/26 02:27:58
VideoCaptureOracle::CompleteCapture() must be call
| |
315 } | 323 } |
316 | 324 |
317 void AuraWindowCaptureMachine::OnWindowBoundsChanged( | 325 void AuraWindowCaptureMachine::OnWindowBoundsChanged( |
318 aura::Window* window, | 326 aura::Window* window, |
319 const gfx::Rect& old_bounds, | 327 const gfx::Rect& old_bounds, |
320 const gfx::Rect& new_bounds) { | 328 const gfx::Rect& new_bounds) { |
321 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 329 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
322 DCHECK(desktop_window_ && window == desktop_window_); | 330 DCHECK(desktop_window_ && window == desktop_window_); |
323 | 331 |
324 // Post a task to update capture size after first returning to the event loop. | 332 // Post a task to update capture size after first returning to the event loop. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). | 367 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). |
360 // http://crbug.com/492839 | 368 // http://crbug.com/492839 |
361 BrowserThread::PostTask( | 369 BrowserThread::PostTask( |
362 BrowserThread::UI, | 370 BrowserThread::UI, |
363 FROM_HERE, | 371 FROM_HERE, |
364 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), | 372 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), |
365 true)); | 373 true)); |
366 } | 374 } |
367 | 375 |
368 } // namespace content | 376 } // namespace content |
OLD | NEW |