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

Unified Diff: content/browser/media/capture/desktop_capture_device_aura.cc

Issue 615133002: Add support for a virtual display on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix remaining comment periods (thanks achuithb@) Created 5 years, 10 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
Index: content/browser/media/capture/desktop_capture_device_aura.cc
diff --git a/content/browser/media/capture/desktop_capture_device_aura.cc b/content/browser/media/capture/desktop_capture_device_aura.cc
index 1b26d4c1823cc59653b2c2706f3fb86f8c32128e..79c59cbd24d397b889d78e61a1db09ca8e4103ee 100644
--- a/content/browser/media/capture/desktop_capture_device_aura.cc
+++ b/content/browser/media/capture/desktop_capture_device_aura.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/metrics/histogram.h"
+#include "base/sys_info.h"
#include "base/timer/timer.h"
#include "cc/output/copy_output_request.h"
#include "cc/output/copy_output_result.h"
@@ -28,8 +29,16 @@
#include "ui/compositor/compositor.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
+#include "ui/gfx/display.h"
+#include "ui/gfx/display_observer.h"
#include "ui/gfx/screen.h"
+#if defined(USE_ASH)
+#include "ash/display/display_controller.h"
piman 2015/02/24 01:58:29 content/ is not allowed to depend on ash/
+#include "ash/shell.h"
+#include "ui/display/chromeos/display_configurator.h"
+#endif
+
namespace content {
namespace {
@@ -93,6 +102,7 @@ class DesktopVideoCaptureMachine
: public VideoCaptureMachine,
public aura::WindowObserver,
public ui::CompositorObserver,
+ public gfx::DisplayObserver,
public base::SupportsWeakPtr<DesktopVideoCaptureMachine> {
public:
DesktopVideoCaptureMachine(const DesktopMediaID& source);
@@ -121,6 +131,12 @@ class DesktopVideoCaptureMachine
void OnCompositingLockStateChanged(ui::Compositor* compositor) override {}
void OnCompositingShuttingDown(ui::Compositor* compositor) override {}
+ // Implements gfx::DisplayObserver.
+ void OnDisplayAdded(const gfx::Display& new_display) override;
+ void OnDisplayRemoved(const gfx::Display& old_display) override {}
+ void OnDisplayMetricsChanged(const gfx::Display& display,
+ uint32_t changed_metrics) override {}
+
private:
// Captures a frame.
// |dirty| is false for timer polls and true for compositor updates.
@@ -152,6 +168,9 @@ class DesktopVideoCaptureMachine
// Clears cursor state.
void ClearCursorState();
+ // Start the capture after setup.
+ void StartCapture();
+
// The window associated with the desktop.
aura::Window* desktop_window_;
@@ -190,24 +209,7 @@ DesktopVideoCaptureMachine::DesktopVideoCaptureMachine(
DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {}
-bool DesktopVideoCaptureMachine::Start(
- const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy,
- const media::VideoCaptureParams& params) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- desktop_window_ = content::DesktopMediaID::GetAuraWindowById(window_id_);
- if (!desktop_window_)
- return false;
-
- // If the associated layer is already destroyed then return failure.
- ui::Layer* layer = desktop_window_->layer();
- if (!layer)
- return false;
-
- DCHECK(oracle_proxy.get());
- oracle_proxy_ = oracle_proxy;
- capture_params_ = params;
-
+void DesktopVideoCaptureMachine::StartCapture() {
// Update capture size.
UpdateCaptureSize();
@@ -226,6 +228,43 @@ bool DesktopVideoCaptureMachine::Start(
timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(),
base::Bind(&DesktopVideoCaptureMachine::Capture, AsWeakPtr(),
false));
+}
+
+bool DesktopVideoCaptureMachine::Start(
Sergey Ulanov 2015/02/23 23:16:12 Can the virtual-screen logic be moved out of this
oshima 2015/02/24 19:43:21 and please move ash code from content/.
robert.bradford 2015/03/03 19:58:00 I've started working on the non virtual display re
+ const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy,
+ const media::VideoCaptureParams& params) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ capture_params_ = params;
+ DCHECK(oracle_proxy.get());
+ oracle_proxy_ = oracle_proxy;
+
+#if defined(USE_ASH)
oshima 2015/02/24 19:43:21 no USE_ASH in content/. You probably should just u
+ // Window for virtual display is available asynchronously after request. The
+ // DisplayObserver on the screen will be notified of the new display and
+ // Window and start the capture.
+ if (window_id_.type == DesktopMediaID::TYPE_AURA_VIRTUAL_SCREEN) {
+ DCHECK(base::SysInfo::IsRunningOnChromeOS());
+ ui::DisplayConfigurator* configurator =
+ ash::Shell::GetInstance()->display_configurator();
+ gfx::Screen::GetNativeScreen()->AddObserver(this);
+ configurator->EnableVirtualDisplay(make_scoped_ptr(
+ new ui::DisplayMode(params.requested_format.frame_size, false, 60)));
+ return true;
+ }
+#else
+ desktop_window_ = content::DesktopMediaID::GetAuraWindowById(window_id_);
+#endif
+
+ if (!desktop_window_)
+ return false;
+
+ // If the associated layer is already destroyed then return failure.
+ ui::Layer* layer = desktop_window_->layer();
+ if (!layer)
+ return false;
+
+ StartCapture();
return true;
}
@@ -244,6 +283,13 @@ void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) {
desktop_window_ = NULL;
}
+#if defined(USE_ASH)
+ if (window_id_.type == DesktopMediaID::TYPE_AURA_VIRTUAL_SCREEN) {
+ gfx::Screen::GetNativeScreen()->RemoveObserver(this);
+ ash::Shell::GetInstance()->display_configurator()->DisableVirtualDisplay();
+ }
+#endif
+
// Stop timer.
timer_.Stop();
@@ -507,6 +553,30 @@ void DesktopVideoCaptureMachine::OnCompositingEnded(
&DesktopVideoCaptureMachine::Capture, AsWeakPtr(), true));
}
+void DesktopVideoCaptureMachine::OnDisplayAdded(
+ const gfx::Display& new_display) {
+#if defined(USE_ASH)
+ DCHECK(base::SysInfo::IsRunningOnChromeOS());
+ ui::DisplayConfigurator* configurator =
+ ash::Shell::GetInstance()->display_configurator();
+ int64 display_id = configurator->GetVirtualDisplayId();
+
+ if (display_id == new_display.id()) {
+ desktop_window_ = ash::Shell::GetInstance()
+ ->display_controller()
+ ->GetRootWindowForDisplayId(display_id);
+
+ // We only need the observer for a short time.
+ gfx::Screen::GetNativeScreen()->RemoveObserver(this);
+
+ if (desktop_window_ && desktop_window_->layer()) {
+ StartCapture();
+ } else {
+ Stop(base::Bind(&base::DoNothing));
+ }
+ }
+}
+#endif
} // namespace
DesktopCaptureDeviceAura::DesktopCaptureDeviceAura(

Powered by Google App Engine
This is Rietveld 408576698