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