| 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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 EXPECT_EQ(1, context3d_->TextureCreationCount()); | 497 EXPECT_EQ(1, context3d_->TextureCreationCount()); |
| 498 | 498 |
| 499 // The texture copy path requires the use of CopyTextureCHROMIUM, which | 499 // The texture copy path requires the use of CopyTextureCHROMIUM, which |
| 500 // enforces that the target texture not be immutable, as it may need | 500 // enforces that the target texture not be immutable, as it may need |
| 501 // to alter the storage of the texture. Therefore, this test asserts | 501 // to alter the storage of the texture. Therefore, this test asserts |
| 502 // that an immutable texture wasn't created by glTexStorage2DEXT, when | 502 // that an immutable texture wasn't created by glTexStorage2DEXT, when |
| 503 // that extension is supported. | 503 // that extension is supported. |
| 504 EXPECT_FALSE(context3d_->WasImmutableTextureCreated()); | 504 EXPECT_FALSE(context3d_->WasImmutableTextureCreated()); |
| 505 } | 505 } |
| 506 | 506 |
| 507 namespace { |
| 508 |
| 509 // Convert an IEEE 754 half-float to a double value |
| 510 // that we can do math on. |
| 511 double FromHalfFloat(uint16_t half_float) { |
| 512 if (!half_float) |
| 513 return 0.0; |
| 514 int sign = (half_float & 0x8000) ? -1 : 1; |
| 515 int exponent = (half_float >> 10) & 0x1F; |
| 516 int fraction = half_float & 0x3FF; |
| 517 if (exponent == 0) { |
| 518 return pow(2.0, -24.0) * fraction; |
| 519 } else if (exponent == 0x1F) { |
| 520 return sign * 1000000000000.0; |
| 521 } else { |
| 522 return pow(2.0, exponent - 25) * (0x400 + fraction); |
| 523 } |
| 524 } |
| 525 |
| 526 } // namespace |
| 527 |
| 528 TEST_F(VideoResourceUpdaterTest, MakeHalfFloatTest) { |
| 529 unsigned short integers[1 << 12]; |
| 530 unsigned short half_floats[1 << 12]; |
| 531 for (int bits = 9; bits <= 12; bits++) { |
| 532 int num_values = 1 << bits; |
| 533 for (int i = 0; i < num_values; i++) |
| 534 integers[i] = i; |
| 535 |
| 536 VideoResourceUpdater::MakeHalfFloats(integers, bits, num_values, |
| 537 half_floats); |
| 538 |
| 539 // Multiplier to converting integers to 0.0..1.0 range. |
| 540 double multiplier = 1.0 / (num_values - 1); |
| 541 |
| 542 for (int i = 0; i < num_values; i++) { |
| 543 // We expect the result to be within +/- one least-significant bit. |
| 544 // Within the range we care about, half-floats values and |
| 545 // their representation both sort in the same order, so we |
| 546 // can just add one to get the next bigger half-float. |
| 547 float expected_precision = |
| 548 FromHalfFloat(half_floats[i] + 1) - FromHalfFloat(half_floats[i]); |
| 549 EXPECT_NEAR(FromHalfFloat(half_floats[i]), integers[i] * multiplier, |
| 550 expected_precision) |
| 551 << "i = " << i << " bits = " << bits; |
| 552 } |
| 553 } |
| 554 } |
| 555 |
| 507 } // namespace | 556 } // namespace |
| 508 } // namespace cc | 557 } // namespace cc |
| OLD | NEW |