Hide misc non-sampling draw methods

Related chrome CL:
https://chromium-review.googlesource.com/c/chromium/src/+/2646604

Bug: skia:7650
Change-Id: I1069a6151cb70bb6d2c743cf2513f47284c9df7b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358221
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-01-25 11:37:10 -05:00 committed by Skia Commit-Bot
parent 232dd2b61b
commit 9911630fc2
27 changed files with 134 additions and 148 deletions

View File

@ -103,9 +103,9 @@ protected:
SkPaint paint;
paint.setAntiAlias(true);
paint.setFilterQuality(kLow_SkFilterQuality);
canvas->experimental_DrawEdgeAAImageSet(batch, kRectCount, nullptr, nullptr, &paint,
canvas->experimental_DrawEdgeAAImageSet(batch, kRectCount, nullptr, nullptr,
SkSamplingOptions(SkFilterMode::kLinear), &paint,
SkCanvas::kFast_SrcRectConstraint);
}

View File

@ -120,8 +120,8 @@ protected:
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
paint.setFilterQuality(kLow_SkFilterQuality);
paint.setAntiAlias(true);
SkSamplingOptions sampling(SkFilterMode::kLinear);
canvas->save();
canvas->concat(this->getTransform());
@ -145,8 +145,8 @@ protected:
fClampMode == ClampingMode::kAlwaysFast
? SkCanvas::kFast_SrcRectConstraint
: SkCanvas::kStrict_SrcRectConstraint;
canvas->experimental_DrawEdgeAAImageSet(set.get(), i, nullptr, nullptr, &paint,
constraint);
canvas->experimental_DrawEdgeAAImageSet(set.get(), i, nullptr, nullptr,
sampling, &paint, constraint);
} else if (fClampMode == ClampingMode::kChromeTiling_RowMajor) {
// Same tile order, but break batching between fast and strict sections, and
// adjust bottom and right tiles to encode content area distinct from src rect.
@ -158,14 +158,14 @@ protected:
}
// Flush "fast" horizontal row
canvas->experimental_DrawEdgeAAImageSet(set.get() + rowStart,
fTileGridSize.fWidth - 1, nullptr, nullptr, &paint,
fTileGridSize.fWidth - 1, nullptr, nullptr, sampling, &paint,
SkCanvas::kFast_SrcRectConstraint);
// Then flush a single adjusted entry for the right edge
SkPoint dstQuad[4];
set[i++] = this->getAdjustedEntry(fTileGridSize.fWidth - 1, y, l, dstQuad);
canvas->experimental_DrawEdgeAAImageSet(
set.get() + fTileGridSize.fWidth - 1, 1, dstQuad, nullptr, &paint,
SkCanvas::kStrict_SrcRectConstraint);
set.get() + fTileGridSize.fWidth - 1, 1, dstQuad, nullptr, sampling,
&paint, SkCanvas::kStrict_SrcRectConstraint);
}
// For last row, accumulate it as a single strict batch
int rowStart = i;
@ -178,7 +178,7 @@ protected:
set[i++] = this->getEntry(
fTileGridSize.fWidth - 1, fTileGridSize.fHeight - 1, l);
canvas->experimental_DrawEdgeAAImageSet(set.get() + rowStart,
fTileGridSize.fWidth, dstQuads.get(), nullptr, &paint,
fTileGridSize.fWidth, dstQuads.get(), nullptr, sampling, &paint,
SkCanvas::kStrict_SrcRectConstraint);
} else {
SkASSERT(fClampMode == ClampingMode::kChromeTiling_Optimal);
@ -189,7 +189,8 @@ protected:
set[i++] = this->getEntry(x, y, l);
}
}
canvas->experimental_DrawEdgeAAImageSet(set.get(), i, nullptr, nullptr, &paint,
canvas->experimental_DrawEdgeAAImageSet(set.get(), i, nullptr, nullptr,
sampling, &paint,
SkCanvas::kFast_SrcRectConstraint);
// Right edge
@ -201,7 +202,7 @@ protected:
dstQuads.get() + y * 4);
}
canvas->experimental_DrawEdgeAAImageSet(set.get() + strictStart,
i - strictStart, dstQuads.get(), nullptr, &paint,
i - strictStart, dstQuads.get(), nullptr, sampling, &paint,
SkCanvas::kStrict_SrcRectConstraint);
int quadStart = 4 * (fTileGridSize.fHeight - 1);
strictStart = i;
@ -212,7 +213,7 @@ protected:
set[i++] = this->getEntry(
fTileGridSize.fWidth - 1, fTileGridSize.fHeight - 1, l);
canvas->experimental_DrawEdgeAAImageSet(set.get() + strictStart,
i - strictStart, dstQuads.get() + quadStart, nullptr, &paint,
i - strictStart, dstQuads.get() + quadStart, nullptr, sampling, &paint,
SkCanvas::kStrict_SrcRectConstraint);
}
}

