Home | History | Annotate | Download | only in dm
      1 #ifndef DMWriteTask_DEFINED
      2 #define DMWriteTask_DEFINED
      3 
      4 #include "DMExpectations.h"
      5 #include "DMTask.h"
      6 #include "SkBitmap.h"
      7 #include "SkString.h"
      8 #include "SkTArray.h"
      9 
     10 
     11 // Writes a bitmap to a file.
     12 
     13 namespace DM {
     14 
     15 class WriteTask : public CpuTask {
     16 
     17 public:
     18     WriteTask(const Task& parent,  // WriteTask must be a child task.
     19               SkBitmap bitmap);    // Bitmap to encode to PNG and write to disk.
     20 
     21     WriteTask(const Task& parent,   // WriteTask must be a child task.
     22               SkData *data,         // Pre-encoded data to write to disk.
     23               const char* ext);     // File extension.
     24 
     25     virtual void draw() SK_OVERRIDE;
     26     virtual bool shouldSkip() const SK_OVERRIDE;
     27     virtual SkString name() const SK_OVERRIDE;
     28 
     29     // Reads image files WriteTask wrote under root and compares them with bitmap.
     30     class Expectations : public DM::Expectations {
     31     public:
     32         explicit Expectations(const char* root) : fRoot(root) {}
     33 
     34         bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE;
     35     private:
     36         const char* fRoot;
     37     };
     38 
     39 private:
     40     SkTArray<SkString> fSuffixes;
     41     const SkString fGmName;
     42     const SkBitmap fBitmap;
     43     SkAutoTUnref<SkData> fData;
     44     const char* fExtension;
     45 
     46     void makeDirOrFail(SkString dir);
     47 };
     48 
     49 }  // namespace DM
     50 
     51 #endif  // DMWriteTask_DEFINED
     52