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 "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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 AuraWindowCaptureMachine::AuraWindowCaptureMachine() | 113 AuraWindowCaptureMachine::AuraWindowCaptureMachine() |
114 : desktop_window_(NULL), | 114 : desktop_window_(NULL), |
115 timer_(true, true), | 115 timer_(true, true), |
116 screen_capture_(false) {} | 116 screen_capture_(false) {} |
117 | 117 |
118 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} | 118 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
119 | 119 |
120 bool AuraWindowCaptureMachine::Start( | 120 bool AuraWindowCaptureMachine::Start( |
121 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 121 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
122 const media::VideoCaptureParams& params) { | 122 const media::VideoCaptureParams& params) { |
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
124 | 124 |
125 // The window might be destroyed between SetWindow() and Start(). | 125 // The window might be destroyed between SetWindow() and Start(). |
126 if (!desktop_window_) | 126 if (!desktop_window_) |
127 return false; | 127 return false; |
128 | 128 |
129 // If the associated layer is already destroyed then return failure. | 129 // If the associated layer is already destroyed then return failure. |
130 ui::Layer* layer = desktop_window_->layer(); | 130 ui::Layer* layer = desktop_window_->layer(); |
131 if (!layer) | 131 if (!layer) |
132 return false; | 132 return false; |
133 | 133 |
(...skipping 16 matching lines...) Expand all Loading... |
150 | 150 |
151 // Starts timer. | 151 // Starts timer. |
152 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), | 152 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), |
153 base::Bind(&AuraWindowCaptureMachine::Capture, AsWeakPtr(), | 153 base::Bind(&AuraWindowCaptureMachine::Capture, AsWeakPtr(), |
154 false)); | 154 false)); |
155 | 155 |
156 return true; | 156 return true; |
157 } | 157 } |
158 | 158 |
159 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { | 159 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { |
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
161 power_save_blocker_.reset(); | 161 power_save_blocker_.reset(); |
162 | 162 |
163 // Stop observing compositor and window events. | 163 // Stop observing compositor and window events. |
164 if (desktop_window_) { | 164 if (desktop_window_) { |
165 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); | 165 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); |
166 // In the host destructor the compositor is destroyed before the window. | 166 // In the host destructor the compositor is destroyed before the window. |
167 if (window_host && window_host->compositor()) | 167 if (window_host && window_host->compositor()) |
168 window_host->compositor()->RemoveObserver(this); | 168 window_host->compositor()->RemoveObserver(this); |
169 desktop_window_->RemoveObserver(this); | 169 desktop_window_->RemoveObserver(this); |
170 desktop_window_ = NULL; | 170 desktop_window_ = NULL; |
171 } | 171 } |
172 | 172 |
173 // Stop timer. | 173 // Stop timer. |
174 timer_.Stop(); | 174 timer_.Stop(); |
175 | 175 |
176 callback.Run(); | 176 callback.Run(); |
177 } | 177 } |
178 | 178 |
179 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { | 179 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { |
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 180 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
181 | 181 |
182 DCHECK(!desktop_window_); | 182 DCHECK(!desktop_window_); |
183 desktop_window_ = window; | 183 desktop_window_ = window; |
184 | 184 |
185 // Start observing window events. | 185 // Start observing window events. |
186 desktop_window_->AddObserver(this); | 186 desktop_window_->AddObserver(this); |
187 | 187 |
188 // We must store this for the UMA reporting in DidCopyOutput() as | 188 // We must store this for the UMA reporting in DidCopyOutput() as |
189 // desktop_window_ might be destroyed at that point. | 189 // desktop_window_ might be destroyed at that point. |
190 screen_capture_ = window->IsRootWindow(); | 190 screen_capture_ = window->IsRootWindow(); |
191 IncrementDesktopCaptureCounter(screen_capture_ ? SCREEN_CAPTURER_CREATED | 191 IncrementDesktopCaptureCounter(screen_capture_ ? SCREEN_CAPTURER_CREATED |
192 : WINDOW_CAPTURER_CREATED); | 192 : WINDOW_CAPTURER_CREATED); |
193 } | 193 } |
194 | 194 |
195 void AuraWindowCaptureMachine::UpdateCaptureSize() { | 195 void AuraWindowCaptureMachine::UpdateCaptureSize() { |
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
197 if (oracle_proxy_.get() && desktop_window_) { | 197 if (oracle_proxy_.get() && desktop_window_) { |
198 ui::Layer* layer = desktop_window_->layer(); | 198 ui::Layer* layer = desktop_window_->layer(); |
199 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( | 199 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( |
200 layer, layer->bounds().size())); | 200 layer, layer->bounds().size())); |
201 } | 201 } |
202 ClearCursorState(); | 202 ClearCursorState(); |
203 } | 203 } |
204 | 204 |
205 void AuraWindowCaptureMachine::Capture(bool dirty) { | 205 void AuraWindowCaptureMachine::Capture(bool dirty) { |
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 206 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
207 | 207 |
208 // Do not capture if the desktop window is already destroyed. | 208 // Do not capture if the desktop window is already destroyed. |
209 if (!desktop_window_) | 209 if (!desktop_window_) |
210 return; | 210 return; |
211 | 211 |
212 scoped_refptr<media::VideoFrame> frame; | 212 scoped_refptr<media::VideoFrame> frame; |
213 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 213 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
214 | 214 |
215 const base::TimeTicks start_time = base::TimeTicks::Now(); | 215 const base::TimeTicks start_time = base::TimeTicks::Now(); |
216 const VideoCaptureOracle::Event event = | 216 const VideoCaptureOracle::Event event = |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 : FIRST_WINDOW_CAPTURE_FAILED); | 260 : FIRST_WINDOW_CAPTURE_FAILED); |
261 } | 261 } |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( | 265 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( |
266 scoped_refptr<media::VideoFrame> video_frame, | 266 scoped_refptr<media::VideoFrame> video_frame, |
267 base::TimeTicks start_time, | 267 base::TimeTicks start_time, |
268 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 268 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
269 scoped_ptr<cc::CopyOutputResult> result) { | 269 scoped_ptr<cc::CopyOutputResult> result) { |
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 270 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
271 | 271 |
272 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) | 272 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) |
273 return false; | 273 return false; |
274 | 274 |
275 if (capture_params_.requested_format.pixel_format == | 275 if (capture_params_.requested_format.pixel_format == |
276 media::PIXEL_FORMAT_TEXTURE) { | 276 media::PIXEL_FORMAT_TEXTURE) { |
277 DCHECK(!video_frame.get()); | 277 DCHECK(!video_frame.get()); |
278 cc::TextureMailbox texture_mailbox; | 278 cc::TextureMailbox texture_mailbox; |
279 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 279 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
280 result->TakeTexture(&texture_mailbox, &release_callback); | 280 result->TakeTexture(&texture_mailbox, &release_callback); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 const gfx::Rect& old_bounds, | 414 const gfx::Rect& old_bounds, |
415 const gfx::Rect& new_bounds) { | 415 const gfx::Rect& new_bounds) { |
416 DCHECK(desktop_window_ && window == desktop_window_); | 416 DCHECK(desktop_window_ && window == desktop_window_); |
417 | 417 |
418 // Post task to update capture size on UI thread. | 418 // Post task to update capture size on UI thread. |
419 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 419 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
420 &AuraWindowCaptureMachine::UpdateCaptureSize, AsWeakPtr())); | 420 &AuraWindowCaptureMachine::UpdateCaptureSize, AsWeakPtr())); |
421 } | 421 } |
422 | 422 |
423 void AuraWindowCaptureMachine::OnWindowDestroyed(aura::Window* window) { | 423 void AuraWindowCaptureMachine::OnWindowDestroyed(aura::Window* window) { |
424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 424 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
425 | 425 |
426 Stop(base::Bind(&base::DoNothing)); | 426 Stop(base::Bind(&base::DoNothing)); |
427 | 427 |
428 oracle_proxy_->ReportError("OnWindowDestroyed()"); | 428 oracle_proxy_->ReportError("OnWindowDestroyed()"); |
429 } | 429 } |
430 | 430 |
431 void AuraWindowCaptureMachine::OnWindowAddedToRootWindow( | 431 void AuraWindowCaptureMachine::OnWindowAddedToRootWindow( |
432 aura::Window* window) { | 432 aura::Window* window) { |
433 DCHECK(window == desktop_window_); | 433 DCHECK(window == desktop_window_); |
434 window->GetHost()->compositor()->AddObserver(this); | 434 window->GetHost()->compositor()->AddObserver(this); |
435 } | 435 } |
436 | 436 |
437 void AuraWindowCaptureMachine::OnWindowRemovingFromRootWindow( | 437 void AuraWindowCaptureMachine::OnWindowRemovingFromRootWindow( |
438 aura::Window* window, | 438 aura::Window* window, |
439 aura::Window* new_root) { | 439 aura::Window* new_root) { |
440 DCHECK(window == desktop_window_); | 440 DCHECK(window == desktop_window_); |
441 window->GetHost()->compositor()->RemoveObserver(this); | 441 window->GetHost()->compositor()->RemoveObserver(this); |
442 } | 442 } |
443 | 443 |
444 void AuraWindowCaptureMachine::OnCompositingEnded( | 444 void AuraWindowCaptureMachine::OnCompositingEnded( |
445 ui::Compositor* compositor) { | 445 ui::Compositor* compositor) { |
446 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 446 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
447 &AuraWindowCaptureMachine::Capture, AsWeakPtr(), true)); | 447 &AuraWindowCaptureMachine::Capture, AsWeakPtr(), true)); |
448 } | 448 } |
449 | 449 |
450 } // namespace content | 450 } // namespace content |
OLD | NEW |