SkClipStack: add bounds() and isEmpty() methods

Also: update some of SkPDF to use these rather than the RasterClip.

Change-Id: I5a2564d2269c145135df6a8eda65ab05e4aeaf14
Reviewed-on: https://skia-review.googlesource.com/8159
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2017-02-07 16:58:28 -05:00 committed by Skia Commit-Bot
parent 384b90af5c
commit f3ee34f1ec
3 changed files with 34 additions and 17 deletions

View File

@ -580,6 +580,20 @@ void SkClipStack::restoreTo(int saveCount) {
}
}
SkRect SkClipStack::bounds(const SkIRect& deviceBounds) const {
// TODO: optimize this.
SkRect r;
SkClipStack::BoundsType bounds;
this->getBounds(&r, &bounds);
if (bounds == SkClipStack::kInsideOut_BoundsType) {
return SkRect::Make(deviceBounds);
}
return r.intersect(SkRect::Make(deviceBounds)) ? r : SkRect::MakeEmpty();
}
// TODO: optimize this.
bool SkClipStack::isEmpty(const SkIRect& r) const { return this->bounds(r).isEmpty(); }
void SkClipStack::getBounds(SkRect* canvFiniteBound,
BoundsType* boundType,
bool* isIntersectionOfRects) const {

View File

@ -353,6 +353,9 @@ public:
BoundsType* boundType,
bool* isIntersectionOfRects = NULL) const;
SkRect bounds(const SkIRect& deviceBounds) const;
bool isEmpty(const SkIRect& deviceBounds) const;
/**
* Returns true if the input (r)rect in device space is entirely contained
* by the clip. A return value of false does not guarantee that the (r)rect

View File

@ -565,7 +565,7 @@ void SkPDFDevice::drawPoints(const SkDraw& d,
// We only use this when there's a path effect because of the overhead
// of multiple calls to setUpContentEntry it causes.
if (passedPaint.getPathEffect()) {
if (d.fRC->isEmpty()) {
if (d.fClipStack->isEmpty(this->getGlobalBounds())) {
return;
}
SkDraw pointDraw(d);
@ -689,7 +689,7 @@ void SkPDFDevice::drawRect(const SkDraw& d,
r.sort();
if (paint.getPathEffect()) {
if (d.fRC->isEmpty()) {
if (d.fClipStack->isEmpty(this->getGlobalBounds())) {
return;
}
SkPath path;
@ -751,7 +751,7 @@ void SkPDFDevice::drawPath(const SkDraw& d,
}
if (paint.getPathEffect()) {
if (d.fRC->isEmpty()) {
if (d.fClipStack->isEmpty(this->getGlobalBounds())) {
return;
}
if (!pathIsMutable) {
@ -871,7 +871,7 @@ void SkPDFDevice::drawBitmap(const SkDraw& d,
const SkBitmap& bitmap,
const SkMatrix& matrix,
const SkPaint& srcPaint) {
if (bitmap.drawsNothing() || d.fRC->isEmpty()) {
if (bitmap.drawsNothing() || d.fClipStack->isEmpty(this->getGlobalBounds())) {
return;
}
SkPaint paint = srcPaint;
@ -893,7 +893,7 @@ void SkPDFDevice::drawSprite(const SkDraw& d,
int x,
int y,
const SkPaint& srcPaint) {
if (bitmap.drawsNothing() || d.fRC->isEmpty()) {
if (bitmap.drawsNothing() || d.fClipStack->isEmpty(this->getGlobalBounds())) {
return;
}
SkPaint paint = srcPaint;
@ -915,7 +915,7 @@ void SkPDFDevice::drawImage(const SkDraw& draw,
SkScalar y,
const SkPaint& srcPaint) {
SkPaint paint = srcPaint;
if (!image || draw.fRC->isEmpty()) {
if (!image) {
return;
}
if (image->isOpaque()) {
@ -1439,7 +1439,7 @@ void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode,
const SkPoint texs[], const SkColor colors[],
SkBlendMode, const uint16_t indices[],
int indexCount, const SkPaint& paint) {
if (d.fRC->isEmpty()) {
if (d.fClipStack->isEmpty(this->getGlobalBounds())) {
return;
}
// TODO: implement drawVertices
@ -1571,7 +1571,7 @@ bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath,
return false;
}
if (d.fRC->isEmpty()) {
if (d.fClipStack->isEmpty(this->getGlobalBounds())) {
return false;
}
@ -1598,7 +1598,6 @@ bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath,
// Get bounds of clip in current transform space
// (clip bounds are given in device space).
SkRect bounds;
SkMatrix transformInverse;
SkMatrix totalMatrix = *d.fMatrix;
if (prePathMatrix) {
@ -1607,7 +1606,7 @@ bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath,
if (!totalMatrix.invert(&transformInverse)) {
return false;
}
bounds.set(d.fRC->getBounds());
SkRect bounds = SkRect::Make(d.fRC->getBounds());
transformInverse.mapRect(&bounds);
// Extend the bounds by the line width (plus some padding)
@ -1745,16 +1744,16 @@ void SkPDFDevice::drawFormXObjectWithMask(int xObjectIndex,
}
SkPDFDevice::ContentEntry* SkPDFDevice::setUpContentEntry(const SkClipStack* clipStack,
const SkRegion& clipRegion,
const SkMatrix& matrix,
const SkPaint& paint,
bool hasText,
sk_sp<SkPDFObject>* dst) {
const SkRegion& clipRegion,
const SkMatrix& matrix,
const SkPaint& paint,
bool hasText,
sk_sp<SkPDFObject>* dst) {
*dst = nullptr;
if (clipRegion.isEmpty()) {
return nullptr;
}
SkASSERT(clipStack);
SkBlendMode blendMode = paint.getBlendMode();
// For the following modes, we want to handle source and destination
@ -2275,7 +2274,8 @@ void SkPDFDevice::drawSpecial(const SkDraw& draw, SkSpecialImage* srcImg, int x,
SkIPoint offset = SkIPoint::Make(0, 0);
SkMatrix matrix = *draw.fMatrix;
matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y);
const SkIRect clipBounds =
draw.fClipStack->bounds(this->imageInfo().bounds()).roundOut().makeOffset(-x, -y);
sk_sp<SkImageFilterCache> cache(this->getImageFilterCache());
// TODO: Should PDF be operating in a specified color space? For now, run the filter
// in the same color space as the source (this is different from all other backends).