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

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: unique_ptr -> scoped_refptr 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..0ad89e840edae9ba3cd6c57c6f88be1ccae9fa53 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"
@@ -39,8 +40,14 @@ namespace webrtc {
// changing. Consumers should retry after a while. (Typically 50 milliseconds,
// but according to hardware performance, this time may vary.)
class DxgiDuplicatorController {
+ private:
+ struct ReferenceReleaser final {
Sergey Ulanov 2017/06/19 18:52:43 I don't think you need this anymore
Hzj_jie 2017/06/19 20:19:46 Done.
+ void operator()(DxgiDuplicatorController* instance) const;
+ };
+
public:
using Context = DxgiFrameContext;
+ using Reference = rtc::scoped_refptr<DxgiDuplicatorController>;
Sergey Ulanov 2017/06/19 18:52:43 I'd prefer to use scoped_refptr<> directly. It won
Hzj_jie 2017/06/19 20:19:47 Done.
// A collection of D3d information we are interested on, which may impact
// capturer performance or reliability.
@@ -65,14 +72,11 @@ class DxgiDuplicatorController {
INVALID_MONITOR_ID,
};
+ // Deprecated: use "GetRefence()" instead.
Sergey Ulanov 2017/06/19 18:52:43 Maybe just update this function to return scoped_r
Hzj_jie 2017/06/19 20:19:46 Done. The only concern is the name "Instance()" do
Do not use (sergeyu) 2017/06/19 20:54:44 I think Instance() is still fine. We still have on
// 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 Reference GetReference();
// All the following public functions implicitly call Initialize() function.
// Detects whether the system supports DXGI based capturer.
@@ -107,16 +111,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::GetReference().
DxgiDuplicatorController();
+ // Not implemented: The singleton DxgiDuplicatorController instance should not
+ // be deleted.
+ ~DxgiDuplicatorController();
+
+ // RefCountedInterface implementations.
+ void AddRef() const;
+ 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 +205,9 @@ class DxgiDuplicatorController {
// DxgiAdapterDuplicator and DxgiOutputDuplicator instances are initialized.
void TranslateRect();
+ // The count of references which are now "living".
+ static 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