From 590b1bad08c6366997fb572d5eb0e4eb40efd6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Thu, 11 Feb 2021 11:52:50 +0100 Subject: [PATCH] Add lock annotations to DxgiDuplicatorController Bug: webrtc:11567 Change-Id: I34b9138cc15cd534059dd64bb990d41174eeef21 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/206471 Reviewed-by: Markus Handell Reviewed-by: Jamie Walch Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#33242} --- .../win/dxgi_duplicator_controller.h | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/modules/desktop_capture/win/dxgi_duplicator_controller.h b/modules/desktop_capture/win/dxgi_duplicator_controller.h index b6f8e78649..ce21e63deb 100644 --- a/modules/desktop_capture/win/dxgi_duplicator_controller.h +++ b/modules/desktop_capture/win/dxgi_duplicator_controller.h @@ -155,65 +155,72 @@ class DxgiDuplicatorController { // If current instance has not been initialized, executes DoInitialize() // function, and returns initialize result. Otherwise directly returns true. // This function may calls Deinitialize() if initialization failed. - bool Initialize(); + bool Initialize() RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Does the real initialization work, this function should only be called in // Initialize(). - bool DoInitialize(); + bool DoInitialize() RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Clears all COM components referred by this instance. So next Duplicate() // call will eventually initialize this instance again. - void Deinitialize(); + void Deinitialize() RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // A helper function to check whether a Context has been expired. - bool ContextExpired(const Context* const context) const; + bool ContextExpired(const Context* const context) const + RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Updates Context if needed. - void Setup(Context* context); + void Setup(Context* context) RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); bool DoDuplicateUnlocked(Context* context, int monitor_id, - SharedDesktopFrame* target); + SharedDesktopFrame* target) + RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Captures all monitors. - bool DoDuplicateAll(Context* context, SharedDesktopFrame* target); + bool DoDuplicateAll(Context* context, SharedDesktopFrame* target) + RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Captures one monitor. bool DoDuplicateOne(Context* context, int monitor_id, - SharedDesktopFrame* target); + SharedDesktopFrame* target) + RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // The minimum GetNumFramesCaptured() returned by |duplicators_|. - int64_t GetNumFramesCaptured() const; + int64_t GetNumFramesCaptured() const RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Returns a DesktopSize to cover entire |desktop_rect_|. - DesktopSize desktop_size() const; + DesktopSize desktop_size() const RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Returns the size of one screen. |id| should be >= 0. If system does not // support DXGI based capturer, or |id| is greater than the total screen count // of all the Duplicators, this function returns an empty DesktopRect. - DesktopRect ScreenRect(int id) const; + DesktopRect ScreenRect(int id) const RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); - int ScreenCountUnlocked() const; + int ScreenCountUnlocked() const RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); - void GetDeviceNamesUnlocked(std::vector* output) const; + void GetDeviceNamesUnlocked(std::vector* output) const + RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Returns the desktop size of the selected screen |monitor_id|. Setting // |monitor_id| < 0 to return the entire screen size. - DesktopSize SelectedDesktopSize(int monitor_id) const; + DesktopSize SelectedDesktopSize(int monitor_id) const + RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Retries DoDuplicateAll() for several times until GetNumFramesCaptured() is // large enough. Returns false if DoDuplicateAll() returns false, or // GetNumFramesCaptured() has never reached the requirement. // According to http://crbug.com/682112, dxgi capturer returns a black frame // during first several capture attempts. - bool EnsureFrameCaptured(Context* context, SharedDesktopFrame* target); + bool EnsureFrameCaptured(Context* context, SharedDesktopFrame* target) + RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // Moves |desktop_rect_| and all underlying |duplicators_|, putting top left // corner of the desktop at (0, 0). This is necessary because DXGI_OUTPUT_DESC // may return negative coordinates. Called from DoInitialize() after all // DxgiAdapterDuplicator and DxgiOutputDuplicator instances are initialized. - void TranslateRect(); + void TranslateRect() RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_); // The count of references which are now "living". std::atomic_int refcount_; @@ -223,14 +230,15 @@ class DxgiDuplicatorController { // A self-incremented integer to compare with the one in Context. It ensures // a Context instance is always initialized after DxgiDuplicatorController. - int identity_ = 0; - DesktopRect desktop_rect_; - DesktopVector dpi_; - std::vector duplicators_; - D3dInfo d3d_info_; - DisplayConfigurationMonitor display_configuration_monitor_; + int identity_ RTC_GUARDED_BY(lock_) = 0; + DesktopRect desktop_rect_ RTC_GUARDED_BY(lock_); + DesktopVector dpi_ RTC_GUARDED_BY(lock_); + std::vector duplicators_ RTC_GUARDED_BY(lock_); + D3dInfo d3d_info_ RTC_GUARDED_BY(lock_); + DisplayConfigurationMonitor display_configuration_monitor_ + RTC_GUARDED_BY(lock_); // A number to indicate how many succeeded duplications have been performed. - uint32_t succeeded_duplications_ = 0; + uint32_t succeeded_duplications_ RTC_GUARDED_BY(lock_) = 0; }; } // namespace webrtc