Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Side by Side Diff: src/gpu/GrOvalRenderer.cpp

Issue 1731413002: Hide GrDrawTarget from GrOvalRenderer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: erg! Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrOvalRenderer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "GrOvalRenderer.h" 8 #include "GrOvalRenderer.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
11 #include "GrBatchTest.h" 11 #include "GrBatchTest.h"
12 #include "GrDrawTarget.h"
13 #include "GrGeometryProcessor.h" 12 #include "GrGeometryProcessor.h"
14 #include "GrInvariantOutput.h" 13 #include "GrInvariantOutput.h"
15 #include "GrPipelineBuilder.h" 14 #include "GrPipelineBuilder.h"
16 #include "GrProcessor.h" 15 #include "GrProcessor.h"
17 #include "GrResourceProvider.h" 16 #include "GrResourceProvider.h"
18 #include "GrVertexBuffer.h"
19 #include "SkRRect.h" 17 #include "SkRRect.h"
20 #include "SkStrokeRec.h" 18 #include "SkStrokeRec.h"
21 #include "SkTLazy.h"
22 #include "batches/GrRectBatchFactory.h"
23 #include "batches/GrVertexBatch.h" 19 #include "batches/GrVertexBatch.h"
24 #include "effects/GrRRectEffect.h"
25 #include "glsl/GrGLSLFragmentShaderBuilder.h" 20 #include "glsl/GrGLSLFragmentShaderBuilder.h"
26 #include "glsl/GrGLSLGeometryProcessor.h" 21 #include "glsl/GrGLSLGeometryProcessor.h"
27 #include "glsl/GrGLSLProgramDataManager.h" 22 #include "glsl/GrGLSLProgramDataManager.h"
28 #include "glsl/GrGLSLVarying.h" 23 #include "glsl/GrGLSLVarying.h"
29 #include "glsl/GrGLSLVertexShaderBuilder.h" 24 #include "glsl/GrGLSLVertexShaderBuilder.h"
30 #include "glsl/GrGLSLUniformHandler.h" 25 #include "glsl/GrGLSLUniformHandler.h"
31 #include "glsl/GrGLSLUtil.h" 26 #include "glsl/GrGLSLUtil.h"
32 27
33 // TODO(joshualitt) - Break this file up during GrBatch post implementation clea nup 28 // TODO(joshualitt) - Break this file up during GrBatch post implementation clea nup
34 29
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 573
579 const GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(GrProcessorTestData* d) { 574 const GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(GrProcessorTestData* d) {
580 return DIEllipseEdgeEffect::Create(GrRandomColor(d->fRandom), 575 return DIEllipseEdgeEffect::Create(GrRandomColor(d->fRandom),
581 GrTest::TestMatrix(d->fRandom), 576 GrTest::TestMatrix(d->fRandom),
582 (Mode)(d->fRandom->nextRangeU(0,2)), 577 (Mode)(d->fRandom->nextRangeU(0,2)),
583 d->fRandom->nextBool()); 578 d->fRandom->nextBool());
584 } 579 }
585 580
586 /////////////////////////////////////////////////////////////////////////////// 581 ///////////////////////////////////////////////////////////////////////////////
587 582
588 bool GrOvalRenderer::DrawOval(GrDrawTarget* target, 583 GrDrawBatch* GrOvalRenderer::CreateOvalBatch(const GrPipelineBuilder& pipelineBu ilder,
589 const GrPipelineBuilder& pipelineBuilder, 584 GrColor color,
590 GrColor color, 585 const SkMatrix& viewMatrix,
591 const SkMatrix& viewMatrix, 586 bool useAA,
592 bool useAA, 587 const SkRect& oval,
593 const SkRect& oval, 588 const SkStrokeRec& stroke,
594 const SkStrokeRec& stroke) { 589 GrShaderCaps* shaderCaps) {
595 bool useCoverageAA = useAA && !pipelineBuilder.getRenderTarget()->isUnifiedM ultisampled(); 590 bool useCoverageAA = useAA && !pipelineBuilder.getRenderTarget()->isUnifiedM ultisampled();
596
597 if (!useCoverageAA) { 591 if (!useCoverageAA) {
598 return false; 592 return nullptr;
599 } 593 }
600 594
601 // we can draw circles 595 // we can draw circles
602 if (SkScalarNearlyEqual(oval.width(), oval.height()) && circle_stays_circle( viewMatrix)) { 596 if (SkScalarNearlyEqual(oval.width(), oval.height()) && circle_stays_circle( viewMatrix)) {
603 DrawCircle(target, pipelineBuilder, color, viewMatrix, useCoverageAA, ov al, stroke); 597 return CreateCircleBatch(color, viewMatrix, oval, stroke);
598 }
599
604 // if we have shader derivative support, render as device-independent 600 // if we have shader derivative support, render as device-independent
605 } else if (target->caps()->shaderCaps()->shaderDerivativeSupport()) { 601 if (shaderCaps->shaderDerivativeSupport()) {
606 return DrawDIEllipse(target, pipelineBuilder, color, viewMatrix, useCove rageAA, oval, 602 return CreateDIEllipseBatch(color, viewMatrix, oval, stroke);
607 stroke); 603 }
604
608 // otherwise axis-aligned ellipses only 605 // otherwise axis-aligned ellipses only
609 } else if (viewMatrix.rectStaysRect()) { 606 if (viewMatrix.rectStaysRect()) {
610 return DrawEllipse(target, pipelineBuilder, color, viewMatrix, useCovera geAA, oval, 607 return CreateEllipseBatch(color, viewMatrix, oval, stroke);
611 stroke);
612 } else {
613 return false;
614 } 608 }
615 609
616 return true; 610 return nullptr;
617 } 611 }
618 612
619 /////////////////////////////////////////////////////////////////////////////// 613 ///////////////////////////////////////////////////////////////////////////////
620 614
621 class CircleBatch : public GrVertexBatch { 615 class CircleBatch : public GrVertexBatch {
622 public: 616 public:
623 DEFINE_BATCH_CLASS_ID 617 DEFINE_BATCH_CLASS_ID
624 618
625 struct Geometry { 619 struct Geometry {
626 SkMatrix fViewMatrix; 620 SkMatrix fViewMatrix;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 }; 775 };
782 776
783 BatchTracker fBatch; 777 BatchTracker fBatch;
784 SkSTArray<1, Geometry, true> fGeoData; 778 SkSTArray<1, Geometry, true> fGeoData;
785 779
786 typedef GrVertexBatch INHERITED; 780 typedef GrVertexBatch INHERITED;
787 }; 781 };
788 782
789 static GrDrawBatch* create_circle_batch(GrColor color, 783 static GrDrawBatch* create_circle_batch(GrColor color,
790 const SkMatrix& viewMatrix, 784 const SkMatrix& viewMatrix,
791 bool useCoverageAA,
792 const SkRect& circle, 785 const SkRect& circle,
793 const SkStrokeRec& stroke) { 786 const SkStrokeRec& stroke) {
794 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); 787 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY());
795 viewMatrix.mapPoints(&center, 1); 788 viewMatrix.mapPoints(&center, 1);
796 SkScalar radius = viewMatrix.mapRadius(SkScalarHalf(circle.width())); 789 SkScalar radius = viewMatrix.mapRadius(SkScalarHalf(circle.width()));
797 SkScalar strokeWidth = viewMatrix.mapRadius(stroke.getWidth()); 790 SkScalar strokeWidth = viewMatrix.mapRadius(stroke.getWidth());
798 791
799 SkStrokeRec::Style style = stroke.getStyle(); 792 SkStrokeRec::Style style = stroke.getStyle();
800 bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || 793 bool isStrokeOnly = SkStrokeRec::kStroke_Style == style ||
801 SkStrokeRec::kHairline_Style == style; 794 SkStrokeRec::kHairline_Style == style;
(...skipping 27 matching lines...) Expand all
829 geometry.fColor = color; 822 geometry.fColor = color;
830 geometry.fInnerRadius = innerRadius; 823 geometry.fInnerRadius = innerRadius;
831 geometry.fOuterRadius = outerRadius; 824 geometry.fOuterRadius = outerRadius;
832 geometry.fStroke = isStrokeOnly && innerRadius > 0; 825 geometry.fStroke = isStrokeOnly && innerRadius > 0;
833 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - outerRadius, center.fY - outerRadius, 826 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - outerRadius, center.fY - outerRadius,
834 center.fX + outerRadius, center.fY + outerRadius); 827 center.fX + outerRadius, center.fY + outerRadius);
835 828
836 return CircleBatch::Create(geometry); 829 return CircleBatch::Create(geometry);
837 } 830 }
838 831
839 void GrOvalRenderer::DrawCircle(GrDrawTarget* target, 832 GrDrawBatch* GrOvalRenderer::CreateCircleBatch(GrColor color,
840 const GrPipelineBuilder& pipelineBuilder, 833 const SkMatrix& viewMatrix,
841 GrColor color, 834 const SkRect& circle,
842 const SkMatrix& viewMatrix, 835 const SkStrokeRec& stroke) {
843 bool useCoverageAA, 836 return create_circle_batch(color, viewMatrix, circle, stroke);
844 const SkRect& circle,
845 const SkStrokeRec& stroke) {
846 SkAutoTUnref<GrDrawBatch> batch(create_circle_batch(color, viewMatrix, useCo verageAA, circle,
847 stroke));
848 target->drawBatch(pipelineBuilder, batch);
849 } 837 }
850 838
851 /////////////////////////////////////////////////////////////////////////////// 839 ///////////////////////////////////////////////////////////////////////////////
852 840
853 class EllipseBatch : public GrVertexBatch { 841 class EllipseBatch : public GrVertexBatch {
854 public: 842 public:
855 DEFINE_BATCH_CLASS_ID 843 DEFINE_BATCH_CLASS_ID
856 844
857 struct Geometry { 845 struct Geometry {
858 SkMatrix fViewMatrix; 846 SkMatrix fViewMatrix;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 }; 994 };
1007 995
1008 BatchTracker fBatch; 996 BatchTracker fBatch;
1009 SkSTArray<1, Geometry, true> fGeoData; 997 SkSTArray<1, Geometry, true> fGeoData;
1010 998
1011 typedef GrVertexBatch INHERITED; 999 typedef GrVertexBatch INHERITED;
1012 }; 1000 };
1013 1001
1014 static GrDrawBatch* create_ellipse_batch(GrColor color, 1002 static GrDrawBatch* create_ellipse_batch(GrColor color,
1015 const SkMatrix& viewMatrix, 1003 const SkMatrix& viewMatrix,
1016 bool useCoverageAA,
1017 const SkRect& ellipse, 1004 const SkRect& ellipse,
1018 const SkStrokeRec& stroke) { 1005 const SkStrokeRec& stroke) {
1019 #ifdef SK_DEBUG 1006 SkASSERT(viewMatrix.rectStaysRect());
1020 {
1021 // we should have checked for this previously
1022 bool isAxisAlignedEllipse = viewMatrix.rectStaysRect();
1023 SkASSERT(useCoverageAA && isAxisAlignedEllipse);
1024 }
1025 #endif
1026 1007
1027 // do any matrix crunching before we reset the draw state for device coords 1008 // do any matrix crunching before we reset the draw state for device coords
1028 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); 1009 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY());
1029 viewMatrix.mapPoints(&center, 1); 1010 viewMatrix.mapPoints(&center, 1);
1030 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); 1011 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width());
1031 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); 1012 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height());
1032 SkScalar xRadius = SkScalarAbs(viewMatrix[SkMatrix::kMScaleX]*ellipseXRadius + 1013 SkScalar xRadius = SkScalarAbs(viewMatrix[SkMatrix::kMScaleX]*ellipseXRadius +
1033 viewMatrix[SkMatrix::kMSkewY]*ellipseYRadius) ; 1014 viewMatrix[SkMatrix::kMSkewY]*ellipseYRadius) ;
1034 SkScalar yRadius = SkScalarAbs(viewMatrix[SkMatrix::kMSkewX]*ellipseXRadius + 1015 SkScalar yRadius = SkScalarAbs(viewMatrix[SkMatrix::kMSkewX]*ellipseXRadius +
1035 viewMatrix[SkMatrix::kMScaleY]*ellipseYRadius ); 1016 viewMatrix[SkMatrix::kMScaleY]*ellipseYRadius );
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 geometry.fYRadius = yRadius; 1072 geometry.fYRadius = yRadius;
1092 geometry.fInnerXRadius = innerXRadius; 1073 geometry.fInnerXRadius = innerXRadius;
1093 geometry.fInnerYRadius = innerYRadius; 1074 geometry.fInnerYRadius = innerYRadius;
1094 geometry.fStroke = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0; 1075 geometry.fStroke = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0;
1095 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRad ius, 1076 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRad ius,
1096 center.fX + xRadius, center.fY + yRad ius); 1077 center.fX + xRadius, center.fY + yRad ius);
1097 1078
1098 return EllipseBatch::Create(geometry); 1079 return EllipseBatch::Create(geometry);
1099 } 1080 }
1100 1081
1101 bool GrOvalRenderer::DrawEllipse(GrDrawTarget* target, 1082 GrDrawBatch* GrOvalRenderer::CreateEllipseBatch(GrColor color,
1102 const GrPipelineBuilder& pipelineBuilder, 1083 const SkMatrix& viewMatrix,
1103 GrColor color, 1084 const SkRect& ellipse,
1104 const SkMatrix& viewMatrix, 1085 const SkStrokeRec& stroke) {
1105 bool useCoverageAA, 1086 return create_ellipse_batch(color, viewMatrix, ellipse, stroke);
1106 const SkRect& ellipse,
1107 const SkStrokeRec& stroke) {
1108 SkAutoTUnref<GrDrawBatch> batch(create_ellipse_batch(color, viewMatrix, useC overageAA, ellipse,
1109 stroke));
1110 if (!batch) {
1111 return false;
1112 }
1113
1114 target->drawBatch(pipelineBuilder, batch);
1115 return true;
1116 } 1087 }
1117 1088
1118 //////////////////////////////////////////////////////////////////////////////// ///////////////// 1089 //////////////////////////////////////////////////////////////////////////////// /////////////////
1119 1090
1120 class DIEllipseBatch : public GrVertexBatch { 1091 class DIEllipseBatch : public GrVertexBatch {
1121 public: 1092 public:
1122 DEFINE_BATCH_CLASS_ID 1093 DEFINE_BATCH_CLASS_ID
1123 1094
1124 struct Geometry { 1095 struct Geometry {
1125 SkMatrix fViewMatrix; 1096 SkMatrix fViewMatrix;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 }; 1239 };
1269 1240
1270 BatchTracker fBatch; 1241 BatchTracker fBatch;
1271 SkSTArray<1, Geometry, true> fGeoData; 1242 SkSTArray<1, Geometry, true> fGeoData;
1272 1243
1273 typedef GrVertexBatch INHERITED; 1244 typedef GrVertexBatch INHERITED;
1274 }; 1245 };
1275 1246
1276 static GrDrawBatch* create_diellipse_batch(GrColor color, 1247 static GrDrawBatch* create_diellipse_batch(GrColor color,
1277 const SkMatrix& viewMatrix, 1248 const SkMatrix& viewMatrix,
1278 bool useCoverageAA,
1279 const SkRect& ellipse, 1249 const SkRect& ellipse,
1280 const SkStrokeRec& stroke) { 1250 const SkStrokeRec& stroke) {
1281 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); 1251 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY());
1282 SkScalar xRadius = SkScalarHalf(ellipse.width()); 1252 SkScalar xRadius = SkScalarHalf(ellipse.width());
1283 SkScalar yRadius = SkScalarHalf(ellipse.height()); 1253 SkScalar yRadius = SkScalarHalf(ellipse.height());
1284 1254
1285 SkStrokeRec::Style style = stroke.getStyle(); 1255 SkStrokeRec::Style style = stroke.getStyle();
1286 DIEllipseEdgeEffect::Mode mode = (SkStrokeRec::kStroke_Style == style) ? 1256 DIEllipseEdgeEffect::Mode mode = (SkStrokeRec::kStroke_Style == style) ?
1287 DIEllipseEdgeEffect::kStroke : 1257 DIEllipseEdgeEffect::kStroke :
1288 (SkStrokeRec::kHairline_Style == style) ? 1258 (SkStrokeRec::kHairline_Style == style) ?
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 geometry.fGeoDy = geoDy; 1314 geometry.fGeoDy = geoDy;
1345 geometry.fMode = mode; 1315 geometry.fMode = mode;
1346 geometry.fBounds = SkRect::MakeLTRB(center.fX - xRadius - geoDx, center.fY - yRadius - geoDy, 1316 geometry.fBounds = SkRect::MakeLTRB(center.fX - xRadius - geoDx, center.fY - yRadius - geoDy,
1347 center.fX + xRadius + geoDx, center.fY + yRadius + geoDy); 1317 center.fX + xRadius + geoDx, center.fY + yRadius + geoDy);
1348 1318
1349 SkRect devBounds = geometry.fBounds; 1319 SkRect devBounds = geometry.fBounds;
1350 viewMatrix.mapRect(&devBounds); 1320 viewMatrix.mapRect(&devBounds);
1351 return DIEllipseBatch::Create(geometry, devBounds); 1321 return DIEllipseBatch::Create(geometry, devBounds);
1352 } 1322 }
1353 1323
1354 bool GrOvalRenderer::DrawDIEllipse(GrDrawTarget* target, 1324 GrDrawBatch* GrOvalRenderer::CreateDIEllipseBatch(GrColor color,
1355 const GrPipelineBuilder& pipelineBuilder, 1325 const SkMatrix& viewMatrix,
1356 GrColor color, 1326 const SkRect& ellipse,
1357 const SkMatrix& viewMatrix, 1327 const SkStrokeRec& stroke) {
1358 bool useCoverageAA, 1328 return create_diellipse_batch(color, viewMatrix, ellipse, stroke);
1359 const SkRect& ellipse,
1360 const SkStrokeRec& stroke) {
1361 SkAutoTUnref<GrDrawBatch> batch(create_diellipse_batch(color, viewMatrix, us eCoverageAA,
1362 ellipse, stroke));
1363 if (!batch) {
1364 return false;
1365 }
1366 target->drawBatch(pipelineBuilder, batch);
1367 return true;
1368 } 1329 }
1369 1330
1370 /////////////////////////////////////////////////////////////////////////////// 1331 ///////////////////////////////////////////////////////////////////////////////
1371 1332
1372 static const uint16_t gRRectIndices[] = { 1333 static const uint16_t gRRectIndices[] = {
1373 // corners 1334 // corners
1374 0, 1, 5, 0, 5, 4, 1335 0, 1, 5, 0, 5, 4,
1375 2, 3, 7, 2, 7, 6, 1336 2, 3, 7, 2, 7, 6,
1376 8, 9, 13, 8, 13, 12, 1337 8, 9, 13, 8, 13, 12,
1377 10, 11, 15, 10, 15, 14, 1338 10, 11, 15, 10, 15, 14,
(...skipping 25 matching lines...) Expand all
1403 gRRectIndices, kIndicesPerStrokeRRect, kNumRRectsInIndexBuffer, kVer tsPerRRect, 1364 gRRectIndices, kIndicesPerStrokeRRect, kNumRRectsInIndexBuffer, kVer tsPerRRect,
1404 gStrokeRRectOnlyIndexBufferKey); 1365 gStrokeRRectOnlyIndexBufferKey);
1405 } else { 1366 } else {
1406 return resourceProvider->findOrCreateInstancedIndexBuffer( 1367 return resourceProvider->findOrCreateInstancedIndexBuffer(
1407 gRRectIndices, kIndicesPerRRect, kNumRRectsInIndexBuffer, kVertsPerR Rect, 1368 gRRectIndices, kIndicesPerRRect, kNumRRectsInIndexBuffer, kVertsPerR Rect,
1408 gRRectOnlyIndexBufferKey); 1369 gRRectOnlyIndexBufferKey);
1409 1370
1410 } 1371 }
1411 } 1372 }
1412 1373
1413 bool GrOvalRenderer::DrawDRRect(GrDrawTarget* target,
1414 const GrPipelineBuilder& pipelineBuilder,
1415 GrColor color,
1416 const SkMatrix& viewMatrix,
1417 bool useAA,
1418 const SkRRect& origOuter,
1419 const SkRRect& origInner) {
1420 bool applyAA = useAA && !pipelineBuilder.getRenderTarget()->isUnifiedMultisa mpled();
1421 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps;
1422 if (!origInner.isEmpty()) {
1423 SkTCopyOnFirstWrite<SkRRect> inner(origInner);
1424 if (!viewMatrix.isIdentity()) {
1425 if (!origInner.transform(viewMatrix, inner.writable())) {
1426 return false;
1427 }
1428 }
1429 GrPrimitiveEdgeType edgeType = applyAA ?
1430 kInverseFillAA_GrProcessorEdgeType :
1431 kInverseFillBW_GrProcessorEdgeType;
1432 // TODO this needs to be a geometry processor
1433 GrFragmentProcessor* fp = GrRRectEffect::Create(edgeType, *inner);
1434 if (nullptr == fp) {
1435 return false;
1436 }
1437 arfps.set(&pipelineBuilder);
1438 arfps.addCoverageFragmentProcessor(fp)->unref();
1439 }
1440
1441 SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle);
1442 if (DrawRRect(target, pipelineBuilder, color, viewMatrix, useAA, origOuter, fillRec)) {
1443 return true;
1444 }
1445
1446 SkASSERT(!origOuter.isEmpty());
1447 SkTCopyOnFirstWrite<SkRRect> outer(origOuter);
1448 if (!viewMatrix.isIdentity()) {
1449 if (!origOuter.transform(viewMatrix, outer.writable())) {
1450 return false;
1451 }
1452 }
1453 GrPrimitiveEdgeType edgeType = applyAA ? kFillAA_GrProcessorEdgeType :
1454 kFillBW_GrProcessorEdgeType;
1455 GrFragmentProcessor* effect = GrRRectEffect::Create(edgeType, *outer);
1456 if (nullptr == effect) {
1457 return false;
1458 }
1459 if (!arfps.isSet()) {
1460 arfps.set(&pipelineBuilder);
1461 }
1462
1463 SkMatrix invert;
1464 if (!viewMatrix.invert(&invert)) {
1465 return false;
1466 }
1467
1468 arfps.addCoverageFragmentProcessor(effect)->unref();
1469 SkRect bounds = outer->getBounds();
1470 if (applyAA) {
1471 bounds.outset(SK_ScalarHalf, SK_ScalarHalf);
1472 }
1473 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, S kMatrix::I(),
1474 bounds, nullptr, &invert));
1475 target->drawBatch(pipelineBuilder, batch);
1476 return true;
1477 }
1478
1479 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1374 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1480 1375
1481 class RRectCircleRendererBatch : public GrVertexBatch { 1376 class RRectCircleRendererBatch : public GrVertexBatch {
1482 public: 1377 public:
1483 DEFINE_BATCH_CLASS_ID 1378 DEFINE_BATCH_CLASS_ID
1484 1379
1485 struct Geometry { 1380 struct Geometry {
1486 SkMatrix fViewMatrix; 1381 SkMatrix fViewMatrix;
1487 SkRect fDevBounds; 1382 SkRect fDevBounds;
1488 SkScalar fInnerRadius; 1383 SkScalar fInnerRadius;
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 geometry.fYRadius = yRadius; 1883 geometry.fYRadius = yRadius;
1989 geometry.fInnerXRadius = innerXRadius; 1884 geometry.fInnerXRadius = innerXRadius;
1990 geometry.fInnerYRadius = innerYRadius; 1885 geometry.fInnerYRadius = innerYRadius;
1991 geometry.fStroke = isStrokeOnly; 1886 geometry.fStroke = isStrokeOnly;
1992 geometry.fDevBounds = bounds; 1887 geometry.fDevBounds = bounds;
1993 1888
1994 return RRectEllipseRendererBatch::Create(geometry); 1889 return RRectEllipseRendererBatch::Create(geometry);
1995 } 1890 }
1996 } 1891 }
1997 1892
1998 bool GrOvalRenderer::DrawRRect(GrDrawTarget* target, 1893 GrDrawBatch* GrOvalRenderer::CreateRRectBatch(const GrPipelineBuilder& pipelineB uilder,
1999 const GrPipelineBuilder& pipelineBuilder, 1894 GrColor color,
2000 GrColor color, 1895 const SkMatrix& viewMatrix,
2001 const SkMatrix& viewMatrix, 1896 bool useAA,
2002 bool useAA, 1897 const SkRRect& rrect,
2003 const SkRRect& rrect, 1898 const SkStrokeRec& stroke,
2004 const SkStrokeRec& stroke) { 1899 GrShaderCaps* shaderCaps) {
2005 if (rrect.isOval()) {
2006 return DrawOval(target, pipelineBuilder, color, viewMatrix, useAA, rrect .getBounds(),
2007 stroke);
2008 }
2009
2010 bool useCoverageAA = useAA && !pipelineBuilder.getRenderTarget()->isUnifiedM ultisampled(); 1900 bool useCoverageAA = useAA && !pipelineBuilder.getRenderTarget()->isUnifiedM ultisampled();
2011 1901
2012 // only anti-aliased rrects for now 1902 // only anti-aliased rrects for now
2013 if (!useCoverageAA) { 1903 if (!useCoverageAA) {
2014 return false; 1904 return nullptr;
1905 }
1906
1907 if (rrect.isOval()) {
1908 return CreateOvalBatch(pipelineBuilder, color, viewMatrix, useAA,
1909 rrect.getBounds(), stroke, shaderCaps);
2015 } 1910 }
2016 1911
2017 if (!viewMatrix.rectStaysRect() || !rrect.isSimple()) { 1912 if (!viewMatrix.rectStaysRect() || !rrect.isSimple()) {
2018 return false; 1913 return nullptr;
2019 } 1914 }
2020 1915
2021 SkAutoTUnref<GrDrawBatch> batch(create_rrect_batch(color, viewMatrix, rrect, stroke)); 1916 return create_rrect_batch(color, viewMatrix, rrect, stroke);
2022 if (!batch) {
2023 return false;
2024 }
2025
2026 target->drawBatch(pipelineBuilder, batch);
2027 return true;
2028 } 1917 }
2029 1918
2030 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1919 //////////////////////////////////////////////////////////////////////////////// ///////////////////
2031 1920
2032 #ifdef GR_TEST_UTILS 1921 #ifdef GR_TEST_UTILS
2033 1922
2034 DRAW_BATCH_TEST_DEFINE(CircleBatch) { 1923 DRAW_BATCH_TEST_DEFINE(CircleBatch) {
2035 SkMatrix viewMatrix = GrTest::TestMatrix(random); 1924 SkMatrix viewMatrix = GrTest::TestMatrix(random);
2036 GrColor color = GrRandomColor(random); 1925 GrColor color = GrRandomColor(random);
2037 bool useCoverageAA = random->nextBool();
2038 SkRect circle = GrTest::TestSquare(random); 1926 SkRect circle = GrTest::TestSquare(random);
2039 return create_circle_batch(color, viewMatrix, useCoverageAA, circle, 1927 return create_circle_batch(color, viewMatrix, circle, GrTest::TestStrokeRec( random));
2040 GrTest::TestStrokeRec(random));
2041 } 1928 }
2042 1929
2043 DRAW_BATCH_TEST_DEFINE(EllipseBatch) { 1930 DRAW_BATCH_TEST_DEFINE(EllipseBatch) {
2044 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 1931 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
2045 GrColor color = GrRandomColor(random); 1932 GrColor color = GrRandomColor(random);
2046 SkRect ellipse = GrTest::TestSquare(random); 1933 SkRect ellipse = GrTest::TestSquare(random);
2047 return create_ellipse_batch(color, viewMatrix, true, ellipse, 1934 return create_ellipse_batch(color, viewMatrix, ellipse, GrTest::TestStrokeRe c(random));
2048 GrTest::TestStrokeRec(random));
2049 } 1935 }
2050 1936
2051 DRAW_BATCH_TEST_DEFINE(DIEllipseBatch) { 1937 DRAW_BATCH_TEST_DEFINE(DIEllipseBatch) {
2052 SkMatrix viewMatrix = GrTest::TestMatrix(random); 1938 SkMatrix viewMatrix = GrTest::TestMatrix(random);
2053 GrColor color = GrRandomColor(random); 1939 GrColor color = GrRandomColor(random);
2054 bool useCoverageAA = random->nextBool();
2055 SkRect ellipse = GrTest::TestSquare(random); 1940 SkRect ellipse = GrTest::TestSquare(random);
2056 return create_diellipse_batch(color, viewMatrix, useCoverageAA, ellipse, 1941 return create_diellipse_batch(color, viewMatrix, ellipse, GrTest::TestStroke Rec(random));
2057 GrTest::TestStrokeRec(random));
2058 } 1942 }
2059 1943
2060 DRAW_BATCH_TEST_DEFINE(RRectBatch) { 1944 DRAW_BATCH_TEST_DEFINE(RRectBatch) {
2061 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 1945 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
2062 GrColor color = GrRandomColor(random); 1946 GrColor color = GrRandomColor(random);
2063 const SkRRect& rrect = GrTest::TestRRectSimple(random); 1947 const SkRRect& rrect = GrTest::TestRRectSimple(random);
2064 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); 1948 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom));
2065 } 1949 }
2066 1950
2067 #endif 1951 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrOvalRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698