View File

@ -209,8 +209,8 @@ protected:
tiny_persp_effect(canvas);
}
for (int i = 0; i < loops; i++) {
canvas->drawAtlas(fAtlas, fXforms, fRects, colors, N, SkBlendMode::kModulate,
cullRect, paintPtr);
canvas->drawAtlas(fAtlas.get(), fXforms, fRects, colors, N, SkBlendMode::kModulate,
SkSamplingOptions(), cullRect, paintPtr);
}
}
private:

View File

@ -9,6 +9,8 @@ void draw(SkCanvas* canvas) {
SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } };
SkColor colors[] = { 0x7f55aa00, 0x7f3333bf };
const SkImage* imagePtr = image.get();
canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr);
SkSamplingOptions sampling;
canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver,
sampling, nullptr, nullptr);
}
} // END FIDDLE

View File

@ -10,6 +10,8 @@ void draw(SkCanvas* canvas) {
SkColor colors[] = { 0x7f55aa00, 0x7f3333bf };
SkPaint paint;
paint.setAlpha(127);
canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint);
SkSamplingOptions sampling;
canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kPlus,
sampling, nullptr, &paint);
}
} // END FIDDLE

View File

@ -1,13 +0,0 @@
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "tools/fiddle/examples.h"
// HASH=8dc0d0fdeab20bbc21cac6874ddbefcd
REG_FIDDLE(Canvas_drawAtlas_3, 256, 256, false, 3) {
void draw(SkCanvas* canvas) {
// sk_sp<SkImage> image = mandrill;
SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } };
SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } };
const SkImage* imagePtr = image.get();
canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr);
}
} // END FIDDLE

View File

@ -1,12 +0,0 @@
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "tools/fiddle/examples.h"
// HASH=c093c2b14bd3e6171ede7cd4049d9b57
REG_FIDDLE(Canvas_drawAtlas_4, 256, 256, false, 3) {
void draw(SkCanvas* canvas) {
// sk_sp<SkImage> image = mandrill;
SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } };
SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } };
canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr);
}
} // END FIDDLE

View File

@ -24,7 +24,8 @@ void draw(SkCanvas* canvas) {
sk_sp<SkImage> image = bitmap.asImage();
SkImage* imagePtr = image.get();
for (auto dest: { 20, 30, 40, 60, 90 } ) {
canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr);
canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest),
SkFilterMode::kNearest, nullptr);
canvas->translate(dest + 4, 0);
}
}

View File

@ -23,7 +23,8 @@ void draw(SkCanvas* canvas) {
}
sk_sp<SkImage> image = bitmap.asImage();
for (auto dest: { 20, 30, 40, 60, 90 } ) {
canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr);
canvas->drawImageNine(image.get(), center, SkRect::MakeWH(dest, 110 - dest),
SkFilterMode::kNearest, nullptr);
canvas->translate(dest + 4, 0);
}
}

View File

@ -7,8 +7,11 @@ void draw(SkCanvas* canvas) {
SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 125, 128 } };
SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } };
SkColor colors[] = { 0x7f55aa00, 0x7f3333bf };
canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kSrc, nullptr, nullptr);
SkSamplingOptions sampling;
canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kSrc,
sampling, nullptr, nullptr);
canvas->translate(128, 0);
canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kDst, nullptr, nullptr);
canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kDst,
sampling, nullptr, nullptr);
}
} // END FIDDLE

View File

@ -6,6 +6,7 @@ void draw(SkCanvas* canvas) {
SkPaint paint;
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 6, false));
canvas->clear(0xFFFF4444);
canvas->drawImageNine(image.get(), {16, 16, 48, 48}, {8, 8, 248, 248}, &paint);
canvas->drawImageNine(image.get(), {16, 16, 48, 48}, {8, 8, 248, 248},
SkFilterMode::kNearest, &paint);
}
} // END FIDDLE

