Pass sampling to drawImageSet

Bug: skia:7650
Change-Id: I93d41ca6e5beb85e9924ea2f3e0a82c18ff51369
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/349617
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-01-05 12:03:47 -05:00 committed by Skia Commit-Bot
parent 5933d4c8e5
commit 4f509345ab
26 changed files with 314 additions and 79 deletions

View File

@ -1939,6 +1939,11 @@ public:
* image set is drawn as if each image used the applied paint independently, so each is affected
* by the image, color, and/or mask filter.
*/
void experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkSamplingOptions&, const SkPaint* paint = nullptr,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
// DEPRECATED -- pass sampling directly
void experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint = nullptr,
@ -2536,6 +2541,9 @@ protected:
const SkRect* cull, const SkPaint* paint);
// never called -- remove from clients' subclasses
virtual void onDrawImageNine(const SkImage*, const SkIRect&, const SkRect&, const SkPaint*) {}
virtual void onDrawEdgeAAImageSet(const ImageSetEntry imageSet[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint);
#endif
virtual void onDrawImage2(const SkImage*, SkScalar dx, SkScalar dy, const SkSamplingOptions&,
const SkPaint*);
@ -2546,6 +2554,10 @@ protected:
virtual void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect src[],
const SkColor[], int count, SkBlendMode, const SkSamplingOptions&,
const SkRect* cull, const SkPaint*);
virtual void onDrawEdgeAAImageSet2(const ImageSetEntry imageSet[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkSamplingOptions&, const SkPaint*,
SrcRectConstraint);
virtual void onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode,
const SkPaint& paint);
@ -2559,9 +2571,6 @@ protected:
virtual void onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], QuadAAFlags aaFlags,
const SkColor4f& color, SkBlendMode mode);
virtual void onDrawEdgeAAImageSet(const ImageSetEntry imageSet[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint);
enum ClipEdgeStyle {
kHard_ClipEdgeStyle,

View File

@ -45,15 +45,9 @@ protected:
// implementations in Android's SkCanvas subclasses until this stabilizes.
void onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
SkCanvas::QuadAAFlags aaFlags, const SkColor4f& color, SkBlendMode mode) override {}
void onDrawEdgeAAImageSet(const SkCanvas::ImageSetEntry imageSet[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint) override {}
#else
void onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
SkCanvas::QuadAAFlags aaFlags, const SkColor4f& color, SkBlendMode mode) override = 0;
void onDrawEdgeAAImageSet(const SkCanvas::ImageSetEntry imageSet[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint) override = 0;
#endif
void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override = 0;

View File

@ -43,6 +43,8 @@ public:
const SkPaint*) override;
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int, SkBlendMode, const SkRect*, const SkPaint*) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
#endif
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
const SkPaint*) override;
@ -61,8 +63,8 @@ public:
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], SkCanvas::QuadAAFlags, const SkColor4f&,
SkBlendMode) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkSamplingOptions&,const SkPaint*, SrcRectConstraint) override;
private:
void drawPosTextCommon(const SkGlyphID[], int, const SkScalar[], int, const SkPoint&,

View File

@ -59,6 +59,8 @@ protected:
const SkPaint*) override;
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int, SkBlendMode, const SkRect*, const SkPaint*) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
#endif
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
const SkPaint*) override;
@ -84,8 +86,8 @@ protected:
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
SkBlendMode) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkSamplingOptions&,const SkPaint*, SrcRectConstraint) override;
void onFlush() override;

View File

@ -61,6 +61,8 @@ protected:
const SkPaint*) override {}
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int, SkBlendMode, const SkRect*, const SkPaint*) override {}
void onDrawEdgeAAImageSet(const ImageSetEntry[], int, const SkPoint[],
const SkMatrix[], const SkPaint*, SrcRectConstraint) override {}
#endif
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
const SkPaint*) override {}
@ -77,8 +79,9 @@ protected:
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
SkBlendMode) override {}
void onDrawEdgeAAImageSet(const ImageSetEntry[], int, const SkPoint[],
const SkMatrix[], const SkPaint*, SrcRectConstraint) override {}
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int, const SkPoint[], const SkMatrix[],
const SkSamplingOptions&, const SkPaint*,
SrcRectConstraint) override {}
private:
using INHERITED = SkCanvasVirtualEnforcer<SkCanvas>;

