| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <d3d9.h> | 5 #include <d3d9.h> |
| 6 #include <random> | 6 #include <random> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/hash.h" | 10 #include "base/hash.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 device_ = NULL; | 117 device_ = NULL; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Gets a human-readable identifier of the graphics hardware being used, | 120 // Gets a human-readable identifier of the graphics hardware being used, |
| 121 // intended for use inside of SCOPED_TRACE(). | 121 // intended for use inside of SCOPED_TRACE(). |
| 122 std::string GetAdapterInfo() { | 122 std::string GetAdapterInfo() { |
| 123 ScopedComPtr<IDirect3D9> d3d; | 123 ScopedComPtr<IDirect3D9> d3d; |
| 124 EXPECT_HRESULT_SUCCEEDED(device()->GetDirect3D(d3d.Receive())); | 124 EXPECT_HRESULT_SUCCEEDED(device()->GetDirect3D(d3d.Receive())); |
| 125 D3DADAPTER_IDENTIFIER9 info; | 125 D3DADAPTER_IDENTIFIER9 info; |
| 126 EXPECT_HRESULT_SUCCEEDED(d3d->GetAdapterIdentifier(0, 0, &info)); | 126 EXPECT_HRESULT_SUCCEEDED(d3d->GetAdapterIdentifier(0, 0, &info)); |
| 127 return StringPrintf("Running on graphics hardware: %s", info.Description); | 127 return base::StringPrintf( |
| 128 "Running on graphics hardware: %s", info.Description); |
| 128 } | 129 } |
| 129 | 130 |
| 130 void SeedRandom(const char* seed) { | 131 void SeedRandom(const char* seed) { |
| 131 rng_.seed(base::Hash(seed)); | 132 rng_.seed(base::Hash(seed)); |
| 132 random_dword_.reset(); | 133 random_dword_.reset(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 // Driver workaround: on an Intel GPU (Mobile Intel 965 Express), it seems | 136 // Driver workaround: on an Intel GPU (Mobile Intel 965 Express), it seems |
| 136 // necessary to flush between drawing and locking, for the synchronization | 137 // necessary to flush between drawing and locking, for the synchronization |
| 137 // to behave properly. | 138 // to behave properly. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 uint8* b = reinterpret_cast<uint8*>(&color_b); | 222 uint8* b = reinterpret_cast<uint8*>(&color_b); |
| 222 int max_error = 0; | 223 int max_error = 0; |
| 223 for (int i = 0; i < 4; i++) | 224 for (int i = 0; i < 4; i++) |
| 224 max_error = std::max(max_error, | 225 max_error = std::max(max_error, |
| 225 std::abs(static_cast<int>(a[i]) - b[i])); | 226 std::abs(static_cast<int>(a[i]) - b[i])); |
| 226 | 227 |
| 227 if (max_error <= color_error_tolerance()) | 228 if (max_error <= color_error_tolerance()) |
| 228 return true; | 229 return true; |
| 229 | 230 |
| 230 std::string expected_color = | 231 std::string expected_color = |
| 231 StringPrintf("%3d, %3d, %3d, %3d", a[0], a[1], a[2], a[3]); | 232 base::StringPrintf("%3d, %3d, %3d, %3d", a[0], a[1], a[2], a[3]); |
| 232 std::string actual_color = | 233 std::string actual_color = |
| 233 StringPrintf("%3d, %3d, %3d, %3d", b[0], b[1], b[2], b[3]); | 234 base::StringPrintf("%3d, %3d, %3d, %3d", b[0], b[1], b[2], b[3]); |
| 234 EXPECT_EQ(expected_color, actual_color) | 235 EXPECT_EQ(expected_color, actual_color) |
| 235 << "Componentwise color difference was " | 236 << "Componentwise color difference was " |
| 236 << max_error << "; max allowed is " << color_error_tolerance(); | 237 << max_error << "; max allowed is " << color_error_tolerance(); |
| 237 | 238 |
| 238 return false; | 239 return false; |
| 239 } | 240 } |
| 240 | 241 |
| 241 bool AssertSameColor(uint8 color_a, uint8 color_b) { | 242 bool AssertSameColor(uint8 color_a, uint8 color_b) { |
| 242 if (color_a == color_b) | 243 if (color_a == color_b) |
| 243 return true; | 244 return true; |
| 244 int max_error = std::abs((int) color_a - (int) color_b); | 245 int max_error = std::abs((int) color_a - (int) color_b); |
| 245 if (max_error <= color_error_tolerance()) | 246 if (max_error <= color_error_tolerance()) |
| 246 return true; | 247 return true; |
| 247 ADD_FAILURE() << "Colors not equal: " << StringPrintf("0x%x", color_a) | 248 ADD_FAILURE() << "Colors not equal: " |
| 248 << " vs. " << StringPrintf("0x%x", color_b); | 249 << base::StringPrintf("0x%x", color_a) |
| 250 << " vs. " << base::StringPrintf("0x%x", color_b); |
| 249 return false; | 251 return false; |
| 250 } | 252 } |
| 251 | 253 |
| 252 // Asserts that an image is symmetric with respect to itself: both | 254 // Asserts that an image is symmetric with respect to itself: both |
| 253 // horizontally and vertically, within the tolerance of AssertSameColor. | 255 // horizontally and vertically, within the tolerance of AssertSameColor. |
| 254 void AssertSymmetry(IDirect3DSurface9* lockable_surface, | 256 void AssertSymmetry(IDirect3DSurface9* lockable_surface, |
| 255 const gfx::Size& size) { | 257 const gfx::Size& size) { |
| 256 BeforeLockWorkaround(); | 258 BeforeLockWorkaround(); |
| 257 | 259 |
| 258 D3DLOCKED_RECT locked_rect; | 260 D3DLOCKED_RECT locked_rect; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 int color_error_tolerance() { | 333 int color_error_tolerance() { |
| 332 return color_error_tolerance_; | 334 return color_error_tolerance_; |
| 333 } | 335 } |
| 334 | 336 |
| 335 void DoResizeBilinearTest(AcceleratedSurfaceTransformer* gpu_ops, | 337 void DoResizeBilinearTest(AcceleratedSurfaceTransformer* gpu_ops, |
| 336 const gfx::Size& src_size, | 338 const gfx::Size& src_size, |
| 337 const gfx::Size& dst_size, | 339 const gfx::Size& dst_size, |
| 338 int checkerboard_size) { | 340 int checkerboard_size) { |
| 339 | 341 |
| 340 SCOPED_TRACE( | 342 SCOPED_TRACE( |
| 341 StringPrintf("Resizing %dx%d -> %dx%d at checkerboard size of %d", | 343 base::StringPrintf( |
| 342 src_size.width(), src_size.height(), | 344 "Resizing %dx%d -> %dx%d at checkerboard size of %d", |
| 343 dst_size.width(), dst_size.height(), | 345 src_size.width(), src_size.height(), |
| 344 checkerboard_size)); | 346 dst_size.width(), dst_size.height(), |
| 347 checkerboard_size)); |
| 345 | 348 |
| 346 set_color_error_tolerance(4); | 349 set_color_error_tolerance(4); |
| 347 | 350 |
| 348 base::win::ScopedComPtr<IDirect3DSurface9> src, dst; | 351 base::win::ScopedComPtr<IDirect3DSurface9> src, dst; |
| 349 ASSERT_TRUE(d3d_utils::CreateTemporaryLockableSurface( | 352 ASSERT_TRUE(d3d_utils::CreateTemporaryLockableSurface( |
| 350 device(), src_size, src.Receive())) | 353 device(), src_size, src.Receive())) |
| 351 << "Could not create src render target"; | 354 << "Could not create src render target"; |
| 352 ASSERT_TRUE(d3d_utils::CreateTemporaryLockableSurface( | 355 ASSERT_TRUE(d3d_utils::CreateTemporaryLockableSurface( |
| 353 device(), dst_size, dst.Receive())) | 356 device(), dst_size, dst.Receive())) |
| 354 << "Could not create dst render target"; | 357 << "Could not create dst render target"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 GTEST_FAIL() << "At pixel (" << x << ", " << y << ")"; | 396 GTEST_FAIL() << "At pixel (" << x << ", " << y << ")"; |
| 394 } | 397 } |
| 395 } | 398 } |
| 396 } | 399 } |
| 397 lockable->UnlockRect(); | 400 lockable->UnlockRect(); |
| 398 } | 401 } |
| 399 | 402 |
| 400 void DoCopyInvertedTest(AcceleratedSurfaceTransformer* gpu_ops, | 403 void DoCopyInvertedTest(AcceleratedSurfaceTransformer* gpu_ops, |
| 401 const gfx::Size& size) { | 404 const gfx::Size& size) { |
| 402 | 405 |
| 403 SCOPED_TRACE( | 406 SCOPED_TRACE(base::StringPrintf( |
| 404 StringPrintf("CopyInverted @ %dx%d", size.width(), size.height())); | 407 "CopyInverted @ %dx%d", size.width(), size.height())); |
| 405 | 408 |
| 406 set_color_error_tolerance(0); | 409 set_color_error_tolerance(0); |
| 407 | 410 |
| 408 base::win::ScopedComPtr<IDirect3DSurface9> dst, reference_pattern; | 411 base::win::ScopedComPtr<IDirect3DSurface9> dst, reference_pattern; |
| 409 base::win::ScopedComPtr<IDirect3DTexture9> src; | 412 base::win::ScopedComPtr<IDirect3DTexture9> src; |
| 410 | 413 |
| 411 CreateRandomCheckerboardTexture(size, 1, reference_pattern.Receive(), | 414 CreateRandomCheckerboardTexture(size, 1, reference_pattern.Receive(), |
| 412 src.Receive()); | 415 src.Receive()); |
| 413 | 416 |
| 414 // Alloc a slightly larger image 75% of the time, to test that the | 417 // Alloc a slightly larger image 75% of the time, to test that the |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 ASSERT_NO_FATAL_FAILURE( | 455 ASSERT_NO_FATAL_FAILURE( |
| 453 DoYUVConversionTest(gpu_ops, src_size, dst_size, 4, false)); | 456 DoYUVConversionTest(gpu_ops, src_size, dst_size, 4, false)); |
| 454 } | 457 } |
| 455 | 458 |
| 456 void DoYUVConversionTest(AcceleratedSurfaceTransformer* gpu_ops, | 459 void DoYUVConversionTest(AcceleratedSurfaceTransformer* gpu_ops, |
| 457 const gfx::Size& src_size, | 460 const gfx::Size& src_size, |
| 458 const gfx::Size& dst_size, | 461 const gfx::Size& dst_size, |
| 459 int checkerboard_size, | 462 int checkerboard_size, |
| 460 boolean use_multi_render_targets) { | 463 boolean use_multi_render_targets) { |
| 461 SCOPED_TRACE( | 464 SCOPED_TRACE( |
| 462 StringPrintf("YUV Converting %dx%d at checkerboard size of %d; MRT %s", | 465 base::StringPrintf( |
| 463 src_size.width(), src_size.height(), | 466 "YUV Converting %dx%d at checkerboard size of %d; MRT %s", |
| 464 checkerboard_size, | 467 src_size.width(), src_size.height(), |
| 465 use_multi_render_targets ? "enabled" : "disabled")); | 468 checkerboard_size, |
| 469 use_multi_render_targets ? "enabled" : "disabled")); |
| 466 | 470 |
| 467 | 471 |
| 468 base::win::ScopedComPtr<IDirect3DTexture9> src; | 472 base::win::ScopedComPtr<IDirect3DTexture9> src; |
| 469 base::win::ScopedComPtr<IDirect3DSurface9> reference; | 473 base::win::ScopedComPtr<IDirect3DSurface9> reference; |
| 470 base::win::ScopedComPtr<IDirect3DSurface9> dst_y, dst_u, dst_v; | 474 base::win::ScopedComPtr<IDirect3DSurface9> dst_y, dst_u, dst_v; |
| 471 | 475 |
| 472 // TODO(ncarter): Use a better error metric that measures aggregate error | 476 // TODO(ncarter): Use a better error metric that measures aggregate error |
| 473 // rather than simply max error. There seems to be slightly more error at | 477 // rather than simply max error. There seems to be slightly more error at |
| 474 // higher resolutions, maybe due to precision issues during rasterization | 478 // higher resolutions, maybe due to precision issues during rasterization |
| 475 // (or maybe more pixels = more test trials). Results are usually to an | 479 // (or maybe more pixels = more test trials). Results are usually to an |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 SCOPED_TRACE(GetAdapterInfo()); | 683 SCOPED_TRACE(GetAdapterInfo()); |
| 680 SeedRandom("LargeSurfaces"); | 684 SeedRandom("LargeSurfaces"); |
| 681 | 685 |
| 682 AcceleratedSurfaceTransformer gpu_ops; | 686 AcceleratedSurfaceTransformer gpu_ops; |
| 683 ASSERT_TRUE(gpu_ops.Init(device())); | 687 ASSERT_TRUE(gpu_ops.Init(device())); |
| 684 | 688 |
| 685 D3DCAPS9 caps; | 689 D3DCAPS9 caps; |
| 686 ASSERT_HRESULT_SUCCEEDED( | 690 ASSERT_HRESULT_SUCCEEDED( |
| 687 device()->GetDeviceCaps(&caps)); | 691 device()->GetDeviceCaps(&caps)); |
| 688 | 692 |
| 689 SCOPED_TRACE(StringPrintf("max texture size: %dx%d, max texture aspect: %d", | 693 SCOPED_TRACE(base::StringPrintf( |
| 694 "max texture size: %dx%d, max texture aspect: %d", |
| 690 caps.MaxTextureWidth, caps.MaxTextureHeight, caps.MaxTextureAspectRatio)); | 695 caps.MaxTextureWidth, caps.MaxTextureHeight, caps.MaxTextureAspectRatio)); |
| 691 | 696 |
| 692 const int w = caps.MaxTextureWidth; | 697 const int w = caps.MaxTextureWidth; |
| 693 const int h = caps.MaxTextureHeight; | 698 const int h = caps.MaxTextureHeight; |
| 694 const int lo = 256; | 699 const int lo = 256; |
| 695 | 700 |
| 696 ASSERT_NO_FATAL_FAILURE( | 701 ASSERT_NO_FATAL_FAILURE( |
| 697 DoResizeBilinearTest(&gpu_ops, gfx::Size(w, lo), gfx::Size(lo, lo), 1)); | 702 DoResizeBilinearTest(&gpu_ops, gfx::Size(w, lo), gfx::Size(lo, lo), 1)); |
| 698 ASSERT_NO_FATAL_FAILURE( | 703 ASSERT_NO_FATAL_FAILURE( |
| 699 DoResizeBilinearTest(&gpu_ops, gfx::Size(lo, h), gfx::Size(lo, lo), 1)); | 704 DoResizeBilinearTest(&gpu_ops, gfx::Size(lo, h), gfx::Size(lo, lo), 1)); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 result.push_back(base::win::GetVersion()); | 888 result.push_back(base::win::GetVersion()); |
| 884 } | 889 } |
| 885 return result; | 890 return result; |
| 886 } | 891 } |
| 887 | 892 |
| 888 } // namespace | 893 } // namespace |
| 889 | 894 |
| 890 INSTANTIATE_TEST_CASE_P(VistaAndUp, | 895 INSTANTIATE_TEST_CASE_P(VistaAndUp, |
| 891 AcceleratedSurfaceTransformerTest, | 896 AcceleratedSurfaceTransformerTest, |
| 892 ::testing::ValuesIn(WindowsVersionIfVistaOrBetter())); | 897 ::testing::ValuesIn(WindowsVersionIfVistaOrBetter())); |
| OLD | NEW |