Commit aaa5aed2 authored by Zhaoliang Ma's avatar Zhaoliang Ma Committed by Commit Bot

gl_renderer_copier: Using libyuv::CopyPlane to do an optimised copy of a linear buffer

memcpy is used to copy a linear buffer to the dst linear buffer, this CL
replaces it with libyuv::CopyPlane.

Bug: None
Test: viz_perftests --gtest_filter=GLRendererCopierPerfTest.*
Change-Id: I4892329e243e2fd577a7571f65b7c33a150ff90a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2373947
Commit-Queue: Daniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802020}
parent 101ea13d
...@@ -203,6 +203,7 @@ viz_component("service") { ...@@ -203,6 +203,7 @@ viz_component("service") {
"//services/tracing/public/cpp:cpp", "//services/tracing/public/cpp:cpp",
"//services/viz/privileged/mojom", "//services/viz/privileged/mojom",
"//skia:skcms", "//skia:skcms",
"//third_party/libyuv",
"//ui/display/types", "//ui/display/types",
] ]
......
...@@ -24,6 +24,7 @@ include_rules = [ ...@@ -24,6 +24,7 @@ include_rules = [
"+mojo/public/cpp/system", "+mojo/public/cpp/system",
"+skia", "+skia",
"+third_party/khronos", "+third_party/khronos",
"+third_party/libyuv",
"+third_party/skia", "+third_party/skia",
"+third_party/perfetto/protos/perfetto/trace/track_event", "+third_party/perfetto/protos/perfetto/trace/track_event",
"+ui/latency", "+ui/latency",
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "gpu/command_buffer/common/mailbox.h" #include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/shared_image_usage.h" #include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/common/sync_token.h" #include "gpu/command_buffer/common/sync_token.h"
#include "third_party/libyuv/include/libyuv/planar_functions.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkImageInfo.h"
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
...@@ -422,10 +423,8 @@ class GLPixelBufferRGBAResult : public CopyOutputResult { ...@@ -422,10 +423,8 @@ class GLPixelBufferRGBAResult : public CopyOutputResult {
} }
} }
} else { } else {
for (int y = 0; y < size().height(); libyuv::CopyPlane(src, src_bytes_per_row, dest, stride,
++y, src += src_bytes_per_row, dest += stride) { src_bytes_per_row, size().height());
memcpy(dest, src, src_bytes_per_row);
}
} }
gl->UnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); gl->UnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM);
} }
...@@ -674,31 +673,23 @@ class GLPixelBufferI420Result : public CopyOutputResult { ...@@ -674,31 +673,23 @@ class GLPixelBufferI420Result : public CopyOutputResult {
uint8_t* pixels = pixels_; uint8_t* pixels = pixels_;
if (pixels) { if (pixels) {
const auto CopyPlane = [](const uint8_t* src, int src_stride,
int row_bytes, int num_rows, uint8_t* out,
int out_stride) {
for (int i = 0; i < num_rows;
++i, src += src_stride, out += out_stride) {
memcpy(out, src, row_bytes);
}
};
const int y_stride = aligned_rect_.width(); const int y_stride = aligned_rect_.width();
const gfx::Vector2d result_offset = const gfx::Vector2d result_offset =
rect().OffsetFromOrigin() - aligned_rect_.OffsetFromOrigin(); rect().OffsetFromOrigin() - aligned_rect_.OffsetFromOrigin();
const int y_start_offset = const int y_start_offset =
result_offset.y() * y_stride + result_offset.x(); result_offset.y() * y_stride + result_offset.x();
CopyPlane(pixels + y_start_offset, y_stride, size().width(), libyuv::CopyPlane(pixels + y_start_offset, y_stride, y_out, y_out_stride,
size().height(), y_out, y_out_stride); size().width(), size().height());
pixels += y_stride * aligned_rect_.height(); pixels += y_stride * aligned_rect_.height();
const int chroma_stride = aligned_rect_.width() / 2; const int chroma_stride = aligned_rect_.width() / 2;
const int chroma_start_offset = const int chroma_start_offset =
((result_offset.y() / 2) * chroma_stride) + (result_offset.x() / 2); ((result_offset.y() / 2) * chroma_stride) + (result_offset.x() / 2);
const int chroma_height = (size().height() + 1) / 2; const int chroma_height = (size().height() + 1) / 2;
CopyPlane(pixels + chroma_start_offset, chroma_stride, chroma_row_bytes, libyuv::CopyPlane(pixels + chroma_start_offset, chroma_stride, u_out,
chroma_height, u_out, u_out_stride); u_out_stride, chroma_row_bytes, chroma_height);
pixels += chroma_stride * (aligned_rect_.height() / 2); pixels += chroma_stride * (aligned_rect_.height() / 2);
CopyPlane(pixels + chroma_start_offset, chroma_stride, chroma_row_bytes, libyuv::CopyPlane(pixels + chroma_start_offset, chroma_stride, v_out,
chroma_height, v_out, v_out_stride); v_out_stride, chroma_row_bytes, chroma_height);
} }
return !!pixels; return !!pixels;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment