本文整理汇总了C++中SkMatrix::setRectToRect方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::setRectToRect方法的具体用法?C++ SkMatrix::setRectToRect怎么用?C++ SkMatrix::setRectToRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::setRectToRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_matrix_recttorect
static void test_matrix_recttorect(skiatest::Reporter* reporter) {
SkRect src, dst;
SkMatrix matrix;
src.set(0, 0, SK_Scalar1*10, SK_Scalar1*10);
dst = src;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
REPORTER_ASSERT(reporter, SkMatrix::kIdentity_Mask == matrix.getType());
REPORTER_ASSERT(reporter, matrix.rectStaysRect());
dst.offset(SK_Scalar1, SK_Scalar1);
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
REPORTER_ASSERT(reporter, SkMatrix::kTranslate_Mask == matrix.getType());
REPORTER_ASSERT(reporter, matrix.rectStaysRect());
dst.fRight += SK_Scalar1;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
REPORTER_ASSERT(reporter,
(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask) == matrix.getType());
REPORTER_ASSERT(reporter, matrix.rectStaysRect());
dst = src;
dst.fRight = src.fRight * 2;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
REPORTER_ASSERT(reporter, SkMatrix::kScale_Mask == matrix.getType());
REPORTER_ASSERT(reporter, matrix.rectStaysRect());
}
示例2: drawResampledBitmap
// This does a lot of computation to resample only the portion of the bitmap
// that will only be drawn. This is critical for performance since when we are
// scrolling, for example, we are only drawing a small strip of the image.
// Resampling the whole image every time is very slow, so this speeds up things
// dramatically.
//
// Note: this code is only used when the canvas transformation is limited to
// scaling or translation.
static void drawResampledBitmap(SkCanvas& canvas, SkPaint& paint, const NativeImageSkia& bitmap, const SkRect& srcRect, const SkRect& destRect)
{
#if PLATFORM(CHROMIUM)
TRACE_EVENT0("skia", "drawResampledBitmap");
#endif
// We want to scale |destRect| with transformation in the canvas to obtain
// the final scale. The final scale is a combination of scale transform
// in canvas and explicit scaling (srcRect and destRect).
SkRect screenRect;
canvas.getTotalMatrix().mapRect(&screenRect, destRect);
float realScaleX = screenRect.width() / srcRect.width();
float realScaleY = screenRect.height() / srcRect.height();
// This part of code limits scaling only to visible portion in the
SkRect destRectVisibleSubset;
ClipRectToCanvas(canvas, destRect, &destRectVisibleSubset);
// ClipRectToCanvas often overshoots, resulting in a larger region than our
// original destRect. Intersecting gets us back inside.
if (!destRectVisibleSubset.intersect(destRect))
return; // Nothing visible in destRect.
// Find the corresponding rect in the source image.
SkMatrix destToSrcTransform;
SkRect srcRectVisibleSubset;
destToSrcTransform.setRectToRect(destRect, srcRect, SkMatrix::kFill_ScaleToFit);
destToSrcTransform.mapRect(&srcRectVisibleSubset, destRectVisibleSubset);
SkRect scaledSrcRect;
SkIRect enclosingScaledSrcRect;
SkBitmap scaledImageFragment = extractScaledImageFragment(bitmap, srcRectVisibleSubset, realScaleX, realScaleY, &scaledSrcRect, &enclosingScaledSrcRect);
// Expand the destination rectangle because the source rectangle was
// expanded to fit to integer boundaries.
SkMatrix scaledSrcToDestTransform;
scaledSrcToDestTransform.setRectToRect(scaledSrcRect, destRectVisibleSubset, SkMatrix::kFill_ScaleToFit);
SkRect enclosingDestRect;
enclosingDestRect.set(enclosingScaledSrcRect);
scaledSrcToDestTransform.mapRect(&enclosingDestRect);
// The reason we do clipping is because Skia doesn't support SkRect as
// source rect. See http://crbug.com/145540.
// When Skia supports then use this as the source rect to replace 0.
//
// scaledSrcRect.offset(-enclosingScaledSrcRect.x(), -enclosingScaledSrcRect.y());
canvas.save();
canvas.clipRect(destRectVisibleSubset);
// Because the image fragment is generated with an approxmiated scaling
// factor. This draw will perform a close to 1 scaling.
//
// NOTE: For future optimization. If the difference in scale is so small
// that Skia doesn't produce a difference then we can just blit it directly
// to enhance performance.
canvas.drawBitmapRect(scaledImageFragment, 0, enclosingDestRect, &paint);
canvas.restore();
}
示例3: drawTextureProducer
void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer,
const SkRect* srcRect,
const SkRect* dstRect,
SkCanvas::SrcRectConstraint constraint,
const SkMatrix& viewMatrix,
const GrClip& clip,
const SkPaint& paint) {
// This is the funnel for all non-tiled bitmap/image draw calls. Log a histogram entry.
SK_HISTOGRAM_BOOLEAN("DrawTiled", false);
// Figure out the actual dst and src rect by clipping the src rect to the bounds of the
// adjuster. If the src rect is clipped then the dst rect must be recomputed. Also determine
// the matrix that maps the src rect to the dst rect.
SkRect clippedSrcRect;
SkRect clippedDstRect;
const SkRect srcBounds = SkRect::MakeIWH(producer->width(), producer->height());
SkMatrix srcToDstMatrix;
if (srcRect) {
if (!dstRect) {
dstRect = &srcBounds;
}
if (!srcBounds.contains(*srcRect)) {
clippedSrcRect = *srcRect;
if (!clippedSrcRect.intersect(srcBounds)) {
return;
}
if (!srcToDstMatrix.setRectToRect(*srcRect, *dstRect, SkMatrix::kFill_ScaleToFit)) {
return;
}
srcToDstMatrix.mapRect(&clippedDstRect, clippedSrcRect);
} else {
clippedSrcRect = *srcRect;
clippedDstRect = *dstRect;
if (!srcToDstMatrix.setRectToRect(*srcRect, *dstRect, SkMatrix::kFill_ScaleToFit)) {
return;
}
}
} else {
clippedSrcRect = srcBounds;
if (dstRect) {
clippedDstRect = *dstRect;
if (!srcToDstMatrix.setRectToRect(srcBounds, *dstRect, SkMatrix::kFill_ScaleToFit)) {
return;
}
} else {
clippedDstRect = srcBounds;
srcToDstMatrix.reset();
}
}
// Now that we have both the view and srcToDst matrices, log our scale factor.
LogDrawScaleFactor(SkMatrix::Concat(viewMatrix, srcToDstMatrix), paint.getFilterQuality());
this->drawTextureProducerImpl(producer, clippedSrcRect, clippedDstRect, constraint, viewMatrix,
srcToDstMatrix, clip, paint);
}
示例4: drawResampledBitmap
// This does a lot of computation to resample only the portion of the bitmap
// that will only be drawn. This is critical for performance since when we are
// scrolling, for example, we are only drawing a small strip of the image.
// Resampling the whole image every time is very slow, so this speeds up things
// dramatically.
//
// Note: this code is only used when the canvas transformation is limited to
// scaling or translation.
void NativeImageSkia::drawResampledBitmap(GraphicsContext* context, SkPaint& paint, const SkRect& srcRect, const SkRect& destRect) const
{
TRACE_EVENT0("skia", "drawResampledBitmap");
// We want to scale |destRect| with transformation in the canvas to obtain
// the final scale. The final scale is a combination of scale transform
// in canvas and explicit scaling (srcRect and destRect).
SkRect screenRect;
context->getTotalMatrix().mapRect(&screenRect, destRect);
float realScaleX = screenRect.width() / srcRect.width();
float realScaleY = screenRect.height() / srcRect.height();
// This part of code limits scaling only to visible portion in the
SkRect destRectVisibleSubset;
if (!context->canvas()->getClipBounds(&destRectVisibleSubset))
return;
// ClipRectToCanvas often overshoots, resulting in a larger region than our
// original destRect. Intersecting gets us back inside.
if (!destRectVisibleSubset.intersect(destRect))
return; // Nothing visible in destRect.
// Find the corresponding rect in the source image.
SkMatrix destToSrcTransform;
SkRect srcRectVisibleSubset;
destToSrcTransform.setRectToRect(destRect, srcRect, SkMatrix::kFill_ScaleToFit);
destToSrcTransform.mapRect(&srcRectVisibleSubset, destRectVisibleSubset);
SkRect scaledSrcRect;
SkBitmap scaledImageFragment = extractScaledImageFragment(srcRectVisibleSubset, realScaleX, realScaleY, &scaledSrcRect);
context->drawBitmapRect(scaledImageFragment, &scaledSrcRect, destRectVisibleSubset, &paint);
}
示例5: extractScaledImageFragment
// This function is used to scale an image and extract a scaled fragment.
//
// ALGORITHM
//
// Because the scaled image size has to be integers, we approximate the real
// scale with the following formula (only X direction is shown):
//
// scaledImageWidth = round(scaleX * imageRect.width())
// approximateScaleX = scaledImageWidth / imageRect.width()
//
// With this method we maintain a constant scale factor among fragments in
// the scaled image. This allows fragments to stitch together to form the
// full scaled image. The downside is there will be a small difference
// between |scaleX| and |approximateScaleX|.
//
// A scaled image fragment is identified by:
//
// - Scaled image size
// - Scaled image fragment rectangle (IntRect)
//
// Scaled image size has been determined and the next step is to compute the
// rectangle for the scaled image fragment which needs to be an IntRect.
//
// scaledSrcRect = srcRect * (approximateScaleX, approximateScaleY)
// enclosingScaledSrcRect = enclosingIntRect(scaledSrcRect)
//
// Finally we extract the scaled image fragment using
// (scaledImageSize, enclosingScaledSrcRect).
//
SkBitmap NativeImageSkia::extractScaledImageFragment(const SkRect& srcRect, float scaleX, float scaleY, SkRect* scaledSrcRect) const
{
SkISize imageSize = SkISize::Make(bitmap().width(), bitmap().height());
SkISize scaledImageSize = SkISize::Make(clampToInteger(roundf(imageSize.width() * scaleX)),
clampToInteger(roundf(imageSize.height() * scaleY)));
SkRect imageRect = SkRect::MakeWH(imageSize.width(), imageSize.height());
SkRect scaledImageRect = SkRect::MakeWH(scaledImageSize.width(), scaledImageSize.height());
SkMatrix scaleTransform;
scaleTransform.setRectToRect(imageRect, scaledImageRect, SkMatrix::kFill_ScaleToFit);
scaleTransform.mapRect(scaledSrcRect, srcRect);
bool ok = scaledSrcRect->intersect(scaledImageRect);
ASSERT_UNUSED(ok, ok);
SkIRect enclosingScaledSrcRect = enclosingIntRect(*scaledSrcRect);
// |enclosingScaledSrcRect| can be larger than |scaledImageSize| because
// of float inaccuracy so clip to get inside.
ok = enclosingScaledSrcRect.intersect(SkIRect::MakeSize(scaledImageSize));
ASSERT_UNUSED(ok, ok);
// scaledSrcRect is relative to the pixel snapped fragment we're extracting.
scaledSrcRect->offset(-enclosingScaledSrcRect.x(), -enclosingScaledSrcRect.y());
return resizedBitmap(scaledImageSize, enclosingScaledSrcRect);
}
示例6: CameraView
CameraView() {
fRX = fRY = fRZ = 0;
fShaderIndex = 0;
fFrontFace = false;
for (int i = 0;; i++) {
SkString str;
str.printf("/skimages/elephant%d.jpeg", i);
SkBitmap bm;
if (SkImageDecoder::DecodeFile(str.c_str(), &bm)) {
SkShader* s = SkShader::CreateBitmapShader(bm,
SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode);
SkRect src = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) };
SkRect dst = { -150, -150, 150, 150 };
SkMatrix matrix;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
s->setLocalMatrix(matrix);
*fShaders.append() = s;
} else {
break;
}
}
this->setBGColor(0xFFDDDDDD);
}
示例7: SkImagePrivDrawPicture
void SkImagePrivDrawPicture(SkCanvas* canvas, SkPicture* picture,
const SkRect* src, const SkRect& dst, const SkPaint* paint) {
int saveCount = canvas->getSaveCount();
SkMatrix matrix;
SkRect tmpSrc;
if (NULL != src) {
tmpSrc = *src;
} else {
tmpSrc.set(0, 0,
SkIntToScalar(picture->width()),
SkIntToScalar(picture->height()));
}
matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
if (paint && needs_layer(*paint)) {
canvas->saveLayer(&dst, paint);
} else {
canvas->save();
}
canvas->concat(matrix);
if (!paint || !needs_layer(*paint)) {
canvas->clipRect(tmpSrc);
}
canvas->drawPicture(*picture);
canvas->restoreToCount(saveCount);
}
示例8: paint
void
DrawTargetSkia::DrawSurface(SourceSurface *aSurface,
const Rect &aDest,
const Rect &aSource,
const DrawSurfaceOptions &aSurfOptions,
const DrawOptions &aOptions)
{
if (aSurface->GetType() != SURFACE_SKIA) {
return;
}
if (aSource.IsEmpty()) {
return;
}
MarkChanged();
SkRect destRect = RectToSkRect(aDest);
SkRect sourceRect = RectToSkRect(aSource);
SkMatrix matrix;
matrix.setRectToRect(sourceRect, destRect, SkMatrix::kFill_ScaleToFit);
const SkBitmap& bitmap = static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap();
AutoPaintSetup paint(mCanvas.get(), aOptions);
SkShader *shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
shader->setLocalMatrix(matrix);
SkSafeUnref(paint.mPaint.setShader(shader));
if (aSurfOptions.mFilter != FILTER_LINEAR) {
paint.mPaint.setFilterBitmap(false);
}
mCanvas->drawRect(destRect, paint.mPaint);
}
示例9: oval_contains
static bool oval_contains(const SkRect& r, SkScalar x, SkScalar y) {
SkMatrix m;
m.setRectToRect(r, gUnitSquare, SkMatrix::kFill_ScaleToFit);
SkPoint pt;
m.mapXY(x, y, &pt);
return pt.lengthSqd() <= 1;
}
示例10: test_huge_stroke
static void test_huge_stroke(SkCanvas* canvas) {
SkRect srcR = { 0, 0, 72000, 54000 };
SkRect dstR = { 0, 0, 640, 480 };
SkPath path;
path.moveTo(17600, 8000);
path.lineTo(52800, 8000);
path.lineTo(52800, 41600);
path.lineTo(17600, 41600);
path.close();
SkPaint paint;
paint.setAntiAlias(true);
paint.setStrokeWidth(8000);
paint.setStrokeMiter(10);
paint.setStrokeCap(SkPaint::kButt_Cap);
paint.setStrokeJoin(SkPaint::kRound_Join);
paint.setStyle(SkPaint::kStroke_Style);
SkMatrix matrix;
matrix.setRectToRect(srcR, dstR, SkMatrix::kCenter_ScaleToFit);
canvas->concat(matrix);
canvas->drawPath(path, paint);
}
示例11: updateScreen
/**
* Method which handles native redrawing screen
*/
void JNISDLVideoDriverListener::updateScreen(SkBitmap* bitmap)
{
SkBitmap screen;
Surface::SurfaceInfo surfaceInfo;
if (!mSurface || !mSurface->isValid()) {
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "nativeSurface wasn't valid");
return;
}
if (mSurface->lock(&surfaceInfo) < 0) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to lock surface");
return;
}
//__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "updating screen: %ix%i", surfaceInfo.w, surfaceInfo.h);
//bitmap which is drawed on android surfaceview
SDLVideoDriver::setBitmapConfig(&screen, surfaceInfo.format, surfaceInfo.w, surfaceInfo.h);
screen.setPixels(surfaceInfo.bits);
SkCanvas canvas(screen);
SkRect surface_sdl;
SkRect surface_android;
SkMatrix matrix;
surface_android.set(0, 0, screen.width(), screen.height());
surface_sdl.set(0, 0, bitmap->width(), bitmap->height());
matrix.setRectToRect(surface_sdl, surface_android, SkMatrix::kFill_ScaleToFit);
canvas.drawBitmapMatrix(*bitmap, matrix);
if (mSurface->unlockAndPost() < 0) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to unlock surface");
}
}
示例12: SkHitTestPath
bool SkHitTestPath(const SkPath& path, SkRect& target, bool hires) {
if (target.isEmpty()) {
return false;
}
bool isInverse = path.isInverseFillType();
if (path.isEmpty()) {
return isInverse;
}
SkRect bounds = path.getBounds();
bool sects = SkRect::Intersects(target, bounds);
if (isInverse) {
if (!sects) {
return true;
}
} else {
if (!sects) {
return false;
}
if (target.contains(bounds)) {
return true;
}
}
SkPath devPath;
const SkPath* pathPtr;
SkRect devTarget;
if (hires) {
const SkScalar coordLimit = SkIntToScalar(16384);
const SkRect limit = { 0, 0, coordLimit, coordLimit };
SkMatrix matrix;
matrix.setRectToRect(bounds, limit, SkMatrix::kFill_ScaleToFit);
path.transform(matrix, &devPath);
matrix.mapRect(&devTarget, target);
pathPtr = &devPath;
} else {
devTarget = target;
pathPtr = &path;
}
SkIRect iTarget;
devTarget.round(&iTarget);
if (iTarget.isEmpty()) {
iTarget.fLeft = SkScalarFloorToInt(devTarget.fLeft);
iTarget.fTop = SkScalarFloorToInt(devTarget.fTop);
iTarget.fRight = iTarget.fLeft + 1;
iTarget.fBottom = iTarget.fTop + 1;
}
SkRegion clip(iTarget);
SkRegion rgn;
return rgn.setPath(*pathPtr, clip) ^ isInverse;
}
示例13: setRectToRect
static jboolean setRectToRect(JNIEnv* env, jobject clazz, jlong matrixHandle, jobject src, jobject dst, jint stfHandle) {
SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
SkMatrix::ScaleToFit stf = static_cast<SkMatrix::ScaleToFit>(stfHandle);
SkRect src_;
GraphicsJNI::jrectf_to_rect(env, src, &src_);
SkRect dst_;
GraphicsJNI::jrectf_to_rect(env, dst, &dst_);
return matrix->setRectToRect(src_, dst_, stf) ? JNI_TRUE : JNI_FALSE;
}
示例14: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkRect dst = SkRect::MakeWH(canvas->getDevice()->width(), canvas->getDevice()->height());
SkRect src = SkRect::MakeWH(640, 480);
SkMatrix matrix;
matrix.setRectToRect(src, dst, SkMatrix::kCenter_ScaleToFit);
canvas->concat(matrix);
fProc(canvas, fShowGL, fFlags);
}
示例15: Make
std::unique_ptr<GrDrawOp> MakeAAFillWithLocalRect(GrPaint&& paint, const SkMatrix& viewMatrix,
const SkRect& rect, const SkRect& localRect) {
if (!view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
return nullptr;
}
SkRect devRect;
viewMatrix.mapRect(&devRect, rect);
SkMatrix localMatrix;
if (!localMatrix.setRectToRect(rect, localRect, SkMatrix::kFill_ScaleToFit)) {
return nullptr;
}
return AAFillRectOp::Make(std::move(paint), viewMatrix, rect, devRect, &localMatrix, nullptr);
}