blob: d2403adfc54d2901852819ef31b6d4f5c385b18c [file] [log] [blame]
mtklein@google.coma7a9f372013-10-18 20:52:44 +00001#ifndef DMWriteTask_DEFINED
2#define DMWriteTask_DEFINED
3
4#include "DMTask.h"
5#include "SkBitmap.h"
mtklein1d0f1642014-09-08 08:05:18 -07006#include "SkJSONCPP.h"
7#include "SkStream.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +00008#include "SkString.h"
rmistry@google.comd6bab022013-12-02 13:50:38 +00009#include "SkTArray.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +000010
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000011
mtklein@google.coma7a9f372013-10-18 20:52:44 +000012// Writes a bitmap to a file.
13
14namespace DM {
15
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000016class WriteTask : public CpuTask {
mtklein@google.coma7a9f372013-10-18 20:52:44 +000017
18public:
mtkleinea65bfa2014-09-09 07:59:46 -070019 WriteTask(const Task& parent, // WriteTask must be a child task.
20 const char* sourceType, // E.g. "GM", "SKP". For humans.
21 SkBitmap bitmap); // Bitmap to encode to PNG and write to disk.
mtklein30bf3e22014-06-03 13:57:14 -070022
halcanarya4c60942014-08-26 10:38:07 -070023 // Takes ownership of SkStreamAsset
mtkleinea65bfa2014-09-09 07:59:46 -070024 WriteTask(const Task& parent, // WriteTask must be a child task.
25 const char* sourceType, // E.g. "GM", "SKP". For humans.
26 SkStreamAsset* data, // Pre-encoded data to write to disk.
27 const char* ext); // File extension.
mtklein@google.coma7a9f372013-10-18 20:52:44 +000028
29 virtual void draw() SK_OVERRIDE;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000030 virtual bool shouldSkip() const SK_OVERRIDE;
31 virtual SkString name() const SK_OVERRIDE;
32
mtklein1d0f1642014-09-08 08:05:18 -070033 static void DumpJson();
34
mtklein@google.coma7a9f372013-10-18 20:52:44 +000035private:
rmistry@google.comd6bab022013-12-02 13:50:38 +000036 SkTArray<SkString> fSuffixes;
mtklein1d0f1642014-09-08 08:05:18 -070037 const SkString fBaseName;
mtkleinea65bfa2014-09-09 07:59:46 -070038 const SkString fSourceType;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000039 const SkBitmap fBitmap;
halcanarya4c60942014-08-26 10:38:07 -070040 SkAutoTDelete<SkStreamAsset> fData;
mtklein30bf3e22014-06-03 13:57:14 -070041 const char* fExtension;
rmistry@google.comd6bab022013-12-02 13:50:38 +000042
43 void makeDirOrFail(SkString dir);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000044};
45
46} // namespace DM
47
48#endif // DMWriteTask_DEFINED