本文整理汇总了C++中SkRect::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::isEmpty方法的具体用法?C++ SkRect::isEmpty怎么用?C++ SkRect::isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void draw(SkCanvas* canvas) {
SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
rect.bottom(), rect.isEmpty() ? "true" : "false");
rect.sort();
SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
rect.bottom(), rect.isEmpty() ? "true" : "false");
}
示例2: draw
void CanvasContext::draw() {
LOG_ALWAYS_FATAL_IF(!mCanvas || mEglSurface == EGL_NO_SURFACE,
"drawRenderNode called on a context with no canvas or surface!");
SkRect dirty;
mDamageAccumulator.finish(&dirty);
// TODO: Re-enable after figuring out cause of b/22592975
// if (dirty.isEmpty() && Properties::skipEmptyFrames) {
// mCurrentFrameInfo->addFlag(FrameInfoFlags::SkippedFrame);
// return;
// }
mCurrentFrameInfo->markIssueDrawCommandsStart();
EGLint width, height;
mEglManager.beginFrame(mEglSurface, &width, &height);
if (width != mCanvas->getViewportWidth() || height != mCanvas->getViewportHeight()) {
mCanvas->setViewport(width, height);
dirty.setEmpty();
} else if (!mBufferPreserved || mHaveNewSurface) {
dirty.setEmpty();
} else {
if (!dirty.isEmpty() && !dirty.intersect(0, 0, width, height)) {
ALOGW("Dirty " RECT_STRING " doesn't intersect with 0 0 %d %d ?",
SK_RECT_ARGS(dirty), width, height);
dirty.setEmpty();
}
profiler().unionDirty(&dirty);
}
if (!dirty.isEmpty()) {
mCanvas->prepareDirty(dirty.fLeft, dirty.fTop,
dirty.fRight, dirty.fBottom, mOpaque);
} else {
mCanvas->prepare(mOpaque);
}
Rect outBounds;
mCanvas->drawRenderNode(mRootRenderNode.get(), outBounds);
profiler().draw(mCanvas);
bool drew = mCanvas->finish();
// Even if we decided to cancel the frame, from the perspective of jank
// metrics the frame was swapped at this point
mCurrentFrameInfo->markSwapBuffers();
if (drew) {
swapBuffers(dirty, width, height);
}
// TODO: Use a fence for real completion?
mCurrentFrameInfo->markFrameCompleted();
mJankTracker.addFrame(*mCurrentFrameInfo);
mRenderThread.jankTracker().addFrame(*mCurrentFrameInfo);
}
示例3: SkRecordOptimize
sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture(uint32_t finishFlags) {
fActivelyRecording = false;
fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
if (fRecord->count() == 0) {
if (finishFlags & kReturnNullForEmpty_FinishFlag) {
return nullptr;
}
return fMiniRecorder.detachAsPicture(fCullRect);
}
// TODO: delay as much of this work until just before first playback?
SkRecordOptimize(fRecord);
if (fRecord->count() == 0) {
if (finishFlags & kReturnNullForEmpty_FinishFlag) {
return nullptr;
}
}
SkAutoTUnref<SkLayerInfo> saveLayerData;
if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) {
saveLayerData.reset(new SkLayerInfo);
}
SkDrawableList* drawableList = fRecorder->getDrawableList();
SkBigPicture::SnapshotArray* pictList =
drawableList ? drawableList->newDrawableSnapshot() : nullptr;
if (fBBH.get()) {
SkAutoTMalloc<SkRect> bounds(fRecord->count());
if (saveLayerData) {
SkRecordComputeLayers(fCullRect, *fRecord, bounds, pictList, saveLayerData);
} else {
SkRecordFillBounds(fCullRect, *fRecord, bounds);
}
fBBH->insert(bounds, fRecord->count());
// Now that we've calculated content bounds, we can update fCullRect, often trimming it.
// TODO: get updated fCullRect from bounds instead of forcing the BBH to return it?
SkRect bbhBound = fBBH->getRootBound();
SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound))
|| (bbhBound.isEmpty() && fCullRect.isEmpty()));
fCullRect = bbhBound;
}
size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures();
for (int i = 0; pictList && i < pictList->count(); i++) {
subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]);
}
return sk_make_sp<SkBigPicture>(fCullRect, fRecord.release(), pictList, fBBH.release(),
saveLayerData.release(), subPictureBytes);
}
示例4: draw
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect,
const FloatRect& srcRect, CompositeOperator compositeOp)
{
startAnimation();
SkBitmapRef* image = this->nativeImageForCurrentFrame();
if (!image) { // If it's too early we won't have an image yet.
return;
}
// in case we get called with an incomplete bitmap
const SkBitmap& bitmap = image->bitmap();
if (bitmap.getPixels() == NULL && bitmap.pixelRef() == NULL) {
#ifdef TRACE_SKIPPED_BITMAPS
SkDebugf("----- skip bitmapimage: [%d %d] pixels %p pixelref %p\n",
bitmap.width(), bitmap.height(),
bitmap.getPixels(), bitmap.pixelRef());
#endif
return;
}
SkIRect srcR;
SkRect dstR;
float invScaleX = (float)bitmap.width() / image->origWidth();
float invScaleY = (float)bitmap.height() / image->origHeight();
android_setrect(&dstR, dstRect);
android_setrect_scaled(&srcR, srcRect, invScaleX, invScaleY);
if (srcR.isEmpty() || dstR.isEmpty()) {
#ifdef TRACE_SKIPPED_BITMAPS
SkDebugf("----- skip bitmapimage: [%d %d] src-empty %d dst-empty %d\n",
bitmap.width(), bitmap.height(),
srcR.isEmpty(), dstR.isEmpty());
#endif
return;
}
SkCanvas* canvas = ctxt->platformContext()->mCanvas;
SkPaint paint;
paint.setFilterBitmap(true);
paint.setPorterDuffXfermode(android_convert_compositeOp(compositeOp));
canvas->drawBitmapRect(bitmap, &srcR, dstR, &paint);
#ifdef TRACE_SUBSAMPLED_BITMAPS
if (bitmap.width() != image->origWidth() ||
bitmap.height() != image->origHeight()) {
SkDebugf("--- BitmapImage::draw [%d %d] orig [%d %d]\n",
bitmap.width(), bitmap.height(),
image->origWidth(), image->origHeight());
}
#endif
}
示例5: draw
void CanvasContext::draw() {
LOG_ALWAYS_FATAL_IF(!mCanvas || mEglSurface == EGL_NO_SURFACE,
"drawRenderNode called on a context with no canvas or surface!");
profiler().markPlaybackStart();
SkRect dirty;
mDamageAccumulator.finish(&dirty);
EGLint width, height;
mEglManager.beginFrame(mEglSurface, &width, &height);
if (width != mCanvas->getViewportWidth() || height != mCanvas->getViewportHeight()) {
mCanvas->setViewport(width, height);
dirty.setEmpty();
} else if (!mBufferPreserved || mHaveNewSurface) {
dirty.setEmpty();
} else {
if (!dirty.isEmpty() && !dirty.intersect(0, 0, width, height)) {
//ALOGW("Dirty " RECT_STRING " doesn't intersect with 0 0 %d %d ?",
// SK_RECT_ARGS(dirty), width, height);
dirty.setEmpty();
}
profiler().unionDirty(&dirty);
}
status_t status;
if (!dirty.isEmpty()) {
status = mCanvas->prepareDirty(dirty.fLeft, dirty.fTop,
dirty.fRight, dirty.fBottom, mOpaque);
} else {
status = mCanvas->prepare(mOpaque);
}
Rect outBounds;
status |= mCanvas->drawRenderNode(mRootRenderNode.get(), outBounds);
profiler().draw(mCanvas);
mCanvas->finish();
profiler().markPlaybackEnd();
if (status & DrawGlInfo::kStatusDrew) {
swapBuffers();
} else {
mEglManager.cancelFrame();
}
profiler().finishFrame();
}
示例6: intersect
bool SkRect::intersect(const SkRect& a, const SkRect& b) {
SkASSERT(&a && &b);
if (!a.isEmpty() && !b.isEmpty() &&
a.fLeft < b.fRight && b.fLeft < a.fRight &&
a.fTop < b.fBottom && b.fTop < a.fBottom) {
fLeft = SkMaxScalar(a.fLeft, b.fLeft);
fTop = SkMaxScalar(a.fTop, b.fTop);
fRight = SkMinScalar(a.fRight, b.fRight);
fBottom = SkMinScalar(a.fBottom, b.fBottom);
return true;
}
return false;
}
示例7: draw_fill
void draw_fill(SkCanvas* canvas, const SkRect& rect, SkScalar width) {
if (rect.isEmpty()) {
return;
}
SkPaint paint;
paint.setColor(0x1f1f0f0f);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(width);
SkPath path;
SkScalar maxSide = SkTMax(rect.width(), rect.height()) / 2;
SkPoint center = { rect.fLeft + maxSide, rect.fTop + maxSide };
path.addCircle(center.fX, center.fY, maxSide);
canvas->drawPath(path, paint);
paint.setStyle(SkPaint::kFill_Style);
path.reset();
path.addCircle(center.fX, center.fY, maxSide - width / 2);
paint.setColor(0x3f0f1f3f);
canvas->drawPath(path, paint);
path.reset();
path.setFillType(SkPath::kEvenOdd_FillType);
path.addCircle(center.fX, center.fY, maxSide + width / 2);
SkRect outside = SkRect::MakeXYWH(center.fX - maxSide - width, center.fY - maxSide - width,
(maxSide + width) * 2, (maxSide + width) * 2);
path.addRect(outside);
canvas->drawPath(path, paint);
}
示例8: setRectXY
void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
if (rect.isEmpty() || !rect.isFinite()) {
this->setEmpty();
return;
}
if (!SkScalarsAreFinite(xRad, yRad)) {
xRad = yRad = 0; // devolve into a simple rect
}
if (xRad <= 0 || yRad <= 0) {
// all corners are square in this case
this->setRect(rect);
return;
}
if (rect.width() < xRad+xRad || rect.height() < yRad+yRad) {
SkScalar scale = SkMinScalar(rect.width() / (xRad + xRad), rect.height() / (yRad + yRad));
SkASSERT(scale < SK_Scalar1);
xRad = SkScalarMul(xRad, scale);
yRad = SkScalarMul(yRad, scale);
}
fRect = rect;
for (int i = 0; i < 4; ++i) {
fRadii[i].set(xRad, yRad);
}
fType = kSimple_Type;
if (xRad >= SkScalarHalf(fRect.width()) && yRad >= SkScalarHalf(fRect.height())) {
fType = kOval_Type;
// TODO: assert that all the x&y radii are already W/2 & H/2
}
SkDEBUGCODE(this->validate();)
}
示例9: fDeque
SkClipStack::SkClipStack(const SkRect& r)
: fDeque(sizeof(Element), kDefaultElementAllocCnt)
, fSaveCount(0) {
if (!r.isEmpty()) {
this->clipDevRect(r, SkRegion::kReplace_Op, false);
}
}
示例10: transformBounds
bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) {
SkRect outBounds = bounds;
outBounds.sort();
if (paint) {
// account for stroking, path effects, shadows, etc
if (paint->canComputeFastBounds()) {
SkRect temp;
outBounds = paint->computeFastBounds(outBounds, &temp);
} else {
// set bounds to current clip
if (!this->getClipBounds(&outBounds)) {
// current clip is empty
return false;
}
}
}
if (!outBounds.isEmpty() && !this->quickReject(outBounds)) {
this->getTotalMatrix().mapRect(&outBounds);
this->handleBBox(outBounds);
return true;
}
return false;
}
示例11: applyOpaqueRegionFromLayer
void OpaqueRegionSkia::applyOpaqueRegionFromLayer(const GraphicsContext* context, const SkRect& layerOpaqueRect, const SkPaint& paint)
{
SkRect deviceClipRect;
bool deviceClipIsARect = getDeviceClipAsRect(context, deviceClipRect);
if (deviceClipRect.isEmpty())
return;
SkRect sourceOpaqueRect = layerOpaqueRect;
// Save the opaque area in the destination, so we can preserve the parts of it under the source opaque area if possible.
SkRect destinationOpaqueRect = currentTrackingOpaqueRect();
bool outsideSourceOpaqueRectPreservesOpaque = xfermodePreservesOpaque(paint, false);
if (!outsideSourceOpaqueRectPreservesOpaque)
markRectAsNonOpaque(deviceClipRect);
if (!deviceClipIsARect)
return;
if (!sourceOpaqueRect.intersect(deviceClipRect))
return;
bool sourceOpaqueRectDrawsOpaque = paintIsOpaque(paint, FillOnly, 0);
bool sourceOpaqueRectXfersOpaque = xfermodeIsOpaque(paint, sourceOpaqueRectDrawsOpaque);
bool sourceOpaqueRectPreservesOpaque = xfermodePreservesOpaque(paint, sourceOpaqueRectDrawsOpaque);
// If the layer's opaque area is being drawn opaque in the layer below, then mark it opaque. Otherwise,
// if it preserves opaque then keep the intersection of the two.
if (sourceOpaqueRectXfersOpaque)
markRectAsOpaque(sourceOpaqueRect);
else if (sourceOpaqueRectPreservesOpaque && sourceOpaqueRect.intersect(destinationOpaqueRect))
markRectAsOpaque(sourceOpaqueRect);
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:32,代码来源:OpaqueRegionSkia.cpp
示例12: insert
void SkTileGrid::insert(void* data, const SkRect& fbounds, bool) {
SkASSERT(!fbounds.isEmpty());
SkIRect dilatedBounds;
if (fbounds.isLargest()) {
// Dilating the largest SkIRect will overflow. Other nearly-largest rects may overflow too,
// but we don't make active use of them like we do the largest.
dilatedBounds.setLargest();
} else {
fbounds.roundOut(&dilatedBounds);
dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height());
dilatedBounds.offset(fInfo.fOffset);
}
const SkIRect gridBounds =
{ 0, 0, fInfo.fTileInterval.width() * fXTiles, fInfo.fTileInterval.height() * fYTiles };
if (!SkIRect::Intersects(dilatedBounds, gridBounds)) {
return;
}
// Note: SkIRects are non-inclusive of the right() column and bottom() row,
// hence the "-1"s in the computations of maxX and maxY.
int minX = SkMax32(0, SkMin32(dilatedBounds.left() / fInfo.fTileInterval.width(), fXTiles - 1));
int minY = SkMax32(0, SkMin32(dilatedBounds.top() / fInfo.fTileInterval.height(), fYTiles - 1));
int maxX = SkMax32(0, SkMin32((dilatedBounds.right() - 1) / fInfo.fTileInterval.width(),
fXTiles - 1));
int maxY = SkMax32(0, SkMin32((dilatedBounds.bottom() - 1) / fInfo.fTileInterval.height(),
fYTiles - 1));
Entry entry = { fCount++, data };
for (int y = minY; y <= maxY; y++) {
for (int x = minX; x <= maxX; x++) {
fTiles[y * fXTiles + x].push(entry);
}
}
}
示例13: swapBuffers
bool EglManager::swapBuffers(const Frame& frame, const SkRect& screenDirty) {
if (CC_UNLIKELY(Properties::waitForGpuCompletion)) {
ATRACE_NAME("Finishing GPU work");
fence();
}
EGLint rects[4];
frame.map(screenDirty, rects);
eglSwapBuffersWithDamageKHR(mEglDisplay, frame.mSurface, rects, screenDirty.isEmpty() ? 0 : 1);
EGLint err = eglGetError();
if (CC_LIKELY(err == EGL_SUCCESS)) {
return true;
}
if (err == EGL_BAD_SURFACE || err == EGL_BAD_NATIVE_WINDOW) {
// For some reason our surface was destroyed out from under us
// This really shouldn't happen, but if it does we can recover easily
// by just not trying to use the surface anymore
ALOGW("swapBuffers encountered EGL error %d on %p, halting rendering...", err,
frame.mSurface);
return false;
}
LOG_ALWAYS_FATAL("Encountered EGL error %d %s during rendering", err, egl_error_str(err));
// Impossible to hit this, but the compiler doesn't know that
return false;
}
示例14: setNinePatch
void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
SkScalar rightRad, SkScalar bottomRad) {
if (rect.isEmpty() || !rect.isFinite()) {
this->setEmpty();
return;
}
const SkScalar array[4] = { leftRad, topRad, rightRad, bottomRad };
if (!SkScalarsAreFinite(array, 4)) {
this->setRect(rect); // devolve into a simple rect
return;
}
leftRad = SkMaxScalar(leftRad, 0);
topRad = SkMaxScalar(topRad, 0);
rightRad = SkMaxScalar(rightRad, 0);
bottomRad = SkMaxScalar(bottomRad, 0);
SkScalar scale = SK_Scalar1;
if (leftRad + rightRad > rect.width()) {
scale = rect.width() / (leftRad + rightRad);
}
if (topRad + bottomRad > rect.height()) {
scale = SkMinScalar(scale, rect.height() / (topRad + bottomRad));
}
if (scale < SK_Scalar1) {
leftRad = SkScalarMul(leftRad, scale);
topRad = SkScalarMul(topRad, scale);
rightRad = SkScalarMul(rightRad, scale);
bottomRad = SkScalarMul(bottomRad, scale);
}
if (leftRad == rightRad && topRad == bottomRad) {
if (leftRad >= SkScalarHalf(rect.width()) && topRad >= SkScalarHalf(rect.height())) {
fType = kOval_Type;
} else if (0 == leftRad || 0 == topRad) {
// If the left and (by equality check above) right radii are zero then it is a rect.
// Same goes for top/bottom.
fType = kRect_Type;
leftRad = 0;
topRad = 0;
rightRad = 0;
bottomRad = 0;
} else {
fType = kSimple_Type;
}
} else {
fType = kNinePatch_Type;
}
fRect = rect;
fRadii[kUpperLeft_Corner].set(leftRad, topRad);
fRadii[kUpperRight_Corner].set(rightRad, topRad);
fRadii[kLowerRight_Corner].set(rightRad, bottomRad);
fRadii[kLowerLeft_Corner].set(leftRad, bottomRad);
SkDEBUGCODE(this->validate();)
}
示例15: 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;
}