Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/core/SkRecordAnalysis.cpp

Issue 366443002: Implement SkRecord::willPlaybackBitmaps, cache in SkPicture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkRecordAnalysis.h ('k') | tests/RecordTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « src/core/SkRecordAnalysis.h ('k') | tests/RecordTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698