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 | |
70 double get_seconds() { | 76 double get_seconds() { |
77 #if defined(_POSIX_TIMERS) && defined(CLOCK_REALTIME) | |
djsollen
2013/07/19 19:11:44
put a TODO here about refactoring BenchTimer so th
| |
71 struct timespec currentTime; | 78 struct timespec currentTime; |
72 clock_gettime(CLOCK_REALTIME, ¤tTime); | 79 clock_gettime(CLOCK_REALTIME, ¤tTime); |
73 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; | 80 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; |
81 #elif SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX | |
82 struct timeval currentTime; | |
83 gettimeofday(¤tTime, NULL); | |
84 return currentTime.tv_sec + (double)currentTime.tv_usec / 1e6; | |
85 #elif SK_BUILD_FOR_WIN32 | |
86 LARGE_INTEGER currentTime; | |
87 LARGE_INTEGER frequency; | |
88 QueryPerformanceCounter(¤tTime); | |
89 QueryPerformanceFrequency(&frequency); | |
90 return (double)currentTime.QuadPart / (double)frequency.QuadPart; | |
91 #endif | |
74 } | 92 } |
75 | 93 |
76 bool get_directory(const char path[], SkTArray<SkString>* entries) { | 94 bool get_directory(const char path[], SkTArray<SkString>* entries) { |
77 // Open the directory and check for success | 95 #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX |
96 » // Open the directory and check for success | |
djsollen
2013/07/19 19:11:44
spaces not tabs
| |
78 DIR* dir = opendir(path); | 97 DIR* dir = opendir(path); |
79 if (NULL == dir) { | 98 if (NULL == dir) { |
80 return false; | 99 return false; |
81 } | 100 } |
82 | 101 |
83 // Loop through dir entries until there are none left (i.e. readdir returns NULL) | 102 // Loop through dir entries until there are none left (i.e. readdir returns NULL) |
84 struct dirent* entry; | 103 struct dirent* entry; |
85 while ((entry = readdir(dir))) { | 104 while ((entry = readdir(dir))) { |
86 // dirent only gives relative paths, we need to join them to the base pa th to check if they | 105 // dirent only gives relative paths, we need to join them to the base pa th to check if they |
87 // are directories. | 106 // are directories. |
88 SkString joinedPath = SkOSPath::SkPathJoin(path, entry->d_name); | 107 SkString joinedPath = SkOSPath::SkPathJoin(path, entry->d_name); |
89 | 108 |
90 // We only care about files | 109 // We only care about files |
91 if (!sk_isdir(joinedPath.c_str())) { | 110 if (!sk_isdir(joinedPath.c_str())) { |
92 entries->push_back(SkString(entry->d_name)); | 111 entries->push_back(SkString(entry->d_name)); |
93 } | 112 } |
94 } | 113 } |
95 | 114 |
96 closedir(dir); | 115 closedir(dir); |
97 | 116 |
98 return true; | 117 return true; |
118 #elif SK_BUILD_FOR_WIN32 | |
119 char pathDirGlob[MAX_PATH]; | |
120 char pathLength = strlen(path); | |
djsollen
2013/07/19 19:11:44
spacing seems way off here.
| |
121 strncpy(pathDirGlob, path, pathLength); | |
122 | |
123 if (path[pathLength - 1] == '/' || path[pathLength - 1] == '\\') { | |
124 SkASSERT(pathLength + 2 <= MAX_PATH); | |
125 pathDirGlob[pathLength] = '*'; | |
126 pathDirGlob[pathLength + 1] = '\0'; | |
127 } else { | |
128 SkASSERT(pathLength + 3 <= MAX_PATH); | |
129 pathDirGlob[pathLength] = '\\'; | |
130 pathDirGlob[pathLength + 1] = '*'; | |
131 pathDirGlob[pathLength + 2] = '\0'; | |
132 } | |
133 | |
134 WIN32_FIND_DATA findFileData; | |
135 HANDLE hFind = FindFirstFile(pathDirGlob, &findFileData); | |
136 if (INVALID_HANDLE_VALUE == hFind) { | |
137 return false; | |
138 } | |
139 | |
140 do { | |
141 if ((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) = = 0) { | |
142 entries->push_back(SkString(findFileData.cFileName)); | |
143 } | |
144 } while (FindNextFile(hFind, &findFileData) != 0); | |
145 | |
146 FindClose(hFind); | |
147 return true; | |
148 #endif | |
99 } | 149 } |
100 | 150 |
101 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { | 151 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { |
152 #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. | 153 // TODO Make sure this works on windows. This may require use of FindNextFil e windows function. |
103 glob_t globBuffer; | 154 glob_t globBuffer; |
104 if (glob(globPattern, 0, NULL, &globBuffer) != 0) { | 155 if (glob(globPattern, 0, NULL, &globBuffer) != 0) { |
105 return false; | 156 return false; |
106 } | 157 } |
107 | 158 |
108 // Note these paths are in sorted order by default according to http://linux .die.net/man/3/glob | 159 // 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 | 160 // Check under the flag GLOB_NOSORT |
110 char** paths = globBuffer.gl_pathv; | 161 char** paths = globBuffer.gl_pathv; |
111 while(NULL != *paths) { | 162 while(NULL != *paths) { |
112 entries->push_back(SkString(*paths)); | 163 entries->push_back(SkString(*paths)); |
113 paths++; | 164 paths++; |
114 } | 165 } |
115 | 166 |
116 globfree(&globBuffer); | 167 globfree(&globBuffer); |
117 | 168 |
118 return true; | 169 return true; |
170 #elif SK_BUILD_FOR_WIN32 | |
171 return false; | |
172 #endif | |
119 } | 173 } |
OLD | NEW |