1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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.glass.ui.monocle;
  27 
  28 import java.nio.Buffer;
  29 import java.nio.IntBuffer;
  30 import com.sun.glass.ui.monocle.linux.LinuxSystem;
  31 import java.lang.reflect.Method;
  32 import java.util.Locale;
  33 
  34 public abstract class NativeScreen {
  35     private static long glesLibraryHandle;
  36     private static long eglLibraryHandle;
  37     private static long nativeDisplayType;
  38     private static boolean initialized;
  39 
  40     public abstract int getDepth();
  41     public abstract int getNativeFormat();
  42     public abstract int getWidth();
  43     public abstract int getHeight();
  44     public abstract int getDPI();
  45     public abstract long getNativeHandle();
  46     public abstract void shutdown();
  47     public static long platformGetNativeDisplay() {return 0L;};
  48 
  49 
  50     public abstract void uploadPixels(Buffer b,
  51                              int x, int y, int width, int height, float alpha);
  52 
  53     public abstract void swapBuffers();
  54 
  55     public abstract IntBuffer getScreenCapture();
  56 
  57     protected static boolean initPlatformLibraries() {
  58         LinuxSystem ls = LinuxSystem.getLinuxSystem();
  59         glesLibraryHandle = ls.dlopen("libGLESv2.so", LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
  60         eglLibraryHandle = ls.dlopen("libEGL.so", LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
  61         return true;
  62     }
  63 
  64     public static synchronized long getNativeDisplay() {
  65         String platformNativeScreenName;
  66 
  67         if (initialized) {
  68             // already initialized
  69             return nativeDisplayType;
  70         }
  71         String platformName = NativePlatformFactory.getNativePlatformName();
  72         platformNativeScreenName = "com.sun.glass.ui.monocle." + platformName + "." +
  73                                            platformName.toUpperCase(Locale.ROOT) + "Screen";
  74         initPlatformLibraries();
  75         try {
  76             Method platformMethod = Class.forName(platformNativeScreenName).getMethod("platformGetNativeDisplay");
  77             nativeDisplayType = (long)platformMethod.invoke(null);
  78         } catch (Exception e){
  79             e.printStackTrace();
  80         }
  81 
  82         initialized = true;
  83         return nativeDisplayType;
  84     }
  85 
  86 }