Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(979)

Unified Diff: cc/resources/video_resource_updater.cc

Issue 2763503002: Move HalfFloatMaker to media (Closed)
Patch Set: Added math.h in half_float_maker_unittest.cc for POW undefined error Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/resources/video_resource_updater.h ('k') | cc/resources/video_resource_updater_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/video_resource_updater.cc
diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc
index 2ad91ae0674558bb9ad7f5963aa68c50d6554c38..fa01b03ad49ad1accbbd3ab44f8d0f2e6ff266e3 100644
--- a/cc/resources/video_resource_updater.cc
+++ b/cc/resources/video_resource_updater.cc
@@ -21,6 +21,7 @@
#include "gpu/command_buffer/client/gles2_interface.h"
#include "media/base/video_frame.h"
#include "media/renderers/skcanvas_video_renderer.h"
+#include "media/video/half_float_maker.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/libyuv/include/libyuv.h"
@@ -298,89 +299,6 @@ static gfx::Size SoftwarePlaneDimension(media::VideoFrame* input_frame,
return gfx::Size(plane_width, plane_height);
}
-namespace {
-// By OR-ing with 0x3800, 10-bit numbers become half-floats in the
-// range [0.5..1) and 9-bit numbers get the range [0.5..0.75).
-//
-// Half-floats are evaluated as:
-// float value = pow(2.0, exponent - 25) * (0x400 + fraction);
-//
-// In our case the exponent is 14 (since we or with 0x3800) and
-// pow(2.0, 14-25) * 0x400 evaluates to 0.5 (our offset) and
-// pow(2.0, 14-25) * fraction is [0..0.49951171875] for 10-bit and
-// [0..0.24951171875] for 9-bit.
-//
-// https://en.wikipedia.org/wiki/Half-precision_floating-point_format
-class HalfFloatMaker_xor : public VideoResourceUpdater::HalfFloatMaker {
- public:
- explicit HalfFloatMaker_xor(int bits_per_channel)
- : bits_per_channel_(bits_per_channel) {}
- float Offset() const override { return 0.5; }
- float Multiplier() const override {
- int max_input_value = (1 << bits_per_channel_) - 1;
- // 2 << 11 = 2048 would be 1.0 with our exponent.
- return 2048.0 / max_input_value;
- }
- void MakeHalfFloats(const uint16_t* src, size_t num, uint16_t* dst) override {
- // Micro-benchmarking indicates that the compiler does
- // a good enough job of optimizing this loop that trying
- // to manually operate on one uint64 at a time is not
- // actually helpful.
- // Note to future optimizers: Benchmark your optimizations!
- for (size_t i = 0; i < num; i++)
- dst[i] = src[i] | 0x3800;
- }
-
- private:
- int bits_per_channel_;
-};
-
-class HalfFloatMaker_libyuv : public VideoResourceUpdater::HalfFloatMaker {
- public:
- explicit HalfFloatMaker_libyuv(int bits_per_channel) {
- int max_value = (1 << bits_per_channel) - 1;
- // For less than 15 bits, we can give libyuv a multiplier of
- // 1.0, which is faster on some platforms. If bits is 16 or larger,
- // a multiplier of 1.0 would cause overflows. However, a multiplier
- // of 1/max_value would cause subnormal floats, which perform
- // very poorly on some platforms.
- if (bits_per_channel <= 15) {
- libyuv_multiplier_ = 1.0f;
- } else {
- // This multiplier makes sure that we avoid subnormal values.
- libyuv_multiplier_ = 1.0f / 4096.0f;
- }
- resource_multiplier_ = 1.0f / libyuv_multiplier_ / max_value;
- }
- float Offset() const override { return 0.0f; }
- float Multiplier() const override { return resource_multiplier_; }
- void MakeHalfFloats(const uint16_t* src, size_t num, uint16_t* dst) override {
- // Source and dest stride can be zero since we're only copying
- // one row at a time.
- int stride = 0;
- int rows = 1;
- libyuv::HalfFloatPlane(src, stride, dst, stride, libyuv_multiplier_, num,
- rows);
- }
-
- private:
- float libyuv_multiplier_;
- float resource_multiplier_;
-};
-
-} // namespace
-
-std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>
-VideoResourceUpdater::NewHalfFloatMaker(int bits_per_channel) {
- if (bits_per_channel < 11) {
- return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>(
- new HalfFloatMaker_xor(bits_per_channel));
- } else {
- return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>(
- new HalfFloatMaker_libyuv(bits_per_channel));
- }
-}
-
VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
scoped_refptr<media::VideoFrame> video_frame) {
TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes");
@@ -518,10 +436,11 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
return external_resources;
}
- std::unique_ptr<HalfFloatMaker> half_float_maker;
+ std::unique_ptr<media::HalfFloatMaker> half_float_maker;
if (resource_provider_->YuvResourceFormat(bits_per_channel) ==
LUMINANCE_F16) {
- half_float_maker = NewHalfFloatMaker(bits_per_channel);
+ half_float_maker =
+ media::HalfFloatMaker::NewHalfFloatMaker(bits_per_channel);
external_resources.offset = half_float_maker->Offset();
external_resources.multiplier = half_float_maker->Multiplier();
}
@@ -533,7 +452,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/.
+ // TODO(hubbe): Move 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.
« no previous file with comments | « cc/resources/video_resource_updater.h ('k') | cc/resources/video_resource_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698