Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Side by Side Diff: cc/resources/video_resource_updater_unittest.cc

Issue 2370453003: 12-bit vp9 video support (Closed)
Patch Set: build fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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];
danakj 2016/09/27 20:49:11 can we name these 2 vars to tell their context a b
hubbe 2016/09/27 22:27:36 Done.
530 unsigned short out[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 in[i] = i;
535
536 VideoResourceUpdater::MakeHalfFloats(in, bits, num_values, out);
537
538 // Multiplier to converting integers to 0.0..1.0 range.
539 float multiplier = 1.0f / (num_values - 1);
danakj 2016/09/27 20:49:11 nit: double (and 1.0 not 1.f) since you're returni
hubbe 2016/09/27 22:27:36 Done.
540
541 for (int i = 0; i < num_values; i++) {
542 // We expect the result to be within +/- one LSB.
danakj 2016/09/27 20:49:11 nit: can you spell out LSB
hubbe 2016/09/27 22:27:36 Done.
543 // Within the range we care about, half-floats values and
544 // their representation both sort in the same order, so we
545 // can just add one to get the next bigger half-float.
546 float expected_precision =
danakj 2016/09/27 20:49:11 Thanks this is helpful
hubbe 2016/09/27 22:27:36 Done.
547 FromHalfFloat(out[i] + 1) - FromHalfFloat(out[i]);
548 EXPECT_NEAR(FromHalfFloat(out[i]), in[i] * multiplier, expected_precision)
549 << "i = " << i << " bits = " << bits;
550 }
551 }
552 }
553
507 } // namespace 554 } // namespace
508 } // namespace cc 555 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698