harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r482341 [1/2] - in /harmony/enhanced/classlib/trunk/modules: awt/ awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/ awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/ awt/src/main/java/unix/org/apache/harmony/awt/nativebridge/...
Date Mon, 04 Dec 2006 20:26:31 GMT
Author: apetrenko
Date: Mon Dec  4 12:26:28 2006
New Revision: 482341

URL: http://svn.apache.org/viewvc?view=rev&rev=482341
Log:
Patch for HARMONY-2374 "[classlib][awt] Missing java2d code for OpenGL pipeline."

Added:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/GLXGraphicsConfiguration.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/nativebridge/linux/GLX.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WGLGraphicsConfiguration.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGL.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGLDefs.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/shared/
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/shared/org_apache_harmony_awt_gl_opengl_GL.cpp
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/shared/org_apache_harmony_awt_gl_opengl_GL.h
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/unix/
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/unix/liboglwrapper.exp
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/unix/makefile
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/windows/
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/windows/makefile
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/windows/oglwrapper.RES   (with props)
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/windows/oglwrapper.def
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/windows/oglwrapper.rc
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/win32wrapper/windows/nativelib_common.cpp
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/win32wrapper/windows/org_apache_harmony_awt_nativebridge_windows_WGL.cpp
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/win32wrapper/windows/org_apache_harmony_awt_nativebridge_windows_WGL.h
Modified:
    harmony/enhanced/classlib/trunk/modules/awt/build.xml
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLContextManager.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLGraphics2D.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLVolatileImage.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphics2DFactory.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsDevice.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WindowProcHandler.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/unix/libgl.exp
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/win32wrapper/windows/makefile
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/win32wrapper/windows/nativelib_common.h
    harmony/enhanced/classlib/trunk/modules/swing/build.xml

