blob: 121dc0d13e4e0d3df77f7cd6760c44259b3c495a [file] [log] [blame]
mtklein@google.coma7a9f372013-10-18 20:52:44 +00001#ifndef DMWriteTask_DEFINED
2#define DMWriteTask_DEFINED
3
commit-bot@chromium.org99589af2013-12-10 14:53:16 +00004#include "DMExpectations.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +00005#include "DMTask.h"
6#include "SkBitmap.h"
7#include "SkString.h"
rmistry@google.comd6bab022013-12-02 13:50:38 +00008#include "SkTArray.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +00009
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000010
mtklein@google.coma7a9f372013-10-18 20:52:44 +000011// Writes a bitmap to a file.
12
13namespace DM {
14
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000015class WriteTask : public CpuTask {
mtklein@google.coma7a9f372013-10-18 20:52:44 +000016
17public:
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000018 enum Mode {
19 kParseName_Mode, // Parse the parent's name into directories by underscores.
20 kVerbatim_Mode, // Don't parse the name at all.
21 };
22 WriteTask(const Task& parent, // WriteTask must be a child Task. Pass its parent here.
23 SkBitmap bitmap, // Bitmap to write.
24 Mode = kParseName_Mode);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000025
26 virtual void draw() SK_OVERRIDE;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000027 virtual bool shouldSkip() const SK_OVERRIDE;
28 virtual SkString name() const SK_OVERRIDE;
29
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000030 // 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.coma7a9f372013-10-18 20:52:44 +000040private:
rmistry@google.comd6bab022013-12-02 13:50:38 +000041 SkTArray<SkString> fSuffixes;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000042 SkString fGmName;
43 const SkBitmap fBitmap;
rmistry@google.comd6bab022013-12-02 13:50:38 +000044
45 void makeDirOrFail(SkString dir);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000046};
47
48} // namespace DM
49
50#endif // DMWriteTask_DEFINED