| 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); |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 305 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 301 | 306 |
| 302 release_callback->Run(gpu::SyncToken(), false); | 307 release_callback->Run(gpu::SyncToken(), false); |
| 303 | 308 |
| 304 // Render the cursor and deliver the captured frame if the | 309 // Render the cursor and deliver the captured frame if the |
| 305 // AuraWindowCaptureMachine has not been stopped (i.e., the WeakPtr is | 310 // AuraWindowCaptureMachine has not been stopped (i.e., the WeakPtr is |
| 306 // still valid). | 311 // still valid). |
| 307 if (machine) { | 312 if (machine) { |
| 308 if (machine->cursor_renderer_ && result) | 313 if (machine->cursor_renderer_ && result) |
| 309 machine->cursor_renderer_->RenderOnVideoFrame(target); | 314 machine->cursor_renderer_->RenderOnVideoFrame(target); |
| 310 capture_frame_cb.Run(target, start_time, result); | 315 } else { |
| 316 result = false; |
| 311 } | 317 } |
| 318 |
| 319 capture_frame_cb.Run(target, start_time, result); |
| 312 } | 320 } |
| 313 | 321 |
| 314 void AuraWindowCaptureMachine::OnWindowBoundsChanged( | 322 void AuraWindowCaptureMachine::OnWindowBoundsChanged( |
| 315 aura::Window* window, | 323 aura::Window* window, |
| 316 const gfx::Rect& old_bounds, | 324 const gfx::Rect& old_bounds, |
| 317 const gfx::Rect& new_bounds) { | 325 const gfx::Rect& new_bounds) { |
| 318 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 326 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 319 DCHECK(desktop_window_ && window == desktop_window_); | 327 DCHECK(desktop_window_ && window == desktop_window_); |
| 320 | 328 |
| 321 // Post a task to update capture size after first returning to the event loop. | 329 // 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... |
| 356 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). | 364 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). |
| 357 // http://crbug.com/492839 | 365 // http://crbug.com/492839 |
| 358 BrowserThread::PostTask( | 366 BrowserThread::PostTask( |
| 359 BrowserThread::UI, | 367 BrowserThread::UI, |
| 360 FROM_HERE, | 368 FROM_HERE, |
| 361 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), | 369 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), |
| 362 true)); | 370 true)); |
| 363 } | 371 } |
| 364 | 372 |
| 365 } // namespace content | 373 } // namespace content |
| OLD | NEW |