本文整理汇总了C++中SkMatrix::hasPerspective方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::hasPerspective方法的具体用法?C++ SkMatrix::hasPerspective怎么用?C++ SkMatrix::hasPerspective使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::hasPerspective方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: canDraw
bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) {
// TODO: support perspective (need getMaxScale replacement)
if (viewMatrix.hasPerspective()) {
return false;
}
SkScalar maxScale = viewMatrix.getMaxScale();
SkScalar scaledTextSize = maxScale*paint.getTextSize();
// Scaling up beyond 2x yields undesireable artifacts
if (scaledTextSize > 2*kLargeDFFontSize) {
return false;
}
if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP() &&
scaledTextSize < kLargeDFFontSize) {
return false;
}
// rasterizers and mask filters modify alpha, which doesn't
// translate well to distance
if (paint.getRasterizer() || paint.getMaskFilter() ||
!fContext->getTextTarget()->caps()->shaderDerivativeSupport()) {
return false;
}
// TODO: add some stroking support
if (paint.getStyle() != SkPaint::kFill_Style) {
return false;
}
return true;
}
示例2: canDrawPath
bool GrAADistanceFieldPathRenderer::canDrawPath(const GrDrawTarget* target,
const GrPipelineBuilder* pipelineBuilder,
const SkMatrix& viewMatrix,
const SkPath& path,
const GrStrokeInfo& stroke,
bool antiAlias) const {
// TODO: Support inverse fill
// TODO: Support strokes
if (!target->caps()->shaderCaps()->shaderDerivativeSupport() || !antiAlias
|| path.isInverseFillType() || path.isVolatile() || !stroke.isFillStyle()) {
return false;
}
// currently don't support perspective
if (viewMatrix.hasPerspective()) {
return false;
}
// only support paths smaller than 64x64, scaled to less than 256x256
// the goal is to accelerate rendering of lots of small paths that may be scaling
SkScalar maxScale = viewMatrix.getMaxScale();
const SkRect& bounds = path.getBounds();
SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height());
return maxDim < 64.f && maxDim * maxScale < 256.f;
}
示例3: canDraw
bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt,
const GrClip& clip,
const GrPaint& paint,
const SkPaint& skPaint,
const SkMatrix& viewMatrix) {
if (skPaint.getRasterizer()) {
return false;
}
if (skPaint.getMaskFilter()) {
return false;
}
if (SkPathEffect* pe = skPaint.getPathEffect()) {
if (pe->asADash(NULL) != SkPathEffect::kDash_DashType) {
return false;
}
}
// No hairlines unless we can map the 1 px width to the object space.
if (skPaint.getStyle() == SkPaint::kStroke_Style
&& skPaint.getStrokeWidth() == 0
&& viewMatrix.hasPerspective()) {
return false;
}
// No color bitmap fonts.
SkScalerContext::Rec rec;
SkScalerContext::MakeRec(skPaint, &fDeviceProperties, NULL, &rec);
return rec.getFormat() != SkMask::kARGB32_Format;
}
示例4: tesselate
static void tesselate(intptr_t vertices,
size_t vertexStride,
GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
const GrQuad* localQuad) {
SkPoint* positions = reinterpret_cast<SkPoint*>(vertices);
positions->setRectFan(rect.fLeft, rect.fTop,
rect.fRight, rect.fBottom, vertexStride);
if (!viewMatrix.hasPerspective()) {
viewMatrix.mapPointsWithStride(positions, vertexStride,
NonAAFillRectBatchBase::kVertsPerInstance);
}
// Setup local coords
// TODO we should only do this if local coords are being read
if (localQuad) {
static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
for (int i = 0; i < NonAAFillRectBatchBase::kVertsPerInstance; i++) {
SkPoint* coords = reinterpret_cast<SkPoint*>(vertices + kLocalOffset +
i * vertexStride);
*coords = localQuad->point(i);
}
}
static const int kColorOffset = sizeof(SkPoint);
GrColor* vertColor = reinterpret_cast<GrColor*>(vertices + kColorOffset);
for (int j = 0; j < 4; ++j) {
*vertColor = color;
vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride);
}
}
示例5: Append
bool Append(GrBatch* origBatch,
GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkRect* localRect,
const SkMatrix* localMatrix) {
bool usePerspective = viewMatrix.hasPerspective() ||
(localMatrix && localMatrix->hasPerspective());
if (usePerspective && origBatch->classID() != NonAAFillRectBatchPerspective::ClassID()) {
return false;
}
if (!usePerspective) {
NonAAFillRectBatchSimple* batch = origBatch->cast<NonAAFillRectBatchSimple>();
append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
batch->updateBoundsAfterAppend();
} else {
NonAAFillRectBatchPerspective* batch = origBatch->cast<NonAAFillRectBatchPerspective>();
const NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->back();
if (!geo.fViewMatrix.cheapEqualTo(viewMatrix) ||
geo.fHasLocalRect != SkToBool(localRect) ||
geo.fHasLocalMatrix != SkToBool(localMatrix) ||
(geo.fHasLocalMatrix && !geo.fLocalMatrix.cheapEqualTo(*localMatrix))) {
return false;
}
append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
batch->updateBoundsAfterAppend();
}
return true;
}
示例6: check_bounds
bool check_bounds(const SkMatrix& viewMatrix, const SkRect& devBounds, void* vertices, int vCount)
{
SkRect tolDevBounds = devBounds;
// The bounds ought to be tight, but in perspective the below code runs the verts
// through the view matrix to get back to dev coords, which can introduce imprecision.
if (viewMatrix.hasPerspective()) {
tolDevBounds.outset(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
} else {
// Non-persp matrices cause this path renderer to draw in device space.
SkASSERT(viewMatrix.isIdentity());
}
SkRect actualBounds;
VertexType* verts = reinterpret_cast<VertexType*>(vertices);
bool first = true;
for (int i = 0; i < vCount; ++i) {
SkPoint pos = verts[i].fPos;
// This is a hack to workaround the fact that we move some degenerate segments offscreen.
if (SK_ScalarMax == pos.fX) {
continue;
}
viewMatrix.mapPoints(&pos, 1);
if (first) {
actualBounds.set(pos.fX, pos.fY, pos.fX, pos.fY);
first = false;
} else {
actualBounds.growToInclude(pos.fX, pos.fY);
}
}
if (!first) {
return tolDevBounds.contains(actualBounds);
}
return true;
}
示例7: createGeom
bool GrAAHairLinePathRenderer::createGeom(
const SkPath& path,
GrDrawTarget* target,
int* lineCnt,
int* quadCnt,
GrDrawTarget::AutoReleaseGeometry* arg) {
const GrDrawState& drawState = target->getDrawState();
int rtHeight = drawState.getRenderTarget()->height();
GrIRect devClipBounds;
target->getClip()->getConservativeBounds(drawState.getRenderTarget(),
&devClipBounds);
GrVertexLayout layout = GrDrawState::kEdge_VertexLayoutBit;
SkMatrix viewM = drawState.getViewMatrix();
PREALLOC_PTARRAY(128) lines;
PREALLOC_PTARRAY(128) quads;
IntArray qSubdivs;
*quadCnt = generate_lines_and_quads(path, viewM, devClipBounds,
&lines, &quads, &qSubdivs);
*lineCnt = lines.count() / 2;
int vertCnt = kVertsPerLineSeg * *lineCnt + kVertsPerQuad * *quadCnt;
GrAssert(sizeof(Vertex) == GrDrawState::VertexSize(layout));
if (!arg->set(target, layout, vertCnt, 0)) {
return false;
}
Vertex* verts = reinterpret_cast<Vertex*>(arg->vertices());
const SkMatrix* toDevice = NULL;
const SkMatrix* toSrc = NULL;
SkMatrix ivm;
if (viewM.hasPerspective()) {
if (viewM.invert(&ivm)) {
toDevice = &viewM;
toSrc = &ivm;
}
}
for (int i = 0; i < *lineCnt; ++i) {
add_line(&lines[2*i], rtHeight, toSrc, &verts);
}
int unsubdivQuadCnt = quads.count() / 3;
for (int i = 0; i < unsubdivQuadCnt; ++i) {
GrAssert(qSubdivs[i] >= 0);
add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &verts);
}
return true;
}
示例8: SkComputeAxisAlignmentForHText
SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix) {
SkASSERT(!matrix.hasPerspective());
if (0 == matrix[SkMatrix::kMSkewY]) {
return kX_SkAxisAlignment;
}
if (0 == matrix[SkMatrix::kMScaleX]) {
return kY_SkAxisAlignment;
}
return kNone_SkAxisAlignment;
}
示例9:
SkShader::Context::MatrixClass SkShader::Context::ComputeMatrixClass(const SkMatrix& mat) {
MatrixClass mc = kLinear_MatrixClass;
if (mat.hasPerspective()) {
if (mat.isFixedStepInX()) {
mc = kFixedStepInX_MatrixClass;
} else {
mc = kPerspective_MatrixClass;
}
}
return mc;
}
示例10: drawPaint
void GrDrawContext::drawPaint(GrRenderTarget* rt,
const GrClip& clip,
const GrPaint& origPaint,
const SkMatrix& viewMatrix) {
RETURN_IF_ABANDONED
// set rect to be big enough to fill the space, but not super-huge, so we
// don't overflow fixed-point implementations
SkRect r;
r.setLTRB(0, 0,
SkIntToScalar(rt->width()),
SkIntToScalar(rt->height()));
SkTCopyOnFirstWrite<GrPaint> paint(origPaint);
// by definition this fills the entire clip, no need for AA
if (paint->isAntiAlias()) {
paint.writable()->setAntiAlias(false);
}
bool isPerspective = viewMatrix.hasPerspective();
// We attempt to map r by the inverse matrix and draw that. mapRect will
// map the four corners and bound them with a new rect. This will not
// produce a correct result for some perspective matrices.
if (!isPerspective) {
SkMatrix inverse;
if (!viewMatrix.invert(&inverse)) {
SkDebugf("Could not invert matrix\n");
return;
}
inverse.mapRect(&r);
this->drawRect(rt, clip, *paint, viewMatrix, r);
} else {
SkMatrix localMatrix;
if (!viewMatrix.invert(&localMatrix)) {
SkDebugf("Could not invert matrix\n");
return;
}
AutoCheckFlush acf(fContext);
if (!this->prepareToDraw(rt)) {
return;
}
GrPipelineBuilder pipelineBuilder(*paint, rt, clip);
fDrawTarget->drawBWRect(pipelineBuilder,
paint->getColor(),
SkMatrix::I(),
r,
NULL,
&localMatrix);
}
}
示例11: InitDistanceFieldPaint
void GrTextUtils::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
SkPaint* skPaint,
SkScalar* textRatio,
const SkMatrix& viewMatrix) {
// getMaxScale doesn't support perspective, so neither do we at the moment
SkASSERT(!viewMatrix.hasPerspective());
SkScalar maxScale = viewMatrix.getMaxScale();
SkScalar textSize = skPaint->getTextSize();
SkScalar scaledTextSize = textSize;
// if we have non-unity scale, we need to choose our base text size
// based on the SkPaint's text size multiplied by the max scale factor
// TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)?
if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) {
scaledTextSize *= maxScale;
}
// We have three sizes of distance field text, and within each size 'bucket' there is a floor
// and ceiling. A scale outside of this range would require regenerating the distance fields
SkScalar dfMaskScaleFloor;
SkScalar dfMaskScaleCeil;
if (scaledTextSize <= kSmallDFFontLimit) {
dfMaskScaleFloor = kMinDFFontSize;
dfMaskScaleCeil = kSmallDFFontLimit;
*textRatio = textSize / kSmallDFFontSize;
skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize));
} else if (scaledTextSize <= kMediumDFFontLimit) {
dfMaskScaleFloor = kSmallDFFontLimit;
dfMaskScaleCeil = kMediumDFFontLimit;
*textRatio = textSize / kMediumDFFontSize;
skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize));
} else {
dfMaskScaleFloor = kMediumDFFontLimit;
dfMaskScaleCeil = kLargeDFFontLimit;
*textRatio = textSize / kLargeDFFontSize;
skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize));
}
// Because there can be multiple runs in the blob, we want the overall maxMinScale, and
// minMaxScale to make regeneration decisions. Specifically, we want the maximum minimum scale
// we can tolerate before we'd drop to a lower mip size, and the minimum maximum scale we can
// tolerate before we'd have to move to a large mip size. When we actually test these values
// we look at the delta in scale between the new viewmatrix and the old viewmatrix, and test
// against these values to decide if we can reuse or not(ie, will a given scale change our mip
// level)
SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil);
blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize);
skPaint->setLCDRenderText(false);
skPaint->setAutohinted(false);
skPaint->setHinting(SkPaint::kNormal_Hinting);
skPaint->setSubpixelText(true);
}
示例12: SkASSERT
static inline bool get_direction(const SkPath& path, const SkMatrix& m, SkPath::Direction* dir) {
if (!path.cheapComputeDirection(dir)) {
return false;
}
// check whether m reverses the orientation
SkASSERT(!m.hasPerspective());
SkScalar det2x2 = SkScalarMul(m.get(SkMatrix::kMScaleX), m.get(SkMatrix::kMScaleY)) -
SkScalarMul(m.get(SkMatrix::kMSkewX), m.get(SkMatrix::kMSkewY));
if (det2x2 < 0) {
*dir = SkPath::OppositeDirection(*dir);
}
return true;
}
示例13: SkASSERT
GrCCPathCache::MaskTransform::MaskTransform(const SkMatrix& m, SkIVector* shift)
: fMatrix2x2{m.getScaleX(), m.getSkewX(), m.getSkewY(), m.getScaleY()} {
SkASSERT(!m.hasPerspective());
Sk2f translate = Sk2f(m.getTranslateX(), m.getTranslateY());
Sk2f transFloor;
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
// On Android framework we pre-round view matrix translates to integers for better caching.
transFloor = translate;
#else
transFloor = translate.floor();
(translate - transFloor).store(fSubpixelTranslate);
#endif
shift->set((int)transFloor[0], (int)transFloor[1]);
SkASSERT((float)shift->fX == transFloor[0]); // Make sure transFloor had integer values.
SkASSERT((float)shift->fY == transFloor[1]);
}
示例14: SkASSERT
inline static void append_to_batch(NonAAFillRectBatchPerspective* batch, GrColor color,
const SkMatrix& viewMatrix, const SkRect& rect,
const SkRect* localRect, const SkMatrix* localMatrix) {
SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspective()));
NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->push_back();
geo.fColor = color;
geo.fViewMatrix = viewMatrix;
geo.fRect = rect;
geo.fHasLocalRect = SkToBool(localRect);
geo.fHasLocalMatrix = SkToBool(localMatrix);
if (localMatrix) {
geo.fLocalMatrix = *localMatrix;
}
if (localRect) {
geo.fLocalRect = *localRect;
}
}
示例15: CanDrawAsDistanceFields
bool GrTextUtils::CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
const SkSurfaceProps& props, const GrShaderCaps& caps) {
// TODO: support perspective (need getMaxScale replacement)
if (viewMatrix.hasPerspective()) {
return false;
}
SkScalar maxScale = viewMatrix.getMaxScale();
SkScalar scaledTextSize = maxScale*skPaint.getTextSize();
// Hinted text looks far better at small resolutions
// Scaling up beyond 2x yields undesireable artifacts
if (scaledTextSize < kMinDFFontSize ||
scaledTextSize > kLargeDFFontLimit) {
return false;
}
bool useDFT = props.isUseDeviceIndependentFonts();
#if SK_FORCE_DISTANCE_FIELD_TEXT
useDFT = true;
#endif
if (!useDFT && scaledTextSize < kLargeDFFontSize) {
return false;
}
// rasterizers and mask filters modify alpha, which doesn't
// translate well to distance
if (skPaint.getRasterizer() || skPaint.getMaskFilter() || !caps.shaderDerivativeSupport()) {
return false;
}
// TODO: add some stroking support
if (skPaint.getStyle() != SkPaint::kFill_Style) {
return false;
}
return true;
}