| Index: content/browser/media/capture/virtual_display_capturer.cc
|
| diff --git a/content/browser/media/capture/virtual_display_capturer.cc b/content/browser/media/capture/virtual_display_capturer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f9410814807c52ddabac037da0add343177ba407
|
| --- /dev/null
|
| +++ b/content/browser/media/capture/virtual_display_capturer.cc
|
| @@ -0,0 +1,89 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/media/capture/virtual_display_capturer.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/sys_info.h"
|
| +#include "base/timer/timer.h"
|
| +#include "content/browser/media/capture/aura_window_capture_machine.h"
|
| +#include "content/browser/media/capture/content_video_capture_device_core.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/display/chromeos/display_configurator.h"
|
| +#include "ui/gfx/screen.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +void EnableVirtualDisplay(const gfx::Size& size) {
|
| + ui::DisplayConfigurator::GetInstance()->EnableVirtualDisplay(size);
|
| +}
|
| +
|
| +void DisableVirtualDisplay() {
|
| + ui::DisplayConfigurator::GetInstance()->DisableVirtualDisplay();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +VirtualDisplayCapturer::VirtualDisplayCapturer(
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
| + const DesktopMediaID& source)
|
| + : source_(source),
|
| + machine_(new AuraWindowCaptureMachine()),
|
| + device_task_runner_(task_runner) {
|
| + core_.reset(new ContentVideoCaptureDeviceCore(make_scoped_ptr(machine_)));
|
| + gfx::Screen::GetNativeScreen()->AddObserver(this);
|
| +}
|
| +
|
| +VirtualDisplayCapturer::~VirtualDisplayCapturer() {
|
| + gfx::Screen::GetNativeScreen()->RemoveObserver(this);
|
| +}
|
| +
|
| +// static
|
| +media::VideoCaptureDevice* VirtualDisplayCapturer::Create(
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
| + const DesktopMediaID& source) {
|
| + DCHECK(base::SysInfo::IsRunningOnChromeOS());
|
| + return new VirtualDisplayCapturer(task_runner, source);
|
| +}
|
| +
|
| +void VirtualDisplayCapturer::AllocateAndStart(
|
| + const media::VideoCaptureParams& params,
|
| + scoped_ptr<Client> client) {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&EnableVirtualDisplay, params.requested_format.frame_size));
|
| +
|
| + params_ = params;
|
| + client_.swap(client);
|
| +}
|
| +
|
| +void VirtualDisplayCapturer::StopAndDeAllocate() {
|
| + core_->StopAndDeAllocate();
|
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&DisableVirtualDisplay));
|
| +}
|
| +
|
| +// This will be called after the VirtualDisplayMonitor object has updated the
|
| +// virtual display in the DesktopMediaID::AuraWindowRegistry.
|
| +void VirtualDisplayCapturer::OnDisplayAdded(const gfx::Display& display) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| +
|
| + if (display.id() ==
|
| + ui::DisplayConfigurator::GetInstance()->GetVirtualDisplayId()) {
|
| + aura::Window* window = DesktopMediaID::GetAuraWindowById(source_);
|
| + machine_->SetWindow(window);
|
| + gfx::Screen::GetNativeScreen()->RemoveObserver(this);
|
| + // Safe to use base::Unretained here as StopAndDeAllocate must be called
|
| + // before destroying |core_|.
|
| + device_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&ContentVideoCaptureDeviceCore::AllocateAndStart,
|
| + base::Unretained(core_.get()), params_,
|
| + base::Passed(client_.Pass())));
|
| + }
|
| +}
|
| +
|
| +} // namespace content
|
|
|