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