本文整理汇总了C++中SkMatrix::getTranslateX方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::getTranslateX方法的具体用法?C++ SkMatrix::getTranslateX怎么用?C++ SkMatrix::getTranslateX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::getTranslateX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: just_trans_integral
/**
* Determine if the matrix can be treated as integral-only-translate,
* for the purpose of filtering.
*/
static bool just_trans_integral(const SkMatrix& m) {
static constexpr SkScalar tol = SK_Scalar1 / 256;
return m.getType() <= SkMatrix::kTranslate_Mask
&& SkScalarNearlyEqual(m.getTranslateX(), SkScalarRoundToScalar(m.getTranslateX()), tol)
&& SkScalarNearlyEqual(m.getTranslateY(), SkScalarRoundToScalar(m.getTranslateY()), tol);
}
示例2: SkASSERT
void SkDeferredCanvas::Rec::setConcat(const SkMatrix& m) {
SkASSERT(m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask));
if (m.getType() <= SkMatrix::kTranslate_Mask) {
fType = kTrans_Type;
fData.fTranslate.set(m.getTranslateX(), m.getTranslateY());
} else {
fType = kScaleTrans_Type;
fData.fScaleTrans.fScale.set(m.getScaleX(), m.getScaleY());
fData.fScaleTrans.fTrans.set(m.getTranslateX(), m.getTranslateY());
}
}
示例3: recordTranslate
void SkGPipeCanvas::recordTranslate(const SkMatrix& m) {
if (this->needOpBytes(2 * sizeof(SkScalar))) {
this->writeOp(kTranslate_DrawOp);
fWriter.writeScalar(m.getTranslateX());
fWriter.writeScalar(m.getTranslateY());
}
}
示例4: ShouldUseBicubic
bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix,
GrTextureParams::FilterMode* filterMode) {
if (matrix.isIdentity()) {
*filterMode = GrTextureParams::kNone_FilterMode;
return false;
}
SkScalar scales[2];
if (!matrix.getMinMaxScales(scales) || scales[0] < SK_Scalar1) {
// Bicubic doesn't handle arbitrary minimization well, as src texels can be skipped
// entirely,
*filterMode = GrTextureParams::kMipMap_FilterMode;
return false;
}
// At this point if scales[1] == SK_Scalar1 then the matrix doesn't do any scaling.
if (scales[1] == SK_Scalar1) {
if (matrix.rectStaysRect() && SkScalarIsInt(matrix.getTranslateX()) &&
SkScalarIsInt(matrix.getTranslateY())) {
*filterMode = GrTextureParams::kNone_FilterMode;
} else {
// Use bilerp to handle rotation or fractional translation.
*filterMode = GrTextureParams::kBilerp_FilterMode;
}
return false;
}
// When we use the bicubic filtering effect each sample is read from the texture using
// nearest neighbor sampling.
*filterMode = GrTextureParams::kNone_FilterMode;
return true;
}
示例5: parsePath
void GrCCPathParser::parsePath(const SkMatrix& m, const SkPath& path, SkRect* devBounds,
SkRect* devBounds45) {
const SkPoint* pts = SkPathPriv::PointData(path);
int numPts = path.countPoints();
SkASSERT(numPts + 1 <= fLocalDevPtsBuffer.count());
if (!numPts) {
devBounds->setEmpty();
devBounds45->setEmpty();
this->parsePath(path, nullptr);
return;
}
// m45 transforms path points into "45 degree" device space. A bounding box in this space gives
// the circumscribing octagon's diagonals. We could use SK_ScalarRoot2Over2, but an orthonormal
// transform is not necessary as long as the shader uses the correct inverse.
SkMatrix m45;
m45.setSinCos(1, 1);
m45.preConcat(m);
// X,Y,T are two parallel view matrices that accumulate two bounding boxes as they map points:
// device-space bounds and "45 degree" device-space bounds (| 1 -1 | * devCoords).
// | 1 1 |
Sk4f X = Sk4f(m.getScaleX(), m.getSkewY(), m45.getScaleX(), m45.getSkewY());
Sk4f Y = Sk4f(m.getSkewX(), m.getScaleY(), m45.getSkewX(), m45.getScaleY());
Sk4f T = Sk4f(m.getTranslateX(), m.getTranslateY(), m45.getTranslateX(), m45.getTranslateY());
// Map the path's points to device space and accumulate bounding boxes.
Sk4f devPt = SkNx_fma(Y, Sk4f(pts[0].y()), T);
devPt = SkNx_fma(X, Sk4f(pts[0].x()), devPt);
Sk4f topLeft = devPt;
Sk4f bottomRight = devPt;
// Store all 4 values [dev.x, dev.y, dev45.x, dev45.y]. We are only interested in the first two,
// and will overwrite [dev45.x, dev45.y] with the next point. This is why the dst buffer must
// be at least one larger than the number of points.
devPt.store(&fLocalDevPtsBuffer[0]);
for (int i = 1; i < numPts; ++i) {
devPt = SkNx_fma(Y, Sk4f(pts[i].y()), T);
devPt = SkNx_fma(X, Sk4f(pts[i].x()), devPt);
topLeft = Sk4f::Min(topLeft, devPt);
bottomRight = Sk4f::Max(bottomRight, devPt);
devPt.store(&fLocalDevPtsBuffer[i]);
}
SkPoint topLeftPts[2], bottomRightPts[2];
topLeft.store(topLeftPts);
bottomRight.store(bottomRightPts);
devBounds->setLTRB(topLeftPts[0].x(), topLeftPts[0].y(), bottomRightPts[0].x(),
bottomRightPts[0].y());
devBounds45->setLTRB(topLeftPts[1].x(), topLeftPts[1].y(), bottomRightPts[1].x(),
bottomRightPts[1].y());
this->parsePath(path, fLocalDevPtsBuffer.get());
}
示例6: MulOutputByInputAlpha
sk_sp<GrFragmentProcessor> SkPerlinNoiseShader::asFragmentProcessor(const AsFPArgs& args) const {
SkASSERT(args.fContext);
SkMatrix localMatrix = this->getLocalMatrix();
if (args.fLocalMatrix) {
localMatrix.preConcat(*args.fLocalMatrix);
}
SkMatrix matrix = *args.fViewMatrix;
matrix.preConcat(localMatrix);
if (0 == fNumOctaves) {
if (kFractalNoise_Type == fType) {
// Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2)
// TODO: Either treat the output of this shader as sRGB or allow client to specify a
// color space of the noise. Either way, this case (and the GLSL) need to convert to
// the destination.
sk_sp<GrFragmentProcessor> inner(
GrConstColorProcessor::Make(GrColor4f::FromGrColor(0x80404040),
GrConstColorProcessor::kModulateRGBA_InputMode));
return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
}
// Emit zero.
return GrConstColorProcessor::Make(GrColor4f::TransparentBlack(),
GrConstColorProcessor::kIgnore_InputMode);
}
// Either we don't stitch tiles, either we have a valid tile size
SkASSERT(!fStitchTiles || !fTileSize.isEmpty());
SkPerlinNoiseShader::PaintingData* paintingData =
new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix);
sk_sp<GrTextureProxy> permutationsProxy(GrMakeCachedBitmapProxy(
args.fContext->resourceProvider(),
paintingData->getPermutationsBitmap()));
sk_sp<GrTextureProxy> noiseProxy(GrMakeCachedBitmapProxy(args.fContext->resourceProvider(),
paintingData->getNoiseBitmap()));
SkMatrix m = *args.fViewMatrix;
m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1);
if (permutationsProxy && noiseProxy) {
sk_sp<GrFragmentProcessor> inner(
GrPerlinNoiseEffect::Make(args.fContext->resourceProvider(),
fType,
fNumOctaves,
fStitchTiles,
paintingData,
std::move(permutationsProxy),
std::move(noiseProxy),
m));
return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
}
delete paintingData;
return nullptr;
}
示例7: recordTranslate
void SkPictureRecord::recordTranslate(const SkMatrix& m) {
SkASSERT(SkMatrix::kTranslate_Mask == m.getType());
// op + dx + dy
size_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
size_t initialOffset = this->addDraw(TRANSLATE, &size);
this->addScalar(m.getTranslateX());
this->addScalar(m.getTranslateY());
this->validate(initialOffset, size);
}
示例8: calculate_translation
static void calculate_translation(bool applyVM,
const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY,
const SkMatrix& currentViewMatrix, SkScalar currentX,
SkScalar currentY, SkScalar* transX, SkScalar* transY) {
if (applyVM) {
*transX = newViewMatrix.getTranslateX() +
newViewMatrix.getScaleX() * (newX - currentX) +
newViewMatrix.getSkewX() * (newY - currentY) -
currentViewMatrix.getTranslateX();
*transY = newViewMatrix.getTranslateY() +
newViewMatrix.getSkewY() * (newX - currentX) +
newViewMatrix.getScaleY() * (newY - currentY) -
currentViewMatrix.getTranslateY();
} else {
*transX = newX - currentX;
*transY = newY - currentY;
}
}
示例9: asFragmentProcessor
const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor(
GrContext* context,
const SkMatrix& viewM,
const SkMatrix* externalLocalMatrix,
SkFilterQuality) const {
SkASSERT(context);
SkMatrix localMatrix = this->getLocalMatrix();
if (externalLocalMatrix) {
localMatrix.preConcat(*externalLocalMatrix);
}
SkMatrix matrix = viewM;
matrix.preConcat(localMatrix);
if (0 == fNumOctaves) {
if (kFractalNoise_Type == fType) {
// Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2)
SkAutoTUnref<const GrFragmentProcessor> inner(
GrConstColorProcessor::Create(0x80404040,
GrConstColorProcessor::kModulateRGBA_InputMode));
return GrFragmentProcessor::MulOutputByInputAlpha(inner);
}
// Emit zero.
return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore_InputMode);
}
// Either we don't stitch tiles, either we have a valid tile size
SkASSERT(!fStitchTiles || !fTileSize.isEmpty());
SkPerlinNoiseShader::PaintingData* paintingData =
new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix);
SkAutoTUnref<GrTexture> permutationsTexture(
GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
GrTextureParams::ClampNoFilter()));
SkAutoTUnref<GrTexture> noiseTexture(
GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(),
GrTextureParams::ClampNoFilter()));
SkMatrix m = viewM;
m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1);
if ((permutationsTexture) && (noiseTexture)) {
SkAutoTUnref<GrFragmentProcessor> inner(
GrPerlinNoiseEffect::Create(fType,
fNumOctaves,
fStitchTiles,
paintingData,
permutationsTexture, noiseTexture,
m));
return GrFragmentProcessor::MulOutputByInputAlpha(inner);
}
delete paintingData;
return nullptr;
}
示例10: nextafterf
SkLinearBitmapPipeline::SkLinearBitmapPipeline(
const SkMatrix& inverse,
SkFilterQuality filterQuality,
SkShader::TileMode xTile, SkShader::TileMode yTile,
SkColor paintColor,
const SkPixmap& srcPixmap)
{
SkISize dimensions = srcPixmap.info().dimensions();
const SkImageInfo& srcImageInfo = srcPixmap.info();
SkMatrix adjustedInverse = inverse;
if (filterQuality == kNone_SkFilterQuality) {
if (inverse.getScaleX() >= 0.0f) {
adjustedInverse.setTranslateX(
nextafterf(inverse.getTranslateX(), std::floor(inverse.getTranslateX())));
}
if (inverse.getScaleY() >= 0.0f) {
adjustedInverse.setTranslateY(
nextafterf(inverse.getTranslateY(), std::floor(inverse.getTranslateY())));
}
}
SkScalar dx = adjustedInverse.getScaleX();
// If it is an index 8 color type, the sampler converts to unpremul for better fidelity.
SkAlphaType alphaType = srcImageInfo.alphaType();
if (srcPixmap.colorType() == kIndex_8_SkColorType) {
alphaType = kUnpremul_SkAlphaType;
}
float postAlpha = SkColorGetA(paintColor) * (1.0f / 255.0f);
// As the stages are built, the chooser function may skip a stage. For example, with the
// identity matrix, the matrix stage is skipped, and the tilerStage is the first stage.
auto blenderStage = choose_blender_for_shading(alphaType, postAlpha, &fBlenderStage);
auto samplerStage = choose_pixel_sampler(
blenderStage, filterQuality, xTile, yTile,
srcPixmap, paintColor, &fSampleStage, &fAccessor);
auto tilerStage = choose_tiler(samplerStage, dimensions, xTile, yTile,
filterQuality, dx, &fTileStage);
fFirstStage = choose_matrix(tilerStage, adjustedInverse, &fMatrixStage);
fLastStage = blenderStage;
}
示例11: mapDstScaleTranslate
void SkLatticeIter::mapDstScaleTranslate(const SkMatrix& matrix) {
SkASSERT(matrix.isScaleTranslate());
SkScalar tx = matrix.getTranslateX();
SkScalar sx = matrix.getScaleX();
for (int i = 0; i < fDstX.count(); i++) {
fDstX[i] = fDstX[i] * sx + tx;
}
SkScalar ty = matrix.getTranslateY();
SkScalar sy = matrix.getScaleY();
for (int i = 0; i < fDstY.count(); i++) {
fDstY[i] = fDstY[i] * sy + ty;
}
}
示例12: INHERITED
SkPerlinNoiseShader::PerlinNoiseShaderContext::PerlinNoiseShaderContext(
const SkPerlinNoiseShader& shader, const ContextRec& rec)
: INHERITED(shader, rec)
{
SkMatrix newMatrix = *rec.fMatrix;
newMatrix.preConcat(shader.getLocalMatrix());
if (rec.fLocalMatrix) {
newMatrix.preConcat(*rec.fLocalMatrix);
}
// This (1,1) translation is due to WebKit's 1 based coordinates for the noise
// (as opposed to 0 based, usually). The same adjustment is in the setData() function.
fMatrix.setTranslate(-newMatrix.getTranslateX() + SK_Scalar1, -newMatrix.getTranslateY() + SK_Scalar1);
fPaintingData = SkNEW_ARGS(PaintingData, (shader.fTileSize, shader.fSeed, shader.fBaseFrequencyX, shader.fBaseFrequencyY, newMatrix));
}
示例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: dump
void SkFlatMatrix::dump() const {
const SkMatrix* matrix = (const SkMatrix*) fMatrixData;
char pBuffer[DUMP_BUFFER_SIZE];
char* bufferPtr = pBuffer;
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"matrix: ");
SkScalar scaleX = matrix->getScaleX();
SkMatrix defaultMatrix;
defaultMatrix.reset();
if (scaleX != defaultMatrix.getScaleX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"scaleX:%g ", SkScalarToFloat(scaleX));
SkScalar scaleY = matrix->getScaleY();
if (scaleY != defaultMatrix.getScaleY())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"scaleY:%g ", SkScalarToFloat(scaleY));
SkScalar skewX = matrix->getSkewX();
if (skewX != defaultMatrix.getSkewX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"skewX:%g ", SkScalarToFloat(skewX));
SkScalar skewY = matrix->getSkewY();
if (skewY != defaultMatrix.getSkewY())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"skewY:%g ", SkScalarToFloat(skewY));
SkScalar translateX = matrix->getTranslateX();
if (translateX != defaultMatrix.getTranslateX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"translateX:%g ", SkScalarToFloat(translateX));
SkScalar translateY = matrix->getTranslateY();
if (translateY != defaultMatrix.getTranslateY())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"translateY:%g ", SkScalarToFloat(translateY));
SkScalar perspX = matrix->getPerspX();
if (perspX != defaultMatrix.getPerspX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"perspX:%g ", SkFractToFloat(perspX));
SkScalar perspY = matrix->getPerspY();
if (perspY != defaultMatrix.getPerspY())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"perspY:%g ", SkFractToFloat(perspY));
SkDebugf("%s\n", pBuffer);
}
示例15: didConcat
void SkDumpCanvas::didConcat(const SkMatrix& matrix) {
SkString str;
switch (matrix.getType()) {
case SkMatrix::kTranslate_Mask:
this->dump(kMatrix_Verb, nullptr, "translate(%g %g)",
SkScalarToFloat(matrix.getTranslateX()),
SkScalarToFloat(matrix.getTranslateY()));
break;
case SkMatrix::kScale_Mask:
this->dump(kMatrix_Verb, nullptr, "scale(%g %g)",
SkScalarToFloat(matrix.getScaleX()),
SkScalarToFloat(matrix.getScaleY()));
break;
default:
matrix.toString(&str);
this->dump(kMatrix_Verb, nullptr, "concat(%s)", str.c_str());
break;
}
this->INHERITED::didConcat(matrix);
}