SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter)
protected:
FailImageFilter() : INHERITED(0) {}
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const {
return false;
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter)
protected:
IdentityImageFilter() : INHERITED(0) {}
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const {
*result = src;
return true;
SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input)
: SkImageFilter(input), fDX(dx), fDY(dy) {}
- virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const SK_OVERRIDE {
SkBitmap source = src;
SkImageFilter* input = getInput(0);
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (NULL != input && !input->filterImage(proxy, src, ctm, &source, &srcOffset)) {
+ if (NULL != input && !input->filterImage(proxy, src, ctx, &source, &srcOffset)) {
return false;
}
SkIRect bounds;
source.getBounds(&bounds);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
* If the device does not recognize or support this filter,
* it just returns false and leaves result and offset unchanged.
*/
- virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
+ virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
private:
#include "SkCanvas.h"
#include "SkColor.h"
#include "SkDeviceProperties.h"
+#include "SkImageFilter.h"
// getDeviceCapabilities() is not called by skia, but this flag keeps it around
// for clients that have "override" annotations on their subclass. These overrides
* If the device does not recognize or support this filter,
* it just returns false and leaves result and offset unchanged.
*/
- virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
+ virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
+ const SkImageFilter::Context& ctx,
SkBitmap* result, SkIPoint* offset) = 0;
// This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
#define SkImageFilter_DEFINED
#include "SkFlattenable.h"
+#include "SkMatrix.h"
#include "SkRect.h"
class SkBitmap;
class SkColorFilter;
class SkBaseDevice;
-class SkMatrix;
struct SkIPoint;
class SkShader;
class GrEffectRef;
uint32_t fFlags;
};
+ class Context {
+ public:
+ Context(const SkMatrix& ctm, const SkIRect& clipBounds) :
+ fCTM(ctm), fClipBounds(clipBounds) {
+ }
+ const SkMatrix& ctm() const { return fCTM; }
+ const SkIRect& clipBounds() const { return fClipBounds; }
+ private:
+ SkMatrix fCTM;
+ SkIRect fClipBounds;
+ };
+
class Proxy {
public:
virtual ~Proxy() {};
// returns true if the proxy handled the filter itself. if this returns
// false then the filter's code will be called.
virtual bool filterImage(const SkImageFilter*, const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context&,
SkBitmap* result, SkIPoint* offset) = 0;
};
* If the result image cannot be created, return false, in which case both
* the result and offset parameters will be ignored by the caller.
*/
- bool filterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
+ bool filterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
/**
* relative to the src when it is drawn. The default implementation does
* single-pass processing using asNewEffect().
*/
- virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
/**
* Recursively evaluate this filter on the GPU. If the filter has no GPU
* implementation, it will be processed in software and uploaded to the GPU.
*/
- bool getInputResultGPU(SkImageFilter::Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ bool getInputResultGPU(SkImageFilter::Proxy* proxy, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
#endif
* case both the result and offset parameters will be ignored by the
* caller.
*/
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
// Given the bounds of the destination rect to be filled in device
// coordinates (first parameter), and the CTM, compute (conservatively)
SkBicubicImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
- virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
protected:
explicit SkBitmapSource(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) const SK_OVERRIDE;
explicit SkBlurImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
SkIRect* dst) const SK_OVERRIDE;
bool canFilterImageGPU() const SK_OVERRIDE { return true; }
- virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
SkColorFilterImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool asColorFilter(SkColorFilter**) const SK_OVERRIDE;
protected:
explicit SkComposeImageFilter(SkReadBuffer& buffer);
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy* proxy,
const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* dst,
SkIPoint* offset) const SK_OVERRIDE;
virtual void computeFastBounds(const SkRect& src, SkRect* dst) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
- virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
protected:
explicit SkDropShadowImageFilter(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& source, const SkMatrix&, SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
+ virtual bool onFilterImage(Proxy*, const SkBitmap& source, const Context&, SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
SkIRect* dst) const SK_OVERRIDE;
explicit SkMagnifierImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, const SkMatrix& matrix, const SkIRect& bounds) const SK_OVERRIDE;
SkMatrixConvolutionImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool asNewEffect(GrEffectRef** effect,
GrTexture*,
- const SkMatrix& matrix,
+ const SkMatrix& ctm,
const SkIRect& bounds) const SK_OVERRIDE;
#endif
SkMergeImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input,
const CropRect* cropRect);
bool filterImageGeneric(Proc procX, Proc procY,
- Proxy*, const SkBitmap& src, const SkMatrix&,
+ Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
SkMorphologyImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
bool filterImageGPUGeneric(bool dilate, Proxy* proxy, const SkBitmap& src,
- const SkMatrix& ctm, SkBitmap* result,
+ const Context& ctm, SkBitmap* result,
SkIPoint* offset) const;
#endif
return SkNEW_ARGS(SkDilateImageFilter, (radiusX, radiusY, input, cropRect));
}
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
return SkNEW_ARGS(SkErodeImageFilter, (radiusX, radiusY, input, cropRect));
}
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
SkOffsetImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const SK_OVERRIDE;
*/
explicit SkPictureImageFilter(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
SkRectShaderImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
private:
SkResizeImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
SkIRect* dst) const SK_OVERRIDE;
SkDownSampleImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
private:
return SkNEW_ARGS(SkTileImageFilter, (srcRect, dstRect, input));
}
- virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTileImageFilter)
virtual bool onFilterImage(Proxy* proxy,
const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* dst,
SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return !cropRectIsSet(); }
- virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
virtual void makeRenderTargetCurrent();
virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE;
- virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
+ virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
+ const SkImageFilter::Context&,
SkBitmap*, SkIPoint*) SK_OVERRIDE;
class SkAutoCachedTexture; // used internally
}
bool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src,
- const SkMatrix& ctm, SkBitmap* result,
+ const SkImageFilter::Context& ctx, SkBitmap* result,
SkIPoint* offset) {
return false;
}
const SkBitmap& src = srcDev->accessBitmap(false);
SkMatrix matrix = *iter.fMatrix;
matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
- if (filter->filterImage(&proxy, src, matrix, &dst, &offset)) {
+ SkIRect clipBounds = SkIRect::MakeWH(srcDev->width(), srcDev->height());
+ SkImageFilter::Context ctx(matrix, clipBounds);
+ if (filter->filterImage(&proxy, src, ctx, &dst, &offset)) {
SkPaint tmpUnfiltered(*paint);
tmpUnfiltered.setImageFilter(NULL);
dstDev->drawSprite(iter, dst, pos.x() + offset.x(), pos.y() + offset.y(),
SkIPoint offset = SkIPoint::Make(0, 0);
SkMatrix matrix = *iter.fMatrix;
matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
- if (filter->filterImage(&proxy, bitmap, matrix, &dst, &offset)) {
+ SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
+ SkImageFilter::Context ctx(matrix, clipBounds);
+ if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) {
SkPaint tmpUnfiltered(*paint);
tmpUnfiltered.setImageFilter(NULL);
iter.fDevice->drawSprite(iter, dst, pos.x() + offset.x(), pos.y() + offset.y(),
return fDevice->canHandleImageFilter(filter);
}
virtual bool filterImage(const SkImageFilter* filter, const SkBitmap& src,
- const SkMatrix& ctm,
+ const SkImageFilter::Context& ctx,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE {
- return fDevice->filterImage(filter, src, ctm, result, offset);
+ return fDevice->filterImage(filter, src, ctx, result, offset);
}
private:
}
bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& context,
SkBitmap* result, SkIPoint* offset) const {
SkASSERT(result);
SkASSERT(offset);
* Give the proxy first shot at the filter. If it returns false, ask
* the filter to do it.
*/
- return (proxy && proxy->filterImage(this, src, ctm, result, offset)) ||
- this->onFilterImage(proxy, src, ctm, result, offset);
+ return (proxy && proxy->filterImage(this, src, context, result, offset)) ||
+ this->onFilterImage(proxy, src, context, result, offset);
}
bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm,
}
}
-bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&,
+bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const Context&,
SkBitmap*, SkIPoint*) const {
return false;
}
return this->asNewEffect(NULL, NULL, SkMatrix::I(), SkIRect());
}
-bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
#if SK_SUPPORT_GPU
SkBitmap input = src;
SkASSERT(fInputCount == 1);
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (this->getInput(0) &&
- !this->getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) {
+ !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
return false;
}
GrTexture* srcTexture = input.getTexture();
SkIRect bounds;
src.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
SkRect srcRect = SkRect::Make(bounds);
offset->fX = bounds.left();
offset->fY = bounds.top();
bounds.offset(-srcOffset);
- SkMatrix matrix(ctm);
+ SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
this->asNewEffect(&effect, srcTexture, matrix, bounds);
SkASSERT(effect);
}
bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy,
- const SkBitmap& src, const SkMatrix& ctm,
+ const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
// Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity
// matrix with no clip and that the matrix, clip, and render target set before this function was
GrContext* context = src.getTexture()->getContext();
GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
if (this->canFilterImageGPU()) {
- return this->filterImageGPU(proxy, src, ctm, result, offset);
+ return this->filterImageGPU(proxy, src, ctx, result, offset);
} else {
- if (this->filterImage(proxy, src, ctm, result, offset)) {
+ if (this->filterImage(proxy, src, ctx, result, offset)) {
if (!result->getTexture()) {
SkImageInfo info;
if (!result->asImageInfo(&info)) {
explicit SkAlphaThresholdFilterImpl(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture,
}
bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src,
- const SkMatrix& matrix, SkBitmap* dst,
+ const Context& ctx, SkBitmap* dst,
SkIPoint* offset) const {
SkASSERT(src.colorType() == kPMColor_SkColorType);
}
SkMatrix localInverse;
- if (!matrix.invert(&localInverse)) {
+ if (!ctx.ctm().invert(&localInverse)) {
return false;
}
bool SkBicubicImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
- const SkMatrix& matrix,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &srcOffset)) {
+ if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
#if SK_SUPPORT_GPU
-bool SkBicubicImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+bool SkBicubicImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkBitmap srcBM = src;
- if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &srcBM, offset)) {
+ if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &srcBM, offset)) {
return false;
}
GrTexture* srcTexture = srcBM.getTexture();
buffer.writeRect(fDstRect);
}
-bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const SkMatrix& matrix,
+bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkRect bounds, dstRect;
fBitmap.getBounds(&bounds);
- matrix.mapRect(&dstRect, fDstRect);
+ ctx.ctm().mapRect(&dstRect, fDstRect);
if (fSrcRect == bounds && dstRect == bounds) {
// No regions cropped out or resized; return entire bitmap.
*result = fBitmap;
}
bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
- const SkBitmap& source, const SkMatrix& ctm,
+ const SkBitmap& source, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcOffset)) {
+ if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkIRect srcBounds, dstBounds;
src.getBounds(&srcBounds);
srcBounds.offset(srcOffset);
- if (!this->applyCropRect(&srcBounds, ctm)) {
+ if (!this->applyCropRect(&srcBounds, ctx.ctm())) {
return false;
}
}
SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height());
- ctm.mapVectors(&sigma, &localSigma, 1);
+ ctx.ctm().mapVectors(&sigma, &localSigma, 1);
int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX;
int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY;
return true;
}
-bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
#if SK_SUPPORT_GPU
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) {
+ if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
return false;
}
GrTexture* source = input.getTexture();
SkIRect rect;
src.getBounds(&rect);
rect.offset(srcOffset);
- if (!this->applyCropRect(&rect, ctm)) {
+ if (!this->applyCropRect(&rect, ctx.ctm())) {
return false;
}
SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height());
- ctm.mapVectors(&sigma, &localSigma, 1);
+ ctx.ctm().mapVectors(&sigma, &localSigma, 1);
offset->fX = rect.fLeft;
offset->fY = rect.fTop;
rect.offset(-srcOffset);
}
bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
- const SkMatrix& matrix,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &srcOffset)) {
+ if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkIRect bounds;
src.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!this->applyCropRect(&bounds, matrix)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
bool SkComposeImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkImageFilter* outer = getInput(0);
}
if (!outer || !inner) {
- return (outer ? outer : inner)->filterImage(proxy, src, ctm, result, offset);
+ return (outer ? outer : inner)->filterImage(proxy, src, ctx, result, offset);
}
SkBitmap tmp;
- return inner->filterImage(proxy, src, ctm, &tmp, offset) &&
- outer->filterImage(proxy, tmp, ctm, result, offset);
+ return inner->filterImage(proxy, src, ctx, &tmp, offset) &&
+ outer->filterImage(proxy, tmp, ctx, result, offset);
}
bool SkComposeImageFilter::onFilterBounds(const SkIRect& src,
bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* dst,
SkIPoint* offset) const {
SkBitmap displ = src, color = src;
const SkImageFilter* colorInput = getColorInput();
const SkImageFilter* displInput = getDisplacementInput();
SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0, 0);
- if ((colorInput && !colorInput->filterImage(proxy, src, ctm, &color, &colorOffset)) ||
- (displInput && !displInput->filterImage(proxy, src, ctm, &displ, &displOffset))) {
+ if ((colorInput && !colorInput->filterImage(proxy, src, ctx, &color, &colorOffset)) ||
+ (displInput && !displInput->filterImage(proxy, src, ctx, &displ, &displOffset))) {
return false;
}
if ((displ.colorType() != kPMColor_SkColorType) ||
SkIRect bounds;
color.getBounds(&bounds);
bounds.offset(colorOffset);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
SkIRect displBounds;
displ.getBounds(&displBounds);
displBounds.offset(displOffset);
- if (!this->applyCropRect(&displBounds, ctm)) {
+ if (!this->applyCropRect(&displBounds, ctx.ctm())) {
return false;
}
if (!bounds.intersect(displBounds)) {
}
SkVector scale = SkVector::Make(fScale, fScale);
- ctm.mapVectors(&scale, 1);
+ ctx.ctm().mapVectors(&scale, 1);
SkIRect colorBounds = bounds;
colorBounds.offset(-colorOffset);
typedef GrEffect INHERITED;
};
-bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkBitmap colorBM = src;
SkIPoint colorOffset = SkIPoint::Make(0, 0);
- if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctm, &colorBM,
+ if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM,
&colorOffset)) {
return false;
}
SkBitmap displacementBM = src;
SkIPoint displacementOffset = SkIPoint::Make(0, 0);
if (getDisplacementInput() &&
- !getDisplacementInput()->getInputResultGPU(proxy, src, ctm, &displacementBM,
+ !getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacementBM,
&displacementOffset)) {
return false;
}
GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
SkVector scale = SkVector::Make(fScale, fScale);
- ctm.mapVectors(&scale, 1);
+ ctx.ctm().mapVectors(&scale, 1);
SkIRect bounds;
colorBM.getBounds(&bounds);
bounds.offset(colorOffset);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
SkIRect displBounds;
displacementBM.getBounds(&displBounds);
displBounds.offset(displacementOffset);
- if (!this->applyCropRect(&displBounds, ctm)) {
+ if (!this->applyCropRect(&displBounds, ctx.ctm())) {
return false;
}
if (!bounds.intersect(displBounds)) {
buffer.writeColor(fColor);
}
-bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, const SkMatrix& matrix, SkBitmap* result, SkIPoint* offset) const
+bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, const Context& ctx, SkBitmap* result, SkIPoint* offset) const
{
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &srcOffset))
+ if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset))
return false;
SkIRect bounds;
src.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!this->applyCropRect(&bounds, matrix)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
SkCanvas canvas(device.get());
SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY);
- matrix.mapVectors(&sigma, &localSigma, 1);
+ ctx.ctm().mapVectors(&sigma, &localSigma, 1);
sigma.fX = SkMaxScalar(0, sigma.fX);
sigma.fY = SkMaxScalar(0, sigma.fY);
SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, sigma.fY));
paint.setColorFilter(colorFilter.get());
paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
SkVector offsetVec, localOffsetVec = SkVector::Make(fDx, fDy);
- matrix.mapVectors(&offsetVec, &localOffsetVec, 1);
+ ctx.ctm().mapVectors(&offsetVec, &localOffsetVec, 1);
canvas.translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop));
canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint);
canvas.drawBitmap(src, 0, 0);
protected:
explicit SkDiffuseLightingImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix, const SkIRect& bounds) const SK_OVERRIDE;
protected:
explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix, const SkIRect& bounds) const SK_OVERRIDE;
bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
- const SkMatrix& ctm,
+ 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, ctm, &src, &srcOffset)) {
+ if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkIRect bounds;
src.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
return false;
}
- SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm));
+ SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm()));
DiffuseLightingType lightingType(fKD);
offset->fX = bounds.left();
bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
- const SkMatrix& ctm,
+ 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, ctm, &src, &srcOffset)) {
+ if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkIRect bounds;
src.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
offset->fX = bounds.left();
offset->fY = bounds.top();
bounds.offset(-srcOffset);
- SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm));
+ SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm()));
switch (transformedLight->type()) {
case SkLight::kDistant_LightType:
lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
}
bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src,
- const SkMatrix&, SkBitmap* dst,
+ const Context&, SkBitmap* dst,
SkIPoint* offset) const {
SkASSERT(src.colorType() == kPMColor_SkColorType);
SkASSERT(fSrcRect.width() < src.width());
bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
- const SkMatrix& matrix,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &srcOffset)) {
+ if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkIRect bounds;
src.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!this->applyCropRect(&bounds, matrix)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
}
bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
if (countInputs() < 1) {
return false;
SkIRect bounds;
src.getBounds(&bounds);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
SkIPoint pos = SkIPoint::Make(0, 0);
SkImageFilter* filter = getInput(i);
if (filter) {
- if (!filter->filterImage(proxy, src, ctm, &tmp, &pos)) {
+ if (!filter->filterImage(proxy, src, ctx, &tmp, &pos)) {
return false;
}
srcPtr = &tmp;
SkMorphologyImageFilter::Proc procY,
Proxy* proxy,
const SkBitmap& source,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* dst,
SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcOffset)) {
+ if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkIRect bounds;
src.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
SkIntToScalar(this->radius().height()));
- ctm.mapVectors(&radius, 1);
+ ctx.ctm().mapVectors(&radius, 1);
int width = SkScalarFloorToInt(radius.fX);
int height = SkScalarFloorToInt(radius.fY);
}
bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
- const SkBitmap& source, const SkMatrix& ctm,
+ const SkBitmap& source, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const {
Proc erodeXProc = SkMorphologyGetPlatformProc(kErodeX_SkMorphologyProcType);
if (!erodeXProc) {
if (!erodeYProc) {
erodeYProc = erode<kY>;
}
- return this->filterImageGeneric(erodeXProc, erodeYProc, proxy, source, ctm, dst, offset);
+ return this->filterImageGeneric(erodeXProc, erodeYProc, proxy, source, ctx, dst, offset);
}
bool SkDilateImageFilter::onFilterImage(Proxy* proxy,
- const SkBitmap& source, const SkMatrix& ctm,
+ const SkBitmap& source, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const {
Proc dilateXProc = SkMorphologyGetPlatformProc(kDilateX_SkMorphologyProcType);
if (!dilateXProc) {
if (!dilateYProc) {
dilateYProc = dilate<kY>;
}
- return this->filterImageGeneric(dilateXProc, dilateYProc, proxy, source, ctm, dst, offset);
+ return this->filterImageGeneric(dilateXProc, dilateYProc, proxy, source, ctx, dst, offset);
}
void SkMorphologyImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const {
bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
Proxy* proxy,
const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) {
+ if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect bounds;
input.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
SkIntToScalar(this->radius().height()));
- ctm.mapVectors(&radius, 1);
+ ctx.ctm().mapVectors(&radius, 1);
int width = SkScalarFloorToInt(radius.fX);
int height = SkScalarFloorToInt(radius.fY);
return true;
}
-bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
- return this->filterImageGPUGeneric(true, proxy, src, ctm, result, offset);
+ return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset);
}
-bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
- return this->filterImageGPUGeneric(false, proxy, src, ctm, result, offset);
+ return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset);
}
#endif
#include "SkPaint.h"
bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
- const SkMatrix& matrix,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkImageFilter* input = getInput(0);
#else
if (!cropRectIsSet()) {
#endif
- if (input && !input->filterImage(proxy, source, matrix, &src, &srcOffset)) {
+ if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkVector vec;
- matrix.mapVectors(&vec, &fOffset, 1);
+ ctx.ctm().mapVectors(&vec, &fOffset, 1);
offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX);
offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY);
*result = src;
} else {
- if (input && !input->filterImage(proxy, source, matrix, &src, &srcOffset)) {
+ if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
src.getBounds(&bounds);
bounds.offset(srcOffset);
- if (!applyCropRect(&bounds, matrix)) {
+ if (!applyCropRect(&bounds, ctx.ctm())) {
return false;
}
canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft),
SkIntToScalar(srcOffset.fY - bounds.fTop));
SkVector vec;
- matrix.mapVectors(&vec, &fOffset, 1);
+ ctx.ctm().mapVectors(&vec, &fOffset, 1);
canvas.drawBitmap(src, vec.x(), vec.y(), &paint);
*result = device->accessBitmap(false);
offset->fX = bounds.fLeft;
buffer.writeRect(fCropRect);
}
-bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const SkMatrix& matrix,
- SkBitmap* result, SkIPoint* offset) const {
+bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Context& ctx,
+ SkBitmap* result, SkIPoint* offset) const {
if (!fPicture) {
offset->fX = offset->fY = 0;
return true;
SkRect floatBounds;
SkIRect bounds;
- matrix.mapRect(&floatBounds, fCropRect);
+ ctx.ctm().mapRect(&floatBounds, fCropRect);
floatBounds.roundOut(&bounds);
if (bounds.isEmpty()) {
SkPaint paint;
canvas.translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop));
- canvas.concat(matrix);
+ canvas.concat(ctx.ctm());
canvas.drawPicture(*fPicture);
*result = device.get()->accessBitmap(false);
bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkIRect bounds;
source.getBounds(&bounds);
- if (!this->applyCropRect(&bounds, ctm)) {
+ if (!this->applyCropRect(&bounds, ctx.ctm())) {
return false;
}
SkCanvas canvas(device.get());
SkPaint paint;
paint.setShader(fShader);
- SkMatrix matrix(ctm);
+ SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
fShader->setLocalMatrix(matrix);
SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bounds.height()));
bool SkResizeImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcOffset)) {
+ if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
srcBounds.offset(srcOffset);
SkRect srcRect = SkRect::Make(srcBounds);
SkMatrix matrix;
- if (!ctm.invert(&matrix)) {
+ if (!ctx.ctm().invert(&matrix)) {
return false;
}
matrix.postScale(fSx, fSy);
- matrix.postConcat(ctm);
+ matrix.postConcat(ctx.ctm());
matrix.mapRect(&dstRect, srcRect);
dstRect.roundOut(&dstBounds);
///////////////////////////////////////////////////////////////////////////////
bool SkDownSampleImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src,
- const SkMatrix&,
+ const Context&,
SkBitmap* result, SkIPoint*) const {
SkScalar scale = fScale;
if (scale > SK_Scalar1 || scale <= 0) {
#include "SkShader.h"
#include "SkValidationUtils.h"
-bool SkTileImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+bool SkTileImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const SkImageFilter::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, ctm, &source, &srcOffset)) {
+ if (input && !input->filterImage(proxy, src, ctx, &source, &srcOffset)) {
return false;
}
SkRect dstRect;
- ctm.mapRect(&dstRect, fDstRect);
+ ctx.ctm().mapRect(&dstRect, fDstRect);
SkIRect dstIRect;
dstRect.roundOut(&dstIRect);
int w = dstIRect.width();
}
SkRect srcRect;
- ctm.mapRect(&srcRect, fSrcRect);
+ ctx.ctm().mapRect(&srcRect, fSrcRect);
SkIRect srcIRect;
srcRect.roundOut(&srcIRect);
srcIRect.offset(-srcOffset);
bool SkXfermodeImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* dst,
SkIPoint* offset) const {
SkBitmap background = src, foreground = src;
SkImageFilter* foregroundInput = getInput(1);
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
if (backgroundInput &&
- !backgroundInput->filterImage(proxy, src, ctm, &background, &backgroundOffset)) {
+ !backgroundInput->filterImage(proxy, src, ctx, &background, &backgroundOffset)) {
return false;
}
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
if (foregroundInput &&
- !foregroundInput->filterImage(proxy, src, ctm, &foreground, &foregroundOffset)) {
+ !foregroundInput->filterImage(proxy, src, ctx, &foreground, &foregroundOffset)) {
return false;
}
foreground.getBounds(&foregroundBounds);
foregroundBounds.offset(foregroundOffset);
bounds.join(foregroundBounds);
- if (!applyCropRect(&bounds, ctm)) {
+ if (!applyCropRect(&bounds, ctx.ctm())) {
return false;
}
bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
const SkBitmap& src,
- const SkMatrix& ctm,
+ const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap background = src;
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
- if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &background,
+ if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &background,
&backgroundOffset)) {
return false;
}
GrTexture* backgroundTex = background.getTexture();
SkBitmap foreground = src;
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
- if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctm, &foreground,
+ if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground,
&foregroundOffset)) {
return false;
}
static bool filter_texture(SkBaseDevice* device, GrContext* context,
GrTexture* texture, const SkImageFilter* filter,
- int w, int h, const SkMatrix& ctm, SkBitmap* result,
- SkIPoint* offset) {
+ int w, int h, const SkImageFilter::Context& ctx,
+ SkBitmap* result, SkIPoint* offset) {
SkASSERT(filter);
SkDeviceImageFilterProxy proxy(device);
// Save the render target and set it to NULL, so we don't accidentally draw to it in the
// filter. Also set the clip wide open and the matrix to identity.
GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
- return filter->filterImageGPU(&proxy, wrap_texture(texture), ctm, result, offset);
+ return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result, offset);
} else {
return false;
}
SkIPoint offset = SkIPoint::Make(0, 0);
SkMatrix matrix(*draw.fMatrix);
matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
- if (filter_texture(this, fContext, texture, filter, w, h, matrix, &filteredBitmap,
+ SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
+ SkImageFilter::Context ctx(matrix, clipBounds);
+ if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filteredBitmap,
&offset)) {
texture = (GrTexture*) filteredBitmap.getTexture();
w = filteredBitmap.width();
SkIPoint offset = SkIPoint::Make(0, 0);
SkMatrix matrix(*draw.fMatrix);
matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
- if (filter_texture(this, fContext, devTex, filter, w, h, matrix, &filteredBitmap,
+ SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height());
+ SkImageFilter::Context ctx(matrix, clipBounds);
+ if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredBitmap,
&offset)) {
devTex = filteredBitmap.getTexture();
w = filteredBitmap.width();
}
bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src,
- const SkMatrix& ctm,
+ const SkImageFilter::Context& ctx,
SkBitmap* result, SkIPoint* offset) {
// want explicitly our impl, so guard against a subclass of us overriding it
if (!this->SkGpuDevice::canHandleImageFilter(filter)) {
// must be pushed upstack.
SkAutoCachedTexture act(this, src, NULL, &texture);
- return filter_texture(this, fContext, texture, filter, src.width(), src.height(), ctm, result,
- offset);
+ return filter_texture(this, fContext, texture, filter, src.width(), src.height(), ctx,
+ result, offset);
}
///////////////////////////////////////////////////////////////////////////////
return false;
}
virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
- const SkMatrix&, SkBitmap*, SkIPoint*) SK_OVERRIDE {
+ const SkImageFilter::Context&, SkBitmap*, SkIPoint*) SK_OVERRIDE {
return false;
}
virtual void unlockPixels() SK_OVERRIDE { NothingToDo(); }
virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE { return false; }
virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE { return false; }
- virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
+ virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE {
return false;
}
virtual void unlockPixels() SK_OVERRIDE { nothing_to_do(); }
virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE { return false; }
virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE { return false; }
- virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
+ virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE {
return false;
}
: SkImageFilter(0), fReporter(reporter), fExpectedMatrix(expectedMatrix) {
}
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE {
- REPORTER_ASSERT(fReporter, ctm == fExpectedMatrix);
+ REPORTER_ASSERT(fReporter, ctx.ctm() == fExpectedMatrix);
return true;
}
SkDeviceImageFilterProxy proxy(&device);
SkIPoint loc = SkIPoint::Make(0, 0);
// An empty input should early return and return false
+ SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeEmpty());
REPORTER_ASSERT(reporter,
- !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &loc));
+ !bicubic->filterImage(&proxy, bitmap, ctx, &result, &loc));
}
}
}
SkIPoint offset;
SkString str;
str.printf("filter %d", static_cast<int>(i));
- REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &offset), str.c_str());
+ SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeEmpty());
+ 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());
}