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.
5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/timer/timer.h"
11 #include "media/capture/content/screen_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"
19 class CopyOutputResult
;
25 class PowerSaveBlocker
;
26 class ReadbackYUVInterface
;
28 class AuraWindowCaptureMachine
29 : public media::VideoCaptureMachine
,
30 public aura::WindowObserver
,
31 public ui::CompositorObserver
,
32 public base::SupportsWeakPtr
<AuraWindowCaptureMachine
> {
34 AuraWindowCaptureMachine();
35 ~AuraWindowCaptureMachine() override
;
37 // VideoCaptureMachine overrides.
38 void Start(const scoped_refptr
<media::ThreadSafeCaptureOracle
>& oracle_proxy
,
39 const media::VideoCaptureParams
& params
,
40 const base::Callback
<void(bool)> callback
) override
;
41 void Stop(const base::Closure
& callback
) override
;
43 // Implements aura::WindowObserver.
44 void OnWindowBoundsChanged(aura::Window
* window
,
45 const gfx::Rect
& old_bounds
,
46 const gfx::Rect
& new_bounds
) override
;
47 void OnWindowDestroying(aura::Window
* window
) override
;
48 void OnWindowAddedToRootWindow(aura::Window
* window
) override
;
49 void OnWindowRemovingFromRootWindow(aura::Window
* window
,
50 aura::Window
* new_root
) override
;
52 // Implements ui::CompositorObserver.
53 void OnCompositingDidCommit(ui::Compositor
* compositor
) override
{}
54 void OnCompositingStarted(ui::Compositor
* compositor
,
55 base::TimeTicks start_time
) override
{}
56 void OnCompositingEnded(ui::Compositor
* compositor
) override
;
57 void OnCompositingAborted(ui::Compositor
* compositor
) override
{}
58 void OnCompositingLockStateChanged(ui::Compositor
* compositor
) override
{}
59 void OnCompositingShuttingDown(ui::Compositor
* compositor
) override
{}
61 // Sets the window to use for capture.
62 void SetWindow(aura::Window
* window
);
66 const scoped_refptr
<media::ThreadSafeCaptureOracle
>& oracle_proxy
,
67 const media::VideoCaptureParams
& params
);
68 void InternalStop(const base::Closure
& callback
);
71 // |dirty| is false for timer polls and true for compositor updates.
72 void Capture(bool dirty
);
74 // Update capture size. Must be called on the UI thread.
75 void UpdateCaptureSize();
77 using CaptureFrameCallback
=
78 media::ThreadSafeCaptureOracle::CaptureFrameCallback
;
80 // Response callback for cc::Layer::RequestCopyOfOutput().
82 scoped_refptr
<media::VideoFrame
> video_frame
,
83 base::TimeTicks start_time
,
84 const CaptureFrameCallback
& capture_frame_cb
,
85 scoped_ptr
<cc::CopyOutputResult
> result
);
87 // A helper which does the real work for DidCopyOutput. Returns true if
89 bool ProcessCopyOutputResponse(
90 scoped_refptr
<media::VideoFrame
> video_frame
,
91 base::TimeTicks start_time
,
92 const CaptureFrameCallback
& capture_frame_cb
,
93 scoped_ptr
<cc::CopyOutputResult
> result
);
95 // Helper function to update cursor state.
96 // |region_in_frame| defines where the desktop is rendered in the captured
98 // Returns the current cursor position in captured frame.
99 gfx::Point
UpdateCursorState(const gfx::Rect
& region_in_frame
);
101 // Clears cursor state.
102 void ClearCursorState();
104 // The window associated with the desktop.
105 aura::Window
* desktop_window_
;
107 // The timer that kicks off period captures.
110 // Whether screen capturing or window capture.
111 bool screen_capture_
;
113 // Makes all the decisions about which frames to copy, and how.
114 scoped_refptr
<media::ThreadSafeCaptureOracle
> oracle_proxy_
;
116 // The capture parameters for this capture.
117 media::VideoCaptureParams capture_params_
;
119 // YUV readback pipeline.
120 scoped_ptr
<content::ReadbackYUVInterface
> yuv_readback_pipeline_
;
123 ui::Cursor last_cursor_
;
124 gfx::Size desktop_size_when_cursor_last_updated_
;
125 gfx::Point cursor_hot_point_
;
126 SkBitmap scaled_cursor_bitmap_
;
128 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the
129 // screen from sleeping for the drive-by web.
130 scoped_ptr
<PowerSaveBlocker
> power_save_blocker_
;
132 DISALLOW_COPY_AND_ASSIGN(AuraWindowCaptureMachine
);
135 } // namespace content
137 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_