Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit aee26ea

Browse files
lhkbobSkia Commit-Bot
authored andcommitted
Reland "Switch drawTexture calls to use attemptQuadOptimization"
This reverts commit dcb832a. Reason for revert: chrome layout tests have been suppressed. Original change's description: > Revert "Switch drawTexture calls to use attemptQuadOptimization" > > This reverts commit 9b2defc. > > Reason for revert: Likely broke chrome layout tests > > Original change's description: > > Switch drawTexture calls to use attemptQuadOptimization > > > > Before the quad-rendering op refactor, regular filled rectangles and > > textured rectangles used an internal crop_filled_rect function to crop > > to the bounding box of the clip. As the quad op refactor progressed, > > regular filled rectangle drawing went through the new attemptQuadOptimization > > function that supported more cropping to the exact clip when axis-aligned, > > and could be better handle complex paints. > > > > Following the generalized factories added to GrTextureOp in earlier CLs, > > it is now possible to route all textured rectangle draws through the same > > optimizations. While there are a number of public interfaces for drawing > > rectangles and textures on GrRTC, internally there is now just drawFilledQuad > > (for complex paints) and drawTexturedQuad(for textures, avoids GrPaint use). > > Both of these are very similar, and share attemptQuadOptimization(), which > > makes all rectangle-drawing code, regardless of shader/paint/etc., handled > > in a consistent manner. > > > > This doesn't entirely resolve the complexities of non-AA clipping and non-AA > > axis-aligned rectangle drawing. That needs additional logic added to the > > GrQuadUtils::CropToRect function, but this CL is the last structural change > > to how the ops are created, and to GrRTC to get Ganesh to that stage. > > > > Change-Id: Icfbd223eef6e3da0054699334725b5084aaee58a > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/223934 > > Commit-Queue: Michael Ludwig <[email protected]> > > Reviewed-by: Brian Salomon <[email protected]> > > [email protected],[email protected] > > # Not skipping CQ checks because original CL landed > 1 day ago. > > Change-Id: Ide21002c336dbc3831a2b042acfec92a509ebacf > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/224639 > Reviewed-by: Michael Ludwig <[email protected]> > Commit-Queue: Michael Ludwig <[email protected]> [email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Bug: 981879 Change-Id: I32ed19d521bd7aed93da787b3de0ca830415f42f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/225725 Commit-Queue: Michael Ludwig <[email protected]> Reviewed-by: Michael Ludwig <[email protected]>
1 parent b021f3e commit aee26ea

File tree

2 files changed

+88
-135
lines changed

2 files changed

+88
-135
lines changed

src/gpu/GrRenderTargetContext.cpp

Lines changed: 55 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -441,58 +441,6 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip,
441441
}
442442
}
443443

