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