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

Side by Side Diff: content/browser/media/capture/virtual_display_capturer.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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/media/capture/virtual_display_capturer.h"
6
7 #include "base/logging.h"
8 #include "base/sys_info.h"
9 #include "base/timer/timer.h"
10 #include "content/browser/media/capture/aura_window_capture_machine.h"
11 #include "content/browser/media/capture/content_video_capture_device_core.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "ui/aura/window.h"
14 #include "ui/display/chromeos/display_configurator.h"
15 #include "ui/gfx/screen.h"
16
17 namespace content {
18
19 namespace {
20
21 void EnableVirtualDisplay(const gfx::Size& size) {
22 ui::DisplayConfigurator::GetInstance()->EnableVirtualDisplay(size);
23 }
24
25 void DisableVirtualDisplay() {
26 ui::DisplayConfigurator::GetInstance()->DisableVirtualDisplay();
27 }
28
29 } // namespace
30
31 VirtualDisplayCapturer::VirtualDisplayCapturer(
32 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
33 const DesktopMediaID& source)
34 : source_(source),
35 machine_(new AuraWindowCaptureMachine()),
36 device_task_runner_(task_runner) {
37 core_.reset(new ContentVideoCaptureDeviceCore(make_scoped_ptr(machine_)));
38 gfx::Screen::GetNativeScreen()->AddObserver(this);
39 }
40
41 VirtualDisplayCapturer::~VirtualDisplayCapturer() {
42 gfx::Screen::GetNativeScreen()->RemoveObserver(this);
43 }
44
45 // static
46 media::VideoCaptureDevice* VirtualDisplayCapturer::Create(
47 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
48 const DesktopMediaID& source) {
49 DCHECK(base::SysInfo::IsRunningOnChromeOS());
50 return new VirtualDisplayCapturer(task_runner, source);
51 }
52
53 void VirtualDisplayCapturer::AllocateAndStart(
54 const media::VideoCaptureParams& params,
55 scoped_ptr<Client> client) {
56 BrowserThread::PostTask(
57 BrowserThread::UI, FROM_HERE,
58 base::Bind(&EnableVirtualDisplay, params.requested_format.frame_size));
59
60 params_ = params;
61 client_.swap(client);
62 }
63
64 void VirtualDisplayCapturer::StopAndDeAllocate() {
65 core_->StopAndDeAllocate();
66 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
67 base::Bind(&DisableVirtualDisplay));
68 }
69
70 // This will be called after the VirtualDisplayMonitor object has updated the
71 // virtual display in the DesktopMediaID::AuraWindowRegistry.
72 void VirtualDisplayCapturer::OnDisplayAdded(const gfx::Display& display) {
73 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
74
75 if (display.id() ==
76 ui::DisplayConfigurator::GetInstance()->GetVirtualDisplayId()) {
77 aura::Window* window = DesktopMediaID::GetAuraWindowById(source_);
78 machine_->SetWindow(window);
79 gfx::Screen::GetNativeScreen()->RemoveObserver(this);
80 // Safe to use base::Unretained here as StopAndDeAllocate must be called
81 // before destroying |core_|.
82 device_task_runner_->PostTask(
83 FROM_HERE, base::Bind(&ContentVideoCaptureDeviceCore::AllocateAndStart,
84 base::Unretained(core_.get()), params_,
85 base::Passed(client_.Pass())));
86 }
87 }
88
89 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/capture/virtual_display_capturer.h ('k') | content/browser/renderer_host/media/video_capture_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698