modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java

Print this page




  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.glass.ui.monocle;
  27 
  28 import com.sun.glass.ui.monocle.linux.LinuxSystem;
  29 
  30 public class AcceleratedScreen {
  31 
  32     private static long glesLibraryHandle;
  33     private static long eglLibraryHandle;
  34     protected static boolean initialized = false;
  35     long eglSurface, eglContext, eglDisplay;

  36 
  37     protected long platformGetNativeDisplay() {
  38         return 0L;
  39     }
  40 
  41     protected long platformGetNativeWindow() {
  42         return 0L;
  43     }
  44 
  45     public AcceleratedScreen(int[] attributes) {
  46         initPlatformLibraries();
  47 
  48         int major[] = {0}, minor[]={0};
  49         eglDisplay =
  50                 EGL.eglGetDisplay(platformGetNativeDisplay());
  51         EGL.eglInitialize(eglDisplay, major, minor);
  52         EGL.eglBindAPI(EGL.EGL_OPENGL_ES_BIT);
  53 
  54         long eglConfigs[] = {0};
  55         int configCount[] = {0};


  57         EGL.eglChooseConfig(eglDisplay, attributes, eglConfigs, 1, configCount);
  58         eglSurface =
  59                 EGL.eglCreateWindowSurface(eglDisplay, eglConfigs[0],
  60                         platformGetNativeWindow(), null);
  61 
  62         int emptyAttrArray [] = {};
  63         eglContext = EGL.eglCreateContext(eglDisplay, eglConfigs[0],
  64                 0, emptyAttrArray);
  65     }
  66 
  67     public void enableRendering(boolean flag) {
  68         if (flag) {
  69             EGL.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
  70         } else {
  71             EGL.eglMakeCurrent(eglDisplay, 0, 0, eglContext);
  72         }
  73     }
  74 
  75     protected boolean initPlatformLibraries() {
  76         if (!initialized) {
  77             LinuxSystem ls = LinuxSystem.getLinuxSystem();
  78             glesLibraryHandle = ls.dlopen("libGLESv2.so",
  79                     LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
  80             eglLibraryHandle = ls.dlopen("libEGL.so",
  81                     LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
  82             initialized = true;
  83         }
  84         return true;
  85     }
  86 
  87     public long getGLHandle() {
  88         return glesLibraryHandle;
  89     }
  90 
  91     public long getEGLHandle() { return eglLibraryHandle; }
  92 
  93     public boolean swapBuffers() {
  94         EGL.eglSwapBuffers(eglDisplay, eglSurface);
  95         return true;
  96     }
  97 


  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.glass.ui.monocle;
  27 
  28 import com.sun.glass.ui.monocle.linux.LinuxSystem;
  29 
  30 public class AcceleratedScreen {
  31 
  32     private static long glesLibraryHandle;
  33     private static long eglLibraryHandle;
  34     protected static boolean initialized = false;
  35     long eglSurface, eglContext, eglDisplay;
  36     protected static LinuxSystem ls = LinuxSystem.getLinuxSystem();
  37 
  38     protected long platformGetNativeDisplay() {
  39         return 0L;
  40     }
  41 
  42     protected long platformGetNativeWindow() {
  43         return 0L;
  44     }
  45 
  46     public AcceleratedScreen(int[] attributes) {
  47         initPlatformLibraries();
  48 
  49         int major[] = {0}, minor[]={0};
  50         eglDisplay =
  51                 EGL.eglGetDisplay(platformGetNativeDisplay());
  52         EGL.eglInitialize(eglDisplay, major, minor);
  53         EGL.eglBindAPI(EGL.EGL_OPENGL_ES_BIT);
  54 
  55         long eglConfigs[] = {0};
  56         int configCount[] = {0};


  58         EGL.eglChooseConfig(eglDisplay, attributes, eglConfigs, 1, configCount);
  59         eglSurface =
  60                 EGL.eglCreateWindowSurface(eglDisplay, eglConfigs[0],
  61                         platformGetNativeWindow(), null);
  62 
  63         int emptyAttrArray [] = {};
  64         eglContext = EGL.eglCreateContext(eglDisplay, eglConfigs[0],
  65                 0, emptyAttrArray);
  66     }
  67 
  68     public void enableRendering(boolean flag) {
  69         if (flag) {
  70             EGL.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
  71         } else {
  72             EGL.eglMakeCurrent(eglDisplay, 0, 0, eglContext);
  73         }
  74     }
  75 
  76     protected boolean initPlatformLibraries() {
  77         if (!initialized) {

  78             glesLibraryHandle = ls.dlopen("libGLESv2.so",
  79                     LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
  80             eglLibraryHandle = ls.dlopen("libEGL.so",
  81                     LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
  82             initialized = true;
  83         }
  84         return true;
  85     }
  86 
  87     public long getGLHandle() {
  88         return glesLibraryHandle;
  89     }
  90 
  91     public long getEGLHandle() { return eglLibraryHandle; }
  92 
  93     public boolean swapBuffers() {
  94         EGL.eglSwapBuffers(eglDisplay, eglSurface);
  95         return true;
  96     }
  97