Index: content/browser/media/capture/aura_window_capture_machine.cc |
diff --git a/content/browser/media/capture/desktop_capture_device_aura.cc b/content/browser/media/capture/aura_window_capture_machine.cc |
similarity index 71% |
copy from content/browser/media/capture/desktop_capture_device_aura.cc |
copy to content/browser/media/capture/aura_window_capture_machine.cc |
index de1a1093b38f828e7522573a7d7612a85c086d2b..f3a1ec81faa35a989dee7d9a4d8fcaec43ac7a5b 100644 |
--- a/content/browser/media/capture/desktop_capture_device_aura.cc |
+++ b/content/browser/media/capture/aura_window_capture_machine.cc |
@@ -2,7 +2,7 @@ |
// 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/desktop_capture_device_aura.h" |
+#include "content/browser/media/capture/aura_window_capture_machine.h" |
#include "base/logging.h" |
#include "base/metrics/histogram.h" |
@@ -89,115 +89,40 @@ void RenderCursorOnVideoFrame( |
cursor_bitmap.unlockPixels(); |
} |
-class DesktopVideoCaptureMachine |
- : public VideoCaptureMachine, |
- public aura::WindowObserver, |
- public ui::CompositorObserver, |
- public base::SupportsWeakPtr<DesktopVideoCaptureMachine> { |
- public: |
- DesktopVideoCaptureMachine(const DesktopMediaID& source); |
- ~DesktopVideoCaptureMachine() override; |
- |
- // VideoCaptureFrameSource overrides. |
- bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
- const media::VideoCaptureParams& params) override; |
- void Stop(const base::Closure& callback) override; |
- |
- // Implements aura::WindowObserver. |
- void OnWindowBoundsChanged(aura::Window* window, |
- const gfx::Rect& old_bounds, |
- const gfx::Rect& new_bounds) override; |
- void OnWindowDestroyed(aura::Window* window) override; |
- void OnWindowAddedToRootWindow(aura::Window* window) override; |
- void OnWindowRemovingFromRootWindow(aura::Window* window, |
- aura::Window* new_root) override; |
- |
- // Implements ui::CompositorObserver. |
- void OnCompositingDidCommit(ui::Compositor* compositor) override {} |
- void OnCompositingStarted(ui::Compositor* compositor, |
- base::TimeTicks start_time) override {} |
- void OnCompositingEnded(ui::Compositor* compositor) override; |
- void OnCompositingAborted(ui::Compositor* compositor) override {} |
- void OnCompositingLockStateChanged(ui::Compositor* compositor) override {} |
- void OnCompositingShuttingDown(ui::Compositor* compositor) override {} |
- |
- private: |
- // Captures a frame. |
- // |dirty| is false for timer polls and true for compositor updates. |
- void Capture(bool dirty); |
- |
- // Update capture size. Must be called on the UI thread. |
- void UpdateCaptureSize(); |
- |
- // Response callback for cc::Layer::RequestCopyOfOutput(). |
- void DidCopyOutput( |
- scoped_refptr<media::VideoFrame> video_frame, |
- base::TimeTicks start_time, |
- const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
- scoped_ptr<cc::CopyOutputResult> result); |
- |
- // A helper which does the real work for DidCopyOutput. Returns true if |
- // succeeded. |
- bool ProcessCopyOutputResponse( |
- scoped_refptr<media::VideoFrame> video_frame, |
- base::TimeTicks start_time, |
- const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
- scoped_ptr<cc::CopyOutputResult> result); |
- |
- // Helper function to update cursor state. |
- // |region_in_frame| defines where the desktop is rendered in the captured |
- // frame. |
- // Returns the current cursor position in captured frame. |
- gfx::Point UpdateCursorState(const gfx::Rect& region_in_frame); |
- |
- // Clears cursor state. |
- void ClearCursorState(); |
- |
- // The window associated with the desktop. |
- aura::Window* desktop_window_; |
- |
- // The timer that kicks off period captures. |
- base::Timer timer_; |
- |
- // The id of the window being captured. |
- DesktopMediaID window_id_; |
- |
- // Makes all the decisions about which frames to copy, and how. |
- scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; |
- |
- // The capture parameters for this capture. |
- media::VideoCaptureParams capture_params_; |
- |
- // YUV readback pipeline. |
- scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; |
- |
- // Cursor state. |
- ui::Cursor last_cursor_; |
- gfx::Size desktop_size_when_cursor_last_updated_; |
- gfx::Point cursor_hot_point_; |
- SkBitmap scaled_cursor_bitmap_; |
- |
- // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the |
- // screen from sleeping for the drive-by web. |
- scoped_ptr<PowerSaveBlocker> power_save_blocker_; |
- |
- DISALLOW_COPY_AND_ASSIGN(DesktopVideoCaptureMachine); |
-}; |
- |
-DesktopVideoCaptureMachine::DesktopVideoCaptureMachine( |
- const DesktopMediaID& source) |
+void CopyOutputFinishedForVideo( |
+ base::TimeTicks start_time, |
+ const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
+ const scoped_refptr<media::VideoFrame>& target, |
+ const SkBitmap& cursor_bitmap, |
+ const gfx::Point& cursor_position, |
+ scoped_ptr<cc::SingleReleaseCallback> release_callback, |
+ bool result) { |
+ if (!cursor_bitmap.isNull()) |
+ RenderCursorOnVideoFrame(target, cursor_bitmap, cursor_position); |
+ release_callback->Run(0, false); |
+ capture_frame_cb.Run(target, start_time, result); |
+} |
+ |
+void RunSingleReleaseCallback(scoped_ptr<cc::SingleReleaseCallback> cb, |
+ uint32 sync_point) { |
+ cb->Run(sync_point, false); |
+} |
+ |
+} // namespace |
+ |
+AuraWindowCaptureMachine::AuraWindowCaptureMachine() |
: desktop_window_(NULL), |
timer_(true, true), |
- window_id_(source) {} |
+ screen_capture_(false) {} |
-DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {} |
+AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
-bool DesktopVideoCaptureMachine::Start( |
+bool AuraWindowCaptureMachine::Start( |
const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
const media::VideoCaptureParams& params) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- desktop_window_ = content::DesktopMediaID::GetAuraWindowById(window_id_); |
+ // The window might be destroyed between SetWindow() and Start(). |
if (!desktop_window_) |
return false; |
@@ -213,9 +138,6 @@ bool DesktopVideoCaptureMachine::Start( |
// Update capture size. |
UpdateCaptureSize(); |
- // Start observing window events. |
- desktop_window_->AddObserver(this); |
- |
// Start observing compositor updates. |
if (desktop_window_->GetHost()) |
desktop_window_->GetHost()->compositor()->AddObserver(this); |
@@ -228,13 +150,13 @@ bool DesktopVideoCaptureMachine::Start( |
// Starts timer. |
timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), |
- base::Bind(&DesktopVideoCaptureMachine::Capture, AsWeakPtr(), |
+ base::Bind(&AuraWindowCaptureMachine::Capture, AsWeakPtr(), |
false)); |
return true; |
} |
-void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) { |
+void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
power_save_blocker_.reset(); |
@@ -254,7 +176,23 @@ void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) { |
callback.Run(); |
} |
-void DesktopVideoCaptureMachine::UpdateCaptureSize() { |
+void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ DCHECK(!desktop_window_); |
+ desktop_window_ = window; |
+ |
+ // Start observing window events. |
+ desktop_window_->AddObserver(this); |
+ |
+ // We must store this for the UMA reporting in DidCopyOutput() as |
+ // desktop_window_ might be destroyed at that point. |
+ screen_capture_ = window->IsRootWindow(); |
+ IncrementDesktopCaptureCounter(screen_capture_ ? SCREEN_CAPTURER_CREATED |
+ : WINDOW_CAPTURER_CREATED); |
+} |
+ |
+void AuraWindowCaptureMachine::UpdateCaptureSize() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
if (oracle_proxy_.get() && desktop_window_) { |
ui::Layer* layer = desktop_window_->layer(); |
@@ -264,7 +202,7 @@ void DesktopVideoCaptureMachine::UpdateCaptureSize() { |
ClearCursorState(); |
} |
-void DesktopVideoCaptureMachine::Capture(bool dirty) { |
+void AuraWindowCaptureMachine::Capture(bool dirty) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
// Do not capture if the desktop window is already destroyed. |
@@ -282,7 +220,7 @@ void DesktopVideoCaptureMachine::Capture(bool dirty) { |
event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
scoped_ptr<cc::CopyOutputRequest> request = |
cc::CopyOutputRequest::CreateRequest( |
- base::Bind(&DesktopVideoCaptureMachine::DidCopyOutput, |
+ base::Bind(&AuraWindowCaptureMachine::DidCopyOutput, |
AsWeakPtr(), frame, start_time, capture_frame_cb)); |
gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), |
desktop_window_->bounds().height()); |
@@ -291,26 +229,7 @@ void DesktopVideoCaptureMachine::Capture(bool dirty) { |
} |
} |
-void CopyOutputFinishedForVideo( |
- base::TimeTicks start_time, |
- const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
- const scoped_refptr<media::VideoFrame>& target, |
- const SkBitmap& cursor_bitmap, |
- const gfx::Point& cursor_position, |
- scoped_ptr<cc::SingleReleaseCallback> release_callback, |
- bool result) { |
- if (!cursor_bitmap.isNull()) |
- RenderCursorOnVideoFrame(target, cursor_bitmap, cursor_position); |
- release_callback->Run(0, false); |
- capture_frame_cb.Run(target, start_time, result); |
-} |
- |
-void RunSingleReleaseCallback(scoped_ptr<cc::SingleReleaseCallback> cb, |
- uint32 sync_point) { |
- cb->Run(sync_point, false); |
-} |
- |
-void DesktopVideoCaptureMachine::DidCopyOutput( |
+void AuraWindowCaptureMachine::DidCopyOutput( |
scoped_refptr<media::VideoFrame> video_frame, |
base::TimeTicks start_time, |
const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
@@ -324,7 +243,7 @@ void DesktopVideoCaptureMachine::DidCopyOutput( |
// The two UMA_ blocks must be put in its own scope since it creates a static |
// variable which expected constant histogram name. |
- if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { |
+ if (screen_capture_) { |
UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); |
} else { |
UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); |
@@ -332,7 +251,7 @@ void DesktopVideoCaptureMachine::DidCopyOutput( |
if (first_call) { |
first_call = false; |
- if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { |
+ if (screen_capture_) { |
IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED |
: FIRST_SCREEN_CAPTURE_FAILED); |
} else { |
@@ -343,7 +262,7 @@ void DesktopVideoCaptureMachine::DidCopyOutput( |
} |
} |
-bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse( |
+bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( |
scoped_refptr<media::VideoFrame> video_frame, |
base::TimeTicks start_time, |
const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
@@ -432,7 +351,7 @@ bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse( |
return true; |
} |
-gfx::Point DesktopVideoCaptureMachine::UpdateCursorState( |
+gfx::Point AuraWindowCaptureMachine::UpdateCursorState( |
const gfx::Rect& region_in_frame) { |
const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds(); |
if (desktop_bounds.IsEmpty()) { |
@@ -483,14 +402,14 @@ gfx::Point DesktopVideoCaptureMachine::UpdateCursorState( |
desktop_bounds.height()); |
} |
-void DesktopVideoCaptureMachine::ClearCursorState() { |
+void AuraWindowCaptureMachine::ClearCursorState() { |
last_cursor_ = ui::Cursor(); |
desktop_size_when_cursor_last_updated_ = gfx::Size(); |
cursor_hot_point_ = gfx::Point(); |
scaled_cursor_bitmap_.reset(); |
} |
-void DesktopVideoCaptureMachine::OnWindowBoundsChanged( |
+void AuraWindowCaptureMachine::OnWindowBoundsChanged( |
aura::Window* window, |
const gfx::Rect& old_bounds, |
const gfx::Rect& new_bounds) { |
@@ -498,10 +417,10 @@ void DesktopVideoCaptureMachine::OnWindowBoundsChanged( |
// Post task to update capture size on UI thread. |
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
- &DesktopVideoCaptureMachine::UpdateCaptureSize, AsWeakPtr())); |
+ &AuraWindowCaptureMachine::UpdateCaptureSize, AsWeakPtr())); |
} |
-void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) { |
+void AuraWindowCaptureMachine::OnWindowDestroyed(aura::Window* window) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
Stop(base::Bind(&base::DoNothing)); |
@@ -509,54 +428,23 @@ void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) { |
oracle_proxy_->ReportError("OnWindowDestroyed()"); |
} |
-void DesktopVideoCaptureMachine::OnWindowAddedToRootWindow( |
+void AuraWindowCaptureMachine::OnWindowAddedToRootWindow( |
aura::Window* window) { |
DCHECK(window == desktop_window_); |
window->GetHost()->compositor()->AddObserver(this); |
} |
-void DesktopVideoCaptureMachine::OnWindowRemovingFromRootWindow( |
+void AuraWindowCaptureMachine::OnWindowRemovingFromRootWindow( |
aura::Window* window, |
aura::Window* new_root) { |
DCHECK(window == desktop_window_); |
window->GetHost()->compositor()->RemoveObserver(this); |
} |
-void DesktopVideoCaptureMachine::OnCompositingEnded( |
+void AuraWindowCaptureMachine::OnCompositingEnded( |
ui::Compositor* compositor) { |
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
- &DesktopVideoCaptureMachine::Capture, AsWeakPtr(), true)); |
-} |
- |
-} // namespace |
- |
-DesktopCaptureDeviceAura::DesktopCaptureDeviceAura( |
- const DesktopMediaID& source) |
- : core_(new ContentVideoCaptureDeviceCore(scoped_ptr<VideoCaptureMachine>( |
- new DesktopVideoCaptureMachine(source)))) {} |
- |
-DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { |
- DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; |
-} |
- |
-// static |
-media::VideoCaptureDevice* DesktopCaptureDeviceAura::Create( |
- const DesktopMediaID& source) { |
- IncrementDesktopCaptureCounter(source.type == DesktopMediaID::TYPE_SCREEN |
- ? SCREEN_CAPTURER_CREATED |
- : WINDOW_CAPTURER_CREATED); |
- return new DesktopCaptureDeviceAura(source); |
-} |
- |
-void DesktopCaptureDeviceAura::AllocateAndStart( |
- const media::VideoCaptureParams& params, |
- scoped_ptr<Client> client) { |
- DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); |
- core_->AllocateAndStart(params, client.Pass()); |
-} |
- |
-void DesktopCaptureDeviceAura::StopAndDeAllocate() { |
- core_->StopAndDeAllocate(); |
+ &AuraWindowCaptureMachine::Capture, AsWeakPtr(), true)); |
} |
} // namespace content |