OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <time.h> | 8 #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
9 #include <dirent.h> | 9 # include <unistd.h> |
10 #include <glob.h> | 10 # include <time.h> |
| 11 # include <sys/time.h> |
| 12 # include <dirent.h> |
| 13 # include <glob.h> |
| 14 #elif SK_BUILD_FOR_WIN32 |
| 15 # include <windows.h> |
| 16 #endif |
| 17 |
11 #include "SkOSFile.h" | 18 #include "SkOSFile.h" |
12 #include "skpdiff_util.h" | 19 #include "skpdiff_util.h" |
13 | 20 |
14 #if SK_SUPPORT_OPENCL | 21 #if SK_SUPPORT_OPENCL |
15 const char* cl_error_to_string(cl_int err) { | 22 const char* cl_error_to_string(cl_int err) { |
16 switch (err) { | 23 switch (err) { |
17 case CL_SUCCESS: return "CL_SUCCESS"; | 24 case CL_SUCCESS: return "CL_SUCCESS"; |
18 case CL_DEVICE_NOT_FOUND: return "CL_DEVICE_NOT_FOUND"; | 25 case CL_DEVICE_NOT_FOUND: return "CL_DEVICE_NOT_FOUND"; |
19 case CL_DEVICE_NOT_AVAILABLE: return "CL_DEVICE_NOT_AVAILABLE
"; | 26 case CL_DEVICE_NOT_AVAILABLE: return "CL_DEVICE_NOT_AVAILABLE
"; |
20 case CL_COMPILER_NOT_AVAILABLE: return "CL_COMPILER_NOT_AVAILAB
LE"; | 27 case CL_COMPILER_NOT_AVAILABLE: return "CL_COMPILER_NOT_AVAILAB
LE"; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 case CL_INVALID_OPERATION: return "CL_INVALID_OPERATION"; | 66 case CL_INVALID_OPERATION: return "CL_INVALID_OPERATION"; |
60 case CL_INVALID_GL_OBJECT: return "CL_INVALID_GL_OBJECT"; | 67 case CL_INVALID_GL_OBJECT: return "CL_INVALID_GL_OBJECT"; |
61 case CL_INVALID_BUFFER_SIZE: return "CL_INVALID_BUFFER_SIZE"
; | 68 case CL_INVALID_BUFFER_SIZE: return "CL_INVALID_BUFFER_SIZE"
; |
62 case CL_INVALID_MIP_LEVEL: return "CL_INVALID_MIP_LEVEL"; | 69 case CL_INVALID_MIP_LEVEL: return "CL_INVALID_MIP_LEVEL"; |
63 default: return "UNKNOWN"; | 70 default: return "UNKNOWN"; |
64 } | 71 } |
65 return "UNKNOWN"; | 72 return "UNKNOWN"; |
66 } | 73 } |
67 #endif | 74 #endif |
68 | 75 |
69 | 76 // TODO refactor BenchTimer to be used here |
70 double get_seconds() { | 77 double get_seconds() { |
| 78 #if defined(_POSIX_TIMERS) && defined(CLOCK_REALTIME) |
71 struct timespec currentTime; | 79 struct timespec currentTime; |
72 clock_gettime(CLOCK_REALTIME, ¤tTime); | 80 clock_gettime(CLOCK_REALTIME, ¤tTime); |
73 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; | 81 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; |
| 82 #elif SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
| 83 struct timeval currentTime; |
| 84 gettimeofday(¤tTime, NULL); |
| 85 return currentTime.tv_sec + (double)currentTime.tv_usec / 1e6; |
| 86 #elif SK_BUILD_FOR_WIN32 |
| 87 LARGE_INTEGER currentTime; |
| 88 LARGE_INTEGER frequency; |
| 89 QueryPerformanceCounter(¤tTime); |
| 90 QueryPerformanceFrequency(&frequency); |
| 91 return (double)currentTime.QuadPart / (double)frequency.QuadPart; |
| 92 #endif |
74 } | 93 } |
75 | 94 |
76 bool get_directory(const char path[], SkTArray<SkString>* entries) { | 95 bool get_directory(const char path[], SkTArray<SkString>* entries) { |
| 96 #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
77 // Open the directory and check for success | 97 // Open the directory and check for success |
78 DIR* dir = opendir(path); | 98 DIR* dir = opendir(path); |
79 if (NULL == dir) { | 99 if (NULL == dir) { |
80 return false; | 100 return false; |
81 } | 101 } |
82 | 102 |
83 // Loop through dir entries until there are none left (i.e. readdir returns
NULL) | 103 // Loop through dir entries until there are none left (i.e. readdir returns
NULL) |
84 struct dirent* entry; | 104 struct dirent* entry; |
85 while ((entry = readdir(dir))) { | 105 while ((entry = readdir(dir))) { |
86 // dirent only gives relative paths, we need to join them to the base pa
th to check if they | 106 // dirent only gives relative paths, we need to join them to the base pa
th to check if they |
87 // are directories. | 107 // are directories. |
88 SkString joinedPath = SkOSPath::SkPathJoin(path, entry->d_name); | 108 SkString joinedPath = SkOSPath::SkPathJoin(path, entry->d_name); |
89 | 109 |
90 // We only care about files | 110 // We only care about files |
91 if (!sk_isdir(joinedPath.c_str())) { | 111 if (!sk_isdir(joinedPath.c_str())) { |
92 entries->push_back(SkString(entry->d_name)); | 112 entries->push_back(SkString(entry->d_name)); |
93 } | 113 } |
94 } | 114 } |
95 | 115 |
96 closedir(dir); | 116 closedir(dir); |
97 | 117 |
98 return true; | 118 return true; |
| 119 #elif SK_BUILD_FOR_WIN32 |
| 120 char pathDirGlob[MAX_PATH]; |
| 121 char pathLength = strlen(path); |
| 122 strncpy(pathDirGlob, path, pathLength); |
| 123 |
| 124 if (path[pathLength - 1] == '/' || path[pathLength - 1] == '\\') { |
| 125 SkASSERT(pathLength + 2 <= MAX_PATH); |
| 126 pathDirGlob[pathLength] = '*'; |
| 127 pathDirGlob[pathLength + 1] = '\0'; |
| 128 } else { |
| 129 SkASSERT(pathLength + 3 <= MAX_PATH); |
| 130 pathDirGlob[pathLength] = '\\'; |
| 131 pathDirGlob[pathLength + 1] = '*'; |
| 132 pathDirGlob[pathLength + 2] = '\0'; |
| 133 } |
| 134 |
| 135 WIN32_FIND_DATA findFileData; |
| 136 HANDLE hFind = FindFirstFile(pathDirGlob, &findFileData); |
| 137 if (INVALID_HANDLE_VALUE == hFind) { |
| 138 return false; |
| 139 } |
| 140 |
| 141 do { |
| 142 if ((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
| 143 entries->push_back(SkString(findFileData.cFileName)); |
| 144 } |
| 145 } while (FindNextFile(hFind, &findFileData) != 0); |
| 146 |
| 147 FindClose(hFind); |
| 148 return true; |
| 149 #endif |
99 } | 150 } |
100 | 151 |
101 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { | 152 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { |
| 153 #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
102 // TODO Make sure this works on windows. This may require use of FindNextFil
e windows function. | 154 // TODO Make sure this works on windows. This may require use of FindNextFil
e windows function. |
103 glob_t globBuffer; | 155 glob_t globBuffer; |
104 if (glob(globPattern, 0, NULL, &globBuffer) != 0) { | 156 if (glob(globPattern, 0, NULL, &globBuffer) != 0) { |
105 return false; | 157 return false; |
106 } | 158 } |
107 | 159 |
108 // Note these paths are in sorted order by default according to http://linux
.die.net/man/3/glob | 160 // Note these paths are in sorted order by default according to http://linux
.die.net/man/3/glob |
109 // Check under the flag GLOB_NOSORT | 161 // Check under the flag GLOB_NOSORT |
110 char** paths = globBuffer.gl_pathv; | 162 char** paths = globBuffer.gl_pathv; |
111 while(NULL != *paths) { | 163 while(NULL != *paths) { |
112 entries->push_back(SkString(*paths)); | 164 entries->push_back(SkString(*paths)); |
113 paths++; | 165 paths++; |
114 } | 166 } |
115 | 167 |
116 globfree(&globBuffer); | 168 globfree(&globBuffer); |
117 | 169 |
118 return true; | 170 return true; |
| 171 #elif SK_BUILD_FOR_WIN32 |
| 172 return false; |
| 173 #endif |
119 } | 174 } |
OLD | NEW |