Home | History | Annotate | Download | only in skpdiff
      1 /*
      2  * Copyright 2013 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkImageDiffer_DEFINED
      9 #define SkImageDiffer_DEFINED
     10 
     11 class SkBitmap;
     12 struct SkIPoint;
     13 
     14 /**
     15  * Encapsulates an image difference metric algorithm that can be potentially run asynchronously.
     16  */
     17 class SkImageDiffer {
     18 public:
     19     SkImageDiffer();
     20     virtual ~SkImageDiffer();
     21 
     22     /**
     23      * Gets a unique and descriptive name of this differ
     24      * @return A statically allocated null terminated string that is the name of this differ
     25      */
     26     virtual const char* getName() = 0;
     27 
     28     /**
     29      * Gets if this differ is in a usable state
     30      * @return True if this differ can be used, false otherwise
     31      */
     32     bool isGood() { return fIsGood; }
     33 
     34     /**
     35      * Gets if this differ needs to be initialized with and OpenCL device and context.
     36      */
     37     virtual bool requiresOpenCL() { return false; }
     38 
     39     /**
     40      * Wraps a call to queueDiff by loading the given filenames into SkBitmaps
     41      * @param  baseline The file path of the baseline image
     42      * @param  test     The file path of the test image
     43      * @return          The results of queueDiff with the loaded bitmaps
     44      */
     45     int queueDiffOfFile(const char baseline[], const char test[]);
     46 
     47     /**
     48      * Queues a diff on a pair of bitmaps to be done at some future time.
     49      * @param  baseline The correct bitmap
     50      * @param  test     The bitmap whose difference is being tested
     51      * @return          An non-negative diff ID on success, a negative integer on failure.
     52      */
     53     virtual int queueDiff(SkBitmap* baseline, SkBitmap* test) = 0;
     54 
     55     /**
     56      * Gets whether a queued diff of the given id has finished
     57      * @param  id The id of the queued diff to query
     58      * @return    True if the queued diff is finished and has results, false otherwise
     59      */
     60     virtual bool isFinished(int id) = 0;
     61 
     62     /**
     63      * Deletes memory associated with a diff and its results. This may block execution until the
     64      * diff is finished,
     65      * @param id The id of the diff to query
     66      */
     67     virtual void deleteDiff(int id) = 0;
     68 
     69     /**
     70      * Gets the results of the queued diff of the given id. The results are only meaningful after
     71      * the queued diff has finished.
     72      * @param  id The id of the queued diff to query
     73      */
     74     virtual double getResult(int id) = 0;
     75 
     76     /**
     77      * Gets the number of points of interest for the diff of the given id. The results are only
     78      * meaningful after the queued diff has finished.
     79      * @param  id The id of the queued diff to query
     80      */
     81     virtual int getPointsOfInterestCount(int id) = 0;
     82 
     83     /**
     84      * Gets an array of the points of interest for the diff of the given id. The results are only
     85      * meaningful after the queued diff has finished.
     86      * @param  id The id of the queued diff to query
     87      */
     88     virtual SkIPoint* getPointsOfInterest(int id) = 0;
     89 
     90 
     91 
     92 protected:
     93     bool fIsGood;
     94 };
     95 
     96 
     97 #endif
     98