| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/browser/media/capture/cursor_renderer_aura.h" | 12 #include "content/browser/media/capture/cursor_renderer_aura.h" |
| 13 #include "media/capture/content/screen_capture_device_core.h" | 13 #include "device/capture/content/screen_capture_device_core.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
| 16 #include "ui/base/cursor/cursors_aura.h" | 16 #include "ui/base/cursor/cursors_aura.h" |
| 17 #include "ui/compositor/compositor.h" | 17 #include "ui/compositor/compositor.h" |
| 18 #include "ui/compositor/compositor_animation_observer.h" | 18 #include "ui/compositor/compositor_animation_observer.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 class CopyOutputResult; | 21 class CopyOutputResult; |
| 22 } // namespace cc | 22 } // namespace cc |
| 23 | 23 |
| 24 namespace device { | 24 namespace device { |
| 25 class PowerSaveBlocker; | 25 class PowerSaveBlocker; |
| 26 } // namespace device | 26 } // namespace device |
| 27 | 27 |
| 28 namespace display_compositor { | 28 namespace display_compositor { |
| 29 class ReadbackYUVInterface; | 29 class ReadbackYUVInterface; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 class AuraWindowCaptureMachine | 34 class AuraWindowCaptureMachine : public device::VideoCaptureMachine, |
| 35 : public media::VideoCaptureMachine, | 35 public aura::WindowObserver, |
| 36 public aura::WindowObserver, | 36 public ui::CompositorAnimationObserver { |
| 37 public ui::CompositorAnimationObserver { | |
| 38 public: | 37 public: |
| 39 AuraWindowCaptureMachine(); | 38 AuraWindowCaptureMachine(); |
| 40 ~AuraWindowCaptureMachine() override; | 39 ~AuraWindowCaptureMachine() override; |
| 41 | 40 |
| 42 // VideoCaptureMachine overrides. | 41 // VideoCaptureMachine overrides. |
| 43 void Start(const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 42 void Start(const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle_proxy, |
| 44 const media::VideoCaptureParams& params, | 43 const media::VideoCaptureParams& params, |
| 45 const base::Callback<void(bool)> callback) override; | 44 const base::Callback<void(bool)> callback) override; |
| 46 void Stop(const base::Closure& callback) override; | 45 void Stop(const base::Closure& callback) override; |
| 47 void MaybeCaptureForRefresh() override; | 46 void MaybeCaptureForRefresh() override; |
| 48 | 47 |
| 49 // Implements aura::WindowObserver. | 48 // Implements aura::WindowObserver. |
| 50 void OnWindowBoundsChanged(aura::Window* window, | 49 void OnWindowBoundsChanged(aura::Window* window, |
| 51 const gfx::Rect& old_bounds, | 50 const gfx::Rect& old_bounds, |
| 52 const gfx::Rect& new_bounds) override; | 51 const gfx::Rect& new_bounds) override; |
| 53 void OnWindowDestroying(aura::Window* window) override; | 52 void OnWindowDestroying(aura::Window* window) override; |
| 54 void OnWindowAddedToRootWindow(aura::Window* window) override; | 53 void OnWindowAddedToRootWindow(aura::Window* window) override; |
| 55 void OnWindowRemovingFromRootWindow(aura::Window* window, | 54 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 56 aura::Window* new_root) override; | 55 aura::Window* new_root) override; |
| 57 | 56 |
| 58 // ui::CompositorAnimationObserver implementation. | 57 // ui::CompositorAnimationObserver implementation. |
| 59 void OnAnimationStep(base::TimeTicks timestamp) override; | 58 void OnAnimationStep(base::TimeTicks timestamp) override; |
| 60 void OnCompositingShuttingDown(ui::Compositor* compositor) override; | 59 void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
| 61 | 60 |
| 62 // Sets the window to use for capture. | 61 // Sets the window to use for capture. |
| 63 void SetWindow(aura::Window* window); | 62 void SetWindow(aura::Window* window); |
| 64 | 63 |
| 65 private: | 64 private: |
| 66 bool InternalStart( | 65 bool InternalStart( |
| 67 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 66 const scoped_refptr<device::ThreadSafeCaptureOracle>& oracle_proxy, |
| 68 const media::VideoCaptureParams& params); | 67 const media::VideoCaptureParams& params); |
| 69 void InternalStop(const base::Closure& callback); | 68 void InternalStop(const base::Closure& callback); |
| 70 | 69 |
| 71 // Captures a frame. |event_time| is provided by the compositor, or is null | 70 // Captures a frame. |event_time| is provided by the compositor, or is null |
| 72 // for refresh requests. | 71 // for refresh requests. |
| 73 void Capture(base::TimeTicks event_time); | 72 void Capture(base::TimeTicks event_time); |
| 74 | 73 |
| 75 // Update capture size. Must be called on the UI thread. | 74 // Update capture size. Must be called on the UI thread. |
| 76 void UpdateCaptureSize(); | 75 void UpdateCaptureSize(); |
| 77 | 76 |
| 78 using CaptureFrameCallback = | 77 using CaptureFrameCallback = |
| 79 media::ThreadSafeCaptureOracle::CaptureFrameCallback; | 78 device::ThreadSafeCaptureOracle::CaptureFrameCallback; |
| 80 | 79 |
| 81 // Response callback for cc::Layer::RequestCopyOfOutput(). | 80 // Response callback for cc::Layer::RequestCopyOfOutput(). |
| 82 void DidCopyOutput(scoped_refptr<media::VideoFrame> video_frame, | 81 void DidCopyOutput(scoped_refptr<media::VideoFrame> video_frame, |
| 83 base::TimeTicks event_time, | 82 base::TimeTicks event_time, |
| 84 base::TimeTicks start_time, | 83 base::TimeTicks start_time, |
| 85 const CaptureFrameCallback& capture_frame_cb, | 84 const CaptureFrameCallback& capture_frame_cb, |
| 86 std::unique_ptr<cc::CopyOutputResult> result); | 85 std::unique_ptr<cc::CopyOutputResult> result); |
| 87 | 86 |
| 88 // 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 |
| 89 // succeeded and |capture_frame_cb| will be run at some future point. Returns | 88 // succeeded and |capture_frame_cb| will be run at some future point. Returns |
| (...skipping 13 matching lines...) Expand all Loading... |
| 103 std::unique_ptr<cc::SingleReleaseCallback> release_callback, | 102 std::unique_ptr<cc::SingleReleaseCallback> release_callback, |
| 104 bool result); | 103 bool result); |
| 105 | 104 |
| 106 // The window associated with the desktop. | 105 // The window associated with the desktop. |
| 107 aura::Window* desktop_window_; | 106 aura::Window* desktop_window_; |
| 108 | 107 |
| 109 // Whether screen capturing or window capture. | 108 // Whether screen capturing or window capture. |
| 110 bool screen_capture_; | 109 bool screen_capture_; |
| 111 | 110 |
| 112 // Makes all the decisions about which frames to copy, and how. | 111 // Makes all the decisions about which frames to copy, and how. |
| 113 scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy_; | 112 scoped_refptr<device::ThreadSafeCaptureOracle> oracle_proxy_; |
| 114 | 113 |
| 115 // The capture parameters for this capture. | 114 // The capture parameters for this capture. |
| 116 media::VideoCaptureParams capture_params_; | 115 media::VideoCaptureParams capture_params_; |
| 117 | 116 |
| 118 // YUV readback pipeline. | 117 // YUV readback pipeline. |
| 119 std::unique_ptr<display_compositor::ReadbackYUVInterface> | 118 std::unique_ptr<display_compositor::ReadbackYUVInterface> |
| 120 yuv_readback_pipeline_; | 119 yuv_readback_pipeline_; |
| 121 | 120 |
| 122 // Renders mouse cursor on frame. | 121 // Renders mouse cursor on frame. |
| 123 std::unique_ptr<content::CursorRendererAura> cursor_renderer_; | 122 std::unique_ptr<content::CursorRendererAura> cursor_renderer_; |
| 124 | 123 |
| 125 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the | 124 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the |
| 126 // screen from sleeping for the drive-by web. | 125 // screen from sleeping for the drive-by web. |
| 127 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_; | 126 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_; |
| 128 | 127 |
| 129 // WeakPtrs are used for the asynchronous capture callbacks passed to external | 128 // WeakPtrs are used for the asynchronous capture callbacks passed to external |
| 130 // modules. They are only valid on the UI thread and become invalidated | 129 // modules. They are only valid on the UI thread and become invalidated |
| 131 // immediately when InternalStop() is called to ensure that no more captured | 130 // immediately when InternalStop() is called to ensure that no more captured |
| 132 // frames will be delivered to the client. | 131 // frames will be delivered to the client. |
| 133 base::WeakPtrFactory<AuraWindowCaptureMachine> weak_factory_; | 132 base::WeakPtrFactory<AuraWindowCaptureMachine> weak_factory_; |
| 134 | 133 |
| 135 DISALLOW_COPY_AND_ASSIGN(AuraWindowCaptureMachine); | 134 DISALLOW_COPY_AND_ASSIGN(AuraWindowCaptureMachine); |
| 136 }; | 135 }; |
| 137 | 136 |
| 138 } // namespace content | 137 } // namespace content |
| 139 | 138 |
| 140 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_ | 139 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_ |
| OLD | NEW |