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

Side by Side Diff: tools/skpdiff/SkPMetric.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
« tools/skpdiff/SkImageDiffer.h ('K') | « tools/skpdiff/SkImageDiffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <cmath> 1 #include <cmath>
2 2
3 #include "SkBitmap.h" 3 #include "SkBitmap.h"
4 #include "skpdiff_util.h" 4 #include "skpdiff_util.h"
5 #include "SkPMetric.h" 5 #include "SkPMetric.h"
6 #include "SkPMetricUtil_generated.h" 6 #include "SkPMetricUtil_generated.h"
7 7
8 struct RGB { 8 struct RGB {
9 float r, g, b; 9 float r, g, b;
10 }; 10 };
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 SkDELETE_ARRAY(contrastSensitivityTable); 423 SkDELETE_ARRAY(contrastSensitivityTable);
424 return 1.0 - (double)failures / (width * height); 424 return 1.0 - (double)failures / (width * height);
425 } 425 }
426 426
427 const char* SkPMetric::getName() { 427 const char* SkPMetric::getName() {
428 return "perceptual"; 428 return "perceptual";
429 } 429 }
430 430
431 int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { 431 int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) {
432 double startTime = get_seconds(); 432 double startTime = get_seconds();
433
434 // since we currently synchronously do the diff within queueDiff we only nee d
435 // to protect the createion of the ID and queuedDiff object.
436 SkAutoMutexAcquire queueLock(fQueueMutex);
433 int diffID = fQueuedDiffs.count(); 437 int diffID = fQueuedDiffs.count();
434 QueuedDiff& diff = fQueuedDiffs.push_back(); 438 QueuedDiff& diff = fQueuedDiffs.push_back();
439 queueLock.release();
440
435 diff.result = 0.0; 441 diff.result = 0.0;
436 442
437 // Ensure the images are comparable 443 // Ensure the images are comparable
438 if (baseline->width() != test->width() || baseline->height() != test->height () || 444 if (baseline->width() != test->width() || baseline->height() != test->height () ||
439 baseline->width() <= 0 || baseline->height() <= 0) { 445 baseline->width() <= 0 || baseline->height() <= 0) {
440 diff.finished = true; 446 diff.finished = true;
441 return diffID; 447 return diffID;
442 } 448 }
443 449
444 ImageLAB baselineLAB(baseline->width(), baseline->height()); 450 ImageLAB baselineLAB(baseline->width(), baseline->height());
445 ImageLAB testLAB(baseline->width(), baseline->height()); 451 ImageLAB testLAB(baseline->width(), baseline->height());
446 452
447 bitmap_to_cielab(baseline, &baselineLAB); 453 bitmap_to_cielab(baseline, &baselineLAB);
448 bitmap_to_cielab(test, &testLAB); 454 bitmap_to_cielab(test, &testLAB);
449 455
450 diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi); 456 diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi);
451 457
452 SkDebugf("Time: %f\n", (get_seconds() - startTime)); 458 SkDebugf("Time: %f\n", (get_seconds() - startTime));
453 459
454 return diffID; 460 return diffID;
455 } 461 }
456 462
457 463
458 void SkPMetric::deleteDiff(int id) { 464 void SkPMetric::deleteDiff(int id) {
459 465 // clean up the POI array to save space
466 return fQueuedDiffs[id].poi.reset();
460 } 467 }
461 468
462 bool SkPMetric::isFinished(int id) { 469 bool SkPMetric::isFinished(int id) {
463 return fQueuedDiffs[id].finished; 470 return fQueuedDiffs[id].finished;
464 } 471 }
465 472
466 double SkPMetric::getResult(int id) { 473 double SkPMetric::getResult(int id) {
467 return fQueuedDiffs[id].result; 474 return fQueuedDiffs[id].result;
468 } 475 }
469 476
470 int SkPMetric::getPointsOfInterestCount(int id) { 477 int SkPMetric::getPointsOfInterestCount(int id) {
471 return fQueuedDiffs[id].poi.count(); 478 return fQueuedDiffs[id].poi.count();
472 } 479 }
473 480
474 SkIPoint* SkPMetric::getPointsOfInterest(int id) { 481 SkIPoint* SkPMetric::getPointsOfInterest(int id) {
475 return fQueuedDiffs[id].poi.begin(); 482 return fQueuedDiffs[id].poi.begin();
476 } 483 }
OLDNEW
« tools/skpdiff/SkImageDiffer.h ('K') | « tools/skpdiff/SkImageDiffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698