Modified: harmony/enhanced/classlib/trunk/modules/awt/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/build.xml?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/build.xml (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/build.xml Mon Dec  4 12:26:28 2006
@@ -164,6 +164,13 @@
             </fileset>
         </copy>
 
+        <make dir="${hy.awt.src.main.native}/oglwrapper/${hy.os}" />
+        <!-- Copy the built shared libs over to the jre/bin dir -->
+        <copy todir="${hy.jdk}/jre/bin" overwrite="yes">
+            <fileset dir="${hy.awt.src.main.native}/oglwrapper">
+                <patternset includes="*${shlib.suffix}*" />
+            </fileset>
+        </copy>
     </target>
 
     <target name="-build-native-unix" if="is.unix">
@@ -210,6 +217,8 @@
               target="clean"/>
         <make dir="${hy.awt.src.main.native}/gl/${hy.os.family}"
               target="clean"/>
+        <make dir="${hy.awt.src.main.native}/oglwrapper/${hy.os}"
+              target="clean"/>
     </target>
 
     <target name="-clean-native-unix" if="is.unix">
@@ -294,6 +303,7 @@
             <jvmarg line="${hy.test.vmargs}" />
 
             <jvmarg value="-DTEST_SRC_DIR=${hy.awt.bin.test}"/>
+<!--            <jvmarg value="-Djava2d.opengl=true"/> -->
             <jvmarg value="-Xbootclasspath/a:${hy.awt.bin.test}${path.separator}${basedir}/../../${junit.jar}"/>
 
             <formatter type="xml" />

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLContextManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLContextManager.java?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLContextManager.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLContextManager.java Mon Dec  4 12:26:28 2006
@@ -20,24 +20,102 @@
  */
 package org.apache.harmony.awt.gl.opengl;
 
+import java.util.ArrayList;
+
 public interface OGLContextManager {
     public static class OffscreenBufferObject {
+        private static final int MAX_CACHED_BUFFERS = 10;
+        private static final ArrayList availableBuffers = new ArrayList();
+
         public final long id;
         public final int width;
         public final int height;
+        public final OGLContextManager config;
+        public final long hdc;
 
-        public OffscreenBufferObject(long id, int width, int height) {
+        public OffscreenBufferObject(long id, long hdc, int width, int height, OGLContextManager config) {
             this.id = id;
+            this.hdc = hdc;
             this.width = width;
             this.height = height;
+            this.config = config;
+        }
+
+        public static final OffscreenBufferObject getCachedBuffer(int w, int h, OGLContextManager config) {
+            for (int i = 0; i < availableBuffers.size(); i++) { // First try to find cached pbuffer
+                OffscreenBufferObject pbuffer = (OffscreenBufferObject) availableBuffers.get(i);
+                if (pbuffer.width >= w && pbuffer.height >= h && pbuffer.config == config) {
+                    availableBuffers.remove(i);
+                    return pbuffer;
+                }
+            }
+
+            return null;
+        }
+
+        public static final OffscreenBufferObject freeCachedBuffer(OffscreenBufferObject pbuffer) {
+            if (availableBuffers.size() <= MAX_CACHED_BUFFERS) {
+                availableBuffers.add(pbuffer);
+                return null;
+            }
+
+            // Try to find smaller pbuffer in the cache and replace it
+            for (int i=0; i<availableBuffers.size(); i++) {
+                OffscreenBufferObject cached = (OffscreenBufferObject) availableBuffers.get(i);
+                if (
+                        cached.width < pbuffer.width ||
+                        cached.height < pbuffer.height ||
+                        cached.config != pbuffer.config
+                ) {
+                    availableBuffers.remove(i);
+                    availableBuffers.add(pbuffer);
+                    pbuffer = cached;
+                    return pbuffer;
+                }
+            }
+
+            return pbuffer;
+        }
+
+        public static final void clearCache() {
+            for (int i=0; i<availableBuffers.size(); i++) {
+                OffscreenBufferObject cached = (OffscreenBufferObject) availableBuffers.get(i);
+                cached.config.freeOffscreenBuffer(cached.id, cached.hdc);
+            }
+            availableBuffers.clear();
         }
     }
 
-    public long getOGLContext(); // Creates OpenGL context based on GraphicsConfiguration
-    public void destroyOGLContext(long oglContext); // Destroys existing OpenGL context
-    public boolean makeCurrent(long oglContext, long drawable); // Makes OpenGL context current
-    public boolean makeContextCurrent(long oglContext, long draw, long read);
-    public void swapBuffers(long drawable);
+    /**
+     * Creates OpenGL context based on GraphicsConfiguration
+     * @param drawable - window handle, pbuffer, or linux drawable
+     * @param hdc - if drawable is offscreen
+     * @return context handle
+     */
+    public long getOGLContext(long drawable, long hdc);
+
+    /**
+     * Destroys existing OpenGL context
+     * @param oglContext - context
+     */
+    public void destroyOGLContext(long oglContext);
+
+    /**
+     * Makes OpenGL context current
+     * @param oglContext - OpenGL context handle
+     * @param drawable - window handle, pbuffer, or linux drawable
+     * @param hdc - if drawable is offscreen
+     * @return false if context was alrady current, true otherwise
+     */
+    public boolean makeCurrent(long oglContext, long drawable, long hdc);
+
+    public boolean makeContextCurrent(long oglContext, long draw, long read, long drawHDC, long readHDC);
+
+    public void swapBuffers(long drawable, long hdc);
+
     public OffscreenBufferObject createOffscreenBuffer(int w, int h);
-    public void freeOffscreenBuffer(OffscreenBufferObject handle);
+    
+    public void freeOffscreenBuffer(OffscreenBufferObject buffer);
+
+    public void freeOffscreenBuffer(long id, long hdc);
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLGraphics2D.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLGraphics2D.java?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLGraphics2D.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLGraphics2D.java Mon Dec  4 12:26:28 2006
@@ -157,15 +157,14 @@
     private double gradObjectPlane[];
     private boolean isGPCyclic;
 
+    private long oshdc = 0; // device context for windows offscreen image
 
     public OGLGraphics2D(NativeWindow nwin, int tx, int ty, MultiRectArea clip) {
-        /*
         if (nwin instanceof OGLVolatileImage.OGLOffscreenWindow) {
-            ctxmgr = (OGLContextManager) getDeviceConfiguration();
-            ctxmgr.makeCurrent(ctxmgr.getOGLContext(), nwin.getId());
-            return;
+            OGLVolatileImage.OGLOffscreenWindow offWin = (OGLVolatileImage.OGLOffscreenWindow) nwin;
+            oshdc = offWin.getHdc();
         }
-        */
+
         this.nwin = nwin;
 
         ctxmgr = (OGLContextManager) getDeviceConfiguration();
@@ -366,8 +365,8 @@
     }
 
     final void makeCurrent() {
-        long oglContext = ctxmgr.getOGLContext();
-        ctxmgr.makeCurrent(oglContext, nwin.getId());
+        long oglContext = ctxmgr.getOGLContext(nwin.getId(), oshdc);
+        ctxmgr.makeCurrent(oglContext, nwin.getId(), oshdc);
         OGLContextValidator.validateContext(this);
     }
 
@@ -409,7 +408,19 @@
             LockedArray lVertices = Utils.arraccess.lockArrayShort(vertices);
 
             gl.glVertexPointer(2, GLDefs.GL_INT, 0, lVertices.getAddress());
-            gl.glDrawArrays(GLDefs.GL_QUADS, 0, vertices.length/2);
+
+            // At least one configuration (ATI MOBILITY FIRE GL T2 card on win32) has
+            // problems with the large arrays, so workaround is used when
+            // the number of vertices exceeds 1024
+            if (vertices.length < 2048) {
+                gl.glDrawArrays(GLDefs.GL_QUADS, 0, vertices.length/2);
+            } else {
+                int iters = vertices.length / 2048;
+                for (int i = 0; i < iters; i++) {
+                    gl.glDrawArrays(GLDefs.GL_QUADS, i*1024, 1024);
+                }
+                gl.glDrawArrays(GLDefs.GL_QUADS, iters*1024, (vertices.length % 2048)/2);
+            }
 
             lVertices.release();
         }
@@ -1297,12 +1308,15 @@
      * @return true on success
      */
     private final boolean setCurrentRead(OGLGraphics2D read) {
-        long oglContext = ctxmgr.getOGLContext();
-        if (read.ctxmgr.getOGLContext() != oglContext) {
+        long oglContext = ctxmgr.getOGLContext(nwin.getId(), oshdc);
+        if (read.ctxmgr.getOGLContext(read.nwin.getId(), read.oshdc) != oglContext)
             return false;
-        }
 
-        ctxmgr.makeContextCurrent(oglContext, nwin.getId(), read.nwin.getId());
+        ctxmgr.makeContextCurrent(
+                oglContext,
+                nwin.getId(), read.nwin.getId(),
+                oshdc, read.oshdc
+        );
         return true;
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLVolatileImage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLVolatileImage.java?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLVolatileImage.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/opengl/OGLVolatileImage.java Mon Dec  4 12:26:28 2006
@@ -63,6 +63,10 @@
             return pbuffer.id;
         }
 
+        public long getHdc() {
+            return pbuffer.hdc;
+        }
+
         public Rectangle getBounds() {
             return bounds;
         }

Added: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/GLXGraphicsConfiguration.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/GLXGraphicsConfiguration.java?view=auto&rev=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/GLXGraphicsConfiguration.java (added)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/GLXGraphicsConfiguration.java Mon Dec  4 12:26:28 2006
@@ -0,0 +1,295 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Oleg V. Khaschansky
+ * @version $Revision$
+ */
+
+package org.apache.harmony.awt.gl.linux;
+
+import org.apache.harmony.awt.nativebridge.linux.X11;
+import org.apache.harmony.awt.nativebridge.linux.GLX;
+import org.apache.harmony.awt.gl.opengl.GLDefs;
+import org.apache.harmony.awt.nativebridge.*;
+import org.apache.harmony.awt.gl.opengl.OGLContextManager;
+import org.apache.harmony.awt.gl.opengl.OGLVolatileImage;
+
+import java.util.ArrayList;
+import java.awt.image.VolatileImage;
+
+public class GLXGraphicsConfiguration extends XGraphicsConfiguration implements OGLContextManager {
+    private static final GLX glx = GLX.getInstance();
+
+    private VoidPointer glxFBConfig; // Cached GLX FB configuration
+
+    private static long currentOGLContext; // Stored to eliminate unneccessary native calls
+    private static long currentDrawable; // Stored to eliminate unneccessary native calls
+    private static ArrayList existingContexts = new ArrayList();
+
+    //private long oglContext; // Last OGL context created for this configuration
+    private static final ThreadLocal oglContextThreadLocal = new ThreadLocal();
+
+    private long getLocalOGLContext() {
+        Long ctxId = (Long) oglContextThreadLocal.get();
+        return ctxId == null ? 0 : ctxId.longValue();
+    }
+
+
+    public GLXGraphicsConfiguration(XGraphicsDevice dev, X11.XVisualInfo info) {
+        super(dev, info);
+    }
+
+    static final class GlxConfigsRec { // Represent configs for one dpy/scr combination
+        // Glx configs for all dpy/scr combinations
+        private static final ArrayList glxConfigs = new ArrayList(1);
+
+        private PointerPointer configs;
+        private int nConfigs;
+        private long display;
+        private int screen;
+
+        private static final GlxConfigsRec findConfigRec(long display, int screen) {
+            for (int i = 0; i < glxConfigs.size(); i++) {
+                GlxConfigsRec rec = (GlxConfigsRec) glxConfigs.get(i);
+                if (rec.display == display && rec.screen == screen)
+                    return rec;
+            }
+
+            // Not found
+            return addConfigRec(display, screen);
+        }
+
+        private static final GlxConfigsRec addConfigRec(long display, int screen) {
+            Int32Pointer nElements = NativeBridge.getInstance().createInt32Pointer(1, true);
+            Int32Pointer attribList = NativeBridge.getInstance().createInt32Pointer(9, true);
+
+            // Fill in FB config attributes
+            attribList.set(0, GLDefs.GLX_DRAWABLE_TYPE);
+            attribList.set(1, GLDefs.GLX_WINDOW_BIT | GLDefs.GLX_PBUFFER_BIT);
+            attribList.set(2, GLDefs.GLX_RENDER_TYPE);
+            attribList.set(3, GLDefs.GLX_RGBA_BIT);
+            attribList.set(4, GLDefs.GLX_STENCIL_SIZE);
+            attribList.set(5, 1);
+            attribList.set(6, GLDefs.GLX_ALPHA_SIZE);
+            attribList.set(7, 8);
+            attribList.set(8, 0);
+
+            GlxConfigsRec res = new GlxConfigsRec();
+            res.configs = glx.glXChooseFBConfig(display, screen, attribList, nElements);
+            res.nConfigs = nElements.get(0);
+            res.display = display;
+            res.screen = screen;
+
+            nElements.free();
+            attribList.free();
+
+            glxConfigs.add(res);
+
+            return res;
+        }
+
+        static final long getBestGLXVisualId(long display, int screen) {
+            long defVisualPtr = x11.XDefaultVisual(display, screen);
+            long defVisId = x11.XVisualIDFromVisual(defVisualPtr);
+
+            GlxConfigsRec rec = findConfigRec(display, screen);
+
+            if (rec.nConfigs <= 0) {
+                return 0; // No GLX configs found
+            }
+
+            // Check if default visual is ok
+            Int32Pointer visId = NativeBridge.getInstance().createInt32Pointer(1, true);
+            VoidPointer ptr = rec.configs.get(0);
+            for (int i = 0; i < rec.nConfigs; i++) {
+                Int8Pointer fbConfig = ptr.byteBase.getElementPointer(i*NativeBridge.ptrSize);
+                glx.glXGetFBConfigAttrib(display, fbConfig.lock(), GLDefs.GLX_VISUAL_ID, visId);
+                fbConfig.unlock();
+                if (visId.get(0) == defVisId) {
+                    visId.free();
+                    return defVisId;
+                }
+            }
+
+            // Get visual id from the first (best) FB config
+            VoidPointer fbConfig = rec.configs.get(0);
+            glx.glXGetFBConfigAttrib(display, fbConfig.lock(), GLDefs.GLX_VISUAL_ID, visId);
+            fbConfig.unlock();
+            long bestVisId = visId.get(0);
+            visId.free();
+
+            return bestVisId;
+        }
+
+        private static final VoidPointer getGLXFBConfig(long display, int screen, long visid) {
+            VoidPointer retval = null;
+            GlxConfigsRec rec = findConfigRec(display, screen);
+
+            Int32Pointer visId = NativeBridge.getInstance().createInt32Pointer(1, true);
+            VoidPointer ptr = rec.configs.get(0);
+            for (int i = 0; i < rec.nConfigs; i++) {
+                Int8Pointer fbConfig = ptr.byteBase.getElementPointer(i*NativeBridge.ptrSize);
+                glx.glXGetFBConfigAttrib(display, fbConfig.lock(), GLDefs.GLX_VISUAL_ID, visId);
+                fbConfig.unlock();
+                if (visId.get(0) == visid) {
+                    retval = fbConfig;
+                    break;
+                }
+            }
+            visId.free();
+
+            return retval;
+        }
+
+        protected void finalize() throws Throwable {
+            super.finalize();
+            if (configs != null)
+                x11.XFree(configs);
+        }
+    }
+
+    public final long getOGLContext(long drawable, long hdc) {
+        if (glxFBConfig == null) {
+            glxFBConfig = GlxConfigsRec.getGLXFBConfig(dev.display, dev.screen, info.get_visualid());
+        }
+
+        long oglContext = getLocalOGLContext();
+        if (oglContext == 0) {
+            oglContext =
+                    glx.glXCreateNewContext(
+                            dev.display,
+                            glxFBConfig.lock(),
+                            GLDefs.GLX_RGBA_TYPE,
+                            existingContexts.isEmpty() ?
+                                0 : ((Long) existingContexts.get(0)).longValue(),
+                            GLDefs.True
+                    );
+            glxFBConfig.unlock();
+
+            existingContexts.add(new Long(oglContext));
+
+            oglContextThreadLocal.set(new Long(oglContext));
+        }
+
+        return oglContext;
+    }
+
+    protected void finalize() throws Throwable {
+        super.finalize();
+
+        long oglContext = getLocalOGLContext();
+        if (oglContext != 0) {
+            destroyOGLContext(oglContext);
+            //oglContext = 0;
+            oglContextThreadLocal.set(null);
+
+            // Remove from the common list of contexts
+            existingContexts.remove(new Long(oglContext));
+        }
+
+        OffscreenBufferObject.clearCache();
+    }
+
+    public final void destroyOGLContext(long oglContext) {
+        if (oglContext == currentOGLContext) {
+            //gl.glXMakeCurrent(dev.display, 0, 0);
+            currentOGLContext = 0;
+        }
+
+        glx.glXDestroyContext(dev.display, oglContext);
+    }
+
+    public final boolean makeCurrent(long oglContext, long drawable, long hdc) {
+        if (oglContext != currentOGLContext || drawable != currentDrawable) {
+
+            glx.glXMakeCurrent(dev.display, drawable, oglContext);
+
+            currentOGLContext = oglContext;
+            currentDrawable = drawable;
+
+            return true;
+        }
+
+        return false;
+    }
+
+    public final boolean makeContextCurrent(
+            long oglContext,
+            long draw, long read,
+            long drawHDC, long readHDC
+    ) {
+        if (read == draw) {
+            return makeCurrent(oglContext, read, 0);
+        }
+
+        glx.glXMakeContextCurrent(dev.display, draw, read, oglContext);
+        // Always step into makeCurrent to set same read/draw drawables
+        // after calling this method.
+        currentOGLContext = 0;
+
+        return true;
+    }
+
+    public final void swapBuffers(long drawable, long hdc) {
+        glx.glXSwapBuffers(dev.display, drawable);
+    }
+
+    public final OffscreenBufferObject createOffscreenBuffer(int w, int h) {
+        if (glxFBConfig == null) {
+            glxFBConfig = GlxConfigsRec.getGLXFBConfig(dev.display, dev.screen, info.get_visualid());
+        }
+
+        // Try to get pbuffer from cache
+        OffscreenBufferObject pbuffer = OffscreenBufferObject.getCachedBuffer(w, h, this);
+        if (pbuffer != null) {
+            return pbuffer;
+        }
+
+        Int32Pointer attribList = NativeBridge.getInstance().createInt32Pointer(7, true);
+
+        // Fill in FB config attributes
+        attribList.set(0, GLDefs.GLX_PBUFFER_WIDTH);
+        attribList.set(1, w);
+        attribList.set(2, GLDefs.GLX_PBUFFER_HEIGHT);
+        attribList.set(3, h);
+        attribList.set(4, GLDefs.GLX_PRESERVED_CONTENTS);
+        attribList.set(5, GLDefs.True);
+        attribList.set(6, 0);
+
+        long pbufferId = glx.glXCreatePbuffer(dev.display, glxFBConfig.lock(), attribList);
+        attribList.free();
+        glxFBConfig.unlock();
+
+        return new OffscreenBufferObject(pbufferId, 0, w, h, this);
+    }
+
+    public void freeOffscreenBuffer(OffscreenBufferObject pbuffer) {
+        pbuffer = OffscreenBufferObject.freeCachedBuffer(pbuffer);
+
+        if (pbuffer != null) {
+            glx.glXDestroyPbuffer(dev.display, pbuffer.id);
+        }
+    }
+
+    public void freeOffscreenBuffer(long id, long hdc) {
+        glx.glXDestroyPbuffer(dev.display, id);
+    }
+
+    public VolatileImage createCompatibleVolatileImage(int width, int height) {
+        return new OGLVolatileImage(this, width, height);
+    }
+}

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java Mon Dec  4 12:26:28 2006
@@ -138,15 +138,15 @@
             X11.XVisualInfo info = x11.createXVisualInfo(
                     infosPtr.getElementPointer(i*infosPtr.size())
             );
-            configs[i] = //useOpenGL ?
-//                    new GLXGraphicsConfiguration(this, info) :
+            configs[i] = useOpenGL ?
+                    new GLXGraphicsConfiguration(this, info) :
                     new XGraphicsConfiguration(this, info);
 
             if (info.get_visualid() == defVisId)
                 defaultConfigIdx = i;
         }
 
-/*        if (useOpenGL) {
+        if (useOpenGL) {
             //defVisId = 36;
             defVisId = GLXGraphicsConfiguration.GlxConfigsRec.getBestGLXVisualId(display, screen);
             for (int i=0; i<numVisualInfos; i++) {
@@ -156,7 +156,6 @@
                 }
             }
         }
-*/        
     }
 
     public int getType() {

Added: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/nativebridge/linux/GLX.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/nativebridge/linux/GLX.java?view=auto&rev=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/nativebridge/linux/GLX.java (added)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/nativebridge/linux/GLX.java Mon Dec  4 12:26:28 2006
@@ -0,0 +1,107 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Oleg V. Khaschansky
+ * @version $Revision$
+ */
+
+package org.apache.harmony.awt.nativebridge.linux;
+
+import org.apache.harmony.awt.nativebridge.*;
+
+/**
+ * This file is based on GLX header and has been generated by the nativebridge tool.
+ */
+public class GLX extends BasicLibWrapper {
+    static GLX instance;
+
+    public static synchronized GLX getInstance() {
+        if (instance == null) {
+            instance = new GLX();
+        }
+        return instance;
+    }
+
+    private GLX() {
+        System.loadLibrary("X11Wrapper");
+        init();
+    }
+
+    private static native void init();
+
+    public final int glXQueryExtension(long dpy, Int32Pointer error_base, Int32Pointer event_base) {
+        long tmp_0 = error_base == null ? 0 : error_base.longLockPointer();
+        long tmp_1 = event_base == null ? 0 : event_base.longLockPointer();
+        int tmp_ret = glXQueryExtension(dpy, tmp_0, tmp_1);
+        if (error_base != null) {
+            error_base.unlock();
+        }
+        if (event_base != null) {
+            event_base.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int glXQueryExtension(long dpy, long error_base, long event_base);
+
+    public final int glXGetFBConfigAttrib(long dpy, long config, int attribute, Int32Pointer value) {
+        long tmp_0 = value == null ? 0 : value.longLockPointer();
+        int tmp_ret = glXGetFBConfigAttrib(dpy, config, attribute, tmp_0);
+        if (value != null) {
+            value.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int glXGetFBConfigAttrib(long dpy, long config, int attribute, long value);
+
+    public final native long glXCreateNewContext(long dpy, long config, int render_type, long share_list, int direct);
+
+    public final native int glXMakeCurrent(long dpy, long drawable, long ctx);
+
+    public final native void glXDestroyContext(long dpy, long ctx);
+
+    public final native void glXDestroyPbuffer(long dpy, long pbuf);
+
+    public final PointerPointer glXChooseFBConfig(long dpy, int screen, Int32Pointer attrib_list, Int32Pointer nelements) {
+        long tmp_0 = attrib_list == null ? 0 : attrib_list.longLockPointer();
+        long tmp_1 = nelements == null ? 0 : nelements.longLockPointer();
+        long tmp_ret = glXChooseFBConfig(dpy, screen, tmp_0, tmp_1);
+        if (attrib_list != null) {
+            attrib_list.unlock();
+        }
+        if (nelements != null) {
+            nelements.unlock();
+        }
+        return nb.createPointerPointer(tmp_ret);
+    }
+    public final native long glXChooseFBConfig(long dpy, int screen, long attrib_list, long nelements);
+
+    public final long glXCreatePbuffer(long dpy, long config, Int32Pointer attrib_list) {
+        long tmp_0 = attrib_list == null ? 0 : attrib_list.longLockPointer();
+        long tmp_ret = glXCreatePbuffer(dpy, config, tmp_0);
+        if (attrib_list != null) {
+            attrib_list.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native long glXCreatePbuffer(long dpy, long config, long attrib_list);
+
+    public final native void glXSwapBuffers(long dpy, long drawable);
+
+    public final native int glXMakeContextCurrent(long display, long draw, long read, long ctx);
+
+}
+

Added: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WGLGraphicsConfiguration.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WGLGraphicsConfiguration.java?view=auto&rev=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WGLGraphicsConfiguration.java (added)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WGLGraphicsConfiguration.java Mon Dec  4 12:26:28 2006
@@ -0,0 +1,343 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Oleg V. Khaschansky
+ * @version $Revision$
+ */
+
+package org.apache.harmony.awt.gl.windows;
+
+import org.apache.harmony.awt.gl.opengl.OGLContextManager;
+import org.apache.harmony.awt.gl.opengl.GLDefs;
+import org.apache.harmony.awt.gl.opengl.OGLVolatileImage;
+import org.apache.harmony.awt.nativebridge.windows.*;
+import org.apache.harmony.awt.nativebridge.NativeBridge;
+import org.apache.harmony.awt.nativebridge.Int32Pointer;
+import org.apache.harmony.awt.wtk.windows.WindowProcHandler;
+import org.apache.harmony.awt.wtk.windows.WinEventQueue;
+import org.apache.harmony.awt.ContextStorage;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.awt.image.VolatileImage;
+
+public class WGLGraphicsConfiguration
+        extends WinGraphicsConfiguration
+        implements OGLContextManager {
+    private static final Win32 w32 = Win32.getInstance();
+    private static final WGL wgl = WGL.getInstance();
+
+    private static final String WINDOW_CLASS_NAME = "org.apache.harmony.awt.gl.tmpWindow";
+    private static final int FORMATTED_DRAWABLES_CACHE_SIZE = 255;
+
+    private static final ThreadLocal oglContextThreadLocal = new ThreadLocal();
+
+    private static long currentOGLContext;
+    private static long currentDrawable;
+
+    private static final ArrayList existingContexts = new ArrayList();
+    private static final HashSet formattedDrawables = new HashSet(255);
+
+    private static boolean wndClassRegistetred;
+
+    private long hTmpWnd;
+    private long hTmpDC;
+    private long tmpCtx;
+
+    // XXX - todo - maybe we need different pointers for different configurations?
+    //private static boolean resolvedEXT = false; // Are ext funcs resolved?
+
+    private long getLocalOGLContext() {
+        Long ctxId = (Long) oglContextThreadLocal.get();
+        return ctxId == null ? 0 : ctxId.longValue();
+    }
+
+    public WGLGraphicsConfiguration(WinGraphicsDevice device, int index, Win32.PIXELFORMATDESCRIPTOR pfd) {
+        super(device, index, pfd);
+    }
+
+    public WGLGraphicsConfiguration(long hwnd, long hdc) {
+        super(hwnd, hdc);
+    }
+
+    public WGLGraphicsConfiguration(long hdc) {
+        super(hdc);
+    }
+
+    public long windowProc(long hwnd, int msg, long wParam, long lParam) {
+        return w32.DefWindowProcW(hwnd, msg, wParam, lParam);
+    }
+
+    private final long getHWND() {
+        if (!wndClassRegistetred) {
+            WindowProcHandler.registerWindowClass(WINDOW_CLASS_NAME);
+            wndClassRegistetred = true;
+        }
+
+        WinEventQueue.Task task = new WinEventQueue.Task () {
+            public void perform() {
+                returnValue = new Long(w32.CreateWindowExW(
+                        0, WINDOW_CLASS_NAME, "TmpWindow",
+                        0, 0, 0, 0, 0, 0, 0, 0, null
+                ));
+            }
+        };
+
+        WinEventQueue winEventQueue = ((WinEventQueue) ContextStorage.getNativeEventQueue());
+        winEventQueue.performTask(task);
+
+        return ((Long)task.returnValue).longValue();
+    }
+
+    private void activateTmpCtx() {
+        if (hTmpWnd == 0) {
+            hTmpWnd = getHWND();
+            hTmpDC = w32.GetDC(hTmpWnd);
+
+            Win32.PIXELFORMATDESCRIPTOR pfd = w32.createPIXELFORMATDESCRIPTOR(false);
+            pfd.set_nSize((short)pfd.size());
+            pfd.set_nVersion((short)1);
+            pfd.set_dwFlags(WindowsDefs.PFD_DRAW_TO_WINDOW | WindowsDefs.PFD_SUPPORT_OPENGL);
+            pfd.set_iPixelType((byte)WindowsDefs.PFD_TYPE_RGBA);
+            pfd.set_cAlphaBits((byte)8);
+            pfd.set_cStencilBits((byte)1);
+            pfd.set_iLayerType((byte)WindowsDefs.PFD_MAIN_PLANE);
+
+            int pixelFormat = w32.ChoosePixelFormat(hTmpDC, pfd);
+            w32.SetPixelFormat(hTmpDC, pixelFormat, pfd);
+            tmpCtx = wgl.wglCreateContext(hTmpDC);
+        }
+
+        wgl.wglMakeCurrent(hTmpDC, tmpCtx);
+    }
+
+    protected void finalize() throws Throwable {
+        wgl.wglDeleteContext(tmpCtx);
+        w32.ReleaseDC(hTmpWnd, hTmpDC);
+        w32.DestroyWindow(hTmpWnd);
+    }
+
+    private final int choosePixelFormatARB(long hdc) {
+        /*
+        if (!resolvedEXT) {
+            resolveEXT();
+        }
+        */
+        activateTmpCtx();
+
+        Int32Pointer nFormats = NativeBridge.getInstance().createInt32Pointer(1, true);
+        Int32Pointer formatPtr = NativeBridge.getInstance().createInt32Pointer(1, true);
+        Int32Pointer attribList = NativeBridge.getInstance().createInt32Pointer(13, true);
+
+        // Fill in FB config attributes
+        attribList.set(0, WGLDefs.WGL_PIXEL_TYPE_ARB);
+        attribList.set(1, WGLDefs.WGL_TYPE_RGBA_ARB);
+        attribList.set(2, WGLDefs.WGL_DRAW_TO_WINDOW_ARB);
+        attribList.set(3, GLDefs.GL_TRUE);
+        attribList.set(4, WGLDefs.WGL_DRAW_TO_PBUFFER_ARB);
+        attribList.set(5, GLDefs.GL_TRUE);
+        attribList.set(6, WGLDefs.WGL_STENCIL_BITS_ARB);
+        attribList.set(7, 1);
+        attribList.set(8, WGLDefs.WGL_ALPHA_BITS_ARB);
+        attribList.set(9, 8);
+        attribList.set(10, WGLDefs.WGL_ACCELERATION_ARB);
+        attribList.set(11, WGLDefs.WGL_FULL_ACCELERATION_ARB);
+        //attribList.set(12, WGLDefs.WGL_DOUBLE_BUFFER_ARB);
+        //attribList.set(13, GLDefs.GL_TRUE);
+        attribList.set(12, 0);
+
+        wgl.wglChoosePixelFormatARB(hdc, attribList, null, 1, formatPtr, nFormats);
+
+        int res = formatPtr.get(0);
+
+        formatPtr.free();
+        nFormats.free();
+        attribList.free();
+
+        return res;
+    }
+
+    /**
+     * This method calls ext (ARB) functions to resolve its addresses.
+     * For now it calls only one - wglChoosePixelFormatARB
+     */
+    /*
+    private final void resolveEXT() {
+        long hwnd = getHWND();
+        long hdc = w32.GetDC(hwnd);
+
+        Win32.PIXELFORMATDESCRIPTOR pfd = w32.createPIXELFORMATDESCRIPTOR(false);
+        pfd.set_nSize((short)pfd.size());
+        pfd.set_nVersion((short)1);
+        pfd.set_dwFlags(WindowsDefs.PFD_DRAW_TO_WINDOW | WindowsDefs.PFD_SUPPORT_OPENGL);
+        pfd.set_iPixelType((byte)WindowsDefs.PFD_TYPE_RGBA);
+        pfd.set_cColorBits((byte)32);
+        pfd.set_cAlphaBits((byte)8);
+        pfd.set_cStencilBits((byte)1);
+        pfd.set_iLayerType((byte)WindowsDefs.PFD_MAIN_PLANE);
+
+        int pixelFormat = w32.ChoosePixelFormat(hdc, pfd);
+        w32.SetPixelFormat(hdc, pixelFormat, pfd);
+        // XXX - todo - check for success
+        long ctx = wgl.wglCreateContext(hdc);
+        wgl.wglMakeCurrent(hdc, ctx);
+
+        WGL.init(); // Initialize function pointers
+
+        wgl.wglMakeCurrent(0, 0);
+        wgl.wglDeleteContext(ctx);
+
+        w32.ReleaseDC(hwnd, hdc);
+        w32.DestroyWindow(hwnd);
+
+        resolvedEXT = true;
+    }
+    */
+    public long getOGLContext(long drawable, long oshdc) {
+        long oglContext = getLocalOGLContext();
+
+        if (oglContext == 0) {
+            long hdc = (oshdc == 0) ? w32.GetDC(drawable) : oshdc;
+
+            if (oshdc == 0) {
+                int pixelFormat = choosePixelFormatARB(hdc);
+                w32.SetPixelFormat(hdc, pixelFormat, w32.createPIXELFORMATDESCRIPTOR(false));
+                if (formattedDrawables.size() > FORMATTED_DRAWABLES_CACHE_SIZE) {
+                    formattedDrawables.clear();
+                }
+                formattedDrawables.add(new Long(drawable));
+            }
+
+            oglContext = wgl.wglCreateContext(hdc);
+
+            if(oshdc == 0) {
+                w32.ReleaseDC(drawable, hdc);
+            }
+
+            // Share display lists if there are othe contexts
+            if (existingContexts.size() > 0) {
+                wgl.wglShareLists(((Long)existingContexts.get(0)).longValue(), oglContext);
+            }
+
+            existingContexts.add(new Long(oglContext));
+            oglContextThreadLocal.set(new Long(oglContext));
+        }
+
+        return oglContext;
+    }
+
+    public void destroyOGLContext(long oglContext) {
+        if (oglContext == currentOGLContext) {
+            currentOGLContext = 0;
+        }
+
+        wgl.wglDeleteContext(oglContext);
+        existingContexts.remove(new Long(oglContext));
+    }
+
+    public boolean makeCurrent(long oglContext, long drawable, long oshdc) {
+        if (oglContext != currentOGLContext || drawable != currentDrawable) {
+
+            long hdc = (oshdc == 0) ? w32.GetDC(drawable) : oshdc;
+
+            if (oshdc == 0 && !formattedDrawables.contains(new Long(drawable))) { // Need to set pixel format
+                int pixelFormat = choosePixelFormatARB(hdc);
+                w32.SetPixelFormat(hdc, pixelFormat, w32.createPIXELFORMATDESCRIPTOR(false));
+                if (formattedDrawables.size() > FORMATTED_DRAWABLES_CACHE_SIZE) {
+                    formattedDrawables.clear();
+                }
+                formattedDrawables.add(new Long(drawable));
+            }
+
+            if (wgl.wglMakeCurrent(hdc, oglContext) == 0) {
+                w32.ReleaseDC(drawable, hdc);
+                throw new IllegalStateException("Cannot make opengl context current");
+            }
+
+            if(oshdc == 0) {
+                w32.ReleaseDC(drawable, hdc);
+            }
+
+            currentOGLContext = oglContext;
+            currentDrawable = drawable;
+
+            return true;
+        }
+
+        return false;
+    }
+
+    public boolean makeContextCurrent(
+            long oglContext,
+            long draw, long read,
+            long drawHDC, long readHDC
+    ) {
+        return makeCurrent(oglContext, draw, drawHDC); // XXX - todo - implement
+    }
+
+    public void swapBuffers(long drawable, long oshdc) {
+        long hdc = (oshdc == 0) ? w32.GetDC(drawable) : oshdc;
+        wgl.SwapBuffers(hdc);
+        if(oshdc == 0) {
+            w32.ReleaseDC(drawable, hdc);
+        }
+    }
+
+    public OffscreenBufferObject createOffscreenBuffer(int w, int h) {
+        // Try to get pbuffer from cache
+        OffscreenBufferObject pbuffer = OffscreenBufferObject.getCachedBuffer(w, h, this);
+        if (pbuffer != null) {
+            return pbuffer;
+        }
+
+        long hwnd = getHWND();
+        long hdc = w32.GetDC(hwnd);
+
+        int pixelFormat = choosePixelFormatARB(hdc);
+
+        Int32Pointer attribList = NativeBridge.getInstance().createInt32Pointer(1, true);
+        attribList.set(0,0);
+        long id = wgl.wglCreatePbufferARB(hdc, pixelFormat, w, h, attribList.lock());
+        attribList.unlock();
+        attribList.free();
+
+        long buffHdc = wgl.wglGetPbufferDCARB(id);
+
+        w32.ReleaseDC(hwnd, hdc);
+        w32.DestroyWindow(hwnd);
+
+        return new OffscreenBufferObject(id, buffHdc, w, h, this);
+    }
+
+    public void freeOffscreenBuffer(OffscreenBufferObject pbuffer) {
+        pbuffer = OffscreenBufferObject.freeCachedBuffer(pbuffer);
+
+        if (pbuffer != null) {
+            wgl.wglReleasePbufferDCARB(pbuffer.id, pbuffer.hdc);
+            wgl.wglDestroyPbufferARB(pbuffer.id);
+        }
+    }
+
+    public void freeOffscreenBuffer(long id, long hdc) {
+        wgl.wglReleasePbufferDCARB(id, hdc);
+        wgl.wglDestroyPbufferARB(id);
+    }
+
+    public VolatileImage createCompatibleVolatileImage(int width, int height) {
+        return new OGLVolatileImage(this, width, height);
+    }
+}

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphics2DFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphics2DFactory.java?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphics2DFactory.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphics2DFactory.java Mon Dec  4 12:26:28 2006
@@ -24,6 +24,7 @@
 
 import org.apache.harmony.awt.gl.CommonGraphics2DFactory;
 import org.apache.harmony.awt.gl.MultiRectArea;
+import org.apache.harmony.awt.gl.opengl.OGLGraphics2D;
 import org.apache.harmony.awt.gl.font.FontManager;
 import org.apache.harmony.awt.gl.font.WinFontManager;
 import org.apache.harmony.awt.gl.font.WindowsFont;
@@ -44,12 +45,20 @@
     @Deprecated
     public Graphics2D getGraphics2D(NativeWindow nw, int tx, int ty, MultiRectArea clip) {
         Insets ins = nw.getInsets();
-        return new WinGDIPGraphics2D(nw, tx - ins.left, ty - ins.top, clip);
+        if (WinGraphicsDevice.useOpenGL) {
+            return new OGLGraphics2D(nw, tx - ins.left, ty - ins.top, clip);
+        } else {
+            return new WinGDIPGraphics2D(nw, tx - ins.left, ty - ins.top, clip);
+        }
     }
 
     public Graphics2D getGraphics2D(NativeWindow nw, int tx, int ty, int width, int height) {
         Insets ins = nw.getInsets();
-        return new WinGDIPGraphics2D(nw, tx - ins.left, ty - ins.top, width, height);
+        if (WinGraphicsDevice.useOpenGL) {
+            return new OGLGraphics2D(nw, tx - ins.left, ty - ins.top, width, height);
+        } else {
+            return new WinGDIPGraphics2D(nw, tx - ins.left, ty - ins.top, width, height);
+        }
     }
 
     public GraphicsEnvironment createGraphicsEnvironment(WindowFactory wf) {

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsDevice.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsDevice.java?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsDevice.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsDevice.java Mon Dec  4 12:26:28 2006
@@ -52,6 +52,12 @@
 
     private byte []idBytes = null;
 
+    static boolean useOpenGL;
+    static {
+        String opengl = System.getProperty("java2d.opengl"); //$NON-NLS-1$
+        useOpenGL = opengl != null && opengl.equals("true"); //$NON-NLS-1$
+    };
+
     public WinGraphicsDevice(int left, int top, int right, int bottom, String id, boolean primary) {
         type = TYPE_RASTER_SCREEN;
         bounds = new Rectangle(left, top, right-left, bottom-top);
@@ -100,7 +106,9 @@
             int dci = win32.GetPixelFormat(hdc);
             Win32.PIXELFORMATDESCRIPTOR pfd = win32.createPIXELFORMATDESCRIPTOR(false);
             if (win32.DescribePixelFormat(hdc, dci, pfd.size(), pfd) > 0) {
-                defaultConfig = new WinGraphicsConfiguration(this, dci, pfd);
+                defaultConfig = useOpenGL ?
+                        new WGLGraphicsConfiguration(this, dci, pfd):
+                        new WinGraphicsConfiguration(this, dci, pfd);
             } else {
                 getConfigurations();
             }
@@ -138,7 +146,9 @@
             Vector<WinGraphicsConfiguration> gcv = new Vector<WinGraphicsConfiguration>(100);
             int i = 1;
             while (win32.DescribePixelFormat(hdc, i, pfd.size(), pfd) > 0) {
-                WinGraphicsConfiguration gc = new WinGraphicsConfiguration(this, i, pfd);
+                WinGraphicsConfiguration gc = useOpenGL ?
+                        new WGLGraphicsConfiguration(this, i, pfd):
+                        new WinGraphicsConfiguration(this, i, pfd);
 
                 if (!gcv.contains(gc)) {
                     gcv.add(gc);

Added: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGL.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGL.java?view=auto&rev=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGL.java (added)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGL.java Mon Dec  4 12:26:28 2006
@@ -0,0 +1,256 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Oleg V. Khaschansky
+ * @version $Revision$
+ */
+/**
+ * This file is based on WGL headers and has been generated by the nativebridge tool.
+ */
+
+package org.apache.harmony.awt.nativebridge.windows;
+
+import org.apache.harmony.awt.nativebridge.*;
+
+/**
+ * This file is based on WGL headers and has been generated by the nativebridge tool.
+ */
+public class WGL extends BasicLibWrapper {
+    static WGL instance;
+
+    public static synchronized WGL getInstance() {
+        if (instance == null) {
+            instance = new WGL();
+        }
+        return instance;
+    }
+
+    private WGL() {
+        System.loadLibrary("Win32Wrapper");
+        init();
+    }
+
+    private static native void init();
+
+    public final long wglGetProcAddress(String param_0) {
+        Int8Pointer _param_0 = null == param_0? null :  nb.createInt8Pointer(param_0, false);
+        long tmp_0 = _param_0 == null ? 0 : _param_0.longLockPointer();
+        long tmp_ret = wglGetProcAddress(tmp_0);
+        if (_param_0 != null) {
+            _param_0.unlock();
+            _param_0.free();
+        }
+        return tmp_ret;
+    }
+    public final long wglGetProcAddress(Int8Pointer param_0) {
+        long tmp_0 = param_0 == null ? 0 : param_0.longLockPointer();
+        long tmp_ret = wglGetProcAddress(tmp_0);
+        if (param_0 != null) {
+            param_0.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native long wglGetProcAddress(long param_0);
+
+    public final native long wglCreateContext(long param_0);
+
+
+    public static class HGLRC__ extends CommonStructWrapper {
+
+        public static final int sizeof = 4;
+
+        HGLRC__(boolean direct) {
+            super(sizeof, direct);
+        }
+        HGLRC__(VoidPointer base) {
+            super(base);
+        }
+        HGLRC__(long addr) {
+            super(addr);
+        }
+        public final void set_unused(int val) {
+            byteBase.setInt32(0, val);
+        }
+        public final int get_unused() {
+            return byteBase.getInt32(0);
+        }
+        public int size() {
+            return sizeof;
+        }
+    }
+
+    public final HGLRC__ createHGLRC__(boolean direct) {
+        return new HGLRC__(direct);
+    }
+    public final HGLRC__ createHGLRC__(VoidPointer base) {
+        return new HGLRC__(base);
+    }
+    public final HGLRC__ createHGLRC__(long addr) {
+        return new HGLRC__(addr);
+    }
+
+    public final int wglMakeCurrent(long param_0, WGL.HGLRC__ param_1) {
+        long tmp_0 = param_1 == null ? 0 : param_1.longLockPointer();
+        int tmp_ret = wglMakeCurrent(param_0, tmp_0);
+        if (param_1 != null) {
+            param_1.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int wglMakeCurrent(long param_0, long param_1);
+
+    public final int wglDestroyPbufferARB(HPBUFFERARB__ param_0) {
+        long tmp_0 = param_0 == null ? 0 : param_0.longLockPointer();
+        int tmp_ret = wglDestroyPbufferARB(tmp_0);
+        if (param_0 != null) {
+            param_0.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int wglDestroyPbufferARB(long param_0);
+
+
+    public static class HPBUFFERARB__ extends CommonStructWrapper {
+
+        public static final int sizeof = 4;
+
+        HPBUFFERARB__(boolean direct) {
+            super(sizeof, direct);
+        }
+        HPBUFFERARB__(VoidPointer base) {
+            super(base);
+        }
+        HPBUFFERARB__(long addr) {
+            super(addr);
+        }
+        public final void set_unused(int val) {
+            byteBase.setInt32(0, val);
+        }
+        public final int get_unused() {
+            return byteBase.getInt32(0);
+        }
+        public int size() {
+            return sizeof;
+        }
+    }
+
+    public final HPBUFFERARB__ createHPBUFFERARB__(boolean direct) {
+        return new HPBUFFERARB__(direct);
+    }
+    public final HPBUFFERARB__ createHPBUFFERARB__(VoidPointer base) {
+        return new HPBUFFERARB__(base);
+    }
+    public final HPBUFFERARB__ createHPBUFFERARB__(long addr) {
+        return new HPBUFFERARB__(addr);
+    }
+
+    public final native int SwapBuffers(long param_0);
+
+    public final int wglReleasePbufferDCARB(WGL.HPBUFFERARB__ param_0, long param_1) {
+        long tmp_0 = param_0 == null ? 0 : param_0.longLockPointer();
+        int tmp_ret = wglReleasePbufferDCARB(tmp_0, param_1);
+        if (param_0 != null) {
+            param_0.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int wglReleasePbufferDCARB(long param_0, long param_1);
+
+    public final WGL.HPBUFFERARB__ wglCreatePbufferARB(long param_0, int param_1, int param_2, int param_3, Int32Pointer param_4) {
+        long tmp_0 = param_4 == null ? 0 : param_4.longLockPointer();
+        long tmp_ret = wglCreatePbufferARB(param_0, param_1, param_2, param_3, tmp_0);
+        if (param_4 != null) {
+            param_4.unlock();
+        }
+        return WGL.instance.createHPBUFFERARB__(tmp_ret);
+    }
+    public final native long wglCreatePbufferARB(long param_0, int param_1, int param_2, int param_3, long param_4);
+
+    public final int wglQueryPbufferARB(WGL.HPBUFFERARB__ param_0, int param_1, Int32Pointer param_2) {
+        long tmp_0 = param_0 == null ? 0 : param_0.longLockPointer();
+        long tmp_1 = param_2 == null ? 0 : param_2.longLockPointer();
+        int tmp_ret = wglQueryPbufferARB(tmp_0, param_1, tmp_1);
+        if (param_0 != null) {
+            param_0.unlock();
+        }
+        if (param_2 != null) {
+            param_2.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int wglQueryPbufferARB(long param_0, int param_1, long param_2);
+
+    public final int wglDeleteContext(WGL.HGLRC__ param_0) {
+        long tmp_0 = param_0 == null ? 0 : param_0.longLockPointer();
+        int tmp_ret = wglDeleteContext(tmp_0);
+        if (param_0 != null) {
+            param_0.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int wglDeleteContext(long param_0);
+
+    public final native long wglGetExtensionsStringARB(long param_0);
+
+    public final int wglChoosePixelFormatARB(long param_0, Int32Pointer param_1, FloatPointer param_2, int param_3, Int32Pointer param_4, Int32Pointer param_5) {
+        long tmp_0 = param_1 == null ? 0 : param_1.longLockPointer();
+        long tmp_1 = param_2 == null ? 0 : param_2.longLockPointer();
+        long tmp_2 = param_4 == null ? 0 : param_4.longLockPointer();
+        long tmp_3 = param_5 == null ? 0 : param_5.longLockPointer();
+        int tmp_ret = wglChoosePixelFormatARB(param_0, tmp_0, tmp_1, param_3, tmp_2, tmp_3);
+        if (param_1 != null) {
+            param_1.unlock();
+        }
+        if (param_2 != null) {
+            param_2.unlock();
+        }
+        if (param_4 != null) {
+            param_4.unlock();
+        }
+        if (param_5 != null) {
+            param_5.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int wglChoosePixelFormatARB(long param_0, long param_1, long param_2, int param_3, long param_4, long param_5);
+
+    public final int wglShareLists(WGL.HGLRC__ param_0, WGL.HGLRC__ param_1) {
+        long tmp_0 = param_0 == null ? 0 : param_0.longLockPointer();
+        long tmp_1 = param_1 == null ? 0 : param_1.longLockPointer();
+        int tmp_ret = wglShareLists(tmp_0, tmp_1);
+        if (param_0 != null) {
+            param_0.unlock();
+        }
+        if (param_1 != null) {
+            param_1.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int wglShareLists(long param_0, long param_1);
+
+    public final long wglGetPbufferDCARB(WGL.HPBUFFERARB__ param_0) {
+        long tmp_0 = param_0 == null ? 0 : param_0.longLockPointer();
+        long tmp_ret = wglGetPbufferDCARB(tmp_0);
+        if (param_0 != null) {
+            param_0.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native long wglGetPbufferDCARB(long param_0);
+
+}
+

Added: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGLDefs.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGLDefs.java?view=auto&rev=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGLDefs.java (added)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WGLDefs.java Mon Dec  4 12:26:28 2006
@@ -0,0 +1,37 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Oleg V. Khaschansky
+ * @version $Revision$
+ */
+/**
+ * This file is based on WGL headers.
+ */
+
+package org.apache.harmony.awt.nativebridge.windows;
+
+public interface WGLDefs {
+    public static final int WGL_DRAW_TO_WINDOW_ARB         = 0x2001;
+    public static final int WGL_PIXEL_TYPE_ARB             = 0x2013;
+    public static final int WGL_TYPE_RGBA_ARB              = 0x202B;
+    public static final int WGL_DRAW_TO_PBUFFER_ARB        = 0x202D;
+    public static final int WGL_STENCIL_BITS_ARB           = 0x2023;
+    public static final int WGL_ALPHA_BITS_ARB             = 0x201B;
+    public static final int WGL_DOUBLE_BUFFER_ARB          = 0x2011;
+    public static final int WGL_ACCELERATION_ARB           = 0x2003;
+    public static final int WGL_FULL_ACCELERATION_ARB      = 0x2027;
+}

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WindowProcHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WindowProcHandler.java?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WindowProcHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WindowProcHandler.java Mon Dec  4 12:26:28 2006
@@ -89,4 +89,9 @@
                     className, winError));
         }
     }
+
+    public static void registerWindowClass(String className) {
+        registerCallback();
+        registerWindowClass(className, instance.windowProcPtr);
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/unix/libgl.exp
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/unix/libgl.exp?view=diff&rev=482341&r1=482340&r2=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/unix/libgl.exp (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/unix/libgl.exp Mon Dec  4 12:26:28 2006
@@ -16,6 +16,7 @@
         Java_org_apache_harmony_awt_gl_render_NativeImageBlitter_bltBG;
         Java_org_apache_harmony_awt_gl_render_NativeImageBlitter_blt;
         Java_org_apache_harmony_awt_gl_render_NativeImageBlitter_xor;
+   Java_org_apache_harmony_awt_gl_ImageSurface_updateCache;
         Java_org_apache_harmony_awt_gl_Surface_initIDs;
     local : *;
 };

Added: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h?view=auto&rev=482341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h (added)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h Mon Dec  4 12:26:28 2006
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+ /**
+ * @author Oleg V. Khaschansky
+ * @version $Revision$
+ */
+#ifndef NATIVELIB_COMMON_H
+#define NATIVELIB_COMMON_H
+
+#ifdef       __linux__
+// common linux section--------------------------------
+#include <dlfcn.h>
+#include <stdint.h>
+
+#define mkstr(x) #x
+
+
+#define LOAD_LIB(res, name) res = dlopen(mkstr(lib##name.so), RTLD_LAZY)
+
+#define FindFunction(lib, name) (void *)dlsym(lib, name)
+
+#define INIT_GL_GET_PROC_ADDRESS
+
+#ifndef __INTEL_COMPILER
+    typedef long long __int64;
+#endif
+
+typedef void* libHandler;
+
+#define __stdcall
+
+// END common linux section----------------------------
+#ifdef           __i386__
+// ia32 linux section----------------------------------
+
+
+
+// END ia32 linux section------------------------------
+#else           
+// ipf linux section----------------------------------
+
+// END ipf linux section------------------------------
+#endif
+#else        //WINDOWS
+// common windows section------------------------------
+#include <windows.h>
+
+#define mkstr(x) #x
+#define GL Opengl32
+#define GLU Glu32
+
+typedef HMODULE libHandler;
+
+#define LOAD_LIB(res, name) res =::LoadLibraryA(mkstr(name))
+
+//#define FindFunction(lib, name) ::GetProcAddress(lib, name)
+
+void * (__stdcall * p_nbridge_wglGetProcAddress) (void *);
+
+#undef FindFunction
+void *findFunctionRes = NULL;
+#define FindFunction(lib, name) ((findFunctionRes = (void *)::GetProcAddress(lib, name)) ? findFunctionRes : (*p_nbridge_wglGetProcAddress)(name))
+
+#define INIT_GL_GET_PROC_ADDRESS p_nbridge_wglGetProcAddress = (void * (__stdcall *) (void *)) ::GetProcAddress(libGL, "wglGetProcAddress");
+
+// END common windows section--------------------------
+#ifdef           _WIN32
+// ia32 windows section--------------------------------
+
+// END ia32 windows section----------------------------
+#else        //ITANIUM
+// ipf windows section--------------------------------
+
+// END ipf windows section----------------------------
+#endif
+#endif
+
+
+#endif



Mime
View raw message