OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 // Some shared code used by both SkBigPicture and SkMiniPicture. | |
9 | |
10 #include "SkRecords.h" | |
11 #include "SkTLogic.h" | |
12 | |
13 struct SkTextHunter { | |
14 // Most ops never have text. Some always do. Subpictures know themeselves. | |
15 template <typename T> bool operator()(const T&) { return false; } | |
16 bool operator()(const SkRecords::DrawPosText&) { return true; } | |
17 bool operator()(const SkRecords::DrawPosTextH&) { return true; } | |
18 bool operator()(const SkRecords::DrawText&) { return true; } | |
19 bool operator()(const SkRecords::DrawTextBlob&) { return true; } | |
20 bool operator()(const SkRecords::DrawTextOnPath&) { return true; } | |
21 bool operator()(const SkRecords::DrawPicture& op) { return op.picture->hasTe
xt(); } | |
22 }; | |
23 | |
24 | |
25 struct SkBitmapHunter { | |
26 // Helpers. These create HasMember_bitmap and HasMember_paint. | |
27 SK_CREATE_MEMBER_DETECTOR(bitmap); | |
28 SK_CREATE_MEMBER_DETECTOR(paint); | |
29 | |
30 // Some ops have a paint, some have an optional paint. Either way, get back
a pointer. | |
31 static const SkPaint* AsPtr(const SkPaint& p) { return &p; } | |
32 static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return
p; } | |
33 | |
34 // Main entry for visitor: | |
35 // If the op is a DrawPicture, recurse. | |
36 // If the op has a bitmap directly, return true. | |
37 // If the op has a paint and the paint has a bitmap, return true. | |
38 // Otherwise, return false. | |
39 bool operator()(const SkRecords::DrawPicture& op) { return op.picture->willP
layBackBitmaps(); } | |
40 | |
41 template <typename T> | |
42 bool operator()(const T& r) { return CheckBitmap(r); } | |
43 | |
44 // If the op has a bitmap, of course we're going to play back bitmaps. | |
45 template <typename T> | |
46 static SK_WHEN(HasMember_bitmap<T>, bool) CheckBitmap(const T&) { return tru
e; } | |
47 | |
48 // If not, look for one in its paint (if it has a paint). | |
49 template <typename T> | |
50 static SK_WHEN(!HasMember_bitmap<T>, bool) CheckBitmap(const T& r) { return
CheckPaint(r); } | |
51 | |
52 // If we have a paint, dig down into the effects looking for a bitmap. | |
53 template <typename T> | |
54 static SK_WHEN(HasMember_paint<T>, bool) CheckPaint(const T& r) { | |
55 const SkPaint* paint = AsPtr(r.paint); | |
56 if (paint) { | |
57 const SkShader* shader = paint->getShader(); | |
58 if (shader && | |
59 shader->asABitmap(nullptr, nullptr, nullptr) == SkShader::kDefau
lt_BitmapType) { | |
60 return true; | |
61 } | |
62 } | |
63 return false; | |
64 } | |
65 | |
66 // If we don't have a paint, that non-paint has no bitmap. | |
67 template <typename T> | |
68 static SK_WHEN(!HasMember_paint<T>, bool) CheckPaint(const T&) { return fals
e; } | |
69 }; | |
70 | |
OLD | NEW |