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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 407 } |
408 | 408 |
409 AutoCheckFlush acf(this); | 409 AutoCheckFlush acf(this); |
410 GrPipelineBuilder pipelineBuilder; | 410 GrPipelineBuilder pipelineBuilder; |
411 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, paint,
&acf); | 411 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, paint,
&acf); |
412 if (NULL == target) { | 412 if (NULL == target) { |
413 return; | 413 return; |
414 } | 414 } |
415 | 415 |
416 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); | 416 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); |
417 target->drawRect(&pipelineBuilder, paint->getColor(), SkMatrix::I(), r,
NULL, &localMatrix); | 417 target->drawRect(&pipelineBuilder, |
| 418 paint->getColor(), |
| 419 SkMatrix::I(), |
| 420 r, |
| 421 NULL, |
| 422 &localMatrix); |
418 } | 423 } |
419 } | 424 } |
420 | 425 |
421 #ifdef SK_DEVELOPER | 426 #ifdef SK_DEVELOPER |
422 void GrContext::dumpFontCache() const { | 427 void GrContext::dumpFontCache() const { |
423 fFontCache->dump(); | 428 fFontCache->dump(); |
424 } | 429 } |
425 #endif | 430 #endif |
426 | 431 |
427 //////////////////////////////////////////////////////////////////////////////// | 432 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 530 |
526 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | 531 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
527 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); | 532 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); |
528 | 533 |
529 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 534 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
530 // cases where the RT is fully inside a stroke. | 535 // cases where the RT is fully inside a stroke. |
531 if (width < 0) { | 536 if (width < 0) { |
532 SkRect rtRect; | 537 SkRect rtRect; |
533 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); | 538 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); |
534 SkRect clipSpaceRTRect = rtRect; | 539 SkRect clipSpaceRTRect = rtRect; |
535 bool checkClip = false; | 540 bool checkClip = fClip && GrClip::kWideOpen_ClipType != fClip->clipType(
); |
536 if (this->getClip()) { | 541 if (checkClip) { |
537 checkClip = true; | 542 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->origin().fX), |
538 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX), | 543 SkIntToScalar(this->getClip()->origin().fY)); |
539 SkIntToScalar(this->getClip()->fOrigin.fY)); | |
540 } | 544 } |
541 // Does the clip contain the entire RT? | 545 // Does the clip contain the entire RT? |
542 if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpace
RTRect)) { | 546 if (!checkClip || fClip->clipStack()->quickContains(clipSpaceRTRect)) { |
543 SkMatrix invM; | 547 SkMatrix invM; |
544 if (!viewMatrix.invert(&invM)) { | 548 if (!viewMatrix.invert(&invM)) { |
545 return; | 549 return; |
546 } | 550 } |
547 // Does the rect bound the RT? | 551 // Does the rect bound the RT? |
548 SkPoint srcSpaceRTQuad[4]; | 552 SkPoint srcSpaceRTQuad[4]; |
549 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); | 553 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
550 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && | 554 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
551 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && | 555 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
552 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && | 556 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 const SkMatrix* localMatrix) { | 649 const SkMatrix* localMatrix) { |
646 AutoCheckFlush acf(this); | 650 AutoCheckFlush acf(this); |
647 GrPipelineBuilder pipelineBuilder; | 651 GrPipelineBuilder pipelineBuilder; |
648 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); | 652 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
649 if (NULL == target) { | 653 if (NULL == target) { |
650 return; | 654 return; |
651 } | 655 } |
652 | 656 |
653 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 657 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
654 | 658 |
655 target->drawRect(&pipelineBuilder, paint.getColor(), viewMatrix, rectToDraw,
&localRect, | 659 target->drawRect(&pipelineBuilder, |
| 660 paint.getColor(), |
| 661 viewMatrix, |
| 662 rectToDraw, |
| 663 &localRect, |
656 localMatrix); | 664 localMatrix); |
657 } | 665 } |
658 | 666 |
659 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords
, | 667 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords
, |
660 const GrColor* colors, | 668 const GrColor* colors, |
661 int* colorOffset, | 669 int* colorOffset, |
662 int* texOffset, | 670 int* texOffset, |
663 GrColor color, | 671 GrColor color, |
664 const SkMatrix& viewMatr
ix) { | 672 const SkMatrix& viewMatr
ix) { |
665 *texOffset = -1; | 673 *texOffset = -1; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); | 771 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
764 if (NULL == target) { | 772 if (NULL == target) { |
765 return; | 773 return; |
766 } | 774 } |
767 | 775 |
768 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | 776 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
769 | 777 |
770 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 778 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
771 | 779 |
772 GrColor color = paint.getColor(); | 780 GrColor color = paint.getColor(); |
773 if (!fOvalRenderer->drawRRect(target, &pipelineBuilder, color, viewMatrix, p
aint.isAntiAlias(), | 781 if (!fOvalRenderer->drawRRect(target, |
774 rrect, strokeRec)) { | 782 &pipelineBuilder, |
| 783 color, |
| 784 viewMatrix, |
| 785 paint.isAntiAlias(), |
| 786 rrect, |
| 787 strokeRec)) { |
775 SkPath path; | 788 SkPath path; |
776 path.addRRect(rrect); | 789 path.addRRect(rrect); |
777 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 790 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
778 path, strokeInfo); | 791 path, strokeInfo); |
779 } | 792 } |
780 } | 793 } |
781 | 794 |
782 /////////////////////////////////////////////////////////////////////////////// | 795 /////////////////////////////////////////////////////////////////////////////// |
783 | 796 |
784 void GrContext::drawDRRect(GrRenderTarget* rt, | 797 void GrContext::drawDRRect(GrRenderTarget* rt, |
785 const GrPaint& paint, | 798 const GrPaint& paint, |
786 const SkMatrix& viewMatrix, | 799 const SkMatrix& viewMatrix, |
787 const SkRRect& outer, | 800 const SkRRect& outer, |
788 const SkRRect& inner) { | 801 const SkRRect& inner) { |
789 if (outer.isEmpty()) { | 802 if (outer.isEmpty()) { |
790 return; | 803 return; |
791 } | 804 } |
792 | 805 |
793 AutoCheckFlush acf(this); | 806 AutoCheckFlush acf(this); |
794 GrPipelineBuilder pipelineBuilder; | 807 GrPipelineBuilder pipelineBuilder; |
795 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); | 808 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
796 | 809 |
797 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); | 810 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
798 | 811 |
799 GrColor color = paint.getColor(); | 812 GrColor color = paint.getColor(); |
800 if (!fOvalRenderer->drawDRRect(target, &pipelineBuilder, color, viewMatrix,
paint.isAntiAlias(), | 813 if (!fOvalRenderer->drawDRRect(target, |
801 outer, inner)) { | 814 &pipelineBuilder, |
| 815 color, |
| 816 viewMatrix, |
| 817 paint.isAntiAlias(), |
| 818 outer, |
| 819 inner)) { |
802 SkPath path; | 820 SkPath path; |
803 path.addRRect(inner); | 821 path.addRRect(inner); |
804 path.addRRect(outer); | 822 path.addRRect(outer); |
805 path.setFillType(SkPath::kEvenOdd_FillType); | 823 path.setFillType(SkPath::kEvenOdd_FillType); |
806 | 824 |
807 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); | 825 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
808 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 826 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
809 path, fillRec); | 827 path, fillRec); |
810 } | 828 } |
811 } | 829 } |
(...skipping 21 matching lines...) Expand all Loading... |
833 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); | 851 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
834 if (NULL == target) { | 852 if (NULL == target) { |
835 return; | 853 return; |
836 } | 854 } |
837 | 855 |
838 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | 856 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
839 | 857 |
840 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 858 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
841 | 859 |
842 GrColor color = paint.getColor(); | 860 GrColor color = paint.getColor(); |
843 if (!fOvalRenderer->drawOval(target, &pipelineBuilder, color, viewMatrix, pa
int.isAntiAlias(), | 861 if (!fOvalRenderer->drawOval(target, |
844 oval, strokeRec)) { | 862 &pipelineBuilder, |
| 863 color, |
| 864 viewMatrix, |
| 865 paint.isAntiAlias(), |
| 866 oval, |
| 867 strokeRec)) { |
845 SkPath path; | 868 SkPath path; |
846 path.addOval(oval); | 869 path.addOval(oval); |
847 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 870 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
848 path, strokeInfo); | 871 path, strokeInfo); |
849 } | 872 } |
850 } | 873 } |
851 | 874 |
852 // Can 'path' be drawn as a pair of filled nested rectangles? | 875 // Can 'path' be drawn as a pair of filled nested rectangles? |
853 static bool is_nested_rects(GrDrawTarget* target, | 876 static bool is_nested_rects(GrDrawTarget* target, |
854 GrPipelineBuilder* pipelineBuilder, | 877 GrPipelineBuilder* pipelineBuilder, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 991 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
969 | 992 |
970 bool useCoverageAA = paint.isAntiAlias() && | 993 bool useCoverageAA = paint.isAntiAlias() && |
971 !pipelineBuilder.getRenderTarget()->isMultisampled(); | 994 !pipelineBuilder.getRenderTarget()->isMultisampled(); |
972 | 995 |
973 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { | 996 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { |
974 // Concave AA paths are expensive - try to avoid them for special cases | 997 // Concave AA paths are expensive - try to avoid them for special cases |
975 SkRect rects[2]; | 998 SkRect rects[2]; |
976 | 999 |
977 if (is_nested_rects(target, &pipelineBuilder, color, viewMatrix, path, s
trokeRec, rects)) { | 1000 if (is_nested_rects(target, &pipelineBuilder, color, viewMatrix, path, s
trokeRec, rects)) { |
978 fAARectRenderer->fillAANestedRects(target, &pipelineBuilder, color,
viewMatrix,rects); | 1001 fAARectRenderer->fillAANestedRects(target, &pipelineBuilder, color,
viewMatrix, rects); |
979 return; | 1002 return; |
980 } | 1003 } |
981 } | 1004 } |
982 | 1005 |
983 SkRect ovalRect; | 1006 SkRect ovalRect; |
984 bool isOval = path.isOval(&ovalRect); | 1007 bool isOval = path.isOval(&ovalRect); |
985 | 1008 |
986 if (!isOval || path.isInverseFillType() || | 1009 if (!isOval || path.isInverseFillType() || |
987 !fOvalRenderer->drawOval(target, &pipelineBuilder, color, viewMatrix, pa
int.isAntiAlias(), | 1010 !fOvalRenderer->drawOval(target, |
988 ovalRect, strokeRec)) { | 1011 &pipelineBuilder, |
| 1012 color, |
| 1013 viewMatrix, |
| 1014 paint.isAntiAlias(), |
| 1015 ovalRect, |
| 1016 strokeRec)) { |
989 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 1017 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
990 path, strokeInfo); | 1018 path, strokeInfo); |
991 } | 1019 } |
992 } | 1020 } |
993 | 1021 |
994 void GrContext::internalDrawPath(GrDrawTarget* target, | 1022 void GrContext::internalDrawPath(GrDrawTarget* target, |
995 GrPipelineBuilder* pipelineBuilder, | 1023 GrPipelineBuilder* pipelineBuilder, |
996 const SkMatrix& viewMatrix, | 1024 const SkMatrix& viewMatrix, |
997 GrColor color, | 1025 GrColor color, |
998 bool useAA, | 1026 bool useAA, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before | 1210 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before |
1183 // drawing a rect to the render target. | 1211 // drawing a rect to the render target. |
1184 // The bracket ensures we pop the stack if we wind up flushing below. | 1212 // The bracket ensures we pop the stack if we wind up flushing below. |
1185 { | 1213 { |
1186 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL); | 1214 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL); |
1187 GrDrawTarget::AutoGeometryPush agp(drawTarget); | 1215 GrDrawTarget::AutoGeometryPush agp(drawTarget); |
1188 | 1216 |
1189 GrPipelineBuilder pipelineBuilder; | 1217 GrPipelineBuilder pipelineBuilder; |
1190 pipelineBuilder.addColorProcessor(fp); | 1218 pipelineBuilder.addColorProcessor(fp); |
1191 pipelineBuilder.setRenderTarget(renderTarget); | 1219 pipelineBuilder.setRenderTarget(renderTarget); |
1192 drawTarget->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, matrix, | 1220 drawTarget->drawSimpleRect(&pipelineBuilder, |
| 1221 GrColor_WHITE, |
| 1222 matrix, |
1193 SkRect::MakeWH(SkIntToScalar(width), SkIntToS
calar(height))); | 1223 SkRect::MakeWH(SkIntToScalar(width), SkIntToS
calar(height))); |
1194 } | 1224 } |
1195 | 1225 |
1196 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1226 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
1197 this->flushSurfaceWrites(surface); | 1227 this->flushSurfaceWrites(surface); |
1198 } | 1228 } |
1199 | 1229 |
1200 return true; | 1230 return true; |
1201 } | 1231 } |
1202 | 1232 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) | 1334 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) |
1305 // can be invoked in this method | 1335 // can be invoked in this method |
1306 { | 1336 { |
1307 GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); | 1337 GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); |
1308 GrPipelineBuilder pipelineBuilder; | 1338 GrPipelineBuilder pipelineBuilder; |
1309 SkASSERT(fp); | 1339 SkASSERT(fp); |
1310 pipelineBuilder.addColorProcessor(fp); | 1340 pipelineBuilder.addColorProcessor(fp); |
1311 | 1341 |
1312 pipelineBuilder.setRenderTarget(tempTexture->asRenderTarget(
)); | 1342 pipelineBuilder.setRenderTarget(tempTexture->asRenderTarget(
)); |
1313 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); | 1343 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); |
1314 fDrawBuffer->drawSimpleRect(&pipelineBuilder, GrColor_WHITE,
SkMatrix::I(), | 1344 fDrawBuffer->drawSimpleRect(&pipelineBuilder, |
| 1345 GrColor_WHITE, |
| 1346 SkMatrix::I(), |
1315 rect); | 1347 rect); |
1316 // we want to read back from the scratch's origin | 1348 // we want to read back from the scratch's origin |
1317 left = 0; | 1349 left = 0; |
1318 top = 0; | 1350 top = 0; |
1319 target = tempTexture->asRenderTarget(); | 1351 target = tempTexture->asRenderTarget(); |
1320 } | 1352 } |
1321 this->flushSurfaceWrites(target); | 1353 this->flushSurfaceWrites(target); |
1322 } | 1354 } |
1323 } | 1355 } |
1324 } | 1356 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 GrRenderTarget* rt, | 1436 GrRenderTarget* rt, |
1405 const GrPaint* paint, | 1437 const GrPaint* paint, |
1406 const AutoCheckFlush* acf) { | 1438 const AutoCheckFlush* acf) { |
1407 if (NULL == fGpu) { | 1439 if (NULL == fGpu) { |
1408 return NULL; | 1440 return NULL; |
1409 } | 1441 } |
1410 | 1442 |
1411 if (pipelineBuilder) { | 1443 if (pipelineBuilder) { |
1412 ASSERT_OWNED_RESOURCE(rt); | 1444 ASSERT_OWNED_RESOURCE(rt); |
1413 SkASSERT(rt && paint && acf); | 1445 SkASSERT(rt && paint && acf); |
1414 pipelineBuilder->setFromPaint(*paint, rt); | 1446 pipelineBuilder->setFromPaint(*paint, rt, fClip); |
1415 pipelineBuilder->setState(GrPipelineBuilder::kClip_StateBit, | |
1416 fClip && !fClip->fClipStack->isWideOpen()); | |
1417 } | 1447 } |
1418 fDrawBuffer->setClip(fClip); | |
1419 return fDrawBuffer; | 1448 return fDrawBuffer; |
1420 } | 1449 } |
1421 | 1450 |
1422 /* | 1451 /* |
1423 * This method finds a path renderer that can draw the specified path on | 1452 * This method finds a path renderer that can draw the specified path on |
1424 * the provided target. | 1453 * the provided target. |
1425 * Due to its expense, the software path renderer has split out so it can | 1454 * Due to its expense, the software path renderer has split out so it can |
1426 * can be individually allowed/disallowed via the "allowSW" boolean. | 1455 * can be individually allowed/disallowed via the "allowSW" boolean. |
1427 */ | 1456 */ |
1428 GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, | 1457 GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 } | 1616 } |
1588 } | 1617 } |
1589 | 1618 |
1590 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1619 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
1591 fGpu->removeGpuTraceMarker(marker); | 1620 fGpu->removeGpuTraceMarker(marker); |
1592 if (fDrawBuffer) { | 1621 if (fDrawBuffer) { |
1593 fDrawBuffer->removeGpuTraceMarker(marker); | 1622 fDrawBuffer->removeGpuTraceMarker(marker); |
1594 } | 1623 } |
1595 } | 1624 } |
1596 | 1625 |
OLD | NEW |