OSDN Git Service

Bugfix (5085850): Added function to allow easy initialization of program host variables.
authorMarius Renn <renn@google.com>
Mon, 1 Aug 2011 19:29:33 +0000 (12:29 -0700)
committerMarius Renn <renn@google.com>
Mon, 1 Aug 2011 19:29:33 +0000 (12:29 -0700)
Change-Id: If7d88a015b75937d5f49cdb51120de5f75ee6d17

Changed 2 filters to use new simplified method.

Note: This requires that other affected filters are updated to make
use of the new functionality.

mca/filterfw/java/android/filterfw/core/FieldPort.java
mca/filterfw/java/android/filterfw/core/Filter.java
mca/filterfw/java/android/filterfw/core/InputPort.java
mca/filterpacks/imageproc/java/ImageCombineFilter.java
mca/filterpacks/imageproc/java/SimpleImageFilter.java

index da9868d..e9251b5 100644 (file)
@@ -50,6 +50,15 @@ public class FieldPort extends InputPort {
     }
 
     @Override
+    public Object getTarget() {
+        try {
+            return mField.get(mFilter);
+        } catch (IllegalAccessException e) {
+            return null;
+        }
+    }
+
+    @Override
     public synchronized void transfer(FilterContext context) {
         if (mValueWaiting) {
             try {
index d855394..c2d2c82 100644 (file)
@@ -279,6 +279,20 @@ public abstract class Filter {
     }
 
     /**
+     * Assigns all program variables to the ports they are connected to. Call this after
+     * constructing a Program instance with attached ProgramPorts.
+     */
+    protected void initProgramInputs(Program program, FilterContext context) {
+        if (program != null) {
+            for (InputPort inputPort : mInputPorts.values()) {
+                if (inputPort.getTarget() == program) {
+                    inputPort.transfer(context);
+                }
+            }
+        }
+    }
+
+    /**
      * Adds an input port to the filter. You should call this from within setupPorts, if your
      * filter has input ports. No type-checking is performed on the input. If you would like to
      * check against a type mask, use
index 53e8442..de5cccc 100644 (file)
@@ -65,6 +65,10 @@ public abstract class InputPort extends FilterPort {
         return mSourcePort != null ? mSourcePort.getPortFormat() : getPortFormat();
     }
 
+    public Object getTarget() {
+        return null;
+    }
+
     public boolean filterMustClose() {
         return !isOpen() && isBlocking() && !hasFrame();
     }
index e4b289e..858489b 100644 (file)
@@ -128,9 +128,7 @@ public abstract class ImageCombineFilter extends Filter {
                 throw new RuntimeException("Could not create a program for image filter "
                     + this + "!");
             }
-            if (mParameterName != null) {
-                transferInputPortFrame(mParameterName, context);
-            }
+            initProgramInputs(mProgram, context);
             mCurrentTarget = target;
         }
     }
index 8df7334..f4fc271 100644 (file)
@@ -105,9 +105,7 @@ public abstract class SimpleImageFilter extends Filter {
             if (mProgram == null) {
                 throw new RuntimeException("Could not create a program for image filter " + this + "!");
             }
-            if (mParameterName != null) {
-                transferInputPortFrame(mParameterName, context);
-            }
+            initProgramInputs(mProgram, context);
             mCurrentTarget = target;
         }
     }