444-
// Attempts to crop a rect and optional local rect to the clip boundaries.
445-
// Returns false if the draw can be skipped entirely.
446-
// FIXME to be removed once drawTexture et al are updated to use attemptQuadOptimization instead
447-
static bool crop_filled_rect(int width, int height, const GrClip& clip,
448-
const SkMatrix& viewMatrix, SkRect* rect,
449-
SkRect* localRect = nullptr) {
450-
if (!viewMatrix.rectStaysRect()) {
451-
return true;
452-
}
453-
454-
SkIRect clipDevBounds;
455-
SkRect clipBounds;
456-
457-
clip.getConservativeBounds(width, height, &clipDevBounds);
458-
if (!SkMatrixPriv::InverseMapRect(viewMatrix, &clipBounds, SkRect::Make(clipDevBounds))) {
459-
return false;
460-
}
461-
462-
if (localRect) {
463-
if (!rect->intersects(clipBounds)) {
464-
return false;
465-
}
466-
// localRect is force-sorted after clipping, so this is a sanity check to make sure callers
467-
// aren't intentionally using inverted local rectangles.
468-
SkASSERT(localRect->isSorted());
469-
const SkScalar dx = localRect->width() / rect->width();
470-
const SkScalar dy = localRect->height() / rect->height();
471-
if (clipBounds.fLeft > rect->fLeft) {
472-
localRect->fLeft += (clipBounds.fLeft - rect->fLeft) * dx;
473-
rect->fLeft = clipBounds.fLeft;
474-
}
475-
if (clipBounds.fTop > rect->fTop) {
476-
localRect->fTop += (clipBounds.fTop - rect->fTop) * dy;
477-
rect->fTop = clipBounds.fTop;
478-
}
479-
if (clipBounds.fRight < rect->fRight) {
480-
localRect->fRight -= (rect->fRight - clipBounds.fRight) * dx;
481-
rect->fRight = clipBounds.fRight;
482-
}
483-
if (clipBounds.fBottom < rect->fBottom) {
484-
localRect->fBottom -= (rect->fBottom - clipBounds.fBottom) * dy;
485-
rect->fBottom = clipBounds.fBottom;
486-
}
487-
// Ensure local coordinates remain sorted after clipping. If the original dstRect was very
488-
// large, numeric precision can invert the localRect
489-
localRect->sort();
490-
return true;
491-
}
492-
493-
return rect->intersect(clipBounds);
494-
}
495-
496444
enum class GrRenderTargetContext::QuadOptimization {
497445
// The rect to draw doesn't intersect clip or render target, so no draw op should be added
498446
kDiscarded,
@@ -718,6 +666,46 @@ void GrRenderTargetContext::drawFilledQuad(const GrClip& clip,
718666
// All other optimization levels were completely handled inside attempt(), so no extra op needed
719667
}
720668

669+
void GrRenderTargetContext::drawTexturedQuad(const GrClip& clip,
670+
sk_sp<GrTextureProxy> proxy,
671+
sk_sp<GrColorSpaceXform> textureXform,
672+
GrSamplerState::Filter filter,
673+
const SkPMColor4f& color,
674+
SkBlendMode blendMode,
675+
GrAA aa,
676+
GrQuadAAFlags edgeFlags,
677+
const GrQuad& deviceQuad,
678+
const GrQuad& localQuad,
679+
const SkRect* domain) {
680+
ASSERT_SINGLE_OWNER
681+
RETURN_IF_ABANDONED
682+
SkDEBUGCODE(this->validate();)
683+
GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTexturedQuad", fContext);
684+
685+
AutoCheckFlush acf(this->drawingManager());
686+
687+
// Functionally this is very similar to drawFilledQuad except that there's no constColor to
688+
// enable the kSubmitted optimizations, no stencil settings support, and its a GrTextureOp.
689+
GrQuad croppedDeviceQuad = deviceQuad;
690+
GrQuad croppedLocalQuad = localQuad;
691+
QuadOptimization opt = this->attemptQuadOptimization(clip, nullptr, nullptr, &aa, &edgeFlags,
692+
&croppedDeviceQuad, &croppedLocalQuad);
693+
694+
SkASSERT(opt != QuadOptimization::kSubmitted);
695+
if (opt != QuadOptimization::kDiscarded) {
696+
// And the texture op if not discarded
697+
const GrClip& finalClip = opt == QuadOptimization::kClipApplied ? GrFixedClip::Disabled()
698+
: clip;
699+
GrAAType aaType = this->chooseAAType(aa);
700+
// Use the provided domain, although hypothetically we could detect that the cropped local
701+
// quad is sufficiently inside the domain and the constraint could be dropped.
702+
this->addDrawOp(finalClip, GrTextureOp::Make(fContext, std::move(proxy),
703+
std::move(textureXform), filter, color,
704+
blendMode, aaType, edgeFlags,
705+
croppedDeviceQuad, croppedLocalQuad, domain));
706+
}
707+
}
708+
721709
void GrRenderTargetContext::drawRect(const GrClip& clip,
722710
GrPaint&& paint,
723711
GrAA aa,
@@ -929,67 +917,6 @@ void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip,
929917
fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps());
930918
}
931919

