| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 <gflags/gflags.h> | 5 #include <gflags/gflags.h> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <time.h> | 10 #include <time.h> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/string_util.h" |
| 13 | 14 |
| 14 #include "main.h" | 15 #include "main.h" |
| 15 #include "utils.h" | 16 #include "utils.h" |
| 16 #include "xlib_window.h" | 17 #include "xlib_window.h" |
| 17 | 18 |
| 18 #include "teartest.h" | 19 #include "teartest.h" |
| 19 | 20 |
| 20 typedef std::map<const char*, Test*> TestMap; | 21 typedef std::map<std::string, Test*> TestMap; |
| 21 | 22 |
| 22 | 23 |
| 23 DEFINE_int32(refresh, 0, | 24 DEFINE_int32(refresh, 0, |
| 24 "If 1 or more, target refresh rate; otherwise enable vsync"); | 25 "If 1 or more, target refresh rate; otherwise enable vsync."); |
| 26 |
| 27 DEFINE_string(tests, "uniform,teximage2d,pixmap_to_texture", |
| 28 "Comma-separated list of tests to run."); |
| 29 |
| 30 DEFINE_int32(seconds_to_run, 5, "Seconds to run a test case for."); |
| 25 | 31 |
| 26 GLuint GenerateAndBindTexture() { | 32 GLuint GenerateAndBindTexture() { |
| 27 GLuint name = ~0; | 33 GLuint name = ~0; |
| 28 glGenTextures(1, &name); | 34 glGenTextures(1, &name); |
| 29 glBindTexture(GL_TEXTURE_2D, name); | 35 glBindTexture(GL_TEXTURE_2D, name); |
| 30 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 31 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 37 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 32 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | 38 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 33 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | 39 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 34 return name; | 40 return name; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 test_map["uniform"] = uniform_test; | 205 test_map["uniform"] = uniform_test; |
| 200 test_map["teximage2d"] = GetTexImage2DTest(); | 206 test_map["teximage2d"] = GetTexImage2DTest(); |
| 201 #ifdef USE_EGL | 207 #ifdef USE_EGL |
| 202 test_map["pixmap_to_texture"] = GetPixmapToTextureTestEGL(); | 208 test_map["pixmap_to_texture"] = GetPixmapToTextureTestEGL(); |
| 203 #else | 209 #else |
| 204 test_map["pixmap_to_texture"] = GetPixmapToTextureTest(); | 210 test_map["pixmap_to_texture"] = GetPixmapToTextureTest(); |
| 205 #endif | 211 #endif |
| 206 | 212 |
| 207 SwapInterval(sleep_duration ? 0 : 1); | 213 SwapInterval(sleep_duration ? 0 : 1); |
| 208 | 214 |
| 209 for (TestMap::iterator it = test_map.begin(); it != test_map.end(); it++) { | 215 std::vector<std::string> tests; |
| 210 Test* t = it->second; | 216 SplitString(FLAGS_tests, ',', &tests); |
| 211 if (!t->Start()) | 217 |
| 218 for (std::vector<std::string>::iterator it = tests.begin(); |
| 219 it != tests.end(); |
| 220 it++) |
| 221 { |
| 222 Test* t = test_map[*it]; |
| 223 if (!t || !t->Start()) |
| 212 continue; | 224 continue; |
| 213 | 225 |
| 214 Bool got_event = False; | 226 Bool got_event = False; |
| 215 for (int x = 0; !got_event; x = (x + 4) % (2 * g_width)) { | 227 uint64_t wait_until = GetUTime() + 1000000ULL * FLAGS_seconds_to_run; |
| 228 for (int x = 0; |
| 229 !got_event && GetUTime() < wait_until; |
| 230 x = (x + 4) % (2 * g_width)) |
| 231 { |
| 216 const int shift = x < g_width ? x : 2 * g_width - x; | 232 const int shift = x < g_width ? x : 2 * g_width - x; |
| 217 | 233 |
| 218 t->Loop(shift); | 234 t->Loop(shift); |
| 219 | 235 |
| 220 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 236 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 221 glFlush(); | 237 glFlush(); |
| 222 | 238 |
| 223 if (sleep_duration) | 239 if (sleep_duration) |
| 224 nanosleep(sleep_duration, NULL); | 240 nanosleep(sleep_duration, NULL); |
| 225 | 241 |
| 226 SwapBuffers(); | 242 SwapBuffers(); |
| 227 | 243 |
| 228 XEvent event; | 244 XEvent event; |
| 229 got_event = XCheckWindowEvent(g_xlib_display, g_xlib_window, | 245 got_event = XCheckWindowEvent(g_xlib_display, g_xlib_window, |
| 230 KeyPressMask, &event); | 246 KeyPressMask, &event); |
| 231 } | 247 } |
| 232 | 248 |
| 233 t->Stop(); | 249 t->Stop(); |
| 234 } | 250 } |
| 235 | 251 |
| 236 // TODO: cleaner teardown. | 252 // TODO: cleaner teardown. |
| 237 | 253 |
| 238 glDeleteTextures(1, &texture); | 254 glDeleteTextures(1, &texture); |
| 239 DestroyContext(); | 255 DestroyContext(); |
| 240 return 0; | 256 return 0; |
| 241 } | 257 } |
| OLD | NEW |