| 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 69%
|
| copy from content/browser/media/capture/desktop_capture_device_aura.cc
|
| copy to content/browser/media/capture/aura_window_capture_machine.cc
|
| index 37979613dddf0572340bda84df472ae3df7c2033..73f4cb30fc10e908ecb8bc0138770c68ff8e0611 100644
|
| --- a/content/browser/media/capture/desktop_capture_device_aura.cc
|
| +++ b/content/browser/media/capture/aura_window_capture_machine.cc
|
| @@ -1,8 +1,8 @@
|
| -// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// 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/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,39 @@ 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 the desktop bound 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::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_);
|
| - if (!desktop_window_)
|
| - return false;
|
| + DCHECK(desktop_window_);
|
|
|
| // If the associated layer is already destroyed then return failure.
|
| ui::Layer* layer = desktop_window_->layer();
|
| @@ -211,13 +135,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);
|
| -
|
| power_save_blocker_.reset(
|
| PowerSaveBlocker::Create(
|
| PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
|
| @@ -226,13 +143,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();
|
|
|
| @@ -252,7 +169,27 @@ 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);
|
| +
|
| + // Start observing compositor updates.
|
| + if (desktop_window_->GetHost())
|
| + desktop_window_->GetHost()->compositor()->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();
|
| @@ -262,7 +199,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.
|
| @@ -280,7 +217,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());
|
| @@ -289,26 +226,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,
|
| @@ -322,7 +240,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);
|
| @@ -330,7 +248,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 {
|
| @@ -341,7 +259,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,
|
| @@ -427,7 +345,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();
|
| gfx::NativeCursor cursor =
|
| @@ -464,13 +382,13 @@ gfx::Point DesktopVideoCaptureMachine::UpdateCursorState(
|
| desktop_bounds.height());
|
| }
|
|
|
| -void DesktopVideoCaptureMachine::ClearCursorState() {
|
| +void AuraWindowCaptureMachine::ClearCursorState() {
|
| last_cursor_ = ui::Cursor();
|
| 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) {
|
| @@ -478,10 +396,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));
|
| @@ -489,54 +407,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
|
|
|