| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 EXPECT_EQ(1, context3d_->TextureCreationCount()); | 512 EXPECT_EQ(1, context3d_->TextureCreationCount()); |
| 513 | 513 |
| 514 // The texture copy path requires the use of CopyTextureCHROMIUM, which | 514 // The texture copy path requires the use of CopyTextureCHROMIUM, which |
| 515 // enforces that the target texture not be immutable, as it may need | 515 // enforces that the target texture not be immutable, as it may need |
| 516 // to alter the storage of the texture. Therefore, this test asserts | 516 // to alter the storage of the texture. Therefore, this test asserts |
| 517 // that an immutable texture wasn't created by glTexStorage2DEXT, when | 517 // that an immutable texture wasn't created by glTexStorage2DEXT, when |
| 518 // that extension is supported. | 518 // that extension is supported. |
| 519 EXPECT_FALSE(context3d_->WasImmutableTextureCreated()); | 519 EXPECT_FALSE(context3d_->WasImmutableTextureCreated()); |
| 520 } | 520 } |
| 521 | 521 |
| 522 namespace { | |
| 523 | |
| 524 // Convert an IEEE 754 half-float to a double value | |
| 525 // that we can do math on. | |
| 526 double FromHalfFloat(uint16_t half_float) { | |
| 527 if (!half_float) | |
| 528 return 0.0; | |
| 529 int sign = (half_float & 0x8000) ? -1 : 1; | |
| 530 int exponent = (half_float >> 10) & 0x1F; | |
| 531 int fraction = half_float & 0x3FF; | |
| 532 if (exponent == 0) { | |
| 533 return pow(2.0, -24.0) * fraction; | |
| 534 } else if (exponent == 0x1F) { | |
| 535 return sign * 1000000000000.0; | |
| 536 } else { | |
| 537 return pow(2.0, exponent - 25) * (0x400 + fraction); | |
| 538 } | |
| 539 } | |
| 540 | |
| 541 } // namespace | |
| 542 | |
| 543 TEST_F(VideoResourceUpdaterTest, MakeHalfFloatTest) { | |
| 544 unsigned short integers[1 << 16]; | |
| 545 unsigned short half_floats[1 << 16]; | |
| 546 for (int bits = 9; bits <= 16; bits++) { | |
| 547 std::unique_ptr<VideoResourceUpdater::HalfFloatMaker> half_float_maker; | |
| 548 half_float_maker = VideoResourceUpdater::NewHalfFloatMaker(bits); | |
| 549 int num_values = 1 << bits; | |
| 550 for (int i = 0; i < num_values; i++) | |
| 551 integers[i] = i; | |
| 552 | |
| 553 half_float_maker->MakeHalfFloats(integers, num_values, half_floats); | |
| 554 // Multiplier to converting integers to 0.0..1.0 range. | |
| 555 double multiplier = 1.0 / (num_values - 1); | |
| 556 | |
| 557 for (int i = 0; i < num_values; i++) { | |
| 558 // This value is in range 0..1 | |
| 559 float value = integers[i] * multiplier; | |
| 560 // Reverse the effect of offset and multiplier to get the expected | |
| 561 // output value from the half-float converter. | |
| 562 float expected_value = | |
| 563 value / half_float_maker->Multiplier() + half_float_maker->Offset(); | |
| 564 EXPECT_EQ(integers[i], i); | |
| 565 | |
| 566 // We expect the result to be within +/- one least-significant bit. | |
| 567 // Within the range we care about, half-floats values and | |
| 568 // their representation both sort in the same order, so we | |
| 569 // can just add one to get the next bigger half-float. | |
| 570 float expected_precision = | |
| 571 FromHalfFloat(half_floats[i] + 1) - FromHalfFloat(half_floats[i]); | |
| 572 EXPECT_NEAR(FromHalfFloat(half_floats[i]), expected_value, | |
| 573 expected_precision) | |
| 574 << "i = " << i << " bits = " << bits; | |
| 575 } | |
| 576 } | |
| 577 } | |
| 578 | |
| 579 } // namespace | 522 } // namespace |
| 580 } // namespace cc | 523 } // namespace cc |
| OLD | NEW |