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

Side by Side Diff: chrome/browser/media/desktop_media_list_ash.cc

Issue 615133002: Add support for a virtual display on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ash/ dep from content Created 5 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 unified diff | Download patch
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | content/browser/media/capture/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/desktop_media_list_ash.h" 5 #include "chrome/browser/media/desktop_media_list_ash.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "ash/display/display_controller.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
11 #include "base/hash.h" 12 #include "base/hash.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/singleton.h"
13 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/sys_info.h"
14 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
15 #include "chrome/browser/media/desktop_media_list_observer.h" 18 #include "chrome/browser/media/desktop_media_list_observer.h"
16 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
17 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
18 #include "media/base/video_util.h" 21 #include "media/base/video_util.h"
19 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/compositor/dip_util.h" 23 #include "ui/compositor/dip_util.h"
24 #include "ui/display/chromeos/display_configurator.h"
25 #include "ui/gfx/display_observer.h"
21 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
22 #include "ui/snapshot/snapshot.h" 27 #include "ui/snapshot/snapshot.h"
23 28
24 using content::BrowserThread; 29 using content::BrowserThread;
25 using content::DesktopMediaID; 30 using content::DesktopMediaID;
26 31
27 namespace { 32 namespace {
28 33
29 // Update the list twice per second. 34 // Update the list twice per second.
30 const int kDefaultUpdatePeriod = 500; 35 const int kDefaultUpdatePeriod = 500;
31 36
37 #if defined(OS_CHROMEOS)
38 // Watches for the creation of a virtual display and updates
39 // DesktopMediaID::AuraWindowRegistry.
40 class VirtualScreenMonitor : public gfx::DisplayObserver {
41 public:
42 VirtualScreenMonitor();
43 ~VirtualScreenMonitor();
44
45 // gfx::DisplayObserver overrides:
46 void OnDisplayAdded(const gfx::Display& display) override;
47 void OnDisplayRemoved(const gfx::Display& display) override {}
48 void OnDisplayMetricsChanged(const gfx::Display& display,
49 uint32_t metrics) override {}
50
51 // static
52 static VirtualScreenMonitor* GetInstance();
53
54 private:
55 friend struct DefaultSingletonTraits<VirtualScreenMonitor>;
56
57 DISALLOW_COPY_AND_ASSIGN(VirtualScreenMonitor);
58 };
59
60 VirtualScreenMonitor::VirtualScreenMonitor() {
61 gfx::Screen::GetNativeScreen()->AddObserver(this);
62 }
63
64 VirtualScreenMonitor::~VirtualScreenMonitor() {
65 }
66
67 // Subsequent observers (e.g. from the VirtualDisplayCapturer class) will see
68 // the updated virtual screen window as the observers are called in the order
69 // they are added.
70 void VirtualScreenMonitor::OnDisplayAdded(const gfx::Display& display) {
71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
72 if (display.id() ==
73 ui::DisplayConfigurator::GetInstance()->GetVirtualDisplayId()) {
74 aura::Window* window = ash::Shell::GetInstance()
75 ->display_controller()
76 ->GetRootWindowForDisplayId(display.id());
77
78 content::DesktopMediaID::RegisterVirtualScreenAuraWindow(window);
79 }
80 }
81
82 // static
83 VirtualScreenMonitor* VirtualScreenMonitor::GetInstance() {
84 return Singleton<VirtualScreenMonitor>::get();
85 }
86
87 #endif // defined(OS_CHROMEOS)
88
32 } // namespace 89 } // namespace
33 90
34 DesktopMediaListAsh::SourceDescription::SourceDescription( 91 DesktopMediaListAsh::SourceDescription::SourceDescription(
35 DesktopMediaID id, 92 DesktopMediaID id,
36 const base::string16& name) 93 const base::string16& name)
37 : id(id), 94 : id(id),
38 name(name) { 95 name(name) {
39 } 96 }
40 97
41 DesktopMediaListAsh::DesktopMediaListAsh(int source_types) 98 DesktopMediaListAsh::DesktopMediaListAsh(int source_types)
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 259
203 if (source_types_ & WINDOWS) { 260 if (source_types_ & WINDOWS) {
204 EnumerateWindowsForRoot( 261 EnumerateWindowsForRoot(
205 sources, root_windows[i], ash::kShellWindowId_DefaultContainer); 262 sources, root_windows[i], ash::kShellWindowId_DefaultContainer);
206 EnumerateWindowsForRoot( 263 EnumerateWindowsForRoot(
207 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer); 264 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer);
208 EnumerateWindowsForRoot( 265 EnumerateWindowsForRoot(
209 sources, root_windows[i], ash::kShellWindowId_DockedContainer); 266 sources, root_windows[i], ash::kShellWindowId_DockedContainer);
210 } 267 }
211 } 268 }
269 #if defined(OS_CHROMEOS)
270 // DisplayConfigurator only works when running on ChromeOS.
271 if (base::SysInfo::IsRunningOnChromeOS()) {
272 if (ui::DisplayConfigurator::GetInstance()->GetVirtualDisplayId() ==
273 gfx::Display::kInvalidDisplayID) {
274 // Instantiate the VirtualScreenMonitor object which will observe for
275 // the virtual display being created and store the window so that it can
276 // be looked up from the content::DesktopMediaID.
277 (void)VirtualScreenMonitor::GetInstance();
278 SourceDescription virtual_screen_source(
279 content::DesktopMediaID(
280 content::DesktopMediaID::TYPE_AURA_VIRTUAL_SCREEN, 0),
281 l10n_util::GetStringUTF16(
282 IDS_DESTOP_MEDIA_PICKER_VIRTUAL_SCREEN_NAME));
283 sources->push_back(virtual_screen_source);
284 // TODO(robert.bradford): crbug.com/425060 There is no thumbnail for the
285 // virtual screen right now.
286 }
287 }
288 #endif // defined(OS_CHROMEOS)
212 } 289 }
213 290
214 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id, 291 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id,
215 aura::Window* window) { 292 aura::Window* window) {
216 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); 293 gfx::Rect window_rect(window->bounds().width(), window->bounds().height());
217 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( 294 gfx::Rect scaled_rect = media::ComputeLetterboxRegion(
218 gfx::Rect(thumbnail_size_), window_rect.size()); 295 gfx::Rect(thumbnail_size_), window_rect.size());
219 296
220 ++pending_window_capture_requests_; 297 ++pending_window_capture_requests_;
221 ui::GrabWindowSnapshotAndScaleAsync( 298 ui::GrabWindowSnapshotAndScaleAsync(
(...skipping 22 matching lines...) Expand all
244 if (!pending_window_capture_requests_) { 321 if (!pending_window_capture_requests_) {
245 // Once we've finished capturing all windows post a task for the next list 322 // Once we've finished capturing all windows post a task for the next list
246 // update. 323 // update.
247 BrowserThread::PostDelayedTask( 324 BrowserThread::PostDelayedTask(
248 BrowserThread::UI, FROM_HERE, 325 BrowserThread::UI, FROM_HERE,
249 base::Bind(&DesktopMediaListAsh::Refresh, 326 base::Bind(&DesktopMediaListAsh::Refresh,
250 weak_factory_.GetWeakPtr()), 327 weak_factory_.GetWeakPtr()),
251 update_period_); 328 update_period_);
252 } 329 }
253 } 330 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | content/browser/media/capture/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698