Skip to content

Commit 85fa756

Browse files
reed-at-googleSkia Commit-Bot
authored andcommitted
Add filtermode to drawnine
Bug: skia:7650, skia:11099 Change-Id: I1e603099d30bd4672cbb6783209bacf4678fa0f3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345156 Reviewed-by: Kevin Lubick <[email protected]> Commit-Queue: Mike Reed <[email protected]>
1 parent 04e3e50 commit 85fa756

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

gm/ninepatchstretch.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,16 @@ class NinePatchStretchGM : public skiagm::GM {
9191
SkScalar y = SkIntToScalar(100);
9292

9393
SkPaint paint;
94-
for (int filter = 0; filter < 2; filter++) {
95-
paint.setFilterQuality(filter == 0 ? kLow_SkFilterQuality : kNone_SkFilterQuality);
96-
canvas->translate(0, filter * SkIntToScalar(400));
94+
for (auto fm : {SkFilterMode::kLinear, SkFilterMode::kNearest}) {
9795
for (int iy = 0; iy < 2; ++iy) {
9896
for (int ix = 0; ix < 2; ++ix) {
9997
int i = ix * 2 + iy;
10098
SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed,
10199
size[i].width(), size[i].height());
102-
canvas->drawImageNine(fImage.get(), fCenter, r, &paint);
100+
canvas->drawImageNine(fImage.get(), fCenter, r, fm);
103101
}
104102
}
103+
canvas->translate(0, 400);
105104
}
106105
}
107106

include/core/SkCanvas.h

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "include/core/SkRasterHandleAllocator.h"
2121
#include "include/core/SkRect.h"
2222
#include "include/core/SkRefCnt.h"
23+
#include "include/core/SkSamplingOptions.h"
2324
#include "include/core/SkScalar.h"
2425
#include "include/core/SkSize.h"
2526
#include "include/core/SkString.h"
@@ -55,7 +56,6 @@ class SkPixmap;
5556
class SkRegion;
5657
class SkRRect;
5758
struct SkRSXform;
58-
struct SkSamplingOptions;
5959
class SkSurface;
6060
class SkSurface_Base;
6161
class SkTextBlob;
@@ -1668,36 +1668,18 @@ class SK_API SkCanvas {
16681668
@param image SkImage containing pixels, dimensions, and format
16691669
@param center SkIRect edge of image corners and sides
16701670
@param dst destination SkRect of image to draw to
1671+
@param filter what technique to use when sampling the image
16711672
@param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
16721673
and so on; or nullptr
16731674
*/
16741675
void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
1675-
const SkPaint* paint = nullptr);
1676-
1677-
/** Draws SkImage image stretched proportionally to fit into SkRect dst.
1678-
SkIRect center divides the image into nine sections: four sides, four corners, and
1679-
the center. Corners are not scaled, or scaled down proportionately if their sides
1680-
are larger than dst; center and four sides are scaled to fit remaining space, if any.
1681-
1682-
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1683-
1684-
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, and
1685-
SkBlendMode. If image is kAlpha_8_SkColorType, apply SkShader.
1686-
If paint contains SkMaskFilter, generate mask from image bounds. If paint
1687-
SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all
1688-
other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels.
1689-
Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.
1676+
SkFilterMode filter, const SkPaint* paint = nullptr);
16901677

1691-
If generated mask extends beyond image bounds, replicate image edge colors, just
1692-
as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1693-
replicates the image edge color when it samples outside of its bounds.
1678+
// DEPRECATED -- pass filtermode explicitly
1679+
void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
1680+
const SkPaint* paint = nullptr);
16941681

1695-
@param image SkImage containing pixels, dimensions, and format
1696-
@param center SkIRect edge of image corners and sides
1697-
@param dst destination SkRect of image to draw to
1698-
@param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1699-
and so on; or nullptr
1700-
*/
1682+
// DEPRECATED -- pass filtermode explicitly
17011683
void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
17021684
const SkPaint* paint = nullptr) {
17031685
this->drawImageNine(image.get(), center, dst, paint);
@@ -1860,9 +1842,14 @@ class SK_API SkCanvas {
18601842
@param image SkImage containing pixels, dimensions, and format
18611843
@param lattice division of bitmap into fixed and variable rectangles
18621844
@param dst destination SkRect of image to draw to
1845+
@param filter what technique to use when sampling the image
18631846
@param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
18641847
and so on; or nullptr
18651848
*/
1849+
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
1850+
SkFilterMode filter, const SkPaint* paint = nullptr);
1851+
1852+
// DEPRECATED -- pass filtermode explicitly
18661853
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
18671854
const SkPaint* paint = nullptr);
18681855

src/core/SkCanvas.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,24 @@ static SkPaint clean_paint_for_lattice(const SkPaint* paint) {
18861886
return cleaned;
18871887
}
18881888

1889+
void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
1890+
SkFilterMode filter, const SkPaint* paint) {
1891+
SkPaint latticePaint = clean_paint_for_lattice(paint);
1892+
// use filterquality until we can update our virtuals to take SkFilterMode
1893+
latticePaint.setFilterQuality(filter == SkFilterMode::kNearest ? kNone_SkFilterQuality
1894+
: kLow_SkFilterQuality);
1895+
this->drawImageNine(image, center, dst, &latticePaint);
1896+
}
1897+
1898+
void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
1899+
SkFilterMode filter, const SkPaint* paint) {
1900+
SkPaint latticePaint = clean_paint_for_lattice(paint);
1901+
// use filterquality until we can update our virtuals to take SkFilterMode
1902+
latticePaint.setFilterQuality(filter == SkFilterMode::kNearest ? kNone_SkFilterQuality
1903+
: kLow_SkFilterQuality);
1904+
this->drawImageLattice(image, lattice, dst, &latticePaint);
1905+
}
1906+
18891907
void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
18901908
const SkPaint* paint) {
18911909
TRACE_EVENT0("skia", TRACE_FUNC);

0 commit comments

Comments
 (0)