modules/graphics/src/test/java/test/com/sun/javafx/sg/prism/EffectDirtyRegionTest.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 test.com.sun.javafx.sg.prism;
  27 
  28 import javafx.scene.Group;
  29 import javafx.scene.Node;
  30 import javafx.scene.Scene;
  31 import javafx.scene.shape.Rectangle;
  32 import com.sun.javafx.geom.BaseBounds;
  33 import com.sun.javafx.geom.DirtyRegionContainer;
  34 import com.sun.javafx.geom.DirtyRegionPool;
  35 import com.sun.javafx.geom.RectBounds;
  36 import com.sun.javafx.geom.transform.BaseTransform;

  37 import com.sun.javafx.sg.prism.NGNode;
  38 import com.sun.javafx.sg.prism.NGNode;
  39 import com.sun.scenario.effect.Blend;
  40 import com.sun.scenario.effect.Bloom;
  41 import com.sun.scenario.effect.BoxBlur;
  42 import com.sun.scenario.effect.BoxShadow;
  43 import com.sun.scenario.effect.ColorAdjust;
  44 import com.sun.scenario.effect.Crop;
  45 import com.sun.scenario.effect.DropShadow;
  46 import com.sun.scenario.effect.Effect;
  47 import com.sun.scenario.effect.GaussianBlur;
  48 import com.sun.scenario.effect.GeneralShadow;
  49 import com.sun.scenario.effect.Glow;
  50 import com.sun.scenario.effect.InnerShadow;
  51 import com.sun.scenario.effect.MotionBlur;
  52 import com.sun.scenario.effect.Offset;
  53 import com.sun.scenario.effect.SepiaTone;
  54 import junit.framework.Assert;
  55 import org.junit.Test;
  56 


 467     }
 468 
 469     private void setupTest() {
 470         drc = new DirtyRegionContainer(6);
 471         drcExpected = new DirtyRegionContainer(6);
 472         drp = new DirtyRegionPool(4);
 473 
 474         Node g1 = group(new Rectangle(50, 50, 10, 10));
 475         g1bn = getBaseNode(g1);
 476         Node g = group(g1, new Rectangle(70, 70, 10, 10));
 477         gbn = getBaseNode(g);
 478     }
 479 
 480     private void compareResult(DirtyRegionContainer expected, DirtyRegionContainer computed) {
 481         for (int i = 0; i < computed.size(); i++) {
 482             Assert.assertEquals(expected.getDirtyRegion(i), computed.getDirtyRegion(i));
 483         }
 484     }
 485 
 486     public static NGNode getBaseNode(Node n) {
 487         Scene.impl_setAllowPGAccess(true);
 488         // Eeek, this is gross! I have to use reflection to invoke this
 489         // method so that bounds are updated...
 490         try {
 491             java.lang.reflect.Method method = Node.class.getDeclaredMethod("updateBounds");
 492             method.setAccessible(true);
 493             method.invoke(n);
 494         } catch (Exception e) {
 495             throw new RuntimeException("Failed to update bounds", e);
 496         }
 497         n.impl_updatePeer();
 498         NGNode bn = n.impl_getPeer();
 499         Scene.impl_setAllowPGAccess(false);
 500         return bn;
 501     }
 502 
 503     public static Node group(Node... n) {
 504         Group g = new Group(n);
 505         return g;
 506     }
 507 
 508     public static BaseBounds getBounds(Node n, BaseTransform tx) {
 509         NGNode pgn = getBaseNode(n);
 510         return pgn.getContentBounds(new RectBounds(), tx);
 511     }
 512 }
   1 /*
   2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 test.com.sun.javafx.sg.prism;
  27 
  28 import javafx.scene.Group;
  29 import javafx.scene.Node;
  30 import javafx.scene.Scene;
  31 import javafx.scene.shape.Rectangle;
  32 import com.sun.javafx.geom.BaseBounds;
  33 import com.sun.javafx.geom.DirtyRegionContainer;
  34 import com.sun.javafx.geom.DirtyRegionPool;
  35 import com.sun.javafx.geom.RectBounds;
  36 import com.sun.javafx.geom.transform.BaseTransform;
  37 import com.sun.javafx.scene.SceneHelper;
  38 import com.sun.javafx.sg.prism.NGNode;
  39 import com.sun.javafx.sg.prism.NGNode;
  40 import com.sun.scenario.effect.Blend;
  41 import com.sun.scenario.effect.Bloom;
  42 import com.sun.scenario.effect.BoxBlur;
  43 import com.sun.scenario.effect.BoxShadow;
  44 import com.sun.scenario.effect.ColorAdjust;
  45 import com.sun.scenario.effect.Crop;
  46 import com.sun.scenario.effect.DropShadow;
  47 import com.sun.scenario.effect.Effect;
  48 import com.sun.scenario.effect.GaussianBlur;
  49 import com.sun.scenario.effect.GeneralShadow;
  50 import com.sun.scenario.effect.Glow;
  51 import com.sun.scenario.effect.InnerShadow;
  52 import com.sun.scenario.effect.MotionBlur;
  53 import com.sun.scenario.effect.Offset;
  54 import com.sun.scenario.effect.SepiaTone;
  55 import junit.framework.Assert;
  56 import org.junit.Test;
  57 


 468     }
 469 
 470     private void setupTest() {
 471         drc = new DirtyRegionContainer(6);
 472         drcExpected = new DirtyRegionContainer(6);
 473         drp = new DirtyRegionPool(4);
 474 
 475         Node g1 = group(new Rectangle(50, 50, 10, 10));
 476         g1bn = getBaseNode(g1);
 477         Node g = group(g1, new Rectangle(70, 70, 10, 10));
 478         gbn = getBaseNode(g);
 479     }
 480 
 481     private void compareResult(DirtyRegionContainer expected, DirtyRegionContainer computed) {
 482         for (int i = 0; i < computed.size(); i++) {
 483             Assert.assertEquals(expected.getDirtyRegion(i), computed.getDirtyRegion(i));
 484         }
 485     }
 486 
 487     public static NGNode getBaseNode(Node n) {
 488         SceneHelper.setAllowPGAccess(true);
 489         // Eeek, this is gross! I have to use reflection to invoke this
 490         // method so that bounds are updated...
 491         try {
 492             java.lang.reflect.Method method = Node.class.getDeclaredMethod("updateBounds");
 493             method.setAccessible(true);
 494             method.invoke(n);
 495         } catch (Exception e) {
 496             throw new RuntimeException("Failed to update bounds", e);
 497         }
 498         n.impl_updatePeer();
 499         NGNode bn = n.impl_getPeer();
 500         SceneHelper.setAllowPGAccess(false);
 501         return bn;
 502     }
 503 
 504     public static Node group(Node... n) {
 505         Group g = new Group(n);
 506         return g;
 507     }
 508 
 509     public static BaseBounds getBounds(Node n, BaseTransform tx) {
 510         NGNode pgn = getBaseNode(n);
 511         return pgn.getContentBounds(new RectBounds(), tx);
 512     }
 513 }