blob: 15e1300af2d2106921e0d0c10eab32e5891a8577 [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:
mtklein30bf3e22014-06-03 13:57:14 -070018 WriteTask(const Task& parent, // WriteTask must be a child task.
19 SkBitmap bitmap); // Bitmap to encode to PNG and write to disk.
20
halcanarya4c60942014-08-26 10:38:07 -070021 // Takes ownership of SkStreamAsset
mtklein30bf3e22014-06-03 13:57:14 -070022 WriteTask(const Task& parent, // WriteTask must be a child task.
halcanarya4c60942014-08-26 10:38:07 -070023 SkStreamAsset* data, // Pre-encoded data to write to disk.
mtklein30bf3e22014-06-03 13:57:14 -070024 const char* ext); // File extension.
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;
mtklein30bf3e22014-06-03 13:57:14 -070042 const SkString fGmName;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000043 const SkBitmap fBitmap;
halcanarya4c60942014-08-26 10:38:07 -070044 SkAutoTDelete<SkStreamAsset> fData;
mtklein30bf3e22014-06-03 13:57:14 -070045 const char* fExtension;
rmistry@google.comd6bab022013-12-02 13:50:38 +000046
47 void makeDirOrFail(SkString dir);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000048};
49
50} // namespace DM
51
52#endif // DMWriteTask_DEFINED