932-
void GrRenderTargetContext::drawTexture(const GrClip& clip, sk_sp<GrTextureProxy> proxy,
933-
GrSamplerState::Filter filter, SkBlendMode mode,
934-
const SkPMColor4f& color, const SkRect& srcRect,
935-
const SkRect& dstRect, GrAA aa, GrQuadAAFlags aaFlags,
936-
SkCanvas::SrcRectConstraint constraint,
937-
const SkMatrix& viewMatrix,
938-
sk_sp<GrColorSpaceXform> textureColorSpaceXform) {
939-
ASSERT_SINGLE_OWNER
940-
RETURN_IF_ABANDONED
941-
SkDEBUGCODE(this->validate();)
942-
GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTexture", fContext);
943-
944-
const SkRect* domain = nullptr;
945-
if (constraint == SkCanvas::kStrict_SrcRectConstraint &&
946-
!srcRect.contains(proxy->getWorstCaseBoundsRect())) {
947-
// The domain coordinates will be the original src rect, not the clipped src rect
948-
domain = &srcRect;
949-
}
950-
951-
GrAAType aaType = this->chooseAAType(aa);
952-
SkRect clippedDstRect = dstRect;
953-
SkRect clippedSrcRect = srcRect;
954-
if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &clippedDstRect,
955-
&clippedSrcRect)) {
956-
return;
957-
}
958-
959-
AutoCheckFlush acf(this->drawingManager());
960-
auto op = GrTextureOp::Make(
961-
fContext, std::move(proxy), std::move(textureColorSpaceXform), filter, color, mode,
962-
aaType, aaFlags, GrQuad::MakeFromRect(clippedDstRect, viewMatrix),
963-
GrQuad(clippedSrcRect), domain);
964-
this->addDrawOp(clip, std::move(op));
965-
}
966-
967-
void GrRenderTargetContext::drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy> proxy,
968-
GrSamplerState::Filter filter, SkBlendMode mode,
969-
const SkPMColor4f& color, const SkPoint srcQuad[4],
970-
const SkPoint dstQuad[4], GrAA aa,
971-
GrQuadAAFlags aaFlags, const SkRect* domain,
972-
const SkMatrix& viewMatrix,
973-
sk_sp<GrColorSpaceXform> texXform) {
974-
ASSERT_SINGLE_OWNER
975-
RETURN_IF_ABANDONED
976-
SkDEBUGCODE(this->validate();)
977-
GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTextureQuad", fContext);
978-
if (domain && domain->contains(proxy->getWorstCaseBoundsRect())) {
979-
domain = nullptr;
980-
}
981-
982-
GrAAType aaType = this->chooseAAType(aa);
983-
984-
// Unlike drawTexture(), don't bother cropping or optimizing the filter type since we're
985-
// sampling an arbitrary quad of the texture.
986-
AutoCheckFlush acf(this->drawingManager());
987-
auto op = GrTextureOp::Make(fContext, std::move(proxy), std::move(texXform), filter, color,
988-
mode, aaType, aaFlags, GrQuad::MakeFromSkQuad(dstQuad, viewMatrix),
989-
GrQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()), domain);
990-
this->addDrawOp(clip, std::move(op));
991-
}
992-
993920
void GrRenderTargetContext::drawTextureSet(const GrClip& clip, const TextureSetEntry set[], int cnt,
994921
GrSamplerState::Filter filter, SkBlendMode mode,
995922
GrAA aa, SkCanvas::SrcRectConstraint constraint,
@@ -1012,22 +939,23 @@ void GrRenderTargetContext::drawTextureSet(const GrClip& clip, const TextureSetE
1012939
ctm.preConcat(*set[i].fPreViewMatrix);
1013940
}
1014941

1015-
if (set[i].fDstClipQuad == nullptr) {
1016-
// Stick with original rectangles, which allows the ops to know more about what's
1017-
// being drawn.
1018-
this->drawTexture(clip, set[i].fProxy, filter, mode, {alpha, alpha, alpha, alpha},
1019-
set[i].fSrcRect, set[i].fDstRect, aa, set[i].fAAFlags,
1020-
constraint, ctm, texXform);
942+
GrQuad quad, srcQuad;
943+
if (set[i].fDstClipQuad) {
944+
quad = GrQuad::MakeFromSkQuad(set[i].fDstClipQuad, ctm);
945+
946+
SkPoint srcPts[4];
947+
GrMapRectPoints(set[i].fDstRect, set[i].fSrcRect, set[i].fDstClipQuad, srcPts, 4);
948+
srcQuad = GrQuad::MakeFromSkQuad(srcPts, SkMatrix::I());
1021949
} else {
1022-
// Generate interpolated texture coordinates to match the dst clip
1023-
SkPoint srcQuad[4];
1024-
GrMapRectPoints(set[i].fDstRect, set[i].fSrcRect, set[i].fDstClipQuad, srcQuad, 4);
1025-
const SkRect* domain = constraint == SkCanvas::kStrict_SrcRectConstraint
1026-
? &set[i].fSrcRect : nullptr;
1027-
this->drawTextureQuad(clip, set[i].fProxy, filter, mode,
1028-
{alpha, alpha, alpha, alpha}, srcQuad, set[i].fDstClipQuad,
1029-
aa, set[i].fAAFlags, domain, ctm, texXform);
950+
quad = GrQuad::MakeFromRect(set[i].fDstRect, ctm);
951+
srcQuad = GrQuad(set[i].fSrcRect);
1030952
}
953+
954+
const SkRect* domain = constraint == SkCanvas::kStrict_SrcRectConstraint
955+
? &set[i].fSrcRect : nullptr;
956+
this->drawTexturedQuad(clip, set[i].fProxy, texXform, filter,
957+
{alpha, alpha, alpha, alpha}, mode, aa, set[i].fAAFlags,
958+
quad, srcQuad, domain);
1031959
}
1032960
} else {
1033961
// Can use a single op, avoiding GrPaint creation, and can batch across proxies

src/gpu/GrRenderTargetContext.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,33 @@ class SK_API GrRenderTargetContext : public GrSurfaceContext {
190190
* specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
191191
* device space.
192192
*/
193-
void drawTexture(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter,
194-
SkBlendMode mode, const SkPMColor4f&, const SkRect& srcRect,
195-
const SkRect& dstRect, GrAA, GrQuadAAFlags, SkCanvas::SrcRectConstraint,
196-
const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform);
193+
void drawTexture(const GrClip& clip, sk_sp<GrTextureProxy> proxy, GrSamplerState::Filter filter,
194+
SkBlendMode mode, const SkPMColor4f& color, const SkRect& srcRect,
195+
const SkRect& dstRect, GrAA aa, GrQuadAAFlags edgeAA,
196+
SkCanvas::SrcRectConstraint constraint, const SkMatrix& viewMatrix,
197+
sk_sp<GrColorSpaceXform> texXform) {
198+
const SkRect* domain = constraint == SkCanvas::kStrict_SrcRectConstraint ?
199+
&srcRect : nullptr;
200+
this->drawTexturedQuad(clip, std::move(proxy), std::move(texXform), filter,
201+
color, mode, aa, edgeAA, GrQuad::MakeFromRect(dstRect, viewMatrix),
202+
GrQuad(srcRect), domain);
203+
}
197204

198205
/**
199206
* Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by
200207
* 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'domain'. If
201208
* 'domain' is null, it's equivalent to using the fast src rect constraint. If 'domain' is
202209
* provided, the strict src rect constraint is applied using 'domain'.
203210
*/
204-
void drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter,
205-
SkBlendMode mode, const SkPMColor4f&, const SkPoint srcQuad[4],
206-
const SkPoint dstQuad[4], GrAA, GrQuadAAFlags, const SkRect* domain,
207-
const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform);
211+
void drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy> proxy,
212+
GrSamplerState::Filter filter, SkBlendMode mode, const SkPMColor4f& color,
213+
const SkPoint srcQuad[4], const SkPoint dstQuad[4], GrAA aa,
214+
GrQuadAAFlags edgeAA, const SkRect* domain, const SkMatrix& viewMatrix,
215+
sk_sp<GrColorSpaceXform> texXform) {
216+
this->drawTexturedQuad(clip, std::move(proxy), std::move(texXform), filter, color, mode,
217+
aa, edgeAA, GrQuad::MakeFromSkQuad(dstQuad, viewMatrix),
218+
GrQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()), domain);
219+
}
208220

209221
/** Used with drawTextureSet */
210222
struct TextureSetEntry {
@@ -572,6 +584,19 @@ class SK_API GrRenderTargetContext : public GrSurfaceContext {
572584
const GrQuad& localQuad,
573585
const GrUserStencilSettings* ss = nullptr);
574586

587+
// Like drawFilledQuad but does not require using a GrPaint or FP for texturing
588+
void drawTexturedQuad(const GrClip& clip,
589+
sk_sp<GrTextureProxy> proxy,
590+
sk_sp<GrColorSpaceXform> textureXform,
591+
GrSamplerState::Filter filter,
592+
const SkPMColor4f& color,
593+
SkBlendMode blendMode,
594+
GrAA aa,
595+
GrQuadAAFlags edgeFlags,
596+
const GrQuad& deviceQuad,
597+
const GrQuad& localQuad,
598+
const SkRect* domain = nullptr);
599+
575600
void drawShapeUsingPathRenderer(const GrClip&, GrPaint&&, GrAA, const SkMatrix&,
576601
const GrShape&);
577602

0 commit comments

Comments
 (0)