| 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/threading/sequenced_worker_pool.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" |
| 20 #include "ui/snapshot/snapshot.h" | 20 #include "ui/snapshot/snapshot.h" |
| 21 | 21 |
| 22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 23 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" | 23 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" |
| 24 #endif // defined(OS_WIN) | 24 #endif // defined(OS_WIN) |
| 25 | 25 |
| 26 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 26 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 27 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 27 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 28 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) | 28 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) |
| 29 | 29 |
| 30 #if defined(USE_AURA) |
| 31 #include "ui/snapshot/snapshot_aura.h" |
| 32 #endif |
| 33 |
| 30 using content::BrowserThread; | 34 using content::BrowserThread; |
| 31 using content::DesktopMediaID; | 35 using content::DesktopMediaID; |
| 32 | 36 |
| 33 namespace { | 37 namespace { |
| 34 | 38 |
| 35 // Update the list every second. | 39 // Update the list every second. |
| 36 const int kDefaultUpdatePeriod = 1000; | 40 const int kDefaultUpdatePeriod = 1000; |
| 37 | 41 |
| 38 // Returns a hash of a DesktopFrame content to detect when image for a desktop | 42 // Returns a hash of a DesktopFrame content to detect when image for a desktop |
| 39 // media source has changed. | 43 // media source has changed. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 const DesktopMediaID& id) { | 339 const DesktopMediaID& id) { |
| 336 gfx::NativeWindow window = DesktopMediaID::GetAuraWindowById(id); | 340 gfx::NativeWindow window = DesktopMediaID::GetAuraWindowById(id); |
| 337 if (!window) | 341 if (!window) |
| 338 return; | 342 return; |
| 339 | 343 |
| 340 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); | 344 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); |
| 341 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( | 345 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( |
| 342 gfx::Rect(thumbnail_size_), window_rect.size()); | 346 gfx::Rect(thumbnail_size_), window_rect.size()); |
| 343 | 347 |
| 344 pending_aura_capture_requests_++; | 348 pending_aura_capture_requests_++; |
| 345 ui::GrabWindowSnapshotAndScaleAsync( | 349 ui::GrabWindowSnapshotAndScaleAsyncAura( |
| 346 window, window_rect, scaled_rect.size(), BrowserThread::GetBlockingPool(), | 350 window, window_rect, scaled_rect.size(), BrowserThread::GetBlockingPool(), |
| 347 base::Bind(&NativeDesktopMediaList::OnAuraThumbnailCaptured, | 351 base::Bind(&NativeDesktopMediaList::OnAuraThumbnailCaptured, |
| 348 weak_factory_.GetWeakPtr(), id)); | 352 weak_factory_.GetWeakPtr(), id)); |
| 349 } | 353 } |
| 350 | 354 |
| 351 void NativeDesktopMediaList::OnAuraThumbnailCaptured(const DesktopMediaID& id, | 355 void NativeDesktopMediaList::OnAuraThumbnailCaptured(const DesktopMediaID& id, |
| 352 const gfx::Image& image) { | 356 const gfx::Image& image) { |
| 353 if (!image.IsEmpty()) { | 357 if (!image.IsEmpty()) { |
| 354 // Only new or changed thumbnail need update. | 358 // Only new or changed thumbnail need update. |
| 355 new_aura_thumbnail_hashes_[id] = GetImageHash(image); | 359 new_aura_thumbnail_hashes_[id] = GetImageHash(image); |
| 356 if (!previous_aura_thumbnail_hashes_.count(id) || | 360 if (!previous_aura_thumbnail_hashes_.count(id) || |
| 357 previous_aura_thumbnail_hashes_[id] != new_aura_thumbnail_hashes_[id]) { | 361 previous_aura_thumbnail_hashes_[id] != new_aura_thumbnail_hashes_[id]) { |
| 358 UpdateSourceThumbnail(id, image.AsImageSkia()); | 362 UpdateSourceThumbnail(id, image.AsImageSkia()); |
| 359 } | 363 } |
| 360 } | 364 } |
| 361 | 365 |
| 362 // After all aura windows are processed, schedule next refresh; | 366 // After all aura windows are processed, schedule next refresh; |
| 363 pending_aura_capture_requests_--; | 367 pending_aura_capture_requests_--; |
| 364 DCHECK_GE(pending_aura_capture_requests_, 0); | 368 DCHECK_GE(pending_aura_capture_requests_, 0); |
| 365 if (pending_aura_capture_requests_ == 0) { | 369 if (pending_aura_capture_requests_ == 0) { |
| 366 previous_aura_thumbnail_hashes_ = std::move(new_aura_thumbnail_hashes_); | 370 previous_aura_thumbnail_hashes_ = std::move(new_aura_thumbnail_hashes_); |
| 367 // Schedule next refresh if aura thumbnail captures finished after native | 371 // Schedule next refresh if aura thumbnail captures finished after native |
| 368 // thumbnail captures. | 372 // thumbnail captures. |
| 369 if (!pending_native_thumbnail_capture_) | 373 if (!pending_native_thumbnail_capture_) |
| 370 ScheduleNextRefresh(); | 374 ScheduleNextRefresh(); |
| 371 } | 375 } |
| 372 } | 376 } |
| 373 | 377 |
| 374 #endif // defined(USE_AURA) | 378 #endif // defined(USE_AURA) |
| OLD | NEW |