View File

@ -1290,7 +1290,8 @@ static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
fuzz->nextRange(&center.fBottom, center.fTop + 1, img->height());
}
fuzz->next(&dst);
canvas->drawImageNine(img, center, dst, usePaint ? &paint : nullptr);
canvas->drawImageNine(img.get(), center, dst, SkFilterMode::kNearest,
usePaint ? &paint : nullptr);
break;
}
case 44: {
@ -1308,7 +1309,8 @@ static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
fuzz->nextRange(&lattice.fYCount, 2, kMax);
fuzz->nextN(xDivs, lattice.fXCount);
fuzz->nextN(yDivs, lattice.fYCount);
canvas->drawImageLattice(img.get(), lattice, dst, usePaint ? &paint : nullptr);
canvas->drawImageLattice(img.get(), lattice, dst, SkFilterMode::kLinear,
usePaint ? &paint : nullptr);
break;
}
case 45: {

View File

@ -813,7 +813,6 @@ private:
void configureTilePaint(const SkRect& rect, SkPaint* paint) const {
paint->setAntiAlias(true);
paint->setFilterQuality(kLow_SkFilterQuality);
paint->setBlendMode(SkBlendMode::kSrcOver);
// Send non-white RGB, that should be ignored
@ -872,7 +871,8 @@ private:
canvas->experimental_DrawEdgeAAImageSet(
fSetEntries.begin(), fSetEntries.count(), fDstClips.begin(),
fPreViewMatrices.begin(), &paint, SkCanvas::kFast_SrcRectConstraint);
fPreViewMatrices.begin(), SkSamplingOptions(SkFilterMode::kLinear),
&paint, SkCanvas::kFast_SrcRectConstraint);
// Reset for next tile
fDstClips.reset();
@ -973,7 +973,8 @@ private:
paint.setBlendMode(SkBlendMode::kSrcOver);
canvas->experimental_DrawEdgeAAImageSet(
fSetEntries.begin(), fSetEntries.count(), fDstClips.begin(), nullptr, &paint,
fSetEntries.begin(), fSetEntries.count(), fDstClips.begin(), nullptr,
SkSamplingOptions(SkFilterMode::kLinear), &paint,
SkCanvas::kFast_SrcRectConstraint);
// Reset for next tile

View File

@ -113,12 +113,14 @@ protected:
}
SkPaint paint;
paint.setFilterQuality(kLow_SkFilterQuality);
paint.setAntiAlias(true);
SkSamplingOptions sampling(SkFilterMode::kLinear);
canvas->drawAtlas(atlas.get(), xform, tex, N, nullptr, &paint);
canvas->drawAtlas(atlas.get(), xform, tex, nullptr, N, SkBlendMode::kDst,
sampling, nullptr, &paint);
canvas->translate(0, 100);
canvas->drawAtlas(atlas.get(), xform, tex, colors, N, SkBlendMode::kSrcIn, nullptr, &paint);
canvas->drawAtlas(atlas.get(), xform, tex, colors, N, SkBlendMode::kSrcIn,
sampling, nullptr, &paint);
}
private:
@ -342,7 +344,8 @@ DEF_SIMPLE_GM(compare_atlas_vertices, canvas, 560, 585) {
canvas->save();
for (const sk_sp<SkColorFilter>& cf : filters) {
paint.setColorFilter(cf);
canvas->drawAtlas(image, &xform, &tex, &color, 1, mode, &tex, &paint);
canvas->drawAtlas(image.get(), &xform, &tex, &color, 1, mode,
SkSamplingOptions(), &tex, &paint);
canvas->translate(128, 0);
paint.setShader(image->makeShader(SkSamplingOptions()));
canvas->drawVertices(verts, mode, paint);

View File

@ -155,11 +155,11 @@ protected:
SkIntToScalar(kTextPad+kPad));
// w/o a paint
canvas->drawAtlas(atlas.get(), xforms, rects, quadColors, numColors,
gModes[i], nullptr, nullptr);
gModes[i], SkSamplingOptions(), nullptr, nullptr);
canvas->translate(0.0f, numColors*(target.height()+kPad));
// w a paint
canvas->drawAtlas(atlas.get(), xforms, rects, quadColors, numColors,
gModes[i], nullptr, &paint);
gModes[i], SkSamplingOptions(), nullptr, &paint);
canvas->restore();
}
}

