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

Unified Diff: src/gpu/GrAARectRenderer.cpp

Issue 794843002: Revert of Remove GP from drawstate, revision of invariant output for GP (Closed) Base URL: https://skia.googlesource.com/skia.git@color-to-gp
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrBitmapTextContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAARectRenderer.cpp
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp
index 23757ce8c536d552dec40a121f8e0890d78c2c98..0cf757502e45e326bee841db0a898b88900e9871 100644
--- a/src/gpu/GrAARectRenderer.cpp
+++ b/src/gpu/GrAARectRenderer.cpp
@@ -25,21 +25,20 @@
};
}
-static const GrGeometryProcessor* create_rect_gp(const GrDrawState& drawState, GrColor color,
- CoverageAttribType* type) {
+static CoverageAttribType set_rect_attribs(GrDrawState* drawState, GrColor color) {
uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType;
- const GrGeometryProcessor* gp;
- if (drawState.canTweakAlphaForCoverage()) {
- gp = GrDefaultGeoProcFactory::Create(color, flags);
- SkASSERT(gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionColorAttr));
- *type = kUseColor_CoverageAttribType;
+ if (drawState->canTweakAlphaForCoverage()) {
+ drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color, flags))->unref();
+ SkASSERT(drawState->getGeometryProcessor()->getVertexStride() ==
+ sizeof(GrDefaultGeoProcFactory::PositionColorAttr));
+ return kUseColor_CoverageAttribType;
} else {
flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
- gp = GrDefaultGeoProcFactory::Create(color, flags);
- SkASSERT(gp->getVertexStride()==sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
- *type = kUseCoverage_CoverageAttribType;
- }
- return gp;
+ drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color, flags))->unref();
+ SkASSERT(drawState->getGeometryProcessor()->getVertexStride() ==
+ sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
+ return kUseCoverage_CoverageAttribType;
+ }
}
static void set_inset_fan(SkPoint* pts, size_t stride,
@@ -183,14 +182,13 @@
const SkRect& devRect) {
GrDrawState::AutoRestoreEffects are(drawState);
- CoverageAttribType type;
- SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(*drawState, color, &type));
- if (kUseCoverage_CoverageAttribType == type && GrColorIsOpaque(color)) {
+ CoverageAttribType covAttribType = set_rect_attribs(drawState, color);
+ if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(color)) {
drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
}
- size_t vertexStride = gp->getVertexStride();
- GrDrawTarget::AutoReleaseGeometry geo(target, 8, vertexStride, 0);
+ size_t vstride = drawState->getGeometryProcessor()->getVertexStride();
+ GrDrawTarget::AutoReleaseGeometry geo(target, 8, vstride, 0);
if (!geo.succeeded()) {
SkDebugf("Failed to get space for vertices!\n");
return;
@@ -211,7 +209,7 @@
intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts);
- SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vertexStride);
+ SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vstride);
SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1);
inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height());
@@ -225,8 +223,8 @@
combinedMatrix.mapRect(&devRect, rect);
#endif
- set_inset_fan(fan0Pos, vertexStride, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
- set_inset_fan(fan1Pos, vertexStride, devRect, inset, inset);
+ set_inset_fan(fan0Pos, vstride, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
+ set_inset_fan(fan1Pos, vstride, devRect, inset, inset);
} else {
// compute transformed (1, 0) and (0, 1) vectors
SkVector vec[2] = {
@@ -241,38 +239,38 @@
// create the rotated rect
fan0Pos->setRectFan(rect.fLeft, rect.fTop,
- rect.fRight, rect.fBottom, vertexStride);
- combinedMatrix.mapPointsWithStride(fan0Pos, vertexStride, 4);
+ rect.fRight, rect.fBottom, vstride);
+ combinedMatrix.mapPointsWithStride(fan0Pos, vstride, 4);
// Now create the inset points and then outset the original
// rotated points
// TL
- *((SkPoint*)((intptr_t)fan1Pos + 0 * vertexStride)) =
- *((SkPoint*)((intptr_t)fan0Pos + 0 * vertexStride)) + vec[0] + vec[1];
- *((SkPoint*)((intptr_t)fan0Pos + 0 * vertexStride)) -= vec[0] + vec[1];
+ *((SkPoint*)((intptr_t)fan1Pos + 0 * vstride)) =
+ *((SkPoint*)((intptr_t)fan0Pos + 0 * vstride)) + vec[0] + vec[1];
+ *((SkPoint*)((intptr_t)fan0Pos + 0 * vstride)) -= vec[0] + vec[1];
// BL
- *((SkPoint*)((intptr_t)fan1Pos + 1 * vertexStride)) =
- *((SkPoint*)((intptr_t)fan0Pos + 1 * vertexStride)) + vec[0] - vec[1];
- *((SkPoint*)((intptr_t)fan0Pos + 1 * vertexStride)) -= vec[0] - vec[1];
+ *((SkPoint*)((intptr_t)fan1Pos + 1 * vstride)) =
+ *((SkPoint*)((intptr_t)fan0Pos + 1 * vstride)) + vec[0] - vec[1];
+ *((SkPoint*)((intptr_t)fan0Pos + 1 * vstride)) -= vec[0] - vec[1];
// BR
- *((SkPoint*)((intptr_t)fan1Pos + 2 * vertexStride)) =
- *((SkPoint*)((intptr_t)fan0Pos + 2 * vertexStride)) - vec[0] - vec[1];
- *((SkPoint*)((intptr_t)fan0Pos + 2 * vertexStride)) += vec[0] + vec[1];
+ *((SkPoint*)((intptr_t)fan1Pos + 2 * vstride)) =
+ *((SkPoint*)((intptr_t)fan0Pos + 2 * vstride)) - vec[0] - vec[1];
+ *((SkPoint*)((intptr_t)fan0Pos + 2 * vstride)) += vec[0] + vec[1];
// TR
- *((SkPoint*)((intptr_t)fan1Pos + 3 * vertexStride)) =
- *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) - vec[0] + vec[1];
- *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) += vec[0] - vec[1];
+ *((SkPoint*)((intptr_t)fan1Pos + 3 * vstride)) =
+ *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) - vec[0] + vec[1];
+ *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) += vec[0] - vec[1];
}
// Make verts point to vertex color and then set all the color and coverage vertex attrs values.
verts += sizeof(SkPoint);
for (int i = 0; i < 4; ++i) {
- if (kUseCoverage_CoverageAttribType == type) {
- *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
- *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = 0;
+ if (kUseCoverage_CoverageAttribType == covAttribType) {
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = color;
+ *reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = 0;
} else {
- *reinterpret_cast<GrColor*>(verts + i * vertexStride) = 0;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = 0;
}
}
@@ -284,23 +282,22 @@
scale = 0xff;
}
- verts += 4 * vertexStride;
+ verts += 4 * vstride;
float innerCoverage = GrNormalizeByteToFloat(scale);
GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
for (int i = 0; i < 4; ++i) {
- if (kUseCoverage_CoverageAttribType == type) {
- *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
- *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = innerCoverage;
+ if (kUseCoverage_CoverageAttribType == covAttribType) {
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = color;
+ *reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = innerCoverage;
} else {
- *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
+ *reinterpret_cast<GrColor*>(verts + i * vstride) = scaledColor;
}
}
target->setIndexSourceToBuffer(indexBuffer);
target->drawIndexedInstances(drawState,
- gp,
kTriangles_GrPrimitiveType,
1,
kVertsPerAAFillRect,
@@ -386,11 +383,9 @@
const SkRect& devInside,
bool miterStroke) {
GrDrawState::AutoRestoreEffects are(drawState);
-
- CoverageAttribType type;
- SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(*drawState, color, &type));
-
- if (kUseCoverage_CoverageAttribType == type && GrColorIsOpaque(color)) {
+ CoverageAttribType covAttribType = set_rect_attribs(drawState, color);
+
+ if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(color)) {
drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
}
@@ -398,7 +393,7 @@
int outerVertexNum = miterStroke ? 4 : 8;
int totalVertexNum = (outerVertexNum + innerVertexNum) * 2;
- size_t vstride = gp->getVertexStride();
+ size_t vstride = drawState->getGeometryProcessor()->getVertexStride();
GrDrawTarget::AutoReleaseGeometry geo(target, totalVertexNum, vstride, 0);
if (!geo.succeeded()) {
SkDebugf("Failed to get space for vertices!\n");
@@ -463,7 +458,7 @@
// The outermost rect has 0 coverage
verts += sizeof(SkPoint);
for (int i = 0; i < outerVertexNum; ++i) {
- if (kUseCoverage_CoverageAttribType == type) {
+ if (kUseCoverage_CoverageAttribType == covAttribType) {
*reinterpret_cast<GrColor*>(verts + i * vstride) = color;
*reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = 0;
} else {
@@ -485,7 +480,7 @@
verts += outerVertexNum * vstride;
for (int i = 0; i < outerVertexNum + innerVertexNum; ++i) {
- if (kUseCoverage_CoverageAttribType == type) {
+ if (kUseCoverage_CoverageAttribType == covAttribType) {
*reinterpret_cast<GrColor*>(verts + i * vstride) = color;
*reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = innerCoverage;
} else {
@@ -496,7 +491,7 @@
// The innermost rect has 0 coverage
verts += (outerVertexNum + innerVertexNum) * vstride;
for (int i = 0; i < innerVertexNum; ++i) {
- if (kUseCoverage_CoverageAttribType == type) {
+ if (kUseCoverage_CoverageAttribType == covAttribType) {
*reinterpret_cast<GrColor*>(verts + i * vstride) = color;
*reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = 0;
} else {
@@ -506,7 +501,6 @@
target->setIndexSourceToBuffer(indexBuffer);
target->drawIndexedInstances(drawState,
- gp,
kTriangles_GrPrimitiveType,
1,
totalVertexNum,
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrBitmapTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698