Chromium Code Reviews| 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 in[1 << 12]; | |
| 530 unsigned short out[1 << 12]; | |
| 531 for (int bits = 9; bits <= 12; bits++) { | |
| 532 size_t num_values = 1 << bits; | |
| 533 for (size_t i = 0; i < num_values; i++) | |
| 534 in[i] = i; | |
| 535 | |
| 536 float mult = 1.0f / (num_values - 1); | |
|
danakj
2016/09/26 22:10:39
Why this mult?
hubbe
2016/09/27 00:03:25
Is "multiplier" better? Or did I misunderstand the
danakj
2016/09/27 00:15:58
I was wondering why 1/(n-1)?
hubbe
2016/09/27 00:31:24
Ah. I did add a comment for that.
| |
| 537 | |
| 538 VideoResourceUpdater::MakeHalfFloats(in, mult, num_values, out); | |
| 539 | |
| 540 for (size_t i = 0; i < num_values; i++) { | |
| 541 EXPECT_NEAR(FromHalfFloat(out[i]), in[i] * mult, | |
| 542 FromHalfFloat(out[i] + 1) - FromHalfFloat(out[i])) | |
|
danakj
2016/09/26 22:10:39
What does +1 on a half-float do to it? Can you lea
hubbe
2016/09/27 00:03:25
Done.
| |
| 543 << "i = " << i << " bits = " << bits; | |
| 544 } | |
| 545 } | |
| 546 } | |
| 547 | |
| 507 } // namespace | 548 } // namespace |
| 508 } // namespace cc | 549 } // namespace cc |
| OLD | NEW |