modules/graphics/src/main/java/com/sun/scenario/effect/Reflection.java

Print this page




  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;
  27 
  28 import com.sun.javafx.geom.Point2D;
  29 import com.sun.javafx.geom.BaseBounds;
  30 import com.sun.javafx.geom.DirtyRegionContainer;
  31 import com.sun.javafx.geom.DirtyRegionPool;
  32 import com.sun.javafx.geom.RectBounds;
  33 import com.sun.javafx.geom.Rectangle;
  34 import com.sun.javafx.geom.transform.BaseTransform;

  35   
  36 /**
  37  * An effect that renders a reflected version of the input below the
  38  * actual input content.
  39  */
  40 public class Reflection extends CoreEffect {
  41 
  42     private float topOffset;
  43     private float topOpacity;
  44     private float bottomOpacity;
  45     private float fraction;
  46 
  47     /**
  48      * Constructs a new {@code Reflection} effect with default values,
  49      * using the default input for source data.
  50      * This is a shorthand equivalent to:
  51      * <pre>
  52      *     new Reflection(DefaultInput)
  53      * </pre>
  54      */


 214         this.fraction = fraction;
 215     }
 216 
 217     @Override
 218     public BaseBounds getBounds(BaseTransform transform,
 219                               Effect defaultInput)
 220     {
 221         Effect input = getDefaultedInput(0, defaultInput);
 222         BaseBounds r = input.getBounds(BaseTransform.IDENTITY_TRANSFORM, defaultInput);
 223         r.roundOut(); // NOTE is this really necessary?
 224         float x1 = (float) r.getMinX();
 225         float y1 = (float) (r.getMaxY() + topOffset);
 226         float x2 = (float) r.getMaxX();
 227         float y2 = (float) (y1 + (fraction * r.getHeight()));
 228         BaseBounds ret = new RectBounds(x1, y1, x2, y2);
 229         ret = ret.deriveWithUnion(r);
 230         return transformBounds(transform, ret);
 231     }
 232 
 233     @Override
 234     public boolean operatesInUserSpace() {
 235         return true;
 236     }
 237 
 238     @Override
 239     public Point2D transform(Point2D p, Effect defaultInput) {
 240         return getDefaultedInput(0, defaultInput).transform(p, defaultInput);
 241     }
 242 
 243     @Override
 244     public Point2D untransform(Point2D p, Effect defaultInput) {
 245         return getDefaultedInput(0, defaultInput).untransform(p, defaultInput);
 246     }
 247 
 248     @Override
 249     protected Rectangle getInputClip(int inputIndex,
 250                                      BaseTransform transform,
 251                                      Rectangle outputClip)


 252     {
 253         // RT-27405
 254         // TODO: Calculate which parts are needed based on the two
 255         // ways that the input is rendered into this ouput rectangle.
 256         // For now, just ask for the entire input.
 257         return null;
 258     }
 259 
 260     @Override
 261     public boolean reducesOpaquePixels() {
 262         final Effect input = getInput();
 263         return input != null && input.reducesOpaquePixels();
 264     }
 265 
 266     @Override
 267     public DirtyRegionContainer getDirtyRegions(Effect defaultInput, DirtyRegionPool regionPool) {
 268         Effect di = getDefaultedInput(0, defaultInput);
 269         DirtyRegionContainer drc = di.getDirtyRegions(defaultInput, regionPool);
 270 
 271         BaseBounds contentBounds = di.getBounds(BaseTransform.IDENTITY_TRANSFORM, defaultInput);
 272         float cbMaxY = contentBounds.getMaxY();
 273         float reflectedMaxYBase = (2 * cbMaxY) + getTopOffset();
 274         float reflecteCbMaxY = cbMaxY + getTopOffset() + (fraction * contentBounds.getHeight());
 275         DirtyRegionContainer newDRC = regionPool.checkOut();
 276         for (int i = 0; i < drc.size(); i++) {
 277             BaseBounds regionBounds = drc.getDirtyRegion(i);


  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;
  27 
  28 import com.sun.javafx.geom.Point2D;
  29 import com.sun.javafx.geom.BaseBounds;
  30 import com.sun.javafx.geom.DirtyRegionContainer;
  31 import com.sun.javafx.geom.DirtyRegionPool;
  32 import com.sun.javafx.geom.RectBounds;
  33 import com.sun.javafx.geom.Rectangle;
  34 import com.sun.javafx.geom.transform.BaseTransform;
  35 import com.sun.scenario.effect.impl.state.RenderState;
  36   
  37 /**
  38  * An effect that renders a reflected version of the input below the
  39  * actual input content.
  40  */
  41 public class Reflection extends CoreEffect {
  42 
  43     private float topOffset;
  44     private float topOpacity;
  45     private float bottomOpacity;
  46     private float fraction;
  47 
  48     /**
  49      * Constructs a new {@code Reflection} effect with default values,
  50      * using the default input for source data.
  51      * This is a shorthand equivalent to:
  52      * <pre>
  53      *     new Reflection(DefaultInput)
  54      * </pre>
  55      */


 215         this.fraction = fraction;
 216     }
 217 
 218     @Override
 219     public BaseBounds getBounds(BaseTransform transform,
 220                               Effect defaultInput)
 221     {
 222         Effect input = getDefaultedInput(0, defaultInput);
 223         BaseBounds r = input.getBounds(BaseTransform.IDENTITY_TRANSFORM, defaultInput);
 224         r.roundOut(); // NOTE is this really necessary?
 225         float x1 = (float) r.getMinX();
 226         float y1 = (float) (r.getMaxY() + topOffset);
 227         float x2 = (float) r.getMaxX();
 228         float y2 = (float) (y1 + (fraction * r.getHeight()));
 229         BaseBounds ret = new RectBounds(x1, y1, x2, y2);
 230         ret = ret.deriveWithUnion(r);
 231         return transformBounds(transform, ret);
 232     }
 233 
 234     @Override





 235     public Point2D transform(Point2D p, Effect defaultInput) {
 236         return getDefaultedInput(0, defaultInput).transform(p, defaultInput);
 237     }
 238 
 239     @Override
 240     public Point2D untransform(Point2D p, Effect defaultInput) {
 241         return getDefaultedInput(0, defaultInput).untransform(p, defaultInput);
 242     }
 243 
 244     @Override
 245     public RenderState getRenderState(FilterContext fctx,
 246                                       BaseTransform transform,
 247                                       Rectangle outputClip,
 248                                       Object renderHelper,
 249                                       Effect defaultInput)
 250     {
 251         // RT-27405
 252         // TODO: We could calculate which parts are needed based on the two
 253         // ways that the input is rendered into this ouput rectangle. For now,
 254         // we will just use the stock object that requests unclipped inputs.
 255         return RenderState.UnclippedUserSpaceRenderState;
 256     }
 257 
 258     @Override
 259     public boolean reducesOpaquePixels() {
 260         final Effect input = getInput();
 261         return input != null && input.reducesOpaquePixels();
 262     }
 263 
 264     @Override
 265     public DirtyRegionContainer getDirtyRegions(Effect defaultInput, DirtyRegionPool regionPool) {
 266         Effect di = getDefaultedInput(0, defaultInput);
 267         DirtyRegionContainer drc = di.getDirtyRegions(defaultInput, regionPool);
 268 
 269         BaseBounds contentBounds = di.getBounds(BaseTransform.IDENTITY_TRANSFORM, defaultInput);
 270         float cbMaxY = contentBounds.getMaxY();
 271         float reflectedMaxYBase = (2 * cbMaxY) + getTopOffset();
 272         float reflecteCbMaxY = cbMaxY + getTopOffset() + (fraction * contentBounds.getHeight());
 273         DirtyRegionContainer newDRC = regionPool.checkOut();
 274         for (int i = 0; i < drc.size(); i++) {
 275             BaseBounds regionBounds = drc.getDirtyRegion(i);