本文整理汇总了C++中SkRect::intersect方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::intersect方法的具体用法?C++ SkRect::intersect怎么用?C++ SkRect::intersect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::intersect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: inval
void SkView::inval(SkRect* rect)
{
if (!this->isVisible())
return;
SkRect bounds;
this->getLocalBounds(&bounds);
if (rect && !bounds.intersect(*rect))
return;
rect = &bounds;
SkView* view = this;
for (;;)
{
if (view->handleInval(bounds))
break;
SkRect parentR;
SkView* parent = view->fParent;
if (parent == NULL || !parent->isVisible())
break;
bounds.offset(view->fLoc.fX, view->fLoc.fY);
parent->getLocalBounds(&parentR);
if (!bounds.intersect(parentR))
return;
view = parent;
}
}
示例2: 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
示例3: FindLayersToAtlas
// Atlased layers must be small enough to fit in the atlas, not have a
// paint with an image filter and be neither nested nor nesting.
// TODO: allow leaf nested layers to appear in the atlas.
void GrLayerHoister::FindLayersToAtlas(GrContext* context,
const SkPicture* topLevelPicture,
const SkMatrix& initialMat,
const SkRect& query,
SkTDArray<GrHoistedLayer>* atlased,
SkTDArray<GrHoistedLayer>* recycled,
int numSamples) {
if (0 != numSamples) {
// MSAA layers are currently never atlased
return;
}
GrLayerCache* layerCache = context->getLayerCache();
layerCache->processDeletedPictures();
SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_getAccelData(key);
if (!topLevelData) {
return;
}
const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLevelData);
if (0 == topLevelGPUData->numBlocks()) {
return;
}
atlased->setReserve(atlased->count() + topLevelGPUData->numBlocks());
for (int i = 0; i < topLevelGPUData->numBlocks(); ++i) {
const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i);
// TODO: ignore perspective projected layers here?
bool disallowAtlasing = info.fHasNestedLayers || info.fIsNested ||
(info.fPaint && info.fPaint->getImageFilter());
if (disallowAtlasing) {
continue;
}
SkRect layerRect;
initialMat.mapRect(&layerRect, info.fBounds);
if (!layerRect.intersect(query)) {
continue;
}
const SkIRect dstIR = layerRect.roundOut();
SkIRect srcIR;
if (!compute_source_rect(info, initialMat, dstIR, &srcIR)) {
continue;
}
prepare_for_hoisting(layerCache, topLevelPicture, initialMat,
info, srcIR, dstIR, atlased, recycled, true, 0);
}
}
示例4: drawPictureAtLocalResolution
void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevice* device,
const SkIRect& deviceBounds,
const Context& ctx) const {
SkMatrix inverseCtm;
if (!ctx.ctm().invert(&inverseCtm))
return;
SkRect localBounds = SkRect::Make(ctx.clipBounds());
inverseCtm.mapRect(&localBounds);
if (!localBounds.intersect(fCropRect))
return;
SkIRect localIBounds = localBounds.roundOut();
SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.width(), localIBounds.height()));
// Pass explicit surface props, as the simplified canvas constructor discards device properties.
// FIXME: switch back to the public constructor (and unfriend) after
// https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
SkCanvas localCanvas(localDevice, &proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(localIBounds.fTop));
localCanvas.drawPicture(fPicture);
// Pass explicit surface props, as the simplified canvas constructor discards device properties.
// FIXME: switch back to the public constructor (and unfriend) after
// https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
SkCanvas canvas(device, &proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
canvas.concat(ctx.ctm());
SkPaint paint;
paint.setFilterQuality(fFilterQuality);
canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(localIBounds.fLeft),
SkIntToScalar(localIBounds.fTop), &paint);
//canvas.drawPicture(fPicture);
}
示例5: beginPage
SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height,
const SkRect* content) {
if (width <= 0 || height <= 0) {
return nullptr;
}
SkRect outer = SkRect::MakeWH(width, height);
SkRect inner;
if (content) {
inner = *content;
if (!inner.intersect(outer)) {
return nullptr;
}
} else {
inner = outer;
}
for (;;) {
switch (fState) {
case kBetweenPages_State:
fState = kInPage_State;
return this->onBeginPage(width, height, inner);
case kInPage_State:
this->endPage();
break;
case kClosed_State:
return nullptr;
}
}
SkDEBUGFAIL("never get here");
return nullptr;
}
示例6: drawPictureAtLocalResolution
void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevice* device,
const SkIRect& deviceBounds,
const Context& ctx) const {
SkMatrix inverseCtm;
if (!ctx.ctm().invert(&inverseCtm)) {
return;
}
SkRect localBounds = SkRect::Make(ctx.clipBounds());
inverseCtm.mapRect(&localBounds);
if (!localBounds.intersect(fCropRect)) {
return;
}
SkIRect localIBounds = localBounds.roundOut();
SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.width(), localIBounds.height()));
SkCanvas localCanvas(localDevice);
localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(localIBounds.fTop));
localCanvas.drawPicture(fPicture);
SkCanvas canvas(device);
canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
canvas.concat(ctx.ctm());
SkPaint paint;
paint.setFilterQuality(fFilterQuality);
canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(localIBounds.fLeft),
SkIntToScalar(localIBounds.fTop), &paint);
}
示例7: didDraw
void OpaqueRegionSkia::didDraw(const GraphicsContext* context, const SkRect& rect, const SkPaint& paint, const SkBitmap* sourceBitmap, bool fillsBounds, DrawType drawType)
{
SkRect targetRect = rect;
// Apply the transform to device coordinate space.
SkMatrix canvasTransform = context->canvas()->getTotalMatrix();
if (!canvasTransform.mapRect(&targetRect))
fillsBounds = false;
// Apply the current clip.
SkRect deviceClipRect;
if (!getDeviceClipAsRect(context, deviceClipRect))
fillsBounds = false;
else if (!targetRect.intersect(deviceClipRect))
return;
bool drawsOpaque = paintIsOpaque(paint, drawType, sourceBitmap);
bool xfersOpaque = xfermodeIsOpaque(paint, drawsOpaque);
bool preservesOpaque = xfermodePreservesOpaque(paint, drawsOpaque);
if (fillsBounds && xfersOpaque)
markRectAsOpaque(targetRect);
else if (!preservesOpaque)
markRectAsNonOpaque(targetRect);
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:25,代码来源:OpaqueRegionSkia.cpp
示例8: adjustAndMap
// Adjust rect for all paints that may affect its geometry, then map it to identity space.
Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const {
// Inverted rectangles really confuse our BBHs.
rect.sort();
// Adjust the rect for its own paint.
if (!AdjustForPaint(paint, &rect)) {
// The paint could do anything to our bounds. The only safe answer is the current clip.
return fCurrentClipBounds;
}
// Adjust rect for all the paints from the SaveLayers we're inside.
if (!this->adjustForSaveLayerPaints(&rect)) {
// Same deal as above.
return fCurrentClipBounds;
}
// Map the rect back to identity space.
fCTM.mapRect(&rect);
// Nothing can draw outside the current clip.
if (!rect.intersect(fCurrentClipBounds)) {
return Bounds::MakeEmpty();
}
return rect;
}
示例9: draw
bool SkHitTest::draw(SkAnimateMaker& maker) {
hits.setCount(bullets.count());
value = false;
int bulletCount = bullets.count();
int targetCount = targets.count();
for (int bIndex = 0; bIndex < bulletCount; bIndex++) {
SkDisplayable* bullet = bullets[bIndex];
SkRect bBounds;
bullet->getBounds(&bBounds);
hits[bIndex] = -1;
if (bBounds.fLeft == (int16_t)0x8000U)
continue;
for (int tIndex = 0; tIndex < targetCount; tIndex++) {
SkDisplayable* target = targets[tIndex];
SkRect tBounds;
target->getBounds(&tBounds);
if (bBounds.intersect(tBounds)) {
hits[bIndex] = tIndex;
value = true;
break;
}
}
}
return false;
}
示例10: 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);
}
示例11: inval
void SkView::inval(SkRect* rect) {
SkView* view = this;
SkRect storage;
for (;;) {
if (!view->isVisible()) {
return;
}
if (view->isClipToBounds()) {
SkRect bounds;
view->getLocalBounds(&bounds);
if (rect && !bounds.intersect(*rect)) {
return;
}
storage = bounds;
rect = &storage;
}
if (view->handleInval(rect)) {
return;
}
SkView* parent = view->fParent;
if (parent == NULL) {
return;
}
if (rect) {
rect->offset(view->fLoc.fX, view->fLoc.fY);
}
view = parent;
}
}
示例12: 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);
}
示例13: 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();
}
示例14: FillPath
void SkScan::FillPath(const SkPath& path, const SkRegion& origClip,
SkBlitter* blitter) {
if (origClip.isEmpty()) {
return;
}
// Our edges are fixed-point, and don't like the bounds of the clip to
// exceed that. Here we trim the clip just so we don't overflow later on
const SkRegion* clipPtr = &origClip;
SkRegion finiteClip;
if (clip_to_limit(origClip, &finiteClip)) {
if (finiteClip.isEmpty()) {
return;
}
clipPtr = &finiteClip;
}
// don't reference "origClip" any more, just use clipPtr
SkRect bounds = path.getBounds();
bool irPreClipped = false;
if (!SkRectPriv::MakeLargeS32().contains(bounds)) {
if (!bounds.intersect(SkRectPriv::MakeLargeS32())) {
bounds.setEmpty();
}
irPreClipped = true;
}
SkIRect ir = conservative_round_to_int(bounds);
if (ir.isEmpty()) {
if (path.isInverseFillType()) {
blitter->blitRegion(*clipPtr);
}
return;
}
SkScanClipper clipper(blitter, clipPtr, ir, path.isInverseFillType(), irPreClipped);
blitter = clipper.getBlitter();
if (blitter) {
// we have to keep our calls to blitter in sorted order, so we
// must blit the above section first, then the middle, then the bottom.
if (path.isInverseFillType()) {
sk_blit_above(blitter, ir, *clipPtr);
}
SkASSERT(clipper.getClipRect() == nullptr ||
*clipper.getClipRect() == clipPtr->getBounds());
sk_fill_path(path, clipPtr->getBounds(), blitter, ir.fTop, ir.fBottom,
0, clipper.getClipRect() == nullptr);
if (path.isInverseFillType()) {
sk_blit_below(blitter, ir, *clipPtr);
}
} else {
// what does it mean to not have a blitter if path.isInverseFillType???
}
}
示例15: 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);
}