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

Unified Diff: tools/skpdiff/skpdiff_util.cpp

Issue 19671002: migrate skpdiff to tools (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: i shake my fist at Visual Studio's default use of tabs Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/skpdiff/skpdiff_util.h ('k') | tools/skpdiff/viewer.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, &currentTime);
return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9;
+#elif SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX
+ struct timeval currentTime;
+ gettimeofday(&currentTime, NULL);
+ return currentTime.tv_sec + (double)currentTime.tv_usec / 1e6;
+#elif SK_BUILD_FOR_WIN32
+ LARGE_INTEGER currentTime;
+ LARGE_INTEGER frequency;
+ QueryPerformanceCounter(&currentTime);
+ 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
}
« no previous file with comments | « tools/skpdiff/skpdiff_util.h ('k') | tools/skpdiff/viewer.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698