Remove isIRect "optimization" & defer computation of device Rect in AA rect rendering
https://chromiumcodereview.appspot.com/14890021/ git-svn-id: http://skia.googlecode.com/svn/trunk@9087 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
0f20a3fc59
commit
18136d1cf2
@ -42,7 +42,6 @@ public:
|
|||||||
GrDrawTarget* target,
|
GrDrawTarget* target,
|
||||||
const GrRect& rect,
|
const GrRect& rect,
|
||||||
const SkMatrix& combinedMatrix,
|
const SkMatrix& combinedMatrix,
|
||||||
const GrRect& devRect,
|
|
||||||
bool useVertexCoverage) {
|
bool useVertexCoverage) {
|
||||||
#ifdef SHADER_AA_FILL_RECT
|
#ifdef SHADER_AA_FILL_RECT
|
||||||
if (combinedMatrix.rectStaysRect()) {
|
if (combinedMatrix.rectStaysRect()) {
|
||||||
@ -55,13 +54,14 @@ public:
|
|||||||
#else
|
#else
|
||||||
this->geometryFillAARect(gpu, target,
|
this->geometryFillAARect(gpu, target,
|
||||||
rect, combinedMatrix,
|
rect, combinedMatrix,
|
||||||
devRect, useVertexCoverage);
|
useVertexCoverage);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void strokeAARect(GrGpu* gpu,
|
void strokeAARect(GrGpu* gpu,
|
||||||
GrDrawTarget* target,
|
GrDrawTarget* target,
|
||||||
const GrRect& devRect,
|
const GrRect& rect,
|
||||||
|
const SkMatrix& combinedMatrix,
|
||||||
const GrVec& devStrokeSize,
|
const GrVec& devStrokeSize,
|
||||||
bool useVertexCoverage);
|
bool useVertexCoverage);
|
||||||
|
|
||||||
@ -80,7 +80,6 @@ private:
|
|||||||
GrDrawTarget* target,
|
GrDrawTarget* target,
|
||||||
const GrRect& rect,
|
const GrRect& rect,
|
||||||
const SkMatrix& combinedMatrix,
|
const SkMatrix& combinedMatrix,
|
||||||
const GrRect& devRect,
|
|
||||||
bool useVertexCoverage);
|
bool useVertexCoverage);
|
||||||
|
|
||||||
void shaderFillAARect(GrGpu* gpu,
|
void shaderFillAARect(GrGpu* gpu,
|
||||||
|
@ -364,7 +364,6 @@ void GrAARectRenderer::geometryFillAARect(GrGpu* gpu,
|
|||||||
GrDrawTarget* target,
|
GrDrawTarget* target,
|
||||||
const GrRect& rect,
|
const GrRect& rect,
|
||||||
const SkMatrix& combinedMatrix,
|
const SkMatrix& combinedMatrix,
|
||||||
const GrRect& devRect,
|
|
||||||
bool useVertexCoverage) {
|
bool useVertexCoverage) {
|
||||||
GrDrawState* drawState = target->drawState();
|
GrDrawState* drawState = target->drawState();
|
||||||
|
|
||||||
@ -389,6 +388,9 @@ void GrAARectRenderer::geometryFillAARect(GrGpu* gpu,
|
|||||||
GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
|
GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
|
||||||
GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
|
GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
|
||||||
|
|
||||||
|
SkRect devRect;
|
||||||
|
combinedMatrix.mapRect(&devRect, rect);
|
||||||
|
|
||||||
if (combinedMatrix.rectStaysRect()) {
|
if (combinedMatrix.rectStaysRect()) {
|
||||||
set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
|
set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
|
||||||
set_inset_fan(fan1Pos, vsize, devRect, SK_ScalarHalf, SK_ScalarHalf);
|
set_inset_fan(fan1Pos, vsize, devRect, SK_ScalarHalf, SK_ScalarHalf);
|
||||||
@ -616,16 +618,20 @@ void GrAARectRenderer::shaderFillAlignedAARect(GrGpu* gpu,
|
|||||||
|
|
||||||
void GrAARectRenderer::strokeAARect(GrGpu* gpu,
|
void GrAARectRenderer::strokeAARect(GrGpu* gpu,
|
||||||
GrDrawTarget* target,
|
GrDrawTarget* target,
|
||||||
const GrRect& devRect,
|
const GrRect& rect,
|
||||||
|
const SkMatrix& combinedMatrix,
|
||||||
const GrVec& devStrokeSize,
|
const GrVec& devStrokeSize,
|
||||||
bool useVertexCoverage) {
|
bool useVertexCoverage) {
|
||||||
GrDrawState* drawState = target->drawState();
|
GrDrawState* drawState = target->drawState();
|
||||||
|
|
||||||
const SkScalar& dx = devStrokeSize.fX;
|
const SkScalar dx = devStrokeSize.fX;
|
||||||
const SkScalar& dy = devStrokeSize.fY;
|
const SkScalar dy = devStrokeSize.fY;
|
||||||
const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf);
|
const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf);
|
||||||
const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf);
|
const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf);
|
||||||
|
|
||||||
|
SkRect devRect;
|
||||||
|
combinedMatrix.mapRect(&devRect, rect);
|
||||||
|
|
||||||
SkScalar spare;
|
SkScalar spare;
|
||||||
{
|
{
|
||||||
SkScalar w = devRect.width() - dx;
|
SkScalar w = devRect.width() - dx;
|
||||||
@ -634,9 +640,8 @@ void GrAARectRenderer::strokeAARect(GrGpu* gpu,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (spare <= 0) {
|
if (spare <= 0) {
|
||||||
GrRect r(devRect);
|
devRect.inset(-rx, -ry);
|
||||||
r.inset(-rx, -ry);
|
this->fillAARect(gpu, target, devRect, SkMatrix::I(), useVertexCoverage);
|
||||||
this->fillAARect(gpu, target, r, SkMatrix::I(), r, useVertexCoverage);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,6 @@ bool GrClipMaskManager::drawElement(GrTexture* target,
|
|||||||
fGpu,
|
fGpu,
|
||||||
element->getRect(),
|
element->getRect(),
|
||||||
SkMatrix::I(),
|
SkMatrix::I(),
|
||||||
element->getRect(),
|
|
||||||
false);
|
false);
|
||||||
} else {
|
} else {
|
||||||
fGpu->drawSimpleRect(element->getRect(), NULL);
|
fGpu->drawSimpleRect(element->getRect(), NULL);
|
||||||
|
@ -680,20 +680,10 @@ static void setStrokeRectStrip(GrPoint verts[10], GrRect rect,
|
|||||||
verts[9] = verts[1];
|
verts[9] = verts[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the rects edges are integer-aligned.
|
|
||||||
*/
|
|
||||||
static bool isIRect(const GrRect& r) {
|
|
||||||
return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) &&
|
|
||||||
SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool apply_aa_to_rect(GrDrawTarget* target,
|
static bool apply_aa_to_rect(GrDrawTarget* target,
|
||||||
const GrRect& rect,
|
|
||||||
SkScalar strokeWidth,
|
SkScalar strokeWidth,
|
||||||
const SkMatrix* matrix,
|
const SkMatrix* matrix,
|
||||||
SkMatrix* combinedMatrix,
|
SkMatrix* combinedMatrix,
|
||||||
GrRect* devRect,
|
|
||||||
bool* useVertexCoverage) {
|
bool* useVertexCoverage) {
|
||||||
// we use a simple coverage ramp to do aa on axis-aligned rects
|
// we use a simple coverage ramp to do aa on axis-aligned rects
|
||||||
// we check if the rect will be axis-aligned, and the rect won't land on
|
// we check if the rect will be axis-aligned, and the rect won't land on
|
||||||
@ -763,17 +753,7 @@ static bool apply_aa_to_rect(GrDrawTarget* target,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
combinedMatrix->mapRect(devRect, rect);
|
return true;
|
||||||
|
|
||||||
if (strokeWidth < 0
|
|
||||||
#if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
|
|
||||||
&& drawState.getViewMatrix().preservesAxisAlignment()
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
return !isIRect(*devRect);
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrContext::drawRect(const GrPaint& paint,
|
void GrContext::drawRect(const GrPaint& paint,
|
||||||
@ -785,13 +765,12 @@ void GrContext::drawRect(const GrPaint& paint,
|
|||||||
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
|
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
|
||||||
GrDrawState::AutoStageDisable atr(fDrawState);
|
GrDrawState::AutoStageDisable atr(fDrawState);
|
||||||
|
|
||||||
GrRect devRect;
|
|
||||||
SkMatrix combinedMatrix;
|
SkMatrix combinedMatrix;
|
||||||
bool useVertexCoverage;
|
bool useVertexCoverage;
|
||||||
bool needAA = paint.isAntiAlias() &&
|
bool needAA = paint.isAntiAlias() &&
|
||||||
!this->getRenderTarget()->isMultisampled();
|
!this->getRenderTarget()->isMultisampled();
|
||||||
bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix,
|
bool doAA = needAA && apply_aa_to_rect(target, width, matrix,
|
||||||
&combinedMatrix, &devRect,
|
&combinedMatrix,
|
||||||
&useVertexCoverage);
|
&useVertexCoverage);
|
||||||
if (doAA) {
|
if (doAA) {
|
||||||
GrDrawState::AutoDeviceCoordDraw adcd(target->drawState());
|
GrDrawState::AutoDeviceCoordDraw adcd(target->drawState());
|
||||||
@ -807,12 +786,13 @@ void GrContext::drawRect(const GrPaint& paint,
|
|||||||
} else {
|
} else {
|
||||||
strokeSize.set(SK_Scalar1, SK_Scalar1);
|
strokeSize.set(SK_Scalar1, SK_Scalar1);
|
||||||
}
|
}
|
||||||
fAARectRenderer->strokeAARect(this->getGpu(), target, devRect,
|
fAARectRenderer->strokeAARect(this->getGpu(), target,
|
||||||
|
rect, combinedMatrix,
|
||||||
strokeSize, useVertexCoverage);
|
strokeSize, useVertexCoverage);
|
||||||
} else {
|
} else {
|
||||||
// filled AA rect
|
// filled AA rect
|
||||||
fAARectRenderer->fillAARect(this->getGpu(), target,
|
fAARectRenderer->fillAARect(this->getGpu(), target,
|
||||||
rect, combinedMatrix, devRect,
|
rect, combinedMatrix,
|
||||||
useVertexCoverage);
|
useVertexCoverage);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user