blob: fad9262c33193ea5881620b93c43d60be524bbcb [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"
mtklein1d0f1642014-09-08 08:05:18 -07007#include "SkJSONCPP.h"
8#include "SkStream.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +00009#include "SkString.h"
rmistry@google.comd6bab022013-12-02 13:50:38 +000010#include "SkTArray.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +000011
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000012
mtklein@google.coma7a9f372013-10-18 20:52:44 +000013// Writes a bitmap to a file.
14
15namespace DM {
16
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000017class WriteTask : public CpuTask {
mtklein@google.coma7a9f372013-10-18 20:52:44 +000018
19public:
mtklein30bf3e22014-06-03 13:57:14 -070020 WriteTask(const Task& parent, // WriteTask must be a child task.
21 SkBitmap bitmap); // Bitmap to encode to PNG and write to disk.
22
halcanarya4c60942014-08-26 10:38:07 -070023 // Takes ownership of SkStreamAsset
mtklein30bf3e22014-06-03 13:57:14 -070024 WriteTask(const Task& parent, // WriteTask must be a child task.
halcanarya4c60942014-08-26 10:38:07 -070025 SkStreamAsset* data, // Pre-encoded data to write to disk.
mtklein30bf3e22014-06-03 13:57:14 -070026 const char* ext); // File extension.
mtklein@google.coma7a9f372013-10-18 20:52:44 +000027
28 virtual void draw() SK_OVERRIDE;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000029 virtual bool shouldSkip() const SK_OVERRIDE;
30 virtual SkString name() const SK_OVERRIDE;
31
mtklein1d0f1642014-09-08 08:05:18 -070032 // Reads JSON file WriteTask wrote under root and compares the bitmap with checksums inside.
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000033 class Expectations : public DM::Expectations {
34 public:
mtklein1d0f1642014-09-08 08:05:18 -070035 static Expectations* Create(const char*);
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000036 bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE;
37 private:
mtklein1d0f1642014-09-08 08:05:18 -070038 Expectations() {}
39 Json::Value fJson;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000040 };
41
mtklein1d0f1642014-09-08 08:05:18 -070042 static void DumpJson();
43
mtklein@google.coma7a9f372013-10-18 20:52:44 +000044private:
rmistry@google.comd6bab022013-12-02 13:50:38 +000045 SkTArray<SkString> fSuffixes;
mtklein1d0f1642014-09-08 08:05:18 -070046 const SkString fFullName;
47 const SkString fBaseName;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000048 const SkBitmap fBitmap;
halcanarya4c60942014-08-26 10:38:07 -070049 SkAutoTDelete<SkStreamAsset> fData;
mtklein30bf3e22014-06-03 13:57:14 -070050 const char* fExtension;
rmistry@google.comd6bab022013-12-02 13:50:38 +000051
52 void makeDirOrFail(SkString dir);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000053};
54
55} // namespace DM
56
57#endif // DMWriteTask_DEFINED