diff --git a/javafx-sg-common/src/com/sun/javafx/sg/BaseNode.java b/javafx-sg-common/src/com/sun/javafx/sg/BaseNode.java --- a/javafx-sg-common/src/com/sun/javafx/sg/BaseNode.java +++ b/javafx-sg-common/src/com/sun/javafx/sg/BaseNode.java @@ -1251,6 +1251,31 @@ * * **************************************************************************/ + public static boolean TEXT_LAST = true; + public static int Count = 0, Max = -1, Min = Integer.MAX_VALUE; + public static boolean DrawText = true; + public static boolean DrawContent = true; + public final void renderAll(G g) { + Count = 0; + int lastMax = Max, lastMin = Min; + if (TEXT_LAST) { + DrawText = false; + DrawContent = true; + render(g); + DrawText = true; + DrawContent = false; + render(g); + } else { + DrawText = DrawContent = true; + render(g); + } + Max = Math.max(Max, Count); + Min = Math.min(Min, Count); + if (Max > lastMax || Min < lastMin) { + System.out.println("Max = " + Max + " , Min=" + Min); + } + } + /** * Render the tree of nodes to the specified G (graphics) object * descending from this node as the root. This method is designed to avoid diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGCanvas.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGCanvas.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGCanvas.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGCanvas.java @@ -38,6 +38,7 @@ import com.sun.javafx.geom.transform.Affine2D; import com.sun.javafx.geom.transform.BaseTransform; import com.sun.javafx.geom.transform.NoninvertibleTransformException; +import com.sun.javafx.sg.BaseNode; import com.sun.javafx.sg.GrowableDataBuffer; import com.sun.javafx.sg.PGCanvas; import com.sun.javafx.sg.PGShape; @@ -429,6 +430,7 @@ @Override protected void renderContent(Graphics g) { + if (!BaseNode.DrawContent) return; initCanvas(g); if (cv.tex != null) { if (thebuf != null) { diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGExternalNode.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGExternalNode.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGExternalNode.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGExternalNode.java @@ -26,6 +26,7 @@ package com.sun.javafx.sg.prism; import com.sun.javafx.geom.Rectangle; +import com.sun.javafx.sg.BaseNode; import com.sun.javafx.sg.PGExternalNode; import com.sun.prism.Graphics; @@ -69,6 +70,7 @@ @Override protected void renderContent(Graphics g) { + if (!BaseNode.DrawContent) return; paintLock.lock(); try { if (srcbuffer == null) { diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGImageView.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGImageView.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGImageView.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGImageView.java @@ -25,6 +25,7 @@ package com.sun.javafx.sg.prism; +import com.sun.javafx.sg.BaseNode; import com.sun.javafx.sg.PGImageView; import com.sun.prism.Graphics; import com.sun.prism.Image; @@ -112,6 +113,7 @@ @Override protected void renderContent(Graphics g) { + if (!BaseNode.DrawContent) return; int imgW = image.getWidth(); int imgH = image.getHeight(); diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGLine.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGLine.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGLine.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGLine.java @@ -30,6 +30,7 @@ import com.sun.javafx.geom.Line2D; import com.sun.javafx.geom.Shape; import com.sun.javafx.geom.transform.BaseTransform; +import com.sun.javafx.sg.BaseNode; import com.sun.javafx.sg.PGLine; import com.sun.prism.Graphics; import com.sun.prism.BasicStroke; @@ -51,6 +52,7 @@ @Override protected void renderContent(Graphics g) { + if (!BaseNode.DrawContent) return; if (!g.getTransformNoClone().is2D()) { super.renderContent(g); return; diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGNode.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGNode.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGNode.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGNode.java @@ -687,6 +687,7 @@ } private void renderCached(Graphics g) { + if (!BaseNode.DrawContent) return; // We will punt on 3D completely for cahcing. // The first check is for any of its children contains a 3D Transform. // The second check is for any of its parents and itself has a 3D Transform diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGRectangle.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGRectangle.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGRectangle.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGRectangle.java @@ -25,6 +25,9 @@ package com.sun.javafx.sg.prism; + +//import org.eclipse.swt.internal.cocoa.OS; + import com.sun.javafx.geom.*; import com.sun.javafx.sg.PGNode; import com.sun.javafx.sg.PGShape; @@ -34,6 +37,7 @@ import com.sun.javafx.sg.PGRectangle; import com.sun.prism.Graphics; import com.sun.prism.BasicStroke; +import com.sun.prism.RenderTarget; import com.sun.prism.paint.Color; import com.sun.prism.paint.Paint; import com.sun.prism.shape.ShapeRep; @@ -132,7 +136,149 @@ boolean isRounded() { return rrect.arcWidth > 0f && rrect.arcHeight > 0f; } +/* + public class GL extends OS { + } + public class GL11 extends OS { + } + public class GLU extends OS { + } + static int loadShader(int type, String source) { + int shader = GL.glCreateShader(type); + if (shader == 0) return 0; + long[] shaderSrc = new long[1]; + byte[] buffer = (source + "\0").getBytes(); + long ptr = OS.malloc(buffer.length); + OS.memmove(ptr, buffer, buffer.length); + shaderSrc[0] = ptr; + GL.glShaderSource(shader, 1, shaderSrc, 0); + if (ptr != 0) OS.free(ptr); + GL.glCompileShader(shader); + int [] params = new int[1]; + GL.glGetShaderiv(shader, GL.GL_COMPILE_STATUS, params); + if (params[0] == GL.GL_FALSE) { + //System.out.println("*** Error: could not compile shader " + params[0]); + } + return shader; + } + + static int createProgram() { + int program = GL.glCreateProgram(); + if (program == 0) return 0; + String vShaderSrc = + "attribute vec4 vPosition;" + "\n" + + "void main() {" + "\n" + + " gl_Position = vPosition;" + "\n" + + "}" + "\n"; + int vertexShader = loadShader(GL.GL_VERTEX_SHADER, vShaderSrc); + String fShaderSrc = +// "precision mediump float;" + "\n" + + "void main() {" + "\n" + + " gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);" + " \n" + + "}" + "\n"; + int fragmentShader = loadShader(GL.GL_FRAGMENT_SHADER, fShaderSrc); + GL.glAttachShader(program, vertexShader); + GL.glAttachShader(program, fragmentShader); + GL.glBindAttribLocation(program, 0, "vPosition"); + GL.glLinkProgram(program); + int [] params = new int[1]; + GL.glGetProgramiv(program, GL.GL_LINK_STATUS, params); + if (params[0] == GL.GL_FALSE) { + //System.out.println("*** Error: could not link program " + params[0]); + } + return program; + } + + static void renderES(float [] transform, int program, int x, int y, int width, int height) { + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glPushClientAttrib(GL11.GL_CLIENT_ALL_ATTRIB_BITS); + int [] params = new int [1]; + GL.glGetIntegerv(GL.GL_CURRENT_PROGRAM, params); + + GL.glViewport(0, 0, width, height); + + float[] vertices = new float[] { + 0.0f, 0.5f, 0.0f, + -0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 0.0f, + }; + GL.glUseProgram(program); + GL.glVertexAttribPointer(0, 3, GL.GL_FLOAT, (byte) GL.GL_FALSE, 0, vertices); + GL.glEnableVertexAttribArray(0); + GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3); + + GL.glUseProgram(params[0]); + GL11.glPopClientAttrib(); + GL11.glPopAttrib(); + } + + void renderDirect(float [] transform, int width, int height, int x, int y, int w, int h) { + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glPushClientAttrib(GL11.GL_CLIENT_ALL_ATTRIB_BITS); + int [] params = new int [1]; + GL.glGetIntegerv(GL.GL_CURRENT_PROGRAM, params); + GL.glUseProgram(0); + + GL11.glViewport(0, 0, width, height); + GL11.glMatrixMode (GL11.GL_PROJECTION); + GL11.glLoadIdentity (); + GL11.glOrtho (0, width, 0, height, -1, 1); + GL11.glMatrixMode (GL11.GL_MODELVIEW); + if (transform == null) { + GL11.glLoadIdentity(); + } else { + GL.glLoadMatrixf(transform); + } + + GL11.glBegin(GL11.GL_QUADS); + GL11.glColor3f(0, 0, 1); + GL11.glVertex2f(x, y); + GL11.glVertex2f(x, y + h); + GL11.glVertex2f(x + w, y + h); + GL11.glVertex2f(x + w, y); + GL11.glEnd(); + + GL.glUseProgram(params[0]); + GL11.glPopClientAttrib(); + GL11.glPopAttrib(); + } + + static int program = 0; + @Override protected void renderContent(Graphics g) { + //System.out.println("HI"); + super.renderContent(g); + g.sync(); + //g.drawLine(rrect.getX(), rrect.getY(), rrect.getWidth(), rrect.getHeight()); + + RenderTarget target = g.getRenderTarget(); + int w = target.getPhysicalWidth(), h = target.getPhysicalHeight(); + BaseTransform t = g.getTransformNoClone(); + float [] matrix = new float[] { + (float)t.getMxx(), + (float)t.getMyx(), + (float)t.getMzx(), + 0, + (float)t.getMxy(), + (float)t.getMyy(), + (float)t.getMzy(), + 0, + (float)t.getMxz(), + (float)t.getMyz(), + (float)t.getMzz(), + 0, + (float)t.getMxt(), + (float)t.getMyt(), + (float)t.getMzt(), + 1, + }; + //if (program == 0) program = createProgram(); + //renderES(matrix, program, (int)rrect.getX(), (int)rrect.getY(), (int)rrect.getWidth(), (int)rrect.getHeight()); + //g.sync(); + + renderDirect(matrix, w, h, (int)rrect.getX(), (int)rrect.getY(), (int)rrect.getWidth(), (int)rrect.getHeight()); + } +*/ @Override protected void renderEffect(Graphics g) { if (!(g instanceof RectShadowGraphics) || !renderEffectDirectly(g)) { diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGRegion.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGRegion.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGRegion.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGRegion.java @@ -462,6 +462,10 @@ *************************************************************************/ @Override protected void renderContent(Graphics g) { + if (!BaseNode.DrawContent) { + super.renderContent(g); + return; + } // Use Effect to render 3D transformed Region that does not contain 3D // transformed children. // This is done in order to render the Region's content and children diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGShape.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGShape.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGShape.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGShape.java @@ -31,6 +31,7 @@ import com.sun.javafx.geom.RectangularShape; import com.sun.javafx.geom.Shape; import com.sun.javafx.geom.transform.BaseTransform; +import com.sun.javafx.sg.BaseNode; import com.sun.javafx.sg.PGShape; import com.sun.prism.BasicStroke; import com.sun.prism.Graphics; @@ -199,6 +200,7 @@ @Override protected void renderContent(Graphics g) { + if (!BaseNode.DrawContent) return; if (mode == Mode.EMPTY) { return; } diff --git a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGText.java b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGText.java --- a/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGText.java +++ b/javafx-sg-prism/src/com/sun/javafx/sg/prism/NGText.java @@ -37,6 +37,7 @@ import com.sun.javafx.geom.Shape; import com.sun.javafx.geom.transform.BaseTransform; import com.sun.javafx.scene.text.GlyphList; +import com.sun.javafx.sg.BaseNode; import com.sun.javafx.sg.PGText; import com.sun.javafx.text.TextRun; import com.sun.prism.Graphics; @@ -215,6 +216,8 @@ private static int TEXT = 1 << 3; private static int DECORATION = 1 << 4; @Override protected void renderContent(Graphics g) { + if (!BaseNode.DrawText) return; + if (mode == Mode.EMPTY) return; if (runs == null || runs.length == 0) return; diff --git a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/PresentingPainter.java b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/PresentingPainter.java --- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/PresentingPainter.java +++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/PresentingPainter.java @@ -26,6 +26,7 @@ package com.sun.javafx.tk.quantum; import com.sun.prism.Graphics; +import com.sun.prism.GraphicsPipeline; import com.sun.prism.impl.Disposer; import com.sun.prism.impl.ManagedResource; import com.sun.prism.impl.PrismSettings; @@ -61,6 +62,13 @@ */ sceneState.lock(); locked = true; + + if (factory == null) { + factory = GraphicsPipeline.getDefaultResourceFactory(); + if (factory == null || !factory.isDeviceReady()) { + return; + } + } boolean needsReset = (presentable == null) || (penWidth != viewWidth) || (penHeight != viewHeight); if (!needsReset && presentable.lockResources()) { diff --git a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/ViewPainter.java b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/ViewPainter.java --- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/ViewPainter.java +++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/ViewPainter.java @@ -28,7 +28,6 @@ import com.sun.javafx.sg.NodePath; import com.sun.javafx.sg.prism.NGNode; import com.sun.prism.Graphics; -import com.sun.prism.GraphicsPipeline; import com.sun.prism.impl.PrismSettings; import com.sun.prism.paint.Color; import com.sun.prism.paint.Paint; @@ -70,24 +69,7 @@ setPaintBounds(viewWidth, viewHeight); - if (factory == null) { - // the factory really should not be null as - // we really want all that factory work on the event thread - try { - sceneState.lock(); - factory = GraphicsPipeline.getDefaultResourceFactory(); - } finally { - /* - * Don't flush to the screen if there was a failure - * creating the graphics factory - */ - sceneState.unlock(); - } - return ((factory != null) && factory.isDeviceReady()); - } - return sceneState.isWindowVisible() && - !sceneState.isWindowMinimized() && - factory.isDeviceReady(); + return sceneState.isWindowVisible() && !sceneState.isWindowMinimized(); } @Override protected void doPaint(Graphics g, NodePath renderRootPath) { @@ -114,7 +96,7 @@ } g.setCamera(scene.getCamera()); g.setRenderRoot(renderRootPath); - root.render(g); + root.renderAll(g); } finally { if (PULSE_LOGGING_ENABLED) { PULSE_LOGGER.renderMessage(start, System.currentTimeMillis(), "Painted"); diff --git a/prism-es2/src/com/sun/prism/es2/ES2VertexBuffer.java b/prism-es2/src/com/sun/prism/es2/ES2VertexBuffer.java --- a/prism-es2/src/com/sun/prism/es2/ES2VertexBuffer.java +++ b/prism-es2/src/com/sun/prism/es2/ES2VertexBuffer.java @@ -62,11 +62,13 @@ @Override protected void drawQuads(int numVertices) { + com.sun.javafx.sg.BaseNode.Count++; glCtx.drawIndexedQuads(coordArray, colorArray, numVertices); } @Override protected void drawTriangles(int numTriangles, float fData[], byte cData[]) { + com.sun.javafx.sg.BaseNode.Count++; glCtx.drawTriangleList(numTriangles, fData, cData); }