OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <d3d9.h> | |
6 #include <random> | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/hash.h" | |
10 #include "base/scoped_native_library.h" | |
11 #include "base/stringprintf.h" | |
12 #include "base/win/scoped_comptr.h" | |
13 #include "base/win/windows_version.h" | |
14 #include "testing/gtest/include/gtest/gtest-param-test.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 #include "ui/gfx/rect.h" | |
17 #include "ui/surface/accelerated_surface_transformer_win.h" | |
18 #include "ui/surface/accelerated_surface_win.h" | |
19 #include "ui/surface/d3d9_utils_win.h" | |
20 | |
21 namespace d3d_utils = ui_surface_d3d9_utils; | |
22 | |
23 using base::win::ScopedComPtr; | |
24 using std::uniform_int_distribution; | |
25 | |
26 // Provides a reference rasterizer (all rendering done by software emulation) | |
27 // Direct3D device, for use by unit tests. | |
28 // | |
29 // This class is parameterized so that it runs only on Vista+. See | |
30 // WindowsVersionIfVistaOrBetter() for details on this works. | |
31 class AcceleratedSurfaceTransformerTest : public testing::TestWithParam<int> { | |
32 public: | |
33 AcceleratedSurfaceTransformerTest() {}; | |
34 | |
35 IDirect3DDevice9Ex* device() { return device_.get(); } | |
36 | |
37 virtual void SetUp() { | |
38 if (!d3d_module_.is_valid()) { | |
39 if (!d3d_utils::LoadD3D9(&d3d_module_)) { | |
40 GTEST_FAIL() << "Could not load d3d9.dll"; | |
41 return; | |
42 } | |
43 } | |
44 if (!d3d_utils::CreateDevice(d3d_module_, | |
45 D3DDEVTYPE_HAL, | |
46 D3DPRESENT_INTERVAL_IMMEDIATE, | |
47 device_.Receive())) { | |
48 GTEST_FAIL() << "Could not create Direct3D device."; | |
49 return; | |
50 } | |
51 | |
52 SeedRandom("default"); | |
53 } | |
54 | |
55 virtual void TearDown() { | |
56 device_ = NULL; | |
57 } | |
58 | |
59 // Gets a human-readable identifier of the graphics hardware being used, | |
60 // intended for use inside of SCOPED_TRACE(). | |
61 std::string GetAdapterInfo() { | |
62 ScopedComPtr<IDirect3D9> d3d; | |
63 EXPECT_HRESULT_SUCCEEDED(device()->GetDirect3D(d3d.Receive())); | |
64 D3DADAPTER_IDENTIFIER9 info; | |
65 EXPECT_HRESULT_SUCCEEDED(d3d->GetAdapterIdentifier(0, 0, &info)); | |
66 return StringPrintf("Running on graphics hardware: %s", info.Description); | |
67 } | |
68 | |
69 void SeedRandom(const char* seed) { | |
70 rng_.seed(base::Hash(seed)); | |
71 random_dword_.reset(); | |
72 } | |
73 | |
74 // Driver workaround: on an Intel GPU (Mobile Intel 965 Express), it seems | |
75 // necessary to flush between drawing and locking, for the synchronization | |
76 // to behave properly. | |
77 void BeforeLockWorkaround() { | |
78 EXPECT_HRESULT_SUCCEEDED( | |
79 device()->Present(0, 0, 0, 0)); | |
apatrick_chromium
2013/01/02 20:45:58
Eek! Have you considered using a reference device
ncarter (slow)
2013/01/02 23:35:21
Using a reference device was my original intent wh
| |
80 } | |
81 | |
82 // Locks and fills a surface with a checkerboard pattern where the colors | |
83 // are random but the total image pattern is horizontally and vertically | |
84 // symmetric. | |
85 void FillSymmetricRandomCheckerboard( | |
86 IDirect3DSurface9* lockable_surface, | |
87 const gfx::Size& size, | |
88 int checker_square_size) { | |
89 | |
90 D3DLOCKED_RECT locked_rect; | |
91 ASSERT_HRESULT_SUCCEEDED( | |
92 lockable_surface->LockRect(&locked_rect, NULL, D3DLOCK_DISCARD)); | |
93 DWORD* surface = reinterpret_cast<DWORD*>(locked_rect.pBits); | |
94 ASSERT_EQ(0, locked_rect.Pitch % sizeof(DWORD)); | |
95 int pitch = locked_rect.Pitch / sizeof(DWORD); | |
96 | |
97 for (int y = 0; y <= size.height() / 2; y += checker_square_size) { | |
98 for (int x = 0; x <= size.width() / 2; x += checker_square_size) { | |
99 DWORD color = RandomColor(); | |
100 int y_limit = std::min(size.height() / 2, y + checker_square_size - 1); | |
101 int x_limit = std::min(size.width() / 2, x + checker_square_size - 1); | |
102 for (int y_lo = y; y_lo <= y_limit; y_lo++) { | |
103 for (int x_lo = x; x_lo <= x_limit; x_lo++) { | |
104 int y_hi = size.height() - 1 - y_lo; | |
105 int x_hi = size.width() - 1 - x_lo; | |
106 surface[x_lo + y_lo*pitch] = color; | |
107 surface[x_lo + y_hi*pitch] = color; | |
108 surface[x_hi + y_lo*pitch] = color; | |
109 surface[x_hi + y_hi*pitch] = color; | |
110 } | |
111 } | |
112 } | |
113 } | |
114 | |
115 lockable_surface->UnlockRect(); | |
116 } | |
117 | |
118 void FillRandomCheckerboard( | |
119 IDirect3DSurface9* lockable_surface, | |
120 const gfx::Size& size, | |
121 int checker_square_size) { | |
122 | |
123 D3DLOCKED_RECT locked_rect; | |
124 ASSERT_HRESULT_SUCCEEDED( | |
125 lockable_surface->LockRect(&locked_rect, NULL, D3DLOCK_DISCARD)); | |
126 DWORD* surface = reinterpret_cast<DWORD*>(locked_rect.pBits); | |
127 ASSERT_EQ(0, locked_rect.Pitch % sizeof(DWORD)); | |
128 int pitch = locked_rect.Pitch / sizeof(DWORD); | |
129 | |
130 for (int y = 0; y <= size.height(); y += checker_square_size) { | |
131 for (int x = 0; x <= size.width(); x += checker_square_size) { | |
132 DWORD color = RandomColor(); | |
133 int y_limit = std::min(size.height(), y + checker_square_size); | |
134 int x_limit = std::min(size.width(), x + checker_square_size); | |
135 for (int square_y = y; square_y < y_limit; square_y++) { | |
136 for (int square_x = x; square_x < x_limit; square_x++) { | |
137 surface[square_x + square_y*pitch] = color; | |
138 } | |
139 } | |
140 } | |
141 } | |
142 | |
143 lockable_surface->UnlockRect(); | |
144 } | |
145 | |
146 // Approximate color-equality check. Allows for some rounding error. | |
147 bool AssertSameColor(DWORD color_a, DWORD color_b) { | |
148 if (color_a == color_b) | |
149 return true; | |
150 uint8* a = reinterpret_cast<uint8*>(&color_a); | |
151 uint8* b = reinterpret_cast<uint8*>(&color_b); | |
152 int max_error = 0; | |
153 for (int i = 0; i < 4; i++) | |
154 max_error = std::max(max_error, | |
155 std::abs(static_cast<int>(a[i]) - b[i])); | |
156 | |
157 if (max_error <= kAbsoluteColorErrorTolerance) | |
158 return true; | |
159 | |
160 std::string expected_color = | |
161 StringPrintf("%3d, %3d, %3d, %3d", a[0], a[1], a[2], a[3]); | |
162 std::string actual_color = | |
163 StringPrintf("%3d, %3d, %3d, %3d", b[0], b[1], b[2], b[3]); | |
164 EXPECT_EQ(expected_color, actual_color) | |
165 << "Componentwise color difference was " | |
166 << max_error << "; max allowed is " << kAbsoluteColorErrorTolerance; | |
167 | |
168 return false; | |
169 } | |
170 | |
171 // Asserts that an image is symmetric with respect to itself: both | |
172 // horizontally and vertically, within the tolerance of AssertSameColor. | |
173 void AssertSymmetry(IDirect3DSurface9* lockable_surface, | |
174 const gfx::Size& size) { | |
175 BeforeLockWorkaround(); | |
176 | |
177 D3DLOCKED_RECT locked_rect; | |
178 ASSERT_HRESULT_SUCCEEDED( | |
179 lockable_surface->LockRect(&locked_rect, NULL, D3DLOCK_READONLY)); | |
180 ASSERT_EQ(0, locked_rect.Pitch % sizeof(DWORD)); | |
181 int pitch = locked_rect.Pitch / sizeof(DWORD); | |
182 DWORD* surface = reinterpret_cast<DWORD*>(locked_rect.pBits); | |
183 for (int y_lo = 0; y_lo < size.height() / 2; y_lo++) { | |
184 int y_hi = size.height() - 1 - y_lo; | |
185 for (int x_lo = 0; x_lo < size.width() / 2; x_lo++) { | |
186 int x_hi = size.width() - 1 - x_lo; | |
187 if (!AssertSameColor(surface[x_lo + y_lo*pitch], | |
188 surface[x_hi + y_lo*pitch])) { | |
189 lockable_surface->UnlockRect(); | |
190 GTEST_FAIL() << "Pixels (" << x_lo << ", " << y_lo << ") vs. " | |
191 << "(" << x_hi << ", " << y_lo << ")"; | |
192 } | |
193 if (!AssertSameColor(surface[x_hi + y_lo*pitch], | |
194 surface[x_hi + y_hi*pitch])) { | |
195 lockable_surface->UnlockRect(); | |
196 GTEST_FAIL() << "Pixels (" << x_hi << ", " << y_lo << ") vs. " | |
197 << "(" << x_hi << ", " << y_hi << ")"; | |
198 } | |
199 if (!AssertSameColor(surface[x_hi + y_hi*pitch], | |
200 surface[x_lo + y_hi*pitch])) { | |
201 lockable_surface->UnlockRect(); | |
202 GTEST_FAIL() << "Pixels (" << x_hi << ", " << y_hi << ") vs. " | |
203 << "(" << x_lo << ", " << y_hi << ")"; | |
204 } | |
205 } | |
206 } | |
207 lockable_surface->UnlockRect(); | |
208 } | |
209 | |
210 // Asserts that the actual image is a bit-identical, vertically mirrored | |
211 // copy of the expected image. | |
212 void AssertIsInvertedCopy(const gfx::Size& size, | |
213 IDirect3DSurface9* expected, | |
214 IDirect3DSurface9* actual) { | |
215 BeforeLockWorkaround(); | |
216 | |
217 D3DLOCKED_RECT locked_expected, locked_actual; | |
218 ASSERT_HRESULT_SUCCEEDED( | |
219 expected->LockRect(&locked_expected, NULL, D3DLOCK_READONLY)); | |
220 ASSERT_HRESULT_SUCCEEDED( | |
221 actual->LockRect(&locked_actual, NULL, D3DLOCK_READONLY)); | |
222 ASSERT_EQ(0, locked_expected.Pitch % sizeof(DWORD)); | |
223 int pitch = locked_expected.Pitch / sizeof(DWORD); | |
224 DWORD* expected_image = reinterpret_cast<DWORD*>(locked_expected.pBits); | |
225 DWORD* actual_image = reinterpret_cast<DWORD*>(locked_actual.pBits); | |
226 for (int y = 0; y < size.height(); y++) { | |
227 int y_actual = size.height() - 1 - y; | |
228 for (int x = 0; x < size.width(); ++x) | |
229 if (!AssertSameColor(expected_image[y*pitch + x], | |
230 actual_image[y_actual*pitch + x])) { | |
231 expected->UnlockRect(); | |
232 actual->UnlockRect(); | |
233 GTEST_FAIL() << "Pixels (" << x << ", " << y << ") vs. " | |
234 << "(" << x << ", " << y_actual << ")"; | |
235 } | |
236 } | |
237 expected->UnlockRect(); | |
238 actual->UnlockRect(); | |
239 } | |
240 | |
241 protected: | |
242 static const int kAbsoluteColorErrorTolerance = 5; | |
243 | |
244 DWORD RandomColor() { | |
245 return random_dword_(rng_); | |
246 } | |
247 | |
248 void DoResizeBilinearTest(AcceleratedSurfaceTransformer* gpu_ops, | |
249 const gfx::Size& src_size, | |
250 const gfx::Size& dst_size, | |
251 int checkerboard_size) { | |
252 | |
253 SCOPED_TRACE( | |
254 StringPrintf("Resizing %dx%d -> %dx%d at checkerboard size of %d", | |
255 src_size.width(), src_size.height(), | |
256 dst_size.width(), dst_size.height(), | |
257 checkerboard_size)); | |
258 | |
259 base::win::ScopedComPtr<IDirect3DSurface9> src, dst; | |
260 ASSERT_TRUE(d3d_utils::CreateTemporaryLockableSurface( | |
261 device(), src_size, src.Receive())) | |
262 << "Could not create src render target"; | |
263 ASSERT_TRUE(d3d_utils::CreateTemporaryLockableSurface( | |
264 device(), dst_size, dst.Receive())) | |
265 << "Could not create dst render target"; | |
266 | |
267 FillSymmetricRandomCheckerboard(src, src_size, checkerboard_size); | |
268 | |
269 ASSERT_TRUE(gpu_ops->ResizeBilinear(src, gfx::Rect(src_size), dst)); | |
270 | |
271 AssertSymmetry(dst, dst_size); | |
272 } | |
273 | |
274 void DoCopyInvertedTest(AcceleratedSurfaceTransformer* gpu_ops, | |
275 const gfx::Size& size) { | |
276 | |
277 SCOPED_TRACE( | |
278 StringPrintf("CopyInverted @ %dx%d", size.width(), size.height())); | |
279 | |
280 base::win::ScopedComPtr<IDirect3DSurface9> checkerboard, src, dst; | |
281 base::win::ScopedComPtr<IDirect3DTexture9> src_texture; | |
282 ASSERT_TRUE(d3d_utils::CreateTemporaryLockableSurface(device(), size, | |
283 checkerboard.Receive())) << "Could not create src render target";; | |
284 ASSERT_TRUE(d3d_utils::CreateTemporaryRenderTargetTexture(device(), size, | |
285 src_texture.Receive(), src.Receive())) | |
286 << "Could not create src texture."; | |
287 ASSERT_TRUE(d3d_utils::CreateTemporaryLockableSurface(device(), size, | |
288 dst.Receive())) << "Could not create dst render target."; | |
289 | |
290 FillRandomCheckerboard(checkerboard, size, 1); | |
291 ASSERT_HRESULT_SUCCEEDED( | |
292 device()->StretchRect(checkerboard, NULL, src, NULL, D3DTEXF_NONE)); | |
293 ASSERT_TRUE(gpu_ops->CopyInverted(src_texture, dst, size)); | |
294 AssertIsInvertedCopy(size, checkerboard, dst); | |
295 } | |
296 | |
297 uniform_int_distribution<DWORD> random_dword_; | |
298 std::mt19937 rng_; | |
299 base::ScopedNativeLibrary d3d_module_; | |
300 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_; | |
301 }; | |
302 | |
303 // Fails on some bots because Direct3D isn't allowed. | |
304 TEST_P(AcceleratedSurfaceTransformerTest, FAILS_Init) { | |
305 SCOPED_TRACE(GetAdapterInfo()); | |
306 AcceleratedSurfaceTransformer gpu_ops; | |
307 ASSERT_TRUE(gpu_ops.Init(device())); | |
308 }; | |
309 | |
310 // Fails on some bots because Direct3D isn't allowed. | |
311 TEST_P(AcceleratedSurfaceTransformerTest, FAILS_TestConsistentRandom) { | |
312 // This behavior should be the same for every execution on every machine. | |
313 // Otherwise tests might be flaky and impossible to debug. | |
314 SeedRandom("AcceleratedSurfaceTransformerTest.TestConsistentRandom"); | |
315 ASSERT_EQ(2922058934, RandomColor()); | |
316 | |
317 SeedRandom("AcceleratedSurfaceTransformerTest.TestConsistentRandom"); | |
318 ASSERT_EQ(2922058934, RandomColor()); | |
319 ASSERT_EQ(4050239976, RandomColor()); | |
320 | |
321 SeedRandom("DifferentSeed"); | |
322 ASSERT_EQ(3904108833, RandomColor()); | |
323 } | |
324 | |
325 // Fails on some bots because Direct3D isn't allowed. | |
326 TEST_P(AcceleratedSurfaceTransformerTest, FAILS_CopyInverted) { | |
327 // This behavior should be the same for every execution on every machine. | |
328 // Otherwise tests might be flaky and impossible to debug. | |
329 SCOPED_TRACE(GetAdapterInfo()); | |
330 SeedRandom("CopyInverted"); | |
331 | |
332 AcceleratedSurfaceTransformer t; | |
333 ASSERT_TRUE(t.Init(device())); | |
334 | |
335 uniform_int_distribution<int> size(1, 512); | |
336 | |
337 for (int i = 0; i < 100; ++i) { | |
338 ASSERT_NO_FATAL_FAILURE( | |
339 DoCopyInvertedTest(&t, gfx::Size(size(rng_), size(rng_)))) | |
340 << "At iteration " << i; | |
341 } | |
342 } | |
343 | |
344 | |
345 // Fails on some bots because Direct3D isn't allowed. | |
346 // Fails on other bots because of ResizeBilinear symmetry failures. | |
347 // Should pass, at least, on NVIDIA Quadro 600. | |
348 TEST_P(AcceleratedSurfaceTransformerTest, FAILS_MixedOperations) { | |
349 SCOPED_TRACE(GetAdapterInfo()); | |
350 SeedRandom("MixedOperations"); | |
351 | |
352 AcceleratedSurfaceTransformer t; | |
353 ASSERT_TRUE(t.Init(device())); | |
354 | |
355 ASSERT_NO_FATAL_FAILURE( | |
356 DoResizeBilinearTest(&t, gfx::Size(256, 256), gfx::Size(255, 255), 1)); | |
357 ASSERT_NO_FATAL_FAILURE( | |
358 DoResizeBilinearTest(&t, gfx::Size(256, 256), gfx::Size(255, 255), 2)); | |
359 ASSERT_NO_FATAL_FAILURE( | |
360 DoCopyInvertedTest(&t, gfx::Size(20, 107))); | |
361 ASSERT_NO_FATAL_FAILURE( | |
362 DoResizeBilinearTest(&t, gfx::Size(256, 256), gfx::Size(255, 255), 5)); | |
363 ASSERT_NO_FATAL_FAILURE( | |
364 DoResizeBilinearTest(&t, gfx::Size(256, 256), gfx::Size(64, 64), 5)); | |
365 ASSERT_NO_FATAL_FAILURE( | |
366 DoResizeBilinearTest(&t, gfx::Size(255, 255), gfx::Size(3, 3), 1)); | |
367 ASSERT_NO_FATAL_FAILURE( | |
368 DoCopyInvertedTest(&t, gfx::Size(1412, 124))); | |
369 ASSERT_NO_FATAL_FAILURE( | |
370 DoResizeBilinearTest(&t, gfx::Size(255, 255), gfx::Size(257, 257), 1)); | |
371 ASSERT_NO_FATAL_FAILURE( | |
372 DoResizeBilinearTest(&t, gfx::Size(255, 255), gfx::Size(257, 257), 2)); | |
373 | |
374 ASSERT_NO_FATAL_FAILURE( | |
375 DoCopyInvertedTest(&t, gfx::Size(1512, 7))); | |
376 ASSERT_NO_FATAL_FAILURE( | |
377 DoResizeBilinearTest(&t, gfx::Size(255, 255), gfx::Size(257, 257), 5)); | |
378 ASSERT_NO_FATAL_FAILURE( | |
379 DoResizeBilinearTest(&t, gfx::Size(150, 256), gfx::Size(126, 256), 8)); | |
380 ASSERT_NO_FATAL_FAILURE( | |
381 DoCopyInvertedTest(&t, gfx::Size(1521, 3))); | |
382 ASSERT_NO_FATAL_FAILURE( | |
383 DoResizeBilinearTest(&t, gfx::Size(150, 256), gfx::Size(126, 256), 1)); | |
384 ASSERT_NO_FATAL_FAILURE( | |
385 DoCopyInvertedTest(&t, gfx::Size(33, 712))); | |
386 ASSERT_NO_FATAL_FAILURE( | |
387 DoResizeBilinearTest(&t, gfx::Size(150, 256), gfx::Size(126, 8), 8)); | |
388 ASSERT_NO_FATAL_FAILURE( | |
389 DoCopyInvertedTest(&t, gfx::Size(33, 2))); | |
390 ASSERT_NO_FATAL_FAILURE( | |
391 DoResizeBilinearTest(&t, gfx::Size(200, 256), gfx::Size(126, 8), 8)); | |
392 } | |
393 | |
394 // Tests ResizeBilinear with 16K wide/hight src and dst surfaces. | |
395 // | |
396 // Fails on some bots because Direct3D isn't allowed. | |
397 // Fails on other bots because of texture allocation failures. | |
398 // Should pass, at least, on NVIDIA Quadro 600. | |
399 TEST_P(AcceleratedSurfaceTransformerTest, FAILS_LargeSurfaces) { | |
400 SCOPED_TRACE(GetAdapterInfo()); | |
401 SeedRandom("LargeSurfaces"); | |
402 | |
403 AcceleratedSurfaceTransformer gpu_ops; | |
404 ASSERT_TRUE(gpu_ops.Init(device())); | |
405 | |
406 D3DCAPS9 caps; | |
407 ASSERT_HRESULT_SUCCEEDED( | |
408 device()->GetDeviceCaps(&caps)); | |
409 | |
410 SCOPED_TRACE(StringPrintf("max texture size: %dx%d, max texture aspect: %d", | |
411 caps.MaxTextureWidth, caps.MaxTextureHeight, caps.MaxTextureAspectRatio)); | |
412 | |
413 const int w = caps.MaxTextureWidth; | |
414 const int h = caps.MaxTextureHeight; | |
415 const int lo = 256; | |
416 | |
417 ASSERT_NO_FATAL_FAILURE( | |
418 DoResizeBilinearTest(&gpu_ops, gfx::Size(w, lo), gfx::Size(lo, lo), 1)); | |
419 ASSERT_NO_FATAL_FAILURE( | |
420 DoResizeBilinearTest(&gpu_ops, gfx::Size(lo, h), gfx::Size(lo, lo), 1)); | |
421 ASSERT_NO_FATAL_FAILURE( | |
422 DoResizeBilinearTest(&gpu_ops, gfx::Size(lo, lo), gfx::Size(w, lo), lo)); | |
423 ASSERT_NO_FATAL_FAILURE( | |
424 DoResizeBilinearTest(&gpu_ops, gfx::Size(lo, lo), gfx::Size(lo, h), lo)); | |
425 ASSERT_NO_FATAL_FAILURE( | |
426 DoCopyInvertedTest(&gpu_ops, gfx::Size(w, lo))); | |
427 ASSERT_NO_FATAL_FAILURE( | |
428 DoCopyInvertedTest(&gpu_ops, gfx::Size(lo, h))); | |
429 } | |
430 | |
431 // Exercises ResizeBilinear with random minification cases where the | |
432 // aspect ratio does not change. | |
433 // | |
434 // Fails on some bots because Direct3D isn't allowed. | |
435 // Fails on other bots because of ResizeBilinear symmetry failures. | |
436 // Should pass, at least, on NVIDIA Quadro 600. | |
437 TEST_P(AcceleratedSurfaceTransformerTest, FAILS_MinifyUniform) { | |
438 SCOPED_TRACE(GetAdapterInfo()); | |
439 SeedRandom("MinifyUniform"); | |
440 | |
441 AcceleratedSurfaceTransformer gpu_ops; | |
442 ASSERT_TRUE(gpu_ops.Init(device())); | |
443 | |
444 int dims[] = { 21, 63, 64, 65, 99, 127, 128, 129, 192, 255, 256, 257}; | |
445 int checkerboards[] = {1, 2, 3, 9}; | |
446 uniform_int_distribution<int> dim(0, arraysize(dims) - 1); | |
447 uniform_int_distribution<int> checkerboard(0, arraysize(checkerboards) - 1); | |
448 | |
449 for (int i = 0; i < 300; i++) { | |
450 // Widths are picked so that dst is smaller than src. | |
451 int dst_width = dims[dim(rng_)]; | |
452 int src_width = dims[dim(rng_)]; | |
453 if (src_width < dst_width) | |
454 std::swap(dst_width, src_width); | |
455 | |
456 // src_width is picked to preserve aspect ratio. | |
457 int dst_height = dims[dim(rng_)]; | |
458 int src_height = static_cast<int>( | |
459 static_cast<int64>(src_width) * dst_height / dst_width); | |
460 | |
461 int checkerboard_size = checkerboards[checkerboard(rng_)]; | |
462 | |
463 ASSERT_NO_FATAL_FAILURE( | |
464 DoResizeBilinearTest(&gpu_ops, | |
465 gfx::Size(src_width, src_height), // Src size (larger) | |
466 gfx::Size(dst_width, dst_height), // Dst size (smaller) | |
467 checkerboard_size)) << "Failed on iteration " << i; | |
468 } | |
469 }; | |
470 | |
471 // Exercises ResizeBilinear with random magnification cases where the | |
472 // aspect ratio does not change. | |
473 // | |
474 // This test relies on an assertion that resizing preserves symmetry in the | |
475 // image, but for the current implementation of ResizeBilinear, this does not | |
476 // seem to be true (fails on NVIDIA Quadro 600; passes on | |
477 // Intel Mobile 965 Express) | |
478 TEST_P(AcceleratedSurfaceTransformerTest, FAILS_MagnifyUniform) { | |
479 SCOPED_TRACE(GetAdapterInfo()); | |
480 SeedRandom("MagnifyUniform"); | |
481 | |
482 AcceleratedSurfaceTransformer gpu_ops; | |
483 ASSERT_TRUE(gpu_ops.Init(device())); | |
484 | |
485 int dims[] = {63, 64, 65, 99, 127, 128, 129, 192, 255, 256, 257}; | |
486 int checkerboards[] = {1, 2, 3, 9}; | |
487 uniform_int_distribution<int> dim(0, arraysize(dims) - 1); | |
488 uniform_int_distribution<int> checkerboard(0, arraysize(checkerboards) - 1); | |
489 | |
490 for (int i = 0; i < 50; i++) { | |
491 // Widths are picked so that b is smaller than a. | |
492 int dst_width = dims[dim(rng_)]; | |
493 int src_width = dims[dim(rng_)]; | |
494 if (dst_width < src_width) | |
495 std::swap(src_width, dst_width); | |
496 | |
497 int dst_height = dims[dim(rng_)]; | |
498 int src_height = static_cast<int>( | |
499 static_cast<int64>(src_width) * dst_height / dst_width); | |
500 | |
501 int checkerboard_size = checkerboards[checkerboard(rng_)]; | |
502 | |
503 ASSERT_NO_FATAL_FAILURE( | |
504 DoResizeBilinearTest(&gpu_ops, | |
505 gfx::Size(src_width, src_height), // Src size (smaller) | |
506 gfx::Size(dst_width, dst_height), // Dst size (larger) | |
507 checkerboard_size)) << "Failed on iteration " << i; | |
508 } | |
509 }; | |
510 | |
511 namespace { | |
512 | |
513 // Used to suppress test on Windows versions prior to Vista. | |
514 std::vector<int> WindowsVersionIfVistaOrBetter() { | |
515 std::vector<int> result; | |
516 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | |
517 result.push_back(base::win::GetVersion()); | |
518 } | |
519 return result; | |
520 } | |
521 | |
522 } // namespace | |
523 | |
524 INSTANTIATE_TEST_CASE_P(VistaAndUp, | |
525 AcceleratedSurfaceTransformerTest, | |
526 ::testing::ValuesIn(WindowsVersionIfVistaOrBetter())); | |
OLD | NEW |