15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.scenario.effect.impl;
27
28 import com.sun.scenario.effect.Effect;
29 import com.sun.scenario.effect.Effect.AccelType;
30 import com.sun.scenario.effect.FilterContext;
31 import com.sun.scenario.effect.ImageData;
32 import com.sun.javafx.geom.Rectangle;
33 import com.sun.javafx.geom.transform.BaseTransform;
34 import com.sun.javafx.geom.transform.NoninvertibleTransformException;
35
36 /**
37 * The abstract base class for all {@code Effect} implementation peers.
38 */
39 public abstract class EffectPeer {
40
41 private final FilterContext fctx;
42 private final Renderer renderer;
43 private final String uniqueName;
44 private Effect effect;
45 private int pass;
46
47 protected EffectPeer(FilterContext fctx, Renderer renderer, String uniqueName) {
48 if (fctx == null) {
49 throw new IllegalArgumentException("FilterContext must be non-null");
50 }
51 this.fctx = fctx;
52 this.renderer = renderer;
53 this.uniqueName = uniqueName;
54 }
55
56 public boolean isImageDataCompatible(ImageData id) {
57 return getRenderer().isImageDataCompatible(id);
58 }
59
60 public abstract ImageData filter(Effect effect,
61 BaseTransform transform,
62 Rectangle outputClip,
63 ImageData... inputs);
64
65 /**
66 * Disposes resources associated with this peer.
67 * Warning: may be called from the rendering thread.
68 */
69 public void dispose() {
70 }
71
72 public AccelType getAccelType() {
73 return renderer.getAccelType();
74 }
75
76 protected final FilterContext getFilterContext() {
77 return fctx;
78 }
79
80 protected Renderer getRenderer() {
84 /**
85 * Returns the unique name of this peer. This value can be used as
86 * the key value in a hashmap of cached peer instances. In the case
87 * of hardware peers, this value is typically the name of the shader that
88 * is used by the peer.
89 *
90 * @return the unique name of this peer
91 */
92 public String getUniqueName() {
93 return uniqueName;
94 }
95
96 protected Effect getEffect() {
97 return effect;
98 }
99
100 protected void setEffect(Effect effect) {
101 this.effect = effect;
102 }
103
104 public final int getPass() {
105 return pass;
106 }
107
108 public void setPass(int pass) {
109 this.pass = pass;
110 }
111
112 // NOTE: this input(Native)Bounds stuff is unpleasant, but we somehow
113 // need to provide access to the native surface bounds for various glue
114 // methods (e.g. getKvals())
115
116 private final Rectangle[] inputBounds = new Rectangle[2];
117 /**
118 * Returns the "valid" bounds of the source image for the given input.
119 * Since Effect implementations try to recycle temporary Images, it is
120 * quite possible that the input bounds returned by this method will
121 * differ from the size of the associated input Image. For example,
122 * this method may return (0, 0, 210, 180) even though the associated
123 * Image has dimensions of 230x200 pixels. Pixels in the input Image
|
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.scenario.effect.impl;
27
28 import com.sun.scenario.effect.Effect;
29 import com.sun.scenario.effect.Effect.AccelType;
30 import com.sun.scenario.effect.FilterContext;
31 import com.sun.scenario.effect.ImageData;
32 import com.sun.javafx.geom.Rectangle;
33 import com.sun.javafx.geom.transform.BaseTransform;
34 import com.sun.javafx.geom.transform.NoninvertibleTransformException;
35 import com.sun.scenario.effect.impl.state.RenderState;
36
37 /**
38 * The abstract base class for all {@code Effect} implementation peers.
39 *
40 * @param <T> an optional subclass of RenderState that can be assumed as the
41 * return value for the getRenderState() method
42 */
43 public abstract class EffectPeer<T extends RenderState> {
44
45 private final FilterContext fctx;
46 private final Renderer renderer;
47 private final String uniqueName;
48 private Effect effect;
49 private T renderState;
50 private int pass;
51
52 protected EffectPeer(FilterContext fctx, Renderer renderer, String uniqueName) {
53 if (fctx == null) {
54 throw new IllegalArgumentException("FilterContext must be non-null");
55 }
56 this.fctx = fctx;
57 this.renderer = renderer;
58 this.uniqueName = uniqueName;
59 }
60
61 public boolean isImageDataCompatible(ImageData id) {
62 return getRenderer().isImageDataCompatible(id);
63 }
64
65 public abstract ImageData filter(Effect effect,
66 T renderState,
67 BaseTransform transform,
68 Rectangle outputClip,
69 ImageData... inputs);
70
71 /**
72 * Disposes resources associated with this peer.
73 * Warning: may be called from the rendering thread.
74 */
75 public void dispose() {
76 }
77
78 public AccelType getAccelType() {
79 return renderer.getAccelType();
80 }
81
82 protected final FilterContext getFilterContext() {
83 return fctx;
84 }
85
86 protected Renderer getRenderer() {
90 /**
91 * Returns the unique name of this peer. This value can be used as
92 * the key value in a hashmap of cached peer instances. In the case
93 * of hardware peers, this value is typically the name of the shader that
94 * is used by the peer.
95 *
96 * @return the unique name of this peer
97 */
98 public String getUniqueName() {
99 return uniqueName;
100 }
101
102 protected Effect getEffect() {
103 return effect;
104 }
105
106 protected void setEffect(Effect effect) {
107 this.effect = effect;
108 }
109
110 protected T getRenderState() {
111 return renderState;
112 }
113
114 protected void setRenderState(T renderState) {
115 this.renderState = renderState;
116 }
117
118 public final int getPass() {
119 return pass;
120 }
121
122 public void setPass(int pass) {
123 this.pass = pass;
124 }
125
126 // NOTE: this input(Native)Bounds stuff is unpleasant, but we somehow
127 // need to provide access to the native surface bounds for various glue
128 // methods (e.g. getKvals())
129
130 private final Rectangle[] inputBounds = new Rectangle[2];
131 /**
132 * Returns the "valid" bounds of the source image for the given input.
133 * Since Effect implementations try to recycle temporary Images, it is
134 * quite possible that the input bounds returned by this method will
135 * differ from the size of the associated input Image. For example,
136 * this method may return (0, 0, 210, 180) even though the associated
137 * Image has dimensions of 230x200 pixels. Pixels in the input Image
|