Chromium Code Reviews| Index: tools/skpdiff/skpdiff_util.cpp |
| diff --git a/experimental/skpdiff/skpdiff_util.cpp b/tools/skpdiff/skpdiff_util.cpp |
| similarity index 76% |
| rename from experimental/skpdiff/skpdiff_util.cpp |
| rename to tools/skpdiff/skpdiff_util.cpp |
| index 1cf02616eaab648a897cdfb5088c7b4904a9c66b..23403d71bf508fa5872a465837d2babeb70210b9 100644 |
| --- a/experimental/skpdiff/skpdiff_util.cpp |
| +++ b/tools/skpdiff/skpdiff_util.cpp |
| @@ -5,9 +5,16 @@ |
| * found in the LICENSE file. |
| */ |
| -#include <time.h> |
| -#include <dirent.h> |
| -#include <glob.h> |
| +#if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
| +# include <unistd.h> |
| +# include <time.h> |
| +# include <sys/time.h> |
| +# include <dirent.h> |
| +# include <glob.h> |
| +#elif SK_BUILD_FOR_WIN32 |
| +# include <windows.h> |
| +#endif |
| + |
| #include "SkOSFile.h" |
| #include "skpdiff_util.h" |
| @@ -66,15 +73,27 @@ const char* cl_error_to_string(cl_int err) { |
| } |
| #endif |
| - |
| double get_seconds() { |
| +#if defined(_POSIX_TIMERS) && defined(CLOCK_REALTIME) |
|
djsollen
2013/07/19 19:11:44
put a TODO here about refactoring BenchTimer so th
|
| struct timespec currentTime; |
| clock_gettime(CLOCK_REALTIME, ¤tTime); |
| return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; |
| +#elif SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
| + struct timeval currentTime; |
| + gettimeofday(¤tTime, NULL); |
| + return currentTime.tv_sec + (double)currentTime.tv_usec / 1e6; |
| +#elif SK_BUILD_FOR_WIN32 |
| + LARGE_INTEGER currentTime; |
| + LARGE_INTEGER frequency; |
| + QueryPerformanceCounter(¤tTime); |
| + QueryPerformanceFrequency(&frequency); |
| + return (double)currentTime.QuadPart / (double)frequency.QuadPart; |
| +#endif |
| } |
| bool get_directory(const char path[], SkTArray<SkString>* entries) { |
| - // Open the directory and check for success |
| +#if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
| + // Open the directory and check for success |
|
djsollen
2013/07/19 19:11:44
spaces not tabs
|
| DIR* dir = opendir(path); |
| if (NULL == dir) { |
| return false; |
| @@ -96,9 +115,41 @@ bool get_directory(const char path[], SkTArray<SkString>* entries) { |
| closedir(dir); |
| return true; |
| +#elif SK_BUILD_FOR_WIN32 |
| + char pathDirGlob[MAX_PATH]; |
| + char pathLength = strlen(path); |
|
djsollen
2013/07/19 19:11:44
spacing seems way off here.
|
| + strncpy(pathDirGlob, path, pathLength); |
| + |
| + if (path[pathLength - 1] == '/' || path[pathLength - 1] == '\\') { |
| + SkASSERT(pathLength + 2 <= MAX_PATH); |
| + pathDirGlob[pathLength] = '*'; |
| + pathDirGlob[pathLength + 1] = '\0'; |
| + } else { |
| + SkASSERT(pathLength + 3 <= MAX_PATH); |
| + pathDirGlob[pathLength] = '\\'; |
| + pathDirGlob[pathLength + 1] = '*'; |
| + pathDirGlob[pathLength + 2] = '\0'; |
| + } |
| + |
| + WIN32_FIND_DATA findFileData; |
| + HANDLE hFind = FindFirstFile(pathDirGlob, &findFileData); |
| + if (INVALID_HANDLE_VALUE == hFind) { |
| + return false; |
| + } |
| + |
| + do { |
| + if ((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
| + entries->push_back(SkString(findFileData.cFileName)); |
| + } |
| + } while (FindNextFile(hFind, &findFileData) != 0); |
| + |
| + FindClose(hFind); |
| + return true; |
| +#endif |
| } |
| bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { |
| +#if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
| // TODO Make sure this works on windows. This may require use of FindNextFile windows function. |
| glob_t globBuffer; |
| if (glob(globPattern, 0, NULL, &globBuffer) != 0) { |
| @@ -116,4 +167,7 @@ bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { |
| globfree(&globBuffer); |
| return true; |
| +#elif SK_BUILD_FOR_WIN32 |
| + return false; |
| +#endif |
| } |