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 void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags) { | 13 void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags) { |
14 const SkISize size = gm->getISize(); | 14 const SkISize size = gm->getISize(); |
15 SkCanvas* canvas = picture->beginRecording(size.width(), size.height(), reco
rdFlags); | 15 SkCanvas* canvas = picture->beginRecording(size.width(), size.height(), reco
rdFlags); |
16 canvas->concat(gm->getInitialTransform()); | 16 canvas->concat(gm->getInitialTransform()); |
17 gm->draw(canvas); | 17 gm->draw(canvas); |
18 canvas->flush(); | 18 canvas->flush(); |
19 picture->endRecording(); | 19 picture->endRecording(); |
20 } | 20 } |
21 | 21 |
| 22 static void setup_bitmap(SkColorType ct, int width, int height, SkBitmap* bitmap
) { |
| 23 bitmap->allocPixels(SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType
)); |
| 24 bitmap->eraseColor(0x00000000); |
| 25 } |
| 26 |
22 void SetupBitmap(const SkColorType ct, skiagm::GM* gm, SkBitmap* bitmap) { | 27 void SetupBitmap(const SkColorType ct, skiagm::GM* gm, SkBitmap* bitmap) { |
23 const SkISize size = gm->getISize(); | 28 setup_bitmap(ct, gm->getISize().width(), gm->getISize().height(), bitmap); |
24 bitmap->allocPixels(SkImageInfo::Make(size.width(), size.height(), | 29 } |
25 ct, kPremul_SkAlphaType)); | 30 |
26 bitmap->eraseColor(0x00000000); | 31 void SetupBitmap(const SkColorType ct, SkBenchmark* bench, SkBitmap* bitmap) { |
| 32 setup_bitmap(ct, bench->getSize().x(), bench->getSize().y(), bitmap); |
27 } | 33 } |
28 | 34 |
29 void DrawPicture(SkPicture* picture, SkBitmap* bitmap) { | 35 void DrawPicture(SkPicture* picture, SkBitmap* bitmap) { |
30 SkASSERT(picture != NULL); | 36 SkASSERT(picture != NULL); |
31 SkASSERT(bitmap != NULL); | 37 SkASSERT(bitmap != NULL); |
32 SkCanvas canvas(*bitmap); | 38 SkCanvas canvas(*bitmap); |
33 canvas.drawPicture(*picture); | 39 canvas.drawPicture(*picture); |
34 canvas.flush(); | 40 canvas.flush(); |
35 } | 41 } |
36 | 42 |
37 bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) { | 43 bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) { |
38 const SkAutoLockPixels lockA(a), lockB(b); | 44 const SkAutoLockPixels lockA(a), lockB(b); |
39 return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(
), b.getSize()); | 45 return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(
), b.getSize()); |
40 } | 46 } |
41 | 47 |
42 } // namespace DM | 48 } // namespace DM |
OLD | NEW |