本文整理汇总了C++中SkMatrix::preScale方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::preScale方法的具体用法?C++ SkMatrix::preScale怎么用?C++ SkMatrix::preScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::preScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runAnimationTask
/**
* Called on a background thread. Here we can only modify fBackMatrices.
*/
virtual void runAnimationTask(double t, double dt, int w, int h) {
for (int idx = 0; idx < kNumPaths; ++idx) {
Velocity* v = &fVelocities[idx];
Glyph* glyph = &fGlyphs[idx];
SkMatrix* backMatrix = &fBackMatrices[idx];
glyph->fPosition.fX += v->fDx * dt;
if (glyph->fPosition.x() < 0) {
glyph->fPosition.fX -= 2 * glyph->fPosition.x();
v->fDx = -v->fDx;
} else if (glyph->fPosition.x() > w) {
glyph->fPosition.fX -= 2 * (glyph->fPosition.x() - w);
v->fDx = -v->fDx;
}
glyph->fPosition.fY += v->fDy * dt;
if (glyph->fPosition.y() < 0) {
glyph->fPosition.fY -= 2 * glyph->fPosition.y();
v->fDy = -v->fDy;
} else if (glyph->fPosition.y() > h) {
glyph->fPosition.fY -= 2 * (glyph->fPosition.y() - h);
v->fDy = -v->fDy;
}
glyph->fSpin += v->fDSpin * dt;
backMatrix->setTranslate(glyph->fPosition.x(), glyph->fPosition.y());
backMatrix->preScale(glyph->fZoom, glyph->fZoom);
backMatrix->preRotate(glyph->fSpin);
backMatrix->preTranslate(-glyph->fMidpt.x(), -glyph->fMidpt.y());
}
}
示例2: onDraw
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
SkMatrix matrix;
SkGroupShape* gs = new SkGroupShape;
SkAutoUnref aur(gs);
gs->appendShape(&fGroup);
matrix.setScale(-SK_Scalar1, SK_Scalar1);
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
gs->appendShape(&fGroup, matrix);
matrix.setTranslate(SkIntToScalar(240), 0);
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 1
SkPicture* pict = new SkPicture;
SkCanvas* cv = pict->beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
gs->draw(cv);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
gs->draw(cv);
pict->endRecording();
canvas->drawPicture(*pict);
pict->unref();
#endif
}
示例3: scaleMatrix
static void scaleMatrix(const SkPath& one, const SkPath& two, SkMatrix& scale) {
SkRect larger = one.getBounds();
larger.join(two.getBounds());
SkScalar largerWidth = larger.width();
if (largerWidth < 4) {
largerWidth = 4;
}
SkScalar largerHeight = larger.height();
if (largerHeight < 4) {
largerHeight = 4;
}
SkScalar hScale = (bitWidth - 2) / largerWidth;
SkScalar vScale = (bitHeight - 2) / largerHeight;
scale.reset();
scale.preScale(hScale, vScale);
larger.fLeft *= hScale;
larger.fRight *= hScale;
larger.fTop *= vScale;
larger.fBottom *= vScale;
SkScalar dx = -16000 > larger.fLeft ? -16000 - larger.fLeft
: 16000 < larger.fRight ? 16000 - larger.fRight : 0;
SkScalar dy = -16000 > larger.fTop ? -16000 - larger.fTop
: 16000 < larger.fBottom ? 16000 - larger.fBottom : 0;
scale.postTranslate(dx, dy);
}
示例4: onDraw
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
SkMatrix saveM = *fMatrixRefs[3];
SkScalar c = SkIntToScalar(50);
fMatrixRefs[3]->preRotate(SkIntToScalar(30), c, c);
SkMatrix matrix;
SkGroupShape* gs = new SkGroupShape;
SkAutoUnref aur(gs);
gs->appendShape(&fGroup);
matrix.setScale(-SK_Scalar1, SK_Scalar1);
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
gs->appendShape(&fGroup, matrix);
matrix.setTranslate(SkIntToScalar(240), 0);
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 0
canvas->drawShape(gs);
#else
SkPicture pict;
SkCanvas* cv = pict.beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
cv->drawShape(gs);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
cv->drawShape(gs);
pict.endRecording();
canvas->drawPicture(pict);
#endif
*fMatrixRefs[3] = saveM;
}
示例5: drawPattern
void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect, const FloatSize& scale,
const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& destRect, const IntSize& repeatSpacing)
{
TRACE_EVENT0("skia", "Image::drawPattern");
SkBitmap bitmap;
if (!bitmapForCurrentFrame(&bitmap))
return;
FloatRect normSrcRect = floatSrcRect;
normSrcRect.intersect(FloatRect(0, 0, bitmap.width(), bitmap.height()));
if (destRect.isEmpty() || normSrcRect.isEmpty())
return; // nothing to draw
SkMatrix localMatrix;
// We also need to translate it such that the origin of the pattern is the
// origin of the destination rect, which is what WebKit expects. Skia uses
// the coordinate system origin as the base for the pattern. If WebKit wants
// a shifted image, it will shift it from there using the localMatrix.
const float adjustedX = phase.x() + normSrcRect.x() * scale.width();
const float adjustedY = phase.y() + normSrcRect.y() * scale.height();
localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjustedY));
// Because no resizing occurred, the shader transform should be
// set to the pattern's transform, which just includes scale.
localMatrix.preScale(scale.width(), scale.height());
SkBitmap bitmapToPaint;
bitmap.extractSubset(&bitmapToPaint, enclosingIntRect(normSrcRect));
if (!repeatSpacing.isZero()) {
SkScalar ctmScaleX = 1.0;
SkScalar ctmScaleY = 1.0;
if (!RuntimeEnabledFeatures::slimmingPaintEnabled()) {
AffineTransform ctm = context->getCTM();
ctmScaleX = ctm.xScale();
ctmScaleY = ctm.yScale();
}
bitmapToPaint = createBitmapWithSpace(
bitmapToPaint,
repeatSpacing.width() * ctmScaleX / scale.width(),
repeatSpacing.height() * ctmScaleY / scale.height());
}
RefPtr<SkShader> shader = adoptRef(SkShader::CreateBitmapShader(bitmapToPaint, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap);
{
SkPaint paint;
int initialSaveCount = context->preparePaintForDrawRectToRect(&paint, floatSrcRect,
destRect, compositeOp, !bitmap.isOpaque(), isLazyDecoded, bitmap.isImmutable());
paint.setShader(shader.get());
context->drawRect(destRect, paint);
context->canvas()->restoreToCount(initialSaveCount);
}
if (isLazyDecoded)
PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID());
}
示例6: NativePreScale
void Matrix::NativePreScale(
/* [in] */ Int64 nObj,
/* [in] */ Float sx,
/* [in] */ Float sy)
{
SkMatrix* obj = reinterpret_cast<SkMatrix*>(nObj);
obj->preScale(sx, sy);
}
示例7: draw
void draw(SkCanvas* canvas) {
SkMatrix matrix;
SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
SkRect::Make(source.bounds()).toQuad(bitmapBounds);
matrix.setPolyToPoly(bitmapBounds, perspect, 4);
matrix.preScale(.75f, 1.5f, source.width() / 2, source.height() / 2);
canvas->concat(matrix);
canvas->drawBitmap(source, 0, 0);
}
示例8: drawPattern
void Image::drawPattern(GraphicsContext& context,
const FloatRect& floatSrcRect,
const FloatSize& scale,
const FloatPoint& phase,
SkBlendMode compositeOp,
const FloatRect& destRect,
const FloatSize& repeatSpacing) {
TRACE_EVENT0("skia", "Image::drawPattern");
sk_sp<SkImage> image = imageForCurrentFrame();
if (!image)
return;
FloatRect normSrcRect = floatSrcRect;
normSrcRect.intersect(FloatRect(0, 0, image->width(), image->height()));
if (destRect.isEmpty() || normSrcRect.isEmpty())
return; // nothing to draw
SkMatrix localMatrix;
// We also need to translate it such that the origin of the pattern is the
// origin of the destination rect, which is what WebKit expects. Skia uses
// the coordinate system origin as the base for the pattern. If WebKit wants
// a shifted image, it will shift it from there using the localMatrix.
const float adjustedX = phase.x() + normSrcRect.x() * scale.width();
const float adjustedY = phase.y() + normSrcRect.y() * scale.height();
localMatrix.setTranslate(SkFloatToScalar(adjustedX),
SkFloatToScalar(adjustedY));
// Because no resizing occurred, the shader transform should be
// set to the pattern's transform, which just includes scale.
localMatrix.preScale(scale.width(), scale.height());
// Fetch this now as subsetting may swap the image.
auto imageID = image->uniqueID();
image = image->makeSubset(enclosingIntRect(normSrcRect));
if (!image)
return;
{
SkPaint paint = context.fillPaint();
paint.setColor(SK_ColorBLACK);
paint.setBlendMode(static_cast<SkBlendMode>(compositeOp));
paint.setFilterQuality(
context.computeFilterQuality(this, destRect, normSrcRect));
paint.setAntiAlias(context.shouldAntialias());
paint.setShader(createPatternShader(
image.get(), localMatrix, paint,
FloatSize(repeatSpacing.width() / scale.width(),
repeatSpacing.height() / scale.height())));
context.drawRect(destRect, paint);
}
if (currentFrameIsLazyDecoded())
PlatformInstrumentation::didDrawLazyPixelRef(imageID);
}
示例9: refBitmapShader
SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatrix* localM) const {
SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0);
SkMatrix m;
m.setConcat(matrix, this->getLocalMatrix());
if (localM) {
m.preConcat(*localM);
}
// Use a rotation-invariant scale
SkPoint scale;
if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) {
// Decomposition failed, use an approximation.
scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m.getSkewX()),
SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m.getSkewY()));
}
SkSize scaledSize = SkSize::Make(scale.x() * fPicture->width(), scale.y() * fPicture->height());
SkISize tileSize = scaledSize.toRound();
if (tileSize.isEmpty()) {
return NULL;
}
// The actual scale, compensating for rounding.
SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fPicture->width(),
SkIntToScalar(tileSize.height()) / fPicture->height());
SkAutoMutexAcquire ama(fCachedBitmapShaderMutex);
if (!fCachedBitmapShader || tileScale != fCachedTileScale) {
SkBitmap bm;
if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) {
return NULL;
}
bm.eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(bm);
canvas.scale(tileScale.width(), tileScale.height());
canvas.drawPicture(fPicture);
fCachedTileScale = tileScale;
SkMatrix shaderMatrix = this->getLocalMatrix();
shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height());
fCachedBitmapShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatrix));
}
// Increment the ref counter inside the mutex to ensure the returned pointer is still valid.
// Otherwise, the pointer may have been overwritten on a different thread before the object's
// ref count was incremented.
fCachedBitmapShader.get()->ref();
return fCachedBitmapShader;
}
示例10: check_decompScale
static bool check_decompScale(const SkMatrix& matrix) {
SkSize scale;
SkMatrix remaining;
if (!matrix.decomposeScale(&scale, &remaining)) {
return false;
}
if (scale.width() <= 0 || scale.height() <= 0) {
return false;
}
remaining.preScale(scale.width(), scale.height());
return nearly_equal(matrix, remaining);
}
示例11: scaledDrawTheSame
static int scaledDrawTheSame(const SkPath& one, const SkPath& two,
int a, int b, bool drawPaths, SkBitmap& bitmap, SkCanvas* canvas) {
SkMatrix scale;
scale.reset();
float aScale = 1.21f;
float bScale = 1.11f;
scale.preScale(a * aScale, b * bScale);
SkPath scaledOne, scaledTwo;
one.transform(scale, &scaledOne);
two.transform(scale, &scaledTwo);
int errors = pathsDrawTheSame(scaledOne, scaledTwo, bitmap, canvas);
if (errors == 0) {
return 0;
}
while (!drawAsciiPaths(scaledOne, scaledTwo, drawPaths)) {
scale.reset();
aScale *= 0.5f;
bScale *= 0.5f;
scale.preScale(a * aScale, b * bScale);
one.transform(scale, &scaledOne);
two.transform(scale, &scaledTwo);
}
return errors;
}
示例12: dump
void SkGlyphCache::dump() const {
const SkTypeface* face = fScalerContext->getTypeface();
const SkScalerContextRec& rec = fScalerContext->getRec();
SkMatrix matrix;
rec.getSingleMatrix(&matrix);
matrix.preScale(SkScalarInvert(rec.fTextSize), SkScalarInvert(rec.fTextSize));
SkString name;
face->getFamilyName(&name);
SkString msg;
SkFontStyle style = face->fontStyle();
msg.printf("cache typeface:%x %25s:(%d,%d,%d)\n %s glyphs:%3d",
face->uniqueID(), name.c_str(), style.weight(), style.width(), style.slant(),
rec.dump().c_str(), fGlyphMap.count());
SkDebugf("%s\n", msg.c_str());
}
示例13: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
SkScalar angle = SampleCode::GetAnimScalar(SkIntToScalar(180),
SkIntToScalar(360));
SkMatrix saveM = *fMatrixRefs[3];
SkScalar c = SkIntToScalar(50);
fMatrixRefs[3]->preRotate(angle, c, c);
const SkScalar dx = 350;
const SkScalar dy = 500;
const int N = 1;
for (int v = -N; v <= N; v++) {
for (int h = -N; h <= N; h++) {
SkAutoCanvasRestore acr(canvas, true);
canvas->translate(h * dx, v * dy);
SkMatrix matrix;
SkGroupShape* gs = new SkGroupShape;
SkAutoUnref aur(gs);
gs->appendShape(&fGroup);
matrix.setScale(-SK_Scalar1, SK_Scalar1);
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
gs->appendShape(&fGroup, matrix);
matrix.setTranslate(SkIntToScalar(240), 0);
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 1
SkPicture* pict = new SkPicture;
SkCanvas* cv = pict->beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
gs->draw(cv);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
gs->draw(cv);
pict->endRecording();
drawpicture(canvas, *pict);
pict->unref();
#endif
}}
*fMatrixRefs[3] = saveM;
this->inval(NULL);
}
示例14: dump
void SkGlyphCache::dump() const {
const SkTypeface* face = fScalerContext->getTypeface();
const SkScalerContextRec& rec = fScalerContext->getRec();
SkMatrix matrix;
rec.getSingleMatrix(&matrix);
matrix.preScale(SkScalarInvert(rec.fTextSize), SkScalarInvert(rec.fTextSize));
SkString name;
face->getFamilyName(&name);
SkString msg;
msg.printf("cache typeface:%x %25s:%d size:%2g [%g %g %g %g] lum:%02X devG:%d pntG:%d cntr:%d glyphs:%3d",
face->uniqueID(), name.c_str(), face->style(), rec.fTextSize,
matrix[SkMatrix::kMScaleX], matrix[SkMatrix::kMSkewX],
matrix[SkMatrix::kMSkewY], matrix[SkMatrix::kMScaleY],
rec.fLumBits & 0xFF, rec.fDeviceGamma, rec.fPaintGamma, rec.fContrast,
fGlyphMap.count());
SkDebugf("%s\n", msg.c_str());
}
示例15: updatePositions
void LayerAndroid::updatePositions() {
// apply the viewport to us
SkMatrix matrix;
if (!m_isFixed) {
// turn our fields into a matrix.
//
// TODO: this should happen in the caller, and we should remove these
// fields from our subclass
matrix.setTranslate(m_translation.fX, m_translation.fY);
if (m_doRotation) {
matrix.preRotate(m_angleTransform);
}
matrix.preScale(m_scale.fX, m_scale.fY);
this->setMatrix(matrix);
}
// now apply it to our children
int count = this->countChildren();
for (int i = 0; i < count; i++) {
this->getChild(i)->updatePositions();
}
}