Do circular clipping in normalized space
BUG=skia:426217 Review URL: https://codereview.chromium.org/1110173002
This commit is contained in:
parent
00ed9a909c
commit
fcabe429a4
@ -49,6 +49,20 @@ protected:
|
||||
|
||||
SkPaint fillPaint;
|
||||
|
||||
// Giant background circular clips (AA, non-inverted, replace/isect)
|
||||
fillPaint.setColor(0x80808080);
|
||||
canvas->save();
|
||||
canvas->scale(10, 10);
|
||||
canvas->translate(-((fX1 + fX2)/2 - fR), -(fY - 2*fR/3));
|
||||
canvas->clipPath(fCircle1, SkRegion::kReplace_Op, true);
|
||||
canvas->clipPath(fCircle2, SkRegion::kIntersect_Op, true);
|
||||
|
||||
canvas->drawRect(rect, fillPaint);
|
||||
|
||||
canvas->restore();
|
||||
|
||||
fillPaint.setColor(0xFF000000);
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
fCircle1.toggleInverseFillType();
|
||||
if (i % 2 == 0) {
|
||||
|
@ -128,10 +128,10 @@ void GLCircleEffect::emitCode(GrGLFPBuilder* builder,
|
||||
const TextureSamplerArray& samplers) {
|
||||
const CircleEffect& ce = fp.cast<CircleEffect>();
|
||||
const char *circleName;
|
||||
// The circle uniform is (center.x, center.y, radius + 0.5) for regular fills and
|
||||
// (... ,radius - 0.5) for inverse fills.
|
||||
// The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0.5)) for regular
|
||||
// fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills.
|
||||
fCircleUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
|
||||
kVec3f_GrSLType, kDefault_GrSLPrecision,
|
||||
kVec4f_GrSLType, kDefault_GrSLPrecision,
|
||||
"circle",
|
||||
&circleName);
|
||||
|
||||
@ -139,12 +139,16 @@ void GLCircleEffect::emitCode(GrGLFPBuilder* builder,
|
||||
const char* fragmentPos = fsBuilder->fragmentPosition();
|
||||
|
||||
SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType());
|
||||
// TODO: Right now the distance to circle caclulation is performed in a space normalized to the
|
||||
// radius and then denormalized. This is to prevent overflow on devices that have a "real"
|
||||
// mediump. It'd be nice to only to this on mediump devices but we currently don't have the
|
||||
// caps here.
|
||||
if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) {
|
||||
fsBuilder->codeAppendf("\t\tfloat d = length(%s.xy - %s.xy) - %s.z;\n",
|
||||
circleName, fragmentPos, circleName);
|
||||
fsBuilder->codeAppendf("\t\tfloat d = (length((%s.xy - %s.xy) * %s.w) - 1.0) * %s.z;\n",
|
||||
circleName, fragmentPos, circleName, circleName);
|
||||
} else {
|
||||
fsBuilder->codeAppendf("\t\tfloat d = %s.z - length(%s.xy - %s.xy);\n",
|
||||
circleName, fragmentPos, circleName);
|
||||
fsBuilder->codeAppendf("\t\tfloat d = (1.0 - length((%s.xy - %s.xy) * %s.w)) * %s.z;\n",
|
||||
circleName, fragmentPos, circleName, circleName);
|
||||
}
|
||||
if (GrProcessorEdgeTypeIsAA(ce.getEdgeType())) {
|
||||
fsBuilder->codeAppend("\t\td = clamp(d, 0.0, 1.0);\n");
|
||||
@ -171,7 +175,8 @@ void GLCircleEffect::setData(const GrGLProgramDataManager& pdman, const GrProces
|
||||
} else {
|
||||
radius += 0.5f;
|
||||
}
|
||||
pdman.set3f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius);
|
||||
pdman.set4f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius,
|
||||
SkScalarInvert(radius));
|
||||
fPrevCenter = ce.getCenter();
|
||||
fPrevRadius = ce.getRadius();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user