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 #include "GrContext.h" | 9 #include "GrContext.h" |
10 | 10 |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 } | 588 } |
589 | 589 |
590 AutoCheckFlush acf(this); | 590 AutoCheckFlush acf(this); |
591 GrPipelineBuilder pipelineBuilder; | 591 GrPipelineBuilder pipelineBuilder; |
592 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 592 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); |
593 if (NULL == target) { | 593 if (NULL == target) { |
594 return; | 594 return; |
595 } | 595 } |
596 | 596 |
597 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | 597 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
598 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); | 598 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getWidth(); |
599 | 599 |
600 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 600 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
601 // cases where the RT is fully inside a stroke. | 601 // cases where the RT is fully inside a stroke. |
602 if (width < 0) { | 602 if (width < 0) { |
603 SkRect rtRect; | 603 SkRect rtRect; |
604 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); | 604 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); |
605 SkRect clipSpaceRTRect = rtRect; | 605 SkRect clipSpaceRTRect = rtRect; |
606 bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType(); | 606 bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType(); |
607 if (checkClip) { | 607 if (checkClip) { |
608 clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX), | 608 clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX), |
(...skipping 23 matching lines...) Expand all Loading... |
632 } | 632 } |
633 | 633 |
634 GrColor color = paint.getColor(); | 634 GrColor color = paint.getColor(); |
635 SkRect devBoundRect; | 635 SkRect devBoundRect; |
636 bool needAA = paint.isAntiAlias() && !pipelineBuilder.getRenderTarget()->isM
ultisampled(); | 636 bool needAA = paint.isAntiAlias() && !pipelineBuilder.getRenderTarget()->isM
ultisampled(); |
637 bool doAA = needAA && apply_aa_to_rect(target, &pipelineBuilder, &devBoundRe
ct, rect, width, | 637 bool doAA = needAA && apply_aa_to_rect(target, &pipelineBuilder, &devBoundRe
ct, rect, width, |
638 viewMatrix, color); | 638 viewMatrix, color); |
639 | 639 |
640 if (doAA) { | 640 if (doAA) { |
641 if (width >= 0) { | 641 if (width >= 0) { |
642 const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); | |
643 fAARectRenderer->strokeAARect(target, | 642 fAARectRenderer->strokeAARect(target, |
644 &pipelineBuilder, | 643 &pipelineBuilder, |
645 color, | 644 color, |
646 viewMatrix, | 645 viewMatrix, |
647 rect, | 646 rect, |
648 devBoundRect, | 647 devBoundRect, |
649 strokeRec); | 648 *strokeInfo); |
650 } else { | 649 } else { |
651 // filled AA rect | 650 // filled AA rect |
652 fAARectRenderer->fillAARect(target, | 651 fAARectRenderer->fillAARect(target, |
653 &pipelineBuilder, | 652 &pipelineBuilder, |
654 color, | 653 color, |
655 viewMatrix, | 654 viewMatrix, |
656 rect, | 655 rect, |
657 devBoundRect); | 656 devBoundRect); |
658 } | 657 } |
659 return; | 658 return; |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 | 1052 |
1054 AutoCheckFlush acf(this); | 1053 AutoCheckFlush acf(this); |
1055 GrPipelineBuilder pipelineBuilder; | 1054 GrPipelineBuilder pipelineBuilder; |
1056 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 1055 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); |
1057 if (NULL == target) { | 1056 if (NULL == target) { |
1058 return; | 1057 return; |
1059 } | 1058 } |
1060 | 1059 |
1061 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | 1060 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
1062 | 1061 |
1063 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | |
1064 | |
1065 GrColor color = paint.getColor(); | 1062 GrColor color = paint.getColor(); |
1066 if (!fOvalRenderer->drawRRect(target, | 1063 if (!fOvalRenderer->drawRRect(target, |
1067 &pipelineBuilder, | 1064 &pipelineBuilder, |
1068 color, | 1065 color, |
1069 viewMatrix, | 1066 viewMatrix, |
1070 paint.isAntiAlias(), | 1067 paint.isAntiAlias(), |
1071 rrect, | 1068 rrect, |
1072 strokeRec)) { | 1069 strokeInfo)) { |
1073 SkPath path; | 1070 SkPath path; |
1074 path.addRRect(rrect); | 1071 path.addRRect(rrect); |
1075 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 1072 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
1076 path, strokeInfo); | 1073 path, strokeInfo); |
1077 } | 1074 } |
1078 } | 1075 } |
1079 | 1076 |
1080 /////////////////////////////////////////////////////////////////////////////// | 1077 /////////////////////////////////////////////////////////////////////////////// |
1081 | 1078 |
1082 void GrContext::drawDRRect(GrRenderTarget* rt, | 1079 void GrContext::drawDRRect(GrRenderTarget* rt, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 | 1134 |
1138 AutoCheckFlush acf(this); | 1135 AutoCheckFlush acf(this); |
1139 GrPipelineBuilder pipelineBuilder; | 1136 GrPipelineBuilder pipelineBuilder; |
1140 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 1137 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); |
1141 if (NULL == target) { | 1138 if (NULL == target) { |
1142 return; | 1139 return; |
1143 } | 1140 } |
1144 | 1141 |
1145 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | 1142 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
1146 | 1143 |
1147 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | |
1148 | |
1149 GrColor color = paint.getColor(); | 1144 GrColor color = paint.getColor(); |
1150 if (!fOvalRenderer->drawOval(target, | 1145 if (!fOvalRenderer->drawOval(target, |
1151 &pipelineBuilder, | 1146 &pipelineBuilder, |
1152 color, | 1147 color, |
1153 viewMatrix, | 1148 viewMatrix, |
1154 paint.isAntiAlias(), | 1149 paint.isAntiAlias(), |
1155 oval, | 1150 oval, |
1156 strokeRec)) { | 1151 strokeInfo)) { |
1157 SkPath path; | 1152 SkPath path; |
1158 path.addOval(oval); | 1153 path.addOval(oval); |
1159 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 1154 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
1160 path, strokeInfo); | 1155 path, strokeInfo); |
1161 } | 1156 } |
1162 } | 1157 } |
1163 | 1158 |
1164 // Can 'path' be drawn as a pair of filled nested rectangles? | 1159 // Can 'path' be drawn as a pair of filled nested rectangles? |
1165 static bool is_nested_rects(GrDrawTarget* target, | 1160 static bool is_nested_rects(GrDrawTarget* target, |
1166 GrPipelineBuilder* pipelineBuilder, | 1161 GrPipelineBuilder* pipelineBuilder, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 AutoCheckFlush acf(this); | 1233 AutoCheckFlush acf(this); |
1239 GrPipelineBuilder pipelineBuilder; | 1234 GrPipelineBuilder pipelineBuilder; |
1240 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 1235 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); |
1241 if (NULL == target) { | 1236 if (NULL == target) { |
1242 return; | 1237 return; |
1243 } | 1238 } |
1244 | 1239 |
1245 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC
onvex()); | 1240 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC
onvex()); |
1246 | 1241 |
1247 if (!strokeInfo.isDashed()) { | 1242 if (!strokeInfo.isDashed()) { |
1248 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | |
1249 bool useCoverageAA = paint.isAntiAlias() && | 1243 bool useCoverageAA = paint.isAntiAlias() && |
1250 !pipelineBuilder.getRenderTarget()->isMultisampled(); | 1244 !pipelineBuilder.getRenderTarget()->isMultisampled(); |
1251 | 1245 |
1252 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { | 1246 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { |
1253 // Concave AA paths are expensive - try to avoid them for special ca
ses | 1247 // Concave AA paths are expensive - try to avoid them for special ca
ses |
1254 SkRect rects[2]; | 1248 SkRect rects[2]; |
1255 | 1249 |
1256 if (is_nested_rects(target, &pipelineBuilder, color, viewMatrix, pat
h, strokeRec, | 1250 if (is_nested_rects(target, &pipelineBuilder, color, viewMatrix, pat
h, strokeInfo, |
1257 rects)) { | 1251 rects)) { |
1258 fAARectRenderer->fillAANestedRects(target, &pipelineBuilder, col
or, viewMatrix, | 1252 fAARectRenderer->fillAANestedRects(target, &pipelineBuilder, col
or, viewMatrix, |
1259 rects); | 1253 rects); |
1260 return; | 1254 return; |
1261 } | 1255 } |
1262 } | 1256 } |
1263 SkRect ovalRect; | 1257 SkRect ovalRect; |
1264 bool isOval = path.isOval(&ovalRect); | 1258 bool isOval = path.isOval(&ovalRect); |
1265 | 1259 |
1266 if (isOval && !path.isInverseFillType()) { | 1260 if (isOval && !path.isInverseFillType()) { |
1267 if (fOvalRenderer->drawOval(target, | 1261 if (fOvalRenderer->drawOval(target, |
1268 &pipelineBuilder, | 1262 &pipelineBuilder, |
1269 color, | 1263 color, |
1270 viewMatrix, | 1264 viewMatrix, |
1271 paint.isAntiAlias(), | 1265 paint.isAntiAlias(), |
1272 ovalRect, | 1266 ovalRect, |
1273 strokeRec)) { | 1267 strokeInfo)) { |
1274 return; | 1268 return; |
1275 } | 1269 } |
1276 } | 1270 } |
1277 } | 1271 } |
1278 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, paint.is
AntiAlias(), | 1272 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, paint.is
AntiAlias(), |
1279 path, strokeInfo); | 1273 path, strokeInfo); |
1280 } | 1274 } |
1281 | 1275 |
1282 void GrContext::internalDrawPath(GrDrawTarget* target, | 1276 void GrContext::internalDrawPath(GrDrawTarget* target, |
1283 GrPipelineBuilder* pipelineBuilder, | 1277 GrPipelineBuilder* pipelineBuilder, |
(...skipping 24 matching lines...) Expand all Loading... |
1308 SkTLazy<SkPath> tmpPath; | 1302 SkTLazy<SkPath> tmpPath; |
1309 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; | 1303 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; |
1310 | 1304 |
1311 // Try a 1st time without stroking the path and without allowing the SW rend
erer | 1305 // Try a 1st time without stroking the path and without allowing the SW rend
erer |
1312 GrPathRenderer* pr = this->getPathRenderer(target, pipelineBuilder, viewMatr
ix, *pathPtr, | 1306 GrPathRenderer* pr = this->getPathRenderer(target, pipelineBuilder, viewMatr
ix, *pathPtr, |
1313 *strokeInfoPtr, false, type); | 1307 *strokeInfoPtr, false, type); |
1314 | 1308 |
1315 GrStrokeInfo dashlessStrokeInfo(strokeInfo, false); | 1309 GrStrokeInfo dashlessStrokeInfo(strokeInfo, false); |
1316 if (NULL == pr && strokeInfo.isDashed()) { | 1310 if (NULL == pr && strokeInfo.isDashed()) { |
1317 // It didn't work above, so try again with dashed stroke converted to a
dashless stroke. | 1311 // It didn't work above, so try again with dashed stroke converted to a
dashless stroke. |
1318 if (!strokeInfo.applyDash(tmpPath.init(), &dashlessStrokeInfo, *pathPtr)
) { | 1312 if (!strokeInfo.applyDashToPath(tmpPath.init(), &dashlessStrokeInfo, *pa
thPtr)) { |
1319 return; | 1313 return; |
1320 } | 1314 } |
1321 pathPtr = tmpPath.get(); | 1315 pathPtr = tmpPath.get(); |
1322 if (pathPtr->isEmpty()) { | 1316 if (pathPtr->isEmpty()) { |
1323 return; | 1317 return; |
1324 } | 1318 } |
1325 strokeInfoPtr = &dashlessStrokeInfo; | 1319 strokeInfoPtr = &dashlessStrokeInfo; |
1326 pr = this->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr
, *strokeInfoPtr, | 1320 pr = this->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr
, *strokeInfoPtr, |
1327 false, type); | 1321 false, type); |
1328 } | 1322 } |
1329 | 1323 |
1330 if (NULL == pr) { | 1324 if (NULL == pr) { |
1331 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*strokeInfoPtr, viewMa
trix, NULL) && | 1325 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*strokeInfoPtr, viewMa
trix, NULL) && |
1332 !strokeInfoPtr->isFillStyle()) { | 1326 !strokeInfoPtr->isFillStyle()) { |
1333 // It didn't work above, so try again with stroke converted to a fil
l. | 1327 // It didn't work above, so try again with stroke converted to a fil
l. |
1334 if (!tmpPath.isValid()) { | 1328 if (!tmpPath.isValid()) { |
1335 tmpPath.init(); | 1329 tmpPath.init(); |
1336 } | 1330 } |
1337 SkStrokeRec* strokeRec = dashlessStrokeInfo.getStrokeRecPtr(); | 1331 dashlessStrokeInfo.setResScale(SkScalarAbs(viewMatrix.getMaxScale())
); |
1338 strokeRec->setResScale(SkScalarAbs(viewMatrix.getMaxScale())); | 1332 if (!dashlessStrokeInfo.applyToPath(tmpPath.get(), *pathPtr)) { |
1339 if (!strokeRec->applyToPath(tmpPath.get(), *pathPtr)) { | |
1340 return; | 1333 return; |
1341 } | 1334 } |
1342 pathPtr = tmpPath.get(); | 1335 pathPtr = tmpPath.get(); |
1343 if (pathPtr->isEmpty()) { | 1336 if (pathPtr->isEmpty()) { |
1344 return; | 1337 return; |
1345 } | 1338 } |
1346 strokeRec->setFillStyle(); | 1339 dashlessStrokeInfo.setFillStyle(); |
1347 strokeInfoPtr = &dashlessStrokeInfo; | 1340 strokeInfoPtr = &dashlessStrokeInfo; |
1348 } | 1341 } |
1349 | 1342 |
1350 // This time, allow SW renderer | 1343 // This time, allow SW renderer |
1351 pr = this->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr
, *strokeInfoPtr, | 1344 pr = this->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr
, *strokeInfoPtr, |
1352 true, type); | 1345 true, type); |
1353 } | 1346 } |
1354 | 1347 |
1355 if (NULL == pr) { | 1348 if (NULL == pr) { |
1356 #ifdef SK_DEBUG | 1349 #ifdef SK_DEBUG |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2000 geometry.fColor = GrRandomColor(random); | 1993 geometry.fColor = GrRandomColor(random); |
2001 return DrawVerticesBatch::Create(geometry, type, viewMatrix, | 1994 return DrawVerticesBatch::Create(geometry, type, viewMatrix, |
2002 positions.begin(), vertexCount, | 1995 positions.begin(), vertexCount, |
2003 indices.begin(), hasIndices ? vertexCount :
0, | 1996 indices.begin(), hasIndices ? vertexCount :
0, |
2004 colors.begin(), | 1997 colors.begin(), |
2005 texCoords.begin(), | 1998 texCoords.begin(), |
2006 bounds); | 1999 bounds); |
2007 } | 2000 } |
2008 | 2001 |
2009 #endif | 2002 #endif |
OLD | NEW |