Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / media / capture / aura_window_capture_machine.h
blobf41e73ce460af2a7bdcf3bfe6739b037aa01307f
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 "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"
17 namespace cc {
19 class CopyOutputResult;
21 } // namespace cc
23 namespace content {
25 class PowerSaveBlocker;
26 class ReadbackYUVInterface;
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;
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;
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;
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 {}
60 // Sets the window to use for capture.
61 void SetWindow(aura::Window* window);
63 private:
64 // Captures a frame.
65 // |dirty| is false for timer polls and true for compositor updates.
66 void Capture(bool dirty);
68 // Update capture size. Must be called on the UI thread.
69 void UpdateCaptureSize();
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);
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);
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);
92 // Clears cursor state.
93 void ClearCursorState();
95 // The window associated with the desktop.
96 aura::Window* desktop_window_;
98 // The timer that kicks off period captures.
99 base::Timer timer_;
101 // Whether screen capturing or window capture.
102 bool screen_capture_;
104 // Makes all the decisions about which frames to copy, and how.
105 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_;
107 // The capture parameters for this capture.
108 media::VideoCaptureParams capture_params_;
110 // YUV readback pipeline.
111 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_;
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_;
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_;
123 DISALLOW_COPY_AND_ASSIGN(AuraWindowCaptureMachine);
126 } // namespace content
128 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AURA_WINDOW_CAPTURE_MACHINE_H_