OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 src_plane += src_plane_stride; | 89 src_plane += src_plane_stride; |
90 dest_plane += dest_plane_stride; | 90 dest_plane += dest_plane_stride; |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 // Returns an array of CGWindowID for all the on-screen windows except | 94 // Returns an array of CGWindowID for all the on-screen windows except |
95 // |window_to_exclude|, or NULL if the window is not found or it fails. The | 95 // |window_to_exclude|, or NULL if the window is not found or it fails. The |
96 // caller should release the returned CFArrayRef. | 96 // caller should release the returned CFArrayRef. |
97 CFArrayRef CreateWindowListWithExclusion(CGWindowID window_to_exclude) { | 97 CFArrayRef CreateWindowListWithExclusion(CGWindowID window_to_exclude) { |
98 if (!window_to_exclude) | 98 if (!window_to_exclude) |
99 return nullptr; | 99 return NULL; |
100 | 100 |
101 CFArrayRef all_windows = CGWindowListCopyWindowInfo( | 101 CFArrayRef all_windows = CGWindowListCopyWindowInfo( |
102 kCGWindowListOptionOnScreenOnly, kCGNullWindowID); | 102 kCGWindowListOptionOnScreenOnly, kCGNullWindowID); |
103 if (!all_windows) | 103 if (!all_windows) |
104 return nullptr; | 104 return NULL; |
105 | 105 |
106 CFMutableArrayRef returned_array = | 106 CFMutableArrayRef returned_array = CFArrayCreateMutable( |
107 CFArrayCreateMutable(nullptr, CFArrayGetCount(all_windows), nullptr); | 107 NULL, CFArrayGetCount(all_windows), NULL); |
108 | 108 |
109 bool found = false; | 109 bool found = false; |
110 for (CFIndex i = 0; i < CFArrayGetCount(all_windows); ++i) { | 110 for (CFIndex i = 0; i < CFArrayGetCount(all_windows); ++i) { |
111 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( | 111 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( |
112 CFArrayGetValueAtIndex(all_windows, i)); | 112 CFArrayGetValueAtIndex(all_windows, i)); |
113 | 113 |
114 CFNumberRef id_ref = reinterpret_cast<CFNumberRef>( | 114 CFNumberRef id_ref = reinterpret_cast<CFNumberRef>( |
115 CFDictionaryGetValue(window, kCGWindowNumber)); | 115 CFDictionaryGetValue(window, kCGWindowNumber)); |
116 | 116 |
117 CGWindowID id; | 117 CGWindowID id; |
118 CFNumberGetValue(id_ref, kCFNumberIntType, &id); | 118 CFNumberGetValue(id_ref, kCFNumberIntType, &id); |
119 if (id == window_to_exclude) { | 119 if (id == window_to_exclude) { |
120 found = true; | 120 found = true; |
121 continue; | 121 continue; |
122 } | 122 } |
123 CFArrayAppendValue(returned_array, reinterpret_cast<void *>(id)); | 123 CFArrayAppendValue(returned_array, reinterpret_cast<void *>(id)); |
124 } | 124 } |
125 CFRelease(all_windows); | 125 CFRelease(all_windows); |
126 | 126 |
127 if (!found) { | 127 if (!found) { |
128 CFRelease(returned_array); | 128 CFRelease(returned_array); |
129 returned_array = nullptr; | 129 returned_array = NULL; |
130 } | 130 } |
131 return returned_array; | 131 return returned_array; |
132 } | 132 } |
133 | 133 |
134 // Returns the bounds of |window| in physical pixels, enlarged by a small amount | 134 // Returns the bounds of |window| in physical pixels, enlarged by a small amount |
135 // on four edges to take account of the border/shadow effects. | 135 // on four edges to take account of the border/shadow effects. |
136 DesktopRect GetExcludedWindowPixelBounds(CGWindowID window, | 136 DesktopRect GetExcludedWindowPixelBounds(CGWindowID window, |
137 float dip_to_pixel_scale) { | 137 float dip_to_pixel_scale) { |
138 // The amount of pixels to add to the actual window bounds to take into | 138 // The amount of pixels to add to the actual window bounds to take into |
139 // account of the border/shadow effects. | 139 // account of the border/shadow effects. |
140 static const int kBorderEffectSize = 20; | 140 static const int kBorderEffectSize = 20; |
141 CGRect rect; | 141 CGRect rect; |
142 CGWindowID ids[1]; | 142 CGWindowID ids[1]; |
143 ids[0] = window; | 143 ids[0] = window; |
144 | 144 |
145 CFArrayRef window_id_array = | 145 CFArrayRef window_id_array = |
146 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr); | 146 CFArrayCreate(NULL, reinterpret_cast<const void **>(&ids), 1, NULL); |
147 CFArrayRef window_array = | 147 CFArrayRef window_array = |
148 CGWindowListCreateDescriptionFromArray(window_id_array); | 148 CGWindowListCreateDescriptionFromArray(window_id_array); |
149 | 149 |
150 if (CFArrayGetCount(window_array) > 0) { | 150 if (CFArrayGetCount(window_array) > 0) { |
151 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( | 151 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( |
152 CFArrayGetValueAtIndex(window_array, 0)); | 152 CFArrayGetValueAtIndex(window_array, 0)); |
153 CFDictionaryRef bounds_ref = reinterpret_cast<CFDictionaryRef>( | 153 CFDictionaryRef bounds_ref = reinterpret_cast<CFDictionaryRef>( |
154 CFDictionaryGetValue(window, kCGWindowBounds)); | 154 CFDictionaryGetValue(window, kCGWindowBounds)); |
155 CGRectMakeWithDictionaryRepresentation(bounds_ref, &rect); | 155 CGRectMakeWithDictionaryRepresentation(bounds_ref, &rect); |
156 } | 156 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 const CGRect *rect_array); | 222 const CGRect *rect_array); |
223 static void ScreenRefreshCallback(CGRectCount count, | 223 static void ScreenRefreshCallback(CGRectCount count, |
224 const CGRect *rect_array, | 224 const CGRect *rect_array, |
225 void *user_parameter); | 225 void *user_parameter); |
226 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, | 226 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, |
227 size_t count, | 227 size_t count, |
228 const CGRect *rect_array, | 228 const CGRect *rect_array, |
229 void *user_parameter); | 229 void *user_parameter); |
230 void ReleaseBuffers(); | 230 void ReleaseBuffers(); |
231 | 231 |
232 std::unique_ptr<DesktopFrame> CreateFrame(); | 232 DesktopFrame* CreateFrame(); |
233 | 233 |
234 Callback* callback_ = nullptr; | 234 Callback* callback_; |
235 | 235 |
236 CGLContextObj cgl_context_ = nullptr; | 236 CGLContextObj cgl_context_; |
237 ScopedPixelBufferObject pixel_buffer_object_; | 237 ScopedPixelBufferObject pixel_buffer_object_; |
238 | 238 |
239 // Queue of the frames buffers. | 239 // Queue of the frames buffers. |
240 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; | 240 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; |
241 | 241 |
242 // Current display configuration. | 242 // Current display configuration. |
243 MacDesktopConfiguration desktop_config_; | 243 MacDesktopConfiguration desktop_config_; |
244 | 244 |
245 // Currently selected display, or 0 if the full desktop is selected. On OS X | 245 // Currently selected display, or 0 if the full desktop is selected. On OS X |
246 // 10.6 and before, this is always 0. | 246 // 10.6 and before, this is always 0. |
247 CGDirectDisplayID current_display_ = 0; | 247 CGDirectDisplayID current_display_; |
248 | 248 |
249 // The physical pixel bounds of the current screen. | 249 // The physical pixel bounds of the current screen. |
250 DesktopRect screen_pixel_bounds_; | 250 DesktopRect screen_pixel_bounds_; |
251 | 251 |
252 // The dip to physical pixel scale of the current screen. | 252 // The dip to physical pixel scale of the current screen. |
253 float dip_to_pixel_scale_ = 1.0f; | 253 float dip_to_pixel_scale_; |
254 | 254 |
255 // A thread-safe list of invalid rectangles, and the size of the most | 255 // A thread-safe list of invalid rectangles, and the size of the most |
256 // recently captured screen. | 256 // recently captured screen. |
257 ScreenCapturerHelper helper_; | 257 ScreenCapturerHelper helper_; |
258 | 258 |
259 // Contains an invalid region from the previous capture. | 259 // Contains an invalid region from the previous capture. |
260 DesktopRegion last_invalid_region_; | 260 DesktopRegion last_invalid_region_; |
261 | 261 |
262 // Monitoring display reconfiguration. | 262 // Monitoring display reconfiguration. |
263 rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor_; | 263 rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor_; |
264 | 264 |
265 // Power management assertion to prevent the screen from sleeping. | 265 // Power management assertion to prevent the screen from sleeping. |
266 IOPMAssertionID power_assertion_id_display_ = kIOPMNullAssertionID; | 266 IOPMAssertionID power_assertion_id_display_; |
267 | 267 |
268 // Power management assertion to indicate that the user is active. | 268 // Power management assertion to indicate that the user is active. |
269 IOPMAssertionID power_assertion_id_user_ = kIOPMNullAssertionID; | 269 IOPMAssertionID power_assertion_id_user_; |
270 | 270 |
271 // Dynamically link to deprecated APIs for Mac OS X 10.6 support. | 271 // Dynamically link to deprecated APIs for Mac OS X 10.6 support. |
272 void* app_services_library_ = nullptr; | 272 void* app_services_library_; |
273 CGDisplayBaseAddressFunc cg_display_base_address_ = nullptr; | 273 CGDisplayBaseAddressFunc cg_display_base_address_; |
274 CGDisplayBytesPerRowFunc cg_display_bytes_per_row_ = nullptr; | 274 CGDisplayBytesPerRowFunc cg_display_bytes_per_row_; |
275 CGDisplayBitsPerPixelFunc cg_display_bits_per_pixel_ = nullptr; | 275 CGDisplayBitsPerPixelFunc cg_display_bits_per_pixel_; |
276 void* opengl_library_ = nullptr; | 276 void* opengl_library_; |
277 CGLSetFullScreenFunc cgl_set_full_screen_ = nullptr; | 277 CGLSetFullScreenFunc cgl_set_full_screen_; |
278 | 278 |
279 CGWindowID excluded_window_ = 0; | 279 CGWindowID excluded_window_; |
280 | 280 |
281 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerMac); | 281 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerMac); |
282 }; | 282 }; |
283 | 283 |
284 // DesktopFrame wrapper that flips wrapped frame upside down by inverting | 284 // DesktopFrame wrapper that flips wrapped frame upside down by inverting |
285 // stride. | 285 // stride. |
286 class InvertedDesktopFrame : public DesktopFrame { | 286 class InvertedDesktopFrame : public DesktopFrame { |
287 public: | 287 public: |
288 InvertedDesktopFrame(std::unique_ptr<DesktopFrame> frame) | 288 // Takes ownership of |frame|. |
| 289 InvertedDesktopFrame(DesktopFrame* frame) |
289 : DesktopFrame( | 290 : DesktopFrame( |
290 frame->size(), | 291 frame->size(), -frame->stride(), |
291 -frame->stride(), | |
292 frame->data() + (frame->size().height() - 1) * frame->stride(), | 292 frame->data() + (frame->size().height() - 1) * frame->stride(), |
293 frame->shared_memory()) { | 293 frame->shared_memory()), |
294 original_frame_ = std::move(frame); | 294 original_frame_(frame) { |
295 set_dpi(original_frame_->dpi()); | 295 set_dpi(frame->dpi()); |
296 set_capture_time_ms(original_frame_->capture_time_ms()); | 296 set_capture_time_ms(frame->capture_time_ms()); |
297 mutable_updated_region()->Swap(original_frame_->mutable_updated_region()); | 297 mutable_updated_region()->Swap(frame->mutable_updated_region()); |
298 } | 298 } |
299 virtual ~InvertedDesktopFrame() {} | 299 virtual ~InvertedDesktopFrame() {} |
300 | 300 |
301 private: | 301 private: |
302 std::unique_ptr<DesktopFrame> original_frame_; | 302 std::unique_ptr<DesktopFrame> original_frame_; |
303 | 303 |
304 RTC_DISALLOW_COPY_AND_ASSIGN(InvertedDesktopFrame); | 304 RTC_DISALLOW_COPY_AND_ASSIGN(InvertedDesktopFrame); |
305 }; | 305 }; |
306 | 306 |
307 ScreenCapturerMac::ScreenCapturerMac( | 307 ScreenCapturerMac::ScreenCapturerMac( |
308 rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor) | 308 rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor) |
309 : desktop_config_monitor_(desktop_config_monitor) {} | 309 : callback_(NULL), |
| 310 cgl_context_(NULL), |
| 311 current_display_(0), |
| 312 dip_to_pixel_scale_(1.0f), |
| 313 desktop_config_monitor_(desktop_config_monitor), |
| 314 power_assertion_id_display_(kIOPMNullAssertionID), |
| 315 power_assertion_id_user_(kIOPMNullAssertionID), |
| 316 app_services_library_(NULL), |
| 317 cg_display_base_address_(NULL), |
| 318 cg_display_bytes_per_row_(NULL), |
| 319 cg_display_bits_per_pixel_(NULL), |
| 320 opengl_library_(NULL), |
| 321 cgl_set_full_screen_(NULL), |
| 322 excluded_window_(0) { |
| 323 } |
310 | 324 |
311 ScreenCapturerMac::~ScreenCapturerMac() { | 325 ScreenCapturerMac::~ScreenCapturerMac() { |
312 if (power_assertion_id_display_ != kIOPMNullAssertionID) { | 326 if (power_assertion_id_display_ != kIOPMNullAssertionID) { |
313 IOPMAssertionRelease(power_assertion_id_display_); | 327 IOPMAssertionRelease(power_assertion_id_display_); |
314 power_assertion_id_display_ = kIOPMNullAssertionID; | 328 power_assertion_id_display_ = kIOPMNullAssertionID; |
315 } | 329 } |
316 if (power_assertion_id_user_ != kIOPMNullAssertionID) { | 330 if (power_assertion_id_user_ != kIOPMNullAssertionID) { |
317 IOPMAssertionRelease(power_assertion_id_user_); | 331 IOPMAssertionRelease(power_assertion_id_user_); |
318 power_assertion_id_user_ = kIOPMNullAssertionID; | 332 power_assertion_id_user_ = kIOPMNullAssertionID; |
319 } | 333 } |
(...skipping 12 matching lines...) Expand all Loading... |
332 desktop_config_ = desktop_config_monitor_->desktop_configuration(); | 346 desktop_config_ = desktop_config_monitor_->desktop_configuration(); |
333 desktop_config_monitor_->Unlock(); | 347 desktop_config_monitor_->Unlock(); |
334 ScreenConfigurationChanged(); | 348 ScreenConfigurationChanged(); |
335 return true; | 349 return true; |
336 } | 350 } |
337 | 351 |
338 void ScreenCapturerMac::ReleaseBuffers() { | 352 void ScreenCapturerMac::ReleaseBuffers() { |
339 if (cgl_context_) { | 353 if (cgl_context_) { |
340 pixel_buffer_object_.Release(); | 354 pixel_buffer_object_.Release(); |
341 CGLDestroyContext(cgl_context_); | 355 CGLDestroyContext(cgl_context_); |
342 cgl_context_ = nullptr; | 356 cgl_context_ = NULL; |
343 } | 357 } |
344 // The buffers might be in use by the encoder, so don't delete them here. | 358 // The buffers might be in use by the encoder, so don't delete them here. |
345 // Instead, mark them as "needs update"; next time the buffers are used by | 359 // Instead, mark them as "needs update"; next time the buffers are used by |
346 // the capturer, they will be recreated if necessary. | 360 // the capturer, they will be recreated if necessary. |
347 queue_.Reset(); | 361 queue_.Reset(); |
348 } | 362 } |
349 | 363 |
350 void ScreenCapturerMac::Start(Callback* callback) { | 364 void ScreenCapturerMac::Start(Callback* callback) { |
351 assert(!callback_); | 365 assert(!callback_); |
352 assert(callback); | 366 assert(callback); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(CreateFrame())); | 412 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(CreateFrame())); |
399 | 413 |
400 DesktopFrame* current_frame = queue_.current_frame(); | 414 DesktopFrame* current_frame = queue_.current_frame(); |
401 | 415 |
402 bool flip = false; // GL capturers need flipping. | 416 bool flip = false; // GL capturers need flipping. |
403 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { | 417 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { |
404 // Lion requires us to use their new APIs for doing screen capture. These | 418 // Lion requires us to use their new APIs for doing screen capture. These |
405 // APIS currently crash on 10.6.8 if there is no monitor attached. | 419 // APIS currently crash on 10.6.8 if there is no monitor attached. |
406 if (!CgBlitPostLion(*current_frame, region)) { | 420 if (!CgBlitPostLion(*current_frame, region)) { |
407 desktop_config_monitor_->Unlock(); | 421 desktop_config_monitor_->Unlock(); |
408 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 422 callback_->OnCaptureCompleted(NULL); |
409 return; | 423 return; |
410 } | 424 } |
411 } else if (cgl_context_) { | 425 } else if (cgl_context_) { |
412 flip = true; | 426 flip = true; |
413 if (pixel_buffer_object_.get() != 0) { | 427 if (pixel_buffer_object_.get() != 0) { |
414 GlBlitFast(*current_frame, region); | 428 GlBlitFast(*current_frame, region); |
415 } else { | 429 } else { |
416 // See comment in ScopedPixelBufferObject::Init about why the slow | 430 // See comment in ScopedPixelBufferObject::Init about why the slow |
417 // path is always used on 10.5. | 431 // path is always used on 10.5. |
418 GlBlitSlow(*current_frame); | 432 GlBlitSlow(*current_frame); |
419 } | 433 } |
420 } else { | 434 } else { |
421 CgBlitPreLion(*current_frame, region); | 435 CgBlitPreLion(*current_frame, region); |
422 } | 436 } |
423 | 437 |
424 std::unique_ptr<DesktopFrame> new_frame = queue_.current_frame()->Share(); | 438 DesktopFrame* new_frame = queue_.current_frame()->Share(); |
425 *new_frame->mutable_updated_region() = region; | 439 *new_frame->mutable_updated_region() = region; |
426 | 440 |
427 if (flip) | 441 if (flip) |
428 new_frame.reset(new InvertedDesktopFrame(std::move(new_frame))); | 442 new_frame = new InvertedDesktopFrame(new_frame); |
429 | 443 |
430 helper_.set_size_most_recent(new_frame->size()); | 444 helper_.set_size_most_recent(new_frame->size()); |
431 | 445 |
432 // Signal that we are done capturing data from the display framebuffer, | 446 // Signal that we are done capturing data from the display framebuffer, |
433 // and accessing display structures. | 447 // and accessing display structures. |
434 desktop_config_monitor_->Unlock(); | 448 desktop_config_monitor_->Unlock(); |
435 | 449 |
436 new_frame->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) / | 450 new_frame->set_capture_time_ms( |
437 rtc::kNumNanosecsPerMillisec); | 451 (rtc::TimeNanos() - capture_start_time_nanos) / |
438 callback_->OnCaptureResult(Result::SUCCESS, std::move(new_frame)); | 452 rtc::kNumNanosecsPerMillisec); |
| 453 callback_->OnCaptureCompleted(new_frame); |
439 } | 454 } |
440 | 455 |
441 void ScreenCapturerMac::SetExcludedWindow(WindowId window) { | 456 void ScreenCapturerMac::SetExcludedWindow(WindowId window) { |
442 excluded_window_ = window; | 457 excluded_window_ = window; |
443 } | 458 } |
444 | 459 |
445 bool ScreenCapturerMac::GetScreenList(ScreenList* screens) { | 460 bool ScreenCapturerMac::GetScreenList(ScreenList* screens) { |
446 assert(screens->size() == 0); | 461 assert(screens->size() == 0); |
447 if (rtc::GetOSVersionName() < rtc::kMacOSLion) { | 462 if (rtc::GetOSVersionName() < rtc::kMacOSLion) { |
448 // Single monitor cast is not supported on pre OS X 10.7. | 463 // Single monitor cast is not supported on pre OS X 10.7. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 } | 527 } |
513 } | 528 } |
514 last_invalid_region_ = region; | 529 last_invalid_region_ = region; |
515 | 530 |
516 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 531 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
517 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); | 532 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); |
518 glReadPixels(0, 0, frame.size().width(), frame.size().height(), GL_BGRA, | 533 glReadPixels(0, 0, frame.size().width(), frame.size().height(), GL_BGRA, |
519 GL_UNSIGNED_BYTE, 0); | 534 GL_UNSIGNED_BYTE, 0); |
520 GLubyte* ptr = static_cast<GLubyte*>( | 535 GLubyte* ptr = static_cast<GLubyte*>( |
521 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); | 536 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); |
522 if (!ptr) { | 537 if (ptr == NULL) { |
523 // If the buffer can't be mapped, assume that it's no longer valid and | 538 // If the buffer can't be mapped, assume that it's no longer valid and |
524 // release it. | 539 // release it. |
525 pixel_buffer_object_.Release(); | 540 pixel_buffer_object_.Release(); |
526 } else { | 541 } else { |
527 // Copy only from the dirty rects. Since the image obtained from OpenGL is | 542 // Copy only from the dirty rects. Since the image obtained from OpenGL is |
528 // upside-down we need to do some magic here to copy the correct rectangle. | 543 // upside-down we need to do some magic here to copy the correct rectangle. |
529 const int y_offset = (frame.size().height() - 1) * frame.stride(); | 544 const int y_offset = (frame.size().height() - 1) * frame.stride(); |
530 for (DesktopRegion::Iterator i(region); | 545 for (DesktopRegion::Iterator i(region); |
531 !i.IsAtEnd(); i.Advance()) { | 546 !i.IsAtEnd(); i.Advance()) { |
532 DesktopRect copy_rect = i.rect(); | 547 DesktopRect copy_rect = i.rect(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 } | 635 } |
621 } | 636 } |
622 } | 637 } |
623 | 638 |
624 bool ScreenCapturerMac::CgBlitPostLion(const DesktopFrame& frame, | 639 bool ScreenCapturerMac::CgBlitPostLion(const DesktopFrame& frame, |
625 const DesktopRegion& region) { | 640 const DesktopRegion& region) { |
626 // Copy the entire contents of the previous capture buffer, to capture over. | 641 // Copy the entire contents of the previous capture buffer, to capture over. |
627 // TODO(wez): Get rid of this as per crbug.com/145064, or implement | 642 // TODO(wez): Get rid of this as per crbug.com/145064, or implement |
628 // crbug.com/92354. | 643 // crbug.com/92354. |
629 if (queue_.previous_frame()) { | 644 if (queue_.previous_frame()) { |
630 memcpy(frame.data(), queue_.previous_frame()->data(), | 645 memcpy(frame.data(), |
| 646 queue_.previous_frame()->data(), |
631 frame.stride() * frame.size().height()); | 647 frame.stride() * frame.size().height()); |
632 } | 648 } |
633 | 649 |
634 MacDisplayConfigurations displays_to_capture; | 650 MacDisplayConfigurations displays_to_capture; |
635 if (current_display_) { | 651 if (current_display_) { |
636 // Capturing a single screen. Note that the screen id may change when | 652 // Capturing a single screen. Note that the screen id may change when |
637 // screens are added or removed. | 653 // screens are added or removed. |
638 const MacDisplayConfiguration* config = | 654 const MacDisplayConfiguration* config = |
639 desktop_config_.FindDisplayConfigurationById(current_display_); | 655 desktop_config_.FindDisplayConfigurationById(current_display_); |
640 if (config) { | 656 if (config) { |
(...skipping 28 matching lines...) Expand all Loading... |
669 // Determine which parts of the blit region, if any, lay within the monitor. | 685 // Determine which parts of the blit region, if any, lay within the monitor. |
670 DesktopRegion copy_region = region; | 686 DesktopRegion copy_region = region; |
671 copy_region.IntersectWith(display_bounds); | 687 copy_region.IntersectWith(display_bounds); |
672 if (copy_region.is_empty()) | 688 if (copy_region.is_empty()) |
673 continue; | 689 continue; |
674 | 690 |
675 // Translate the region to be copied into display-relative coordinates. | 691 // Translate the region to be copied into display-relative coordinates. |
676 copy_region.Translate(-display_bounds.left(), -display_bounds.top()); | 692 copy_region.Translate(-display_bounds.left(), -display_bounds.top()); |
677 | 693 |
678 DesktopRect excluded_window_bounds; | 694 DesktopRect excluded_window_bounds; |
679 CGImageRef excluded_image = nullptr; | 695 CGImageRef excluded_image = NULL; |
680 if (excluded_window_ && window_list) { | 696 if (excluded_window_ && window_list) { |
681 // Get the region of the excluded window relative the primary display. | 697 // Get the region of the excluded window relative the primary display. |
682 excluded_window_bounds = GetExcludedWindowPixelBounds( | 698 excluded_window_bounds = GetExcludedWindowPixelBounds( |
683 excluded_window_, display_config.dip_to_pixel_scale); | 699 excluded_window_, display_config.dip_to_pixel_scale); |
684 excluded_window_bounds.IntersectWith(display_config.pixel_bounds); | 700 excluded_window_bounds.IntersectWith(display_config.pixel_bounds); |
685 | 701 |
686 // Create the image under the excluded window first, because it's faster | 702 // Create the image under the excluded window first, because it's faster |
687 // than captuing the whole display. | 703 // than captuing the whole display. |
688 if (!excluded_window_bounds.is_empty()) { | 704 if (!excluded_window_bounds.is_empty()) { |
689 excluded_image = CreateExcludedWindowRegionImage( | 705 excluded_image = CreateExcludedWindowRegionImage( |
690 excluded_window_bounds, display_config.dip_to_pixel_scale, | 706 excluded_window_bounds, display_config.dip_to_pixel_scale, |
691 window_list); | 707 window_list); |
692 } | 708 } |
693 } | 709 } |
694 | 710 |
695 // Create an image containing a snapshot of the display. | 711 // Create an image containing a snapshot of the display. |
696 CGImageRef image = CGDisplayCreateImage(display_config.id); | 712 CGImageRef image = CGDisplayCreateImage(display_config.id); |
697 if (!image) { | 713 if (image == NULL) { |
698 if (excluded_image) | 714 if (excluded_image) |
699 CFRelease(excluded_image); | 715 CFRelease(excluded_image); |
700 continue; | 716 continue; |
701 } | 717 } |
702 | 718 |
703 // Verify that the image has 32-bit depth. | 719 // Verify that the image has 32-bit depth. |
704 int bits_per_pixel = CGImageGetBitsPerPixel(image); | 720 int bits_per_pixel = CGImageGetBitsPerPixel(image); |
705 if (bits_per_pixel / 8 != DesktopFrame::kBytesPerPixel) { | 721 if (bits_per_pixel / 8 != DesktopFrame::kBytesPerPixel) { |
706 LOG(LS_ERROR) << "CGDisplayCreateImage() returned imaged with " | 722 LOG(LS_ERROR) << "CGDisplayCreateImage() returned imaged with " |
707 << bits_per_pixel | 723 << bits_per_pixel |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 // deprecated in 10.6 -- it's still functional there, and it's not used on | 867 // deprecated in 10.6 -- it's still functional there, and it's not used on |
852 // newer OS X versions. | 868 // newer OS X versions. |
853 #pragma clang diagnostic push | 869 #pragma clang diagnostic push |
854 #pragma clang diagnostic ignored "-Wdeprecated-declarations" | 870 #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
855 kCGLPFAFullScreen, | 871 kCGLPFAFullScreen, |
856 #pragma clang diagnostic pop | 872 #pragma clang diagnostic pop |
857 kCGLPFADisplayMask, | 873 kCGLPFADisplayMask, |
858 (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(mainDevice), | 874 (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(mainDevice), |
859 (CGLPixelFormatAttribute)0 | 875 (CGLPixelFormatAttribute)0 |
860 }; | 876 }; |
861 CGLPixelFormatObj pixel_format = nullptr; | 877 CGLPixelFormatObj pixel_format = NULL; |
862 GLint matching_pixel_format_count = 0; | 878 GLint matching_pixel_format_count = 0; |
863 CGLError err = CGLChoosePixelFormat(attributes, | 879 CGLError err = CGLChoosePixelFormat(attributes, |
864 &pixel_format, | 880 &pixel_format, |
865 &matching_pixel_format_count); | 881 &matching_pixel_format_count); |
866 assert(err == kCGLNoError); | 882 assert(err == kCGLNoError); |
867 err = CGLCreateContext(pixel_format, nullptr, &cgl_context_); | 883 err = CGLCreateContext(pixel_format, NULL, &cgl_context_); |
868 assert(err == kCGLNoError); | 884 assert(err == kCGLNoError); |
869 CGLDestroyPixelFormat(pixel_format); | 885 CGLDestroyPixelFormat(pixel_format); |
870 (*cgl_set_full_screen_)(cgl_context_); | 886 (*cgl_set_full_screen_)(cgl_context_); |
871 CGLSetCurrentContext(cgl_context_); | 887 CGLSetCurrentContext(cgl_context_); |
872 | 888 |
873 size_t buffer_size = screen_pixel_bounds_.width() * | 889 size_t buffer_size = screen_pixel_bounds_.width() * |
874 screen_pixel_bounds_.height() * | 890 screen_pixel_bounds_.height() * |
875 sizeof(uint32_t); | 891 sizeof(uint32_t); |
876 pixel_buffer_object_.Init(cgl_context_, buffer_size); | 892 pixel_buffer_object_.Init(cgl_context_, buffer_size); |
877 } | 893 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 void ScreenCapturerMac::ScreenUpdateMoveCallback( | 962 void ScreenCapturerMac::ScreenUpdateMoveCallback( |
947 CGScreenUpdateMoveDelta delta, | 963 CGScreenUpdateMoveDelta delta, |
948 size_t count, | 964 size_t count, |
949 const CGRect* rect_array, | 965 const CGRect* rect_array, |
950 void* user_parameter) { | 966 void* user_parameter) { |
951 ScreenCapturerMac* capturer = | 967 ScreenCapturerMac* capturer = |
952 reinterpret_cast<ScreenCapturerMac*>(user_parameter); | 968 reinterpret_cast<ScreenCapturerMac*>(user_parameter); |
953 capturer->ScreenUpdateMove(delta, count, rect_array); | 969 capturer->ScreenUpdateMove(delta, count, rect_array); |
954 } | 970 } |
955 | 971 |
956 std::unique_ptr<DesktopFrame> ScreenCapturerMac::CreateFrame() { | 972 DesktopFrame* ScreenCapturerMac::CreateFrame() { |
957 std::unique_ptr<DesktopFrame> frame( | 973 std::unique_ptr<DesktopFrame> frame( |
958 new BasicDesktopFrame(screen_pixel_bounds_.size())); | 974 new BasicDesktopFrame(screen_pixel_bounds_.size())); |
| 975 |
959 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_, | 976 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_, |
960 kStandardDPI * dip_to_pixel_scale_)); | 977 kStandardDPI * dip_to_pixel_scale_)); |
961 return frame; | 978 return frame.release(); |
962 } | 979 } |
963 | 980 |
964 } // namespace | 981 } // namespace |
965 | 982 |
966 // static | 983 // static |
967 ScreenCapturer* ScreenCapturer::Create(const DesktopCaptureOptions& options) { | 984 ScreenCapturer* ScreenCapturer::Create(const DesktopCaptureOptions& options) { |
968 if (!options.configuration_monitor()) | 985 if (!options.configuration_monitor()) |
969 return nullptr; | 986 return NULL; |
970 | 987 |
971 std::unique_ptr<ScreenCapturerMac> capturer( | 988 std::unique_ptr<ScreenCapturerMac> capturer( |
972 new ScreenCapturerMac(options.configuration_monitor())); | 989 new ScreenCapturerMac(options.configuration_monitor())); |
973 if (!capturer->Init()) | 990 if (!capturer->Init()) |
974 capturer.reset(); | 991 capturer.reset(); |
975 return capturer.release(); | 992 return capturer.release(); |
976 } | 993 } |
977 | 994 |
978 } // namespace webrtc | 995 } // namespace webrtc |
OLD | NEW |