blob: c2c1d9fd4773641b926dfdce1bf304a7e2c1d652 [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
21 WriteTask(const Task& parent, // WriteTask must be a child task.
22 SkData *data, // Pre-encoded data to write to disk.
23 const char* ext); // File extension.
mtklein@google.coma7a9f372013-10-18 20:52:44 +000024
25 virtual void draw() SK_OVERRIDE;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000026 virtual bool shouldSkip() const SK_OVERRIDE;
27 virtual SkString name() const SK_OVERRIDE;
28
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000029 // Reads image files WriteTask wrote under root and compares them with bitmap.
30 class Expectations : public DM::Expectations {
31 public:
32 explicit Expectations(const char* root) : fRoot(root) {}
33
34 bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE;
35 private:
36 const char* fRoot;
37 };
38
mtklein@google.coma7a9f372013-10-18 20:52:44 +000039private:
rmistry@google.comd6bab022013-12-02 13:50:38 +000040 SkTArray<SkString> fSuffixes;
mtklein30bf3e22014-06-03 13:57:14 -070041 const SkString fGmName;
mtklein@google.coma7a9f372013-10-18 20:52:44 +000042 const SkBitmap fBitmap;
mtklein30bf3e22014-06-03 13:57:14 -070043 SkAutoTUnref<SkData> fData;
44 const char* fExtension;
rmistry@google.comd6bab022013-12-02 13:50:38 +000045
46 void makeDirOrFail(SkString dir);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000047};
48
49} // namespace DM
50
51#endif // DMWriteTask_DEFINED