mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 1 | #ifndef DMWriteTask_DEFINED |
| 2 | #define DMWriteTask_DEFINED |
| 3 | |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 4 | #include "DMExpectations.h" |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 5 | #include "DMTask.h" |
| 6 | #include "SkBitmap.h" |
| 7 | #include "SkString.h" |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 8 | #include "SkTArray.h" |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 9 | |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 10 | |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 11 | // Writes a bitmap to a file. |
| 12 | |
| 13 | namespace DM { |
| 14 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 15 | class WriteTask : public CpuTask { |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 16 | |
| 17 | public: |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 18 | WriteTask(const Task& parent, // WriteTask must be a child task. |
| 19 | SkBitmap bitmap); // Bitmap to encode to PNG and write to disk. |
| 20 | |
halcanary | a4c6094 | 2014-08-26 10:38:07 -0700 | [diff] [blame] | 21 | // Takes ownership of SkStreamAsset |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 22 | WriteTask(const Task& parent, // WriteTask must be a child task. |
halcanary | a4c6094 | 2014-08-26 10:38:07 -0700 | [diff] [blame] | 23 | SkStreamAsset* data, // Pre-encoded data to write to disk. |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 24 | const char* ext); // File extension. |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 25 | |
| 26 | virtual void draw() SK_OVERRIDE; |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 27 | virtual bool shouldSkip() const SK_OVERRIDE; |
| 28 | virtual SkString name() const SK_OVERRIDE; |
| 29 | |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 30 | // Reads image files WriteTask wrote under root and compares them with bitmap. |
| 31 | class Expectations : public DM::Expectations { |
| 32 | public: |
| 33 | explicit Expectations(const char* root) : fRoot(root) {} |
| 34 | |
| 35 | bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE; |
| 36 | private: |
| 37 | const char* fRoot; |
| 38 | }; |
| 39 | |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 40 | private: |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 41 | SkTArray<SkString> fSuffixes; |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 42 | const SkString fGmName; |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 43 | const SkBitmap fBitmap; |
halcanary | a4c6094 | 2014-08-26 10:38:07 -0700 | [diff] [blame] | 44 | SkAutoTDelete<SkStreamAsset> fData; |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 45 | const char* fExtension; |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 46 | |
| 47 | void makeDirOrFail(SkString dir); |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | } // namespace DM |
| 51 | |
| 52 | #endif // DMWriteTask_DEFINED |