skia2/dm/DMExpectations.h
scroggo f01a6c3663 In Android framework, make tools depend on jsoncpp
Always build the tools with JSON, but either build our own
or use the system's.

Rename skia_build_json_writer to skia_use_system_jsoncpp,
since we now always build with JSON.

Remove SK_BUILD_JSON_WRITER, which was only there so
we could build without JSON it in the framework.

BUG=skia:2448
R=djsollen@google.com, reed@google.com

Author: scroggo@google.com

Review URL: https://codereview.chromium.org/303913002
2014-06-18 10:31:40 -07:00

47 lines
1.2 KiB
C++

#ifndef DMExpectations_DEFINED
#define DMExpectations_DEFINED
#include "DMTask.h"
#include "gm_expectations.h"
namespace DM {
struct Expectations {
virtual ~Expectations() {}
// Return true if bitmap is the correct output for task, else false.
virtual bool check(const Task& task, SkBitmap bitmap) const = 0;
};
class NoExpectations : public Expectations {
public:
NoExpectations() {}
bool check(const Task&, SkBitmap) const SK_OVERRIDE { return true; }
};
class JsonExpectations : public Expectations {
public:
explicit JsonExpectations(const char* path) : fGMExpectations(path) {}
bool check(const Task& task, SkBitmap bitmap) const SK_OVERRIDE {
SkString filename = task.name();
filename.append(".png");
const skiagm::Expectations expectations = fGMExpectations.get(filename.c_str());
if (expectations.ignoreFailure() || expectations.empty()) {
return true;
}
// Delay this calculation as long as possible. It's expensive.
const skiagm::GmResultDigest digest(bitmap);
return expectations.match(digest);
}
private:
skiagm::JsonExpectationsSource fGMExpectations;
};
} // namespace DM
#endif // DMExpectations_DEFINED