OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPaint.h" | 8 #include "SkPaint.h" |
9 #include "SkPathEffect.h" | 9 #include "SkPathEffect.h" |
10 #include "SkPictureContentInfo.h" | 10 #include "SkPictureContentInfo.h" |
11 | 11 |
12 bool SkPictureContentInfo::suitableForGpuRasterization(GrContext* context, const
char **reason, | 12 bool SkPictureContentInfo::suitableForGpuRasterization(GrContext* context, const
char **reason, |
13 int sampleCount) const { | 13 int sampleCount) const { |
14 // TODO: the heuristic used here needs to be refined | 14 // TODO: the heuristic used here needs to be refined |
15 static const int kNumPaintWithPathEffectUsesTol = 1; | 15 static const int kNumPaintWithPathEffectUsesTol = 1; |
16 static const int kNumAAConcavePaths = 5; | 16 static const int kNumAAConcavePaths = 5; |
17 | 17 |
18 SkASSERT(fNumAAHairlineConcavePaths <= fNumAAConcavePaths); | 18 SkASSERT(fNumAAHairlineConcavePaths <= fNumAAConcavePaths); |
19 | 19 |
20 int numNonDashedPathEffects = fNumPaintWithPathEffectUses - | 20 int numNonDashedPathEffects = fNumPaintWithPathEffectUses - |
21 fNumFastPathDashEffects; | 21 fNumFastPathDashEffects; |
22 | 22 |
23 bool suitableForDash = (0 == fNumPaintWithPathEffectUses) || | 23 bool suitableForDash = (0 == fNumPaintWithPathEffectUses) || |
24 (numNonDashedPathEffects < kNumPaintWithPathEffectUse
sTol | 24 (numNonDashedPathEffects < kNumPaintWithPathEffectUse
sTol |
25 && 0 == sampleCount); | 25 && 0 == sampleCount); |
26 | 26 |
27 bool ret = suitableForDash && | 27 bool ret = suitableForDash && |
28 (fNumAAConcavePaths - fNumAAHairlineConcavePaths) | 28 (fNumAAConcavePaths - fNumAAHairlineConcavePaths - fNumAADFE
ligibleConcavePaths) |
29 < kNumAAConcavePaths; | 29 < kNumAAConcavePaths; |
30 if (!ret && reason) { | 30 if (!ret && reason) { |
31 if (!suitableForDash) { | 31 if (!suitableForDash) { |
32 if (0 != sampleCount) { | 32 if (0 != sampleCount) { |
33 *reason = "Can't use multisample on dash effect."; | 33 *reason = "Can't use multisample on dash effect."; |
34 } else { | 34 } else { |
35 *reason = "Too many non dashed path effects."; | 35 *reason = "Too many non dashed path effects."; |
36 } | 36 } |
37 } else if ((fNumAAConcavePaths - fNumAAHairlineConcavePaths) | 37 } else if ((fNumAAConcavePaths - fNumAAHairlineConcavePaths - fNumAADFEl
igibleConcavePaths) |
38 >= kNumAAConcavePaths) { | 38 >= kNumAAConcavePaths) { |
39 *reason = "Too many anti-aliased concave paths."; | 39 *reason = "Too many anti-aliased concave paths."; |
40 } else { | 40 } else { |
41 *reason = "Unknown reason for GPU unsuitability."; | 41 *reason = "Unknown reason for GPU unsuitability."; |
42 } | 42 } |
43 } | 43 } |
44 return ret; | 44 return ret; |
45 } | 45 } |
46 | 46 |
47 void SkPictureContentInfo::onDrawPoints(size_t count, const SkPaint& paint) { | 47 void SkPictureContentInfo::onDrawPoints(size_t count, const SkPaint& paint) { |
48 if (paint.getPathEffect() != NULL) { | 48 if (paint.getPathEffect() != NULL) { |
49 SkPathEffect::DashInfo info; | 49 SkPathEffect::DashInfo info; |
50 SkPathEffect::DashType dashType = paint.getPathEffect()->asADash(&info); | 50 SkPathEffect::DashType dashType = paint.getPathEffect()->asADash(&info); |
51 if (2 == count && SkPaint::kRound_Cap != paint.getStrokeCap() && | 51 if (2 == count && SkPaint::kRound_Cap != paint.getStrokeCap() && |
52 SkPathEffect::kDash_DashType == dashType && 2 == info.fCount) { | 52 SkPathEffect::kDash_DashType == dashType && 2 == info.fCount) { |
53 ++fNumFastPathDashEffects; | 53 ++fNumFastPathDashEffects; |
54 } | 54 } |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 void SkPictureContentInfo::onDrawPath(const SkPath& path, const SkPaint& paint)
{ | 58 void SkPictureContentInfo::onDrawPath(const SkPath& path, const SkPaint& paint)
{ |
59 if (paint.isAntiAlias() && !path.isConvex()) { | 59 if (paint.isAntiAlias() && !path.isConvex()) { |
60 ++fNumAAConcavePaths; | 60 ++fNumAAConcavePaths; |
61 | 61 |
| 62 SkPaint::Style paintStyle = paint.getStyle(); |
| 63 const SkRect& pathBounds = path.getBounds(); |
62 if (SkPaint::kStroke_Style == paint.getStyle() && 0 == paint.getStrokeWi
dth()) { | 64 if (SkPaint::kStroke_Style == paint.getStyle() && 0 == paint.getStrokeWi
dth()) { |
63 ++fNumAAHairlineConcavePaths; | 65 ++fNumAAHairlineConcavePaths; |
| 66 } else if (SkPaint::kFill_Style == paintStyle && pathBounds.width() < 64
.f && |
| 67 pathBounds.height() < 64.f && !path.isVolatile()) { |
| 68 ++fNumAADFEligibleConcavePaths; |
64 } | 69 } |
65 } | 70 } |
66 } | 71 } |
67 | 72 |
68 void SkPictureContentInfo::onAddPaintPtr(const SkPaint* paint) { | 73 void SkPictureContentInfo::onAddPaintPtr(const SkPaint* paint) { |
69 if (paint && paint->getPathEffect()) { | 74 if (paint && paint->getPathEffect()) { |
70 ++fNumPaintWithPathEffectUses; | 75 ++fNumPaintWithPathEffectUses; |
71 } | 76 } |
72 } | 77 } |
73 | 78 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 132 } |
128 } | 133 } |
129 | 134 |
130 void SkPictureContentInfo::set(const SkPictureContentInfo& src) { | 135 void SkPictureContentInfo::set(const SkPictureContentInfo& src) { |
131 fNumOperations = src.fNumOperations; | 136 fNumOperations = src.fNumOperations; |
132 fNumTexts = src.fNumTexts; | 137 fNumTexts = src.fNumTexts; |
133 fNumPaintWithPathEffectUses = src.fNumPaintWithPathEffectUses; | 138 fNumPaintWithPathEffectUses = src.fNumPaintWithPathEffectUses; |
134 fNumFastPathDashEffects = src.fNumFastPathDashEffects; | 139 fNumFastPathDashEffects = src.fNumFastPathDashEffects; |
135 fNumAAConcavePaths = src.fNumAAConcavePaths; | 140 fNumAAConcavePaths = src.fNumAAConcavePaths; |
136 fNumAAHairlineConcavePaths = src.fNumAAHairlineConcavePaths; | 141 fNumAAHairlineConcavePaths = src.fNumAAHairlineConcavePaths; |
| 142 fNumAADFEligibleConcavePaths = src.fNumAADFEligibleConcavePaths; |
137 fNumLayers = src.fNumLayers; | 143 fNumLayers = src.fNumLayers; |
138 fNumInteriorLayers = src.fNumInteriorLayers; | 144 fNumInteriorLayers = src.fNumInteriorLayers; |
139 fNumLeafLayers = src.fNumLeafLayers; | 145 fNumLeafLayers = src.fNumLeafLayers; |
140 fSaveStack = src.fSaveStack; | 146 fSaveStack = src.fSaveStack; |
141 } | 147 } |
142 | 148 |
143 void SkPictureContentInfo::reset() { | 149 void SkPictureContentInfo::reset() { |
144 fNumOperations = 0; | 150 fNumOperations = 0; |
145 fNumTexts = 0; | 151 fNumTexts = 0; |
146 fNumPaintWithPathEffectUses = 0; | 152 fNumPaintWithPathEffectUses = 0; |
147 fNumFastPathDashEffects = 0; | 153 fNumFastPathDashEffects = 0; |
148 fNumAAConcavePaths = 0; | 154 fNumAAConcavePaths = 0; |
149 fNumAAHairlineConcavePaths = 0; | 155 fNumAAHairlineConcavePaths = 0; |
| 156 fNumAADFEligibleConcavePaths = 0; |
150 fNumLayers = 0; | 157 fNumLayers = 0; |
151 fNumInteriorLayers = 0; | 158 fNumInteriorLayers = 0; |
152 fNumLeafLayers = 0; | 159 fNumLeafLayers = 0; |
153 fSaveStack.rewind(); | 160 fSaveStack.rewind(); |
154 } | 161 } |
155 | 162 |
156 void SkPictureContentInfo::swap(SkPictureContentInfo* other) { | 163 void SkPictureContentInfo::swap(SkPictureContentInfo* other) { |
157 SkTSwap(fNumOperations, other->fNumOperations); | 164 SkTSwap(fNumOperations, other->fNumOperations); |
158 SkTSwap(fNumTexts, other->fNumTexts); | 165 SkTSwap(fNumTexts, other->fNumTexts); |
159 SkTSwap(fNumPaintWithPathEffectUses, other->fNumPaintWithPathEffectUses); | 166 SkTSwap(fNumPaintWithPathEffectUses, other->fNumPaintWithPathEffectUses); |
160 SkTSwap(fNumFastPathDashEffects, other->fNumFastPathDashEffects); | 167 SkTSwap(fNumFastPathDashEffects, other->fNumFastPathDashEffects); |
161 SkTSwap(fNumAAConcavePaths, other->fNumAAConcavePaths); | 168 SkTSwap(fNumAAConcavePaths, other->fNumAAConcavePaths); |
162 SkTSwap(fNumAAHairlineConcavePaths, other->fNumAAHairlineConcavePaths); | 169 SkTSwap(fNumAAHairlineConcavePaths, other->fNumAAHairlineConcavePaths); |
| 170 SkTSwap(fNumAADFEligibleConcavePaths, other->fNumAADFEligibleConcavePaths); |
163 SkTSwap(fNumLayers, other->fNumLayers); | 171 SkTSwap(fNumLayers, other->fNumLayers); |
164 SkTSwap(fNumInteriorLayers, other->fNumInteriorLayers); | 172 SkTSwap(fNumInteriorLayers, other->fNumInteriorLayers); |
165 SkTSwap(fNumLeafLayers, other->fNumLeafLayers); | 173 SkTSwap(fNumLeafLayers, other->fNumLeafLayers); |
166 fSaveStack.swap(other->fSaveStack); | 174 fSaveStack.swap(other->fSaveStack); |
167 } | 175 } |
OLD | NEW |