OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
11 | 11 |
12 #include "effects/GrSingleTextureEffect.h" | 12 #include "effects/GrSingleTextureEffect.h" |
13 #include "effects/GrConfigConversionEffect.h" | 13 #include "effects/GrConfigConversionEffect.h" |
14 | 14 |
15 #include "GrBufferAllocPool.h" | 15 #include "GrBufferAllocPool.h" |
16 #include "GrGpu.h" | 16 #include "GrGpu.h" |
17 #include "GrDrawTargetCaps.h" | 17 #include "GrDrawTargetCaps.h" |
18 #include "GrIndexBuffer.h" | 18 #include "GrIndexBuffer.h" |
19 #include "GrInOrderDrawBuffer.h" | 19 #include "GrInOrderDrawBuffer.h" |
20 #include "GrOvalRenderer.h" | 20 #include "GrOvalRenderer.h" |
21 #include "GrPathRenderer.h" | 21 #include "GrPathRenderer.h" |
22 #include "GrPathUtils.h" | 22 #include "GrPathUtils.h" |
23 #include "GrResourceCache.h" | 23 #include "GrResourceCache.h" |
24 #include "GrSoftwarePathRenderer.h" | 24 #include "GrSoftwarePathRenderer.h" |
25 #include "GrStencilBuffer.h" | 25 #include "GrStencilBuffer.h" |
26 #include "GrTextStrike.h" | 26 #include "GrTextStrike.h" |
27 #include "SkRTConf.h" | 27 #include "SkRTConf.h" |
| 28 #include "SkRRect.h" |
28 #include "SkStrokeRec.h" | 29 #include "SkStrokeRec.h" |
29 #include "SkTLazy.h" | 30 #include "SkTLazy.h" |
30 #include "SkTLS.h" | 31 #include "SkTLS.h" |
31 #include "SkTrace.h" | 32 #include "SkTrace.h" |
32 | 33 |
33 SK_DEFINE_INST_COUNT(GrContext) | 34 SK_DEFINE_INST_COUNT(GrContext) |
34 SK_DEFINE_INST_COUNT(GrDrawState) | 35 SK_DEFINE_INST_COUNT(GrDrawState) |
35 | 36 |
36 // It can be useful to set this to false to test whether a bug is caused by usin
g the | 37 // It can be useful to set this to false to test whether a bug is caused by usin
g the |
37 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe
r, or to make | 38 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe
r, or to make |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 } else { | 946 } else { |
946 target->drawNonIndexed(primitiveType, 0, vertexCount); | 947 target->drawNonIndexed(primitiveType, 0, vertexCount); |
947 } | 948 } |
948 } | 949 } |
949 | 950 |
950 /////////////////////////////////////////////////////////////////////////////// | 951 /////////////////////////////////////////////////////////////////////////////// |
951 | 952 |
952 void GrContext::drawRRect(const GrPaint& paint, | 953 void GrContext::drawRRect(const GrPaint& paint, |
953 const SkRRect& rect, | 954 const SkRRect& rect, |
954 const SkStrokeRec& stroke) { | 955 const SkStrokeRec& stroke) { |
| 956 if (rect.isEmpty()) { |
| 957 return; |
| 958 } |
955 | 959 |
956 AutoRestoreEffects are; | 960 AutoRestoreEffects are; |
957 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); | 961 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
958 | 962 |
959 bool useAA = paint.isAntiAlias() && | 963 bool useAA = paint.isAntiAlias() && |
960 !target->getDrawState().getRenderTarget()->isMultisampled() && | 964 !target->getDrawState().getRenderTarget()->isMultisampled() && |
961 !disable_coverage_aa_for_blend(target); | 965 !disable_coverage_aa_for_blend(target); |
962 | 966 |
963 if (!fOvalRenderer->drawSimpleRRect(target, this, useAA, rect, stroke)) { | 967 if (!fOvalRenderer->drawSimpleRRect(target, this, useAA, rect, stroke)) { |
964 SkPath path; | 968 SkPath path; |
965 path.addRRect(rect); | 969 path.addRRect(rect); |
966 this->internalDrawPath(target, useAA, path, stroke); | 970 this->internalDrawPath(target, useAA, path, stroke); |
967 } | 971 } |
968 } | 972 } |
969 | 973 |
970 /////////////////////////////////////////////////////////////////////////////// | 974 /////////////////////////////////////////////////////////////////////////////// |
971 | 975 |
972 void GrContext::drawOval(const GrPaint& paint, | 976 void GrContext::drawOval(const GrPaint& paint, |
973 const SkRect& oval, | 977 const SkRect& oval, |
974 const SkStrokeRec& stroke) { | 978 const SkStrokeRec& stroke) { |
| 979 if (oval.isEmpty()) { |
| 980 return; |
| 981 } |
975 | 982 |
976 AutoRestoreEffects are; | 983 AutoRestoreEffects are; |
977 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); | 984 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
978 | 985 |
979 bool useAA = paint.isAntiAlias() && | 986 bool useAA = paint.isAntiAlias() && |
980 !target->getDrawState().getRenderTarget()->isMultisampled() && | 987 !target->getDrawState().getRenderTarget()->isMultisampled() && |
981 !disable_coverage_aa_for_blend(target); | 988 !disable_coverage_aa_for_blend(target); |
982 | 989 |
983 if (!fOvalRenderer->drawOval(target, this, useAA, oval, stroke)) { | 990 if (!fOvalRenderer->drawOval(target, this, useAA, oval, stroke)) { |
984 SkPath path; | 991 SkPath path; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 bool isOval = path.isOval(&ovalRect); | 1082 bool isOval = path.isOval(&ovalRect); |
1076 | 1083 |
1077 if (!isOval || path.isInverseFillType() | 1084 if (!isOval || path.isInverseFillType() |
1078 || !fOvalRenderer->drawOval(target, this, useAA, ovalRect, stroke)) { | 1085 || !fOvalRenderer->drawOval(target, this, useAA, ovalRect, stroke)) { |
1079 this->internalDrawPath(target, useAA, path, stroke); | 1086 this->internalDrawPath(target, useAA, path, stroke); |
1080 } | 1087 } |
1081 } | 1088 } |
1082 | 1089 |
1083 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath&
path, | 1090 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath&
path, |
1084 const SkStrokeRec& stroke) { | 1091 const SkStrokeRec& stroke) { |
| 1092 SkASSERT(!path.isEmpty()); |
1085 | 1093 |
1086 // An Assumption here is that path renderer would use some form of tweaking | 1094 // An Assumption here is that path renderer would use some form of tweaking |
1087 // the src color (either the input alpha or in the frag shader) to implement | 1095 // the src color (either the input alpha or in the frag shader) to implement |
1088 // aa. If we have some future driver-mojo path AA that can do the right | 1096 // aa. If we have some future driver-mojo path AA that can do the right |
1089 // thing WRT to the blend then we'll need some query on the PR. | 1097 // thing WRT to the blend then we'll need some query on the PR. |
1090 if (disable_coverage_aa_for_blend(target)) { | 1098 if (disable_coverage_aa_for_blend(target)) { |
1091 #if GR_DEBUG | 1099 #if GR_DEBUG |
1092 //GrPrintf("Turning off AA to correctly apply blend.\n"); | 1100 //GrPrintf("Turning off AA to correctly apply blend.\n"); |
1093 #endif | 1101 #endif |
1094 useAA = false; | 1102 useAA = false; |
(...skipping 10 matching lines...) Expand all Loading... |
1105 GrPathRenderer* pr = this->getPathRenderer(*pathPtr, strokeRec, target, fals
e, type); | 1113 GrPathRenderer* pr = this->getPathRenderer(*pathPtr, strokeRec, target, fals
e, type); |
1106 | 1114 |
1107 if (NULL == pr) { | 1115 if (NULL == pr) { |
1108 if (!strokeRec.isHairlineStyle()) { | 1116 if (!strokeRec.isHairlineStyle()) { |
1109 // It didn't work the 1st time, so try again with the stroked path | 1117 // It didn't work the 1st time, so try again with the stroked path |
1110 if (strokeRec.applyToPath(&tmpPath, *pathPtr)) { | 1118 if (strokeRec.applyToPath(&tmpPath, *pathPtr)) { |
1111 pathPtr = &tmpPath; | 1119 pathPtr = &tmpPath; |
1112 strokeRec.setFillStyle(); | 1120 strokeRec.setFillStyle(); |
1113 } | 1121 } |
1114 } | 1122 } |
| 1123 if (pathPtr->isEmpty()) { |
| 1124 return; |
| 1125 } |
| 1126 |
1115 // This time, allow SW renderer | 1127 // This time, allow SW renderer |
1116 pr = this->getPathRenderer(*pathPtr, strokeRec, target, true, type); | 1128 pr = this->getPathRenderer(*pathPtr, strokeRec, target, true, type); |
1117 } | 1129 } |
1118 | 1130 |
1119 if (NULL == pr) { | 1131 if (NULL == pr) { |
1120 #if GR_DEBUG | 1132 #if GR_DEBUG |
1121 GrPrintf("Unable to find path renderer compatible with path.\n"); | 1133 GrPrintf("Unable to find path renderer compatible with path.\n"); |
1122 #endif | 1134 #endif |
1123 return; | 1135 return; |
1124 } | 1136 } |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 return NULL; | 1717 return NULL; |
1706 } | 1718 } |
1707 } | 1719 } |
1708 | 1720 |
1709 /////////////////////////////////////////////////////////////////////////////// | 1721 /////////////////////////////////////////////////////////////////////////////// |
1710 #if GR_CACHE_STATS | 1722 #if GR_CACHE_STATS |
1711 void GrContext::printCacheStats() const { | 1723 void GrContext::printCacheStats() const { |
1712 fTextureCache->printStats(); | 1724 fTextureCache->printStats(); |
1713 } | 1725 } |
1714 #endif | 1726 #endif |
OLD | NEW |