remove imagefilter::sizeconstraint

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1571033002

Review URL: https://codereview.chromium.org/1571033002
This commit is contained in:
reed 2016-01-11 10:56:59 -08:00 committed by Commit bot
parent 5651ee6376
commit 4e23cdaa6b
18 changed files with 37 additions and 105 deletions

View File

@ -45,31 +45,22 @@ public:
virtual void purgeByImageFilterId(uint32_t) {}
};
enum SizeConstraint {
kExact_SizeConstraint,
kApprox_SizeConstraint,
};
class Context {
public:
Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache,
SizeConstraint constraint)
Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache)
: fCTM(ctm)
, fClipBounds(clipBounds)
, fCache(cache)
, fSizeConstraint(constraint)
{}
const SkMatrix& ctm() const { return fCTM; }
const SkIRect& clipBounds() const { return fClipBounds; }
Cache* cache() const { return fCache; }
SizeConstraint sizeConstraint() const { return fSizeConstraint; }
private:
SkMatrix fCTM;
SkIRect fClipBounds;
Cache* fCache;
SizeConstraint fSizeConstraint;
};
class CropRect {
@ -373,7 +364,7 @@ protected:
// calls filterImage() on that input, and returns true on success.
// i.e., return !getInput(index) || getInput(index)->filterImage(...);
bool filterInput(int index, Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset, bool relaxSizeConstraint = true) const;
SkBitmap* result, SkIPoint* offset) const;
/**
* Return true (and return a ref'd colorfilter) if this node in the DAG is just a

View File

@ -64,31 +64,6 @@ public:
*/
GrTexture* createApproxTexture(const GrSurfaceDesc&);
enum SizeConstraint {
kExact_SizeConstraint,
kApprox_SizeConstraint,
};
GrTexture* createTexture(const GrSurfaceDesc& desc, SizeConstraint constraint) {
switch (constraint) {
case kExact_SizeConstraint:
return this->createTexture(desc, true);
case kApprox_SizeConstraint:
return this->createApproxTexture(desc);
}
sk_throw();
return nullptr;
}
static SizeConstraint FromImageFilter(SkImageFilter::SizeConstraint constraint) {
if (SkImageFilter::kExact_SizeConstraint == constraint) {
return kExact_SizeConstraint;
} else {
SkASSERT(SkImageFilter::kApprox_SizeConstraint == constraint);
return kApprox_SizeConstraint;
}
}
/** Legacy function that no longer should be used. */
enum ScratchTexMatch {
kExact_ScratchTexMatch,

View File

@ -1439,8 +1439,7 @@ void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
SkIRect clipBounds = iter.fClip->getBounds().makeOffset(-pos.x(), -pos.y());
#endif
SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache.get(),
SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
if (filter->filterImage(&proxy, src, ctx, &dst, &offset)) {
SkPaint tmpUnfiltered(*paint);
tmpUnfiltered.setImageFilter(nullptr);

View File

@ -418,8 +418,7 @@ void SkBaseDevice::drawBitmapAsSprite(const SkDraw& draw, const SkBitmap& bitmap
const SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-x, -y);
#endif
SkAutoTUnref<SkImageFilter::Cache> cache(this->getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache.get(),
SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) {
SkPaint tmpUnfiltered(paint);
tmpUnfiltered.setImageFilter(nullptr);

View File

@ -265,25 +265,16 @@ bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src,
}
bool SkImageFilter::filterInput(int index, Proxy* proxy, const SkBitmap& src,
const Context& origCtx,
SkBitmap* result, SkIPoint* offset,
bool relaxSizeConstraint) const {
const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkImageFilter* input = this->getInput(index);
if (!input) {
return true;
}
SizeConstraint constraint = origCtx.sizeConstraint();
if (relaxSizeConstraint && (kExact_SizeConstraint == constraint)) {
constraint = kApprox_SizeConstraint;
}
Context ctx(origCtx.ctm(), origCtx.clipBounds(), origCtx.cache(), constraint);
return input->filterImage(proxy, src, this->mapContext(ctx), result, offset);
}
bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm,
SkIRect* dst) const {
bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) const {
SkASSERT(dst);
return this->onFilterBounds(src, ctm, dst);
}
@ -353,8 +344,7 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
desc.fHeight = bounds.height();
desc.fConfig = kRGBA_8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc,
GrTextureProvider::FromImageFilter(ctx.sizeConstraint())));
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
if (!dst) {
return false;
}
@ -488,7 +478,7 @@ SkImageFilter::Context SkImageFilter::mapContext(const Context& ctx) const {
SkIRect clipBounds;
this->onFilterNodeBounds(ctx.clipBounds(), ctx.ctm(), &clipBounds,
MapDirection::kReverse_MapDirection);
return Context(ctx.ctm(), clipBounds, ctx.cache(), ctx.sizeConstraint());
return Context(ctx.ctm(), clipBounds, ctx.cache());
#endif
}
@ -519,7 +509,7 @@ void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
}
bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy,
const SkBitmap& src, const Context& origCtx,
const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkImageFilter* input = this->getInput(index);
if (!input) {
@ -529,9 +519,6 @@ bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy,
// matrix with no clip and that the matrix, clip, and render target set before this function was
// called are restored before we return to the caller.
GrContext* context = src.getTexture()->getContext();
Context ctx(origCtx.ctm(), origCtx.clipBounds(), origCtx.cache(), kApprox_SizeConstraint);
if (input->filterImage(proxy, src, this->mapContext(ctx), result, offset)) {
if (!result->getTexture()) {
const SkImageInfo info = result->info();

View File

@ -40,9 +40,8 @@ void SkLocalMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
bool SkLocalMatrixImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
Context localCtx(SkMatrix::Concat(ctx.ctm(), fLocalM), ctx.clipBounds(), ctx.cache(),
ctx.sizeConstraint());
return this->filterInput(0, proxy, src, localCtx, result, offset, false);
Context localCtx(SkMatrix::Concat(ctx.ctm(), fLocalM), ctx.clipBounds(), ctx.cache());
return this->filterInput(0, proxy, src, localCtx, result, offset);
}
bool SkLocalMatrixImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& matrix,

View File

@ -217,15 +217,13 @@ bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
srcBounds.offset(-srcOffset);
dstBounds.offset(-srcOffset);
SkRect srcBoundsF(SkRect::Make(srcBounds));
auto constraint = GrTextureProvider::FromImageFilter(ctx.sizeConstraint());
SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(),
source,
false,
SkRect::Make(dstBounds),
&srcBoundsF,
sigma.x(),
sigma.y(),
constraint));
sigma.y()));
if (!tex) {
return false;
}

View File

@ -1241,8 +1241,7 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
// gaussianBlur. Otherwise, we need to save it for later compositing.
bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle);
*result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOverwriteSrc,
clipRect, nullptr, xformedSigma, xformedSigma,
GrTextureProvider::kApprox_SizeConstraint);
clipRect, nullptr, xformedSigma, xformedSigma);
if (nullptr == *result) {
return false;
}

View File

@ -37,8 +37,8 @@ bool SkComposeImageFilter::onFilterImage(Proxy* proxy,
outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-innerOffset.y()));
SkIRect clipBounds = ctx.clipBounds();
clipBounds.offset(-innerOffset.x(), -innerOffset.y());
Context outerContext(outerMatrix, clipBounds, ctx.cache(), ctx.sizeConstraint());
if (!this->filterInput(0, proxy, tmp, outerContext, result, &outerOffset, false)) {
Context outerContext(outerMatrix, clipBounds, ctx.cache());
if (!this->filterInput(0, proxy, tmp, outerContext, result, &outerOffset)) {
return false;
}

View File

@ -428,8 +428,7 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
desc.fHeight = bounds.height();
desc.fConfig = kSkia8888_GrPixelConfig;
auto constraint = GrTextureProvider::FromImageFilter(ctx.sizeConstraint());
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc, constraint));
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
if (!dst) {
return false;

View File

@ -167,8 +167,7 @@ GrTexture* GaussianBlur(GrContext* context,
const SkRect& dstBounds,
const SkRect* srcBounds,
float sigmaX,
float sigmaY,
GrTextureProvider::SizeConstraint constraint) {
float sigmaY) {
SkASSERT(context);
SkIRect clearRect;
int scaleFactorX, radiusX;
@ -211,12 +210,12 @@ GrTexture* GaussianBlur(GrContext* context,
GrTexture* tempTexture;
SkAutoTUnref<GrTexture> temp1, temp2;
temp1.reset(context->textureProvider()->createTexture(desc, constraint));
temp1.reset(context->textureProvider()->createApproxTexture(desc));
dstTexture = temp1.get();
if (canClobberSrc) {
tempTexture = srcTexture;
} else {
temp2.reset(context->textureProvider()->createTexture(desc, constraint));
temp2.reset(context->textureProvider()->createApproxTexture(desc));
tempTexture = temp2.get();
}

View File

@ -40,8 +40,7 @@ namespace SkGpuBlurUtils {
const SkRect& dstBounds,
const SkRect* srcBounds,
float sigmaX,
float sigmaY,
GrTextureProvider::SizeConstraint);
float sigmaY);
#endif
};

View File

@ -383,8 +383,7 @@ bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy,
desc.fHeight = bounds.height();
desc.fConfig = kRGBA_8888_GrPixelConfig;
auto constraint = GrTextureProvider::FromImageFilter(ctx.sizeConstraint());
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc, constraint));
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
if (!dst) {
return false;
}

View File