View File

@ -65,6 +65,8 @@ protected:
const SkPaint*) override;
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int, SkBlendMode, const SkRect*, const SkPaint*) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
#endif
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
const SkPaint*) override;
@ -89,8 +91,8 @@ protected:
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
SkBlendMode) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkSamplingOptions&,const SkPaint*, SrcRectConstraint) override;
// Forwarded to the wrapped canvas.
sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;

View File

@ -2100,8 +2100,25 @@ void SkCanvas::experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], i
const SkMatrix preViewMatrices[],
const SkPaint* paint,
SrcRectConstraint constraint) {
#ifdef SK_SUPPORT_LEGACY_ONDRAWIMAGERECT
TRACE_EVENT0("skia", TRACE_FUNC);
this->onDrawEdgeAAImageSet(imageSet, cnt, dstClips, preViewMatrices, paint, constraint);
#else
this->experimental_DrawEdgeAAImageSet(imageSet, cnt, dstClips, preViewMatrices,
paint_to_sampling(paint, this->recordingContext()),
paint, constraint);
#endif
}
void SkCanvas::experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling,
const SkPaint* paint,
SrcRectConstraint constraint) {
TRACE_EVENT0("skia", TRACE_FUNC);
this->onDrawEdgeAAImageSet2(imageSet, cnt, dstClips, preViewMatrices, sampling, paint,
constraint);
}
//////////////////////////////////////////////////////////////////////////////
@ -2423,6 +2440,49 @@ void SkCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const
AutoLayerForImageFilter layer(this, realPaint);
this->topDevice()->drawAtlas(atlas, xform, tex, colors, count, bmode, sampling, layer.paint());
}
void SkCanvas::onDrawEdgeAAImageSet(const ImageSetEntry imageSet[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint) {
if (count <= 0) {
// Nothing to draw
return;
}
SkPaint realPaint = clean_paint_for_drawImage(paint);
// We could calculate the set's dstRect union to always check quickReject(), but we can't reject
// individual entries and Chromium's occlusion culling already makes it likely that at least one
// entry will be visible. So, we only calculate the draw bounds when it's trivial (count == 1),
// or we need it for the autolooper (since it greatly improves image filter perf).
bool needsAutoLayer = SkToBool(realPaint.getImageFilter());
bool setBoundsValid = count == 1 || needsAutoLayer;
SkRect setBounds = imageSet[0].fDstRect;
if (imageSet[0].fMatrixIndex >= 0) {
// Account for the per-entry transform that is applied prior to the CTM when drawing
preViewMatrices[imageSet[0].fMatrixIndex].mapRect(&setBounds);
}
if (needsAutoLayer) {
for (int i = 1; i < count; ++i) {
SkRect entryBounds = imageSet[i].fDstRect;
if (imageSet[i].fMatrixIndex >= 0) {
preViewMatrices[imageSet[i].fMatrixIndex].mapRect(&entryBounds);
}
setBounds.joinPossiblyEmptyRect(entryBounds);
}
}
// If we happen to have the draw bounds, though, might as well check quickReject().
if (setBoundsValid && this->internalQuickReject(setBounds, realPaint)) {
return;
}
AutoLayerForImageFilter layer(this, realPaint, setBoundsValid ? &setBounds : nullptr);
this->topDevice()->drawEdgeAAImageSet(imageSet, count, dstClips, preViewMatrices,
SkSamplingOptions(SkPaintPriv::GetFQ(layer.paint())),
layer.paint(), constraint);
}
#endif
void SkCanvas::onDrawImage2(const SkImage* image, SkScalar x, SkScalar y,
@ -2661,9 +2721,10 @@ void SkCanvas::onDrawEdgeAAQuad(const SkRect& r, const SkPoint clip[4], QuadAAFl
this->topDevice()->drawEdgeAAQuad(r, clip, edgeAA, color, mode);
}
void SkCanvas::onDrawEdgeAAImageSet(const ImageSetEntry imageSet[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint) {
void SkCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry imageSet[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling, const SkPaint* paint,
SrcRectConstraint constraint) {
if (count <= 0) {
// Nothing to draw
return;
@ -2698,8 +2759,8 @@ void SkCanvas::onDrawEdgeAAImageSet(const ImageSetEntry imageSet[], int count,
}
AutoLayerForImageFilter layer(this, realPaint, setBoundsValid ? &setBounds : nullptr);
this->topDevice()->drawEdgeAAImageSet(imageSet, count, dstClips, preViewMatrices,
layer.paint(), constraint);
this->topDevice()->drawEdgeAAImageSet(imageSet, count, dstClips, preViewMatrices, sampling,
layer.paint(), constraint);
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -257,13 +257,11 @@ void SkBaseDevice::drawEdgeAAQuad(const SkRect& r, const SkPoint clip[4], SkCanv
void SkBaseDevice::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry images[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint& paint,
const SkSamplingOptions& sampling, const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) {
SkASSERT(paint.getStyle() == SkPaint::kFill_Style);
SkASSERT(!paint.getPathEffect());
// TODO: pass this in directly
const SkSamplingOptions sampling(paint.getFilterQuality());
SkPaint entryPaint = paint;
const SkM44 baseLocalToDevice = this->localToDevice44();
int clipIndex = 0;

View File

@ -298,7 +298,8 @@ protected:
// are all set. If there's a clip region, it will be applied using clipPath().
virtual void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint& paint, SkCanvas::SrcRectConstraint);
const SkSamplingOptions&, const SkPaint&,
SkCanvas::SrcRectConstraint);
void drawGlyphRunRSXform(const SkFont&, const SkGlyphID[], const SkRSXform[], int count,
SkPoint origin, const SkPaint& paint);

View File

@ -197,6 +197,28 @@ void SkOverdrawCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[]
fList[0]->onDrawAtlas(image, xform, texs, colors, count, mode, cull, paintPtr);
}
void SkOverdrawCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[], const SkPaint* paint,
SrcRectConstraint constraint) {
int clipIndex = 0;
for (int i = 0; i < count; ++i) {
if (set[i].fMatrixIndex >= 0) {
fList[0]->save();
fList[0]->concat(preViewMatrices[set[i].fMatrixIndex]);
}
if (set[i].fHasClip) {
fList[0]->onDrawPath(SkPath::Polygon(dstClips + clipIndex, 4, true), fPaint);
clipIndex += 4;
} else {
fList[0]->onDrawRect(set[i].fDstRect, fPaint);
}
if (set[i].fMatrixIndex >= 0) {
fList[0]->restore();
}
}
}
#endif
void SkOverdrawCanvas::onDrawImage2(const SkImage* image, SkScalar x, SkScalar y,
@ -256,10 +278,12 @@ void SkOverdrawCanvas::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4
}
}
void SkOverdrawCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[], const SkPaint* paint,
SrcRectConstraint constraint) {
void SkOverdrawCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling,
const SkPaint* paint,
SrcRectConstraint constraint) {
int clipIndex = 0;
for (int i = 0; i < count; ++i) {
if (set[i].fMatrixIndex >= 0) {

View File

@ -112,8 +112,9 @@ enum DrawType {
DRAW_IMAGE2,
DRAW_IMAGE_RECT2,
DRAW_IMAGE_LATTICE2,
DRAW_EDGEAA_IMAGE_SET2,
LAST_DRAWTYPE_ENUM = DRAW_IMAGE_LATTICE2,
LAST_DRAWTYPE_ENUM = DRAW_EDGEAA_IMAGE_SET2,
};
enum DrawVertexFlags {

View File

@ -277,7 +277,8 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
BREAK_ON_READ_ERROR(reader);
canvas->experimental_DrawEdgeAAQuad(rect, clip, aaFlags, color, blend);
} break;
case DRAW_EDGEAA_IMAGE_SET: {
case DRAW_EDGEAA_IMAGE_SET:
case DRAW_EDGEAA_IMAGE_SET2: {
static const size_t kEntryReadSize =
4 * sizeof(uint32_t) + 2 * sizeof(SkRect) + sizeof(SkScalar);
static const size_t kMatrixSize = 9 * sizeof(SkScalar); // != sizeof(SkMatrix)
@ -288,6 +289,14 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
}
const SkPaint* paint = fPictureData->optionalPaint(reader);
SkSamplingOptions sampling;
if (op == DRAW_EDGEAA_IMAGE_SET2) {
sampling = reader->readSampling();
} else {
sampling = SkSamplingOptions(paint ? paint->getFilterQuality()
: kNone_SkFilterQuality);
}
SkCanvas::SrcRectConstraint constraint =
reader->checkRange(SkCanvas::kStrict_SrcRectConstraint,
SkCanvas::kFast_SrcRectConstraint);
@ -343,7 +352,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
BREAK_ON_READ_ERROR(reader);
canvas->experimental_DrawEdgeAAImageSet(set.get(), cnt, dstClips, matrices.begin(),
paint, constraint);
sampling, paint, constraint);
} break;
case DRAW_IMAGE: {
const SkPaint* paint = fPictureData->optionalPaint(reader);

View File

@ -614,6 +614,41 @@ void SkPictureRecord::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[],
this->validate(initialOffset, size);
}
void SkPictureRecord::onDrawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint) {
static constexpr size_t kMatrixSize = 9 * sizeof(SkScalar); // *not* sizeof(SkMatrix)
// op + count + paint + constraint + (image index, src rect, dst rect, alpha, aa flags,
// hasClip(int), matrixIndex) * cnt + totalClipCount + dstClips + totalMatrixCount + matrices
int totalDstClipCount, totalMatrixCount;
SkCanvasPriv::GetDstClipAndMatrixCounts(set, count, &totalDstClipCount, &totalMatrixCount);
size_t size = 6 * kUInt32Size + sizeof(SkPoint) * totalDstClipCount +
kMatrixSize * totalMatrixCount +
(4 * kUInt32Size + 2 * sizeof(SkRect) + sizeof(SkScalar)) * count;
size_t initialOffset = this->addDraw(DRAW_EDGEAA_IMAGE_SET, &size);
this->addInt(count);
this->addPaintPtr(paint);
this->addInt((int) constraint);
for (int i = 0; i < count; ++i) {
this->addImage(set[i].fImage.get());
this->addRect(set[i].fSrcRect);
this->addRect(set[i].fDstRect);
this->addInt(set[i].fMatrixIndex);
this->addScalar(set[i].fAlpha);
this->addInt((int)set[i].fAAFlags);
this->addInt(set[i].fHasClip);
}
this->addInt(totalDstClipCount);
this->addPoints(dstClips, totalDstClipCount);
this->addInt(totalMatrixCount);
for (int i = 0; i < totalMatrixCount; ++i) {
this->addMatrix(preViewMatrices[i]);
}
this->validate(initialOffset, size);
}
#endif
void SkPictureRecord::onDrawImage2(const SkImage* image, SkScalar x, SkScalar y,
@ -850,11 +885,12 @@ void SkPictureRecord::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4]
this->validate(initialOffset, size);
}
void SkPictureRecord::onDrawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint) {
void SkPictureRecord::onDrawEdgeAAImageSet2(const SkCanvas::ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling,
const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint) {
static constexpr size_t kMatrixSize = 9 * sizeof(SkScalar); // *not* sizeof(SkMatrix)
// op + count + paint + constraint + (image index, src rect, dst rect, alpha, aa flags,
// hasClip(int), matrixIndex) * cnt + totalClipCount + dstClips + totalMatrixCount + matrices
@ -863,10 +899,12 @@ void SkPictureRecord::onDrawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[],
size_t size = 6 * kUInt32Size + sizeof(SkPoint) * totalDstClipCount +
kMatrixSize * totalMatrixCount +
(4 * kUInt32Size + 2 * sizeof(SkRect) + sizeof(SkScalar)) * count;
size_t initialOffset = this->addDraw(DRAW_EDGEAA_IMAGE_SET, &size);
(4 * kUInt32Size + 2 * sizeof(SkRect) + sizeof(SkScalar)) * count +
SkSamplingPriv::kFlatSize;
size_t initialOffset = this->addDraw(DRAW_EDGEAA_IMAGE_SET2, &size);
this->addInt(count);
this->addPaintPtr(paint);
this->addSampling(sampling);
this->addInt((int) constraint);
for (int i = 0; i < count; ++i) {
this->addImage(set[i].fImage.get());

View File

@ -194,6 +194,8 @@ protected:
const SkPaint*) override;
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
SkBlendMode, const SkRect*, const SkPaint*) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
#endif
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
const SkPaint*) override;
@ -220,8 +222,8 @@ protected:
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
SkBlendMode) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkSamplingOptions&,const SkPaint*, SrcRectConstraint) override;
int addPathToHeap(const SkPath& path); // does not write to ops stream

