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..6ebd7cc5fa3cb72d0b09cddc5460170fa302d84f 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" |
+#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{}; |
achuithb
2015/02/11 23:41:43
override {}
|
+ void OnDisplayMetricsChanged(const gfx::Display& display, |
+ uint32_t changed_metrics) override{}; |
achuithb
2015/02/11 23:41:43
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,44 @@ bool DesktopVideoCaptureMachine::Start( |
timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), |
base::Bind(&DesktopVideoCaptureMachine::Capture, AsWeakPtr(), |
false)); |
+} |
+ |
+bool DesktopVideoCaptureMachine::Start( |
+ 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) |
+ |
achuithb
2015/02/11 23:41:43
remove newline
|
+ // 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 +284,15 @@ void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) { |
desktop_window_ = NULL; |
} |
+#if defined(USE_ASH) |
+ gfx::Screen::GetNativeScreen()->RemoveObserver(this); |
achuithb
2015/02/11 23:41:43
Shouldn't this be within the if stmt below?
|
+ if (window_id_.type == DesktopMediaID::TYPE_AURA_VIRTUAL_SCREEN) { |
+ ui::DisplayConfigurator* configurator = |
+ ash::Shell::GetInstance()->display_configurator(); |
+ configurator->DisableVirtualDisplay(); |
achuithb
2015/02/11 23:41:44
Why not combine the above two statements?
ash::Sh
|
+ } |
+#endif |
+ |
// Stop timer. |
timer_.Stop(); |
@@ -507,6 +556,27 @@ void DesktopVideoCaptureMachine::OnCompositingEnded( |
&DesktopVideoCaptureMachine::Capture, AsWeakPtr(), true)); |
} |
+void DesktopVideoCaptureMachine::OnDisplayAdded( |
+ const gfx::Display& new_display) { |
+ ui::DisplayConfigurator* configurator = |
achuithb
2015/02/11 23:41:44
SHould there not be a USE_ASH define?
Should there
|
+ 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)); |
+ } |
+ } |
+} |
} // namespace |
DesktopCaptureDeviceAura::DesktopCaptureDeviceAura( |