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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 522 |
518 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | 523 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
519 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); | 524 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); |
520 | 525 |
521 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 526 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
522 // cases where the RT is fully inside a stroke. | 527 // cases where the RT is fully inside a stroke. |
523 if (width < 0) { | 528 if (width < 0) { |
524 SkRect rtRect; | 529 SkRect rtRect; |
525 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); | 530 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); |
526 SkRect clipSpaceRTRect = rtRect; | 531 SkRect clipSpaceRTRect = rtRect; |
527 bool checkClip = false; | 532 bool checkClip = fClip && GrClip::kWideOpen_ClipType != fClip->clipType(
); |
528 if (this->getClip()) { | 533 if (checkClip) { |
529 checkClip = true; | 534 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->origin().fX), |
530 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX), | 535 SkIntToScalar(this->getClip()->origin().fY)); |
531 SkIntToScalar(this->getClip()->fOrigin.fY)); | |
532 } | 536 } |
533 // Does the clip contain the entire RT? | 537 // Does the clip contain the entire RT? |
534 if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpace
RTRect)) { | 538 if (!checkClip || fClip->clipStack()->quickContains(clipSpaceRTRect)) { |
535 SkMatrix invM; | 539 SkMatrix invM; |
536 if (!viewMatrix.invert(&invM)) { | 540 if (!viewMatrix.invert(&invM)) { |
537 return; | 541 return; |
538 } | 542 } |
539 // Does the rect bound the RT? | 543 // Does the rect bound the RT? |
540 SkPoint srcSpaceRTQuad[4]; | 544 SkPoint srcSpaceRTQuad[4]; |
541 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); | 545 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
542 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && | 546 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
543 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && | 547 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
544 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && | 548 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 const SkMatrix* localMatrix) { | 641 const SkMatrix* localMatrix) { |
638 AutoCheckFlush acf(this); | 642 AutoCheckFlush acf(this); |
639 GrPipelineBuilder pipelineBuilder; | 643 GrPipelineBuilder pipelineBuilder; |
640 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); | 644 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
641 if (NULL == target) { | 645 if (NULL == target) { |
642 return; | 646 return; |
643 } | 647 } |
644 | 648 |
645 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 649 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
646 | 650 |
647 target->drawRect(&pipelineBuilder, paint.getColor(), viewMatrix, rectToDraw,
&localRect, | 651 target->drawRect(&pipelineBuilder, |
| 652 paint.getColor(), |
| 653 viewMatrix, |
| 654 rectToDraw, |
| 655 &localRect, |
648 localMatrix); | 656 localMatrix); |
649 } | 657 } |
650 | 658 |
651 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords
, | 659 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords
, |
652 const GrColor* colors, | 660 const GrColor* colors, |
653 int* colorOffset, | 661 int* colorOffset, |
654 int* texOffset, | 662 int* texOffset, |
655 GrColor color, | 663 GrColor color, |
656 const SkMatrix& viewMatr
ix) { | 664 const SkMatrix& viewMatr
ix) { |
657 *texOffset = -1; | 665 *texOffset = -1; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); | 763 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
756 if (NULL == target) { | 764 if (NULL == target) { |
757 return; | 765 return; |
758 } | 766 } |
759 | 767 |
760 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | 768 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
761 | 769 |
762 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 770 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
763 | 771 |
764 GrColor color = paint.getColor(); | 772 GrColor color = paint.getColor(); |
765 if (!fOvalRenderer->drawRRect(target, &pipelineBuilder, color, viewMatrix, p
aint.isAntiAlias(), | 773 if (!fOvalRenderer->drawRRect(target, |
766 rrect, strokeRec)) { | 774 &pipelineBuilder, |
| 775 color, |
| 776 viewMatrix, |
| 777 paint.isAntiAlias(), |
| 778 rrect, |
| 779 strokeRec)) { |
767 SkPath path; | 780 SkPath path; |
768 path.addRRect(rrect); | 781 path.addRRect(rrect); |
769 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 782 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
770 path, strokeInfo); | 783 path, strokeInfo); |
771 } | 784 } |
772 } | 785 } |
773 | 786 |
774 /////////////////////////////////////////////////////////////////////////////// | 787 /////////////////////////////////////////////////////////////////////////////// |
775 | 788 |
776 void GrContext::drawDRRect(GrRenderTarget* rt, | 789 void GrContext::drawDRRect(GrRenderTarget* rt, |
777 const GrPaint& paint, | 790 const GrPaint& paint, |
778 const SkMatrix& viewMatrix, | 791 const SkMatrix& viewMatrix, |
779 const SkRRect& outer, | 792 const SkRRect& outer, |
780 const SkRRect& inner) { | 793 const SkRRect& inner) { |
781 if (outer.isEmpty()) { | 794 if (outer.isEmpty()) { |
782 return; | 795 return; |
783 } | 796 } |
784 | 797 |
785 AutoCheckFlush acf(this); | 798 AutoCheckFlush acf(this); |
786 GrPipelineBuilder pipelineBuilder; | 799 GrPipelineBuilder pipelineBuilder; |
787 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); | 800 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
788 | 801 |
789 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); | 802 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
790 | 803 |
791 GrColor color = paint.getColor(); | 804 GrColor color = paint.getColor(); |
792 if (!fOvalRenderer->drawDRRect(target, &pipelineBuilder, color, viewMatrix,
paint.isAntiAlias(), | 805 if (!fOvalRenderer->drawDRRect(target, |
793 outer, inner)) { | 806 &pipelineBuilder, |
| 807 color, |
| 808 viewMatrix, |
| 809 paint.isAntiAlias(), |
| 810 outer, |
| 811 inner)) { |
794 SkPath path; | 812 SkPath path; |
795 path.addRRect(inner); | 813 path.addRRect(inner); |
796 path.addRRect(outer); | 814 path.addRRect(outer); |
797 path.setFillType(SkPath::kEvenOdd_FillType); | 815 path.setFillType(SkPath::kEvenOdd_FillType); |
798 | 816 |
799 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); | 817 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
800 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 818 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
801 path, fillRec); | 819 path, fillRec); |
802 } | 820 } |
803 } | 821 } |
(...skipping 21 matching lines...) Expand all Loading... |
825 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); | 843 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
826 if (NULL == target) { | 844 if (NULL == target) { |
827 return; | 845 return; |
828 } | 846 } |
829 | 847 |
830 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | 848 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
831 | 849 |
832 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 850 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
833 | 851 |
834 GrColor color = paint.getColor(); | 852 GrColor color = paint.getColor(); |
835 if (!fOvalRenderer->drawOval(target, &pipelineBuilder, color, viewMatrix, pa
int.isAntiAlias(), | 853 if (!fOvalRenderer->drawOval(target, |
836 oval, strokeRec)) { | 854 &pipelineBuilder, |
| 855 color, |
| 856 viewMatrix, |
| 857 paint.isAntiAlias(), |
| 858 oval, |
| 859 strokeRec)) { |
837 SkPath path; | 860 SkPath path; |
838 path.addOval(oval); | 861 path.addOval(oval); |
839 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 862 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
840 path, strokeInfo); | 863 path, strokeInfo); |
841 } | 864 } |
842 } | 865 } |
843 | 866 |
844 // Can 'path' be drawn as a pair of filled nested rectangles? | 867 // Can 'path' be drawn as a pair of filled nested rectangles? |
845 static bool is_nested_rects(GrDrawTarget* target, | 868 static bool is_nested_rects(GrDrawTarget* target, |
846 GrPipelineBuilder* pipelineBuilder, | 869 GrPipelineBuilder* pipelineBuilder, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 978 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
956 | 979 |
957 bool useCoverageAA = paint.isAntiAlias() && | 980 bool useCoverageAA = paint.isAntiAlias() && |
958 !pipelineBuilder.getRenderTarget()->isMultisampled(); | 981 !pipelineBuilder.getRenderTarget()->isMultisampled(); |
959 | 982 |
960 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { | 983 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { |
961 // Concave AA paths are expensive - try to avoid them for special cases | 984 // Concave AA paths are expensive - try to avoid them for special cases |
962 SkRect rects[2]; | 985 SkRect rects[2]; |
963 | 986 |
964 if (is_nested_rects(target, &pipelineBuilder, color, viewMatrix, path, s
trokeRec, rects)) { | 987 if (is_nested_rects(target, &pipelineBuilder, color, viewMatrix, path, s
trokeRec, rects)) { |
965 fAARectRenderer->fillAANestedRects(target, &pipelineBuilder, color,
viewMatrix,rects); | 988 fAARectRenderer->fillAANestedRects(target, &pipelineBuilder, color,
viewMatrix, rects); |
966 return; | 989 return; |
967 } | 990 } |
968 } | 991 } |
969 | 992 |
970 SkRect ovalRect; | 993 SkRect ovalRect; |
971 bool isOval = path.isOval(&ovalRect); | 994 bool isOval = path.isOval(&ovalRect); |
972 | 995 |
973 if (!isOval || path.isInverseFillType() || | 996 if (!isOval || path.isInverseFillType() || |
974 !fOvalRenderer->drawOval(target, &pipelineBuilder, color, viewMatrix, pa
int.isAntiAlias(), | 997 !fOvalRenderer->drawOval(target, |
975 ovalRect, strokeRec)) { | 998 &pipelineBuilder, |
| 999 color, |
| 1000 viewMatrix, |
| 1001 paint.isAntiAlias(), |
| 1002 ovalRect, |
| 1003 strokeRec)) { |
976 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 1004 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
977 path, strokeInfo); | 1005 path, strokeInfo); |
978 } | 1006 } |
979 } | 1007 } |
980 | 1008 |
981 void GrContext::internalDrawPath(GrDrawTarget* target, | 1009 void GrContext::internalDrawPath(GrDrawTarget* target, |
982 GrPipelineBuilder* pipelineBuilder, | 1010 GrPipelineBuilder* pipelineBuilder, |
983 const SkMatrix& viewMatrix, | 1011 const SkMatrix& viewMatrix, |
984 GrColor color, | 1012 GrColor color, |
985 bool useAA, | 1013 bool useAA, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before | 1196 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before |
1169 // drawing a rect to the render target. | 1197 // drawing a rect to the render target. |
1170 // The bracket ensures we pop the stack if we wind up flushing below. | 1198 // The bracket ensures we pop the stack if we wind up flushing below. |
1171 { | 1199 { |
1172 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL); | 1200 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL); |
1173 GrDrawTarget::AutoGeometryPush agp(drawTarget); | 1201 GrDrawTarget::AutoGeometryPush agp(drawTarget); |
1174 | 1202 |
1175 GrPipelineBuilder pipelineBuilder; | 1203 GrPipelineBuilder pipelineBuilder; |
1176 pipelineBuilder.addColorProcessor(fp); | 1204 pipelineBuilder.addColorProcessor(fp); |
1177 pipelineBuilder.setRenderTarget(renderTarget); | 1205 pipelineBuilder.setRenderTarget(renderTarget); |
1178 drawTarget->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, matrix, | 1206 drawTarget->drawSimpleRect(&pipelineBuilder, |
| 1207 GrColor_WHITE, |
| 1208 matrix, |
1179 SkRect::MakeWH(SkIntToScalar(width), SkIntToS
calar(height))); | 1209 SkRect::MakeWH(SkIntToScalar(width), SkIntToS
calar(height))); |
1180 } | 1210 } |
1181 | 1211 |
1182 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1212 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
1183 this->flushSurfaceWrites(surface); | 1213 this->flushSurfaceWrites(surface); |
1184 } | 1214 } |
1185 | 1215 |
1186 return true; | 1216 return true; |
1187 } | 1217 } |
1188 | 1218 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) | 1320 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) |
1291 // can be invoked in this method | 1321 // can be invoked in this method |
1292 { | 1322 { |
1293 GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); | 1323 GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); |
1294 GrPipelineBuilder pipelineBuilder; | 1324 GrPipelineBuilder pipelineBuilder; |
1295 SkASSERT(fp); | 1325 SkASSERT(fp); |
1296 pipelineBuilder.addColorProcessor(fp); | 1326 pipelineBuilder.addColorProcessor(fp); |
1297 | 1327 |
1298 pipelineBuilder.setRenderTarget(tempTexture->asRenderTarget(
)); | 1328 pipelineBuilder.setRenderTarget(tempTexture->asRenderTarget(
)); |
1299 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); | 1329 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); |
1300 fDrawBuffer->drawSimpleRect(&pipelineBuilder, GrColor_WHITE,
SkMatrix::I(), | 1330 fDrawBuffer->drawSimpleRect(&pipelineBuilder, |
| 1331 GrColor_WHITE, |
| 1332 SkMatrix::I(), |
1301 rect); | 1333 rect); |
1302 // we want to read back from the scratch's origin | 1334 // we want to read back from the scratch's origin |
1303 left = 0; | 1335 left = 0; |
1304 top = 0; | 1336 top = 0; |
1305 target = tempTexture->asRenderTarget(); | 1337 target = tempTexture->asRenderTarget(); |
1306 } | 1338 } |
1307 this->flushSurfaceWrites(target); | 1339 this->flushSurfaceWrites(target); |
1308 } | 1340 } |
1309 } | 1341 } |
1310 } | 1342 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 GrRenderTarget* rt, | 1422 GrRenderTarget* rt, |
1391 const GrPaint* paint, | 1423 const GrPaint* paint, |
1392 const AutoCheckFlush* acf) { | 1424 const AutoCheckFlush* acf) { |
1393 if (NULL == fGpu) { | 1425 if (NULL == fGpu) { |
1394 return NULL; | 1426 return NULL; |
1395 } | 1427 } |
1396 | 1428 |
1397 if (pipelineBuilder) { | 1429 if (pipelineBuilder) { |
1398 ASSERT_OWNED_RESOURCE(rt); | 1430 ASSERT_OWNED_RESOURCE(rt); |
1399 SkASSERT(rt && paint && acf); | 1431 SkASSERT(rt && paint && acf); |
1400 pipelineBuilder->setFromPaint(*paint, rt); | 1432 pipelineBuilder->setFromPaint(*paint, rt, fClip); |
1401 pipelineBuilder->setState(GrPipelineBuilder::kClip_StateBit, | |
1402 fClip && !fClip->fClipStack->isWideOpen()); | |
1403 } | 1433 } |
1404 fDrawBuffer->setClip(fClip); | |
1405 return fDrawBuffer; | 1434 return fDrawBuffer; |
1406 } | 1435 } |
1407 | 1436 |
1408 /* | 1437 /* |
1409 * This method finds a path renderer that can draw the specified path on | 1438 * This method finds a path renderer that can draw the specified path on |
1410 * the provided target. | 1439 * the provided target. |
1411 * Due to its expense, the software path renderer has split out so it can | 1440 * Due to its expense, the software path renderer has split out so it can |
1412 * can be individually allowed/disallowed via the "allowSW" boolean. | 1441 * can be individually allowed/disallowed via the "allowSW" boolean. |
1413 */ | 1442 */ |
1414 GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, | 1443 GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 } | 1602 } |
1574 } | 1603 } |
1575 | 1604 |
1576 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1605 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
1577 fGpu->removeGpuTraceMarker(marker); | 1606 fGpu->removeGpuTraceMarker(marker); |
1578 if (fDrawBuffer) { | 1607 if (fDrawBuffer) { |
1579 fDrawBuffer->removeGpuTraceMarker(marker); | 1608 fDrawBuffer->removeGpuTraceMarker(marker); |
1580 } | 1609 } |
1581 } | 1610 } |
1582 | 1611 |
OLD | NEW |