Chromium Code Reviews| Index: cc/resources/video_resource_updater_unittest.cc |
| diff --git a/cc/resources/video_resource_updater_unittest.cc b/cc/resources/video_resource_updater_unittest.cc |
| index 938c0fc546bdcaef7301b99a822963244e29274a..475cbc3d74ba540e6014c33847d67c8ae96d5dae 100644 |
| --- a/cc/resources/video_resource_updater_unittest.cc |
| +++ b/cc/resources/video_resource_updater_unittest.cc |
| @@ -504,5 +504,43 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_StreamTexture) { |
| EXPECT_FALSE(context3d_->WasImmutableTextureCreated()); |
| } |
| +namespace { |
|
danakj
2016/09/26 20:35:04
whitespace below this
hubbe
2016/09/26 21:19:36
Done.
|
| +double from_half_float(uint16_t f) { |
|
danakj
2016/09/26 20:35:04
FromHalfFloat
Please a better name than |f|, and
hubbe
2016/09/26 21:19:36
Done.
|
| + if (!f) |
| + return 0.0; |
| + int sign = (f & 0x8000) ? -1 : 1; |
| + int exponent = (f >> 10) & 0x1F; |
| + int fraction = f & 0x3FF; |
| + if (exponent == 0) { |
| + return pow(2.0, -24.0) * fraction; |
| + } else if (exponent == 0x1F) { |
| + return sign * 1000000000000.0; |
| + } else { |
| + return pow(2.0, exponent - 25) * (0x400 + fraction); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +TEST_F(VideoResourceUpdaterTest, MakeHalfFloatTest) { |
| + unsigned short in[1 << 12]; |
| + unsigned short out[1 << 12]; |
| + for (int bits = 9; bits <= 12; bits++) { |
| + size_t num_values = 1 << bits; |
| + for (size_t i = 0; i < num_values; i++) |
| + in[i] = i; |
| + |
| + float mult = 1.0f / (num_values - 1); |
| + |
| + VideoResourceUpdater::MakeHalfFloats(in, mult, num_values, out); |
| + |
| + for (size_t i = 0; i < num_values; i++) { |
| + EXPECT_NEAR(from_half_float(out[i]), in[i] * mult, |
| + from_half_float(out[i] + 1) - from_half_float(out[i])) |
| + << "i = " << i << " bits = " << bits; |
| + } |
| + } |
| +} |
| + |
| } // namespace |
| } // namespace cc |