This source file includes following definitions.
- ReadTestCase
- RunTestCase
- ReadAndRunTestCase
- main
#include "base/file_util.h"
#include "base/logging.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkFlattenableSerialization.h"
#include "third_party/skia/include/core/SkImageFilter.h"
namespace {
static const int BitmapSize = 24;
bool ReadTestCase(const char* filename, std::string* ipc_filter_message) {
base::FilePath filepath = base::FilePath::FromUTF8Unsafe(filename);
if (!base::ReadFileToString(filepath, ipc_filter_message)) {
LOG(ERROR) << filename << ": couldn't read file.";
return false;
}
return true;
}
void RunTestCase(std::string& ipc_filter_message, SkBitmap& bitmap,
SkCanvas* canvas) {
SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
ipc_filter_message.c_str(), ipc_filter_message.size(),
SkImageFilter::GetFlattenableType());
if (flattenable != NULL) {
LOG(INFO) << "Valid stream detected.";
SkPaint paint;
paint.setImageFilter(static_cast<SkImageFilter*>(flattenable))->unref();
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(
0, 0, SkIntToScalar(BitmapSize), SkIntToScalar(BitmapSize)));
canvas->drawBitmap(bitmap, 0, 0, &paint);
LOG(INFO) << "Filter DAG rendered successfully";
canvas->restore();
} else {
LOG(INFO) << "Invalid stream detected.";
}
}
bool ReadAndRunTestCase(const char* filename, SkBitmap& bitmap,
SkCanvas* canvas) {
std::string ipc_filter_message;
LOG(INFO) << "Test case: " << filename;
if (!ReadTestCase(filename, &ipc_filter_message))
return false;
RunTestCase(ipc_filter_message, bitmap, canvas);
return true;
}
}
int main(int argc, char** argv) {
int ret = 0;
SkBitmap bitmap;
bitmap.allocN32Pixels(BitmapSize, BitmapSize);
SkCanvas canvas(bitmap);
canvas.clear(0x00000000);
for (int i = 1; i < argc; i++)
if (!ReadAndRunTestCase(argv[i], bitmap, &canvas))
ret = 2;
printf("#EOF\n");
return ret;
}