Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: content/browser/media/capture/cursor_renderer.h

Issue 2553763002: Fix cursor missing in tabCapture on OSX Sierra (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_CURSOR_RENDERER_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_ 6 #define CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/time/default_tick_clock.h"
12 #include "base/time/tick_clock.h"
11 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
12 #include "media/base/video_frame.h" 14 #include "media/base/video_frame.h"
15 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "ui/base/cursor/cursor.h"
13 #include "ui/gfx/native_widget_types.h" 17 #include "ui/gfx/native_widget_types.h"
14 18
15 namespace content { 19 namespace content {
16 20
17 // CursorRenderer is an interface that can be implememented to do cursor 21 // Setting to control cursor display based on either mouse movement or always
18 // rendering on a video frame. 22 // forced to be enabled.
23 enum CursorDisplaySetting {
24 kCursorAlwaysEnabled,
25 kCursorEnabledOnMouseMovement
26 };
27
28 // CursorRenderer is an abstract base class that handles all the
29 // non-platform-specific common cursor rendering functionality.
19 // 30 //
20 // In order to track the cursor, the platform-specific implementation 31 // In order to track the cursor, the platform-specific implementation
21 // will listen to mouse events. 32 // will listen to mouse events.
22 class CONTENT_EXPORT CursorRenderer { 33 class CONTENT_EXPORT CursorRenderer {
23 public: 34 public:
24 static std::unique_ptr<CursorRenderer> Create(gfx::NativeView view); 35 static std::unique_ptr<CursorRenderer> Create(gfx::NativeView view);
25 36
26 virtual ~CursorRenderer() {} 37 CursorRenderer(gfx::NativeView captured_view,
38 CursorDisplaySetting cursor_display);
39
40 virtual ~CursorRenderer();
27 41
28 // Clears the cursor state being tracked. Called when there is a need to 42 // Clears the cursor state being tracked. Called when there is a need to
29 // reset the state. 43 // reset the state.
30 virtual void Clear() = 0; 44 void Clear();
31 45
32 // Takes a snapshot of the current cursor state and determines whether 46 // Takes a snapshot of the current cursor state and determines whether
33 // the cursor will be rendered, which cursor image to render, and at what 47 // the cursor will be rendered, which cursor image to render, and at what
34 // location within |region_in_frame| to render it. Returns true if cursor 48 // location within |region_in_frame| to render it. Returns true if cursor
35 // needs to be rendered. 49 // needs to be rendered.
36 virtual bool SnapshotCursorState(const gfx::Rect& region_in_frame) = 0; 50 bool SnapshotCursorState(const gfx::Rect& region_in_frame);
37 51
38 // Renders cursor on the |target| video frame. 52 // Renders cursor on the |target| video frame.
39 virtual void RenderOnVideoFrame( 53 void RenderOnVideoFrame(media::VideoFrame* target) const;
40 const scoped_refptr<media::VideoFrame>& target) const = 0;
41 54
42 // Returns a weak pointer. 55 // Returns a weak pointer.
43 virtual base::WeakPtr<CursorRenderer> GetWeakPtr() = 0; 56 base::WeakPtr<CursorRenderer> GetWeakPtr();
44 57
45 protected: 58 protected:
46 enum { 59 enum {
47 // Minium movement before cursor is rendered on frame. 60 // Minium movement before cursor is rendered on frame.
48 MIN_MOVEMENT_PIXELS = 15, 61 MIN_MOVEMENT_PIXELS = 15,
49 // Maximum idle time allowed before we stop rendering the cursor 62 // Maximum idle time allowed before we stop rendering the cursor on frame.
50 // on frame.
51 MAX_IDLE_TIME_SECONDS = 2 63 MAX_IDLE_TIME_SECONDS = 2
52 }; 64 };
65
66 // Returns true if the captured view is a part of an active application
67 // window.
68 virtual bool IsCapturedViewActive() = 0;
69
70 // Returns the size of the captured view (view coordinates).
71 virtual gfx::Size GetCapturedViewSize() = 0;
72
73 // Returns the cursor's position within the captured view (view coordinates).
74 virtual gfx::Point GetCursorPositionInView() = 0;
75
76 // Returns the last-known mouse cursor.
77 virtual gfx::NativeCursor GetLastKnownCursor() = 0;
78
79 // Returns the image of the last-known mouse cursor and its hotspot.
80 virtual SkBitmap GetLastKnownCursorImage(gfx::Point* hot_point) = 0;
81
82 // Called by subclasses to report mouse events within the captured view.
83 void OnMouseMoved(const gfx::Point& location, base::TimeTicks timestamp);
84 void OnMouseClicked(const gfx::Point& location, base::TimeTicks timestamp);
85
86 private:
87 friend class CursorRendererAuraTest;
88
89 const gfx::NativeView captured_view_;
90
91 // Snapshot of cursor, source size, scale, position, and cursor bitmap;
92 // as of the last call to SnapshotCursorState.
93 float last_x_scale_;
94 float last_y_scale_;
95 gfx::NativeCursor last_cursor_;
96 gfx::Point cursor_position_in_frame_;
97 gfx::Point last_cursor_hot_point_;
98 SkBitmap scaled_cursor_bitmap_;
99
100 // Updated in mouse event listener and used to make a decision on
101 // when the cursor is rendered.
102 base::TimeTicks last_mouse_movement_timestamp_;
103 float last_mouse_position_x_;
104 float last_mouse_position_y_;
105 bool cursor_displayed_;
106
107 // Controls whether cursor is displayed based on active mouse movement.
108 CursorDisplaySetting cursor_display_setting_;
109
110 // Allows tests to replace the clock.
111 base::DefaultTickClock default_tick_clock_;
112 base::TickClock* tick_clock_;
113
114 base::WeakPtrFactory<CursorRenderer> weak_factory_;
115
116 DISALLOW_COPY_AND_ASSIGN(CursorRenderer);
53 }; 117 };
54 118
55 } // namespace content 119 } // namespace content
56 120
57 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_ 121 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_
OLDNEW
« no previous file with comments | « content/browser/media/capture/aura_window_capture_machine.cc ('k') | content/browser/media/capture/cursor_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698