OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2013 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include <time.h> | |
9 #include <dirent.h> | |
10 #include <glob.h> | |
11 #include "SkOSFile.h" | |
12 #include "skpdiff_util.h" | |
13 | |
14 #if SK_SUPPORT_OPENCL | |
15 const char* cl_error_to_string(cl_int err) { | |
16 switch (err) { | |
17 case CL_SUCCESS: return "CL_SUCCESS"; | |
18 case CL_DEVICE_NOT_FOUND: return "CL_DEVICE_NOT_FOUND"; | |
19 case CL_DEVICE_NOT_AVAILABLE: return "CL_DEVICE_NOT_AVAILABLE
"; | |
20 case CL_COMPILER_NOT_AVAILABLE: return "CL_COMPILER_NOT_AVAILAB
LE"; | |
21 case CL_MEM_OBJECT_ALLOCATION_FAILURE: return "CL_MEM_OBJECT_ALLOCATIO
N_FAILURE"; | |
22 case CL_OUT_OF_RESOURCES: return "CL_OUT_OF_RESOURCES"; | |
23 case CL_OUT_OF_HOST_MEMORY: return "CL_OUT_OF_HOST_MEMORY"; | |
24 case CL_PROFILING_INFO_NOT_AVAILABLE: return "CL_PROFILING_INFO_NOT_A
VAILABLE"; | |
25 case CL_MEM_COPY_OVERLAP: return "CL_MEM_COPY_OVERLAP"; | |
26 case CL_IMAGE_FORMAT_MISMATCH: return "CL_IMAGE_FORMAT_MISMATC
H"; | |
27 case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "CL_IMAGE_FORMAT_NOT_SUP
PORTED"; | |
28 case CL_BUILD_PROGRAM_FAILURE: return "CL_BUILD_PROGRAM_FAILUR
E"; | |
29 case CL_MAP_FAILURE: return "CL_MAP_FAILURE"; | |
30 case CL_INVALID_VALUE: return "CL_INVALID_VALUE"; | |
31 case CL_INVALID_DEVICE_TYPE: return "CL_INVALID_DEVICE_TYPE"
; | |
32 case CL_INVALID_PLATFORM: return "CL_INVALID_PLATFORM"; | |
33 case CL_INVALID_DEVICE: return "CL_INVALID_DEVICE"; | |
34 case CL_INVALID_CONTEXT: return "CL_INVALID_CONTEXT"; | |
35 case CL_INVALID_QUEUE_PROPERTIES: return "CL_INVALID_QUEUE_PROPER
TIES"; | |
36 case CL_INVALID_COMMAND_QUEUE: return "CL_INVALID_COMMAND_QUEU
E"; | |
37 case CL_INVALID_HOST_PTR: return "CL_INVALID_HOST_PTR"; | |
38 case CL_INVALID_MEM_OBJECT: return "CL_INVALID_MEM_OBJECT"; | |
39 case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return "CL_INVALID_IMAGE_FORMAT
_DESCRIPTOR"; | |
40 case CL_INVALID_IMAGE_SIZE: return "CL_INVALID_IMAGE_SIZE"; | |
41 case CL_INVALID_SAMPLER: return "CL_INVALID_SAMPLER"; | |
42 case CL_INVALID_BINARY: return "CL_INVALID_BINARY"; | |
43 case CL_INVALID_BUILD_OPTIONS: return "CL_INVALID_BUILD_OPTION
S"; | |
44 case CL_INVALID_PROGRAM: return "CL_INVALID_PROGRAM"; | |
45 case CL_INVALID_PROGRAM_EXECUTABLE: return "CL_INVALID_PROGRAM_EXEC
UTABLE"; | |
46 case CL_INVALID_KERNEL_NAME: return "CL_INVALID_KERNEL_NAME"
; | |
47 case CL_INVALID_KERNEL_DEFINITION: return "CL_INVALID_KERNEL_DEFIN
ITION"; | |
48 case CL_INVALID_KERNEL: return "CL_INVALID_KERNEL"; | |
49 case CL_INVALID_ARG_INDEX: return "CL_INVALID_ARG_INDEX"; | |
50 case CL_INVALID_ARG_VALUE: return "CL_INVALID_ARG_VALUE"; | |
51 case CL_INVALID_ARG_SIZE: return "CL_INVALID_ARG_SIZE"; | |
52 case CL_INVALID_KERNEL_ARGS: return "CL_INVALID_KERNEL_ARGS"
; | |
53 case CL_INVALID_WORK_DIMENSION: return "CL_INVALID_WORK_DIMENSI
ON"; | |
54 case CL_INVALID_WORK_GROUP_SIZE: return "CL_INVALID_WORK_GROUP_S
IZE"; | |
55 case CL_INVALID_WORK_ITEM_SIZE: return "CL_INVALID_WORK_ITEM_SI
ZE"; | |
56 case CL_INVALID_GLOBAL_OFFSET: return "CL_INVALID_GLOBAL_OFFSE
T"; | |
57 case CL_INVALID_EVENT_WAIT_LIST: return "CL_INVALID_EVENT_WAIT_L
IST"; | |
58 case CL_INVALID_EVENT: return "CL_INVALID_EVENT"; | |
59 case CL_INVALID_OPERATION: return "CL_INVALID_OPERATION"; | |
60 case CL_INVALID_GL_OBJECT: return "CL_INVALID_GL_OBJECT"; | |
61 case CL_INVALID_BUFFER_SIZE: return "CL_INVALID_BUFFER_SIZE"
; | |
62 case CL_INVALID_MIP_LEVEL: return "CL_INVALID_MIP_LEVEL"; | |
63 default: return "UNKNOWN"; | |
64 } | |
65 return "UNKNOWN"; | |
66 } | |
67 #endif | |
68 | |
69 | |
70 double get_seconds() { | |
71 struct timespec currentTime; | |
72 clock_gettime(CLOCK_REALTIME, ¤tTime); | |
73 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; | |
74 } | |
75 | |
76 bool get_directory(const char path[], SkTArray<SkString>* entries) { | |
77 // Open the directory and check for success | |
78 DIR* dir = opendir(path); | |
79 if (NULL == dir) { | |
80 return false; | |
81 } | |
82 | |
83 // Loop through dir entries until there are none left (i.e. readdir returns
NULL) | |
84 struct dirent* entry; | |
85 while ((entry = readdir(dir))) { | |
86 // dirent only gives relative paths, we need to join them to the base pa
th to check if they | |
87 // are directories. | |
88 SkString joinedPath = SkOSPath::SkPathJoin(path, entry->d_name); | |
89 | |
90 // We only care about files | |
91 if (!sk_isdir(joinedPath.c_str())) { | |
92 entries->push_back(SkString(entry->d_name)); | |
93 } | |
94 } | |
95 | |
96 closedir(dir); | |
97 | |
98 return true; | |
99 } | |
100 | |
101 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { | |
102 // TODO Make sure this works on windows. This may require use of FindNextFil
e windows function. | |
103 glob_t globBuffer; | |
104 if (glob(globPattern, 0, NULL, &globBuffer) != 0) { | |
105 return false; | |
106 } | |
107 | |
108 // 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 | |
110 char** paths = globBuffer.gl_pathv; | |
111 while(NULL != *paths) { | |
112 entries->push_back(SkString(*paths)); | |
113 paths++; | |
114 } | |
115 | |
116 globfree(&globBuffer); | |
117 | |
118 return true; | |
119 } | |
OLD | NEW |