OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/host/capturer.h" | 5 #include "remoting/host/capturer.h" |
6 | 6 |
7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #include <IOKit/pwr_mgt/IOPMLib.h> | 9 #include <IOKit/pwr_mgt/IOPMLib.h> |
10 #include <OpenGL/CGLMacro.h> | 10 #include <OpenGL/CGLMacro.h> |
11 #include <OpenGL/OpenGL.h> | 11 #include <OpenGL/OpenGL.h> |
12 #include <stddef.h> | 12 #include <stddef.h> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/mac/mac_util.h" | 15 #include "base/mac/mac_util.h" |
16 #include "base/mac/scoped_cftyperef.h" | 16 #include "base/mac/scoped_cftyperef.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
| 20 #include "remoting/base/capture_data.h" |
20 #include "remoting/base/util.h" | 21 #include "remoting/base/util.h" |
21 #include "remoting/host/capturer_helper.h" | 22 #include "remoting/host/capturer_helper.h" |
22 | 23 #include "remoting/proto/control.pb.h" |
23 | 24 |
24 namespace remoting { | 25 namespace remoting { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 SkIRect CGRectToSkIRect(const CGRect& rect) { | 29 SkIRect CGRectToSkIRect(const CGRect& rect) { |
29 SkIRect sk_rect = { | 30 SkIRect sk_rect = { |
30 SkScalarRound(rect.origin.x), | 31 SkScalarRound(rect.origin.x), |
31 SkScalarRound(rect.origin.y), | 32 SkScalarRound(rect.origin.y), |
32 SkScalarRound(rect.origin.x + rect.size.width), | 33 SkScalarRound(rect.origin.x + rect.size.width), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 152 |
152 // A class to perform capturing for mac. | 153 // A class to perform capturing for mac. |
153 class CapturerMac : public Capturer { | 154 class CapturerMac : public Capturer { |
154 public: | 155 public: |
155 CapturerMac(); | 156 CapturerMac(); |
156 virtual ~CapturerMac(); | 157 virtual ~CapturerMac(); |
157 | 158 |
158 bool Init(); | 159 bool Init(); |
159 | 160 |
160 // Capturer interface. | 161 // Capturer interface. |
161 virtual void Start() OVERRIDE; | 162 virtual void Start(const CursorShapeChangedCallback& callback) OVERRIDE; |
162 virtual void Stop() OVERRIDE; | 163 virtual void Stop() OVERRIDE; |
163 virtual void ScreenConfigurationChanged() OVERRIDE; | 164 virtual void ScreenConfigurationChanged() OVERRIDE; |
164 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | 165 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; |
165 virtual void ClearInvalidRegion() OVERRIDE; | 166 virtual void ClearInvalidRegion() OVERRIDE; |
166 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | 167 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; |
167 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; | 168 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; |
168 virtual void InvalidateFullScreen() OVERRIDE; | 169 virtual void InvalidateFullScreen() OVERRIDE; |
169 virtual void CaptureInvalidRegion( | 170 virtual void CaptureInvalidRegion( |
170 const CaptureCompletedCallback& callback) OVERRIDE; | 171 const CaptureCompletedCallback& callback) OVERRIDE; |
171 virtual const SkISize& size_most_recent() const OVERRIDE; | 172 virtual const SkISize& size_most_recent() const OVERRIDE; |
(...skipping 27 matching lines...) Expand all Loading... |
199 | 200 |
200 CGLContextObj cgl_context_; | 201 CGLContextObj cgl_context_; |
201 static const int kNumBuffers = 2; | 202 static const int kNumBuffers = 2; |
202 scoped_pixel_buffer_object pixel_buffer_object_; | 203 scoped_pixel_buffer_object pixel_buffer_object_; |
203 VideoFrameBuffer buffers_[kNumBuffers]; | 204 VideoFrameBuffer buffers_[kNumBuffers]; |
204 | 205 |
205 // A thread-safe list of invalid rectangles, and the size of the most | 206 // A thread-safe list of invalid rectangles, and the size of the most |
206 // recently captured screen. | 207 // recently captured screen. |
207 CapturerHelper helper_; | 208 CapturerHelper helper_; |
208 | 209 |
| 210 // Callback notified whenever the cursor shape is changed. |
| 211 CursorShapeChangedCallback cursor_shape_changed_callback_; |
| 212 |
209 // The current buffer with valid data for reading. | 213 // The current buffer with valid data for reading. |
210 int current_buffer_; | 214 int current_buffer_; |
211 | 215 |
212 // The previous buffer into which we captured, or NULL for the first capture | 216 // The previous buffer into which we captured, or NULL for the first capture |
213 // for a particular screen resolution. | 217 // for a particular screen resolution. |
214 uint8* last_buffer_; | 218 uint8* last_buffer_; |
215 | 219 |
216 // Contains an invalid region from the previous capture. | 220 // Contains an invalid region from the previous capture. |
217 SkRegion last_invalid_region_; | 221 SkRegion last_invalid_region_; |
218 | 222 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 cgl_context_ = NULL; | 303 cgl_context_ = NULL; |
300 } | 304 } |
301 // The buffers might be in use by the encoder, so don't delete them here. | 305 // The buffers might be in use by the encoder, so don't delete them here. |
302 // Instead, mark them as "needs update"; next time the buffers are used by | 306 // Instead, mark them as "needs update"; next time the buffers are used by |
303 // the capturer, they will be recreated if necessary. | 307 // the capturer, they will be recreated if necessary. |
304 for (int i = 0; i < kNumBuffers; ++i) { | 308 for (int i = 0; i < kNumBuffers; ++i) { |
305 buffers_[i].set_needs_update(); | 309 buffers_[i].set_needs_update(); |
306 } | 310 } |
307 } | 311 } |
308 | 312 |
309 void CapturerMac::Start() { | 313 void CapturerMac::Start( |
| 314 const CursorShapeChangedCallback& callback) { |
| 315 cursor_shape_changed_callback_ = callback; |
| 316 |
310 // Create power management assertions to wake the display and prevent it from | 317 // Create power management assertions to wake the display and prevent it from |
311 // going to sleep on user idle. | 318 // going to sleep on user idle. |
312 IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, | 319 IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, |
313 kIOPMAssertionLevelOn, | 320 kIOPMAssertionLevelOn, |
314 &power_assertion_id_display_); | 321 &power_assertion_id_display_); |
315 IOPMAssertionCreate(CFSTR("UserIsActive"), | 322 IOPMAssertionCreate(CFSTR("UserIsActive"), |
316 kIOPMAssertionLevelOn, | 323 kIOPMAssertionLevelOn, |
317 &power_assertion_id_user_); | 324 &power_assertion_id_user_); |
318 } | 325 } |
319 | 326 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 Capturer* Capturer::Create() { | 674 Capturer* Capturer::Create() { |
668 CapturerMac* capturer = new CapturerMac(); | 675 CapturerMac* capturer = new CapturerMac(); |
669 if (!capturer->Init()) { | 676 if (!capturer->Init()) { |
670 delete capturer; | 677 delete capturer; |
671 capturer = NULL; | 678 capturer = NULL; |
672 } | 679 } |
673 return capturer; | 680 return capturer; |
674 } | 681 } |
675 | 682 |
676 } // namespace remoting | 683 } // namespace remoting |
OLD | NEW |