@ -548,8 +548,7 @@ bool apply_morphology(const SkBitmap& input,
const SkIRect& rect,
GrMorphologyEffect::MorphologyType morphType,
SkISize radius,
SkBitmap* dst,
GrTextureProvider::SizeConstraint constraint) {
SkBitmap* dst) {
SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture()));
SkASSERT(srcTexture);
GrContext* context = srcTexture->getContext();
@ -567,14 +566,7 @@ bool apply_morphology(const SkBitmap& input,
SkIRect srcRect = rect;
if (radius.fWidth > 0) {
GrTextureProvider::SizeConstraint horiConstraint = constraint;
if (radius.fHeight > 0) {
// Optimization: we will fall through and allocate the "real" texture after this one
// so ours can be approximate (likely faster to allocate)
horiConstraint = GrTextureProvider::kApprox_SizeConstraint;
}
GrTexture* scratch = context->textureProvider()->createTexture(desc, horiConstraint);
GrTexture* scratch = context->textureProvider()->createApproxTexture(desc);
if (nullptr == scratch) {
return false;
}
@ -598,7 +590,7 @@ bool apply_morphology(const SkBitmap& input,
srcRect = dstRect;
}
if (radius.fHeight > 0) {
GrTexture* scratch = context->textureProvider()->createTexture(desc, constraint);
GrTexture* scratch = context->textureProvider()->createApproxTexture(desc);
if (nullptr == scratch) {
return false;
}
@ -656,8 +648,7 @@ bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDilate_MorphologyType
: GrMorphologyEffect::kErode_MorphologyType;
if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height), result,
GrTextureProvider::FromImageFilter(ctx.sizeConstraint()))) {
if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height), result)) {
return false;
}
offset->fX = bounds.left();

View File

@ -155,8 +155,7 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
desc.fWidth = src.width();
desc.fHeight = src.height();
desc.fConfig = kSkia8888_GrPixelConfig;
auto constraint = GrTextureProvider::FromImageFilter(ctx.sizeConstraint());
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc, constraint));
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
if (!dst) {
return false;
}

View File

@ -311,7 +311,7 @@ void GrLayerHoister::FilterLayer(GrContext* context,
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefaultCacheSize));
SkImageFilter::Context filterContext(totMat, clipBounds, cache, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context filterContext(totMat, clipBounds, cache);
SkImageFilter::DeviceProxy proxy(device);
const SkBitmap src = wrap_texture(layer->texture());

View File

@ -1157,7 +1157,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
SkImageFilter::Context ctx(matrix, clipBounds, cache, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(matrix, clipBounds, cache);
if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredBitmap,
&offset)) {
texture = (GrTexture*) filteredBitmap.getTexture();
@ -1323,7 +1323,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(matrix, clipBounds, cache);
if (this->filterTexture(fContext, devTex, device->width(), device->height(),
filter, ctx, &filteredBitmap, &offset)) {
devTex = filteredBitmap.getTexture();

View File

@ -319,7 +319,7 @@ static void test_crop_rects(SkImageFilter::Proxy* proxy, skiatest::Reporter* rep
SkIPoint offset;
SkString str;
str.printf("filter %d", static_cast<int>(i));
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(proxy, bitmap, ctx,
&result, &offset), str.c_str());
REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, str.c_str());
@ -364,12 +364,12 @@ static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy, skiatest::Repo
SkBitmap positiveResult1, negativeResult1;
SkBitmap positiveResult2, negativeResult2;
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr);
REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, ctx, &positiveResult1, &offset));
REPORTER_ASSERT(reporter, negativeFilter->filterImage(proxy, gradient, ctx, &negativeResult1, &offset));
SkMatrix negativeScale;
negativeScale.setScale(-SK_Scalar1, SK_Scalar1);
SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), nullptr, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), nullptr);
REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, negativeCTX, &negativeResult2, &offset));
REPORTER_ASSERT(reporter, negativeFilter->filterImage(proxy, gradient, negativeCTX, &positiveResult2, &offset));
SkAutoLockPixels lockP1(positiveResult1);
@ -658,8 +658,7 @@ DEF_TEST(ImageFilterMergeResultSize, reporter) {
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
SkImageFilter::DeviceProxy proxy(device);
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr,
SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr);
SkBitmap result;
SkIPoint offset;
REPORTER_ASSERT(reporter, merge->filterImage(&proxy, bitmap, ctx, &result, &offset));
@ -906,7 +905,7 @@ DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) {
SkBitmap result;
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nullptr, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nullptr);
SkBitmap bitmap;
bitmap.allocN32Pixels(2, 2);
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
@ -1159,7 +1158,7 @@ DEF_TEST(ComposedImageFilterOffset, reporter) {
offsetFilter.get()));
SkBitmap result;
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &result, &offset));
REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0);
}
@ -1177,7 +1176,7 @@ DEF_TEST(PartialCropRect, reporter) {
SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
SkBitmap result;
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result, &offset));
REPORTER_ASSERT(reporter, offset.fX == 0);
REPORTER_ASSERT(reporter, offset.fY == 0);