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

Side by Side Diff: tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp

Issue 60833002: fix multithread related crashes in skpdiff (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 #include <cstring> 8 #include <cstring>
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 11
12 #include "SkDifferentPixelsMetric.h" 12 #include "SkDifferentPixelsMetric.h"
13 #include "skpdiff_util.h" 13 #include "skpdiff_util.h"
14 14
15 struct SkDifferentPixelsMetric::QueuedDiff { 15 struct SkDifferentPixelsMetric::QueuedDiff {
16 bool finished; 16 bool finished;
17 double result; 17 double result;
18 SkTDArray<SkIPoint>* poi; 18 SkTDArray<SkIPoint>* poi;
19 }; 19 };
20 20
21 const char* SkDifferentPixelsMetric::getName() { 21 const char* SkDifferentPixelsMetric::getName() {
22 return "different_pixels"; 22 return "different_pixels";
23 } 23 }
24 24
25 int SkDifferentPixelsMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { 25 int SkDifferentPixelsMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) {
26 double startTime = get_seconds(); 26 double startTime = get_seconds();
27
28 // since we currently synchronously do the diff within queueDiff we only nee d
29 // to protect the createion of the ID and queuedDiff object.
30 SkAutoMutexAcquire queueLock(fQueueMutex);
27 int diffID = fQueuedDiffs.count(); 31 int diffID = fQueuedDiffs.count();
28 QueuedDiff* diff = fQueuedDiffs.push(); 32 QueuedDiff* diff = fQueuedDiffs.push();
33 queueLock.release();
34
29 SkTDArray<SkIPoint>* poi = diff->poi = new SkTDArray<SkIPoint>(); 35 SkTDArray<SkIPoint>* poi = diff->poi = new SkTDArray<SkIPoint>();
30 36
31 // If we never end up running the kernel, include some safe defaults in the result. 37 // If we never end up running the kernel, include some safe defaults in the result.
32 diff->finished = false; 38 diff->finished = false;
33 diff->result = -1; 39 diff->result = -1;
34 40
35 // Ensure the images are comparable 41 // Ensure the images are comparable
36 if (baseline->width() != test->width() || baseline->height() != test->height () || 42 if (baseline->width() != test->width() || baseline->height() != test->height () ||
37 baseline->width() <= 0 || baseline->height() <= 0 || 43 baseline->width() <= 0 || baseline->height() <= 0 ||
38 baseline->config() != test->config()) { 44 baseline->config() != test->config()) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return fQueuedDiffs[id].result; 92 return fQueuedDiffs[id].result;
87 } 93 }
88 94
89 int SkDifferentPixelsMetric::getPointsOfInterestCount(int id) { 95 int SkDifferentPixelsMetric::getPointsOfInterestCount(int id) {
90 return fQueuedDiffs[id].poi->count(); 96 return fQueuedDiffs[id].poi->count();
91 } 97 }
92 98
93 SkIPoint* SkDifferentPixelsMetric::getPointsOfInterest(int id) { 99 SkIPoint* SkDifferentPixelsMetric::getPointsOfInterest(int id) {
94 return fQueuedDiffs[id].poi->begin(); 100 return fQueuedDiffs[id].poi->begin();
95 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698