OLD | NEW |
1 #ifndef DMWriteTask_DEFINED | 1 #ifndef DMWriteTask_DEFINED |
2 #define DMWriteTask_DEFINED | 2 #define DMWriteTask_DEFINED |
3 | 3 |
4 #include "DMExpectations.h" | |
5 #include "DMTask.h" | 4 #include "DMTask.h" |
6 #include "SkBitmap.h" | 5 #include "SkBitmap.h" |
7 #include "SkJSONCPP.h" | 6 #include "SkJSONCPP.h" |
8 #include "SkStream.h" | 7 #include "SkStream.h" |
9 #include "SkString.h" | 8 #include "SkString.h" |
10 #include "SkTArray.h" | 9 #include "SkTArray.h" |
11 | 10 |
12 | 11 |
13 // Writes a bitmap to a file. | 12 // Writes a bitmap to a file. |
14 | 13 |
15 namespace DM { | 14 namespace DM { |
16 | 15 |
17 class WriteTask : public CpuTask { | 16 class WriteTask : public CpuTask { |
18 | 17 |
19 public: | 18 public: |
20 WriteTask(const Task& parent, // WriteTask must be a child task. | 19 WriteTask(const Task& parent, // WriteTask must be a child task. |
21 SkBitmap bitmap); // Bitmap to encode to PNG and write to disk. | 20 SkBitmap bitmap); // Bitmap to encode to PNG and write to disk. |
22 | 21 |
23 // Takes ownership of SkStreamAsset | 22 // Takes ownership of SkStreamAsset |
24 WriteTask(const Task& parent, // WriteTask must be a child task. | 23 WriteTask(const Task& parent, // WriteTask must be a child task. |
25 SkStreamAsset* data, // Pre-encoded data to write to disk. | 24 SkStreamAsset* data, // Pre-encoded data to write to disk. |
26 const char* ext); // File extension. | 25 const char* ext); // File extension. |
27 | 26 |
28 virtual void draw() SK_OVERRIDE; | 27 virtual void draw() SK_OVERRIDE; |
29 virtual bool shouldSkip() const SK_OVERRIDE; | 28 virtual bool shouldSkip() const SK_OVERRIDE; |
30 virtual SkString name() const SK_OVERRIDE; | 29 virtual SkString name() const SK_OVERRIDE; |
31 | 30 |
32 // Reads JSON file WriteTask wrote under root and compares the bitmap with c
hecksums inside. | |
33 class Expectations : public DM::Expectations { | |
34 public: | |
35 static Expectations* Create(const char*); | |
36 bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE; | |
37 private: | |
38 Expectations() {} | |
39 Json::Value fJson; | |
40 }; | |
41 | |
42 static void DumpJson(); | 31 static void DumpJson(); |
43 | 32 |
44 private: | 33 private: |
45 SkTArray<SkString> fSuffixes; | 34 SkTArray<SkString> fSuffixes; |
46 const SkString fFullName; | 35 const SkString fFullName; |
47 const SkString fBaseName; | 36 const SkString fBaseName; |
48 const SkBitmap fBitmap; | 37 const SkBitmap fBitmap; |
49 SkAutoTDelete<SkStreamAsset> fData; | 38 SkAutoTDelete<SkStreamAsset> fData; |
50 const char* fExtension; | 39 const char* fExtension; |
51 | 40 |
52 void makeDirOrFail(SkString dir); | 41 void makeDirOrFail(SkString dir); |
53 }; | 42 }; |
54 | 43 |
55 } // namespace DM | 44 } // namespace DM |
56 | 45 |
57 #endif // DMWriteTask_DEFINED | 46 #endif // DMWriteTask_DEFINED |
OLD | NEW |