View File

@ -140,10 +140,10 @@ private:
dst[2] = {1.f / 3.f * kM * kTileW, 1 / 2.f * kN * kTileH - 0.1f * kTileH};
SkAssertResult(matrices[3].setPolyToPoly(src, dst, 4));
matrices[3].postTranslate(100.f, d);
for (auto fm : {kNone_SkFilterQuality, kLow_SkFilterQuality}) {
for (auto fm : {SkFilterMode::kNearest, SkFilterMode::kLinear}) {
SkPaint setPaint;
setPaint.setFilterQuality(fm);
setPaint.setBlendMode(SkBlendMode::kSrcOver);
SkSamplingOptions sampling(fm);
for (size_t m = 0; m < SK_ARRAY_COUNT(matrices); ++m) {
// Draw grid of red lines at interior tile boundaries.
@ -169,7 +169,8 @@ private:
}
canvas->save();
canvas->concat(matrices[m]);
canvas->experimental_DrawEdgeAAImageSet(fSet, kM * kN, nullptr, nullptr, &setPaint,
canvas->experimental_DrawEdgeAAImageSet(fSet, kM * kN, nullptr, nullptr, sampling,
&setPaint,
SkCanvas::kFast_SrcRectConstraint);
canvas->restore();
}
@ -185,13 +186,13 @@ private:
canvas->rotate(3.f);
setPaint.setBlendMode(SkBlendMode::kExclusion);
canvas->experimental_DrawEdgeAAImageSet(&entry, 1, nullptr, nullptr, &setPaint,
SkCanvas::kFast_SrcRectConstraint);
canvas->experimental_DrawEdgeAAImageSet(&entry, 1, nullptr, nullptr, sampling,
&setPaint, SkCanvas::kFast_SrcRectConstraint);
canvas->translate(entry.fDstRect.width() + 8.f, 0);
SkPaint cfPaint = setPaint;
cfPaint.setColorFilter(SkColorFilters::LinearToSRGBGamma());
canvas->experimental_DrawEdgeAAImageSet(&entry, 1, nullptr, nullptr, &cfPaint,
SkCanvas::kFast_SrcRectConstraint);
canvas->experimental_DrawEdgeAAImageSet(&entry, 1, nullptr, nullptr, sampling,
&cfPaint, SkCanvas::kFast_SrcRectConstraint);
canvas->restore();
canvas->translate(2 * d, 0);
}
@ -236,7 +237,6 @@ private:
matrices[4].postScale(2.f, 0.5f);
SkPaint paint;
paint.setFilterQuality(kLow_SkFilterQuality);
paint.setBlendMode(SkBlendMode::kSrcOver);
static constexpr SkScalar kTranslate = std::max(kW, kH) * 2.f + 10.f;
@ -248,8 +248,9 @@ private:
for (size_t m = 0; m < SK_ARRAY_COUNT(matrices); ++m) {
canvas->save();
canvas->concat(matrices[m]);
canvas->experimental_DrawEdgeAAImageSet(fSet, kM * kN, nullptr, nullptr, &paint,
SkCanvas::kFast_SrcRectConstraint);
canvas->experimental_DrawEdgeAAImageSet(fSet, kM * kN, nullptr, nullptr,
SkSamplingOptions(SkFilterMode::kLinear),
&paint, SkCanvas::kFast_SrcRectConstraint);
canvas->restore();
canvas->translate(kTranslate, 0);
}
@ -272,6 +273,7 @@ private:
canvas->save();
canvas->concat(matrices[m]);
canvas->experimental_DrawEdgeAAImageSet(scaledSet, kM * kN, nullptr, nullptr,
SkSamplingOptions(SkFilterMode::kLinear),
&paint, SkCanvas::kFast_SrcRectConstraint);
canvas->restore();
canvas->translate(kTranslate, 0);
@ -320,12 +322,12 @@ private:
ToolUtils::draw_checkerboard(canvas, SK_ColorGRAY, SK_ColorDKGRAY, 25);
SkPaint paint;
paint.setFilterQuality(kLow_SkFilterQuality);
paint.setBlendMode(SkBlendMode::kSrcOver);
paint.setColor4f({0.2f, 0.8f, 0.4f, 1.f}); // colorizes even rows, no effect on odd rows
// Top rows use experimental edge set API
canvas->experimental_DrawEdgeAAImageSet(fSet, kM * kN, nullptr, nullptr, &paint,
canvas->experimental_DrawEdgeAAImageSet(fSet, kM * kN, nullptr, nullptr,
SkSamplingOptions(SkFilterMode::kLinear), &paint,
SkCanvas::kFast_SrcRectConstraint);
canvas->translate(0.f, kN * kTileH);

View File

@ -189,10 +189,10 @@ static void draw_atlas(SkCanvas* canvas, SkImage* atlas, const SkRect& r,
SkPaint paint;
paint.setImageFilter(std::move(imf));
paint.setFilterQuality(kHigh_SkFilterQuality);
paint.setAntiAlias(true);
SkSamplingOptions sampling({1.0f/3, 1.0f/3});
canvas->drawAtlas(atlas, &xform, &r, /*colors=*/nullptr, /*count=*/1, SkBlendMode::kSrc,
/*cullRect=*/nullptr, &paint);
sampling, /*cullRect=*/nullptr, &paint);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -325,13 +325,15 @@ public:
lattice.fColors = colors;
paint.setColor(0xFFFFFFFF);
canvas->drawImageLattice(image.get(), lattice,
SkRect::MakeXYWH(100, 100, 200, 200), &paint);
SkRect::MakeXYWH(100, 100, 200, 200),
SkFilterMode::kNearest, &paint);
//draw the same content with alpha
canvas->translate(400, 0);
paint.setColor(0x80000FFF);
canvas->drawImageLattice(image.get(), lattice,
SkRect::MakeXYWH(100, 100, 200, 200), &paint);
SkRect::MakeXYWH(100, 100, 200, 200),
SkFilterMode::kNearest, &paint);
canvas->restore();
}
@ -379,5 +381,6 @@ DEF_SIMPLE_GM_BG(lattice_alpha, canvas, 120, 120, SK_ColorWHITE) {
SkPaint paint;
paint.setColor(SK_ColorMAGENTA);
canvas->drawImageLattice(image.get(), lattice, SkRect::MakeWH(120, 120), &paint);
canvas->drawImageLattice(image.get(), lattice, SkRect::MakeWH(120, 120),
SkFilterMode::kNearest, &paint);
}

