Clear DesktopFrame in DxgiFrame to avoid legacy image
Once the buffer returned by Windows is not newly allocated, it may contain
legacy images from previous capturing attempts. This usually is not a problem,
as implementations other than ScreenCapturerWinDirectx paint each pixel on the
frame. But due to the one capturer per monitor design of
ScreenCapturerWinDirectx, part of the frame may not be covered by any
DxgiOutputDuplicator, and cause the legacy image to be shown.
So a very simple fix is to clear the DesktopFrame in DxgiFrame.
BUG=708766
Review-Url: https://codereview.webrtc.org/2827983007
Cr-Original-Commit-Position: refs/heads/master@{#17847}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 9d1ea5cc22f7f8801b6980d524b237088e01f4e1
diff --git a/modules/desktop_capture/win/dxgi_frame.cc b/modules/desktop_capture/win/dxgi_frame.cc
index 0ba678d..6e33b64 100644
--- a/modules/desktop_capture/win/dxgi_frame.cc
+++ b/modules/desktop_capture/win/dxgi_frame.cc
@@ -10,6 +10,8 @@
#include "webrtc/modules/desktop_capture/win/dxgi_frame.h"
+#include <string.h>
+
#include <utility>
#include "webrtc/base/checks.h"
@@ -46,6 +48,13 @@
if (!frame) {
return false;
}
+ // DirectX capturer won't paint each pixel in the frame due to its one
+ // capturer per monitor design. So once the new frame is created, we should
+ // clear it to avoid the legacy image to be remained on it. See
+ // http://crbug.com/708766.
+ RTC_DCHECK_EQ(frame->stride(),
+ frame->size().width() * DesktopFrame::kBytesPerPixel);
+ memset(frame->data(), 0, frame->stride() * frame->size().height());
frame_ = SharedDesktopFrame::Wrap(std::move(frame));
}