Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_ | 6 #define CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| 11 #include "content/browser/media/capture/content_video_capture_device_core.h" | 11 #include "media/capture/media_video_capture_device_core.h" |
| 12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_observer.h" | 13 #include "ui/aura/window_observer.h" |
| 14 #include "ui/base/cursor/cursors_aura.h" | 14 #include "ui/base/cursor/cursors_aura.h" |
| 15 #include "ui/compositor/compositor.h" | 15 #include "ui/compositor/compositor.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 class CopyOutputResult; | 19 class CopyOutputResult; |
| 20 | 20 |
| 21 } // namespace cc | 21 } // namespace cc |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 class PowerSaveBlocker; | 25 class PowerSaveBlocker; |
| 26 class ReadbackYUVInterface; | 26 class ReadbackYUVInterface; |
| 27 | 27 |
| 28 class AuraWindowCaptureMachine | 28 class AuraWindowCaptureMachine |
| 29 : public VideoCaptureMachine, | 29 : public media::VideoCaptureMachine, |
| 30 public aura::WindowObserver, | 30 public aura::WindowObserver, |
| 31 public ui::CompositorObserver, | 31 public ui::CompositorObserver, |
| 32 public base::SupportsWeakPtr<AuraWindowCaptureMachine> { | 32 public base::SupportsWeakPtr<AuraWindowCaptureMachine> { |
| 33 public: | 33 public: |
| 34 AuraWindowCaptureMachine(); | 34 AuraWindowCaptureMachine(); |
| 35 ~AuraWindowCaptureMachine() override; | 35 ~AuraWindowCaptureMachine() override; |
| 36 | 36 |
| 37 // VideoCaptureFrameSource overrides. | 37 // VideoCaptureMachine overrides. |
| 38 bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 38 void Start(const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
| 39 const media::VideoCaptureParams& params) override; | 39 const media::VideoCaptureParams& params, |
| 40 const base::Callback<void(bool)> callback) override; | |
| 40 void Stop(const base::Closure& callback) override; | 41 void Stop(const base::Closure& callback) override; |
| 41 | 42 |
| 42 // Implements aura::WindowObserver. | 43 // Implements aura::WindowObserver. |
| 43 void OnWindowBoundsChanged(aura::Window* window, | 44 void OnWindowBoundsChanged(aura::Window* window, |
| 44 const gfx::Rect& old_bounds, | 45 const gfx::Rect& old_bounds, |
| 45 const gfx::Rect& new_bounds) override; | 46 const gfx::Rect& new_bounds) override; |
| 46 void OnWindowDestroyed(aura::Window* window) override; | 47 void OnWindowDestroyed(aura::Window* window) override; |
| 47 void OnWindowAddedToRootWindow(aura::Window* window) override; | 48 void OnWindowAddedToRootWindow(aura::Window* window) override; |
| 48 void OnWindowRemovingFromRootWindow(aura::Window* window, | 49 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 49 aura::Window* new_root) override; | 50 aura::Window* new_root) override; |
| 50 | 51 |
| 51 // Implements ui::CompositorObserver. | 52 // Implements ui::CompositorObserver. |
| 52 void OnCompositingDidCommit(ui::Compositor* compositor) override {} | 53 void OnCompositingDidCommit(ui::Compositor* compositor) override {} |
| 53 void OnCompositingStarted(ui::Compositor* compositor, | 54 void OnCompositingStarted(ui::Compositor* compositor, |
| 54 base::TimeTicks start_time) override {} | 55 base::TimeTicks start_time) override {} |
| 55 void OnCompositingEnded(ui::Compositor* compositor) override; | 56 void OnCompositingEnded(ui::Compositor* compositor) override; |
| 56 void OnCompositingAborted(ui::Compositor* compositor) override {} | 57 void OnCompositingAborted(ui::Compositor* compositor) override {} |
| 57 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {} | 58 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {} |
| 58 void OnCompositingShuttingDown(ui::Compositor* compositor) override {} | 59 void OnCompositingShuttingDown(ui::Compositor* compositor) override {} |
| 59 | 60 |
| 60 // Sets the window to use for capture. | 61 // Sets the window to use for capture. |
| 61 void SetWindow(aura::Window* window); | 62 void SetWindow(aura::Window* window); |
| 62 | 63 |
| 63 private: | 64 private: |
| 65 bool InternalStart( | |
| 66 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | |
| 67 const media::VideoCaptureParams& params); | |
| 68 void InternalStop(const base::Closure& callback); | |
| 69 | |
| 64 // Captures a frame. | 70 // Captures a frame. |
| 65 // |dirty| is false for timer polls and true for compositor updates. | 71 // |dirty| is false for timer polls and true for compositor updates. |
| 66 void Capture(bool dirty); | 72 void Capture(bool dirty); |
| 67 | 73 |
| 68 // Update capture size. Must be called on the UI thread. | 74 // Update capture size. Must be called on the UI thread. |
| 69 void UpdateCaptureSize(); | 75 void UpdateCaptureSize(); |
| 70 | 76 |
| 77 typedef media::ThreadSafeCaptureOracle::CaptureFrameCallback | |
|
miu
2015/06/05 01:13:36
nit: With C++11, this style is now preferred:
u
jiajia.qin
2015/06/08 04:58:23
Done.
| |
| 78 CaptureFrameCallback; | |
| 79 | |
| 71 // Response callback for cc::Layer::RequestCopyOfOutput(). | 80 // Response callback for cc::Layer::RequestCopyOfOutput(). |
| 72 void DidCopyOutput( | 81 void DidCopyOutput( |
| 73 scoped_refptr<media::VideoFrame> video_frame, | 82 scoped_refptr<media::VideoFrame> video_frame, |
| 74 base::TimeTicks start_time, | 83 base::TimeTicks start_time, |
| 75 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 84 const CaptureFrameCallback& capture_frame_cb, |
| 76 scoped_ptr<cc::CopyOutputResult> result); | 85 scoped_ptr<cc::CopyOutputResult> result); |
| 77 | 86 |
| 78 // A helper which does the real work for DidCopyOutput. Returns true if | 87 // A helper which does the real work for DidCopyOutput. Returns true if |
| 79 // succeeded. | 88 // succeeded. |
| 80 bool ProcessCopyOutputResponse( | 89 bool ProcessCopyOutputResponse( |
| 81 scoped_refptr<media::VideoFrame> video_frame, | 90 scoped_refptr<media::VideoFrame> video_frame, |
| 82 base::TimeTicks start_time, | 91 base::TimeTicks start_time, |
| 83 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 92 const CaptureFrameCallback& capture_frame_cb, |
| 84 scoped_ptr<cc::CopyOutputResult> result); | 93 scoped_ptr<cc::CopyOutputResult> result); |
| 85 | 94 |
| 86 // Helper function to update cursor state. | 95 // Helper function to update cursor state. |
| 87 // |region_in_frame| defines where the desktop is rendered in the captured | 96 // |region_in_frame| defines where the desktop is rendered in the captured |
| 88 // frame. | 97 // frame. |
| 89 // Returns the current cursor position in captured frame. | 98 // Returns the current cursor position in captured frame. |
| 90 gfx::Point UpdateCursorState(const gfx::Rect& region_in_frame); | 99 gfx::Point UpdateCursorState(const gfx::Rect& region_in_frame); |
| 91 | 100 |
| 92 // Clears cursor state. | 101 // Clears cursor state. |
| 93 void ClearCursorState(); | 102 void ClearCursorState(); |
| 94 | 103 |
| 95 // The window associated with the desktop. | 104 // The window associated with the desktop. |
| 96 aura::Window* desktop_window_; | 105 aura::Window* desktop_window_; |
| 97 | 106 |
| 98 // The timer that kicks off period captures. | 107 // The timer that kicks off period captures. |
| 99 base::Timer timer_; | 108 base::Timer timer_; |
| 100 | 109 |
| 101 // Whether screen capturing or window capture. | 110 // Whether screen capturing or window capture. |
| 102 bool screen_capture_; | 111 bool screen_capture_; |
| 103 | 112 |
| 104 // Makes all the decisions about which frames to copy, and how. | 113 // Makes all the decisions about which frames to copy, and how. |
| 105 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; | 114 scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy_; |
| 106 | 115 |
| 107 // The capture parameters for this capture. | 116 // The capture parameters for this capture. |
| 108 media::VideoCaptureParams capture_params_; | 117 media::VideoCaptureParams capture_params_; |
| 109 | 118 |
| 110 // YUV readback pipeline. | 119 // YUV readback pipeline. |
| 111 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; | 120 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; |
| 112 | 121 |
| 113 // Cursor state. | 122 // Cursor state. |
| 114 ui::Cursor last_cursor_; | 123 ui::Cursor last_cursor_; |
| 115 gfx::Size desktop_size_when_cursor_last_updated_; | 124 gfx::Size desktop_size_when_cursor_last_updated_; |
| 116 gfx::Point cursor_hot_point_; | 125 gfx::Point cursor_hot_point_; |
| 117 SkBitmap scaled_cursor_bitmap_; | 126 SkBitmap scaled_cursor_bitmap_; |
| 118 | 127 |
| 119 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the | 128 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the |
| 120 // screen from sleeping for the drive-by web. | 129 // screen from sleeping for the drive-by web. |
| 121 scoped_ptr<PowerSaveBlocker> power_save_blocker_; | 130 scoped_ptr<PowerSaveBlocker> power_save_blocker_; |
| 122 | 131 |
| 123 DISALLOW_COPY_AND_ASSIGN(AuraWindowCaptureMachine); | 132 DISALLOW_COPY_AND_ASSIGN(AuraWindowCaptureMachine); |
| 124 }; | 133 }; |
| 125 | 134 |
| 126 } // namespace content | 135 } // namespace content |
| 127 | 136 |
| 128 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_ | 137 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_ |
| OLD | NEW |