View File

@ -40,6 +40,10 @@
#define SK_SUPPORT_LEGACY_DRAWIMAGE_NOSAMPLING
#ifndef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
#define SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
#endif
class GrBackendRenderTarget;
class GrRecordingContext;
class GrSurfaceDrawContext;
@ -1707,15 +1711,15 @@ public:
void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
SkFilterMode filter, const SkPaint* paint = nullptr);
// DEPRECATED -- pass filtermode explicitly
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint = nullptr);
// DEPRECATED -- pass filtermode explicitly
void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint = nullptr) {
this->drawImageNine(image.get(), center, dst, paint);
}
#endif
#ifdef SK_SUPPORT_LEGACY_DRAWBITMAP
public:
@ -1884,10 +1888,13 @@ public:
*/
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
SkFilterMode filter, const SkPaint* paint = nullptr);
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst) {
this->drawImageLattice(image, lattice, dst, SkFilterMode::kNearest, nullptr);
}
// DEPRECATED -- pass filtermode explicitly
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
const SkPaint* paint = nullptr);
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
void drawImageLattice(const SkImage*, const Lattice&, const SkRect& dst, const SkPaint*);
#endif
/**
* Experimental. Controls anti-aliasing of each edge of images in an image-set.
@ -1982,11 +1989,13 @@ public:
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkSamplingOptions&, const SkPaint* paint = nullptr,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
// DEPRECATED -- pass sampling directly
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
void experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt,
const SkPoint dstClips[], const SkMatrix preViewMatrices[],
const SkPaint* paint = nullptr,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
#endif
/** Draws text, with origin at (x, y), using clip, SkMatrix, SkFont font,
and SkPaint paint.
@ -2310,78 +2319,28 @@ public:
const SkColor colors[], int count, SkBlendMode mode,
const SkSamplingOptions& sampling, const SkRect* cullRect, const SkPaint* paint);
// DEPRECATED -- pass sampling
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
const SkPaint* paint);
/** Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
to draw, if present. For each entry in the array, SkRect tex locates sprite in
atlas, and SkRSXform xform transforms it into destination space.
xform, text, and colors if present, must contain count entries.
Optional colors is applied for each sprite using SkBlendMode.
Optional cullRect is a conservative bounds of all transformed sprites.
If cullRect is outside of clip, canvas can skip drawing.
@param atlas SkImage containing sprites
@param xform SkRSXform mappings for sprites in atlas
@param tex SkRect locations of sprites in atlas
@param colors one per sprite, blended with sprite using SkBlendMode; may be nullptr
@param count number of sprites to draw
@param mode SkBlendMode combining colors and sprites
@param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
@param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
*/
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
const SkPaint* paint) {
this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
}
/** Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
to draw, if present. For each entry in the array, SkRect tex locates sprite in
atlas, and SkRSXform xform transforms it into destination space.
xform and text must contain count entries.
Optional cullRect is a conservative bounds of all transformed sprites.
If cullRect is outside of clip, canvas can skip drawing.
@param atlas SkImage containing sprites
@param xform SkRSXform mappings for sprites in atlas
@param tex SkRect locations of sprites in atlas
@param count number of sprites to draw
@param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
@param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
*/
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
const SkRect* cullRect, const SkPaint* paint) {
this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
}
/** Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
to draw, if present. For each entry in the array, SkRect tex locates sprite in
atlas, and SkRSXform xform transforms it into destination space.
xform and text must contain count entries.
Optional cullRect is a conservative bounds of all transformed sprites.
If cullRect is outside of clip, canvas can skip drawing.
@param atlas SkImage containing sprites
@param xform SkRSXform mappings for sprites in atlas
@param tex SkRect locations of sprites in atlas
@param count number of sprites to draw
@param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
@param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
*/
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
int count, const SkRect* cullRect, const SkPaint* paint) {
this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
cullRect, paint);
}
#endif
/** Draws SkDrawable drawable using clip and SkMatrix, concatenated with
optional matrix.

View File

@ -884,7 +884,10 @@ EMSCRIPTEN_BINDINGS(Skia) {
if (cptr) {
colors = reinterpret_cast<const SkColor*>(cptr);
}
self.drawAtlas(atlas, dstXforms, srcRects, colors, count, mode, nullptr, paint);
// TODO: take sampling as an explicit parameter from the caller
SkSamplingOptions sampling(SkFilterMode::kLinear);
self.drawAtlas(atlas.get(), dstXforms, srcRects, colors, count, mode, sampling,
nullptr, paint);
}), allow_raw_pointers())
.function("drawCircle", select_overload<void (SkScalar, SkScalar, SkScalar, const SkPaint& paint)>(&SkCanvas::drawCircle))
.function("_drawColor", optional_override([](SkCanvas& self, uintptr_t /* float* */ cPtr) {

View File

@ -85,8 +85,10 @@ public:
for (int i = 0; i < count; ++i) {
arrays.fRects[i].setIWH(fImage->width(), fImage->height());
}
canvas->drawAtlas(fImage, arrays.fXforms.get(), arrays.fRects.get(), arrays.fColors.get(),
count, SkBlendMode::kModulate, nullptr, &paint);
SkSamplingOptions sampling(SkFilterMode::kLinear);
canvas->drawAtlas(fImage.get(), arrays.fXforms.get(), arrays.fRects.get(),
arrays.fColors.get(), count, SkBlendMode::kModulate, sampling,
nullptr, &paint);
}
void prepare(const skresources::ResourceProvider*) override {
@ -136,8 +138,9 @@ public:
int col = frame % cols;
arrays.fRects[i] = baseRect.makeOffset(col * baseRect.width(), row * baseRect.height());
}
canvas->drawAtlas(fImage, arrays.fXforms.get(), arrays.fRects.get(), arrays.fColors.get(),
count, SkBlendMode::kModulate, nullptr, &paint);
canvas->drawAtlas(fImage.get(), arrays.fXforms.get(), arrays.fRects.get(),
arrays.fColors.get(), count, SkBlendMode::kModulate,
SkSamplingOptions(SkFilterMode::kLinear), nullptr, &paint);
}
void prepare(const skresources::ResourceProvider* resourceProvider) override {

View File

@ -73,10 +73,12 @@ static SkSamplingOptions paint_to_sampling(const SkPaint* paint, const GrRecordi
return SkSamplingOptions(paint ? paint->getFilterQuality() : kNone_SkFilterQuality, mb);
}
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
static SkFilterMode paint_to_filter(const SkPaint* paint) {
return paint && paint->getFilterQuality() >= kLow_SkFilterQuality ? SkFilterMode::kLinear
: SkFilterMode::kNearest;
}
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -1913,10 +1915,12 @@ void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const
this->drawImageLattice(image, lat, dst, filter, paint);
}
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint) {
this->drawImageNine(image, center, dst, paint_to_filter(paint), paint);
}
#endif
void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
SkFilterMode filter, const SkPaint* paint) {
@ -1942,10 +1946,12 @@ void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, co
}
}
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
const SkPaint* paint) {
this->drawImageLattice(image, lattice, dst, paint_to_filter(paint), paint);
}
#endif
static sk_sp<SkImage> bitmap_as_image(const SkBitmap& bitmap) {
if (bitmap.drawsNothing()) {
@ -1990,12 +1996,14 @@ void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk
this->onDrawAtlas2(atlas, xform, tex, colors, count, mode, sampling, cull, paint);
}
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
const SkColor colors[], int count, SkBlendMode mode,
const SkRect* cull, const SkPaint* paint) {
this->drawAtlas(atlas, xform, tex, colors, count, mode,
paint_to_sampling(paint, this->recordingContext()), cull, paint);
}
#endif
void SkCanvas::drawAnnotation(const SkRect& rect, const char key[], SkData* value) {
TRACE_EVENT0("skia", TRACE_FUNC);
@ -2024,6 +2032,7 @@ void SkCanvas::experimental_DrawEdgeAAQuad(const SkRect& rect, const SkPoint cli
this->onDrawEdgeAAQuad(rect.makeSorted(), clip, aaFlags, color, mode);
}
#ifdef SK_SUPPORT_LEGACY_PAINT_QUALITY_APIS
void SkCanvas::experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt,
const SkPoint dstClips[],
const SkMatrix preViewMatrices[],
@ -2033,6 +2042,7 @@ void SkCanvas::experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], i
paint_to_sampling(paint, this->recordingContext()),
paint, constraint);
}
#endif
void SkCanvas::experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt,
const SkPoint dstClips[],

