| OLD | NEW |
| (Empty) |
| 1 #include "SkRecordAnalysis.h" | |
| 2 | |
| 3 #include "SkShader.h" | |
| 4 #include "SkTLogic.h" | |
| 5 | |
| 6 /** SkRecords visitor to determine whether an instance may require an | |
| 7 "external" bitmap to rasterize. May return false positives. | |
| 8 Does not return true for bitmap text. | |
| 9 | |
| 10 Expected use is to determine whether images need to be decoded before | |
| 11 rasterizing a particular SkRecord. | |
| 12 */ | |
| 13 struct BitmapTester { | |
| 14 // Helpers. These create HasMember_bitmap and HasMember_paint. | |
| 15 SK_CREATE_MEMBER_DETECTOR(bitmap); | |
| 16 SK_CREATE_MEMBER_DETECTOR(paint); | |
| 17 | |
| 18 // Some commands have a paint, some have an optional paint. Either way, get
back a pointer. | |
| 19 static const SkPaint* AsPtr(const SkPaint& p) { return &p; } | |
| 20 static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return
p; } | |
| 21 | |
| 22 | |
| 23 // Main entry for visitor: | |
| 24 // If the command has a bitmap directly, return true. | |
| 25 // If the command has a paint and the paint has a bitmap, return true. | |
| 26 // Otherwise, return false. | |
| 27 template <typename T> | |
| 28 bool operator()(const T& r) { return CheckBitmap(r); } | |
| 29 | |
| 30 | |
| 31 // If the command has a bitmap, of course we're going to play back bitmaps. | |
| 32 template <typename T> | |
| 33 static SK_WHEN(HasMember_bitmap<T>, bool) CheckBitmap(const T&) { return tru
e; } | |
| 34 | |
| 35 // If not, look for one in its paint (if it has a paint). | |
| 36 template <typename T> | |
| 37 static SK_WHEN(!HasMember_bitmap<T>, bool) CheckBitmap(const T& r) { return
CheckPaint(r); } | |
| 38 | |
| 39 // If we have a paint, dig down into the effects looking for a bitmap. | |
| 40 template <typename T> | |
| 41 static SK_WHEN(HasMember_paint<T>, bool) CheckPaint(const T& r) { | |
| 42 const SkPaint* paint = AsPtr(r.paint); | |
| 43 if (paint) { | |
| 44 const SkShader* shader = paint->getShader(); | |
| 45 if (shader && | |
| 46 shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault_Bitmap
Type) { | |
| 47 return true; | |
| 48 } | |
| 49 } | |
| 50 return false; | |
| 51 } | |
| 52 | |
| 53 // If we don't have a paint, that non-paint has no bitmap. | |
| 54 template <typename T> | |
| 55 static SK_WHEN(!HasMember_paint<T>, bool) CheckPaint(const T&) { return fals
e; } | |
| 56 }; | |
| 57 | |
| 58 bool SkRecordWillPlaybackBitmaps(const SkRecord& record) { | |
| 59 BitmapTester tester; | |
| 60 for (unsigned i = 0; i < record.count(); i++) { | |
| 61 if (record.visit<bool>(i, tester)) { | |
| 62 return true; | |
| 63 } | |
| 64 } | |
| 65 return false; | |
| 66 } | |
| OLD | NEW |