OLD | NEW |
1 #include "DMUtil.h" | 1 #include "DMUtil.h" |
2 | 2 |
3 #include "SkPicture.h" | 3 #include "SkPicture.h" |
4 | 4 |
5 namespace DM { | 5 namespace DM { |
6 | 6 |
7 SkString UnderJoin(const char* a, const char* b) { | 7 SkString UnderJoin(const char* a, const char* b) { |
8 SkString s; | 8 SkString s; |
9 s.appendf("%s_%s", a, b); | 9 s.appendf("%s_%s", a, b); |
10 return s; | 10 return s; |
11 } | 11 } |
12 | 12 |
13 SkString Png(SkString s) { | 13 SkString Png(SkString s) { |
14 s.appendf(".png"); | 14 s.appendf(".png"); |
15 return s; | 15 return s; |
16 } | 16 } |
17 | 17 |
18 bool MeetsExpectations(const skiagm::Expectations& expectations, const SkBitmap
bitmap) { | 18 bool MeetsExpectations(const skiagm::Expectations& expectations, const SkBitmap
bitmap) { |
19 if (expectations.ignoreFailure() || expectations.empty()) { | 19 if (expectations.ignoreFailure() || expectations.empty()) { |
20 return true; | 20 return true; |
21 } | 21 } |
22 const skiagm::GmResultDigest digest(bitmap); | 22 const skiagm::GmResultDigest digest(bitmap); |
23 return expectations.match(digest); | 23 return expectations.match(digest); |
24 } | 24 } |
25 | 25 |
26 void RecordPicture(skiagm::GM* gm, SkPicture* picture) { | 26 void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags) { |
27 SkCanvas* canvas = picture->beginRecording(SkScalarCeilToInt(gm->width()), | 27 SkCanvas* canvas = picture->beginRecording(SkScalarCeilToInt(gm->width()), |
28 SkScalarCeilToInt(gm->height()), | 28 SkScalarCeilToInt(gm->height()), |
29 0 /*flags*/); | 29 recordFlags); |
30 canvas->concat(gm->getInitialTransform()); | 30 canvas->concat(gm->getInitialTransform()); |
31 gm->draw(canvas); | 31 gm->draw(canvas); |
32 canvas->flush(); | 32 canvas->flush(); |
33 picture->endRecording(); | 33 picture->endRecording(); |
34 } | 34 } |
35 | 35 |
36 void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap
) { | 36 void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap
) { |
37 bitmap->setConfig(config, SkScalarCeilToInt(gm->width()), SkScalarCeilToInt(
gm->height())); | 37 bitmap->setConfig(config, SkScalarCeilToInt(gm->width()), SkScalarCeilToInt(
gm->height())); |
38 bitmap->allocPixels(); | 38 bitmap->allocPixels(); |
39 bitmap->eraseColor(0x00000000); | 39 bitmap->eraseColor(0x00000000); |
40 } | 40 } |
41 | 41 |
42 void DrawPicture(SkPicture* picture, SkBitmap* bitmap) { | 42 void DrawPicture(SkPicture* picture, SkBitmap* bitmap) { |
43 SkASSERT(picture != NULL); | 43 SkASSERT(picture != NULL); |
44 SkASSERT(bitmap != NULL); | 44 SkASSERT(bitmap != NULL); |
45 SkCanvas canvas(*bitmap); | 45 SkCanvas canvas(*bitmap); |
46 canvas.drawPicture(*picture); | 46 canvas.drawPicture(*picture); |
47 canvas.flush(); | 47 canvas.flush(); |
48 } | 48 } |
49 | 49 |
50 bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) { | 50 bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) { |
51 const SkAutoLockPixels lockA(a), lockB(b); | 51 const SkAutoLockPixels lockA(a), lockB(b); |
52 return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(
), b.getSize()); | 52 return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(
), b.getSize()); |
53 } | 53 } |
54 | 54 |
55 } // namespace DM | 55 } // namespace DM |
OLD | NEW |