blob: c6ef1cb20b9df41993e6dccb083e413db4955d4d [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 "SkStream.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +00007#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:
mtkleinea65bfa2014-09-09 07:59:46 -070018 WriteTask(const Task& parent, // WriteTask must be a child task.
19 const char* sourceType, // E.g. "GM", "SKP". For humans.
20 SkBitmap bitmap); // Bitmap to encode to PNG and write to disk.
mtklein30bf3e22014-06-03 13:57:14 -070021
halcanarya4c60942014-08-26 10:38:07 -070022 // Takes ownership of SkStreamAsset
mtkleinea65bfa2014-09-09 07:59:46 -070023 WriteTask(const Task& parent, // WriteTask must be a child task.
24 const char* sourceType, // E.g. "GM", "SKP". For humans.
25 SkStreamAsset* data, // Pre-encoded data to write to disk.
26 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
32private:
rmistry@google.comd6bab022013-12-02 13:50:38 +000033 SkTArray<SkString> fSuffixes;
mtklein1d0f1642014-09-08 08:05:18 -070034 const SkString fBaseName;
mtkleinea65bfa2014-09-09 07:59:46 -070035 const SkString fSourceType;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000036 const SkBitmap fBitmap;
halcanarya4c60942014-08-26 10:38:07 -070037 SkAutoTDelete<SkStreamAsset> fData;
mtklein30bf3e22014-06-03 13:57:14 -070038 const char* fExtension;
rmistry@google.comd6bab022013-12-02 13:50:38 +000039
40 void makeDirOrFail(SkString dir);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000041};
42
43} // namespace DM
44
45#endif // DMWriteTask_DEFINED