View File

@ -158,6 +158,8 @@ DRAW(DrawEdgeAAQuad, experimental_DrawEdgeAAQuad(
r.rect, r.clip, r.aa, r.color, r.mode));
DRAW(DrawEdgeAAImageSet, experimental_DrawEdgeAAImageSet(
r.set.get(), r.count, r.dstClips, r.preViewMatrices, r.paint, r.constraint));
DRAW(DrawEdgeAAImageSet2, experimental_DrawEdgeAAImageSet(
r.set.get(), r.count, r.dstClips, r.preViewMatrices, r.sampling, r.paint, r.constraint));
#undef DRAW
@ -524,6 +526,22 @@ private:
}
return rect;
}
Bounds bounds(const DrawEdgeAAImageSet2& op) const {
SkRect rect = SkRect::MakeEmpty();
int clipIndex = 0;
for (int i = 0; i < op.count; ++i) {
SkRect entryBounds = op.set[i].fDstRect;
if (op.set[i].fHasClip) {
entryBounds.setBounds(op.dstClips + clipIndex, 4);
clipIndex += 4;
}
if (op.set[i].fMatrixIndex >= 0) {
op.preViewMatrices[op.set[i].fMatrixIndex].mapRect(&entryBounds);
}
rect.join(this->adjustAndMap(entryBounds, nullptr));
}
return rect;
}
// Returns true if rect was meaningfully adjusted for the effects of paint,
// false if the paint could affect the rect in unknown ways.

