class SkColorFilter;
class SkBaseDevice;
struct SkIPoint;
-class GrEffect;
+class GrFragmentProcessor;
class GrTexture;
/**
/**
* Returns true if the filter can be processed on the GPU. This is most
* often used for multi-pass effects, where intermediate results must be
- * rendered to textures. For single-pass effects, use asNewEffect().
- * The default implementation returns asNewEffect(NULL, NULL, SkMatrix::I(),
+ * rendered to textures. For single-pass effects, use asFragmentProcessor().
+ * The default implementation returns asFragmentProcessor(NULL, NULL, SkMatrix::I(),
* SkIRect()).
*/
virtual bool canFilterImageGPU() const;
/**
* Process this image filter on the GPU. This is most often used for
* multi-pass effects, where intermediate results must be rendered to
- * textures. For single-pass effects, use asNewEffect(). src is the
+ * textures. For single-pass effects, use asFragmentProcessor(). src is the
* source image for processing, as a texture-backed bitmap. result is
* the destination bitmap, which should contain a texture-backed pixelref
* on success. offset is the amount to translate the resulting image
* relative to the src when it is drawn. The default implementation does
- * single-pass processing using asNewEffect().
+ * single-pass processing using asFragmentProcessor().
*/
virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
SkBitmap* result, SkIPoint* offset) const;
#endif
- /**
- * Set an external cache to be used for all image filter processing. This
- * will replace the default intra-frame cache.
- */
- static void SetExternalCache(Cache* cache);
-
- /**
- * Returns the currently-set external cache, or NULL if none is set.
- */
- static Cache* GetExternalCache();
-
SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
protected:
Common() {}
~Common();
- bool unflatten(SkReadBuffer&, int expectedInputs = -1);
-
- CropRect cropRect() const { return fCropRect; }
+ /**
+ * Attempt to unflatten the cropRect and the expected number of input filters.
+ * If any number of input filters is valid, pass -1.
+ * If this fails (i.e. corrupt buffer or contents) then return false and common will
+ * be left uninitialized.
+ * If this returns true, then inputCount() is the number of found input filters, each
+ * of which may be NULL or a valid imagefilter.
+ */
+ bool unflatten(SkReadBuffer&, int expectedInputs);
+
+ const CropRect& cropRect() const { return fCropRect; }
int inputCount() const { return fInputs.count(); }
SkImageFilter** inputs() const { return fInputs.get(); }
uint32_t uniqueID() const { return fUniqueID; }
+ SkImageFilter* getInput(int index) const { return fInputs[index]; }
+
// If the caller wants a copy of the inputs, call this and it will transfer ownership
// of the unflattened input filters to the caller. This is just a short-cut for copying
// the inputs, calling ref() on each, and then waiting for Common's destructor to call
void allocInputs(int count);
};
- SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect = NULL);
+ SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect = NULL, uint32_t uniqueID = 0);
virtual ~SkImageFilter();
*/
explicit SkImageFilter(int inputCount, SkReadBuffer& rb);
- virtual void flatten(SkWriteBuffer& wb) const SK_OVERRIDE;
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
/**
* This is the virtual which should be overridden by the derived class
/**
* Returns true if the filter can be expressed a single-pass
- * GrEffect, used to process this filter on the GPU, or false if
+ * GrProcessor, used to process this filter on the GPU, or false if
* not.
*
- * If effect is non-NULL, a new GrEffect instance is stored
+ * If effect is non-NULL, a new GrProcessor instance is stored
* in it. The caller assumes ownership of the stage, and it is up to the
* caller to unref it.
*
* will be called with (NULL, NULL, SkMatrix::I()) to query for support,
* so returning "true" indicates support for all possible matrices.
*/
- virtual bool asNewEffect(GrEffect** effect,
- GrTexture*,
- const SkMatrix& matrix,
- const SkIRect& bounds) const;
+ virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&,
+ const SkIRect& bounds) const;
private:
bool usesSrcInput() const { return fUsesSrcInput; }
uint32_t fUniqueID; // Globally unique
};
+/**
+ * Helper to unflatten the common data, and return NULL if we fail.
+ */
+#define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \
+ Common localVar; \
+ do { \
+ if (!localVar.unflatten(buffer, expectedCount)) { \
+ return NULL; \
+ } \
+ } while (0)
+
#endif