modules/desktop_capture: replace memcpy with libyuv::CopyPlane

According to our previous data from trace_event with using direct memcpy
and libyuv::CopyPlane on chromebook atlas, the average cpu duration is
0.624ms and 0.541ms, so using libyuv::CopyPlane is 13.3% faster than
direct memcpy.

Bug: webrtc:12496
Change-Id: I1c41424b402a7eec34052c67933f2e88eaf0a8f4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/196485
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33344}
This commit is contained in:
Zhaoliang Ma 2020-12-04 21:34:26 +08:00 committed by Commit Bot
parent 258e9899f4
commit 5cfcf2282a
2 changed files with 8 additions and 10 deletions

View File

@ -44,6 +44,7 @@ rtc_library("primitives") {
"../../api:scoped_refptr",
"../../rtc_base:checks",
"../../rtc_base/system:rtc_export",
"//third_party/libyuv",
]
if (!build_with_mozilla) {

View File

@ -19,6 +19,7 @@
#include "modules/desktop_capture/desktop_capture_types.h"
#include "modules/desktop_capture/desktop_geometry.h"
#include "rtc_base/checks.h"
#include "third_party/libyuv/include/libyuv/planar_functions.h"
namespace webrtc {
@ -44,11 +45,9 @@ void DesktopFrame::CopyPixelsFrom(const uint8_t* src_buffer,
RTC_CHECK(DesktopRect::MakeSize(size()).ContainsRect(dest_rect));
uint8_t* dest = GetFrameDataAtPos(dest_rect.top_left());
for (int y = 0; y < dest_rect.height(); ++y) {
memcpy(dest, src_buffer, DesktopFrame::kBytesPerPixel * dest_rect.width());
src_buffer += src_stride;
dest += stride();
}
libyuv::CopyPlane(src_buffer, src_stride, dest, stride(),
DesktopFrame::kBytesPerPixel * dest_rect.width(),
dest_rect.height());
}
void DesktopFrame::CopyPixelsFrom(const DesktopFrame& src_frame,
@ -158,11 +157,9 @@ BasicDesktopFrame::~BasicDesktopFrame() {
// static
DesktopFrame* BasicDesktopFrame::CopyOf(const DesktopFrame& frame) {
DesktopFrame* result = new BasicDesktopFrame(frame.size());
for (int y = 0; y < frame.size().height(); ++y) {
memcpy(result->data() + y * result->stride(),
frame.data() + y * frame.stride(),
frame.size().width() * kBytesPerPixel);
}
libyuv::CopyPlane(result->data(), result->stride(), frame.data(),
frame.stride(), frame.size().width() * kBytesPerPixel,
frame.size().height());
result->CopyFrameInfoFrom(frame);
return result;
}