| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "content/browser/media/capture/cursor_renderer_mac.h" | 5 #include "content/browser/media/capture/cursor_renderer_mac.h" |
| 6 | 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 #include <Cocoa/Cocoa.h> | 8 #include <Cocoa/Cocoa.h> |
| 9 #include <CoreFoundation/CoreFoundation.h> | 9 #include <CoreFoundation/CoreFoundation.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 last_mouse_location_y_ = 0; | 54 last_mouse_location_y_ = 0; |
| 55 last_mouse_movement_timestamp_ = base::TimeTicks(); | 55 last_mouse_movement_timestamp_ = base::TimeTicks(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Polls mouse cursor location and image and returns whether the mouse | 58 // Polls mouse cursor location and image and returns whether the mouse |
| 59 // cursor should be rendered on the frame. | 59 // cursor should be rendered on the frame. |
| 60 bool CursorRendererMac::SnapshotCursorState(const gfx::Rect& region_in_frame) { | 60 bool CursorRendererMac::SnapshotCursorState(const gfx::Rect& region_in_frame) { |
| 61 // Mouse location in window co-ordinates. | 61 // Mouse location in window co-ordinates. |
| 62 NSPoint mouse_window_location = | 62 NSPoint mouse_window_location = |
| 63 [view_ window].mouseLocationOutsideOfEventStream; | 63 [view_ window].mouseLocationOutsideOfEventStream; |
| 64 // Mouse location with respect to the web contents. |
| 65 NSPoint mouse_tab_location = |
| 66 [view_ convertPoint:mouse_window_location fromView:nil]; |
| 64 | 67 |
| 65 // Mouse co-ordinates directly comparable against frame co-ordinates | 68 // Mouse co-ordinates directly comparable against frame co-ordinates |
| 66 // after translation. | 69 // after translation. |
| 67 if (mouse_window_location.x < 0 || mouse_window_location.y < 0 || | 70 if (mouse_tab_location.x < 0 || mouse_tab_location.y < 0 || |
| 68 mouse_window_location.x > region_in_frame.width() || | 71 mouse_tab_location.x > region_in_frame.width() || |
| 69 mouse_window_location.y > region_in_frame.height()) { | 72 mouse_tab_location.y > region_in_frame.height()) { |
| 70 VLOG(2) << "Mouse outside content region"; | 73 VLOG(2) << "Mouse outside content region"; |
| 71 return false; | 74 return false; |
| 72 } | 75 } |
| 73 | 76 |
| 74 if (![[view_ window] isKeyWindow]) { | 77 if (![[view_ window] isKeyWindow]) { |
| 75 VLOG(2) << "Window currently inactive"; | 78 VLOG(2) << "Window currently inactive"; |
| 76 return false; | 79 return false; |
| 77 } | 80 } |
| 78 | 81 |
| 79 if ((base::TimeTicks::Now() - last_mouse_movement_timestamp_).InSeconds() > | 82 if ((base::TimeTicks::Now() - last_mouse_movement_timestamp_).InSeconds() > |
| 80 MAX_IDLE_TIME_SECONDS && | 83 MAX_IDLE_TIME_SECONDS && |
| 81 std::abs(mouse_window_location.x - last_mouse_location_x_) < | 84 std::abs(mouse_tab_location.x - last_mouse_location_x_) < |
| 82 MIN_MOVEMENT_PIXELS && | 85 MIN_MOVEMENT_PIXELS && |
| 83 std::abs(mouse_window_location.y - last_mouse_location_y_) < | 86 std::abs(mouse_tab_location.y - last_mouse_location_y_) < |
| 84 MIN_MOVEMENT_PIXELS) { | 87 MIN_MOVEMENT_PIXELS) { |
| 85 VLOG(2) << "No mouse movement in a while"; | 88 VLOG(2) << "No mouse movement in a while"; |
| 86 return false; | 89 return false; |
| 87 } | 90 } |
| 88 | 91 |
| 89 // Mouse cursor position within the frame. | 92 // Mouse cursor position within the frame. |
| 90 cursor_position_in_frame_ = | 93 cursor_position_in_frame_ = |
| 91 gfx::Point(region_in_frame.x() + mouse_window_location.x, | 94 gfx::Point(region_in_frame.x() + mouse_tab_location.x, |
| 92 region_in_frame.y() + mouse_window_location.y); | 95 region_in_frame.y() + mouse_tab_location.y); |
| 93 | 96 |
| 94 // Grab system cursor. | 97 // Grab system cursor. |
| 95 NSCursor* nscursor = [NSCursor currentSystemCursor]; | 98 NSCursor* nscursor = [NSCursor currentSystemCursor]; |
| 96 NSPoint nshotspot = [nscursor hotSpot]; | 99 NSPoint nshotspot = [nscursor hotSpot]; |
| 97 NSImage* nsimage = [nscursor image]; | 100 NSImage* nsimage = [nscursor image]; |
| 98 NSSize nssize = [nsimage size]; | 101 NSSize nssize = [nsimage size]; |
| 99 | 102 |
| 100 // The cursor co-ordinates in the window and the video frame co-ordinates are | 103 // The cursor co-ordinates in the window and the video frame co-ordinates are |
| 101 // inverted along y-axis. We render the cursor inverse vertically on the | 104 // inverted along y-axis. We render the cursor inverse vertically on the |
| 102 // frame. Hence the inversion on hotspot offset here. | 105 // frame. Hence the inversion on hotspot offset here. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 116 CGImageGetBitsPerComponent(cg_image) != 8) { | 119 CGImageGetBitsPerComponent(cg_image) != 8) { |
| 117 return false; | 120 return false; |
| 118 } | 121 } |
| 119 | 122 |
| 120 CGDataProviderRef provider = CGImageGetDataProvider(cg_image); | 123 CGDataProviderRef provider = CGImageGetDataProvider(cg_image); |
| 121 CFDataRef image_data_ref = CGDataProviderCopyData(provider); | 124 CFDataRef image_data_ref = CGDataProviderCopyData(provider); |
| 122 if (!image_data_ref) | 125 if (!image_data_ref) |
| 123 return false; | 126 return false; |
| 124 last_cursor_data_.reset(image_data_ref, base::scoped_policy::ASSUME); | 127 last_cursor_data_.reset(image_data_ref, base::scoped_policy::ASSUME); |
| 125 | 128 |
| 126 if (std::abs(mouse_window_location.x - last_mouse_location_x_) > | 129 if (std::abs(mouse_tab_location.x - last_mouse_location_x_) > |
| 127 MIN_MOVEMENT_PIXELS || | 130 MIN_MOVEMENT_PIXELS || |
| 128 std::abs(mouse_window_location.y - last_mouse_location_y_) > | 131 std::abs(mouse_tab_location.y - last_mouse_location_y_) > |
| 129 MIN_MOVEMENT_PIXELS) { | 132 MIN_MOVEMENT_PIXELS) { |
| 130 last_mouse_movement_timestamp_ = base::TimeTicks::Now(); | 133 last_mouse_movement_timestamp_ = base::TimeTicks::Now(); |
| 131 last_mouse_location_x_ = mouse_window_location.x; | 134 last_mouse_location_x_ = mouse_tab_location.x; |
| 132 last_mouse_location_y_ = mouse_window_location.y; | 135 last_mouse_location_y_ = mouse_tab_location.y; |
| 133 } | 136 } |
| 134 return true; | 137 return true; |
| 135 } | 138 } |
| 136 | 139 |
| 137 // Helper function to composite a RGBA cursor bitmap on a YUV420 video frame. | 140 // Helper function to composite a RGBA cursor bitmap on a YUV420 video frame. |
| 138 void CursorRendererMac::RenderOnVideoFrame( | 141 void CursorRendererMac::RenderOnVideoFrame( |
| 139 const scoped_refptr<media::VideoFrame>& target) const { | 142 const scoped_refptr<media::VideoFrame>& target) const { |
| 140 DCHECK(target); | 143 DCHECK(target); |
| 141 DCHECK(last_cursor_data_); | 144 DCHECK(last_cursor_data_); |
| 142 const uint8_t* cursor_data_ = | 145 const uint8_t* cursor_data_ = |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 int color_v = clip_byte( | 183 int color_v = clip_byte( |
| 181 ((color_r * 112 + color_g * -94 + color_b * -18 + 128) >> 8) + 128); | 184 ((color_r * 112 + color_g * -94 + color_b * -18 + 128) >> 8) + 128); |
| 182 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); | 185 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); |
| 183 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); | 186 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); |
| 184 } | 187 } |
| 185 } | 188 } |
| 186 } | 189 } |
| 187 } | 190 } |
| 188 | 191 |
| 189 } // namespace content | 192 } // namespace content |
| OLD | NEW |