View File

@ -237,6 +237,21 @@ void SkRecorder::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], cons
mode,
this->copy(cull));
}
void SkRecorder::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint) {
int totalDstClipCount, totalMatrixCount;
SkCanvasPriv::GetDstClipAndMatrixCounts(set, count, &totalDstClipCount, &totalMatrixCount);
SkAutoTArray<ImageSetEntry> setCopy(count);
for (int i = 0; i < count; ++i) {
setCopy[i] = set[i];
}
this->append<SkRecords::DrawEdgeAAImageSet>(this->copy(paint), std::move(setCopy), count,
this->copy(dstClips, totalDstClipCount),
this->copy(preViewMatrices, totalMatrixCount), constraint);
}
#endif
void SkRecorder::onDrawImage2(const SkImage* image, SkScalar x, SkScalar y,
@ -319,9 +334,10 @@ void SkRecorder::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
rect, this->copy(clip, 4), aa, color, mode);
}
void SkRecorder::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint) {
void SkRecorder::onDrawEdgeAAImageSet2(const ImageSetEntry set[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling, const SkPaint* paint,
SrcRectConstraint constraint) {
int totalDstClipCount, totalMatrixCount;
SkCanvasPriv::GetDstClipAndMatrixCounts(set, count, &totalDstClipCount, &totalMatrixCount);
@ -330,9 +346,9 @@ void SkRecorder::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
setCopy[i] = set[i];
}
this->append<SkRecords::DrawEdgeAAImageSet>(this->copy(paint), std::move(setCopy), count,
this->append<SkRecords::DrawEdgeAAImageSet2>(this->copy(paint), std::move(setCopy), count,
this->copy(dstClips, totalDstClipCount),
this->copy(preViewMatrices, totalMatrixCount), constraint);
this->copy(preViewMatrices, totalMatrixCount), sampling, constraint);
}
void SkRecorder::onFlush() {

View File

@ -94,6 +94,8 @@ public:
const SkPaint*) override;
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int, SkBlendMode, const SkRect*, const SkPaint*) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
#endif
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
const SkPaint*) override;
@ -119,8 +121,9 @@ public:
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
SkBlendMode) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkPaint*, SrcRectConstraint) override;
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
const SkSamplingOptions&, const SkPaint*,
SrcRectConstraint) override;
sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;

