| 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_SUPPORT_OPENCL | 8 #if SK_SUPPORT_OPENCL |
| 9 |
| 9 #define __NO_STD_VECTOR // Uses cl::vectpr instead of std::vectpr | 10 #define __NO_STD_VECTOR // Uses cl::vectpr instead of std::vectpr |
| 10 #define __NO_STD_STRING // Uses cl::STRING_CLASS instead of std::string | 11 #define __NO_STD_STRING // Uses cl::STRING_CLASS instead of std::string |
| 11 #include <CL/cl.hpp> | 12 #if SK_BUILD_FOR_MAC |
| 13 // Note that some macs don't have this header and it can be downloaded from the
Khronos registry |
| 14 # include <OpenCL/cl.hpp> |
| 15 #else |
| 16 # include <CL/cl.hpp> |
| 17 #endif |
| 18 |
| 12 #endif | 19 #endif |
| 13 | 20 |
| 14 #include "SkCommandLineFlags.h" | 21 #include "SkCommandLineFlags.h" |
| 15 #include "SkGraphics.h" | 22 #include "SkGraphics.h" |
| 16 #include "SkStream.h" | 23 #include "SkStream.h" |
| 17 #include "SkTDArray.h" | 24 #include "SkTDArray.h" |
| 18 | 25 |
| 19 #include "SkDifferentPixelsMetric.h" | 26 #include "SkDifferentPixelsMetric.h" |
| 20 #include "SkDiffContext.h" | 27 #include "SkDiffContext.h" |
| 21 #include "SkImageDiffer.h" | 28 #include "SkImageDiffer.h" |
| 22 #include "SkPMetric.h" | 29 #include "SkPMetric.h" |
| 23 #include "skpdiff_util.h" | 30 #include "skpdiff_util.h" |
| 24 | 31 |
| 25 #include "SkForceLinking.h" | 32 #include "SkForceLinking.h" |
| 26 __SK_FORCE_IMAGE_DECODER_LINKING; | 33 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 27 | 34 |
| 28 // Command line argument definitions go here | 35 // Command line argument definitions go here |
| 29 DEFINE_bool2(list, l, false, "List out available differs"); | 36 DEFINE_bool2(list, l, false, "List out available differs"); |
| 30 DEFINE_string2(differs, d, "", "The names of the differs to use or all of them b
y default"); | 37 DEFINE_string2(differs, d, "", "The names of the differs to use or all of them b
y default"); |
| 31 DEFINE_string2(folders, f, "", "Compare two folders with identical subfile names
: <baseline folder> <test folder>"); | 38 DEFINE_string2(folders, f, "", "Compare two folders with identical subfile names
: <baseline folder> <test folder>"); |
| 32 DEFINE_string2(patterns, p, "", "Use two patterns to compare images: <baseline>
<test>"); | 39 DEFINE_string2(patterns, p, "", "Use two patterns to compare images: <baseline>
<test>"); |
| 33 DEFINE_string2(output, o, "skpdiff_output.json", "Writes the output of these dif
fs to output: <output>"); | 40 DEFINE_string2(output, o, "skpdiff_output.json", "Writes the output of these dif
fs to output: <output>"); |
| 34 DEFINE_bool(jsonp, true, "Output JSON with padding"); | 41 DEFINE_bool(jsonp, true, "Output JSON with padding"); |
| 35 DEFINE_string(csv, "", "Writes the output of these diffs to a csv file"); | 42 DEFINE_string(csv, "", "Writes the output of these diffs to a csv file"); |
| 36 | 43 |
| 37 #if SK_SUPPORT_OPENCL | 44 #if SK_SUPPORT_OPENCL |
| 38 /// A callback for any OpenCL errors | 45 /// A callback for any OpenCL errors |
| 39 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize
, ::size_t cb, void* userData) { | 46 static void CL_CALLBACK error_notify(const char* errorInfo, const void* privateI
nfoSize, ::size_t cb, void* userData) { |
| 40 SkDebugf("OpenCL error notify: %s\n", errorInfo); | 47 SkDebugf("OpenCL error notify: %s\n", errorInfo); |
| 41 exit(1); | 48 exit(1); |
| 42 } | 49 } |
| 43 | 50 |
| 44 /// Creates a device and context with OpenCL | 51 /// Creates a device and context with OpenCL |
| 45 static bool init_device_and_context(cl::Device* device, cl::Context* context) { | 52 static bool init_device_and_context(cl::Device* device, cl::Context* context) { |
| 46 // Query for a platform | 53 // Query for a platform |
| 47 cl::vector<cl::Platform> platformList; | 54 cl::vector<cl::Platform> platformList; |
| 48 cl::Platform::get(&platformList); | 55 cl::Platform::get(&platformList); |
| 49 SkDebugf("The number of platforms is %u\n", platformList.size()); | 56 SkDebugf("The number of platforms is %u\n", platformList.size()); |
| 50 | 57 |
| 51 // Print some information about the platform for debugging | 58 // Print some information about the platform for debugging |
| 52 cl::Platform& platform = platformList[0]; | 59 cl::Platform& platform = platformList[0]; |
| 53 cl::STRING_CLASS platformName; | 60 cl::STRING_CLASS platformName; |
| 54 platform.getInfo(CL_PLATFORM_NAME, &platformName); | 61 platform.getInfo(CL_PLATFORM_NAME, &platformName); |
| 55 SkDebugf("Platform index 0 is named %s\n", platformName.c_str()); | 62 SkDebugf("Platform index 0 is named %s\n", platformName.c_str()); |
| 56 | 63 |
| 57 // Query for a device | 64 // Query for a device |
| 58 cl::vector<cl::Device> deviceList; | 65 cl::vector<cl::Device> deviceList; |
| 59 platform.getDevices(CL_DEVICE_TYPE_GPU, &deviceList); | 66 platform.getDevices(CL_DEVICE_TYPE_ALL, &deviceList); |
| 60 SkDebugf("The number of GPU devices is %u\n", deviceList.size()); | 67 SkDebugf("The number of devices is %u\n", deviceList.size()); |
| 61 | 68 |
| 62 // Print some information about the device for debugging | 69 // Print some information about the device for debugging |
| 63 *device = deviceList[0]; | 70 *device = deviceList[0]; |
| 64 cl::STRING_CLASS deviceName; | 71 cl::STRING_CLASS deviceName; |
| 65 device->getInfo(CL_DEVICE_NAME, &deviceName); | 72 device->getInfo(CL_DEVICE_NAME, &deviceName); |
| 66 SkDebugf("Device index 0 is named %s\n", deviceName.c_str()); | 73 SkDebugf("Device index 0 is named %s\n", deviceName.c_str()); |
| 67 | 74 |
| 68 // Create a CL context and check for all errors | 75 // Create a CL context and check for all errors |
| 69 cl_int contextErr = CL_SUCCESS; | 76 cl_int contextErr = CL_SUCCESS; |
| 70 *context = cl::Context(deviceList, NULL, error_notify, NULL, &contextErr); | 77 *context = cl::Context(deviceList, NULL, error_notify, NULL, &contextErr); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 // TODO Find a better home for the diff registry. One possibility is to have the
differs self | 100 // TODO Find a better home for the diff registry. One possibility is to have the
differs self |
| 94 // register. | 101 // register. |
| 95 | 102 |
| 96 // List here every differ | 103 // List here every differ |
| 97 SkDifferentPixelsMetric gDiffPixel; | 104 SkDifferentPixelsMetric gDiffPixel; |
| 98 SkPMetric gPDiff; | 105 SkPMetric gPDiff; |
| 99 | 106 |
| 100 // A null terminated array of pointer to every differ declared above | 107 // A null terminated array of pointer to every differ declared above |
| 101 SkImageDiffer* gDiffers[] = { &gDiffPixel, &gPDiff, NULL }; | 108 SkImageDiffer* gDiffers[] = { &gDiffPixel, &gPDiff, NULL }; |
| 102 | 109 |
| 103 int main(int argc, char** argv) { | 110 int tool_main(int argc, char * argv[]); |
| 111 int tool_main(int argc, char * argv[]) { |
| 104 // Setup command line parsing | 112 // Setup command line parsing |
| 105 SkCommandLineFlags::SetUsage("Compare images using various metrics."); | 113 SkCommandLineFlags::SetUsage("Compare images using various metrics."); |
| 106 SkCommandLineFlags::Parse(argc, argv); | 114 SkCommandLineFlags::Parse(argc, argv); |
| 107 | 115 |
| 108 // Needed by various Skia components | 116 // Needed by various Skia components |
| 109 SkAutoGraphics ag; | 117 SkAutoGraphics ag; |
| 110 | 118 |
| 111 if (FLAGS_list) { | 119 if (FLAGS_list) { |
| 112 SkDebugf("Available Metrics:\n"); | 120 SkDebugf("Available Metrics:\n"); |
| 113 } | 121 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 ctx.outputRecords(outputStream, FLAGS_jsonp); | 204 ctx.outputRecords(outputStream, FLAGS_jsonp); |
| 197 } | 205 } |
| 198 | 206 |
| 199 if (!FLAGS_csv.isEmpty()) { | 207 if (!FLAGS_csv.isEmpty()) { |
| 200 SkFILEWStream outputStream(FLAGS_csv[0]); | 208 SkFILEWStream outputStream(FLAGS_csv[0]); |
| 201 ctx.outputCsv(outputStream); | 209 ctx.outputCsv(outputStream); |
| 202 } | 210 } |
| 203 | 211 |
| 204 return 0; | 212 return 0; |
| 205 } | 213 } |
| 214 |
| 215 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 216 int main(int argc, char * argv[]) { |
| 217 return tool_main(argc, (char**) argv); |
| 218 } |
| 219 #endif |
| OLD | NEW |