本文整理汇总了C++中SkRect::round方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::round方法的具体用法?C++ SkRect::round怎么用?C++ SkRect::round使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::round方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: subtractLayers
SkRect LayerAndroid::subtractLayers(const SkRect& visibleRect) const
{
SkRect result;
if (m_recordingPicture) {
SkRect globalRect = bounds();
globalRect.offset(-getPosition()); // localToGlobal adds in position
SkMatrix globalMatrix;
localToGlobal(&globalMatrix);
globalMatrix.mapRect(&globalRect);
SkIRect roundedGlobal;
globalRect.round(&roundedGlobal);
SkIRect iVisibleRect;
visibleRect.round(&iVisibleRect);
SkRegion visRegion(iVisibleRect);
visRegion.op(roundedGlobal, SkRegion::kDifference_Op);
result.set(visRegion.getBounds());
#if DEBUG_NAV_UI
SkDebugf("%s visibleRect=(%g,%g,r=%g,b=%g) globalRect=(%g,%g,r=%g,b=%g)"
"result=(%g,%g,r=%g,b=%g)", __FUNCTION__,
visibleRect.fLeft, visibleRect.fTop,
visibleRect.fRight, visibleRect.fBottom,
globalRect.fLeft, globalRect.fTop,
globalRect.fRight, globalRect.fBottom,
result.fLeft, result.fTop, result.fRight, result.fBottom);
#endif
} else
result = visibleRect;
for (int i = 0; i < countChildren(); i++)
result = getChild(i)->subtractLayers(result);
return result;
}
示例2: FillRect
void SkScan::FillRect(const SkRect& r, const SkRegion* clip,
SkBlitter* blitter) {
SkIRect ir;
r.round(&ir);
SkScan::FillIRect(ir, clip, blitter);
}
示例3: canvas
static void test_cubic2() {
const char* str = "M2242 -590088L-377758 9.94099e+07L-377758 9.94099e+07L2242 -590088Z";
SkPath path;
SkParsePath::FromSVGString(str, &path);
{
#ifdef SK_BUILD_FOR_WIN
// windows doesn't have strtof
float x = (float)strtod("9.94099e+07", NULL);
#else
float x = strtof("9.94099e+07", NULL);
#endif
int ix = (int)x;
int fx = (int)(x * 65536);
int ffx = SkScalarToFixed(x);
printf("%g %x %x %x\n", x, ix, fx, ffx);
SkRect r = path.getBounds();
SkIRect ir;
r.round(&ir);
printf("[%g %g %g %g] [%x %x %x %x]\n",
SkScalarToDouble(r.fLeft), SkScalarToDouble(r.fTop),
SkScalarToDouble(r.fRight), SkScalarToDouble(r.fBottom),
ir.fLeft, ir.fTop, ir.fRight, ir.fBottom);
}
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 300, 200);
bitmap.allocPixels();
SkCanvas canvas(bitmap);
SkPaint paint;
paint.setAntiAlias(true);
canvas.drawPath(path, paint);
}
示例4: 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 SkPixmap& pixmap) {
SkASSERT(matrix_only_scale_translate(matrix));
if (matrix.getType() & SkMatrix::kScale_Mask) {
SkRect dst;
SkRect src = SkRect::Make(pixmap.bounds());
// 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() == pixmap.width() && idst.height() == pixmap.height();
}
// if we got here, we're either kTranslate_Mask or identity
return true;
}
示例5: 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;
}
示例6: inval
void SkPageFlipper::inval(const SkRect& rect, bool antialias) {
SkIRect r;
rect.round(&r);
if (antialias) {
r.inset(-1, -1);
}
this->inval(r);
}
示例7: getClipBounds
static bool getClipBounds(JNIEnv* env, jobject, SkCanvas* canvas,
jobject bounds) {
SkRect r;
SkIRect ir;
bool result = canvas->getClipBounds(&r, SkCanvas::kBW_EdgeType);
r.round(&ir);
(void)GraphicsJNI::irect_to_jrect(ir, env, bounds);
return result;
}
示例8: drawResampledBitmap
// Draws the given bitmap to the given canvas. The subset of the source bitmap
// identified by src_rect is drawn to the given destination rect. The bitmap
// will be resampled to resample_width * resample_height (this is the size of
// the whole image, not the subset). See shouldResampleBitmap for more.
//
// 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 SkIRect& srcIRect, const SkRect& destRect)
{
#if PLATFORM(CHROMIUM)
TRACE_EVENT("drawResampledBitmap", &canvas, 0);
#endif
// Apply forward transform to destRect to estimate required size of
// re-sampled bitmap, and use only in calls required to resize, or that
// check for the required size.
SkRect destRectTransformed;
canvas.getTotalMatrix().mapRect(&destRectTransformed, destRect);
SkIRect destRectTransformedRounded;
destRectTransformed.round(&destRectTransformedRounded);
// Compute the visible portion of our rect.
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.
// Compute the transformed (screen space) portion of the visible portion for
// use below.
SkRect destRectVisibleSubsetTransformed;
canvas.getTotalMatrix().mapRect(&destRectVisibleSubsetTransformed, destRectVisibleSubset);
SkRect destBitmapSubsetTransformed = destRectVisibleSubsetTransformed;
destBitmapSubsetTransformed.offset(-destRectTransformed.fLeft,
-destRectTransformed.fTop);
SkIRect destBitmapSubsetTransformedRounded;
destBitmapSubsetTransformed.round(&destBitmapSubsetTransformedRounded);
// Transforms above plus rounding may cause destBitmapSubsetTransformedRounded
// to go outside the image, so need to clip to avoid problems.
if (!destBitmapSubsetTransformedRounded.intersect(
0, 0, destRectTransformedRounded.width(), destRectTransformedRounded.height()))
return; // Image is not visible.
SkBitmap resampled = bitmap.resizedBitmap(srcIRect,
destRectTransformedRounded.width(),
destRectTransformedRounded.height(),
destBitmapSubsetTransformedRounded);
canvas.drawBitmapRect(resampled, 0, destRectVisibleSubset, &paint);
}
示例9: drawRect
void drawRect(const SkRect& r, SkColor c) override {
HDC hdc = (HDC)fCanvas->accessTopRasterHandle();
COLORREF cr = RGB(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c));// SkEndian_Swap32(c) >> 8;
FillRect(hdc, &toRECT(r.round()), CreateSolidBrush(cr));
// Assuming GDI wrote zeros for alpha, this will or-in 0xFF for alpha
SkPaint paint;
paint.setBlendMode(SkBlendMode::kDstATop);
fCanvas->drawRect(r, paint);
}
示例10: getClipBounds
static jboolean getClipBounds(JNIEnv* env, jobject, jlong canvasHandle, jobject bounds) {
SkRect r;
SkIRect ir;
bool result = get_canvas(canvasHandle)->getClipBounds(&r);
if (!result) {
r.setEmpty();
}
r.round(&ir);
(void)GraphicsJNI::irect_to_jrect(ir, env, bounds);
return result ? JNI_TRUE : JNI_FALSE;
}
示例11: op
bool SkRasterClip::op(const SkRect& localRect, const SkMatrix& matrix, const SkIRect& bounds,
SkRegion::Op op, bool doAA) {
AUTO_RASTERCLIP_VALIDATE(*this);
SkRect devRect;
if (fForceConservativeRects) {
SkIRect ir;
switch (mutate_conservative_op(&op, false)) {
case kDoNothing_MutateResult:
return !this->isEmpty();
case kReplaceClippedAgainstGlobalBounds_MutateResult:
ir = bounds;
break;
case kContinue_MutateResult:
matrix.mapRect(&devRect, localRect);
ir = devRect.roundOut();
break;
}
return this->op(ir, op);
}
const bool isScaleTrans = matrix.isScaleTranslate();
if (!isScaleTrans) {
SkPath path;
path.addRect(localRect);
path.setIsVolatile(true);
return this->op(path, matrix, bounds, op, doAA);
}
matrix.mapRect(&devRect, localRect);
if (fIsBW && doAA) {
// check that the rect really needs aa, or is it close enought to
// integer boundaries that we can just treat it as a BW rect?
if (nearly_integral(devRect.fLeft) && nearly_integral(devRect.fTop) &&
nearly_integral(devRect.fRight) && nearly_integral(devRect.fBottom)) {
doAA = false;
}
}
if (fIsBW && !doAA) {
SkIRect ir;
devRect.round(&ir);
(void)fBW.op(ir, op);
} else {
if (fIsBW) {
this->convertToAA();
}
(void)fAA.op(devRect, op, doAA);
}
return this->updateCacheAndReturnNonEmpty();
}
示例12: opRect
void SkConservativeClip::opRect(const SkRect& localRect, const SkMatrix& ctm,
const SkIRect& devBounds, SkRegion::Op op, bool doAA) {
SkIRect ir;
switch (mutate_conservative_op(&op, false)) {
case kDoNothing_MutateResult:
return;
case kReplaceClippedAgainstGlobalBounds_MutateResult:
ir = devBounds;
break;
case kContinue_MutateResult: {
SkRect devRect;
ctm.mapRect(&devRect, localRect);
ir = doAA ? devRect.roundOut() : devRect.round();
} break;
}
this->opIRect(ir, op);
}
示例13: platformBoundsForGlyph
FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const
{
if (!m_platformData.size())
return FloatRect();
SkASSERT(sizeof(glyph) == 2); // compile-time assert
SkPaint paint;
m_platformData.setupPaint(&paint);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
SkRect bounds;
paint.measureText(&glyph, 2, &bounds);
if (!paint.isSubpixelText()) {
SkIRect ir;
bounds.round(&ir);
bounds.set(ir);
}
return FloatRect(bounds);
}
示例14: drawImageNine
void Canvas::drawImageNine(const CanvasImage* image,
double centerLeft,
double centerTop,
double centerRight,
double centerBottom,
double dstLeft,
double dstTop,
double dstRight,
double dstBottom,
const Paint& paint) {
if (!m_canvas)
return;
ASSERT(image);
SkRect center = SkRect::MakeLTRB(centerLeft, centerTop, centerRight, centerBottom);
SkIRect icenter;
center.round(&icenter);
m_canvas->drawImageNine(image->image(),
icenter,
SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom),
paint.paint());
}
示例15: handleInval
bool SkWindow::handleInval(const SkRect* localR) {
SkIRect ir;
if (localR) {
SkRect devR;
SkMatrix inverse;
if (!fMatrix.invert(&inverse)) {
return false;
}
fMatrix.mapRect(&devR, *localR);
devR.round(&ir);
} else {
ir.set(0, 0,
SkScalarRoundToInt(this->width()),
SkScalarRoundToInt(this->height()));
}
fDirtyRgn.op(ir, SkRegion::kUnion_Op);
this->onHandleInval(ir);
return true;
}