| Index: tools/skpdiff/skpdiff_util.cpp
|
| diff --git a/experimental/skpdiff/skpdiff_util.cpp b/tools/skpdiff/skpdiff_util.cpp
|
| similarity index 75%
|
| rename from experimental/skpdiff/skpdiff_util.cpp
|
| rename to tools/skpdiff/skpdiff_util.cpp
|
| index 1cf02616eaab648a897cdfb5088c7b4904a9c66b..8013cd8ec2f9ca750a2ea47a5c8c0cd005dc1f4a 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,14 +73,27 @@ const char* cl_error_to_string(cl_int err) {
|
| }
|
| #endif
|
|
|
| -
|
| +// TODO refactor BenchTimer to be used here
|
| double get_seconds() {
|
| +#if defined(_POSIX_TIMERS) && defined(CLOCK_REALTIME)
|
| 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) {
|
| +#if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX
|
| // Open the directory and check for success
|
| DIR* dir = opendir(path);
|
| if (NULL == dir) {
|
| @@ -96,9 +116,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);
|
| + 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 +168,7 @@ bool glob_files(const char globPattern[], SkTArray<SkString>* entries) {
|
| globfree(&globBuffer);
|
|
|
| return true;
|
| +#elif SK_BUILD_FOR_WIN32
|
| + return false;
|
| +#endif
|
| }
|
|
|