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

Unified Diff: webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h

Issue 2933893003: Add reference counter of DxgiDuplicatorController to unload DXGI components (Closed)
Patch Set: Avoid copy-constructor of std::atomic_int Created 3 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h
diff --git a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h
index c9838ad7a1e5d63c918da9b22fcde0c0276d0dac..308b2f3a746500fbacc9e2c2216585abe8168633 100644
--- a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h
+++ b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h
@@ -13,10 +13,11 @@
#include <D3DCommon.h>
-#include <memory>
+#include <atomic>
#include <vector>
#include "webrtc/base/criticalsection.h"
+#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/desktop_capture/desktop_geometry.h"
#include "webrtc/modules/desktop_capture/resolution_change_detector.h"
#include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
@@ -66,12 +67,7 @@ class DxgiDuplicatorController {
};
// Returns the singleton instance of DxgiDuplicatorController.
- static DxgiDuplicatorController* Instance();
-
- // Destructs current instance. We need to make sure COM components and their
- // containers are destructed in correct order. This function calls
- // Deinitialize() to do the real work.
- ~DxgiDuplicatorController();
+ static rtc::scoped_refptr<DxgiDuplicatorController> Instance();
// All the following public functions implicitly call Initialize() function.
@@ -107,16 +103,32 @@ class DxgiDuplicatorController {
// destructing.
friend DxgiFrameContext::~DxgiFrameContext();
+ // scoped_refptr<DxgiDuplicatorController> accesses private AddRef() and
+ // Release() functions.
+ friend class rtc::scoped_refptr<DxgiDuplicatorController>;
+
// A private constructor to ensure consumers to use
// DxgiDuplicatorController::Instance().
DxgiDuplicatorController();
+ // Not implemented: The singleton DxgiDuplicatorController instance should not
+ // be deleted.
+ ~DxgiDuplicatorController();
+
+ // RefCountedInterface implementations.
+ void AddRef();
+ void Release();
+
// Does the real duplication work. Setting |monitor_id| < 0 to capture entire
// screen. This function calls Initialize(). And if the duplication failed,
// this function calls Deinitialize() to ensure the Dxgi components can be
// reinitialized next time.
Result DoDuplicate(DxgiFrame* frame, int monitor_id);
+ // Unload all the DXGI components and releases the resources. This function
+ // wraps Deinitialize() with |lock_|.
+ void Unload();
+
// Unregisters Context from this instance and all DxgiAdapterDuplicator(s)
// it owns.
void Unregister(const Context* const context);
@@ -185,6 +197,9 @@ class DxgiDuplicatorController {
// DxgiAdapterDuplicator and DxgiOutputDuplicator instances are initialized.
void TranslateRect();
+ // The count of references which are now "living".
+ std::atomic_int refcount_;
+
// This lock must be locked whenever accessing any of the following objects.
rtc::CriticalSection lock_;

Powered by Google App Engine
This is Rietveld 408576698