Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2103)

Unified Diff: chrome/browser/media/native_desktop_media_list.cc

Issue 1808273002: Use DesktopCaptureDeviceAura for all aura windows in Windows and Linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media/native_desktop_media_list.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/native_desktop_media_list.cc
diff --git a/chrome/browser/media/native_desktop_media_list.cc b/chrome/browser/media/native_desktop_media_list.cc
index 06e0751a6bc4cbeaefa355986dd8bbc728585062..87c820643920643bf7e2bd41ad0729e08157737e 100644
--- a/chrome/browser/media/native_desktop_media_list.cc
+++ b/chrome/browser/media/native_desktop_media_list.cc
@@ -25,6 +25,14 @@
#include "ui/gfx/native_widget_types.h"
#include "ui/snapshot/snapshot.h"
+#if defined(OS_WIN)
+#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
+#endif
+
+#if defined(USE_X11) && !defined(OS_CHROMEOS)
+#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
+#endif
+
using content::BrowserThread;
using content::DesktopMediaID;
@@ -74,33 +82,6 @@ gfx::ImageSkia ScaleDesktopFrame(scoped_ptr<webrtc::DesktopFrame> frame,
return gfx::ImageSkia::CreateFrom1xBitmap(result);
}
-#if defined(USE_AURA)
-
-NativeDesktopMediaList::NativeAuraIdMap GetBrowserNativeAuraIdMap() {
- NativeDesktopMediaList::NativeAuraIdMap id_map;
- for (auto* browser : *BrowserList::GetInstance()) {
- aura::Window* aura_window = browser->window()->GetNativeWindow();
- if (!aura_window)
- continue;
- aura::WindowTreeHost* host = aura_window->GetHost();
- if (!host)
- continue;
- gfx::AcceleratedWidget widget = host->GetAcceleratedWidget();
-#if defined(OS_WIN)
- DesktopMediaID::Id native_id = reinterpret_cast<DesktopMediaID::Id>(widget);
-#else
- DesktopMediaID::Id native_id = widget;
-#endif
- DesktopMediaID media_id = DesktopMediaID::RegisterAuraWindow(
- DesktopMediaID::TYPE_WINDOW, aura_window);
- id_map[native_id] = media_id.aura_id;
- }
-
- return id_map;
-}
-
-#endif // defined(USE_AURA)
-
} // namespace
class NativeDesktopMediaList::Worker
@@ -111,9 +92,10 @@ class NativeDesktopMediaList::Worker
scoped_ptr<webrtc::WindowCapturer> window_capturer);
~Worker() override;
- void Refresh(const gfx::Size& thumbnail_size,
- const DesktopMediaID::Id& view_dialog_id,
- const NativeAuraIdMap& native_aura_id_map);
+ void Refresh(const DesktopMediaID::Id& view_dialog_id);
+
+ void UpdateSources(const std::vector<SourceDescription>& sources,
+ const gfx::Size& thumbnail_size);
private:
typedef std::map<DesktopMediaID, uint32_t> ImageHashesMap;
@@ -149,11 +131,8 @@ NativeDesktopMediaList::Worker::Worker(
NativeDesktopMediaList::Worker::~Worker() {}
void NativeDesktopMediaList::Worker::Refresh(
- const gfx::Size& thumbnail_size,
- const DesktopMediaID::Id& view_dialog_id,
- const NativeAuraIdMap& native_aura_id_map) {
+ const DesktopMediaID::Id& view_dialog_id) {
std::vector<SourceDescription> sources;
- std::vector<DesktopMediaID> aura_media_ids;
if (screen_capturer_) {
webrtc::ScreenCapturer::ScreenList screens;
@@ -181,34 +160,37 @@ void NativeDesktopMediaList::Worker::Refresh(
for (webrtc::WindowCapturer::WindowList::iterator it = windows.begin();
it != windows.end(); ++it) {
// Skip the picker dialog window.
- if (it->id != view_dialog_id) {
- DesktopMediaID media_id(DesktopMediaID::TYPE_WINDOW, it->id);
-#if defined(USE_AURA)
- // Associate aura id with native id.
- auto aura_id = native_aura_id_map.find(media_id.id);
- if (aura_id != native_aura_id_map.end()) {
- media_id.aura_id = aura_id->second;
- aura_media_ids.push_back(media_id);
- }
-#endif
- sources.push_back(
- SourceDescription(media_id, base::UTF8ToUTF16(it->title)));
- }
+ if (it->id == view_dialog_id)
+ continue;
+
+ DesktopMediaID media_id(DesktopMediaID::TYPE_WINDOW, it->id);
+ sources.push_back(
+ SourceDescription(media_id, base::UTF8ToUTF16(it->title)));
}
}
}
+ // AddAuraIdToMediaId() registers aura windows which needs to be done in UI
+ // thread. It calls Worker::UpdateSources() to complete refresh.
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&NativeDesktopMediaList::AddAuraIdToMediaId, media_list_,
+ sources));
+}
+
+void NativeDesktopMediaList::Worker::UpdateSources(
Sergey Ulanov 2016/03/17 21:59:18 Call this UpdateThumbnails()?
GeorgeZ 2016/03/18 16:44:08 Done.
+ const std::vector<SourceDescription>& sources,
+ const gfx::Size& thumbnail_size) {
// Update list of windows before updating thumbnails.
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&NativeDesktopMediaList::UpdateSourcesList,
Sergey Ulanov 2016/03/17 21:59:18 UpdateSources() has been posted from the UI thread
GeorgeZ 2016/03/18 16:44:08 Good suggestion and make code and logic concise.
media_list_, sources));
ImageHashesMap new_image_hashes;
+ std::vector<DesktopMediaID> aura_media_ids;
// Get a thumbnail for each source.
- for (size_t i = 0; i < sources.size(); ++i) {
- SourceDescription& source = sources[i];
-
+ for (const auto& source : sources) {
switch (source.id.type) {
case DesktopMediaID::TYPE_SCREEN:
if (!screen_capturer_->SelectScreen(source.id.id))
@@ -220,8 +202,10 @@ void NativeDesktopMediaList::Worker::Refresh(
#if defined(USE_AURA)
// Aura window thumbmail capture is skipped here. It will be done
// asynchronously in the UI thread.
- if (source.id.aura_id > DesktopMediaID::kNullId)
+ if (source.id.aura_id > DesktopMediaID::kNullId) {
+ aura_media_ids.push_back(source.id);
continue;
+ }
#endif
if (!window_capturer_->SelectWindow(source.id.id))
continue;
@@ -246,8 +230,8 @@ void NativeDesktopMediaList::Worker::Refresh(
ScaleDesktopFrame(std::move(current_frame_), thumbnail_size);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&NativeDesktopMediaList::OnSourceThumbnailCaptured,
- media_list_, i, thumbnail));
+ base::Bind(&NativeDesktopMediaList::UpdateSourceThumbnail,
+ media_list_, source.id, thumbnail));
}
}
}
@@ -288,23 +272,41 @@ NativeDesktopMediaList::~NativeDesktopMediaList() {
}
void NativeDesktopMediaList::Refresh() {
- NativeAuraIdMap native_aura_id_map;
#if defined(USE_AURA)
- native_aura_id_map = GetBrowserNativeAuraIdMap();
pending_aura_capture_requests_ = 0;
new_aura_thumbnail_hashes_.clear();
#endif
capture_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&Worker::Refresh, base::Unretained(worker_.get()),
- thumbnail_size_, view_dialog_id_.id, native_aura_id_map));
+ FROM_HERE, base::Bind(&Worker::Refresh, base::Unretained(worker_.get()),
+ view_dialog_id_.id));
}
-void NativeDesktopMediaList::OnSourceThumbnailCaptured(
- int index,
- const gfx::ImageSkia& image) {
- UpdateSourceThumbnail(GetSource(index).id, image);
+void NativeDesktopMediaList::AddAuraIdToMediaId(
+ std::vector<SourceDescription> sources) {
+#if defined(USE_AURA)
+ for (auto& source : sources) {
+#if defined(OS_WIN)
+ aura::Window* aura_window =
+ views::DesktopWindowTreeHostWin::GetContentWindowForHWND(
+ reinterpret_cast<HWND>(source.id.id));
+#else
Sergey Ulanov 2016/03/17 21:59:18 // defined(OS_WIN)
GeorgeZ 2016/03/18 16:44:07 Done.
+ // For linux.
+ aura::Window* aura_window =
+ views::DesktopWindowTreeHostX11::GetContentWindowForXID(source.id.id);
+#endif
Sergey Ulanov 2016/03/17 21:59:18 // !defined(OS_WIN)
GeorgeZ 2016/03/18 16:44:07 Done.
+ // Associate aura id with native id.
+ if (aura_window) {
+ DesktopMediaID aura_id = DesktopMediaID::RegisterAuraWindow(
+ DesktopMediaID::TYPE_WINDOW, aura_window);
+ source.id.aura_id = aura_id.aura_id;
Sergey Ulanov 2016/03/17 21:59:18 Also initiate thumbnail capture here instead of in
GeorgeZ 2016/03/18 16:44:07 I have to schedule next refresh after both aura wi
+ }
+ }
+#endif
Sergey Ulanov 2016/03/17 21:59:18 // defined(USE_AURA)
GeorgeZ 2016/03/18 16:44:07 Done.
+ capture_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&Worker::UpdateSources, base::Unretained(worker_.get()),
+ sources, thumbnail_size_));
}
void NativeDesktopMediaList::FinishRefreshOnUiThreadAndScheduleNext(
« no previous file with comments | « chrome/browser/media/native_desktop_media_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698