Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: tools/skpdiff/skpdiff_util.cpp

Issue 628763005: Fix usage of SK_BUILD_* defines. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/skpdiff/skpdiff_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_ FOR_ANDROID)
9 # include <unistd.h> 9 # include <unistd.h>
10 # include <sys/time.h> 10 # include <sys/time.h>
11 # include <dirent.h> 11 # include <dirent.h>
12 #endif 12 #endif
13 13
14 #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX 14 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
15 # include <glob.h> 15 # include <glob.h>
16 #endif 16 #endif
17 17
18 #if SK_BUILD_FOR_MAC 18 #if defined(SK_BUILD_FOR_MAC)
19 # include <sys/syslimits.h> // PATH_MAX is here for Macs 19 # include <sys/syslimits.h> // PATH_MAX is here for Macs
20 #endif 20 #endif
21 21
22 #if SK_BUILD_FOR_WIN32 22 #if defined(SK_BUILD_FOR_WIN32)
23 # include <windows.h> 23 # include <windows.h>
24 #endif 24 #endif
25 25
26 #include <stdlib.h> 26 #include <stdlib.h>
27 #include <time.h> 27 #include <time.h>
28 #include "SkOSFile.h" 28 #include "SkOSFile.h"
29 #include "skpdiff_util.h" 29 #include "skpdiff_util.h"
30 30
31 #if SK_SUPPORT_OPENCL 31 #if SK_SUPPORT_OPENCL
32 const char* cl_error_to_string(cl_int err) { 32 const char* cl_error_to_string(cl_int err) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 case CL_INVALID_BUFFER_SIZE: return "CL_INVALID_BUFFER_SIZE" ; 78 case CL_INVALID_BUFFER_SIZE: return "CL_INVALID_BUFFER_SIZE" ;
79 case CL_INVALID_MIP_LEVEL: return "CL_INVALID_MIP_LEVEL"; 79 case CL_INVALID_MIP_LEVEL: return "CL_INVALID_MIP_LEVEL";
80 default: return "UNKNOWN"; 80 default: return "UNKNOWN";
81 } 81 }
82 return "UNKNOWN"; 82 return "UNKNOWN";
83 } 83 }
84 #endif 84 #endif
85 85
86 // TODO refactor Timer to be used here 86 // TODO refactor Timer to be used here
87 double get_seconds() { 87 double get_seconds() {
88 #if SK_BUILD_FOR_WIN32 88 #if defined(SK_BUILD_FOR_WIN32)
89 LARGE_INTEGER currentTime; 89 LARGE_INTEGER currentTime;
90 LARGE_INTEGER frequency; 90 LARGE_INTEGER frequency;
91 QueryPerformanceCounter(&currentTime); 91 QueryPerformanceCounter(&currentTime);
92 QueryPerformanceFrequency(&frequency); 92 QueryPerformanceFrequency(&frequency);
93 return (double)currentTime.QuadPart / (double)frequency.QuadPart; 93 return (double)currentTime.QuadPart / (double)frequency.QuadPart;
94 #elif _POSIX_TIMERS > 0 && defined(CLOCK_REALTIME) 94 #elif _POSIX_TIMERS > 0 && defined(CLOCK_REALTIME)
95 struct timespec currentTime; 95 struct timespec currentTime;
96 clock_gettime(CLOCK_REALTIME, &currentTime); 96 clock_gettime(CLOCK_REALTIME, &currentTime);
97 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; 97 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9;
98 #elif SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX || SK_BUILD_FOR_ANDROID 98 #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUIL D_FOR_ANDROID)
99 struct timeval currentTime; 99 struct timeval currentTime;
100 gettimeofday(&currentTime, NULL); 100 gettimeofday(&currentTime, NULL);
101 return currentTime.tv_sec + (double)currentTime.tv_usec / 1e6; 101 return currentTime.tv_sec + (double)currentTime.tv_usec / 1e6;
102 #else 102 #else
103 return clock() / (double)CLOCKS_PER_SEC; 103 return clock() / (double)CLOCKS_PER_SEC;
104 #endif 104 #endif
105 } 105 }
106 106
107 bool get_directory(const char path[], SkTArray<SkString>* entries) { 107 bool get_directory(const char path[], SkTArray<SkString>* entries) {
108 #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX || SK_BUILD_FOR_ANDROID 108 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_ FOR_ANDROID)
109 // Open the directory and check for success 109 // Open the directory and check for success
110 DIR* dir = opendir(path); 110 DIR* dir = opendir(path);
111 if (NULL == dir) { 111 if (NULL == dir) {
112 return false; 112 return false;
113 } 113 }
114 114
115 // Loop through dir entries until there are none left (i.e. readdir returns NULL) 115 // Loop through dir entries until there are none left (i.e. readdir returns NULL)
116 struct dirent* entry; 116 struct dirent* entry;
117 while ((entry = readdir(dir))) { 117 while ((entry = readdir(dir))) {
118 // dirent only gives relative paths, we need to join them to the base pa th to check if they 118 // dirent only gives relative paths, we need to join them to the base pa th to check if they
119 // are directories. 119 // are directories.
120 SkString joinedPath = SkOSPath::Join(path, entry->d_name); 120 SkString joinedPath = SkOSPath::Join(path, entry->d_name);
121 121
122 // We only care about files 122 // We only care about files
123 if (!sk_isdir(joinedPath.c_str())) { 123 if (!sk_isdir(joinedPath.c_str())) {
124 entries->push_back(SkString(entry->d_name)); 124 entries->push_back(SkString(entry->d_name));
125 } 125 }
126 } 126 }
127 127
128 closedir(dir); 128 closedir(dir);
129 129
130 return true; 130 return true;
131 #elif SK_BUILD_FOR_WIN32 131 #elif defined(SK_BUILD_FOR_WIN32)
132 char pathDirGlob[MAX_PATH]; 132 char pathDirGlob[MAX_PATH];
133 size_t pathLength = strlen(path); 133 size_t pathLength = strlen(path);
134 strncpy(pathDirGlob, path, pathLength); 134 strncpy(pathDirGlob, path, pathLength);
135 135
136 if (path[pathLength - 1] == '/' || path[pathLength - 1] == '\\') { 136 if (path[pathLength - 1] == '/' || path[pathLength - 1] == '\\') {
137 SkASSERT(pathLength + 2 <= MAX_PATH); 137 SkASSERT(pathLength + 2 <= MAX_PATH);
138 pathDirGlob[pathLength] = '*'; 138 pathDirGlob[pathLength] = '*';
139 pathDirGlob[pathLength + 1] = '\0'; 139 pathDirGlob[pathLength + 1] = '\0';
140 } else { 140 } else {
141 SkASSERT(pathLength + 3 <= MAX_PATH); 141 SkASSERT(pathLength + 3 <= MAX_PATH);
(...skipping 15 matching lines...) Expand all
157 } while (FindNextFile(hFind, &findFileData) != 0); 157 } while (FindNextFile(hFind, &findFileData) != 0);
158 158
159 FindClose(hFind); 159 FindClose(hFind);
160 return true; 160 return true;
161 #else 161 #else
162 return false; 162 return false;
163 #endif 163 #endif
164 } 164 }
165 165
166 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { 166 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) {
167 #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX 167 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
168 // TODO Make sure this works on windows. This may require use of FindNextFil e windows function. 168 // TODO Make sure this works on windows. This may require use of FindNextFil e windows function.
169 glob_t globBuffer; 169 glob_t globBuffer;
170 if (glob(globPattern, 0, NULL, &globBuffer) != 0) { 170 if (glob(globPattern, 0, NULL, &globBuffer) != 0) {
171 return false; 171 return false;
172 } 172 }
173 173
174 // Note these paths are in sorted order by default according to http://linux .die.net/man/3/glob 174 // Note these paths are in sorted order by default according to http://linux .die.net/man/3/glob
175 // Check under the flag GLOB_NOSORT 175 // Check under the flag GLOB_NOSORT
176 char** paths = globBuffer.gl_pathv; 176 char** paths = globBuffer.gl_pathv;
177 while(*paths) { 177 while(*paths) {
178 entries->push_back(SkString(*paths)); 178 entries->push_back(SkString(*paths));
179 paths++; 179 paths++;
180 } 180 }
181 181
182 globfree(&globBuffer); 182 globfree(&globBuffer);
183 183
184 return true; 184 return true;
185 #else 185 #else
186 return false; 186 return false;
187 #endif 187 #endif
188 } 188 }
189 189
190 SkString get_absolute_path(const SkString& path) { 190 SkString get_absolute_path(const SkString& path) {
191 #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX || SK_BUILD_FOR_ANDROID 191 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_ FOR_ANDROID)
192 SkString fullPath(PATH_MAX + 1); 192 SkString fullPath(PATH_MAX + 1);
193 if (realpath(path.c_str(), fullPath.writable_str()) == NULL) { 193 if (realpath(path.c_str(), fullPath.writable_str()) == NULL) {
194 fullPath.reset(); 194 fullPath.reset();
195 } 195 }
196 return fullPath; 196 return fullPath;
197 #elif SK_BUILD_FOR_WIN32 197 #elif defined(SK_BUILD_FOR_WIN32)
198 SkString fullPath(MAX_PATH); 198 SkString fullPath(MAX_PATH);
199 if (_fullpath(fullPath.writable_str(), path.c_str(), MAX_PATH) == NULL) { 199 if (_fullpath(fullPath.writable_str(), path.c_str(), MAX_PATH) == NULL) {
200 fullPath.reset(); 200 fullPath.reset();
201 } 201 }
202 return fullPath; 202 return fullPath;
203 #else 203 #else
204 return SkString(); 204 return SkString();
205 #endif 205 #endif
206 } 206 }
OLDNEW
« no previous file with comments | « tools/skpdiff/skpdiff_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698