Chromium Code Reviews| 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 #define __NO_STD_VECTOR // Uses cl::vectpr instead of std::vectpr | |
| 9 #define __NO_STD_STRING // Uses cl::STRING_CLASS instead of std::string | |
| 10 #include <CL/cl.hpp> | |
| 11 | |
| 12 #include "SkOSFile.h" | |
| 13 #include "SkStream.h" | |
| 14 #include "SkString.h" | |
| 15 #include "SkTArray.h" | |
| 16 #include "SkTDArray.h" | |
| 17 | |
| 18 #include "SkImageDiffer.h" | |
| 19 #include "SkCLImageDiffer.h" | |
| 20 #include "skpdiff_util.h" | |
| 21 | |
| 22 /// A callback for any OpenCL errors | |
| 23 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize , ::size_t cb, void* userData) { | |
| 24 SkDebugf("OpenCL error notify: %s\n", errorInfo); | |
| 25 exit(1); | |
| 26 } | |
| 27 | |
| 28 /// Creates a device and context with OpenCL | |
| 29 static bool init_device_and_context(cl::Device* device, cl::Context* context) { | |
| 30 // Query for a platform | |
| 31 cl::vector<cl::Platform> platformList; | |
| 32 cl::Platform::get(&platformList); | |
| 33 SkDebugf("The number of platforms is %u\n", platformList.size()); | |
| 34 | |
| 35 // Print some information about the platform for debugging | |
| 36 cl::Platform& platform = platformList[0]; | |
| 37 cl::STRING_CLASS platformName; | |
| 38 platform.getInfo(CL_PLATFORM_NAME, &platformName); | |
| 39 SkDebugf("Platform index 0 is named %s\n", platformName.c_str()); | |
| 40 | |
| 41 // Query for a device | |
| 42 cl::vector<cl::Device> deviceList; | |
| 43 platform.getDevices(CL_DEVICE_TYPE_GPU, &deviceList); | |
| 44 SkDebugf("The number of GPU devices is %u\n", deviceList.size()); | |
| 45 | |
| 46 // Print some information about the device for debugging | |
| 47 *device = deviceList[0]; | |
| 48 cl::STRING_CLASS deviceName; | |
| 49 device->getInfo(CL_DEVICE_NAME, &deviceName); | |
| 50 SkDebugf("Device index 0 is named %s\n", deviceName.c_str()); | |
| 51 | |
| 52 // Create a CL context and check for all errors | |
| 53 cl_int contextErr = CL_SUCCESS; | |
| 54 *context = cl::Context(deviceList, NULL, error_notify, NULL, &contextErr); | |
| 55 if (contextErr != CL_SUCCESS) { | |
| 56 SkDebugf("Context creation failed: %s\n", cl_error_to_string(contextErr) ); | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 /// Compares two directories of images with the given differ | |
| 64 static void diff_directories(const char baselinePath[], const char testPath[], S kImageDiffer* differ) { | |
| 65 // Get the files in the baseline, we will then look for those inside the tes t path | |
| 66 SkTArray<SkString> baselineEntries; | |
| 67 if (!get_directory(baselinePath, &baselineEntries)) { | |
| 68 SkDebugf("Unable to open path \"s\"\n", baselinePath); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 SkTDArray<int> queuedDiffIDs; | |
| 73 for (int baselineIndex = 0; baselineIndex < baselineEntries.count(); baselin eIndex++) { | |
| 74 const char* baseFilename = baselineEntries[baselineIndex].c_str(); | |
| 75 SkDebugf("%s\n", baseFilename); | |
| 76 | |
| 77 // Find the real location of each file to compare | |
| 78 SkString baselineFile = SkOSPath::SkPathJoin(baselinePath, baseFilename) ; | |
| 79 SkString testFile = SkOSPath::SkPathJoin(testPath, baseFilename); | |
| 80 | |
| 81 // Check that the test file exists and is a file | |
| 82 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) { | |
| 83 // Queue up the comparison with the differ | |
| 84 int diffID = differ->queueDiffOfFile(baselineFile.c_str(), testFile. c_str()); | |
| 85 if (diffID >= 0) { | |
| 86 queuedDiffIDs.push(diffID); | |
| 87 SkDebugf("Result: %f\n", differ->getResult(diffID)); | |
| 88 } | |
| 89 } else { | |
| 90 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba selineFile.c_str()); | |
| 91 } | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 int main(int argc, char** argv) { | |
| 96 // Setup OpenCL | |
| 97 cl::Device device; | |
| 98 cl::Context context; | |
| 99 if (!init_device_and_context(&device, &context)) { | |
| 100 return 1; | |
| 101 } | |
| 102 | |
| 103 // Setup our differ of choice | |
| 104 SkCLImageDiffer* differ = SkNEW(SkDifferentPixelsImageDiffer); | |
| 105 if (!differ->init(device(), context())) { | |
| 106 return 1; | |
| 107 } | |
| 108 | |
| 109 // Diff our folders | |
| 110 diff_directories("/usr/local/google/home/zachr/Downloads/diffs/baseline", | |
|
djsollen
2013/06/13 13:33:02
let's take these as argv[1] and argv[2] for now
| |
| 111 "/usr/local/google/home/zachr/Downloads/diffs/test", differ ); | |
| 112 | |
| 113 return 0; | |
| 114 } | |
| OLD | NEW |