SkIRect::makeOffset(SkVector)

Change-Id: I0e236bf14acf1a8b7df3433be05a192633096df0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/246098
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-10-03 14:57:07 -04:00 committed by Skia Commit-Bot
parent 9241a6d394
commit 9bd947ddb1
14 changed files with 34 additions and 23 deletions

View File

@ -273,13 +273,27 @@ struct SK_API SkIRect {
@param dy offset added to fTop and fBottom
@return SkIRect offset by dx and dy, with original width and height
*/
SkIRect makeOffset(int32_t dx, int32_t dy) const {
constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const {
return {
Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
};
}
/** Returns SkIRect offset by (offset.x(), offset.y()).
If offset.x() is negative, SkIRect returned is moved to the left.
If offset.x() is positive, SkIRect returned is moved to the right.
If offset.y() is negative, SkIRect returned is moved upward.
If offset.y() is positive, SkIRect returned is moved downward.
@param offset translation vector
@return SkIRect translated by offset, with original width and height
*/
constexpr SkIRect makeOffset(SkIVector offset) const {
return this->makeOffset(offset.x(), offset.y());
}
/** Returns SkIRect, inset by (dx, dy).
If dx is negative, SkIRect returned is wider.

View File

@ -2243,7 +2243,7 @@ void SkCanvas::onDrawBehind(const SkPaint& paint) {
// We use clipRegion because it is already defined to operate in dev-space
// (i.e. ignores the ctm). However, it is going to first translate by -origin,
// but we don't want that, so we undo that before calling in.
SkRegion rgn(bounds.makeOffset(dev->fOrigin.fX, dev->fOrigin.fY));
SkRegion rgn(bounds.makeOffset(dev->fOrigin));
dev->clipRegion(rgn, SkClipOp::kIntersect);
dev->drawPaint(draw.paint());
dev->restore(fMCRec->fMatrix);

View File

@ -56,7 +56,7 @@ void SkClipStackDevice::onSetDeviceClipRestriction(SkIRect* clipRestriction) {
fClipStack.setDeviceClipRestriction(*clipRestriction);
} else {
SkIPoint origin = this->getOrigin();
SkIRect rect = clipRestriction->makeOffset(-origin.x(), -origin.y());
SkIRect rect = clipRestriction->makeOffset(-origin);
fClipStack.setDeviceClipRestriction(rect);
fClipStack.clipDevRect(rect, SkClipOp::kIntersect);
}

View File

@ -174,13 +174,13 @@ sk_sp<SkSurface> SkSpecialImage::makeTightSurface(
}
sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const {
SkIRect absolute = subset.makeOffset(this->subset().x(), this->subset().y());
SkIRect absolute = subset.makeOffset(this->subset().topLeft());
return as_SIB(this)->onMakeSubset(absolute);
}
sk_sp<SkImage> SkSpecialImage::asImage(const SkIRect* subset) const {
if (subset) {
SkIRect absolute = subset->makeOffset(this->subset().x(), this->subset().y());
SkIRect absolute = subset->makeOffset(this->subset().topLeft());
return as_SIB(this)->onAsImage(&absolute);
} else {
return as_SIB(this)->onAsImage(nullptr);

View File

@ -321,7 +321,7 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffectImpl::onFilterImage(const Context&
return nullptr;
}
const SkIRect colorBounds = bounds.makeOffset(-colorOffset.x(), -colorOffset.y());
const SkIRect colorBounds = bounds.makeOffset(-colorOffset);
// If the offset overflowed (saturated) then we have to abort, as we need their
// dimensions to be equal. See https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7209
if (colorBounds.size() != bounds.size()) {

View File

@ -141,5 +141,5 @@ SkIRect SkOffsetImageFilterImpl::onFilterNodeBounds(
SkPointPriv::Negate(vec);
}
return src.makeOffset(vec.fX, vec.fY);
return src.makeOffset(vec);
}

View File

@ -303,7 +303,7 @@ bool GrCCDrawPathsOp::SingleDraw::shouldCachePathMask(int maxRenderTargetSize) c
// The hitRect should already be contained within the shape's bounds, but we still intersect it
// because it's possible for edges very near pixel boundaries (e.g., 0.999999), to round out
// inconsistently, depending on the integer translation values and fp32 precision.
SkIRect hitRect = fCacheEntry->hitRect().makeOffset(fCachedMaskShift.x(), fCachedMaskShift.y());
SkIRect hitRect = fCacheEntry->hitRect().makeOffset(fCachedMaskShift);
hitRect.intersect(fShapeConservativeIBounds);
// Render and cache the entire path mask if we see enough of it to justify rendering all the

View File

@ -110,8 +110,7 @@ void GrCCFiller::parseDeviceSpaceFill(const SkPath& path, const SkPoint* deviceS
if (GrScissorTest::kEnabled == scissorTest) {
fScissorSubBatches.push_back() = {fTotalPrimitiveCounts[(int)GrScissorTest::kEnabled],
clippedDevIBounds.makeOffset(devToAtlasOffset.fX,
devToAtlasOffset.fY)};
clippedDevIBounds.makeOffset(devToAtlasOffset)};
}
}

View File

@ -245,7 +245,7 @@ GrCCPathCache::OnFlushEntryRef GrCCPathCache::find(
}
}
}
entry->fHitRect.join(clippedDrawBounds.makeOffset(-maskShift->x(), -maskShift->y()));
entry->fHitRect.join(clippedDrawBounds.makeOffset(-*maskShift));
SkASSERT(!entry->fCachedAtlas || entry->fCachedAtlas->getOnFlushProxy());
return OnFlushEntryRef::OnFlushRef(entry);
}
@ -374,7 +374,7 @@ void GrCCPathCacheEntry::setCoverageCountAtlas(
fAtlasOffset = atlasOffset + maskShift;
fOctoBounds.setOffset(octoBounds, -maskShift.fX, -maskShift.fY);
fDevIBounds = devIBounds.makeOffset(-maskShift.fX, -maskShift.fY);
fDevIBounds = devIBounds.makeOffset(-maskShift);
}
GrCCPathCacheEntry::ReleaseAtlasResult GrCCPathCacheEntry::upgradeToLiteralCoverageAtlas(

View File

@ -487,8 +487,7 @@ void GrCCPerFlushResources::recordStencilResolveInstance(
SkASSERT(GrCCAtlas::CoverageType::kA8_Multisample == this->renderedPathCoverageType());
SkASSERT(fNextStencilResolveInstanceIdx < fEndStencilResolveInstance);
SkIRect atlasIBounds = clippedPathIBounds.makeOffset(
devToAtlasOffset.x(), devToAtlasOffset.y());
SkIRect atlasIBounds = clippedPathIBounds.makeOffset(devToAtlasOffset);
if (GrFillRule::kEvenOdd == fillRule) {
// Make even/odd fills counterclockwise. The resolve draw uses two-sided stencil, with
// "nonzero" settings in front and "even/odd" settings in back.

View File

@ -296,9 +296,9 @@ void GrCCStroker::parseDeviceSpaceStroke(const SkPath& path, const SkPoint* devi
InstanceTallies* currStrokeEndIndices;
if (GrScissorTest::kEnabled == scissorTest) {
SkASSERT(fBatches.back().fEndScissorSubBatch == fScissorSubBatches.count());
fScissorSubBatches.emplace_back(
&fTalliesAllocator, *fInstanceCounts[(int)GrScissorTest::kEnabled],
clippedDevIBounds.makeOffset(devToAtlasOffset.x(), devToAtlasOffset.y()));
fScissorSubBatches.emplace_back(&fTalliesAllocator,
*fInstanceCounts[(int)GrScissorTest::kEnabled],
clippedDevIBounds.makeOffset(devToAtlasOffset));
fBatches.back().fEndScissorSubBatch = fScissorSubBatches.count();
fInstanceCounts[(int)GrScissorTest::kEnabled] =
currStrokeEndIndices = fScissorSubBatches.back().fEndInstances;

View File

@ -289,7 +289,7 @@ sk_sp<SkImage> SkImage::makeWithFilter(GrContext* grContext,
// original coordinate system, so configure the CTM to correct crop rects and explicitly adjust
// the clip bounds (since it is assumed to already be in image space).
SkImageFilter_Base::Context context(SkMatrix::MakeTrans(-subset.x(), -subset.y()),
clipBounds.makeOffset(-subset.x(), -subset.y()),
clipBounds.makeOffset(-subset.topLeft()),
cache.get(), fInfo.colorType(), fInfo.colorSpace(),
srcSpecialImage.get());
@ -309,8 +309,7 @@ sk_sp<SkImage> SkImage::makeWithFilter(GrContext* grContext,
// result->subset() ensures that the result's image pixel origin does not affect results.
SkIRect dstRect = result->subset();
SkIRect clippedDstRect = dstRect;
if (!clippedDstRect.intersect(clipBounds.makeOffset(result->subset().x() - offset->x(),
result->subset().y() - offset->y()))) {
if (!clippedDstRect.intersect(clipBounds.makeOffset(result->subset().topLeft() - *offset))) {
return nullptr;
}

View File

@ -254,7 +254,7 @@ sk_sp<SkImage> SkImage_Lazy::onMakeSubset(GrRecordingContext* context,
SkASSERT(this->bounds().contains(subset));
SkASSERT(this->bounds() != subset);
const SkIRect generatorSubset = subset.makeOffset(fOrigin.x(), fOrigin.y());
const SkIRect generatorSubset = subset.makeOffset(fOrigin);
const SkColorType colorType = this->colorType();
Validator validator(fSharedGenerator, &generatorSubset, &colorType, this->refColorSpace());
return validator ? sk_sp<SkImage>(new SkImage_Lazy(&validator)) : nullptr;

View File

@ -15,7 +15,7 @@ SkBitmapKey SkBitmapKeyFromImage(const SkImage* image) {
}
if (const SkBitmap* bm = as_IB(image)->onPeekBitmap()) {
SkIPoint o = bm->pixelRefOrigin();
return {image->bounds().makeOffset(o.x(), o.y()), bm->getGenerationID()};
return {image->bounds().makeOffset(o), bm->getGenerationID()};
}
return {image->bounds(), image->uniqueID()};
}
@ -35,7 +35,7 @@ SkKeyedImage SkKeyedImage::subset(SkIRect subset) const {
if (fImage && subset.intersect(fImage->bounds())) {
img.fImage = fImage->makeSubset(subset);
if (img.fImage) {
img.fKey = {subset.makeOffset(fKey.fSubset.x(), fKey.fSubset.y()), fKey.fID};
img.fKey = {subset.makeOffset(fKey.fSubset.topLeft()), fKey.fID};
}
}
return img;