View File

@ -83,7 +83,8 @@ namespace SkRecords {
M(DrawShadowRec) \
M(DrawAnnotation) \
M(DrawEdgeAAQuad) \
M(DrawEdgeAAImageSet)
M(DrawEdgeAAImageSet) \
M(DrawEdgeAAImageSet2)
// Defines SkRecords::Type, an enum of all record types.
@ -369,6 +370,14 @@ RECORD(DrawEdgeAAImageSet, kDraw_Tag|kHasImage_Tag|kHasPaint_Tag,
PODArray<SkPoint> dstClips;
PODArray<SkMatrix> preViewMatrices;
SkCanvas::SrcRectConstraint constraint);
RECORD(DrawEdgeAAImageSet2, kDraw_Tag|kHasImage_Tag|kHasPaint_Tag,
Optional<SkPaint> paint;
SkAutoTArray<SkCanvas::ImageSetEntry> set;
int count;
PODArray<SkPoint> dstClips;
PODArray<SkMatrix> preViewMatrices;
SkSamplingOptions sampling;
SkCanvas::SrcRectConstraint constraint);
#undef RECORD
} // namespace SkRecords

View File

@ -123,7 +123,8 @@ public:
void drawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags,
const SkColor4f& color, SkBlendMode mode) override;
void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[],
const SkMatrix[], const SkPaint&, SkCanvas::SrcRectConstraint) override;
const SkMatrix[], const SkSamplingOptions&, const SkPaint&,
SkCanvas::SrcRectConstraint) override;
sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override;
sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override;

