OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <OpenGL/CGLMacro.h> | 9 #include <OpenGL/CGLMacro.h> |
10 #include <OpenGL/OpenGL.h> | 10 #include <OpenGL/OpenGL.h> |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 bool Init(); | 147 bool Init(); |
148 | 148 |
149 // Capturer interface. | 149 // Capturer interface. |
150 virtual void ScreenConfigurationChanged() OVERRIDE; | 150 virtual void ScreenConfigurationChanged() OVERRIDE; |
151 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | 151 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; |
152 virtual void ClearInvalidRegion() OVERRIDE; | 152 virtual void ClearInvalidRegion() OVERRIDE; |
153 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | 153 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; |
154 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; | 154 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; |
155 virtual void InvalidateFullScreen() OVERRIDE; | 155 virtual void InvalidateFullScreen() OVERRIDE; |
156 virtual void CaptureInvalidRegion(CaptureCompletedCallback* callback) | 156 virtual void CaptureInvalidRegion( |
157 OVERRIDE; | 157 const CaptureCompletedCallback& callback) OVERRIDE; |
158 virtual const SkISize& size_most_recent() const OVERRIDE; | 158 virtual const SkISize& size_most_recent() const OVERRIDE; |
159 | 159 |
160 private: | 160 private: |
161 void GlBlitFast(const VideoFrameBuffer& buffer, const SkRegion& region); | 161 void GlBlitFast(const VideoFrameBuffer& buffer, const SkRegion& region); |
162 void GlBlitSlow(const VideoFrameBuffer& buffer); | 162 void GlBlitSlow(const VideoFrameBuffer& buffer); |
163 void CgBlitPreLion(const VideoFrameBuffer& buffer, const SkRegion& region); | 163 void CgBlitPreLion(const VideoFrameBuffer& buffer, const SkRegion& region); |
164 void CgBlitPostLion(const VideoFrameBuffer& buffer, const SkRegion& region); | 164 void CgBlitPostLion(const VideoFrameBuffer& buffer, const SkRegion& region); |
165 void CaptureRegion(const SkRegion& region, | 165 void CaptureRegion(const SkRegion& region, |
166 CaptureCompletedCallback* callback); | 166 const CaptureCompletedCallback& callback); |
167 | 167 |
168 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); | 168 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); |
169 void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, | 169 void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, |
170 size_t count, | 170 size_t count, |
171 const CGRect *rect_array); | 171 const CGRect *rect_array); |
172 void DisplaysReconfigured(CGDirectDisplayID display, | 172 void DisplaysReconfigured(CGDirectDisplayID display, |
173 CGDisplayChangeSummaryFlags flags); | 173 CGDisplayChangeSummaryFlags flags); |
174 static void ScreenRefreshCallback(CGRectCount count, | 174 static void ScreenRefreshCallback(CGRectCount count, |
175 const CGRect *rect_array, | 175 const CGRect *rect_array, |
176 void *user_parameter); | 176 void *user_parameter); |
177 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, | 177 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, |
178 size_t count, | 178 size_t count, |
179 const CGRect *rect_array, | 179 const CGRect *rect_array, |
180 void *user_parameter); | 180 void *user_parameter); |
181 static void DisplaysReconfiguredCallback(CGDirectDisplayID display, | 181 static void DisplaysReconfiguredCallback(CGDirectDisplayID display, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 339 } |
340 | 340 |
341 void CapturerMac::InvalidateScreen(const SkISize& size) { | 341 void CapturerMac::InvalidateScreen(const SkISize& size) { |
342 helper_.InvalidateScreen(size); | 342 helper_.InvalidateScreen(size); |
343 } | 343 } |
344 | 344 |
345 void CapturerMac::InvalidateFullScreen() { | 345 void CapturerMac::InvalidateFullScreen() { |
346 helper_.InvalidateFullScreen(); | 346 helper_.InvalidateFullScreen(); |
347 } | 347 } |
348 | 348 |
349 void CapturerMac::CaptureInvalidRegion(CaptureCompletedCallback* callback) { | 349 void CapturerMac::CaptureInvalidRegion( |
| 350 const CaptureCompletedCallback& callback) { |
350 // Only allow captures when the display configuration is not occurring. | 351 // Only allow captures when the display configuration is not occurring. |
351 scoped_refptr<CaptureData> data; | 352 scoped_refptr<CaptureData> data; |
352 | 353 |
353 // Critical section shared with DisplaysReconfigured(...). | 354 // Critical section shared with DisplaysReconfigured(...). |
354 CHECK(display_configuration_capture_event_.TimedWait( | 355 CHECK(display_configuration_capture_event_.TimedWait( |
355 base::TimeDelta::FromSeconds(kDisplayReconfigurationTimeoutInSeconds))); | 356 base::TimeDelta::FromSeconds(kDisplayReconfigurationTimeoutInSeconds))); |
356 SkRegion region; | 357 SkRegion region; |
357 helper_.SwapInvalidRegion(®ion); | 358 helper_.SwapInvalidRegion(®ion); |
358 VideoFrameBuffer& current_buffer = buffers_[current_buffer_]; | 359 VideoFrameBuffer& current_buffer = buffers_[current_buffer_]; |
359 current_buffer.Update(); | 360 current_buffer.Update(); |
(...skipping 24 matching lines...) Expand all Loading... |
384 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); | 385 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); |
385 } | 386 } |
386 | 387 |
387 data = new CaptureData(planes, current_buffer.size(), pixel_format()); | 388 data = new CaptureData(planes, current_buffer.size(), pixel_format()); |
388 data->mutable_dirty_region() = region; | 389 data->mutable_dirty_region() = region; |
389 | 390 |
390 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; | 391 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; |
391 helper_.set_size_most_recent(data->size()); | 392 helper_.set_size_most_recent(data->size()); |
392 display_configuration_capture_event_.Signal(); | 393 display_configuration_capture_event_.Signal(); |
393 | 394 |
394 callback->Run(data); | 395 callback.Run(data); |
395 delete callback; | |
396 } | 396 } |
397 | 397 |
398 void CapturerMac::GlBlitFast(const VideoFrameBuffer& buffer, | 398 void CapturerMac::GlBlitFast(const VideoFrameBuffer& buffer, |
399 const SkRegion& region) { | 399 const SkRegion& region) { |
400 const int buffer_height = buffer.size().height(); | 400 const int buffer_height = buffer.size().height(); |
401 const int buffer_width = buffer.size().width(); | 401 const int buffer_width = buffer.size().width(); |
402 | 402 |
403 // Clip to the size of our current screen. | 403 // Clip to the size of our current screen. |
404 SkIRect clip_rect = SkIRect::MakeWH(buffer_width, buffer_height); | 404 SkIRect clip_rect = SkIRect::MakeWH(buffer_width, buffer_height); |
405 if (last_buffer_) { | 405 if (last_buffer_) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 Capturer* Capturer::Create() { | 623 Capturer* Capturer::Create() { |
624 CapturerMac* capturer = new CapturerMac(); | 624 CapturerMac* capturer = new CapturerMac(); |
625 if (!capturer->Init()) { | 625 if (!capturer->Init()) { |
626 delete capturer; | 626 delete capturer; |
627 capturer = NULL; | 627 capturer = NULL; |
628 } | 628 } |
629 return capturer; | 629 return capturer; |
630 } | 630 } |
631 | 631 |
632 } // namespace remoting | 632 } // namespace remoting |
OLD | NEW |