Image Filters: refactor all CPU input processing into a filterInput helper function.
No change in behaviour; this is a straight refactoring. BUG=skia:3194 Review URL: https://codereview.chromium.org/1404743005
This commit is contained in:
parent
5f5527fb46
commit
b9519f86bb
@ -41,9 +41,8 @@ public:
|
||||
virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx,
|
||||
SkBitmap* dst, SkIPoint* offset) const override {
|
||||
SkBitmap source = src;
|
||||
SkImageFilter* input = getInput(0);
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (input && !input->filterImage(proxy, src, ctx, &source, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, src, ctx, &source, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -337,6 +337,14 @@ protected:
|
||||
// no inputs.
|
||||
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const;
|
||||
|
||||
// Helper function which invokes filter processing on the input at the
|
||||
// specified "index". If the input is null, it leaves "result" and
|
||||
// "offset" untouched, and returns true. If the input is non-null, it
|
||||
// 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) const;
|
||||
|
||||
/**
|
||||
* Return true (and return a ref'd colorfilter) if this node in the DAG is just a
|
||||
* colorfilter w/o CropRect constraints.
|
||||
|
@ -226,7 +226,7 @@ SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer)
|
||||
void SkImageFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
buffer.writeInt(fInputCount);
|
||||
for (int i = 0; i < fInputCount; i++) {
|
||||
SkImageFilter* input = getInput(i);
|
||||
SkImageFilter* input = this->getInput(i);
|
||||
buffer.writeBool(input != nullptr);
|
||||
if (input != nullptr) {
|
||||
buffer.writeFlattenable(input);
|
||||
@ -262,6 +262,13 @@ bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkImageFilter::filterInput(int index, Proxy* proxy, const SkBitmap& src,
|
||||
const Context& context,
|
||||
SkBitmap* result, SkIPoint* offset) const {
|
||||
SkImageFilter* input = this->getInput(index);
|
||||
return !input || input->filterImage(proxy, src, context, result, offset);
|
||||
}
|
||||
|
||||
bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm,
|
||||
SkIRect* dst) const {
|
||||
SkASSERT(dst);
|
||||
|
@ -41,7 +41,7 @@ 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());
|
||||
return this->getInput(0)->filterImage(proxy, src, localCtx, result, offset);
|
||||
return this->filterInput(0, proxy, src, localCtx, result, offset);
|
||||
}
|
||||
|
||||
bool SkLocalMatrixImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& matrix,
|
||||
|
@ -53,7 +53,7 @@ bool SkMatrixImageFilter::onFilterImage(Proxy* proxy,
|
||||
SkIPoint* offset) const {
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -72,8 +72,7 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
|
||||
SkBitmap* dst, SkIPoint* offset) const {
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (this->getInput(0) &&
|
||||
!this->getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc
|
||||
SkIPoint* offset) const {
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -27,19 +27,16 @@ bool SkComposeImageFilter::onFilterImage(Proxy* proxy,
|
||||
const Context& ctx,
|
||||
SkBitmap* result,
|
||||
SkIPoint* offset) const {
|
||||
SkImageFilter* outer = getInput(0);
|
||||
SkImageFilter* inner = getInput(1);
|
||||
|
||||
SkBitmap tmp;
|
||||
SkIPoint innerOffset = SkIPoint::Make(0, 0);
|
||||
SkIPoint outerOffset = SkIPoint::Make(0, 0);
|
||||
if (!inner->filterImage(proxy, src, ctx, &tmp, &innerOffset))
|
||||
if (!this->filterInput(1, proxy, src, ctx, &tmp, &innerOffset))
|
||||
return false;
|
||||
|
||||
SkMatrix outerMatrix(ctx.ctm());
|
||||
outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-innerOffset.y()));
|
||||
Context outerContext(outerMatrix, ctx.clipBounds(), ctx.cache());
|
||||
if (!outer->filterImage(proxy, tmp, outerContext, result, &outerOffset)) {
|
||||
if (!this->filterInput(0, proxy, tmp, outerContext, result, &outerOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -212,11 +212,9 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
|
||||
SkBitmap* dst,
|
||||
SkIPoint* offset) const {
|
||||
SkBitmap displ = src, color = src;
|
||||
const SkImageFilter* colorInput = this->getColorInput();
|
||||
const SkImageFilter* displInput = this->getDisplacementInput();
|
||||
SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0, 0);
|
||||
if ((colorInput && !colorInput->filterImage(proxy, src, ctx, &color, &colorOffset)) ||
|
||||
(displInput && !displInput->filterImage(proxy, src, ctx, &displ, &displOffset))) {
|
||||
if (!this->filterInput(1, proxy, src, ctx, &color, &colorOffset) ||
|
||||
!this->filterInput(0, proxy, src, ctx, &displ, &displOffset)) {
|
||||
return false;
|
||||
}
|
||||
if ((displ.colorType() != kN32_SkColorType) ||
|
||||
|
@ -59,7 +59,7 @@ bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source
|
||||
{
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset))
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset))
|
||||
return false;
|
||||
|
||||
SkIRect bounds;
|
||||
|
@ -1168,10 +1168,9 @@ bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy,
|
||||
const Context& ctx,
|
||||
SkBitmap* dst,
|
||||
SkIPoint* offset) const {
|
||||
SkImageFilter* input = getInput(0);
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1309,10 +1308,9 @@ bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
|
||||
const Context& ctx,
|
||||
SkBitmap* dst,
|
||||
SkIPoint* offset) const {
|
||||
SkImageFilter* input = getInput(0);
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,7 @@ bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy,
|
||||
SkIPoint* offset) const {
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -81,24 +81,17 @@ bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src,
|
||||
int inputCount = countInputs();
|
||||
for (int i = 0; i < inputCount; ++i) {
|
||||
SkBitmap tmp;
|
||||
const SkBitmap* srcPtr;
|
||||
SkBitmap input = src;
|
||||
SkIPoint pos = SkIPoint::Make(0, 0);
|
||||
SkImageFilter* filter = getInput(i);
|
||||
if (filter) {
|
||||
if (!filter->filterImage(proxy, src, ctx, &tmp, &pos)) {
|
||||
continue;
|
||||
}
|
||||
srcPtr = &tmp;
|
||||
} else {
|
||||
srcPtr = &src;
|
||||
if (!this->filterInput(i, proxy, src, ctx, &input, &pos)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fModes) {
|
||||
paint.setXfermodeMode((SkXfermode::Mode)fModes[i]);
|
||||
} else {
|
||||
paint.setXfermode(nullptr);
|
||||
}
|
||||
canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint);
|
||||
canvas.drawSprite(input, pos.x() - x0, pos.y() - y0, &paint);
|
||||
didProduceResult = true;
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,7 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p
|
||||
SkIPoint* offset) const {
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (this->getInput(0) &&
|
||||
!this->getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@ bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
|
||||
const Context& ctx,
|
||||
SkBitmap* result,
|
||||
SkIPoint* offset) const {
|
||||
SkImageFilter* input = getInput(0);
|
||||
SkBitmap src = source;
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
#ifdef SK_DISABLE_OFFSETIMAGEFILTER_OPTIMIZATION
|
||||
@ -26,7 +25,7 @@ bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
|
||||
#else
|
||||
if (!cropRectIsSet()) {
|
||||
#endif
|
||||
if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -37,7 +36,7 @@ bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
|
||||
offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY);
|
||||
*result = src;
|
||||
} else {
|
||||
if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,8 @@ bool SkTileImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src,
|
||||
const Context& ctx,
|
||||
SkBitmap* dst, SkIPoint* offset) const {
|
||||
SkBitmap source = src;
|
||||
SkImageFilter* input = getInput(0);
|
||||
SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
||||
if (input && !input->filterImage(proxy, src, ctx, &source, &srcOffset)) {
|
||||
if (!this->filterInput(0, proxy, src, ctx, &source, &srcOffset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -50,16 +50,12 @@ bool SkXfermodeImageFilter::onFilterImage(Proxy* proxy,
|
||||
SkBitmap* dst,
|
||||
SkIPoint* offset) const {
|
||||
SkBitmap background = src, foreground = src;
|
||||
SkImageFilter* backgroundInput = this->getInput(0);
|
||||
SkImageFilter* foregroundInput = this->getInput(1);
|
||||
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
|
||||
if (backgroundInput &&
|
||||
!backgroundInput->filterImage(proxy, src, ctx, &background, &backgroundOffset)) {
|
||||
if (!this->filterInput(0, proxy, src, ctx, &background, &backgroundOffset)) {
|
||||
background.reset();
|
||||
}
|
||||
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
|
||||
if (foregroundInput &&
|
||||
!foregroundInput->filterImage(proxy, src, ctx, &foreground, &foregroundOffset)) {
|
||||
if (!this->filterInput(1, proxy, src, ctx, &foreground, &foregroundOffset)) {
|
||||
foreground.reset();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user