fix multithread related crashes in skpdiff

BUG=skia:1798
R=mtklein@google.com, scroggo@google.com

Review URL: https://codereview.chromium.org/60833002

git-svn-id: http://skia.googlecode.com/svn/trunk@12252 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/skpdiff/SkPMetric.cpp b/tools/skpdiff/SkPMetric.cpp
index 5120e12..22337d8 100644
--- a/tools/skpdiff/SkPMetric.cpp
+++ b/tools/skpdiff/SkPMetric.cpp
@@ -265,7 +265,11 @@
     }
 }
 
-static double pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, SkTDArray<SkIPoint>* poi) {
+static double pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, int* poiCount) {
+    SkASSERT(baselineLAB);
+    SkASSERT(testLAB);
+    SkASSERT(poiCount);
+
     int width = baselineLAB->width;
     int height = baselineLAB->height;
     int maxLevels = 0;
@@ -329,7 +333,6 @@
                                                contrast_sensitivity(cpd, 100.0f);
     }
 
-    int failures = 0;
     // Calculate F
     for (int y = 0; y < height; y++) {
         for (int x = 0; x < width; x++) {
@@ -424,8 +427,7 @@
             }
 
             if (isFailure) {
-                failures++;
-                poi->push()->set(x, y);
+                (*poiCount)++;
             }
         }
     }
@@ -434,57 +436,28 @@
     SkDELETE_ARRAY(contrast);
     SkDELETE_ARRAY(thresholdFactorFrequency);
     SkDELETE_ARRAY(contrastSensitivityTable);
-    return 1.0 - (double)failures / (width * height);
+    return 1.0 - (double)(*poiCount) / (width * height);
 }
 
-const char* SkPMetric::getName() {
-    return "perceptual";
-}
-
-int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) {
+bool SkPMetric::diff(SkBitmap* baseline, SkBitmap* test, bool computeMask, Result* result) const {
     double startTime = get_seconds();
-    int diffID = fQueuedDiffs.count();
-    QueuedDiff& diff = fQueuedDiffs.push_back();
-    diff.result = 0.0;
 
     // Ensure the images are comparable
     if (baseline->width() != test->width() || baseline->height() != test->height() ||
                     baseline->width() <= 0 || baseline->height() <= 0) {
-        diff.finished = true;
-        return diffID;
+        return false;
     }
 
     ImageLAB baselineLAB(baseline->width(), baseline->height());
     ImageLAB testLAB(baseline->width(), baseline->height());
 
     if (!bitmap_to_cielab(baseline, &baselineLAB) || !bitmap_to_cielab(test, &testLAB)) {
-        return diffID;
+        return true;
     }
 
-    diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi);
+    result->poiCount = 0;
+    result->result = pmetric(&baselineLAB, &testLAB, &result->poiCount);
+    result->timeElapsed = get_seconds() - startTime;
 
-    SkDebugf("Time: %f\n", (get_seconds() - startTime));
-
-    return diffID;
-}
-
-
-void SkPMetric::deleteDiff(int id) {
-
-}
-
-bool SkPMetric::isFinished(int id) {
-    return fQueuedDiffs[id].finished;
-}
-
-double SkPMetric::getResult(int id) {
-    return fQueuedDiffs[id].result;
-}
-
-int SkPMetric::getPointsOfInterestCount(int id) {
-    return fQueuedDiffs[id].poi.count();
-}
-
-SkIPoint* SkPMetric::getPointsOfInterest(int id) {
-    return fQueuedDiffs[id].poi.begin();
+    return true;
 }