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:
parent
9241a6d394
commit
9bd947ddb1
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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()) {
|
||||
|
@ -141,5 +141,5 @@ SkIRect SkOffsetImageFilterImpl::onFilterNodeBounds(
|
||||
SkPointPriv::Negate(vec);
|
||||
}
|
||||
|
||||
return src.makeOffset(vec.fX, vec.fY);
|
||||
return src.makeOffset(vec);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user