diff --git a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc index b17c195340..122ad1f6e1 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc @@ -16,6 +16,8 @@ #include #include +#include + #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/modules/desktop_capture/win/dxgi_texture_mapping.h" @@ -274,29 +276,20 @@ void DxgiOutputDuplicator::Setup(Context* context) { RTC_DCHECK(context->updated_region.is_empty()); // Always copy entire monitor during the first Duplicate() function call. context->updated_region.AddRect(desktop_rect_); - for (size_t i = 0; i < contexts_.size(); i++) { - if (contexts_[i] == nullptr) { - contexts_[i] = context; - return; - } - } - + RTC_DCHECK(std::find(contexts_.begin(), contexts_.end(), context) == + contexts_.end()); contexts_.push_back(context); } void DxgiOutputDuplicator::Unregister(const Context* const context) { - for (size_t i = 0; i < contexts_.size(); i++) { - if (contexts_[i] == context) { - contexts_[i] = nullptr; - return; - } - } - - RTC_NOTREACHED(); + auto it = std::find(contexts_.begin(), contexts_.end(), context); + RTC_DCHECK(it != contexts_.end()); + contexts_.erase(it); } void DxgiOutputDuplicator::SpreadContextChange(const Context* const source) { for (Context* dest : contexts_) { + RTC_DCHECK(dest); if (dest != source) { dest->updated_region.AddRegion(source->updated_region); }