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 { | |
|
danakj
2016/09/26 20:35:04
whitespace below this
hubbe
2016/09/26 21:19:36
Done.
| |
| 508 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.
| |
| 509 if (!f) | |
| 510 return 0.0; | |
| 511 int sign = (f & 0x8000) ? -1 : 1; | |
| 512 int exponent = (f >> 10) & 0x1F; | |
| 513 int fraction = f & 0x3FF; | |
| 514 if (exponent == 0) { | |
| 515 return pow(2.0, -24.0) * fraction; | |
| 516 } else if (exponent == 0x1F) { | |
| 517 return sign * 1000000000000.0; | |
| 518 } else { | |
| 519 return pow(2.0, exponent - 25) * (0x400 + fraction); | |
| 520 } | |
| 521 } | |
| 522 | |
| 523 } // namespace | |
| 524 | |
| 525 TEST_F(VideoResourceUpdaterTest, MakeHalfFloatTest) { | |
| 526 unsigned short in[1 << 12]; | |
| 527 unsigned short out[1 << 12]; | |
| 528 for (int bits = 9; bits <= 12; bits++) { | |
| 529 size_t num_values = 1 << bits; | |
| 530 for (size_t i = 0; i < num_values; i++) | |
| 531 in[i] = i; | |
| 532 | |
| 533 float mult = 1.0f / (num_values - 1); | |
| 534 | |
| 535 VideoResourceUpdater::MakeHalfFloats(in, mult, num_values, out); | |
| 536 | |
| 537 for (size_t i = 0; i < num_values; i++) { | |
| 538 EXPECT_NEAR(from_half_float(out[i]), in[i] * mult, | |
| 539 from_half_float(out[i] + 1) - from_half_float(out[i])) | |
| 540 << "i = " << i << " bits = " << bits; | |
| 541 } | |
| 542 } | |
| 543 } | |
| 544 | |
| 507 } // namespace | 545 } // namespace |
| 508 } // namespace cc | 546 } // namespace cc |
| OLD | NEW |