View File

@ -808,11 +808,8 @@ void SkGpuDevice::drawImageQuad(const SkImage* image, const SkRect* srcRect, con
void SkGpuDevice::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
// TODO: pass in directly
// pass sampling, or just filter?
SkSamplingOptions sampling(SkPaintPriv::GetFQ(paint));
const SkSamplingOptions& sampling, const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) {
SkASSERT(count > 0);
if (!can_use_draw_texture(paint, sampling.useCubic, sampling.mipmap)) {
// Send every entry through drawImageQuad() to handle the more complicated paint

View File

@ -273,6 +273,15 @@ void SkNWayCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[], co
iter->drawAtlas(image, xform, tex, colors, count, bmode, cull, paint);
}
}
void SkNWayCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint) {
Iter iter(fList);
while (iter.next()) {
iter->experimental_DrawEdgeAAImageSet(
set, count, dstClips, preViewMatrices, paint, constraint);
}
}
#endif
void SkNWayCanvas::onDrawImage2(const SkImage* image, SkScalar left, SkScalar top,
@ -373,13 +382,14 @@ void SkNWayCanvas::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
}
}
void SkNWayCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint) {
void SkNWayCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry set[], int count,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling, const SkPaint* paint,
SrcRectConstraint constraint) {
Iter iter(fList);
while (iter.next()) {
iter->experimental_DrawEdgeAAImageSet(
set, count, dstClips, preViewMatrices, paint, constraint);
set, count, dstClips, preViewMatrices, sampling, paint, constraint);
}
}

View File

@ -149,6 +149,16 @@ void SkPaintFilterCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xfor
this->SkNWayCanvas::onDrawAtlas(image, xform, tex, colors, count, bmode, cull, &apf.paint());
}
}
void SkPaintFilterCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint) {
AutoPaintFilter apf(this, paint);
if (apf.shouldDraw()) {
this->SkNWayCanvas::onDrawEdgeAAImageSet(
set, count, dstClips, preViewMatrices, &apf.paint(), constraint);
}
}
#endif
void SkPaintFilterCanvas::onDrawImage2(const SkImage* image, SkScalar left, SkScalar top,
@ -265,14 +275,16 @@ void SkPaintFilterCanvas::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint cli
}
}
void SkPaintFilterCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkPaint* paint, SrcRectConstraint constraint) {
void SkPaintFilterCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry set[], int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling,
const SkPaint* paint,
SrcRectConstraint constraint) {
AutoPaintFilter apf(this, paint);
if (apf.shouldDraw()) {
this->SkNWayCanvas::onDrawEdgeAAImageSet(
set, count, dstClips, preViewMatrices, &apf.paint(), constraint);
this->SkNWayCanvas::onDrawEdgeAAImageSet2(
set, count, dstClips, preViewMatrices, sampling, &apf.paint(), constraint);
}
}

