Wide color support in the AA linearizing convex path renderer
Bug: skia: Change-Id: I6df042eb79af56b763cda1c58130dc40f6f4bbea Reviewed-on: https://skia-review.googlesource.com/c/179993 Reviewed-by: Chris Dalton <csmartdalton@google.com> Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
7561dba7c1
commit
4948e5578a
@ -83,20 +83,20 @@ GrAALinearizingConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) co
|
|||||||
static void extract_verts(const GrAAConvexTessellator& tess,
|
static void extract_verts(const GrAAConvexTessellator& tess,
|
||||||
void* vertData,
|
void* vertData,
|
||||||
size_t vertexStride,
|
size_t vertexStride,
|
||||||
GrColor color,
|
const SkPMColor4f& origColor,
|
||||||
|
bool wideColor,
|
||||||
uint16_t firstIndex,
|
uint16_t firstIndex,
|
||||||
uint16_t* idxs,
|
uint16_t* idxs,
|
||||||
bool tweakAlphaForCoverage) {
|
bool tweakAlphaForCoverage) {
|
||||||
GrVertexWriter verts{vertData};
|
GrVertexWriter verts{vertData};
|
||||||
for (int i = 0; i < tess.numPts(); ++i) {
|
|
||||||
verts.write(tess.point(i));
|
|
||||||
if (tweakAlphaForCoverage) {
|
if (tweakAlphaForCoverage) {
|
||||||
SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255);
|
for (int i = 0; i < tess.numPts(); ++i) {
|
||||||
unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i));
|
verts.write(tess.point(i), GrVertexColor(origColor * tess.coverage(i), wideColor));
|
||||||
GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
|
}
|
||||||
verts.write(scaledColor);
|
|
||||||
} else {
|
} else {
|
||||||
verts.write(color, tess.coverage(i));
|
GrVertexColor color(origColor, wideColor);
|
||||||
|
for (int i = 0; i < tess.numPts(); ++i) {
|
||||||
|
verts.write(tess.point(i), color, tess.coverage(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,22 +108,18 @@ static void extract_verts(const GrAAConvexTessellator& tess,
|
|||||||
static sk_sp<GrGeometryProcessor> create_lines_only_gp(const GrShaderCaps* shaderCaps,
|
static sk_sp<GrGeometryProcessor> create_lines_only_gp(const GrShaderCaps* shaderCaps,
|
||||||
bool tweakAlphaForCoverage,
|
bool tweakAlphaForCoverage,
|
||||||
const SkMatrix& viewMatrix,
|
const SkMatrix& viewMatrix,
|
||||||
bool usesLocalCoords) {
|
bool usesLocalCoords,
|
||||||
|
bool wideColor) {
|
||||||
using namespace GrDefaultGeoProcFactory;
|
using namespace GrDefaultGeoProcFactory;
|
||||||
|
|
||||||
Coverage::Type coverageType;
|
Coverage::Type coverageType =
|
||||||
if (tweakAlphaForCoverage) {
|
tweakAlphaForCoverage ? Coverage::kSolid_Type : Coverage::kAttribute_Type;
|
||||||
coverageType = Coverage::kSolid_Type;
|
|
||||||
} else {
|
|
||||||
coverageType = Coverage::kAttribute_Type;
|
|
||||||
}
|
|
||||||
LocalCoords::Type localCoordsType =
|
LocalCoords::Type localCoordsType =
|
||||||
usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
|
usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
|
||||||
return MakeForDeviceSpace(shaderCaps,
|
Color::Type colorType =
|
||||||
Color::kPremulGrColorAttribute_Type,
|
wideColor ? Color::kPremulWideColorAttribute_Type : Color::kPremulGrColorAttribute_Type;
|
||||||
coverageType,
|
|
||||||
localCoordsType,
|
return MakeForDeviceSpace(shaderCaps, colorType, coverageType, localCoordsType, viewMatrix);
|
||||||
viewMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -174,6 +170,7 @@ public:
|
|||||||
bounds.outset(w, w);
|
bounds.outset(w, w);
|
||||||
}
|
}
|
||||||
this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsZeroArea::kNo);
|
this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsZeroArea::kNo);
|
||||||
|
fWideColor = !SkPMColor4fFitsInBytes(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* name() const override { return "AAFlatteningConvexPathOp"; }
|
const char* name() const override { return "AAFlatteningConvexPathOp"; }
|
||||||
@ -243,7 +240,8 @@ private:
|
|||||||
sk_sp<GrGeometryProcessor> gp(create_lines_only_gp(target->caps().shaderCaps(),
|
sk_sp<GrGeometryProcessor> gp(create_lines_only_gp(target->caps().shaderCaps(),
|
||||||
fHelper.compatibleWithAlphaAsCoverage(),
|
fHelper.compatibleWithAlphaAsCoverage(),
|
||||||
this->viewMatrix(),
|
this->viewMatrix(),
|
||||||
fHelper.usesLocalCoords()));
|
fHelper.usesLocalCoords(),
|
||||||
|
fWideColor));
|
||||||
if (!gp) {
|
if (!gp) {
|
||||||
SkDebugf("Couldn't create a GrGeometryProcessor\n");
|
SkDebugf("Couldn't create a GrGeometryProcessor\n");
|
||||||
return;
|
return;
|
||||||
@ -296,9 +294,8 @@ private:
|
|||||||
indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
|
indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO4F: Preserve float colors
|
|
||||||
extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride,
|
extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride,
|
||||||
args.fColor.toBytes_RGBA(), vertexCount, indices + indexCount,
|
args.fColor, fWideColor, vertexCount, indices + indexCount,
|
||||||
fHelper.compatibleWithAlphaAsCoverage());
|
fHelper.compatibleWithAlphaAsCoverage());
|
||||||
vertexCount += currentVertices;
|
vertexCount += currentVertices;
|
||||||
indexCount += currentIndices;
|
indexCount += currentIndices;
|
||||||
@ -318,6 +315,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
|
fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
|
||||||
|
fWideColor |= that->fWideColor;
|
||||||
return CombineResult::kMerged;
|
return CombineResult::kMerged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,6 +333,7 @@ private:
|
|||||||
|
|
||||||
SkSTArray<1, PathData, true> fPaths;
|
SkSTArray<1, PathData, true> fPaths;
|
||||||
Helper fHelper;
|
Helper fHelper;
|
||||||
|
bool fWideColor;
|
||||||
|
|
||||||
typedef GrMeshDrawOp INHERITED;
|
typedef GrMeshDrawOp INHERITED;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user