本文整理汇总了C++中GrDrawState::getViewInverse方法的典型用法代码示例。如果您正苦于以下问题:C++ GrDrawState::getViewInverse方法的具体用法?C++ GrDrawState::getViewInverse怎么用?C++ GrDrawState::getViewInverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrDrawState
的用法示例。
在下文中一共展示了GrDrawState::getViewInverse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawPath
void GrGLPathRendering::drawPath(const GrPath* path, SkPath::FillType fill) {
GrGLuint id = static_cast<const GrGLPath*>(path)->pathID();
SkASSERT(NULL != fGpu->drawState()->getRenderTarget());
SkASSERT(NULL != fGpu->drawState()->getRenderTarget()->getStencilBuffer());
this->flushPathStencilSettings(fill);
SkASSERT(!fHWPathStencilSettings.isTwoSided());
const SkStrokeRec& stroke = path->getStroke();
SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fill);
GrGLenum fillMode =
gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face));
GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face);
if (nonInvertedFill == fill) {
if (stroke.needToApply()) {
if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) {
GL_CALL(StencilFillPath(id, fillMode, writeMask));
}
this->stencilThenCoverStrokePath(id, 0xffff, writeMask, GR_GL_BOUNDING_BOX);
} else {
this->stencilThenCoverFillPath(id, fillMode, writeMask, GR_GL_BOUNDING_BOX);
}
} else {
if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) {
GL_CALL(StencilFillPath(id, fillMode, writeMask));
}
if (stroke.needToApply()) {
GL_CALL(StencilStrokePath(id, 0xffff, writeMask));
}
GrDrawState* drawState = fGpu->drawState();
GrDrawState::AutoViewMatrixRestore avmr;
SkRect bounds = SkRect::MakeLTRB(0, 0,
SkIntToScalar(drawState->getRenderTarget()->width()),
SkIntToScalar(drawState->getRenderTarget()->height()));
SkMatrix vmi;
// mapRect through persp matrix may not be correct
if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewInverse(&vmi)) {
vmi.mapRect(&bounds);
// theoretically could set bloat = 0, instead leave it because of matrix inversion
// precision.
SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_ScalarHalf;
bounds.outset(bloat, bloat);
} else {
avmr.setIdentity(drawState);
}
fGpu->drawSimpleRect(bounds);
}
}
示例2: drawPath
void GrAAHairLinePathRenderer::drawPath(GrDrawState::StageMask stageMask) {
if (!this->createGeom(stageMask)) {
return;
}
GrDrawState* drawState = fTarget->drawState();
GrDrawTarget::AutoStateRestore asr;
if (!drawState->getViewMatrix().hasPerspective()) {
asr.set(fTarget);
GrMatrix ivm;
if (drawState->getViewInverse(&ivm)) {
drawState->preConcatSamplerMatrices(stageMask, ivm);
}
drawState->setViewMatrix(GrMatrix::I());
}
// TODO: See whether rendering lines as degenerate quads improves perf
// when we have a mix
fTarget->setIndexSourceToBuffer(fLinesIndexBuffer);
int lines = 0;
int nBufLines = fLinesIndexBuffer->maxQuads();
while (lines < fLineSegmentCnt) {
int n = GrMin(fLineSegmentCnt-lines, nBufLines);
drawState->setVertexEdgeType(GrDrawState::kHairLine_EdgeType);
fTarget->drawIndexed(kTriangles_PrimitiveType,
kVertsPerLineSeg*lines, // startV
0, // startI
kVertsPerLineSeg*n, // vCount
kIdxsPerLineSeg*n); // iCount
lines += n;
}
fTarget->setIndexSourceToBuffer(fQuadsIndexBuffer);
int quads = 0;
while (quads < fQuadCnt) {
int n = GrMin(fQuadCnt-quads, kNumQuadsInIdxBuffer);
drawState->setVertexEdgeType(GrDrawState::kHairQuad_EdgeType);
fTarget->drawIndexed(kTriangles_PrimitiveType,
4*fLineSegmentCnt + kVertsPerQuad*quads, // startV
0, // startI
kVertsPerQuad*n, // vCount
kIdxsPerQuad*n); // iCount
quads += n;
}
}
示例3: onDrawPath
bool GrTesselatedPathRenderer::onDrawPath(const SkPath& path,
GrPathFill fill,
const GrVec* translate,
GrDrawTarget* target,
GrDrawState::StageMask stageMask,
bool antiAlias) {
GrDrawTarget::AutoStateRestore asr(target);
GrDrawState* drawState = target->drawState();
// face culling doesn't make sense here
GrAssert(GrDrawState::kBoth_DrawFace == drawState->getDrawFace());
GrMatrix viewM = drawState->getViewMatrix();
GrScalar tol = GR_Scalar1;
tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds());
GrScalar tolSqd = GrMul(tol, tol);
int subpathCnt;
int maxPts = GrPathUtils::worstCasePointCount(path, &subpathCnt, tol);
GrVertexLayout layout = 0;
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if ((1 << s) & stageMask) {
layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
}
}
bool inverted = GrIsFillInverted(fill);
if (inverted) {
maxPts += 4;
subpathCnt++;
}
if (maxPts > USHRT_MAX) {
return false;
}
SkAutoSTMalloc<8, GrPoint> baseMem(maxPts);
GrPoint* base = baseMem;
GrPoint* vert = base;
GrPoint* subpathBase = base;
SkAutoSTMalloc<8, uint16_t> subpathVertCount(subpathCnt);
GrPoint pts[4];
SkPath::Iter iter(path, false);
bool first = true;
int subpath = 0;
for (;;) {
switch (iter.next(pts)) {
case kMove_PathCmd:
if (!first) {
subpathVertCount[subpath] = vert-subpathBase;
subpathBase = vert;
++subpath;
}
*vert = pts[0];
vert++;
break;
case kLine_PathCmd:
*vert = pts[1];
vert++;
break;
case kQuadratic_PathCmd: {
GrPathUtils::generateQuadraticPoints(pts[0], pts[1], pts[2],
tolSqd, &vert,
GrPathUtils::quadraticPointCount(pts, tol));
break;
}
case kCubic_PathCmd: {
GrPathUtils::generateCubicPoints(pts[0], pts[1], pts[2], pts[3],
tolSqd, &vert,
GrPathUtils::cubicPointCount(pts, tol));
break;
}
case kClose_PathCmd:
break;
case kEnd_PathCmd:
subpathVertCount[subpath] = vert-subpathBase;
++subpath; // this could be only in debug
goto FINISHED;
}
first = false;
}
FINISHED:
if (NULL != translate && 0 != translate->fX && 0 != translate->fY) {
for (int i = 0; i < vert - base; i++) {
base[i].offset(translate->fX, translate->fY);
}
}
if (inverted) {
GrRect bounds;
GrAssert(NULL != drawState->getRenderTarget());
bounds.setLTRB(0, 0,
GrIntToScalar(drawState->getRenderTarget()->width()),
GrIntToScalar(drawState->getRenderTarget()->height()));
GrMatrix vmi;
if (drawState->getViewInverse(&vmi)) {
//.........这里部分代码省略.........
示例4: onDrawPath
bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path,
GrPathFill fill,
GrDrawTarget* target,
bool antiAlias) {
GrAssert(!antiAlias);
GrAssert(kHairLine_GrPathFill != fill);
GrDrawState* drawState = target->drawState();
GrAssert(drawState->getStencil().isDisabled());
SkAutoTUnref<GrPath> p(fGpu->createPath(path));
GrPathFill nonInvertedFill = GrNonInvertedFill(fill);
target->stencilPath(p, nonInvertedFill);
// TODO: Use built in cover operation rather than a rect draw. This will require making our
// fragment shaders be able to eat varyings generated by a matrix.
// fill the path, zero out the stencil
GrRect bounds = p->getBounds();
GrScalar bloat = drawState->getViewMatrix().getMaxStretch() * GR_ScalarHalf;
GrDrawState::AutoDeviceCoordDraw adcd;
if (nonInvertedFill == fill) {
GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
kZero_StencilOp,
kZero_StencilOp,
kNotEqual_StencilFunc,
0xffff,
0x0000,
0xffff);
*drawState->stencil() = kStencilPass;
} else {
GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass,
kZero_StencilOp,
kZero_StencilOp,
// We know our rect will hit pixels outside the clip and the user bits will be 0
// outside the clip. So we can't just fill where the user bits are 0. We also need to
// check that the clip bit is set.
kEqualIfInClip_StencilFunc,
0xffff,
0x0000,
0xffff);
GrMatrix vmi;
bounds.setLTRB(0, 0,
GrIntToScalar(drawState->getRenderTarget()->width()),
GrIntToScalar(drawState->getRenderTarget()->height()));
// mapRect through persp matrix may not be correct
if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewInverse(&vmi)) {
vmi.mapRect(&bounds);
// theoretically could set bloat = 0, instead leave it because of matrix inversion
// precision.
} else {
adcd.set(drawState);
bloat = 0;
}
*drawState->stencil() = kInvertedStencilPass;
}
bounds.outset(bloat, bloat);
target->drawSimpleRect(bounds, NULL);
target->drawState()->stencil()->setDisabled();
return true;
}
示例5: internalDrawPath
//.........这里部分代码省略.........
if (reverse) {
passes[1] = &gInvEOColorPass;
} else {
passes[1] = &gEOColorPass;
}
}
drawFace[0] = drawFace[1] = GrDrawState::kBoth_DrawFace;
break;
case SkPath::kInverseWinding_FillType:
reverse = true;
// fallthrough
case SkPath::kWinding_FillType:
if (fSeparateStencil) {
if (fStencilWrapOps) {
passes[0] = &gWindStencilSeparateWithWrap;
} else {
passes[0] = &gWindStencilSeparateNoWrap;
}
passCount = 2;
drawFace[0] = GrDrawState::kBoth_DrawFace;
} else {
if (fStencilWrapOps) {
passes[0] = &gWindSingleStencilWithWrapInc;
passes[1] = &gWindSingleStencilWithWrapDec;
} else {
passes[0] = &gWindSingleStencilNoWrapInc;
passes[1] = &gWindSingleStencilNoWrapDec;
}
// which is cw and which is ccw is arbitrary.
drawFace[0] = GrDrawState::kCW_DrawFace;
drawFace[1] = GrDrawState::kCCW_DrawFace;
passCount = 3;
}
if (stencilOnly) {
lastPassIsBounds = false;
--passCount;
} else {
lastPassIsBounds = true;
drawFace[passCount-1] = GrDrawState::kBoth_DrawFace;
if (reverse) {
passes[passCount-1] = &gInvWindColorPass;
} else {
passes[passCount-1] = &gWindColorPass;
}
}
break;
default:
SkDEBUGFAIL("Unknown path fFill!");
return false;
}
}
}
SkRect devBounds;
GetPathDevBounds(path, drawState->getRenderTarget(), viewM, &devBounds);
for (int p = 0; p < passCount; ++p) {
drawState->setDrawFace(drawFace[p]);
if (NULL != passes[p]) {
*drawState->stencil() = *passes[p];
}
if (lastPassIsBounds && (p == passCount-1)) {
if (!colorWritesWereDisabled) {
drawState->disableState(GrDrawState::kNoColorWrites_StateBit);
}
SkRect bounds;
GrDrawState::AutoViewMatrixRestore avmr;
if (reverse) {
SkASSERT(NULL != drawState->getRenderTarget());
// draw over the dev bounds (which will be the whole dst surface for inv fill).
bounds = devBounds;
SkMatrix vmi;
// mapRect through persp matrix may not be correct
if (!drawState->getViewMatrix().hasPerspective() &&
drawState->getViewInverse(&vmi)) {
vmi.mapRect(&bounds);
} else {
avmr.setIdentity(drawState);
}
} else {
bounds = path.getBounds();
}
GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::kPreserve_ASRInit);
target->drawSimpleRect(bounds, NULL);
} else {
if (passCount > 1) {
drawState->enableState(GrDrawState::kNoColorWrites_StateBit);
}
if (indexCnt) {
target->drawIndexed(primType, 0, 0,
vertexCnt, indexCnt, &devBounds);
} else {
target->drawNonIndexed(primType, 0, vertexCnt, &devBounds);
}
}
}
return true;
}
示例6: internalDrawPath
//.........这里部分代码省略.........
passes[1] = &gInvEOColorPass;
} else {
passes[1] = &gEOColorPass;
}
}
drawFace[0] = drawFace[1] = GrDrawState::kBoth_DrawFace;
break;
case kInverseWinding_GrPathFill:
reverse = true;
// fallthrough
case kWinding_GrPathFill:
if (fSeparateStencil) {
if (fStencilWrapOps) {
passes[0] = &gWindStencilSeparateWithWrap;
} else {
passes[0] = &gWindStencilSeparateNoWrap;
}
passCount = 2;
drawFace[0] = GrDrawState::kBoth_DrawFace;
} else {
if (fStencilWrapOps) {
passes[0] = &gWindSingleStencilWithWrapInc;
passes[1] = &gWindSingleStencilWithWrapDec;
} else {
passes[0] = &gWindSingleStencilNoWrapInc;
passes[1] = &gWindSingleStencilNoWrapDec;
}
// which is cw and which is ccw is arbitrary.
drawFace[0] = GrDrawState::kCW_DrawFace;
drawFace[1] = GrDrawState::kCCW_DrawFace;
passCount = 3;
}
if (stencilOnly) {
lastPassIsBounds = false;
--passCount;
} else {
lastPassIsBounds = true;
drawFace[passCount-1] = GrDrawState::kBoth_DrawFace;
if (reverse) {
passes[passCount-1] = &gInvWindColorPass;
} else {
passes[passCount-1] = &gWindColorPass;
}
}
break;
default:
GrAssert(!"Unknown path fFill!");
return false;
}
}
}
{
for (int p = 0; p < passCount; ++p) {
drawState->setDrawFace(drawFace[p]);
if (NULL != passes[p]) {
*drawState->stencil() = *passes[p];
}
if (lastPassIsBounds && (p == passCount-1)) {
if (!colorWritesWereDisabled) {
drawState->disableState(GrDrawState::kNoColorWrites_StateBit);
}
GrRect bounds;
GrDrawState::AutoDeviceCoordDraw adcd;
if (reverse) {
GrAssert(NULL != drawState->getRenderTarget());
// draw over the whole world.
bounds.setLTRB(0, 0,
GrIntToScalar(drawState->getRenderTarget()->width()),
GrIntToScalar(drawState->getRenderTarget()->height()));
GrMatrix vmi;
// mapRect through persp matrix may not be correct
if (!drawState->getViewMatrix().hasPerspective() &&
drawState->getViewInverse(&vmi)) {
vmi.mapRect(&bounds);
} else {
adcd.set(drawState);
}
} else {
bounds = path.getBounds();
}
GrDrawTarget::AutoGeometryPush agp(target);
target->drawSimpleRect(bounds, NULL);
} else {
if (passCount > 1) {
drawState->enableState(GrDrawState::kNoColorWrites_StateBit);
}
if (indexCnt) {
target->drawIndexed(primType, 0, 0,
vertexCnt, indexCnt);
} else {
target->drawNonIndexed(primType, 0, vertexCnt);
}
}
}
}
return true;
}
示例7: onDrawPath
bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path,
const SkStrokeRec& stroke,
GrDrawTarget* target,
bool antiAlias) {
SkASSERT(!antiAlias);
SkASSERT(!stroke.isHairlineStyle());
GrDrawState* drawState = target->drawState();
SkASSERT(drawState->getStencil().isDisabled());
SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke));
if (path.isInverseFillType()) {
GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass,
kZero_StencilOp,
kZero_StencilOp,
// We know our rect will hit pixels outside the clip and the user bits will be 0
// outside the clip. So we can't just fill where the user bits are 0. We also need to
// check that the clip bit is set.
kEqualIfInClip_StencilFunc,
0xffff,
0x0000,
0xffff);
drawState->setStencil(kInvertedStencilPass);
// fake inverse with a stencil and cover
target->stencilPath(p, convert_skpath_filltype(path.getFillType()));
GrDrawState::AutoViewMatrixRestore avmr;
SkRect bounds = SkRect::MakeLTRB(0, 0,
SkIntToScalar(drawState->getRenderTarget()->width()),
SkIntToScalar(drawState->getRenderTarget()->height()));
SkMatrix vmi;
// mapRect through persp matrix may not be correct
if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewInverse(&vmi)) {
vmi.mapRect(&bounds);
// theoretically could set bloat = 0, instead leave it because of matrix inversion
// precision.
SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_ScalarHalf;
bounds.outset(bloat, bloat);
} else {
avmr.setIdentity(drawState);
}
target->drawSimpleRect(bounds);
} else {
GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
kZero_StencilOp,
kZero_StencilOp,
kNotEqual_StencilFunc,
0xffff,
0x0000,
0xffff);
drawState->setStencil(kStencilPass);
target->drawPath(p, convert_skpath_filltype(path.getFillType()));
}
target->drawState()->stencil()->setDisabled();
return true;
}
示例8: onDrawPath
//.........这里部分代码省略.........
case kWinding_PathFill:
if (fSeparateStencil) {
if (fStencilWrapOps) {
passes[0] = &gWindStencilSeparateWithWrap;
} else {
passes[0] = &gWindStencilSeparateNoWrap;
}
passCount = 2;
drawFace[0] = GrDrawState::kBoth_DrawFace;
} else {
if (fStencilWrapOps) {
passes[0] = &gWindSingleStencilWithWrapInc;
passes[1] = &gWindSingleStencilWithWrapDec;
} else {
passes[0] = &gWindSingleStencilNoWrapInc;
passes[1] = &gWindSingleStencilNoWrapDec;
}
// which is cw and which is ccw is arbitrary.
drawFace[0] = GrDrawState::kCW_DrawFace;
drawFace[1] = GrDrawState::kCCW_DrawFace;
passCount = 3;
}
if (stencilOnly) {
lastPassIsBounds = false;
--passCount;
} else {
lastPassIsBounds = true;
drawFace[passCount-1] = GrDrawState::kBoth_DrawFace;
if (reverse) {
passes[passCount-1] = &gInvWindColorPass;
} else {
passes[passCount-1] = &gWindColorPass;
}
}
break;
default:
GrAssert(!"Unknown path fFill!");
return;
}
}
}
{
for (int p = 0; p < passCount; ++p) {
drawState->setDrawFace(drawFace[p]);
if (NULL != passes[p]) {
*drawState->stencil() = *passes[p];
}
if (lastPassIsBounds && (p == passCount-1)) {
if (!colorWritesWereDisabled) {
drawState->disableState(GrDrawState::kNoColorWrites_StateBit);
}
GrRect bounds;
if (reverse) {
GrAssert(NULL != drawState->getRenderTarget());
// draw over the whole world.
bounds.setLTRB(0, 0,
GrIntToScalar(drawState->getRenderTarget()->width()),
GrIntToScalar(drawState->getRenderTarget()->height()));
GrMatrix vmi;
// mapRect through persp matrix may not be correct
if (!drawState->getViewMatrix().hasPerspective() &&
drawState->getViewInverse(&vmi)) {
vmi.mapRect(&bounds);
} else {
if (stageMask) {
if (!drawState->getViewInverse(&vmi)) {
GrPrintf("Could not invert matrix.");
return;
}
drawState->preConcatSamplerMatrices(stageMask, vmi);
}
drawState->setViewMatrix(GrMatrix::I());
}
} else {
bounds = fPath->getBounds();
bounds.offset(fTranslate);
}
GrDrawTarget::AutoGeometryPush agp(fTarget);
fTarget->drawSimpleRect(bounds, NULL, stageMask);
} else {
if (passCount > 1) {
drawState->enableState(GrDrawState::kNoColorWrites_StateBit);
}
if (fUseIndexedDraw) {
fTarget->drawIndexed(fPrimitiveType, 0, 0,
fVertexCnt, fIndexCnt);
} else {
int baseVertex = 0;
for (int sp = 0; sp < fSubpathCount; ++sp) {
fTarget->drawNonIndexed(fPrimitiveType, baseVertex,
fSubpathVertCount[sp]);
baseVertex += fSubpathVertCount[sp];
}
}
}
}
}
}
示例9: onDrawPath
bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
GrPathFill fill,
const GrVec* translate,
GrDrawTarget* target,
GrDrawState::StageMask stageMask,
bool antiAlias) {
int lineCnt;
int quadCnt;
GrDrawTarget::AutoReleaseGeometry arg;
if (!this->createGeom(path,
translate,
target,
stageMask,
&lineCnt,
&quadCnt,
&arg)) {
return false;
}
GrDrawTarget::AutoStateRestore asr;
GrDrawState* drawState = target->drawState();
if (!drawState->getViewMatrix().hasPerspective()) {
// we are going to whack the view matrix to identity to remove
// perspective.
asr.set(target,
GrDrawTarget::kPreserve_ASRInit);
drawState = target->drawState();
GrMatrix ivm;
if (drawState->getViewInverse(&ivm)) {
drawState->preConcatSamplerMatrices(stageMask, ivm);
}
drawState->viewMatrix()->reset();
}
// TODO: See whether rendering lines as degenerate quads improves perf
// when we have a mix
target->setIndexSourceToBuffer(fLinesIndexBuffer);
int lines = 0;
int nBufLines = fLinesIndexBuffer->maxQuads();
while (lines < lineCnt) {
int n = GrMin(lineCnt - lines, nBufLines);
drawState->setVertexEdgeType(GrDrawState::kHairLine_EdgeType);
target->drawIndexed(kTriangles_GrPrimitiveType,
kVertsPerLineSeg*lines, // startV
0, // startI
kVertsPerLineSeg*n, // vCount
kIdxsPerLineSeg*n); // iCount
lines += n;
}
target->setIndexSourceToBuffer(fQuadsIndexBuffer);
int quads = 0;
while (quads < quadCnt) {
int n = GrMin(quadCnt - quads, kNumQuadsInIdxBuffer);
drawState->setVertexEdgeType(GrDrawState::kHairQuad_EdgeType);
target->drawIndexed(kTriangles_GrPrimitiveType,
4 * lineCnt + kVertsPerQuad*quads, // startV
0, // startI
kVertsPerQuad*n, // vCount
kIdxsPerQuad*n); // iCount
quads += n;
}
return true;
}