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

Side by Side Diff: tools/skpdiff/SkImageDiffer.h

Issue 60833002: fix multithread related crashes in skpdiff (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: addressing comments 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 #ifndef SkImageDiffer_DEFINED 8 #ifndef SkImageDiffer_DEFINED
9 #define SkImageDiffer_DEFINED 9 #define SkImageDiffer_DEFINED
10 10
11 class SkBitmap; 11 #include "SkBitmap.h"
12 struct SkIPoint;
13 12
14 /** 13 /**
15 * Encapsulates an image difference metric algorithm that can be potentially run asynchronously. 14 * Encapsulates an image difference metric algorithm that can be potentially run asynchronously.
16 */ 15 */
17 class SkImageDiffer { 16 class SkImageDiffer {
18 public: 17 public:
19 SkImageDiffer(); 18 SkImageDiffer();
20 virtual ~SkImageDiffer(); 19 virtual ~SkImageDiffer();
21 20
22 static const double RESULT_CORRECT; 21 static const double RESULT_CORRECT;
23 static const double RESULT_INCORRECT; 22 static const double RESULT_INCORRECT;
24 23
24 struct Result {
25 double result;
26 int poiCount;
27 SkBitmap poiAlphaMask; // optional
28 double timeElapsed; // optional
29 };
30
25 /** 31 /**
26 * Gets a unique and descriptive name of this differ 32 * Gets a unique and descriptive name of this differ
27 * @return A statically allocated null terminated string that is the name of this differ 33 * @return A statically allocated null terminated string that is the name of this differ
28 */ 34 */
29 virtual const char* getName() = 0; 35 virtual const char* getName() const = 0;
30
31 /**
32 * Gets if this differ is in a usable state
33 * @return True if this differ can be used, false otherwise
34 */
35 bool isGood() { return fIsGood; }
36 36
37 /** 37 /**
38 * Gets if this differ needs to be initialized with and OpenCL device and co ntext. 38 * Gets if this differ needs to be initialized with and OpenCL device and co ntext.
39 */ 39 */
40 virtual bool requiresOpenCL() { return false; } 40 virtual bool requiresOpenCL() const { return false; }
41 41
42 /** 42 /**
43 * Enables the generation of an alpha mask for all points of interest. 43 * diff on a pair of bitmaps.
44 * @return True if the differ supports generating an alpha mask and false ot herwise. 44 * @param baseline The correct bitmap
45 * @param test The bitmap whose difference is being tested
46 * @param computeMask true if the differ is to attempt to create poiAlphaMa sk
47 * @return true on success, and false in the case of failure
45 */ 48 */
46 virtual bool enablePOIAlphaMask() { return false; } 49 virtual bool diff(SkBitmap* baseline, SkBitmap* test, bool computeMask,
47 50 Result* result) const = 0;
48 /**
49 * Wraps a call to queueDiff by loading the given filenames into SkBitmaps
50 * @param baseline The file path of the baseline image
51 * @param test The file path of the test image
52 * @return The results of queueDiff with the loaded bitmaps
53 */
54 int queueDiffOfFile(const char baseline[], const char test[]);
55
56 /**
57 * Queues a diff on a pair of bitmaps to be done at some future time.
58 * @param baseline The correct bitmap
59 * @param test The bitmap whose difference is being tested
60 * @return An non-negative diff ID on success, a negative integer o n failure.
61 */
62 virtual int queueDiff(SkBitmap* baseline, SkBitmap* test) = 0;
63
64 /**
65 * Gets whether a queued diff of the given id has finished
66 * @param id The id of the queued diff to query
67 * @return True if the queued diff is finished and has results, false oth erwise
68 */
69 virtual bool isFinished(int id) = 0;
70
71 /**
72 * Deletes memory associated with a diff and its results. This may block exe cution until the
73 * diff is finished,
74 * @param id The id of the diff to query
75 */
76 virtual void deleteDiff(int id) = 0;
77
78 /**
79 * Gets the results of the queued diff of the given id. The results are only meaningful after
80 * the queued diff has finished.
81 * @param id The id of the queued diff to query
82 */
83 virtual double getResult(int id) = 0;
84
85 /**
86 * Gets the number of points of interest for the diff of the given id. The r esults are only
87 * meaningful after the queued diff has finished.
88 * @param id The id of the queued diff to query
89 */
90 virtual int getPointsOfInterestCount(int id) = 0;
91
92 /**
93 * Gets an array of the points of interest for the diff of the given id. The results are only
94 * meaningful after the queued diff has finished.
95 * @param id The id of the queued diff to query
96 */
97 virtual SkIPoint* getPointsOfInterest(int id) = 0;
98
99 /*
100 * Gets a bitmap containing an alpha mask containing transparent pixels at t he points of
101 * interest for the diff of the given id. The results are only meaningful af ter the
102 * queued diff has finished.
103 * @param id The id of the queued diff to query
104 */
105 virtual SkBitmap* getPointsOfInterestAlphaMask(int id) { return NULL; }
106
107
108 protected:
109 bool fIsGood;
110 }; 51 };
111 52
112
113 #endif 53 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698