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

Side by Side Diff: experimental/skpdiff/main.cpp

Issue 19374006: make OpenCL optional for skpdiff (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: comments 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 unified diff | Download patch | Annotate | Revision Log
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_SUPPORT_OPENCL
8 #define __NO_STD_VECTOR // Uses cl::vectpr instead of std::vectpr 9 #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 #define __NO_STD_STRING // Uses cl::STRING_CLASS instead of std::string
10 #include <CL/cl.hpp> 11 #include <CL/cl.hpp>
11 12
13 #include "SkCLImageDiffer.h"
djsollen 2013/07/16 20:11:46 this is not needed.
14 #endif
15
12 #include "SkCommandLineFlags.h" 16 #include "SkCommandLineFlags.h"
13 #include "SkGraphics.h" 17 #include "SkGraphics.h"
14 #include "SkStream.h" 18 #include "SkStream.h"
15 #include "SkTDArray.h" 19 #include "SkTDArray.h"
16 20
17 #include "SkCLImageDiffer.h" 21 #include "SkDifferentPixelsMetric.h"
18 #include "SkDiffContext.h" 22 #include "SkDiffContext.h"
19 #include "SkImageDiffer.h" 23 #include "SkImageDiffer.h"
20 #include "SkPMetric.h" 24 #include "SkPMetric.h"
21 #include "skpdiff_util.h" 25 #include "skpdiff_util.h"
22 26
23 #include "SkForceLinking.h" 27 #include "SkForceLinking.h"
24 __SK_FORCE_IMAGE_DECODER_LINKING; 28 __SK_FORCE_IMAGE_DECODER_LINKING;
25 29
26 // Command line argument definitions go here 30 // Command line argument definitions go here
27 DEFINE_bool2(list, l, false, "List out available differs"); 31 DEFINE_bool2(list, l, false, "List out available differs");
28 DEFINE_string2(differs, d, "", "The names of the differs to use or all of them b y default"); 32 DEFINE_string2(differs, d, "", "The names of the differs to use or all of them b y default");
29 DEFINE_string2(folders, f, "", "Compare two folders with identical subfile names : <baseline folder> <test folder>"); 33 DEFINE_string2(folders, f, "", "Compare two folders with identical subfile names : <baseline folder> <test folder>");
30 DEFINE_string2(patterns, p, "", "Use two patterns to compare images: <baseline> <test>"); 34 DEFINE_string2(patterns, p, "", "Use two patterns to compare images: <baseline> <test>");
31 DEFINE_string2(output, o, "skpdiff_output.json", "Writes the output of these dif fs to output: <output>"); 35 DEFINE_string2(output, o, "skpdiff_output.json", "Writes the output of these dif fs to output: <output>");
32 DEFINE_bool(jsonp, true, "Output JSON with padding"); 36 DEFINE_bool(jsonp, true, "Output JSON with padding");
33 37
38 #if SK_SUPPORT_OPENCL
34 /// A callback for any OpenCL errors 39 /// A callback for any OpenCL errors
35 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize , ::size_t cb, void* userData) { 40 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize , ::size_t cb, void* userData) {
36 SkDebugf("OpenCL error notify: %s\n", errorInfo); 41 SkDebugf("OpenCL error notify: %s\n", errorInfo);
37 exit(1); 42 exit(1);
38 } 43 }
39 44
40 /// Creates a device and context with OpenCL 45 /// Creates a device and context with OpenCL
41 static bool init_device_and_context(cl::Device* device, cl::Context* context) { 46 static bool init_device_and_context(cl::Device* device, cl::Context* context) {
42 // Query for a platform 47 // Query for a platform
43 cl::vector<cl::Platform> platformList; 48 cl::vector<cl::Platform> platformList;
(...skipping 21 matching lines...) Expand all
65 cl_int contextErr = CL_SUCCESS; 70 cl_int contextErr = CL_SUCCESS;
66 *context = cl::Context(deviceList, NULL, error_notify, NULL, &contextErr); 71 *context = cl::Context(deviceList, NULL, error_notify, NULL, &contextErr);
67 if (contextErr != CL_SUCCESS) { 72 if (contextErr != CL_SUCCESS) {
68 SkDebugf("Context creation failed: %s\n", cl_error_to_string(contextErr) ); 73 SkDebugf("Context creation failed: %s\n", cl_error_to_string(contextErr) );
69 return false; 74 return false;
70 } 75 }
71 76
72 return true; 77 return true;
73 } 78 }
74 79
75
76
77 static bool init_cl_diff(SkImageDiffer* differ) { 80 static bool init_cl_diff(SkImageDiffer* differ) {
78 // Setup OpenCL 81 // Setup OpenCL
79 cl::Device device; 82 cl::Device device;
80 cl::Context context; 83 cl::Context context;
81 if (!init_device_and_context(&device, &context)) { 84 if (!init_device_and_context(&device, &context)) {
82 return false; 85 return false;
83 } 86 }
84 87
85 // Setup our differ of choice 88 // Setup our differ of choice
86 SkCLImageDiffer* clDiffer = (SkCLImageDiffer*)differ; 89 SkCLImageDiffer* clDiffer = (SkCLImageDiffer*)differ;
87 return clDiffer->init(device(), context()); 90 return clDiffer->init(device(), context());
88 } 91 }
92 #endif
89 93
90 static bool init_dummy(SkImageDiffer* differ) { 94 static bool init_dummy(SkImageDiffer* differ) {
91 return true; 95 return true;
92 } 96 }
93 97
94 98
95 // TODO Find a better home for the diff registry. One possibility is to have the differs self 99 // TODO Find a better home for the diff registry. One possibility is to have the differs self
96 // register. 100 // register.
97 101
98 // List here every differ 102 // List here every differ
99 SkDifferentPixelsImageDiffer gDiffPixel; 103 SkDifferentPixelsMetric gDiffPixel;
100 SkPMetric gPDiff; 104 SkPMetric gPDiff;
101 105
102 // A null terminated array of pointer to every differ declared above 106 // A null terminated array of pointer to every differ declared above
103 SkImageDiffer* gDiffers[] = { &gDiffPixel, &gPDiff, NULL }; 107 SkImageDiffer* gDiffers[] = { &gDiffPixel, &gPDiff, NULL };
104 108
105 // A parallel array of functions to initialize the above differs. The reason we don't initialize 109 // A parallel array of functions to initialize the above differs. The reason we don't initialize
106 // everything immediately is that certain differs may require special initializa tion, but we still 110 // everything immediately is that certain differs may require special initializa tion, but we still
107 // want to construct all of them globally so they can be queried for things like their name and 111 // want to construct all of them globally so they can be queried for things like their name and
108 // description. 112 // description.
109 bool (*gDiffInits[])(SkImageDiffer*) = { init_cl_diff, init_dummy, NULL }; 113 bool (*gDiffInits[])(SkImageDiffer*) = {
114 #if SK_SUPPORT_OPENCL
115 init_cl_diff,
djsollen 2013/07/16 20:11:46 why not have skImageDiffer have a static function
116 #else
117 init_dummy,
118 #endif
119 init_dummy,
120 NULL
121 };
110 122
111 123
112 int main(int argc, char** argv) { 124 int main(int argc, char** argv) {
113 // Setup command line parsing 125 // Setup command line parsing
114 SkCommandLineFlags::SetUsage("Compare images using various metrics."); 126 SkCommandLineFlags::SetUsage("Compare images using various metrics.");
115 SkCommandLineFlags::Parse(argc, argv); 127 SkCommandLineFlags::Parse(argc, argv);
116 128
117 // Needed by various Skia components 129 // Needed by various Skia components
118 SkAutoGraphics ag; 130 SkAutoGraphics ag;
119 131
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 192 }
181 193
182 // Output to the file specified 194 // Output to the file specified
183 if (!FLAGS_output.isEmpty()) { 195 if (!FLAGS_output.isEmpty()) {
184 SkFILEWStream outputStream(FLAGS_output[0]); 196 SkFILEWStream outputStream(FLAGS_output[0]);
185 ctx.outputRecords(outputStream, FLAGS_jsonp); 197 ctx.outputRecords(outputStream, FLAGS_jsonp);
186 } 198 }
187 199
188 return 0; 200 return 0;
189 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698