View File

@ -450,6 +450,16 @@ void DebugCanvas::onDrawAtlas(const SkImage* image,
this->addDrawCommand(
new DrawAtlasCommand(image, xform, tex, colors, count, bmode, cull, paint));
}
void DebugCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[],
int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkPaint* paint,
SrcRectConstraint constraint) {
SkSamplingOptions sampling(paint ? paint->getFilterQuality() : kNone_SkFilterQuality);
this->addDrawCommand(new DrawEdgeAAImageSetCommand(
set, count, dstClips, preViewMatrices, sampling, paint, constraint));
}
#endif
void DebugCanvas::onDrawImage2(const SkImage* image,
@ -607,14 +617,15 @@ void DebugCanvas::onDrawEdgeAAQuad(const SkRect& rect,
this->addDrawCommand(new DrawEdgeAAQuadCommand(rect, clip, aa, color, mode));
}
void DebugCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[],
int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkPaint* paint,
SrcRectConstraint constraint) {
void DebugCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry set[],
int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling,
const SkPaint* paint,
SrcRectConstraint constraint) {
this->addDrawCommand(new DrawEdgeAAImageSetCommand(
set, count, dstClips, preViewMatrices, paint, constraint));
set, count, dstClips, preViewMatrices, sampling, paint, constraint));
}
void DebugCanvas::willRestore() {

View File

@ -177,6 +177,12 @@ protected:
const SkPaint*) override;
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int, SkBlendMode, const SkRect*, const SkPaint*) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[],
int count,
const SkPoint[],
const SkMatrix[],
const SkPaint*,
SrcRectConstraint) override;
#endif
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
const SkPaint*) override;
@ -202,12 +208,13 @@ protected:
QuadAAFlags,
const SkColor4f&,
SkBlendMode) override;
void onDrawEdgeAAImageSet(const ImageSetEntry[],
int count,
const SkPoint[],
const SkMatrix[],
const SkPaint*,
SrcRectConstraint) override;
void onDrawEdgeAAImageSet2(const ImageSetEntry[],
int count,
const SkPoint[],
const SkMatrix[],
const SkSamplingOptions&,
const SkPaint*,
SrcRectConstraint) override;
private:
SkTDArray<DrawCommand*> fCommandVector;

View File

@ -1921,11 +1921,13 @@ DrawEdgeAAImageSetCommand::DrawEdgeAAImageSetCommand(const SkCanvas::ImageSetEnt
int count,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
const SkSamplingOptions& sampling,
const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint)
: INHERITED(kDrawEdgeAAImageSet_OpType)
, fSet(count)
, fCount(count)
, fSampling(sampling)
, fPaint(paint)
, fConstraint(constraint) {
int totalDstClipCount, totalMatrixCount;
@ -1943,6 +1945,7 @@ void DrawEdgeAAImageSetCommand::execute(SkCanvas* canvas) const {
fCount,
fDstClips.get(),
fPreViewMatrices.get(),
fSampling,
fPaint.getMaybeNull(),
fConstraint);
}

View File

@ -691,6 +691,7 @@ public:
int count,
const SkPoint[],
const SkMatrix[],
const SkSamplingOptions&,
const SkPaint*,
SkCanvas::SrcRectConstraint);
void execute(SkCanvas* canvas) const override;
@ -700,6 +701,7 @@ private:
int fCount;
SkAutoTArray<SkPoint> fDstClips;
SkAutoTArray<SkMatrix> fPreViewMatrices;
SkSamplingOptions fSampling;
SkTLazy<SkPaint> fPaint;
SkCanvas::SrcRectConstraint fConstraint;