It is dangerous to ignore SkRect::intersect's return value
Review URL: https://codereview.chromium.org/833943002
This commit is contained in:
parent
bd0d9da981
commit
152f524fd3
@ -704,8 +704,10 @@ public:
|
|||||||
SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
|
SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
|
||||||
SkIntToScalar(pageSize.height()));
|
SkIntToScalar(pageSize.height()));
|
||||||
initialTransform.mapRect(&content);
|
initialTransform.mapRect(&content);
|
||||||
content.intersect(0, 0, SkIntToScalar(pageSize.width()),
|
if (!content.intersect(0, 0, SkIntToScalar(pageSize.width()),
|
||||||
SkIntToScalar(pageSize.height()));
|
SkIntToScalar(pageSize.height()))) {
|
||||||
|
content.setEmpty();
|
||||||
|
}
|
||||||
SkISize contentSize =
|
SkISize contentSize =
|
||||||
SkISize::Make(SkScalarRoundToInt(content.width()),
|
SkISize::Make(SkScalarRoundToInt(content.width()),
|
||||||
SkScalarRoundToInt(content.height()));
|
SkScalarRoundToInt(content.height()));
|
||||||
|
@ -82,8 +82,9 @@ protected:
|
|||||||
scaleMatrix.setScale(scale, scale);
|
scaleMatrix.setScale(scale, scale);
|
||||||
SkRect cropRectFloat;
|
SkRect cropRectFloat;
|
||||||
scaleMatrix.mapRect(&cropRectFloat, SkRect::Make(cropRect));
|
scaleMatrix.mapRect(&cropRectFloat, SkRect::Make(cropRect));
|
||||||
clipRect.intersect(cropRectFloat);
|
if (clipRect.intersect(cropRectFloat)) {
|
||||||
canvas->drawRect(clipRect, strokePaint);
|
canvas->drawRect(clipRect, strokePaint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void onDraw(SkCanvas* canvas) {
|
virtual void onDraw(SkCanvas* canvas) {
|
||||||
|
@ -267,7 +267,7 @@ struct SK_API SkIRect {
|
|||||||
intersection, otherwise return false and do not change this rectangle.
|
intersection, otherwise return false and do not change this rectangle.
|
||||||
If either rectangle is empty, do nothing and return false.
|
If either rectangle is empty, do nothing and return false.
|
||||||
*/
|
*/
|
||||||
bool intersect(const SkIRect& r) {
|
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& r) {
|
||||||
SkASSERT(&r);
|
SkASSERT(&r);
|
||||||
return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
|
return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
|
||||||
}
|
}
|
||||||
@ -276,7 +276,7 @@ struct SK_API SkIRect {
|
|||||||
that intersection, otherwise return false and do not change this
|
that intersection, otherwise return false and do not change this
|
||||||
rectangle. If either rectangle is empty, do nothing and return false.
|
rectangle. If either rectangle is empty, do nothing and return false.
|
||||||
*/
|
*/
|
||||||
bool intersect(const SkIRect& a, const SkIRect& b) {
|
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b) {
|
||||||
|
|
||||||
if (!a.isEmpty() && !b.isEmpty() &&
|
if (!a.isEmpty() && !b.isEmpty() &&
|
||||||
a.fLeft < b.fRight && b.fLeft < a.fRight &&
|
a.fLeft < b.fRight && b.fLeft < a.fRight &&
|
||||||
@ -296,7 +296,7 @@ struct SK_API SkIRect {
|
|||||||
If either is, then the return result is undefined. In the debug build,
|
If either is, then the return result is undefined. In the debug build,
|
||||||
we assert that both rectangles are non-empty.
|
we assert that both rectangles are non-empty.
|
||||||
*/
|
*/
|
||||||
bool intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b) {
|
bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b) {
|
||||||
SkASSERT(!a.isEmpty() && !b.isEmpty());
|
SkASSERT(!a.isEmpty() && !b.isEmpty());
|
||||||
|
|
||||||
if (a.fLeft < b.fRight && b.fLeft < a.fRight &&
|
if (a.fLeft < b.fRight && b.fLeft < a.fRight &&
|
||||||
@ -315,7 +315,8 @@ struct SK_API SkIRect {
|
|||||||
otherwise return false and do not change this rectangle.
|
otherwise return false and do not change this rectangle.
|
||||||
If either rectangle is empty, do nothing and return false.
|
If either rectangle is empty, do nothing and return false.
|
||||||
*/
|
*/
|
||||||
bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom) {
|
bool SK_WARN_UNUSED_RESULT intersect(int32_t left, int32_t top,
|
||||||
|
int32_t right, int32_t bottom) {
|
||||||
if (left < right && top < bottom && !this->isEmpty() &&
|
if (left < right && top < bottom && !this->isEmpty() &&
|
||||||
fLeft < right && left < fRight && fTop < bottom && top < fBottom) {
|
fLeft < right && left < fRight && fTop < bottom && top < fBottom) {
|
||||||
if (fLeft < left) fLeft = left;
|
if (fLeft < left) fLeft = left;
|
||||||
@ -331,8 +332,8 @@ struct SK_API SkIRect {
|
|||||||
*/
|
*/
|
||||||
static bool Intersects(const SkIRect& a, const SkIRect& b) {
|
static bool Intersects(const SkIRect& a, const SkIRect& b) {
|
||||||
return !a.isEmpty() && !b.isEmpty() && // check for empties
|
return !a.isEmpty() && !b.isEmpty() && // check for empties
|
||||||
a.fLeft < b.fRight && b.fLeft < a.fRight &&
|
a.fLeft < b.fRight && b.fLeft < a.fRight &&
|
||||||
a.fTop < b.fBottom && b.fTop < a.fBottom;
|
a.fTop < b.fBottom && b.fTop < a.fBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -656,21 +657,22 @@ struct SK_API SkRect {
|
|||||||
intersection, otherwise return false and do not change this rectangle.
|
intersection, otherwise return false and do not change this rectangle.
|
||||||
If either rectangle is empty, do nothing and return false.
|
If either rectangle is empty, do nothing and return false.
|
||||||
*/
|
*/
|
||||||
bool intersect(const SkRect& r);
|
bool SK_WARN_UNUSED_RESULT intersect(const SkRect& r);
|
||||||
|
|
||||||
/** If this rectangle intersects the rectangle specified by left, top, right, bottom,
|
/** If this rectangle intersects the rectangle specified by left, top, right, bottom,
|
||||||
return true and set this rectangle to that intersection, otherwise return false
|
return true and set this rectangle to that intersection, otherwise return false
|
||||||
and do not change this rectangle.
|
and do not change this rectangle.
|
||||||
If either rectangle is empty, do nothing and return false.
|
If either rectangle is empty, do nothing and return false.
|
||||||
*/
|
*/
|
||||||
bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
|
bool SK_WARN_UNUSED_RESULT intersect(SkScalar left, SkScalar top,
|
||||||
|
SkScalar right, SkScalar bottom);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If rectangles a and b intersect, return true and set this rectangle to
|
* If rectangles a and b intersect, return true and set this rectangle to
|
||||||
* that intersection, otherwise return false and do not change this
|
* that intersection, otherwise return false and do not change this
|
||||||
* rectangle. If either rectangle is empty, do nothing and return false.
|
* rectangle. If either rectangle is empty, do nothing and return false.
|
||||||
*/
|
*/
|
||||||
bool intersect(const SkRect& a, const SkRect& b);
|
bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -454,7 +454,10 @@ MaskSuperBlitter::MaskSuperBlitter(SkBlitter* realBlitter, const SkIRect& ir, co
|
|||||||
fMask.fFormat = SkMask::kA8_Format;
|
fMask.fFormat = SkMask::kA8_Format;
|
||||||
|
|
||||||
fClipRect = ir;
|
fClipRect = ir;
|
||||||
fClipRect.intersect(clip.getBounds());
|
if (!fClipRect.intersect(clip.getBounds())) {
|
||||||
|
SkASSERT(0);
|
||||||
|
fClipRect.setEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
// For valgrind, write 1 extra byte at the end so we don't read
|
// For valgrind, write 1 extra byte at the end so we don't read
|
||||||
// uninitialized memory. See comment in add_aa_span and fStorage[].
|
// uninitialized memory. See comment in add_aa_span and fStorage[].
|
||||||
|
@ -1184,7 +1184,9 @@ bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds,
|
|||||||
// Outset srcRect and clipRect by 3 * sigma, to compute affected blur area.
|
// Outset srcRect and clipRect by 3 * sigma, to compute affected blur area.
|
||||||
srcRect.outset(sigma3, sigma3);
|
srcRect.outset(sigma3, sigma3);
|
||||||
clipRect.outset(sigma3, sigma3);
|
clipRect.outset(sigma3, sigma3);
|
||||||
srcRect.intersect(clipRect);
|
if (!srcRect.intersect(clipRect)) {
|
||||||
|
srcRect.setEmpty();
|
||||||
|
}
|
||||||
*maskRect = srcRect;
|
*maskRect = srcRect;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,10 @@ void GrReducedClip::ReduceClipStack(const SkClipStack& stack,
|
|||||||
if (tighterBounds) {
|
if (tighterBounds) {
|
||||||
SkIRect stackIBounds;
|
SkIRect stackIBounds;
|
||||||
stackBounds.roundOut(&stackIBounds);
|
stackBounds.roundOut(&stackIBounds);
|
||||||
tighterBounds->intersect(queryBounds, stackIBounds);
|
if (!tighterBounds->intersect(queryBounds, stackIBounds)) {
|
||||||
|
SkASSERT(0);
|
||||||
|
tighterBounds->setEmpty();
|
||||||
|
}
|
||||||
bounds = tighterBounds;
|
bounds = tighterBounds;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -79,8 +79,9 @@ protected:
|
|||||||
SkRect mappedRect;
|
SkRect mappedRect;
|
||||||
draw.fMatrix->mapRect(&mappedRect, rect);
|
draw.fMatrix->mapRect(&mappedRect, rect);
|
||||||
SkRect clipRect = SkRect::Make(draw.fRC->getBounds());
|
SkRect clipRect = SkRect::Make(draw.fRC->getBounds());
|
||||||
mappedRect.intersect(clipRect);
|
if (mappedRect.intersect(clipRect)) {
|
||||||
fPRCont->add(bm.pixelRef(), mappedRect);
|
fPRCont->add(bm.pixelRef(), mappedRect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void drawOval(const SkDraw& draw, const SkRect& rect,
|
virtual void drawOval(const SkDraw& draw, const SkRect& rect,
|
||||||
|
Loading…
Reference in New Issue
Block a user