hide legacy scalePixels and makeShader
Change-Id: Idae1e44aa0417adb943fd20112fb4f1fa81167f2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/337719 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
26e1073885
commit
ce0c876ce2
@ -15,7 +15,7 @@ void draw(SkCanvas* canvas) {
|
|||||||
SkFilterQuality qualities[] = { kNone_SkFilterQuality, kLow_SkFilterQuality,
|
SkFilterQuality qualities[] = { kNone_SkFilterQuality, kLow_SkFilterQuality,
|
||||||
kMedium_SkFilterQuality, kHigh_SkFilterQuality };
|
kMedium_SkFilterQuality, kHigh_SkFilterQuality };
|
||||||
for (unsigned index = 0; index < SK_ARRAY_COUNT(qualities); ++index) {
|
for (unsigned index = 0; index < SK_ARRAY_COUNT(qualities); ++index) {
|
||||||
image->scalePixels(pixmap, qualities[index]);
|
image->scalePixels(pixmap, SkSamplingOptions(qualities[index]));
|
||||||
sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
|
sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
|
||||||
canvas->drawImage(filtered, 16 * index, 0);
|
canvas->drawImage(filtered, 16 * index, 0);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@ void draw(SkCanvas* canvas) {
|
|||||||
std::vector<int32_t> dstPixels;
|
std::vector<int32_t> dstPixels;
|
||||||
dstPixels.resize(image->height() * rowBytes);
|
dstPixels.resize(image->height() * rowBytes);
|
||||||
SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
|
SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
|
||||||
pixmap.scalePixels(dstmap, kMedium_SkFilterQuality);
|
pixmap.scalePixels(dstmap, SkSamplingOptions(SkFilterMode::kLinear,
|
||||||
|
SkMipmapMode::kNearest));
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
bitmap.installPixels(dstmap);
|
bitmap.installPixels(dstmap);
|
||||||
canvas->translate(32, 32);
|
canvas->translate(32, 32);
|
||||||
|
@ -204,7 +204,7 @@ static void show_scaled_pixels(SkCanvas* canvas, SkImage* image) {
|
|||||||
for (auto ch : chints) {
|
for (auto ch : chints) {
|
||||||
canvas->save();
|
canvas->save();
|
||||||
for (auto q : qualities) {
|
for (auto q : qualities) {
|
||||||
if (image->scalePixels(storage, q, ch)) {
|
if (image->scalePixels(storage, SkSamplingOptions(q), ch)) {
|
||||||
draw_pixmap(canvas, storage);
|
draw_pixmap(canvas, storage);
|
||||||
}
|
}
|
||||||
canvas->translate(70, 0);
|
canvas->translate(70, 0);
|
||||||
@ -407,7 +407,7 @@ DEF_SIMPLE_GM(scalepixels_unpremul, canvas, 1080, 280) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (auto fq : qualities) {
|
for (auto fq : qualities) {
|
||||||
pm.scalePixels(pm2, fq);
|
pm.scalePixels(pm2, SkSamplingOptions(fq));
|
||||||
slam_ff(pm2);
|
slam_ff(pm2);
|
||||||
draw_pixmap(canvas, pm2, 10, 10);
|
draw_pixmap(canvas, pm2, 10, 10);
|
||||||
canvas->translate(pm2.width() + 10.0f, 0);
|
canvas->translate(pm2.width() + 10.0f, 0);
|
||||||
|
@ -117,7 +117,8 @@ DEF_SIMPLE_GM(localmatrixshader_persp, canvas, 542, 266) {
|
|||||||
|
|
||||||
SkBitmap downsized;
|
SkBitmap downsized;
|
||||||
downsized.allocPixels(image->imageInfo().makeWH(128, 128));
|
downsized.allocPixels(image->imageInfo().makeWH(128, 128));
|
||||||
image->scalePixels(downsized.pixmap(), kLow_SkFilterQuality);
|
image->scalePixels(downsized.pixmap(), SkSamplingOptions(SkFilterMode::kLinear,
|
||||||
|
SkMipmapMode::kNone));
|
||||||
image = SkImage::MakeFromBitmap(downsized);
|
image = SkImage::MakeFromBitmap(downsized);
|
||||||
SkRect imgRect = SkRect::MakeIWH(image->width(), image->height());
|
SkRect imgRect = SkRect::MakeIWH(image->width(), image->height());
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ flutter_defines = [
|
|||||||
"SK_SUPPORT_LEGACY_MATRIX_FACTORIES",
|
"SK_SUPPORT_LEGACY_MATRIX_FACTORIES",
|
||||||
"SK_SUPPORT_LEGACY_ADJUSTHQHEURISTIC",
|
"SK_SUPPORT_LEGACY_ADJUSTHQHEURISTIC",
|
||||||
"SK_SUPPORT_LEGACY_ONDRAWIMAGERECT",
|
"SK_SUPPORT_LEGACY_ONDRAWIMAGERECT",
|
||||||
|
"SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM",
|
||||||
|
|
||||||
# Fast low-precision software rendering isn't a priority for Flutter.
|
# Fast low-precision software rendering isn't a priority for Flutter.
|
||||||
"SK_DISABLE_LEGACY_SHADERCONTEXT",
|
"SK_DISABLE_LEGACY_SHADERCONTEXT",
|
||||||
|
@ -701,8 +701,12 @@ public:
|
|||||||
return this->makeShader(tmx, tmy, &localMatrix);
|
return this->makeShader(tmx, tmy, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM
|
||||||
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix* localMatrix,
|
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix* localMatrix,
|
||||||
SkFilterQuality) const;
|
SkFilterQuality fq) const {
|
||||||
|
return this->makeShader(tmx, tmy, SkSamplingOptions(fq), localMatrix);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses
|
/** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses
|
||||||
SkShader::kClamp_TileMode to fill drawn area outside SkImage. localMatrix permits
|
SkShader::kClamp_TileMode to fill drawn area outside SkImage. localMatrix permits
|
||||||
@ -1003,22 +1007,22 @@ public:
|
|||||||
match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns
|
match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns
|
||||||
false if pixel conversion is not possible.
|
false if pixel conversion is not possible.
|
||||||
|
|
||||||
Scales the image, with filterQuality, to match dst.width() and dst.height().
|
|
||||||
filterQuality kNone_SkFilterQuality is fastest, typically implemented with
|
|
||||||
nearest neighbor filter. kLow_SkFilterQuality is typically implemented with
|
|
||||||
bilerp filter. kMedium_SkFilterQuality is typically implemented with
|
|
||||||
bilerp filter, and mip-map filter when size is reduced.
|
|
||||||
kHigh_SkFilterQuality is slowest, typically implemented with bicubic filter.
|
|
||||||
|
|
||||||
If cachingHint is kAllow_CachingHint, pixels may be retained locally.
|
If cachingHint is kAllow_CachingHint, pixels may be retained locally.
|
||||||
If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
|
If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
|
||||||
|
|
||||||
@param dst destination SkPixmap: SkImageInfo, pixels, row bytes
|
@param dst destination SkPixmap: SkImageInfo, pixels, row bytes
|
||||||
@return true if pixels are scaled to fit dst
|
@return true if pixels are scaled to fit dst
|
||||||
*/
|
*/
|
||||||
bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
|
bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&,
|
||||||
CachingHint cachingHint = kAllow_CachingHint) const;
|
CachingHint cachingHint = kAllow_CachingHint) const;
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM
|
||||||
|
bool scalePixels(const SkPixmap& dst, SkFilterQuality fq,
|
||||||
|
CachingHint cachingHint = kAllow_CachingHint) const {
|
||||||
|
return this->scalePixels(dst, SkSamplingOptions(fq), cachingHint);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Encodes SkImage pixels, returning result as SkData.
|
/** Encodes SkImage pixels, returning result as SkData.
|
||||||
|
|
||||||
Returns nullptr if encoding fails, or if encodedImageFormat is not supported.
|
Returns nullptr if encoding fails, or if encodedImageFormat is not supported.
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
#include "include/core/SkColor.h"
|
#include "include/core/SkColor.h"
|
||||||
#include "include/core/SkFilterQuality.h"
|
#include "include/core/SkFilterQuality.h"
|
||||||
#include "include/core/SkImageInfo.h"
|
#include "include/core/SkImageInfo.h"
|
||||||
|
#include "include/core/SkSamplingOptions.h"
|
||||||
|
|
||||||
|
#ifndef SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM
|
||||||
|
#define SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM
|
||||||
|
#endif
|
||||||
|
|
||||||
class SkData;
|
class SkData;
|
||||||
struct SkMask;
|
struct SkMask;
|
||||||
@ -654,19 +659,16 @@ public:
|
|||||||
|
|
||||||
Returns false if SkBitmap width() or height() is zero or negative.
|
Returns false if SkBitmap width() or height() is zero or negative.
|
||||||
|
|
||||||
Scales the image, with filterQuality, to match dst.width() and dst.height().
|
|
||||||
filterQuality kNone_SkFilterQuality is fastest, typically implemented with
|
|
||||||
nearest neighbor filter. kLow_SkFilterQuality is typically implemented with
|
|
||||||
bilerp filter. kMedium_SkFilterQuality is typically implemented with
|
|
||||||
bilerp filter, and mip-map filter when size is reduced.
|
|
||||||
kHigh_SkFilterQuality is slowest, typically implemented with bicubic filter.
|
|
||||||
|
|
||||||
@param dst SkImageInfo and pixel address to write to
|
@param dst SkImageInfo and pixel address to write to
|
||||||
@return true if pixels are scaled to fit dst
|
@return true if pixels are scaled to fit dst
|
||||||
|
|
||||||
example: https://fiddle.skia.org/c/@Pixmap_scalePixels
|
example: https://fiddle.skia.org/c/@Pixmap_scalePixels
|
||||||
*/
|
*/
|
||||||
bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const;
|
bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&) const;
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM
|
||||||
|
bool scalePixels(const SkPixmap& dst, SkFilterQuality fq) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Writes color to pixels bounded by subset; returns true on success.
|
/** Writes color to pixels bounded by subset; returns true on success.
|
||||||
Returns false if colorType() is kUnknown_SkColorType, or if subset does
|
Returns false if colorType() is kUnknown_SkColorType, or if subset does
|
||||||
|
@ -42,7 +42,7 @@ struct SkCubicResampler {
|
|||||||
float B, C;
|
float B, C;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SkSamplingOptions {
|
struct SK_API SkSamplingOptions {
|
||||||
bool fUseCubic = false;
|
bool fUseCubic = false;
|
||||||
SkCubicResampler fCubic = {0, 0};
|
SkCubicResampler fCubic = {0, 0};
|
||||||
SkFilterMode fFilter = SkFilterMode::kNearest;
|
SkFilterMode fFilter = SkFilterMode::kNearest;
|
||||||
|
@ -124,7 +124,8 @@ sk_sp<SkImage> MultiFrameImageAsset::generateFrame(float t) {
|
|||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
if (bm.tryAllocPixels(info, info.minRowBytes()) &&
|
if (bm.tryAllocPixels(info, info.minRowBytes()) &&
|
||||||
image->scalePixels(bm.pixmap(),
|
image->scalePixels(bm.pixmap(),
|
||||||
SkFilterQuality::kMedium_SkFilterQuality,
|
SkSamplingOptions(SkFilterMode::kLinear,
|
||||||
|
SkMipmapMode::kNearest),
|
||||||
SkImage::kDisallow_CachingHint)) {
|
SkImage::kDisallow_CachingHint)) {
|
||||||
image = SkImage::MakeFromBitmap(bm);
|
image = SkImage::MakeFromBitmap(bm);
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ bool SkPixmap::erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* su
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkPixmap::scalePixels(const SkPixmap& actualDst, SkFilterQuality quality) const {
|
bool SkPixmap::scalePixels(const SkPixmap& actualDst, const SkSamplingOptions& sampling) const {
|
||||||
// We may need to tweak how we interpret these just a little below, so we make copies.
|
// We may need to tweak how we interpret these just a little below, so we make copies.
|
||||||
SkPixmap src = *this,
|
SkPixmap src = *this,
|
||||||
dst = actualDst;
|
dst = actualDst;
|
||||||
@ -238,8 +238,6 @@ bool SkPixmap::scalePixels(const SkPixmap& actualDst, SkFilterQuality quality) c
|
|||||||
SkRect::Make(dst.bounds()),
|
SkRect::Make(dst.bounds()),
|
||||||
SkMatrix::kFill_ScaleToFit);
|
SkMatrix::kFill_ScaleToFit);
|
||||||
|
|
||||||
// We'll create a shader to do this draw so we have control over the bicubic clamp.
|
|
||||||
auto sampling = SkSamplingOptions(quality);
|
|
||||||
sk_sp<SkShader> shader = SkImageShader::Make(SkImage::MakeFromBitmap(bitmap),
|
sk_sp<SkShader> shader = SkImageShader::Make(SkImage::MakeFromBitmap(bitmap),
|
||||||
SkTileMode::kClamp,
|
SkTileMode::kClamp,
|
||||||
SkTileMode::kClamp,
|
SkTileMode::kClamp,
|
||||||
@ -256,12 +254,17 @@ bool SkPixmap::scalePixels(const SkPixmap& actualDst, SkFilterQuality quality) c
|
|||||||
|
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
paint.setBlendMode(SkBlendMode::kSrc);
|
paint.setBlendMode(SkBlendMode::kSrc);
|
||||||
paint.setFilterQuality(quality);
|
|
||||||
paint.setShader(std::move(shader));
|
paint.setShader(std::move(shader));
|
||||||
surface->getCanvas()->drawPaint(paint);
|
surface->getCanvas()->drawPaint(paint);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM
|
||||||
|
bool SkPixmap::scalePixels(const SkPixmap& dst, SkFilterQuality fq) const {
|
||||||
|
return this->scalePixels(dst, SkSamplingOptions(fq));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SkColor SkPixmap::getColor(int x, int y) const {
|
SkColor SkPixmap::getColor(int x, int y) const {
|
||||||
|
@ -102,7 +102,8 @@ void SkImage::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
|
|||||||
context);
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingHint chint) const {
|
bool SkImage::scalePixels(const SkPixmap& dst, const SkSamplingOptions& sampling,
|
||||||
|
CachingHint chint) const {
|
||||||
// Context TODO: Elevate GrDirectContext requirement to public API.
|
// Context TODO: Elevate GrDirectContext requirement to public API.
|
||||||
auto dContext = as_IB(this)->directContext();
|
auto dContext = as_IB(this)->directContext();
|
||||||
if (this->width() == dst.width() && this->height() == dst.height()) {
|
if (this->width() == dst.width() && this->height() == dst.height()) {
|
||||||
@ -119,7 +120,7 @@ bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingH
|
|||||||
// is (currently) only being applied to the getROPixels. If we get a request to
|
// is (currently) only being applied to the getROPixels. If we get a request to
|
||||||
// also attempt to cache the final (scaled) result, we would add that logic here.
|
// also attempt to cache the final (scaled) result, we would add that logic here.
|
||||||
//
|
//
|
||||||
return bm.peekPixels(&pmap) && pmap.scalePixels(dst, quality);
|
return bm.peekPixels(&pmap) && pmap.scalePixels(dst, sampling);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -148,13 +149,6 @@ sk_sp<SkShader> SkImage::makeShader(SkTileMode tmx, SkTileMode tmy,
|
|||||||
&sampling, localMatrix);
|
&sampling, localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<SkShader> SkImage::makeShader(SkTileMode tmx, SkTileMode tmy,
|
|
||||||
const SkMatrix* localMatrix, SkFilterQuality filtering) const {
|
|
||||||
auto sampling = SkSamplingOptions(filtering);
|
|
||||||
return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tmx, tmy, &sampling,
|
|
||||||
localMatrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
sk_sp<SkData> SkImage::encodeToData(SkEncodedImageFormat type, int quality) const {
|
sk_sp<SkData> SkImage::encodeToData(SkEncodedImageFormat type, int quality) const {
|
||||||
// Context TODO: Elevate GrDirectContext requirement to public API.
|
// Context TODO: Elevate GrDirectContext requirement to public API.
|
||||||
auto dContext = as_IB(this)->directContext();
|
auto dContext = as_IB(this)->directContext();
|
||||||
|
@ -516,7 +516,8 @@ sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrDirectContext* dContext,
|
|||||||
int newWidth = std::min(static_cast<int>(originalPixmap.width() * scale), maxTextureSize);
|
int newWidth = std::min(static_cast<int>(originalPixmap.width() * scale), maxTextureSize);
|
||||||
int newHeight = std::min(static_cast<int>(originalPixmap.height() * scale), maxTextureSize);
|
int newHeight = std::min(static_cast<int>(originalPixmap.height() * scale), maxTextureSize);
|
||||||
SkImageInfo info = originalPixmap.info().makeWH(newWidth, newHeight);
|
SkImageInfo info = originalPixmap.info().makeWH(newWidth, newHeight);
|
||||||
if (!resized.tryAlloc(info) || !originalPixmap.scalePixels(resized, kLow_SkFilterQuality)) {
|
SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
|
||||||
|
if (!resized.tryAlloc(info) || !originalPixmap.scalePixels(resized, sampling)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
pixmap = &resized;
|
pixmap = &resized;
|
||||||
|
@ -343,7 +343,8 @@ sk_sp<SkImage> SkImage::MakeFromYUVAPixmaps(GrRecordingContext* context,
|
|||||||
int newWidth = std::min(static_cast<int>(pixmap->width() *scale), maxTextureSize);
|
int newWidth = std::min(static_cast<int>(pixmap->width() *scale), maxTextureSize);
|
||||||
int newHeight = std::min(static_cast<int>(pixmap->height()*scale), maxTextureSize);
|
int newHeight = std::min(static_cast<int>(pixmap->height()*scale), maxTextureSize);
|
||||||
SkImageInfo info = pixmap->info().makeWH(newWidth, newHeight);
|
SkImageInfo info = pixmap->info().makeWH(newWidth, newHeight);
|
||||||
if (!resized.tryAlloc(info) || !pixmap->scalePixels(resized, kLow_SkFilterQuality)) {
|
SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
|
||||||
|
if (!resized.tryAlloc(info) || !pixmap->scalePixels(resized, sampling)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
pixmap = &resized;
|
pixmap = &resized;
|
||||||
|
@ -131,7 +131,8 @@ DEF_TEST(image_shader_filtering, reporter) {
|
|||||||
for (auto scale : scales) {
|
for (auto scale : scales) {
|
||||||
SkMatrix m = SkMatrix::Scale(scale, scale);
|
SkMatrix m = SkMatrix::Scale(scale, scale);
|
||||||
paint.setFilterQuality(kNone_SkFilterQuality); // this setting should be ignored
|
paint.setFilterQuality(kNone_SkFilterQuality); // this setting should be ignored
|
||||||
paint.setShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m, q));
|
paint.setShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||||
|
SkSamplingOptions(q), &m));
|
||||||
auto img0 = make_img(paint);
|
auto img0 = make_img(paint);
|
||||||
|
|
||||||
paint.setFilterQuality(q); // this should (still) be ignored
|
paint.setFilterQuality(q); // this should (still) be ignored
|
||||||
|
Loading…
Reference in New Issue
Block a user