View File

@ -215,13 +215,12 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
}
BREAK_ON_READ_ERROR(reader);
SkSamplingOptions sampling;
if (flags & DRAW_ATLAS_HAS_SAMPLING) {
auto sampling = reader->readSampling();
sampling = reader->readSampling();
BREAK_ON_READ_ERROR(reader);
canvas->drawAtlas(atlas, xform, tex, colors, count, mode, sampling, cull, paint);
} else {
canvas->drawAtlas(atlas, xform, tex, colors, count, mode, cull, paint);
}
canvas->drawAtlas(atlas, xform, tex, colors, count, mode, sampling, cull, paint);
} break;
case DRAW_CLEAR: {
auto c = reader->readInt();
@ -380,7 +379,11 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
const SkRect* dst = reader->skipT<SkRect>();
BREAK_ON_READ_ERROR(reader);
canvas->drawImageLattice(image, lattice, *dst, paint);
SkFilterMode filter = SkFilterMode::kNearest;
if (paint && paint->getFilterQuality() != kNone_SkFilterQuality) {
filter = SkFilterMode::kLinear;
}
canvas->drawImageLattice(image, lattice, *dst, filter, paint);
} break;
case DRAW_IMAGE_LATTICE2: {
const SkPaint* paint = fPictureData->optionalPaint(reader);
@ -402,7 +405,11 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
reader->readRect(&dst);
BREAK_ON_READ_ERROR(reader);
canvas->drawImageNine(image, center, dst, paint);
SkFilterMode filter = SkFilterMode::kNearest;
if (paint && paint->getFilterQuality() != kNone_SkFilterQuality) {
filter = SkFilterMode::kLinear;
}
canvas->drawImageNine(image, center, dst, filter, paint);
} break;
case DRAW_IMAGE_RECT: {
const SkPaint* paint = fPictureData->optionalPaint(reader);

View File

@ -415,7 +415,7 @@ void DebugCanvas::onDrawImageLattice2(const SkImage* image,
const SkRect& dst,
SkFilterMode filter, // todo
const SkPaint* paint) {
this->addDrawCommand(new DrawImageLatticeCommand(image, lattice, dst, paint));
this->addDrawCommand(new DrawImageLatticeCommand(image, lattice, dst, filter, paint));
}
void DebugCanvas::onDrawImageRect2(const SkImage* image,
@ -539,7 +539,7 @@ void DebugCanvas::onDrawAtlas2(const SkImage* image,
const SkRect* cull,
const SkPaint* paint) {
this->addDrawCommand(
new DrawAtlasCommand(image, xform, tex, colors, count, bmode, cull, paint));
new DrawAtlasCommand(image, xform, tex, colors, count, bmode, sampling, cull, paint));
}
void DebugCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {

View File

@ -1259,15 +1259,17 @@ void DrawImageCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManag
DrawImageLatticeCommand::DrawImageLatticeCommand(const SkImage* image,
const SkCanvas::Lattice& lattice,
const SkRect& dst,
SkFilterMode filter,
const SkPaint* paint)
: INHERITED(kDrawImageLattice_OpType)
, fImage(SkRef(image))
, fLattice(lattice)
, fDst(dst)
, fFilter(filter)
, fPaint(paint) {}
void DrawImageLatticeCommand::execute(SkCanvas* canvas) const {
canvas->drawImageLattice(fImage.get(), fLattice, fDst, fPaint.getMaybeNull());
canvas->drawImageLattice(fImage.get(), fLattice, fDst, fFilter, fPaint.getMaybeNull());
}
bool DrawImageLatticeCommand::render(SkCanvas* canvas) const {
@ -1982,6 +1984,7 @@ DrawAtlasCommand::DrawAtlasCommand(const SkImage* image,
const SkColor colors[],
int count,
SkBlendMode bmode,
const SkSamplingOptions& sampling,
const SkRect* cull,
const SkPaint* paint)
: INHERITED(kDrawAtlas_OpType)
@ -1990,6 +1993,7 @@ DrawAtlasCommand::DrawAtlasCommand(const SkImage* image,
, fTex(tex, count)
, fColors(colors, colors ? count : 0)
, fBlendMode(bmode)
, fSampling(sampling)
, fCull(cull)
, fPaint(paint) {}
@ -2000,6 +2004,7 @@ void DrawAtlasCommand::execute(SkCanvas* canvas) const {
fColors.isEmpty() ? nullptr : fColors.begin(),
fXform.count(),
fBlendMode,
fSampling,
fCull.getMaybeNull(),
fPaint.getMaybeNull());
}

View File

@ -274,6 +274,7 @@ public:
DrawImageLatticeCommand(const SkImage* image,
const SkCanvas::Lattice& lattice,
const SkRect& dst,
SkFilterMode,
const SkPaint* paint);
void execute(SkCanvas* canvas) const override;
bool render(SkCanvas* canvas) const override;
@ -284,6 +285,7 @@ private:
sk_sp<const SkImage> fImage;
SkCanvas::Lattice fLattice;
SkRect fDst;
SkFilterMode fFilter;
SkTLazy<SkPaint> fPaint;
using INHERITED = DrawCommand;
@ -580,6 +582,7 @@ public:
const SkColor[],
int,
SkBlendMode,
const SkSamplingOptions&,
const SkRect*,
const SkPaint*);
@ -591,6 +594,7 @@ private:
SkTDArray<SkRect> fTex;
SkTDArray<SkColor> fColors;
SkBlendMode fBlendMode;
SkSamplingOptions fSampling;
SkTLazy<SkRect> fCull;
SkTLazy<SkPaint> fPaint;

View File

@ -120,8 +120,6 @@
#include "../../docs/examples/Canvas_drawArc_b.cpp"
#include "../../docs/examples/Canvas_drawAtlas.cpp"
#include "../../docs/examples/Canvas_drawAtlas_2.cpp"
#include "../../docs/examples/Canvas_drawAtlas_3.cpp"
#include "../../docs/examples/Canvas_drawAtlas_4.cpp"
#include "../../docs/examples/Canvas_drawBitmap.cpp"
#include "../../docs/examples/Canvas_drawBitmapRect.cpp"
#include "../../docs/examples/Canvas_drawBitmapRect_2.cpp"