Simplify GrClip::getConservativeBounds() signature

It turns out no one was using the intersection of rect functionality on
GrClip, and this helps simplify what the new clip stack needs to define.

Bug: skia:10205
Change-Id: If85a0c744dd68a8ad2f380b54a539ac74850e4ac
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/289440
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Michael Ludwig 2020-05-13 14:17:57 -04:00 committed by Skia Commit-Bot
parent 7190399725
commit c002d5619e
17 changed files with 60 additions and 102 deletions

View File

@ -162,12 +162,6 @@ class MaskOnlyClipBase : public GrClip {
private:
bool quickContains(const SkRect&) const final { return false; }
bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; }
void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final {
rect->setWH(width, height);
if (iior) {
*iior = false;
}
}
};
/**

View File

@ -245,9 +245,8 @@ static bool get_shape_and_clip_bounds(GrRenderTargetContext* renderTargetContext
SkIRect* unclippedDevShapeBounds,
SkIRect* devClipBounds) {
// compute bounds as intersection of rt size, clip, and path
clip.getConservativeBounds(renderTargetContext->width(),
renderTargetContext->height(),
devClipBounds);
*devClipBounds = clip.getConservativeBounds(renderTargetContext->width(),
renderTargetContext->height());
if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
*unclippedDevShapeBounds = SkIRect::MakeEmpty();

View File

@ -25,8 +25,15 @@ public:
virtual bool quickContains(const SkRRect& rrect) const {
return this->quickContains(rrect.getBounds());
}
virtual void getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects = nullptr) const = 0;
/**
* Compute a conservative pixel bounds restricted to the given render target dimensions.
* The returned bounds represent the limits of pixels that can be drawn; anything outside of the
* bounds will be entirely clipped out.
*/
virtual SkIRect getConservativeBounds(int width, int height) const {
return SkIRect::MakeWH(width, height);
}
/**
* This computes a GrAppliedClip from the clip which in turn can be used to build a GrPipeline.
* To determine the appropriate clipping implementation the GrClip subclass must know whether
@ -160,13 +167,6 @@ class GrNoClip final : public GrHardClip {
private:
bool quickContains(const SkRect&) const final { return true; }
bool quickContains(const SkRRect&) const final { return true; }
void getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const final {
devResult->setXYWH(0, 0, width, height);
if (isIntersectionOfRects) {
*isIntersectionOfRects = true;
}
}
bool apply(int rtWidth, int rtHeight, GrAppliedHardClip*, SkRect*) const final { return true; }
bool isRRect(const SkRect&, SkRRect*, GrAA*) const override { return false; }
};

View File

@ -62,18 +62,14 @@ bool GrClipStackClip::isRRect(const SkRect& origRTBounds, SkRRect* rr, GrAA* aa)
return false;
}
void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const {
if (!fStack) {
devResult->setXYWH(0, 0, width, height);
if (isIntersectionOfRects) {
*isIntersectionOfRects = true;
}
return;
SkIRect GrClipStackClip::getConservativeBounds(int width, int height) const {
if (fStack) {
SkRect devBounds;
fStack->getConservativeBounds(0, 0, width, height, &devBounds);
return devBounds.roundOut();
} else {
return this->GrClip::getConservativeBounds(width, height);
}
SkRect devBounds;
fStack->getConservativeBounds(0, 0, width, height, &devBounds, isIntersectionOfRects);
devBounds.roundOut(devResult);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -26,8 +26,7 @@ public:
bool quickContains(const SkRect&) const final;
bool quickContains(const SkRRect&) const final;
void getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const final;
SkIRect getConservativeBounds(int width, int height) const final;
bool apply(GrRecordingContext*, GrRenderTargetContext*, bool useHWAA,
bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const final;

View File

@ -17,16 +17,14 @@ bool GrFixedClip::quickContains(const SkRect& rect) const {
return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect);
}
void GrFixedClip::getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const {
devResult->setXYWH(0, 0, w, h);
SkIRect GrFixedClip::getConservativeBounds(int w, int h) const {
SkIRect devResult = this->GrClip::getConservativeBounds(w, h);
if (fScissorState.enabled()) {
if (!devResult->intersect(fScissorState.rect())) {
devResult->setEmpty();
if (!devResult.intersect(fScissorState.rect())) {
devResult.setEmpty();
}
}
if (iior) {
*iior = true;
}
return devResult;
}
bool GrFixedClip::isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const {

View File

@ -43,7 +43,7 @@ public:
}
bool quickContains(const SkRect&) const override;
void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override;
SkIRect getConservativeBounds(int w, int h) const override;
bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const override;
bool apply(int rtWidth, int rtHeight, GrAppliedHardClip*, SkRect*) const override;

View File

@ -771,9 +771,7 @@ GrRenderTargetContext::QuadOptimization GrRenderTargetContext::attemptQuadOptimi
}
// Crop the quad to the conservative bounds of the clip.
SkIRect clipDevBounds;
clip.getConservativeBounds(rtRect.width(), rtRect.height(), &clipDevBounds);
SkRect clipBounds = SkRect::Make(clipDevBounds);
SkRect clipBounds = SkRect::Make(clip.getConservativeBounds(rtRect.width(), rtRect.height()));
// One final check for discarding, since we may have gone here directly due to a complex clip
if (!clipBounds.intersects(drawBounds)) {
@ -2304,9 +2302,8 @@ bool GrRenderTargetContextPriv::drawAndStencilPath(const GrHardClip& clip,
GrAAType aaType = fRenderTargetContext->chooseAAType(aa);
bool hasUserStencilSettings = !ss->isUnused();
SkIRect clipConservativeBounds;
clip.getConservativeBounds(fRenderTargetContext->width(), fRenderTargetContext->height(),
&clipConservativeBounds, nullptr);
SkIRect clipConservativeBounds = clip.getConservativeBounds(fRenderTargetContext->width(),
fRenderTargetContext->height());
GrPaint paint;
paint.setCoverageSetOpXPFactory(op, invert);
@ -2379,8 +2376,7 @@ void GrRenderTargetContext::drawShapeUsingPathRenderer(const GrClip& clip,
return;
}
SkIRect clipConservativeBounds;
clip.getConservativeBounds(this->width(), this->height(), &clipConservativeBounds, nullptr);
SkIRect clipConservativeBounds = clip.getConservativeBounds(this->width(), this->height());
GrStyledShape tempShape;
GrAAType aaType = this->chooseAAType(aa);
@ -2567,9 +2563,7 @@ bool GrRenderTargetContext::setupDstProxyView(const GrClip& clip, const GrOp& op
SkIRect copyRect = SkIRect::MakeSize(this->asSurfaceProxy()->dimensions());
SkIRect clippedRect;
clip.getConservativeBounds(
this->width(), this->height(), &clippedRect);
SkIRect clippedRect = clip.getConservativeBounds(this->width(), this->height());
SkRect opBounds = op.bounds();
// If the op has aa bloating or is a infinitely thin geometry (hairline) outset the bounds by
// 0.5 pixels.

View File

@ -75,9 +75,8 @@ bool GrSoftwarePathRenderer::GetShapeAndClipBounds(GrRenderTargetContext* render
SkIRect* clippedDevShapeBounds,
SkIRect* devClipBounds) {
// compute bounds as intersection of rt size, clip, and path
clip.getConservativeBounds(renderTargetContext->width(),
renderTargetContext->height(),
devClipBounds);
*devClipBounds = clip.getConservativeBounds(renderTargetContext->width(),
renderTargetContext->height());
if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
*unclippedDevShapeBounds = SkIRect::MakeEmpty();

View File

@ -33,8 +33,8 @@ public:
bool quickContains(const SkRect& rect) const override {
return !this->hasStencilClip() && fFixedClip.quickContains(rect);
}
void getConservativeBounds(int width, int height, SkIRect* bounds, bool* iior) const override {
fFixedClip.getConservativeBounds(width, height, bounds, iior);
SkIRect getConservativeBounds(int width, int height) const override {
return fFixedClip.getConservativeBounds(width, height);
}
bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override {
return !this->hasStencilClip() && fFixedClip.isRRect(rtBounds, rr, aa);

View File

@ -124,32 +124,31 @@ static int determine_tile_size(const SkIRect& src, int maxTileSize) {
// Given a bitmap, an optional src rect, and a context with a clip and matrix determine what
// pixels from the bitmap are necessary.
static void determine_clipped_src_rect(int width, int height,
const GrClip& clip,
const SkMatrix& viewMatrix,
const SkMatrix& srcToDstRect,
const SkISize& imageDimensions,
const SkRect* srcRectPtr,
SkIRect* clippedSrcIRect) {
clip.getConservativeBounds(width, height, clippedSrcIRect, nullptr);
static SkIRect determine_clipped_src_rect(int width, int height,
const GrClip& clip,
const SkMatrix& viewMatrix,
const SkMatrix& srcToDstRect,
const SkISize& imageDimensions,
const SkRect* srcRectPtr) {
SkIRect clippedSrcIRect = clip.getConservativeBounds(width, height);
SkMatrix inv = SkMatrix::Concat(viewMatrix, srcToDstRect);
if (!inv.invert(&inv)) {
clippedSrcIRect->setEmpty();
return;
return SkIRect::MakeEmpty();
}
SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect);
SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect);
inv.mapRect(&clippedSrcRect);
if (srcRectPtr) {
if (!clippedSrcRect.intersect(*srcRectPtr)) {
clippedSrcIRect->setEmpty();
return;
return SkIRect::MakeEmpty();
}
}
clippedSrcRect.roundOut(clippedSrcIRect);
clippedSrcRect.roundOut(&clippedSrcIRect);
SkIRect bmpBounds = SkIRect::MakeSize(imageDimensions);
if (!clippedSrcIRect->intersect(bmpBounds)) {
clippedSrcIRect->setEmpty();
if (!clippedSrcIRect.intersect(bmpBounds)) {
return SkIRect::MakeEmpty();
}
return clippedSrcIRect;
}
// tileSize and clippedSubset are valid if true is returned
@ -166,8 +165,8 @@ static bool should_tile_image_id(GrContext* context,
SkIRect* clippedSubset) {
// if it's larger than the max tile size, then we have no choice but tiling.
if (imageSize.width() > maxTileSize || imageSize.height() > maxTileSize) {
determine_clipped_src_rect(rtSize.width(), rtSize.height(), clip, ctm, srcToDst,
imageSize, src, clippedSubset);
*clippedSubset = determine_clipped_src_rect(rtSize.width(), rtSize.height(), clip, ctm,
srcToDst, imageSize, src);
*tileSize = determine_tile_size(*clippedSubset, maxTileSize);
return true;
}
@ -199,8 +198,8 @@ static bool should_tile_image_id(GrContext* context,
// Figure out how much of the src we will need based on the src rect and clipping. Reject if
// tiling memory savings would be < 50%.
determine_clipped_src_rect(rtSize.width(), rtSize.height(), clip, ctm, srcToDst, imageSize, src,
clippedSubset);
*clippedSubset = determine_clipped_src_rect(rtSize.width(), rtSize.height(), clip, ctm,
srcToDst, imageSize, src);
*tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile.
size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) *
kBmpSmallTileSize * kBmpSmallTileSize *

View File

@ -167,9 +167,8 @@ GrPathRenderer::CanDrawPath GrCoverageCountingPathRenderer::onCanDrawPath(
bool GrCoverageCountingPathRenderer::onDrawPath(const DrawPathArgs& args) {
SkASSERT(!fFlushing);
SkIRect clipIBounds;
GrRenderTargetContext* rtc = args.fRenderTargetContext;
args.fClip->getConservativeBounds(rtc->width(), rtc->height(), &clipIBounds, nullptr);
SkIRect clipIBounds = args.fClip->getConservativeBounds(rtc->width(), rtc->height());
auto op = GrCCDrawPathsOp::Make(args.fContext, clipIBounds, *args.fViewMatrix, *args.fShape,
std::move(args.fPaint));

View File

@ -1272,10 +1272,8 @@ bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
"GrAAHairlinePathRenderer::onDrawPath");
SkASSERT(args.fRenderTargetContext->numSamples() <= 1);
SkIRect devClipBounds;
args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
args.fRenderTargetContext->height(),
&devClipBounds);
SkIRect devClipBounds = args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
args.fRenderTargetContext->height());
SkPath path;
args.fShape->asPath(&path);
std::unique_ptr<GrDrawOp> op =

View File

@ -419,10 +419,8 @@ private:
bool GrTriangulatingPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrTriangulatingPathRenderer::onDrawPath");
SkIRect clipBoundsI;
args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
args.fRenderTargetContext->height(),
&clipBoundsI);
SkIRect clipBoundsI = args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
args.fRenderTargetContext->height());
std::unique_ptr<GrDrawOp> op = TriangulatingPathOp::Make(
args.fContext, std::move(args.fPaint), *args.fShape, *args.fViewMatrix, clipBoundsI,
args.fAAType, args.fUserStencilSettings);

View File

@ -43,12 +43,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) {
// wrap the SkClipStack in a GrClip
GrClipStackClip clipData(&stack);
SkIRect devGrClipBound;
clipData.getConservativeBounds(kXSize, kYSize,
&devGrClipBound,
&isIntersectionOfRects);
SkIRect devGrClipBound = clipData.getConservativeBounds(kXSize, kYSize);
// make sure that GrClip is behaving itself
REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
REPORTER_ASSERT(reporter, isIntersectionOfRects);
}

View File

@ -48,12 +48,7 @@ private:
}
bool quickContains(const SkRect&) const final { return false; }
bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; }
void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final {
rect->setWH(width, height);
if (iior) {
*iior = false;
}
}
GrCoverageCountingPathRenderer* const fCCPR;
const SkPath fPath;
};

View File

@ -185,12 +185,6 @@ public:
}
bool quickContains(const SkRect&) const final { return false; }
bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; }
void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final {
rect->setLTRB(0, 0, width, height);
if (iior) {
*iior = false;
}
}
LazyProxyTest* const fTest;
GrTextureProxy* fAtlas;