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 "chrome/browser/media/webrtc/native_desktop_media_list.h" | 5 #include "chrome/browser/media/webrtc/native_desktop_media_list.h" |
6 | 6 |
7 #include "base/hash.h" | 7 #include "base/hash.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/task_scheduler/post_task.h" |
10 #include "chrome/browser/media/webrtc/desktop_media_list_observer.h" | 10 #include "chrome/browser/media/webrtc/desktop_media_list_observer.h" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "media/base/video_util.h" | 13 #include "media/base/video_util.h" |
14 #include "third_party/libyuv/include/libyuv/scale_argb.h" | 14 #include "third_party/libyuv/include/libyuv/scale_argb.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 16 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
17 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 17 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 std::unique_ptr<webrtc::DesktopFrame> frame) { | 230 std::unique_ptr<webrtc::DesktopFrame> frame) { |
231 current_frame_ = std::move(frame); | 231 current_frame_ = std::move(frame); |
232 } | 232 } |
233 | 233 |
234 NativeDesktopMediaList::NativeDesktopMediaList( | 234 NativeDesktopMediaList::NativeDesktopMediaList( |
235 std::unique_ptr<webrtc::DesktopCapturer> screen_capturer, | 235 std::unique_ptr<webrtc::DesktopCapturer> screen_capturer, |
236 std::unique_ptr<webrtc::DesktopCapturer> window_capturer) | 236 std::unique_ptr<webrtc::DesktopCapturer> window_capturer) |
237 : DesktopMediaListBase( | 237 : DesktopMediaListBase( |
238 base::TimeDelta::FromMilliseconds(kDefaultUpdatePeriod)), | 238 base::TimeDelta::FromMilliseconds(kDefaultUpdatePeriod)), |
239 weak_factory_(this) { | 239 weak_factory_(this) { |
240 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 240 capture_task_runner_ = base::CreateSequencedTaskRunnerWithTraits( |
241 capture_task_runner_ = worker_pool->GetSequencedTaskRunner( | 241 {base::MayBlock(), base::TaskPriority::USER_VISIBLE}); |
242 worker_pool->GetSequenceToken()); | |
243 | 242 |
244 worker_.reset(new Worker(weak_factory_.GetWeakPtr(), | 243 worker_.reset(new Worker(weak_factory_.GetWeakPtr(), |
245 std::move(screen_capturer), | 244 std::move(screen_capturer), |
246 std::move(window_capturer))); | 245 std::move(window_capturer))); |
247 } | 246 } |
248 | 247 |
249 NativeDesktopMediaList::~NativeDesktopMediaList() { | 248 NativeDesktopMediaList::~NativeDesktopMediaList() { |
250 capture_task_runner_->DeleteSoon(FROM_HERE, worker_.release()); | 249 capture_task_runner_->DeleteSoon(FROM_HERE, worker_.release()); |
251 } | 250 } |
252 | 251 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 gfx::NativeWindow window = DesktopMediaID::GetAuraWindowById(id); | 337 gfx::NativeWindow window = DesktopMediaID::GetAuraWindowById(id); |
339 if (!window) | 338 if (!window) |
340 return; | 339 return; |
341 | 340 |
342 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); | 341 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); |
343 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( | 342 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( |
344 gfx::Rect(thumbnail_size_), window_rect.size()); | 343 gfx::Rect(thumbnail_size_), window_rect.size()); |
345 | 344 |
346 pending_aura_capture_requests_++; | 345 pending_aura_capture_requests_++; |
347 ui::GrabWindowSnapshotAndScaleAsyncAura( | 346 ui::GrabWindowSnapshotAndScaleAsyncAura( |
348 window, window_rect, scaled_rect.size(), BrowserThread::GetBlockingPool(), | 347 window, window_rect, scaled_rect.size(), |
| 348 base::CreateTaskRunnerWithTraits( |
| 349 {base::MayBlock(), base::TaskPriority::USER_VISIBLE}), |
349 base::Bind(&NativeDesktopMediaList::OnAuraThumbnailCaptured, | 350 base::Bind(&NativeDesktopMediaList::OnAuraThumbnailCaptured, |
350 weak_factory_.GetWeakPtr(), id)); | 351 weak_factory_.GetWeakPtr(), id)); |
351 } | 352 } |
352 | 353 |
353 void NativeDesktopMediaList::OnAuraThumbnailCaptured(const DesktopMediaID& id, | 354 void NativeDesktopMediaList::OnAuraThumbnailCaptured(const DesktopMediaID& id, |
354 const gfx::Image& image) { | 355 const gfx::Image& image) { |
355 if (!image.IsEmpty()) { | 356 if (!image.IsEmpty()) { |
356 // Only new or changed thumbnail need update. | 357 // Only new or changed thumbnail need update. |
357 new_aura_thumbnail_hashes_[id] = GetImageHash(image); | 358 new_aura_thumbnail_hashes_[id] = GetImageHash(image); |
358 if (!previous_aura_thumbnail_hashes_.count(id) || | 359 if (!previous_aura_thumbnail_hashes_.count(id) || |
359 previous_aura_thumbnail_hashes_[id] != new_aura_thumbnail_hashes_[id]) { | 360 previous_aura_thumbnail_hashes_[id] != new_aura_thumbnail_hashes_[id]) { |
360 UpdateSourceThumbnail(id, image.AsImageSkia()); | 361 UpdateSourceThumbnail(id, image.AsImageSkia()); |
361 } | 362 } |
362 } | 363 } |
363 | 364 |
364 // After all aura windows are processed, schedule next refresh; | 365 // After all aura windows are processed, schedule next refresh; |
365 pending_aura_capture_requests_--; | 366 pending_aura_capture_requests_--; |
366 DCHECK_GE(pending_aura_capture_requests_, 0); | 367 DCHECK_GE(pending_aura_capture_requests_, 0); |
367 if (pending_aura_capture_requests_ == 0) { | 368 if (pending_aura_capture_requests_ == 0) { |
368 previous_aura_thumbnail_hashes_ = std::move(new_aura_thumbnail_hashes_); | 369 previous_aura_thumbnail_hashes_ = std::move(new_aura_thumbnail_hashes_); |
369 // Schedule next refresh if aura thumbnail captures finished after native | 370 // Schedule next refresh if aura thumbnail captures finished after native |
370 // thumbnail captures. | 371 // thumbnail captures. |
371 if (!pending_native_thumbnail_capture_) | 372 if (!pending_native_thumbnail_capture_) |
372 ScheduleNextRefresh(); | 373 ScheduleNextRefresh(); |
373 } | 374 } |
374 } | 375 } |
375 | 376 |
376 #endif // defined(USE_AURA) | 377 #endif // defined(USE_AURA) |
OLD | NEW |