Pass bounds into draw calls in path renderers.

R=jvanverth@google.com, robertphillips@google.com

Review URL: https://codereview.chromium.org/14882011

git-svn-id: http://skia.googlecode.com/svn/trunk@9171 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2013-05-16 19:58:46 +00:00
parent 719a3733ae
commit f438c97258
5 changed files with 48 additions and 12 deletions

View File

@ -660,6 +660,9 @@ bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
SkSTArray<kPreallocDrawCnt, Draw, true> draws; SkSTArray<kPreallocDrawCnt, Draw, true> draws;
create_vertices(segments, fanPt, &draws, verts, idxs); create_vertices(segments, fanPt, &draws, verts, idxs);
SkRect devBounds;
GetPathDevBounds(origPath, drawState->getRenderTarget(), adcd.getOriginalMatrix(), &devBounds);
int vOffset = 0; int vOffset = 0;
for (int i = 0; i < draws.count(); ++i) { for (int i = 0; i < draws.count(); ++i) {
const Draw& draw = draws[i]; const Draw& draw = draws[i];
@ -667,7 +670,8 @@ bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
vOffset, // start vertex vOffset, // start vertex
0, // start index 0, // start index
draw.fVertexCnt, draw.fVertexCnt,
draw.fIndexCnt); draw.fIndexCnt,
&devBounds);
vOffset += draw.fVertexCnt; vOffset += draw.fVertexCnt;
} }

View File

@ -816,6 +816,9 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
GrEffectRef* hairLineEffect = HairLineEdgeEffect::Create(); GrEffectRef* hairLineEffect = HairLineEdgeEffect::Create();
GrEffectRef* hairQuadEffect = HairQuadEdgeEffect::Create(); GrEffectRef* hairQuadEffect = HairQuadEdgeEffect::Create();
SkRect devBounds;
GetPathDevBounds(path, drawState->getRenderTarget(), adcd.getOriginalMatrix(), &devBounds);
target->setIndexSourceToBuffer(fLinesIndexBuffer); target->setIndexSourceToBuffer(fLinesIndexBuffer);
int lines = 0; int lines = 0;
int nBufLines = fLinesIndexBuffer->maxQuads(); int nBufLines = fLinesIndexBuffer->maxQuads();
@ -826,7 +829,8 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
kVertsPerLineSeg*lines, // startV kVertsPerLineSeg*lines, // startV
0, // startI 0, // startI
kVertsPerLineSeg*n, // vCount kVertsPerLineSeg*n, // vCount
kIdxsPerLineSeg*n); // iCount kIdxsPerLineSeg*n,
&devBounds); // iCount
lines += n; lines += n;
} }
@ -839,7 +843,8 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
4 * lineCnt + kVertsPerQuad*quads, // startV 4 * lineCnt + kVertsPerQuad*quads, // startV
0, // startI 0, // startI
kVertsPerQuad*n, // vCount kVertsPerQuad*n, // vCount
kIdxsPerQuad*n); // iCount kIdxsPerQuad*n, // iCount
&devBounds);
quads += n; quads += n;
} }
target->resetIndexSource(); target->resetIndexSource();

View File

@ -445,7 +445,9 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
} }
} }
{ SkRect devBounds;
GetPathDevBounds(path, drawState->getRenderTarget(), viewM, &devBounds);
for (int p = 0; p < passCount; ++p) { for (int p = 0; p < passCount; ++p) {
drawState->setDrawFace(drawFace[p]); drawState->setDrawFace(drawFace[p]);
if (NULL != passes[p]) { if (NULL != passes[p]) {
@ -460,10 +462,8 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
GrDrawState::AutoDeviceCoordDraw adcd; GrDrawState::AutoDeviceCoordDraw adcd;
if (reverse) { if (reverse) {
GrAssert(NULL != drawState->getRenderTarget()); GrAssert(NULL != drawState->getRenderTarget());
// draw over the whole world. // draw over the dev bounds (which will be the whole dst surface for inv fill).
bounds.setLTRB(0, 0, bounds = devBounds;
SkIntToScalar(drawState->getRenderTarget()->width()),
SkIntToScalar(drawState->getRenderTarget()->height()));
SkMatrix vmi; SkMatrix vmi;
// mapRect through persp matrix may not be correct // mapRect through persp matrix may not be correct
if (!drawState->getViewMatrix().hasPerspective() && if (!drawState->getViewMatrix().hasPerspective() &&
@ -483,13 +483,12 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
} }
if (indexCnt) { if (indexCnt) {
target->drawIndexed(primType, 0, 0, target->drawIndexed(primType, 0, 0,
vertexCnt, indexCnt); vertexCnt, indexCnt, &devBounds);
} else { } else {
target->drawNonIndexed(primType, 0, vertexCnt); target->drawNonIndexed(primType, 0, vertexCnt, &devBounds);
} }
} }
} }
}
return true; return true;
} }

View File

@ -12,3 +12,15 @@ SK_DEFINE_INST_COUNT(GrPathRenderer)
GrPathRenderer::GrPathRenderer() { GrPathRenderer::GrPathRenderer() {
} }
void GrPathRenderer::GetPathDevBounds(const SkPath& path,
int devW, int devH,
const SkMatrix& matrix,
SkRect* bounds) {
if (path.isInverseFillType()) {
*bounds = SkRect::MakeWH(SkIntToScalar(devW), SkIntToScalar(devH));
return;
}
*bounds = path.getBounds();
matrix.mapRect(bounds);
}

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2011 Google Inc. * Copyright 2011 Google Inc.
* *
@ -173,6 +173,22 @@ protected:
this->drawPath(path, stroke, target, false); this->drawPath(path, stroke, target, false);
} }
// Helper for getting the device bounds of a path. Inverse filled paths will have bounds set
// by devSize. Non-inverse path bounds will not necessarily be clipped to devSize.
static void GetPathDevBounds(const SkPath& path,
int devW,
int devH,
const SkMatrix& matrix,
SkRect* bounds);
// Helper version that gets the dev width and height from a GrSurface.
static void GetPathDevBounds(const SkPath& path,
const GrSurface* device,
const SkMatrix& matrix,
SkRect* bounds) {
GetPathDevBounds(path, device->width(), device->height(), matrix, bounds);
}
private: private:
typedef GrRefCnt INHERITED; typedef GrRefCnt INHERITED;