Commit dc658038 authored by hubbe's avatar hubbe Committed by Commit bot

Call libyuv for short->half-float conversion

Libyuv has a more optimized version of the half-float conversion code now, and it
will probably become more optimized in the future.

BUG=445071
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel

Review-Url: https://codereview.chromium.org/2389003002
Cr-Commit-Position: refs/heads/master@{#422659}
parent df2d7ede
......@@ -583,6 +583,7 @@ component("cc") {
"//gpu",
"//gpu/command_buffer/client:gles2_interface",
"//media",
"//third_party/libyuv",
"//ui/events:events_base",
"//ui/gfx",
"//ui/gfx/geometry",
......
......@@ -15,6 +15,7 @@ include_rules = [
"+skia/ext",
"+third_party/khronos/GLES2/gl2.h",
"+third_party/khronos/GLES2/gl2ext.h",
"+third_party/libyuv",
"+third_party/skia/include",
"+ui/events/latency_info.h",
"+ui/gfx",
......
......@@ -22,6 +22,7 @@
#include "media/renderers/skcanvas_video_renderer.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/libyuv/include/libyuv.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/gfx/geometry/size_conversions.h"
......@@ -298,19 +299,13 @@ void VideoResourceUpdater::MakeHalfFloats(const uint16_t* src,
int bits_per_channel,
size_t num,
uint16_t* dst) {
// TODO(hubbe): Make AVX and neon versions of this code.
// This magic constant is 2^-112. Multiplying by this
// is the same as subtracting 112 from the exponent, which
// is the difference in exponent bias between 32-bit and
// 16-bit floats. Once we've done this subtraction, we can
// simply extract the low bits of the exponent and the high
// bits of the mantissa from our float and we're done.
float mult = 1.9259299444e-34f / ((1 << bits_per_channel) - 1);
for (size_t i = 0; i < num; i++) {
float value = src[i] * mult;
dst[i] = (*(uint32_t*)&value) >> 13;
}
// Source and dest stride can be zero since we're only copying
// one row at a time.
int stride = 0;
// Maximum value used in |src|.
int max_value = (1 << bits_per_channel) - 1;
int rows = 1;
libyuv::HalfFloatPlane(src, stride, dst, stride, 1.0f / max_value, num, rows);
}
VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
......@@ -495,6 +490,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
resource_provider_->YuvResourceFormat(bits_per_channel));
if (!plane_resource.Matches(video_frame->unique_id(), i)) {
// TODO(hubbe): Move all conversion (and upload?) code to media/.
// We need to transfer data from |video_frame| to the plane resource.
// TODO(reveman): Can use GpuMemoryBuffers here to improve performance.
......
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