Merge mozilla-central to inbound
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Tue, 25 Jul 2017 17:45:21 +0200
changeset 422004 8b75dcf74517e96f8a2779fe1510c88934749415
parent 422003 2af86a1d1f7a540d8bfab23544373adbc86d9cde (current diff)
parent 421906 32d9d1e81cc607320a36391845917f645f7a7f72 (diff)
child 422005 506c0fc7d2f25e68ba7d000d957db4f9781518f3
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge mozilla-central to inbound
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_mac.mm
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_mac.mm
@@ -24,17 +24,16 @@
 #include <dlfcn.h>
 #include <IOKit/pwr_mgt/IOPMLib.h>
 #include <OpenGL/CGLMacro.h>
 #include <OpenGL/OpenGL.h>
 
 #include "webrtc/base/checks.h"
 #include "webrtc/base/constructormagic.h"
 #include "webrtc/base/macutils.h"
-#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/timeutils.h"
 #include "webrtc/modules/desktop_capture/desktop_capturer.h"
 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
 #include "webrtc/modules/desktop_capture/desktop_frame.h"
 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
 #include "webrtc/modules/desktop_capture/desktop_region.h"
 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h"
 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h"
@@ -327,24 +326,16 @@ class ScreenCapturerMac : public Desktop
                         const CGRect *rect_array);
   static void ScreenRefreshCallback(CGRectCount count,
                                     const CGRect *rect_array,
                                     void *user_parameter);
   static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta,
                                        size_t count,
                                        const CGRect *rect_array,
                                        void *user_parameter);
-  struct ScreenCallbackData {
-    explicit ScreenCallbackData(ScreenCapturerMac* capturer)
-              : capturer(capturer) {}
-    rtc::CriticalSection crit_sect_;
-    ScreenCapturerMac* GUARDED_BY(crit_sect_) capturer;
-  };
-
-  ScreenCallbackData* screen_callback_data_;
 #endif
 
   std::unique_ptr<DesktopFrame> CreateFrame();
 
   Callback* callback_ = nullptr;
 
   CGLContextObj cgl_context_ = nullptr;
   ScopedPixelBufferObject pixel_buffer_object_;
@@ -421,28 +412,26 @@ class InvertedDesktopFrame : public Desk
  private:
   std::unique_ptr<DesktopFrame> original_frame_;
 
   RTC_DISALLOW_COPY_AND_ASSIGN(InvertedDesktopFrame);
 };
 
 ScreenCapturerMac::ScreenCapturerMac(
     rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor)
-    : screen_callback_data_(new ScreenCallbackData(this))
-    , desktop_config_monitor_(desktop_config_monitor) {
+    : desktop_config_monitor_(desktop_config_monitor) {
 #if defined(MAC_OS_X_VERSION_10_8) && \
   (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8)
   display_stream_manager_ = new DisplayStreamManager;
 #endif
 }
 
 ScreenCapturerMac::~ScreenCapturerMac() {
   ReleaseBuffers();
-  rtc::CritScope lock(&screen_callback_data_->crit_sect_);
-  screen_callback_data_->capturer = nullptr;
+  UnregisterRefreshAndMoveHandlers();
 #if defined(MAC_OS_X_VERSION_10_8) && \
   (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8)
   display_stream_manager_->PrepareForSelfDestruction();
 #endif
   dlclose(app_services_library_);
   dlclose(opengl_library_);
 }
 
@@ -1040,24 +1029,24 @@ bool ScreenCapturerMac::RegisterRefreshA
       CFRunLoopSourceRef source =
           CGDisplayStreamGetRunLoopSource(display_stream);
       CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
       display_stream_manager_->SaveStream(unique_id, display_stream);
     }
   }
 #else
  CGError err = CGRegisterScreenRefreshCallback(
-      ScreenCapturerMac::ScreenRefreshCallback, screen_callback_data_);
+      ScreenCapturerMac::ScreenRefreshCallback, this);
   if (err != kCGErrorSuccess) {
     LOG(LS_ERROR) << "CGRegisterScreenRefreshCallback " << err;
     return false;
   }
 
   err = CGScreenRegisterMoveCallback(
-      ScreenCapturerMac::ScreenUpdateMoveCallback, screen_callback_data_);
+      ScreenCapturerMac::ScreenUpdateMoveCallback, this);
   if (err != kCGErrorSuccess) {
     LOG(LS_ERROR) << "CGScreenRegisterMoveCallback " << err;
     return false;
   }
 #endif
 
   return true;
 }
@@ -1104,53 +1093,31 @@ void ScreenCapturerMac::ScreenUpdateMove
 
   // Currently we just treat move events the same as refreshes.
   ScreenRefresh(count, refresh_rects);
 }
 
 void ScreenCapturerMac::ScreenRefreshCallback(CGRectCount count,
                                               const CGRect* rect_array,
                                               void* user_parameter) {
-  ScreenCallbackData* screen_callback_data =
-      reinterpret_cast<ScreenCallbackData*>(user_parameter);
-
-  rtc::CritScope lock(&screen_callback_data->crit_sect_);
-  if (!screen_callback_data->capturer) {
-    CGUnregisterScreenRefreshCallback(
-        ScreenCapturerMac::ScreenRefreshCallback, screen_callback_data);
-    CGScreenUnregisterMoveCallback(
-        ScreenCapturerMac::ScreenUpdateMoveCallback, screen_callback_data);
-    delete screen_callback_data;
-    return;
-  }
-
-  if (screen_callback_data->capturer->screen_pixel_bounds_.is_empty())
-    screen_callback_data->capturer->ScreenConfigurationChanged();
-  screen_callback_data->capturer->ScreenRefresh(count, rect_array);
+  ScreenCapturerMac* capturer =
+      reinterpret_cast<ScreenCapturerMac*>(user_parameter);
+  if (capturer->screen_pixel_bounds_.is_empty())
+    capturer->ScreenConfigurationChanged();
+  capturer->ScreenRefresh(count, rect_array);
 }
 
 void ScreenCapturerMac::ScreenUpdateMoveCallback(
     CGScreenUpdateMoveDelta delta,
     size_t count,
     const CGRect* rect_array,
     void* user_parameter) {
-  ScreenCallbackData* screen_callback_data =
-      reinterpret_cast<ScreenCallbackData*>(user_parameter);
-
-  rtc::CritScope lock(&screen_callback_data->crit_sect_);
-  if (!screen_callback_data->capturer) {
-    CGUnregisterScreenRefreshCallback(
-        ScreenCapturerMac::ScreenRefreshCallback, screen_callback_data);
-    CGScreenUnregisterMoveCallback(
-        ScreenCapturerMac::ScreenUpdateMoveCallback, screen_callback_data);
-    delete screen_callback_data;
-    return;
-  }
-
-  screen_callback_data->capturer->ScreenUpdateMove(delta, count, rect_array);
+  ScreenCapturerMac* capturer =
+      reinterpret_cast<ScreenCapturerMac*>(user_parameter);
+  capturer->ScreenUpdateMove(delta, count, rect_array);
 }
 #endif
 
 std::unique_ptr<DesktopFrame> ScreenCapturerMac::CreateFrame() {
   std::unique_ptr<DesktopFrame> frame(
       new BasicDesktopFrame(screen_pixel_bounds_.size()));
   frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_,
                                kStandardDPI * dip_to_pixel_scale_));