Crash in DirectX capturer

A tiny but critical change to avoid a crash failure in DirectX capturer.
A good news is this failure is caught by ScreenCapturer integration tests.

BUG=314516

Review-Url: https://codereview.webrtc.org/2494893002
Cr-Commit-Position: refs/heads/master@{#15046}
This commit is contained in:
zijiehe 2016-11-11 16:54:14 -08:00 committed by Commit bot
parent c9a6e4a67e
commit 3074096816

View File

@ -16,6 +16,8 @@
#include <DXGIFormat.h>
#include <Windows.h>
#include <algorithm>
#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);
}