Replace RWLockWrapper --> Mutex in ScreenCapturerHelper

This class used only write locks, no read locks, and hence a plain
mutex is equivalent.

Bug: webrtc:12102
Change-Id: Ia3e52a5cb2db7679a50fca0ab80f85640876d0bd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/190720
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32539}
diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn
index 956e0a6..fda6cb4 100644
--- a/modules/desktop_capture/BUILD.gn
+++ b/modules/desktop_capture/BUILD.gn
@@ -425,7 +425,6 @@
     "../../rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
     "../../rtc_base:checks",
     "../../rtc_base/synchronization:mutex",
-    "../../rtc_base/synchronization:rw_lock_wrapper",
     "../../rtc_base/system:arch",
     "../../rtc_base/system:rtc_export",
     "../../system_wrappers",
diff --git a/modules/desktop_capture/screen_capturer_helper.cc b/modules/desktop_capture/screen_capturer_helper.cc
index 8a23c88..535b653 100644
--- a/modules/desktop_capture/screen_capturer_helper.cc
+++ b/modules/desktop_capture/screen_capturer_helper.cc
@@ -14,24 +14,19 @@
 
 namespace webrtc {
 
-ScreenCapturerHelper::ScreenCapturerHelper()
-    : invalid_region_lock_(RWLockWrapper::CreateRWLock()), log_grid_size_(0) {}
-
-ScreenCapturerHelper::~ScreenCapturerHelper() {}
-
 void ScreenCapturerHelper::ClearInvalidRegion() {
-  WriteLockScoped scoped_invalid_region_lock(*invalid_region_lock_);
+  MutexLock scoped_invalid_region_lock(&invalid_region_mutex_);
   invalid_region_.Clear();
 }
 
 void ScreenCapturerHelper::InvalidateRegion(
     const DesktopRegion& invalid_region) {
-  WriteLockScoped scoped_invalid_region_lock(*invalid_region_lock_);
+  MutexLock scoped_invalid_region_lock(&invalid_region_mutex_);
   invalid_region_.AddRegion(invalid_region);
 }
 
 void ScreenCapturerHelper::InvalidateScreen(const DesktopSize& size) {
-  WriteLockScoped scoped_invalid_region_lock(*invalid_region_lock_);
+  MutexLock scoped_invalid_region_lock(&invalid_region_mutex_);
   invalid_region_.AddRect(DesktopRect::MakeSize(size));
 }
 
@@ -39,7 +34,7 @@
   invalid_region->Clear();
 
   {
-    WriteLockScoped scoped_invalid_region_lock(*invalid_region_lock_);
+    MutexLock scoped_invalid_region_lock(&invalid_region_mutex_);
     invalid_region->Swap(&invalid_region_);
   }
 
diff --git a/modules/desktop_capture/screen_capturer_helper.h b/modules/desktop_capture/screen_capturer_helper.h
index fc4c85b..3e65860 100644
--- a/modules/desktop_capture/screen_capturer_helper.h
+++ b/modules/desktop_capture/screen_capturer_helper.h
@@ -16,7 +16,8 @@
 #include "modules/desktop_capture/desktop_geometry.h"
 #include "modules/desktop_capture/desktop_region.h"
 #include "rtc_base/constructor_magic.h"
-#include "rtc_base/synchronization/rw_lock_wrapper.h"
+#include "rtc_base/synchronization/mutex.h"
+#include "rtc_base/thread_annotations.h"
 
 namespace webrtc {
 
@@ -26,8 +27,8 @@
 // ScreenCapturer that owns it.
 class ScreenCapturerHelper {
  public:
-  ScreenCapturerHelper();
-  ~ScreenCapturerHelper();
+  ScreenCapturerHelper() = default;
+  ~ScreenCapturerHelper() = default;
 
   // Clear out the invalid region.
   void ClearInvalidRegion();
@@ -69,10 +70,10 @@
   // A region that has been manually invalidated (through InvalidateRegion).
   // These will be returned as dirty_region in the capture data during the next
   // capture.
-  DesktopRegion invalid_region_;
+  DesktopRegion invalid_region_ RTC_GUARDED_BY(invalid_region_mutex_);
 
   // A lock protecting |invalid_region_| across threads.
-  std::unique_ptr<RWLockWrapper> invalid_region_lock_;
+  Mutex invalid_region_mutex_;
 
   // The size of the most recently captured screen.
   DesktopSize size_most_recent_;
@@ -80,7 +81,7 @@
   // The log (base 2) of the size of the grid to which the invalid region is
   // expanded.
   // If the value is <= 0, then the invalid region is not expanded to a grid.
-  int log_grid_size_;
+  int log_grid_size_ = 0;
 
   RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerHelper);
 };