aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-17 19:35:09 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-17 19:35:09 +0000
commit1aa68723b8ef4ce0b6db9fe51e7d8051cdd543ff (patch)
treeed72c3ebed65ccecfafb41aecd2e8507a635d988
parent32bbcf828d66ad244fa25b468bc3a229e531491f (diff)
Make SkImageFilter::asNewEffect() (and all derived-class overrides) protected.
R=bsalomon@google.com, bsalomon Review URL: https://codereview.chromium.org/26937006 git-svn-id: http://skia.googlecode.com/svn/trunk@11847 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkImageFilter.h34
-rw-r--r--include/effects/SkMagnifierImageFilter.h7
-rw-r--r--src/effects/SkLightingImageFilter.cpp15
-rw-r--r--src/effects/SkMagnifierImageFilter.cpp20
4 files changed, 37 insertions, 39 deletions
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 60cc63f13b..9c1fd6c812 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -86,23 +86,6 @@ public:
bool filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst);
/**
- * Returns true if the filter can be expressed a single-pass
- * GrEffect, used to process this filter on the GPU, or false if
- * not.
- *
- * If effect is non-NULL, a new GrEffect instance is stored
- * in it. The caller assumes ownership of the stage, and it is up to the
- * caller to unref it.
- *
- * The effect can assume its vertexCoords space maps 1-to-1 with texels
- * in the texture. "matrix" is a transformation to apply to filter
- * parameters before they are used in the effect. Note that this function
- * will be called with (NULL, NULL, SkMatrix::I()) to query for support,
- * so returning "true" indicates support for all possible matrices.
- */
- virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix) const;
-
- /**
* 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().
@@ -185,6 +168,23 @@ protected:
// false and leaves "rect" unchanged.
bool applyCropRect(SkIRect* rect, const SkMatrix& matrix) const;
+ /**
+ * Returns true if the filter can be expressed a single-pass
+ * GrEffect, used to process this filter on the GPU, or false if
+ * not.
+ *
+ * If effect is non-NULL, a new GrEffect instance is stored
+ * in it. The caller assumes ownership of the stage, and it is up to the
+ * caller to unref it.
+ *
+ * The effect can assume its vertexCoords space maps 1-to-1 with texels
+ * in the texture. "matrix" is a transformation to apply to filter
+ * parameters before they are used in the effect. Note that this function
+ * will be called with (NULL, NULL, SkMatrix::I()) to query for support,
+ * so returning "true" indicates support for all possible matrices.
+ */
+ virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix) const;
+
private:
typedef SkFlattenable INHERITED;
int fInputCount;
diff --git a/include/effects/SkMagnifierImageFilter.h b/include/effects/SkMagnifierImageFilter.h
index 31b446f6a5..9ce349d11e 100644
--- a/include/effects/SkMagnifierImageFilter.h
+++ b/include/effects/SkMagnifierImageFilter.h
@@ -16,10 +16,6 @@ class SK_API SkMagnifierImageFilter : public SkImageFilter {
public:
SkMagnifierImageFilter(SkRect srcRect, SkScalar inset);
-#if SK_SUPPORT_GPU
- virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, const SkMatrix& matrix) const SK_OVERRIDE;
-#endif
-
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMagnifierImageFilter)
protected:
@@ -28,6 +24,9 @@ protected:
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
+#if SK_SUPPORT_GPU
+ virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, const SkMatrix& matrix) const SK_OVERRIDE;
+#endif
private:
SkRect fSrcRect;
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index a41a8f52f5..d34bd7a5d7 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -262,10 +262,6 @@ public:
SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale,
SkScalar kd, SkImageFilter* input, const CropRect* cropRect);
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFilter)
-
-#if SK_SUPPORT_GPU
- virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix) const SK_OVERRIDE;
-#endif
SkScalar kd() const { return fKD; }
protected:
@@ -273,7 +269,9 @@ protected:
virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
-
+#if SK_SUPPORT_GPU
+ virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix) const SK_OVERRIDE;
+#endif
private:
typedef SkLightingImageFilter INHERITED;
@@ -285,10 +283,6 @@ public:
SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect);
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageFilter)
-#if SK_SUPPORT_GPU
- virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix) const SK_OVERRIDE;
-#endif
-
SkScalar ks() const { return fKS; }
SkScalar shininess() const { return fShininess; }
@@ -297,6 +291,9 @@ protected:
virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
+#if SK_SUPPORT_GPU
+ virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix) const SK_OVERRIDE;
+#endif
private:
typedef SkLightingImageFilter INHERITED;
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index e3d6efd437..bef1e8da81 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -184,6 +184,7 @@ GrEffectRef* GrMagnifierEffect::TestCreate(SkRandom* random,
GrContext* context,
const GrDrawTargetCaps&,
GrTexture** textures) {
+ GrTexture* texture = textures[0];
const int kMaxWidth = 200;
const int kMaxHeight = 200;
const int kMaxInset = 20;
@@ -191,15 +192,16 @@ GrEffectRef* GrMagnifierEffect::TestCreate(SkRandom* random,
uint32_t height = random->nextULessThan(kMaxHeight);
uint32_t x = random->nextULessThan(kMaxWidth - width);
uint32_t y = random->nextULessThan(kMaxHeight - height);
- SkScalar inset = SkIntToScalar(random->nextULessThan(kMaxInset));
-
- SkAutoTUnref<SkMagnifierImageFilter> filter(
- new SkMagnifierImageFilter(
- SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
- SkIntToScalar(width), SkIntToScalar(height)),
- inset));
- GrEffectRef* effect;
- filter->asNewEffect(&effect, textures[0], SkMatrix::I());
+ uint32_t inset = random->nextULessThan(kMaxInset);
+
+ GrEffectRef* effect = GrMagnifierEffect::Create(
+ texture,
+ (float) width / texture->width(),
+ (float) height / texture->height(),
+ texture->width() / (float) x,
+ texture->height() / (float) y,
+ (float) inset / texture->width(),
+ (float) inset / texture->height());
SkASSERT(NULL != effect);
return effect;
}