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 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 | 9 |
10 #include "SkDifferentPixelsMetric.h" | 10 #include "SkDifferentPixelsMetric.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 cl_mem test; | 41 cl_mem test; |
42 cl_mem resultsBuffer; | 42 cl_mem resultsBuffer; |
43 cl_mem poiBuffer; | 43 cl_mem poiBuffer; |
44 }; | 44 }; |
45 | 45 |
46 const char* SkDifferentPixelsMetric::getName() { | 46 const char* SkDifferentPixelsMetric::getName() { |
47 return "different_pixels"; | 47 return "different_pixels"; |
48 } | 48 } |
49 | 49 |
50 int SkDifferentPixelsMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { | 50 int SkDifferentPixelsMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { |
51 double startTime = get_seconds(); | |
52 | |
53 // since we currently synchronously do the diff within queueDiff we only nee d | |
54 // to protect the createion of the ID and queuedDiff object. | |
55 SkAutoMutexAcquire queueLock(fQueueMutex); | |
51 int diffID = fQueuedDiffs.count(); | 56 int diffID = fQueuedDiffs.count(); |
52 double startTime = get_seconds(); | |
53 QueuedDiff* diff = fQueuedDiffs.push(); | 57 QueuedDiff* diff = fQueuedDiffs.push(); |
58 queueLock.release(); | |
54 | 59 |
55 // If we never end up running the kernel, include some safe defaults in the result. | 60 // If we never end up running the kernel, include some safe defaults in the result. |
56 diff->finished = false; | 61 diff->finished = false; |
57 diff->result = -1.0; | 62 diff->result = -1.0; |
58 diff->numDiffPixels = 0; | 63 diff->numDiffPixels = 0; |
59 diff->poi = NULL; | 64 diff->poi = NULL; |
60 | 65 |
61 // Ensure the images are comparable | 66 // Ensure the images are comparable |
62 if (baseline->width() != test->width() || baseline->height() != test->height () || | 67 if (baseline->width() != test->width() || baseline->height() != test->height () || |
63 baseline->width() <= 0 || baseline->height() <= 0 || | 68 baseline->width() <= 0 || baseline->height() <= 0 || |
64 baseline->config() != test->config()) { | 69 baseline->config() != test->config()) { |
65 diff->finished = true; | 70 diff->finished = true; |
66 return diffID; | 71 return diffID; |
67 } | 72 } |
68 | 73 |
69 // Upload images to the CL device | 74 // Upload images to the CL device |
70 if (!this->makeImage2D(baseline, &diff->baseline) || !this->makeImage2D(test , &diff->test)) { | 75 if (!this->makeImage2D(baseline, &diff->baseline) || !this->makeImage2D(test , &diff->test)) { |
71 diff->finished = true; | 76 diff->finished = true; |
72 fIsGood = false; | 77 fIsGood = false; |
mtklein
2013/11/06 14:24:36
I doubt it's going to cause much trouble, but fIsG
djsollen
2013/11/06 15:01:58
Yes, it currently isn't read by anything so I was
| |
73 return -1; | 78 return -1; |
74 } | 79 } |
75 | 80 |
76 // A small hack that makes calculating percentage difference easier later on . | 81 // A small hack that makes calculating percentage difference easier later on . |
77 diff->result = 1.0 / ((double)baseline->width() * baseline->height()); | 82 diff->result = 1.0 / ((double)baseline->width() * baseline->height()); |
78 | 83 |
79 // Make a buffer to store results into. It must be initialized with pointers to memory. | 84 // Make a buffer to store results into. It must be initialized with pointers to memory. |
80 static const int kZero = 0; | 85 static const int kZero = 0; |
81 // We know OpenCL won't write to it because we use CL_MEM_COPY_HOST_PTR | 86 // We know OpenCL won't write to it because we use CL_MEM_COPY_HOST_PTR |
82 diff->resultsBuffer = clCreateBuffer(fContext, CL_MEM_READ_WRITE | CL_MEM_CO PY_HOST_PTR, | 87 diff->resultsBuffer = clCreateBuffer(fContext, CL_MEM_READ_WRITE | CL_MEM_CO PY_HOST_PTR, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 return fQueuedDiffs[id].poi; | 166 return fQueuedDiffs[id].poi; |
162 } | 167 } |
163 | 168 |
164 bool SkDifferentPixelsMetric::onInit() { | 169 bool SkDifferentPixelsMetric::onInit() { |
165 if (!this->loadKernelSource(kDifferentPixelsKernelSource, "diff", &fKernel)) { | 170 if (!this->loadKernelSource(kDifferentPixelsKernelSource, "diff", &fKernel)) { |
166 return false; | 171 return false; |
167 } | 172 } |
168 | 173 |
169 return true; | 174 return true; |
170 } | 175 } |
OLD | NEW |