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

Side by Side Diff: webrtc/modules/desktop_capture/screen_capturer_mac.mm

Issue 1988783003: Use std::unique_ptr<> to pass frame ownership in DesktopCapturer impls. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 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 /* 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
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 NULL; 99 return nullptr;
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 NULL; 104 return nullptr;
105 105
106 CFMutableArrayRef returned_array = CFArrayCreateMutable( 106 CFMutableArrayRef returned_array =
107 NULL, CFArrayGetCount(all_windows), NULL); 107 CFArrayCreateMutable(nullptr, CFArrayGetCount(all_windows), nullptr);
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 = NULL; 129 returned_array = nullptr;
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(NULL, reinterpret_cast<const void **>(&ids), 1, NULL); 146 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr);
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
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 DesktopFrame* CreateFrame(); 232 std::unique_ptr<DesktopFrame> CreateFrame();
233 233
234 Callback* callback_; 234 Callback* callback_ = nullptr;
235 235
236 CGLContextObj cgl_context_; 236 CGLContextObj cgl_context_ = nullptr;
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_; 247 CGDirectDisplayID current_display_ = 0;
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_; 253 float dip_to_pixel_scale_ = 1.0f;
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_; 266 IOPMAssertionID power_assertion_id_display_ = kIOPMNullAssertionID;
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_; 269 IOPMAssertionID power_assertion_id_user_ = kIOPMNullAssertionID;
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_; 272 void* app_services_library_ = nullptr;
273 CGDisplayBaseAddressFunc cg_display_base_address_; 273 CGDisplayBaseAddressFunc cg_display_base_address_ = nullptr;
274 CGDisplayBytesPerRowFunc cg_display_bytes_per_row_; 274 CGDisplayBytesPerRowFunc cg_display_bytes_per_row_ = nullptr;
275 CGDisplayBitsPerPixelFunc cg_display_bits_per_pixel_; 275 CGDisplayBitsPerPixelFunc cg_display_bits_per_pixel_ = nullptr;
276 void* opengl_library_; 276 void* opengl_library_ = nullptr;
277 CGLSetFullScreenFunc cgl_set_full_screen_; 277 CGLSetFullScreenFunc cgl_set_full_screen_ = nullptr;
278 278
279 CGWindowID excluded_window_; 279 CGWindowID excluded_window_ = 0;
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 // Takes ownership of |frame|. 288 InvertedDesktopFrame(std::unique_ptr<DesktopFrame> frame)
289 InvertedDesktopFrame(DesktopFrame* frame)
290 : DesktopFrame( 289 : DesktopFrame(
291 frame->size(), -frame->stride(), 290 frame->size(),
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_(frame) { 294 original_frame_ = std::move(frame);
295 set_dpi(frame->dpi()); 295 set_dpi(original_frame_->dpi());
296 set_capture_time_ms(frame->capture_time_ms()); 296 set_capture_time_ms(original_frame_->capture_time_ms());
297 mutable_updated_region()->Swap(frame->mutable_updated_region()); 297 mutable_updated_region()->Swap(original_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 : callback_(NULL), 309 : desktop_config_monitor_(desktop_config_monitor) {}
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 }
324 310
325 ScreenCapturerMac::~ScreenCapturerMac() { 311 ScreenCapturerMac::~ScreenCapturerMac() {
326 if (power_assertion_id_display_ != kIOPMNullAssertionID) { 312 if (power_assertion_id_display_ != kIOPMNullAssertionID) {
327 IOPMAssertionRelease(power_assertion_id_display_); 313 IOPMAssertionRelease(power_assertion_id_display_);
328 power_assertion_id_display_ = kIOPMNullAssertionID; 314 power_assertion_id_display_ = kIOPMNullAssertionID;
329 } 315 }
330 if (power_assertion_id_user_ != kIOPMNullAssertionID) { 316 if (power_assertion_id_user_ != kIOPMNullAssertionID) {
331 IOPMAssertionRelease(power_assertion_id_user_); 317 IOPMAssertionRelease(power_assertion_id_user_);
332 power_assertion_id_user_ = kIOPMNullAssertionID; 318 power_assertion_id_user_ = kIOPMNullAssertionID;
333 } 319 }
(...skipping 12 matching lines...) Expand all
346 desktop_config_ = desktop_config_monitor_->desktop_configuration(); 332 desktop_config_ = desktop_config_monitor_->desktop_configuration();
347 desktop_config_monitor_->Unlock(); 333 desktop_config_monitor_->Unlock();
348 ScreenConfigurationChanged(); 334 ScreenConfigurationChanged();
349 return true; 335 return true;
350 } 336 }
351 337
352 void ScreenCapturerMac::ReleaseBuffers() { 338 void ScreenCapturerMac::ReleaseBuffers() {
353 if (cgl_context_) { 339 if (cgl_context_) {
354 pixel_buffer_object_.Release(); 340 pixel_buffer_object_.Release();
355 CGLDestroyContext(cgl_context_); 341 CGLDestroyContext(cgl_context_);
356 cgl_context_ = NULL; 342 cgl_context_ = nullptr;
357 } 343 }
358 // The buffers might be in use by the encoder, so don't delete them here. 344 // The buffers might be in use by the encoder, so don't delete them here.
359 // Instead, mark them as "needs update"; next time the buffers are used by 345 // Instead, mark them as "needs update"; next time the buffers are used by
360 // the capturer, they will be recreated if necessary. 346 // the capturer, they will be recreated if necessary.
361 queue_.Reset(); 347 queue_.Reset();
362 } 348 }
363 349
364 void ScreenCapturerMac::Start(Callback* callback) { 350 void ScreenCapturerMac::Start(Callback* callback) {
365 assert(!callback_); 351 assert(!callback_);
366 assert(callback); 352 assert(callback);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(CreateFrame())); 398 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(CreateFrame()));
413 399
414 DesktopFrame* current_frame = queue_.current_frame(); 400 DesktopFrame* current_frame = queue_.current_frame();
415 401
416 bool flip = false; // GL capturers need flipping. 402 bool flip = false; // GL capturers need flipping.
417 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { 403 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) {
418 // Lion requires us to use their new APIs for doing screen capture. These 404 // Lion requires us to use their new APIs for doing screen capture. These
419 // APIS currently crash on 10.6.8 if there is no monitor attached. 405 // APIS currently crash on 10.6.8 if there is no monitor attached.
420 if (!CgBlitPostLion(*current_frame, region)) { 406 if (!CgBlitPostLion(*current_frame, region)) {
421 desktop_config_monitor_->Unlock(); 407 desktop_config_monitor_->Unlock();
422 callback_->OnCaptureCompleted(NULL); 408 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);
423 return; 409 return;
424 } 410 }
425 } else if (cgl_context_) { 411 } else if (cgl_context_) {
426 flip = true; 412 flip = true;
427 if (pixel_buffer_object_.get() != 0) { 413 if (pixel_buffer_object_.get() != 0) {
428 GlBlitFast(*current_frame, region); 414 GlBlitFast(*current_frame, region);
429 } else { 415 } else {
430 // See comment in ScopedPixelBufferObject::Init about why the slow 416 // See comment in ScopedPixelBufferObject::Init about why the slow
431 // path is always used on 10.5. 417 // path is always used on 10.5.
432 GlBlitSlow(*current_frame); 418 GlBlitSlow(*current_frame);
433 } 419 }
434 } else { 420 } else {
435 CgBlitPreLion(*current_frame, region); 421 CgBlitPreLion(*current_frame, region);
436 } 422 }
437 423
438 DesktopFrame* new_frame = queue_.current_frame()->Share(); 424 std::unique_ptr<DesktopFrame> new_frame = queue_.current_frame()->Share();
439 *new_frame->mutable_updated_region() = region; 425 *new_frame->mutable_updated_region() = region;
440 426
441 if (flip) 427 if (flip)
442 new_frame = new InvertedDesktopFrame(new_frame); 428 new_frame.reset(new InvertedDesktopFrame(std::move(new_frame)));
443 429
444 helper_.set_size_most_recent(new_frame->size()); 430 helper_.set_size_most_recent(new_frame->size());
445 431
446 // Signal that we are done capturing data from the display framebuffer, 432 // Signal that we are done capturing data from the display framebuffer,
447 // and accessing display structures. 433 // and accessing display structures.
448 desktop_config_monitor_->Unlock(); 434 desktop_config_monitor_->Unlock();
449 435
450 new_frame->set_capture_time_ms( 436 new_frame->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) /
451 (rtc::TimeNanos() - capture_start_time_nanos) / 437 rtc::kNumNanosecsPerMillisec);
452 rtc::kNumNanosecsPerMillisec); 438 callback_->OnCaptureResult(Result::SUCCESS, std::move(new_frame));
453 callback_->OnCaptureCompleted(new_frame);
454 } 439 }
455 440
456 void ScreenCapturerMac::SetExcludedWindow(WindowId window) { 441 void ScreenCapturerMac::SetExcludedWindow(WindowId window) {
457 excluded_window_ = window; 442 excluded_window_ = window;
458 } 443 }
459 444
460 bool ScreenCapturerMac::GetScreenList(ScreenList* screens) { 445 bool ScreenCapturerMac::GetScreenList(ScreenList* screens) {
461 assert(screens->size() == 0); 446 assert(screens->size() == 0);
462 if (rtc::GetOSVersionName() < rtc::kMacOSLion) { 447 if (rtc::GetOSVersionName() < rtc::kMacOSLion) {
463 // Single monitor cast is not supported on pre OS X 10.7. 448 // Single monitor cast is not supported on pre OS X 10.7.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 512 }
528 } 513 }
529 last_invalid_region_ = region; 514 last_invalid_region_ = region;
530 515
531 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; 516 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_;
532 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); 517 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get());
533 glReadPixels(0, 0, frame.size().width(), frame.size().height(), GL_BGRA, 518 glReadPixels(0, 0, frame.size().width(), frame.size().height(), GL_BGRA,
534 GL_UNSIGNED_BYTE, 0); 519 GL_UNSIGNED_BYTE, 0);
535 GLubyte* ptr = static_cast<GLubyte*>( 520 GLubyte* ptr = static_cast<GLubyte*>(
536 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); 521 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB));
537 if (ptr == NULL) { 522 if (!ptr) {
538 // If the buffer can't be mapped, assume that it's no longer valid and 523 // If the buffer can't be mapped, assume that it's no longer valid and
539 // release it. 524 // release it.
540 pixel_buffer_object_.Release(); 525 pixel_buffer_object_.Release();
541 } else { 526 } else {
542 // Copy only from the dirty rects. Since the image obtained from OpenGL is 527 // Copy only from the dirty rects. Since the image obtained from OpenGL is
543 // upside-down we need to do some magic here to copy the correct rectangle. 528 // upside-down we need to do some magic here to copy the correct rectangle.
544 const int y_offset = (frame.size().height() - 1) * frame.stride(); 529 const int y_offset = (frame.size().height() - 1) * frame.stride();
545 for (DesktopRegion::Iterator i(region); 530 for (DesktopRegion::Iterator i(region);
546 !i.IsAtEnd(); i.Advance()) { 531 !i.IsAtEnd(); i.Advance()) {
547 DesktopRect copy_rect = i.rect(); 532 DesktopRect copy_rect = i.rect();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 620 }
636 } 621 }
637 } 622 }
638 623
639 bool ScreenCapturerMac::CgBlitPostLion(const DesktopFrame& frame, 624 bool ScreenCapturerMac::CgBlitPostLion(const DesktopFrame& frame,
640 const DesktopRegion& region) { 625 const DesktopRegion& region) {
641 // Copy the entire contents of the previous capture buffer, to capture over. 626 // Copy the entire contents of the previous capture buffer, to capture over.
642 // TODO(wez): Get rid of this as per crbug.com/145064, or implement 627 // TODO(wez): Get rid of this as per crbug.com/145064, or implement
643 // crbug.com/92354. 628 // crbug.com/92354.
644 if (queue_.previous_frame()) { 629 if (queue_.previous_frame()) {
645 memcpy(frame.data(), 630 memcpy(frame.data(), queue_.previous_frame()->data(),
646 queue_.previous_frame()->data(),
647 frame.stride() * frame.size().height()); 631 frame.stride() * frame.size().height());
648 } 632 }
649 633
650 MacDisplayConfigurations displays_to_capture; 634 MacDisplayConfigurations displays_to_capture;
651 if (current_display_) { 635 if (current_display_) {
652 // Capturing a single screen. Note that the screen id may change when 636 // Capturing a single screen. Note that the screen id may change when
653 // screens are added or removed. 637 // screens are added or removed.
654 const MacDisplayConfiguration* config = 638 const MacDisplayConfiguration* config =
655 desktop_config_.FindDisplayConfigurationById(current_display_); 639 desktop_config_.FindDisplayConfigurationById(current_display_);
656 if (config) { 640 if (config) {
(...skipping 28 matching lines...) Expand all
685 // Determine which parts of the blit region, if any, lay within the monitor. 669 // Determine which parts of the blit region, if any, lay within the monitor.
686 DesktopRegion copy_region = region; 670 DesktopRegion copy_region = region;
687 copy_region.IntersectWith(display_bounds); 671 copy_region.IntersectWith(display_bounds);
688 if (copy_region.is_empty()) 672 if (copy_region.is_empty())
689 continue; 673 continue;
690 674
691 // Translate the region to be copied into display-relative coordinates. 675 // Translate the region to be copied into display-relative coordinates.
692 copy_region.Translate(-display_bounds.left(), -display_bounds.top()); 676 copy_region.Translate(-display_bounds.left(), -display_bounds.top());
693 677
694 DesktopRect excluded_window_bounds; 678 DesktopRect excluded_window_bounds;
695 CGImageRef excluded_image = NULL; 679 CGImageRef excluded_image = nullptr;
696 if (excluded_window_ && window_list) { 680 if (excluded_window_ && window_list) {
697 // Get the region of the excluded window relative the primary display. 681 // Get the region of the excluded window relative the primary display.
698 excluded_window_bounds = GetExcludedWindowPixelBounds( 682 excluded_window_bounds = GetExcludedWindowPixelBounds(
699 excluded_window_, display_config.dip_to_pixel_scale); 683 excluded_window_, display_config.dip_to_pixel_scale);
700 excluded_window_bounds.IntersectWith(display_config.pixel_bounds); 684 excluded_window_bounds.IntersectWith(display_config.pixel_bounds);
701 685
702 // Create the image under the excluded window first, because it's faster 686 // Create the image under the excluded window first, because it's faster
703 // than captuing the whole display. 687 // than captuing the whole display.
704 if (!excluded_window_bounds.is_empty()) { 688 if (!excluded_window_bounds.is_empty()) {
705 excluded_image = CreateExcludedWindowRegionImage( 689 excluded_image = CreateExcludedWindowRegionImage(
706 excluded_window_bounds, display_config.dip_to_pixel_scale, 690 excluded_window_bounds, display_config.dip_to_pixel_scale,
707 window_list); 691 window_list);
708 } 692 }
709 } 693 }
710 694
711 // Create an image containing a snapshot of the display. 695 // Create an image containing a snapshot of the display.
712 CGImageRef image = CGDisplayCreateImage(display_config.id); 696 CGImageRef image = CGDisplayCreateImage(display_config.id);
713 if (image == NULL) { 697 if (!image) {
714 if (excluded_image) 698 if (excluded_image)
715 CFRelease(excluded_image); 699 CFRelease(excluded_image);
716 continue; 700 continue;
717 } 701 }
718 702
719 // Verify that the image has 32-bit depth. 703 // Verify that the image has 32-bit depth.
720 int bits_per_pixel = CGImageGetBitsPerPixel(image); 704 int bits_per_pixel = CGImageGetBitsPerPixel(image);
721 if (bits_per_pixel / 8 != DesktopFrame::kBytesPerPixel) { 705 if (bits_per_pixel / 8 != DesktopFrame::kBytesPerPixel) {
722 LOG(LS_ERROR) << "CGDisplayCreateImage() returned imaged with " 706 LOG(LS_ERROR) << "CGDisplayCreateImage() returned imaged with "
723 << bits_per_pixel 707 << bits_per_pixel
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 // deprecated in 10.6 -- it's still functional there, and it's not used on 851 // deprecated in 10.6 -- it's still functional there, and it's not used on
868 // newer OS X versions. 852 // newer OS X versions.
869 #pragma clang diagnostic push 853 #pragma clang diagnostic push
870 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 854 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
871 kCGLPFAFullScreen, 855 kCGLPFAFullScreen,
872 #pragma clang diagnostic pop 856 #pragma clang diagnostic pop
873 kCGLPFADisplayMask, 857 kCGLPFADisplayMask,
874 (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(mainDevice), 858 (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(mainDevice),
875 (CGLPixelFormatAttribute)0 859 (CGLPixelFormatAttribute)0
876 }; 860 };
877 CGLPixelFormatObj pixel_format = NULL; 861 CGLPixelFormatObj pixel_format = nullptr;
878 GLint matching_pixel_format_count = 0; 862 GLint matching_pixel_format_count = 0;
879 CGLError err = CGLChoosePixelFormat(attributes, 863 CGLError err = CGLChoosePixelFormat(attributes,
880 &pixel_format, 864 &pixel_format,
881 &matching_pixel_format_count); 865 &matching_pixel_format_count);
882 assert(err == kCGLNoError); 866 assert(err == kCGLNoError);
883 err = CGLCreateContext(pixel_format, NULL, &cgl_context_); 867 err = CGLCreateContext(pixel_format, nullptr, &cgl_context_);
884 assert(err == kCGLNoError); 868 assert(err == kCGLNoError);
885 CGLDestroyPixelFormat(pixel_format); 869 CGLDestroyPixelFormat(pixel_format);
886 (*cgl_set_full_screen_)(cgl_context_); 870 (*cgl_set_full_screen_)(cgl_context_);
887 CGLSetCurrentContext(cgl_context_); 871 CGLSetCurrentContext(cgl_context_);
888 872
889 size_t buffer_size = screen_pixel_bounds_.width() * 873 size_t buffer_size = screen_pixel_bounds_.width() *
890 screen_pixel_bounds_.height() * 874 screen_pixel_bounds_.height() *
891 sizeof(uint32_t); 875 sizeof(uint32_t);
892 pixel_buffer_object_.Init(cgl_context_, buffer_size); 876 pixel_buffer_object_.Init(cgl_context_, buffer_size);
893 } 877 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 void ScreenCapturerMac::ScreenUpdateMoveCallback( 946 void ScreenCapturerMac::ScreenUpdateMoveCallback(
963 CGScreenUpdateMoveDelta delta, 947 CGScreenUpdateMoveDelta delta,
964 size_t count, 948 size_t count,
965 const CGRect* rect_array, 949 const CGRect* rect_array,
966 void* user_parameter) { 950 void* user_parameter) {
967 ScreenCapturerMac* capturer = 951 ScreenCapturerMac* capturer =
968 reinterpret_cast<ScreenCapturerMac*>(user_parameter); 952 reinterpret_cast<ScreenCapturerMac*>(user_parameter);
969 capturer->ScreenUpdateMove(delta, count, rect_array); 953 capturer->ScreenUpdateMove(delta, count, rect_array);
970 } 954 }
971 955
972 DesktopFrame* ScreenCapturerMac::CreateFrame() { 956 std::unique_ptr<DesktopFrame> ScreenCapturerMac::CreateFrame() {
973 std::unique_ptr<DesktopFrame> frame( 957 std::unique_ptr<DesktopFrame> frame(
974 new BasicDesktopFrame(screen_pixel_bounds_.size())); 958 new BasicDesktopFrame(screen_pixel_bounds_.size()));
975
976 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_, 959 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_,
977 kStandardDPI * dip_to_pixel_scale_)); 960 kStandardDPI * dip_to_pixel_scale_));
978 return frame.release(); 961 return frame;
979 } 962 }
980 963
981 } // namespace 964 } // namespace
982 965
983 // static 966 // static
984 ScreenCapturer* ScreenCapturer::Create(const DesktopCaptureOptions& options) { 967 ScreenCapturer* ScreenCapturer::Create(const DesktopCaptureOptions& options) {
985 if (!options.configuration_monitor()) 968 if (!options.configuration_monitor())
986 return NULL; 969 return nullptr;
987 970
988 std::unique_ptr<ScreenCapturerMac> capturer( 971 std::unique_ptr<ScreenCapturerMac> capturer(
989 new ScreenCapturerMac(options.configuration_monitor())); 972 new ScreenCapturerMac(options.configuration_monitor()));
990 if (!capturer->Init()) 973 if (!capturer->Init())
991 capturer.reset(); 974 capturer.reset();
992 return capturer.release(); 975 return capturer.release();
993 } 976 }
994 977
995 } // namespace webrtc 978 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698