| caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 1 | #include "SkBitmap.h"
|
| 2 | #include "SkDevice.h"
|
| 3 | #include "SkCanvas.h"
|
| 4 | #include "SkImageEncoder.h"
|
| 5 | #include "SkStream.h"
|
| 6 | #include "SkOSFile.h"
|
| 7 | #include "SkPicture.h"
|
| 8 | #include "SkString.h"
|
| 9 | #include "Test.h"
|
| 10 |
|
| 11 | static void make_filepath(SkString* path, const char* dir, const SkString& name) {
|
| 12 | size_t len = strlen(dir);
|
| 13 | path->set(dir);
|
| 14 | if (len > 0 && dir[len - 1] != '/') {
|
| 15 | path->append("\\");
|
| 16 | }
|
| 17 | path->append(name);
|
| 18 | }
|
| 19 |
|
| 20 | static void PathOpsSkpClipTest(skiatest::Reporter* reporter) {
|
| 21 | const char pictDir[] = "C:\\Users\\caryclark\\skp";
|
| 22 | const char outSkpClipDir[] = "C:\\Users\\caryclark\\skpClip";
|
| 23 | const char outOldClipDir[] = "C:\\Users\\caryclark\\oldClip";
|
| 24 | SkOSFile::Iter iter(pictDir, "skp");
|
| 25 | SkString filename;
|
| 26 | while (iter.next(&filename)) {
|
| 27 | #if 0
|
| 28 | if (strcmp(filename.c_str(), "tabl_androidpolice.skp")) {
|
| 29 | continue;
|
| 30 | }
|
| 31 | #endif
|
| 32 | SkString path;
|
| 33 | make_filepath(&path, pictDir, filename);
|
| 34 | SkFILEStream stream(path.c_str());
|
| 35 | if (!stream.isValid()) {
|
| 36 | continue;
|
| 37 | }
|
| 38 | SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream));
|
| 39 | int width = pic->width();
|
| 40 | int height = pic->height();
|
| 41 | SkBitmap bitmap;
|
| 42 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
| 43 | bitmap.allocPixels();
|
| 44 | SkCanvas canvas(bitmap);
|
| 45 | filename.remove(filename.size() - 3, 3);
|
| 46 | filename.append("png");
|
| 47 | for (int i = 0; i < 2; ++i) {
|
| 48 | bool useOp = i ? true : false;
|
| 49 | canvas.setAllowSimplifyClip(useOp);
|
| 50 | pic->draw(&canvas);
|
| 51 | SkString outFile;
|
| 52 | make_filepath(&outFile, useOp ? outSkpClipDir : outOldClipDir, filename);
|
| 53 | SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
|
| 54 | }
|
| 55 | SkDELETE(pic);
|
| 56 | reporter->bumpTestCount();
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | #include "TestClassDef.h"
|
| 61 | DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest)
|