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.RectBounds;
29 import com.sun.javafx.geom.transform.BaseTransform;
30 import com.sun.javafx.geom.transform.GeneralTransform3D;
31 import org.junit.Test;
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertSame;
34 import static org.junit.Assert.assertTrue;
35
36 /**
37 *
38 */
39 public class OcclusionCullingTest extends NGTestBase {
40
41
42 @Test
43 public void testRectangleOcclusion() {
44 final TestNGRectangle root = createRectangle(0, 0, 50, 50);
45 TestNGGroup group = createGroup(
46 createRectangle(0, 0, 100, 100), root);
47 NodePath rootPath = new NodePath();
48 group.getRenderRoot(rootPath, new RectBounds(20, 20, 30, 30), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
49 TestGraphics g = new TestGraphics();
50 g.setRenderRoot(rootPath);
102 final TestNGRectangle root = createRectangle(10, 10, 100, 100);
103 TestNGGroup group = createGroup(
104 createGroup(createRectangle(10, 10, 100, 100), createRectangle(20, 20, 20, 20)),
105 createGroup(root));
106 NodePath rootPath = new NodePath();
107 group.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
108 TestGraphics g = new TestGraphics();
109 g.setRenderRoot(rootPath);
110 group.render(g);
111 assertRoot(rootPath, root);
112 checkRootRendering(group, rootPath);
113 }
114
115 @Test
116 public void test2SameRectanglesOcclusionWithRootNotDirty() {
117 final TestNGRectangle root = createRectangle(10, 10, 100, 100);
118 final TestNGGroup rootParent = createGroup(root);
119 TestNGGroup group = createGroup(
120 createGroup(createRectangle(10, 10, 100, 100), createRectangle(20, 20, 20, 20)), rootParent);
121
122 group.dirty = NGNode.DirtyFlag.CLEAN; // need to clean default dirty flags
123 rootParent.dirty = NGNode.DirtyFlag.CLEAN;
124 rootParent.childDirty = false;
125 root.dirty = NGNode.DirtyFlag.CLEAN;
126 root.childDirty = false;
127 NodePath rootPath = new NodePath();
128 group.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
129 assertTrue(rootPath.isEmpty());
130
131 final TestNGRectangle dirtySibling = createRectangle(0,0,10,10);
132 rootParent.add(-1, dirtySibling);
133 rootPath = new NodePath();
134 group.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
135 assertRoot(rootPath, root);
136 }
137
138 @Test
139 public void testTransparentRegionWithChildren() {
140 final TestNGRectangle root = createRectangle(10, 10, 100, 100);
141 final TestNGGroup rootParent = createGroup(root);
142 TestNGRegion region = createTransparentRegion(0, 0, 100, 100,
143 createGroup(createRectangle(10, 10, 100, 100), createRectangle(20, 20, 20, 20)), rootParent);
144
145 region.dirty = NGNode.DirtyFlag.CLEAN; // need to clean default dirty flags
146 rootParent.dirty = NGNode.DirtyFlag.CLEAN;
147 rootParent.childDirty = false;
148 root.dirty = NGNode.DirtyFlag.CLEAN;
149 root.childDirty = false;
150 NodePath rootPath = new NodePath();
151 region.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
152 assertTrue(rootPath.isEmpty());
153
154 final TestNGRectangle dirtySibling = createRectangle(0,0,10,10);
155 rootParent.add(-1,dirtySibling);
156 rootPath = new NodePath();
157 region.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
158 assertRoot(rootPath, root);
159 }
160
161 @Test
162 public void testOpaqueRegion() {
163 final TestNGRectangle rect = createRectangle(10, 10, 100, 100);
164 TestNGRegion region = createOpaqueRegion(0, 0, 200, 200, rect);
165 TestNGGroup root = createGroup(region);
166
167 NodePath rootPath = new NodePath();
168 root.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
169 assertRoot(rootPath, rect);
|
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 test.com.sun.javafx.sg.prism.TestGraphics;
29 import com.sun.javafx.geom.RectBounds;
30 import com.sun.javafx.geom.transform.BaseTransform;
31 import com.sun.javafx.geom.transform.GeneralTransform3D;
32 import com.sun.javafx.sg.prism.NGNode;
33 import com.sun.javafx.sg.prism.NGNodeShim;
34 import com.sun.javafx.sg.prism.NodePath;
35 import org.junit.Test;
36 import static org.junit.Assert.assertEquals;
37 import static org.junit.Assert.assertSame;
38 import static org.junit.Assert.assertTrue;
39
40 /**
41 *
42 */
43 public class OcclusionCullingTest extends NGTestBase {
44
45
46 @Test
47 public void testRectangleOcclusion() {
48 final TestNGRectangle root = createRectangle(0, 0, 50, 50);
49 TestNGGroup group = createGroup(
50 createRectangle(0, 0, 100, 100), root);
51 NodePath rootPath = new NodePath();
52 group.getRenderRoot(rootPath, new RectBounds(20, 20, 30, 30), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
53 TestGraphics g = new TestGraphics();
54 g.setRenderRoot(rootPath);
106 final TestNGRectangle root = createRectangle(10, 10, 100, 100);
107 TestNGGroup group = createGroup(
108 createGroup(createRectangle(10, 10, 100, 100), createRectangle(20, 20, 20, 20)),
109 createGroup(root));
110 NodePath rootPath = new NodePath();
111 group.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
112 TestGraphics g = new TestGraphics();
113 g.setRenderRoot(rootPath);
114 group.render(g);
115 assertRoot(rootPath, root);
116 checkRootRendering(group, rootPath);
117 }
118
119 @Test
120 public void test2SameRectanglesOcclusionWithRootNotDirty() {
121 final TestNGRectangle root = createRectangle(10, 10, 100, 100);
122 final TestNGGroup rootParent = createGroup(root);
123 TestNGGroup group = createGroup(
124 createGroup(createRectangle(10, 10, 100, 100), createRectangle(20, 20, 20, 20)), rootParent);
125
126 NGNodeShim.set_dirty(group, NGNode.DirtyFlag.CLEAN); // need to clean default dirty flags
127 NGNodeShim.set_dirty(rootParent, NGNode.DirtyFlag.CLEAN);
128 NGNodeShim.set_childDirty(rootParent, false);
129 NGNodeShim.set_dirty(root, NGNode.DirtyFlag.CLEAN);
130 NGNodeShim.set_childDirty(root, false);
131 NodePath rootPath = new NodePath();
132 group.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
133 assertTrue(rootPath.isEmpty());
134
135 final TestNGRectangle dirtySibling = createRectangle(0,0,10,10);
136 rootParent.add(-1, dirtySibling);
137 rootPath = new NodePath();
138 group.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
139 assertRoot(rootPath, root);
140 }
141
142 @Test
143 public void testTransparentRegionWithChildren() {
144 final TestNGRectangle root = createRectangle(10, 10, 100, 100);
145 final TestNGGroup rootParent = createGroup(root);
146 TestNGRegion region = createTransparentRegion(0, 0, 100, 100,
147 createGroup(createRectangle(10, 10, 100, 100), createRectangle(20, 20, 20, 20)), rootParent);
148
149 NGNodeShim.set_dirty(region, NGNode.DirtyFlag.CLEAN); // need to clean default dirty flags
150 NGNodeShim.set_dirty(rootParent, NGNode.DirtyFlag.CLEAN);
151 NGNodeShim.set_childDirty(rootParent, false);
152 NGNodeShim.set_dirty(root, NGNode.DirtyFlag.CLEAN);
153 NGNodeShim.set_childDirty(root, false);
154 NodePath rootPath = new NodePath();
155 region.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
156 assertTrue(rootPath.isEmpty());
157
158 final TestNGRectangle dirtySibling = createRectangle(0,0,10,10);
159 rootParent.add(-1,dirtySibling);
160 rootPath = new NodePath();
161 region.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
162 assertRoot(rootPath, root);
163 }
164
165 @Test
166 public void testOpaqueRegion() {
167 final TestNGRectangle rect = createRectangle(10, 10, 100, 100);
168 TestNGRegion region = createOpaqueRegion(0, 0, 200, 200, rect);
169 TestNGGroup root = createGroup(region);
170
171 NodePath rootPath = new NodePath();
172 root.getRenderRoot(rootPath, new RectBounds(10, 10, 100, 100), -1, BaseTransform.IDENTITY_TRANSFORM, new GeneralTransform3D());
173 assertRoot(rootPath, rect);
|