本文整理汇总了C++中SkMatrix::mapPoints方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::mapPoints方法的具体用法?C++ SkMatrix::mapPoints怎么用?C++ SkMatrix::mapPoints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::mapPoints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawTriangle
void FatBits::drawTriangle(SkCanvas* canvas, SkPoint pts[3]) {
SkPaint paint;
fInverse.mapPoints(pts, 3);
if (fGrid) {
apply_grid(pts, 3);
}
SkPath path;
path.moveTo(pts[0]);
path.lineTo(pts[1]);
path.lineTo(pts[2]);
path.close();
erase(fMinSurface);
this->setupPaint(&paint);
paint.setColor(FAT_PIXEL_COLOR);
fMinSurface->getCanvas()->drawPath(path, paint);
this->copyMinToMax();
SkCanvas* max = fMaxSurface->getCanvas();
fMatrix.mapPoints(pts, 3);
this->drawTriangleSkeleton(max, pts);
fMaxSurface->draw(canvas, 0, 0, NULL);
}
示例2: drawLine
void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) {
SkPaint paint;
fInverse.mapPoints(pts, 2);
if (fGrid) {
apply_grid(pts, 2);
}
erase(fMinSurface);
this->setupPaint(&paint);
paint.setColor(FAT_PIXEL_COLOR);
if (fUseClip) {
fMinSurface->getCanvas()->save();
SkRect r = fClipRect;
r.inset(SK_Scalar1/3, SK_Scalar1/3);
fMinSurface->getCanvas()->clipRect(r, SkRegion::kIntersect_Op, true);
}
fMinSurface->getCanvas()->drawLine(pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, paint);
if (fUseClip) {
fMinSurface->getCanvas()->restore();
}
this->copyMinToMax();
SkCanvas* max = fMaxSurface->getCanvas();
fMatrix.mapPoints(pts, 2);
this->drawLineSkeleton(max, pts);
fMaxSurface->draw(canvas, 0, 0, NULL);
}
示例3: drawRect
void FatBits::drawRect(SkCanvas* canvas, SkPoint pts[2]) {
SkPaint paint;
fInverse.mapPoints(pts, 2);
if (fGrid) {
apply_grid(pts, 2);
}
SkRect r;
r.set(pts, 2);
erase(fMinSurface);
this->setupPaint(&paint);
paint.setColor(FAT_PIXEL_COLOR);
{
SkCanvas* c = fMinSurface->getCanvas();
fRectAsOval ? c->drawOval(r, paint) : c->drawRect(r, paint);
}
this->copyMinToMax();
SkCanvas* max = fMaxSurface->getCanvas();
fMatrix.mapPoints(pts, 2);
r.set(pts, 2);
this->drawRectSkeleton(max, r);
fMaxSurface->draw(canvas, 0, 0, NULL);
}
示例4: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkMatrix m;
m.reset();
m.setRotate(33 * SK_Scalar1);
m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1);
m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1);
canvas->concat(m);
SkPaint paint;
paint.setColor(SK_ColorRED);
paint.setAntiAlias(true);
bool success = m.invert(&m);
SkASSERT(success);
(void) success; // silence compiler :(
SkPath path;
SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
SkScalar small = 1 / (500 * SK_Scalar1);
m.mapPoints(&pt, 1);
path.addCircle(pt.fX, pt.fY, small);
canvas->drawPath(path, paint);
pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
m.mapPoints(&pt, 1);
SkRect rect = {pt.fX - small, pt.fY - small,
pt.fX + small, pt.fY + small};
canvas->drawRect(rect, paint);
SkBitmap bmp;
bmp.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
bmp.allocPixels();
bmp.lockPixels();
uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
bmp.unlockPixels();
pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
m.mapPoints(&pt, 1);
SkShader* shader = SkShader::CreateBitmapShader(
bmp,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode);
SkMatrix s;
s.reset();
s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
shader->setLocalMatrix(s);
paint.setShader(shader)->unref();
paint.setAntiAlias(false);
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
rect.setLTRB(pt.fX - small, pt.fY - small,
pt.fX + small, pt.fY + small);
canvas->drawRect(rect, paint);
}
示例5: NativeMapPoints
void Matrix::NativeMapPoints(
/* [in] */ Int64 matrixHandle,
/* [out] */ ArrayOf<Float>* dst,
/* [in] */ Int32 dstIndex,
/* [in] */ ArrayOf<Float>* src,
/* [in] */ Int32 srcIndex,
/* [in] */ Int32 ptCount,
/* [in] */ Boolean isPts)
{
SkASSERT(ptCount >= 0);
SkASSERT(src->GetLength() >= srcIndex + (ptCount << 1));
SkASSERT(dst->GetLength() >= dstIndex + (ptCount << 1));
SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
// AutoJavaFloatArray autoSrc(env, src, srcIndex + (ptCount << 1), kRO_JNIAccess);
// AutoJavaFloatArray autoDst(env, dst, dstIndex + (ptCount << 1), kRW_JNIAccess);
Float* srcArray = src->GetPayload() + srcIndex;
Float* dstArray = dst->GetPayload() + dstIndex;
#ifdef SK_SCALAR_IS_FLOAT
if (isPts)
matrix->mapPoints((SkPoint*)dstArray, (const SkPoint*)srcArray,
ptCount);
else
matrix->mapVectors((SkVector*)dstArray, (const SkVector*)srcArray,
ptCount);
#else
SkASSERT(FALSE);
#endif
}
示例6: GiantDashBench
GiantDashBench(LineType lt, SkScalar width) {
fName.printf("giantdashline_%s_%g", LineTypeName(lt), width);
fStrokeWidth = width;
// deliberately pick intervals that won't be caught by asPoints(), so
// we can test the filterPath code-path.
const SkScalar intervals[] = { 20, 10, 10, 10 };
fPathEffect.reset(SkDashPathEffect::Create(intervals,
SK_ARRAY_COUNT(intervals), 0));
SkScalar cx = 640 / 2; // center X
SkScalar cy = 480 / 2; // center Y
SkMatrix matrix;
switch (lt) {
case kHori_LineType:
matrix.setIdentity();
break;
case kVert_LineType:
matrix.setRotate(90, cx, cy);
break;
case kDiag_LineType:
matrix.setRotate(45, cx, cy);
break;
case kLineTypeCount:
// Not a real enum value.
break;
}
const SkScalar overshoot = 100*1000;
const SkPoint pts[2] = {
{ -overshoot, cy }, { 640 + overshoot, cy }
};
matrix.mapPoints(fPts, pts, 2);
}
示例7: make_strip
static void make_strip(Rec* rec, int texWidth, int texHeight) {
const SkScalar tx = SkIntToScalar(texWidth);
const SkScalar ty = SkIntToScalar(texHeight);
const int n = 24;
rec->fMode = SkCanvas::kTriangleStrip_VertexMode;
rec->fCount = 2 * (n + 1);
rec->fVerts = new SkPoint[rec->fCount];
rec->fTexs = new SkPoint[rec->fCount];
SkPoint* v = rec->fVerts;
SkPoint* t = rec->fTexs;
for (int i = 0; i < n; i++) {
SkScalar cos;
SkScalar sin = SkScalarSinCos(SK_ScalarPI * 2 * i / n, &cos);
v[i*2 + 0].set(cos/2, sin/2);
v[i*2 + 1].set(cos, sin);
t[i*2 + 0].set(tx * i / n, ty);
t[i*2 + 1].set(tx * i / n, 0);
}
v[2*n + 0] = v[0];
v[2*n + 1] = v[1];
t[2*n + 0].set(tx, ty);
t[2*n + 1].set(tx, 0);
SkMatrix m;
m.setScale(SkIntToScalar(100), SkIntToScalar(100));
m.postTranslate(SkIntToScalar(110), SkIntToScalar(110));
m.mapPoints(v, rec->fCount);
}
示例8: onClick
virtual bool onClick(Click* click) {
SkPoint pts[2] = { click->fOrig, click->fCurr };
fInverse.mapPoints(pts, 2);
this->warp(pts[0], pts[1]);
this->inval(NULL);
return true;
}
示例9: just_trans_clamp
/**
* For the purposes of drawing bitmaps, if a matrix is "almost" translate
* go ahead and treat it as if it were, so that subsequent code can go fast.
*/
static bool just_trans_clamp(const SkMatrix& matrix, const SkBitmap& bitmap) {
SkASSERT(matrix_only_scale_translate(matrix));
if (matrix.getType() & SkMatrix::kScale_Mask) {
SkRect src, dst;
bitmap.getBounds(&src);
// Can't call mapRect(), since that will fix up inverted rectangles,
// e.g. when scale is negative, and we don't want to return true for
// those.
matrix.mapPoints(SkTCast<SkPoint*>(&dst),
SkTCast<const SkPoint*>(&src),
2);
// Now round all 4 edges to device space, and then compare the device
// width/height to the original. Note: we must map all 4 and subtract
// rather than map the "width" and compare, since we care about the
// phase (in pixel space) that any translate in the matrix might impart.
SkIRect idst;
dst.round(&idst);
return idst.width() == bitmap.width() && idst.height() == bitmap.height();
}
// if we got here, we're either kTranslate_Mask or identity
return true;
}
示例10: 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;
}
示例11: flush
void GrStencilAndCoverTextContext::flush() {
if (fQueuedGlyphCount > 0) {
SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor(),
fViewMatrix,
fLocalMatrix));
// We should only be flushing about once every run. However, if this impacts performance
// we could move the creation of the GrPipelineBuilder earlier.
GrPipelineBuilder pipelineBuilder(fPaint, fRenderTarget, fClip);
SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiAlias());
pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fPaint.isAntiAlias());
GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
kZero_StencilOp,
kZero_StencilOp,
kNotEqual_StencilFunc,
0xffff,
0x0000,
0xffff);
*pipelineBuilder.stencil() = kStencilPass;
SkASSERT(0 == fQueuedGlyphCount);
SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx);
fDrawContext->drawPaths(&pipelineBuilder, pp, fGlyphs,
fGlyphIndices, GrPathRange::kU16_PathIndexType,
get_xy_scalar_array(fGlyphPositions),
GrPathRendering::kTranslate_PathTransformType,
fQueuedGlyphCount, GrPathRendering::kWinding_FillType);
fQueuedGlyphCount = 0;
}
if (fFallbackGlyphsIdx < kGlyphBufferSize) {
int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx;
GrPaint paintFallback(fPaint);
SkPaint skPaintFallback(fSkPaint);
if (!fUsingDeviceSpaceGlyphs) {
fStroke.applyToPaint(&skPaintFallback);
}
skPaintFallback.setTextAlign(SkPaint::kLeft_Align); // Align has already been accounted for.
skPaintFallback.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
SkMatrix inverse;
if (this->mapToFallbackContext(&inverse)) {
inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyphCount);
}
fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, skPaintFallback,
fViewMatrix, (char*)&fGlyphIndices[fFallbackGlyphsIdx],
2 * fallbackGlyphCount,
get_xy_scalar_array(&fGlyphPositions[fFallbackGlyphsIdx]),
2, SkPoint::Make(0, 0), fRegionClipBounds);
fFallbackGlyphsIdx = kGlyphBufferSize;
}
}
示例12: make_fan
void make_fan(Rec* rec, int texWidth, int texHeight) {
const SkScalar tx = SkIntToScalar(texWidth);
const SkScalar ty = SkIntToScalar(texHeight);
const int n = 24;
rec->fMode = SkCanvas::kTriangleFan_VertexMode;
rec->fCount = n + 2;
rec->fVerts = new SkPoint[rec->fCount];
rec->fTexs = new SkPoint[rec->fCount];
SkPoint* v = rec->fVerts;
SkPoint* t = rec->fTexs;
v[0].set(0, 0);
t[0].set(0, 0);
for (int i = 0; i < n; i++) {
SkScalar cos;
SkScalar sin = SkScalarSinCos(SK_ScalarPI * 2 * i / n, &cos);
v[i+1].set(cos, sin);
t[i+1].set(i*tx/n, ty);
}
v[n+1] = v[1];
t[n+1].set(tx, ty);
SkMatrix m;
m.setScale(SkIntToScalar(100), SkIntToScalar(100));
m.postTranslate(SkIntToScalar(110), SkIntToScalar(110));
m.mapPoints(v, rec->fCount);
}
示例13: convertToLocal
SkPoint View::convertToLocal(SkPoint point, View* reference)
{
SkMatrix m;
if (currentTransformMatrix(reference).invert(&m)) {
m.mapPoints(&point, 1);
}
return point;
}
示例14: hittest
int hittest(SkScalar x, SkScalar y) {
SkPoint target = { x, y };
SkPoint pts[2] = { fPts[1], fPts[2] };
fMatrix.mapPoints(pts, 2);
for (int i = 0; i < 2; i++) {
if (SkPoint::Distance(pts[i], target) < SkIntToScalar(4)) {
return i + 1;
}
}
return -1;
}
示例15: isPointSkiaSafe
static bool isPointSkiaSafe(const SkMatrix& transform, const SkPoint& pt)
{
#ifdef ENSURE_VALUE_SAFETY_FOR_SKIA
// Now check for points that will overflow. We check the *transformed*
// points since this is what will be rasterized.
SkPoint xPt;
transform.mapPoints(&xPt, &pt, 1);
return isCoordinateSkiaSafe(xPt.fX) && isCoordinateSkiaSafe(xPt.fY);
#else
return true;
#endif
}