Commit 249c5e8e authored by hshi@chromium.org's avatar hshi@chromium.org

DesktopVideoCaptureMachine: do not cache window layer pointer.

The aura window's layer pointer is subject to change due to layer recreation,
so the cached pointer |desktop_layer_| may be invalid.

Always use aura::Window::layer() accessor instead.

BUG=385751
TEST=start desktop sharing and switch between windowed/immersive mode.

Review URL: https://codereview.chromium.org/348623005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278695 0039d316-1c4b-4281-b951-d872f2087c98
parent d146bcd8
...@@ -108,6 +108,9 @@ class DesktopVideoCaptureMachine ...@@ -108,6 +108,9 @@ class DesktopVideoCaptureMachine
const gfx::Rect& old_bounds, const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE; const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE;
virtual void OnWindowRemovingFromRootWindow(aura::Window* window,
aura::Window* new_root) OVERRIDE;
// Implements ui::CompositorObserver. // Implements ui::CompositorObserver.
virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE {} virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE {}
...@@ -152,9 +155,6 @@ class DesktopVideoCaptureMachine ...@@ -152,9 +155,6 @@ class DesktopVideoCaptureMachine
// The window associated with the desktop. // The window associated with the desktop.
aura::Window* desktop_window_; aura::Window* desktop_window_;
// The layer associated with the desktop.
ui::Layer* desktop_layer_;
// The timer that kicks off period captures. // The timer that kicks off period captures.
base::Timer timer_; base::Timer timer_;
...@@ -181,7 +181,6 @@ class DesktopVideoCaptureMachine ...@@ -181,7 +181,6 @@ class DesktopVideoCaptureMachine
DesktopVideoCaptureMachine::DesktopVideoCaptureMachine( DesktopVideoCaptureMachine::DesktopVideoCaptureMachine(
const DesktopMediaID& source) const DesktopMediaID& source)
: desktop_window_(NULL), : desktop_window_(NULL),
desktop_layer_(NULL),
timer_(true, true), timer_(true, true),
window_id_(source) {} window_id_(source) {}
...@@ -196,9 +195,9 @@ bool DesktopVideoCaptureMachine::Start( ...@@ -196,9 +195,9 @@ bool DesktopVideoCaptureMachine::Start(
if (!desktop_window_) if (!desktop_window_)
return false; return false;
// If the desktop layer is already destroyed then return failure. // If the associated layer is already destroyed then return failure.
desktop_layer_ = desktop_window_->layer(); ui::Layer* layer = desktop_window_->layer();
if (!desktop_layer_) if (!layer)
return false; return false;
DCHECK(oracle_proxy.get()); DCHECK(oracle_proxy.get());
...@@ -212,11 +211,8 @@ bool DesktopVideoCaptureMachine::Start( ...@@ -212,11 +211,8 @@ bool DesktopVideoCaptureMachine::Start(
desktop_window_->AddObserver(this); desktop_window_->AddObserver(this);
// Start observing compositor updates. // Start observing compositor updates.
ui::Compositor* compositor = desktop_layer_->GetCompositor(); if (desktop_window_->GetHost())
if (!compositor) desktop_window_->GetHost()->compositor()->AddObserver(this);
return false;
compositor->AddObserver(this);
// Starts timer. // Starts timer.
timer_.Start(FROM_HERE, oracle_proxy_->capture_period(), timer_.Start(FROM_HERE, oracle_proxy_->capture_period(),
...@@ -230,20 +226,14 @@ bool DesktopVideoCaptureMachine::Start( ...@@ -230,20 +226,14 @@ bool DesktopVideoCaptureMachine::Start(
void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) { void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Stop observing window events. // Stop observing compositor and window events.
if (desktop_window_) { if (desktop_window_) {
if (desktop_window_->GetHost())
desktop_window_->GetHost()->compositor()->RemoveObserver(this);
desktop_window_->RemoveObserver(this); desktop_window_->RemoveObserver(this);
desktop_window_ = NULL; desktop_window_ = NULL;
} }
// Stop observing compositor updates.
if (desktop_layer_) {
ui::Compositor* compositor = desktop_layer_->GetCompositor();
if (compositor)
compositor->RemoveObserver(this);
desktop_layer_ = NULL;
}
// Stop timer. // Stop timer.
timer_.Stop(); timer_.Stop();
...@@ -254,9 +244,10 @@ void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) { ...@@ -254,9 +244,10 @@ void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) {
void DesktopVideoCaptureMachine::UpdateCaptureSize() { void DesktopVideoCaptureMachine::UpdateCaptureSize() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (oracle_proxy_ && desktop_layer_) { if (oracle_proxy_ && desktop_window_) {
ui::Layer* layer = desktop_window_->layer();
oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel(
desktop_layer_, desktop_layer_->bounds().size())); layer, layer->bounds().size()));
} }
ClearCursorState(); ClearCursorState();
} }
...@@ -264,8 +255,8 @@ void DesktopVideoCaptureMachine::UpdateCaptureSize() { ...@@ -264,8 +255,8 @@ void DesktopVideoCaptureMachine::UpdateCaptureSize() {
void DesktopVideoCaptureMachine::Capture(bool dirty) { void DesktopVideoCaptureMachine::Capture(bool dirty) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Do not capture if the desktop layer is already destroyed. // Do not capture if the desktop window is already destroyed.
if (!desktop_layer_) if (!desktop_window_)
return; return;
scoped_refptr<media::VideoFrame> frame; scoped_refptr<media::VideoFrame> frame;
...@@ -286,7 +277,7 @@ void DesktopVideoCaptureMachine::Capture(bool dirty) { ...@@ -286,7 +277,7 @@ void DesktopVideoCaptureMachine::Capture(bool dirty) {
gfx::Rect(desktop_window_->bounds().width(), gfx::Rect(desktop_window_->bounds().width(),
desktop_window_->bounds().height())); desktop_window_->bounds().height()));
request->set_area(window_rect); request->set_area(window_rect);
desktop_layer_->RequestCopyOfOutput(request.Pass()); desktop_window_->layer()->RequestCopyOfOutput(request.Pass());
} }
} }
...@@ -350,7 +341,7 @@ bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse( ...@@ -350,7 +341,7 @@ bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse(
const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb,
scoped_ptr<cc::CopyOutputResult> result) { scoped_ptr<cc::CopyOutputResult> result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (result->IsEmpty() || result->size().IsEmpty() || !desktop_layer_) if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_)
return false; return false;
if (capture_params_.requested_format.pixel_format == if (capture_params_.requested_format.pixel_format ==
...@@ -437,7 +428,7 @@ bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse( ...@@ -437,7 +428,7 @@ bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse(
gfx::Point DesktopVideoCaptureMachine::UpdateCursorState( gfx::Point DesktopVideoCaptureMachine::UpdateCursorState(
const gfx::Rect& region_in_frame) { const gfx::Rect& region_in_frame) {
const gfx::Rect desktop_bounds = desktop_layer_->bounds(); const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds();
gfx::NativeCursor cursor = gfx::NativeCursor cursor =
desktop_window_->GetHost()->last_cursor(); desktop_window_->GetHost()->last_cursor();
if (last_cursor_ != cursor) { if (last_cursor_ != cursor) {
...@@ -462,7 +453,7 @@ gfx::Point DesktopVideoCaptureMachine::UpdateCursorState( ...@@ -462,7 +453,7 @@ gfx::Point DesktopVideoCaptureMachine::UpdateCursorState(
aura::client::GetScreenPositionClient(desktop_window_->GetRootWindow())-> aura::client::GetScreenPositionClient(desktop_window_->GetRootWindow())->
ConvertPointFromScreen(desktop_window_, &cursor_position); ConvertPointFromScreen(desktop_window_, &cursor_position);
const gfx::Point hot_point_in_dip = ui::ConvertPointToDIP( const gfx::Point hot_point_in_dip = ui::ConvertPointToDIP(
desktop_layer_, cursor_hot_point_); desktop_window_->layer(), cursor_hot_point_);
cursor_position.Offset(-desktop_bounds.x() - hot_point_in_dip.x(), cursor_position.Offset(-desktop_bounds.x() - hot_point_in_dip.x(),
-desktop_bounds.y() - hot_point_in_dip.y()); -desktop_bounds.y() - hot_point_in_dip.y());
return gfx::Point( return gfx::Point(
...@@ -497,6 +488,19 @@ void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) { ...@@ -497,6 +488,19 @@ void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) {
oracle_proxy_->ReportError("OnWindowDestroyed()"); oracle_proxy_->ReportError("OnWindowDestroyed()");
} }
void DesktopVideoCaptureMachine::OnWindowAddedToRootWindow(
aura::Window* window) {
DCHECK(window == desktop_window_);
window->GetHost()->compositor()->AddObserver(this);
}
void DesktopVideoCaptureMachine::OnWindowRemovingFromRootWindow(
aura::Window* window,
aura::Window* new_root) {
DCHECK(window == desktop_window_);
window->GetHost()->compositor()->RemoveObserver(this);
}
void DesktopVideoCaptureMachine::OnCompositingEnded( void DesktopVideoCaptureMachine::OnCompositingEnded(
ui::Compositor* compositor) { ui::Compositor* compositor) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment