Remove unnecessary memset to DesktopFrame

With a recent change, the webrtc::DesktopFrame is created and
initialized with 0. So it's not necessary to call memset() to
the frame again any more.

See https://webrtc-review.googlesource.com/c/src/+/97184/

Bug: webrtc:9703
Change-Id: I27d096058ead075765f4c49bf60cb8d725da1afd
Reviewed-on: https://webrtc-review.googlesource.com/c/120700
Commit-Queue: Brave Yao <braveyao@webrtc.org>
Reviewed-by: Brave Yao <braveyao@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26504}
This commit is contained in:
Julien Isorce
2019-01-31 15:55:26 -08:00
committed by Commit Bot
parent f3e9abf6b3
commit 831bd96138
5 changed files with 27 additions and 13 deletions

View File

@ -64,4 +64,17 @@ TEST(CroppedDesktopFrameTest, SetTopLeft) {
ASSERT_EQ(frame->top_left().y(), 203);
}
TEST(CroppedDesktopFrameTest, InitializedWithZeros) {
std::unique_ptr<DesktopFrame> frame = CreateTestFrame();
const DesktopVector frame_origin = frame->top_left();
const DesktopSize frame_size = frame->size();
std::unique_ptr<DesktopFrame> cropped = CreateCroppedDesktopFrame(
std::move(frame), DesktopRect::MakeOriginSize(frame_origin, frame_size));
for (int j = 0; j < cropped->size().height(); ++j) {
for (int i = 0; i < cropped->stride(); ++i) {
ASSERT_EQ(cropped->data()[i + j * cropped->stride()], 0);
}
}
}
} // namespace webrtc

View File

@ -126,7 +126,6 @@ class FakeMouseMonitor : public MouseCursorMonitor {
std::unique_ptr<DesktopFrame> image(
new BasicDesktopFrame(DesktopSize(kCursorWidth, kCursorHeight)));
uint32_t* data = reinterpret_cast<uint32_t*>(image->data());
memset(data, 0, image->stride() * kCursorHeight);
// Set four pixels near the hotspot and leave all other blank.
for (int y = 0; y < kTestCursorSize; ++y) {

View File

@ -138,6 +138,7 @@ class RTC_EXPORT DesktopFrame {
// A DesktopFrame that stores data in the heap.
class RTC_EXPORT BasicDesktopFrame : public DesktopFrame {
public:
// The entire data buffer used for the frame is initialized with zeros.
explicit BasicDesktopFrame(DesktopSize size);
~BasicDesktopFrame() override;

View File

@ -41,20 +41,22 @@ bool DxgiFrame::Prepare(DesktopSize size, DesktopCapturer::SourceId source_id) {
std::unique_ptr<DesktopFrame> frame;
if (factory_) {
frame = SharedMemoryDesktopFrame::Create(size, factory_);
} else {
frame.reset(new BasicDesktopFrame(size));
}
if (!frame) {
RTC_LOG(LS_WARNING) << "DxgiFrame cannot create a new DesktopFrame.";
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
// 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());
} else {
frame.reset(new BasicDesktopFrame(size));
}
frame_ = SharedDesktopFrame::Wrap(std::move(frame));
}

View File

@ -249,7 +249,6 @@ void WindowCapturerWin::CaptureFrame() {
!window_capture_helper_.IsWindowVisibleOnCurrentDesktop(window_)) {
std::unique_ptr<DesktopFrame> frame(
new BasicDesktopFrame(DesktopSize(1, 1)));
memset(frame->data(), 0, frame->stride() * frame->size().height());
previous_size_ = frame->size();
window_size_map_[window_] = previous_size_;