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

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:


   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 com.sun.javafx.sg.prism;
  27 
  28 import com.sun.javafx.geom.BaseBounds;
  29 import com.sun.javafx.geom.RectBounds;
  30 import com.sun.javafx.geom.Rectangle;
  31 import com.sun.javafx.geom.transform.BaseTransform;




  32 import com.sun.prism.Graphics;
  33 import com.sun.prism.paint.Color;
  34 import com.sun.scenario.effect.Blend;
  35 import com.sun.scenario.effect.Effect;
  36 import com.sun.scenario.effect.FilterContext;
  37 import com.sun.scenario.effect.ImageData;
  38 import org.junit.Before;
  39 import org.junit.Test;
  40 import static org.junit.Assert.assertEquals;
  41 import static org.junit.Assert.assertFalse;
  42 import static org.junit.Assert.assertNotNull;
  43 import static org.junit.Assert.assertNotSame;
  44 import static org.junit.Assert.assertNull;
  45 import static org.junit.Assert.assertSame;
  46 import static org.junit.Assert.assertTrue;
  47 
  48 /**
  49  */
  50 public class NGNodeTest extends NGTestBase {
  51     NGNodeMock n;


 557     @Test public void testGetOpaqueRegionWithTranslatedAndScaledRectangleClip() {
 558         NGRectangle clip = new NGRectangle();
 559         clip.setFillPaint(Color.BLACK);
 560         clip.updateRectangle(0, 0, 4, 4, 0, 0);
 561         clip.setTransformMatrix(
 562                 BaseTransform.getTranslateInstance(2, 2).deriveWithConcatenation(
 563                         BaseTransform.getScaleInstance(.5, .5)));
 564         n.setClipNode(clip);
 565         assertEquals(new RectBounds(2, 2, 4, 4), n.getOpaqueRegion());
 566     }
 567 
 568     @Test public void testGetOpaqueRegionWithRotatedRectangleClip() {
 569         NGRectangle clip = new NGRectangle();
 570         clip.setFillPaint(Color.BLACK);
 571         clip.updateRectangle(0, 0, 4, 4, 0, 0);
 572         clip.setTransformMatrix(BaseTransform.getRotateInstance(45, 5, 5));
 573         n.setClipNode(clip);
 574         assertNull(n.getOpaqueRegion());
 575     }
 576 
 577     class NGNodeMock extends NGNode {
 578         boolean opaqueRegionRecomputed = false;
 579         RectBounds computedOpaqueRegion = new RectBounds(0, 0, 10, 10);
 580 
 581         void changeOpaqueRegion(float x, float y, float x2, float y2) {
 582             computedOpaqueRegion = new RectBounds(x, y, x2, y2);
 583             geometryChanged();
 584         }
 585 
 586         @Override
 587         protected boolean hasOpaqueRegion() {
 588             opaqueRegionRecomputed = true;
 589             return super.hasOpaqueRegion() && computedOpaqueRegion != null;

 590         }
 591 
 592         @Override
 593         protected RectBounds computeOpaqueRegion(RectBounds opaqueRegion) {
 594             opaqueRegionRecomputed = true;
 595             assert computedOpaqueRegion != null;
 596             return (RectBounds) opaqueRegion.deriveWithNewBounds(computedOpaqueRegion);
 597         }
 598 
 599         @Override
 600         protected void renderContent(Graphics g) { }
 601 
 602         @Override
 603         protected boolean hasOverlappingContents() {
 604             return false;
 605         }
 606 
 607         @Override
 608         protected boolean supportsOpaqueRegions() {
 609             return true;




   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 com.sun.javafx.geom.BaseBounds;
  29 import com.sun.javafx.geom.RectBounds;
  30 import com.sun.javafx.geom.Rectangle;
  31 import com.sun.javafx.geom.transform.BaseTransform;
  32 import com.sun.javafx.sg.prism.NGNode;
  33 import com.sun.javafx.sg.prism.NGNodeShim;
  34 import com.sun.javafx.sg.prism.NGPath;
  35 import com.sun.javafx.sg.prism.NGRectangle;
  36 import com.sun.prism.Graphics;
  37 import com.sun.prism.paint.Color;
  38 import com.sun.scenario.effect.Blend;
  39 import com.sun.scenario.effect.Effect;
  40 import com.sun.scenario.effect.FilterContext;
  41 import com.sun.scenario.effect.ImageData;
  42 import org.junit.Before;
  43 import org.junit.Test;
  44 import static org.junit.Assert.assertEquals;
  45 import static org.junit.Assert.assertFalse;
  46 import static org.junit.Assert.assertNotNull;
  47 import static org.junit.Assert.assertNotSame;
  48 import static org.junit.Assert.assertNull;
  49 import static org.junit.Assert.assertSame;
  50 import static org.junit.Assert.assertTrue;
  51 
  52 /**
  53  */
  54 public class NGNodeTest extends NGTestBase {
  55     NGNodeMock n;


 561     @Test public void testGetOpaqueRegionWithTranslatedAndScaledRectangleClip() {
 562         NGRectangle clip = new NGRectangle();
 563         clip.setFillPaint(Color.BLACK);
 564         clip.updateRectangle(0, 0, 4, 4, 0, 0);
 565         clip.setTransformMatrix(
 566                 BaseTransform.getTranslateInstance(2, 2).deriveWithConcatenation(
 567                         BaseTransform.getScaleInstance(.5, .5)));
 568         n.setClipNode(clip);
 569         assertEquals(new RectBounds(2, 2, 4, 4), n.getOpaqueRegion());
 570     }
 571 
 572     @Test public void testGetOpaqueRegionWithRotatedRectangleClip() {
 573         NGRectangle clip = new NGRectangle();
 574         clip.setFillPaint(Color.BLACK);
 575         clip.updateRectangle(0, 0, 4, 4, 0, 0);
 576         clip.setTransformMatrix(BaseTransform.getRotateInstance(45, 5, 5));
 577         n.setClipNode(clip);
 578         assertNull(n.getOpaqueRegion());
 579     }
 580 
 581     class NGNodeMock extends NGNodeShim {
 582         boolean opaqueRegionRecomputed = false;
 583         RectBounds computedOpaqueRegion = new RectBounds(0, 0, 10, 10);
 584 
 585         void changeOpaqueRegion(float x, float y, float x2, float y2) {
 586             computedOpaqueRegion = new RectBounds(x, y, x2, y2);
 587             geometryChanged();
 588         }
 589 
 590         @Override
 591         public boolean hasOpaqueRegion() {
 592             opaqueRegionRecomputed = true;
 593             return super.hasOpaqueRegion()
 594                     && computedOpaqueRegion != null;
 595         }
 596 
 597         @Override
 598         protected RectBounds computeOpaqueRegion(RectBounds opaqueRegion) {
 599             opaqueRegionRecomputed = true;
 600             assert computedOpaqueRegion != null;
 601             return (RectBounds) opaqueRegion.deriveWithNewBounds(computedOpaqueRegion);
 602         }
 603 
 604         @Override
 605         protected void renderContent(Graphics g) { }
 606 
 607         @Override
 608         protected boolean hasOverlappingContents() {
 609             return false;
 610         }
 611 
 612         @Override
 613         protected boolean supportsOpaqueRegions() {
 614             return true;