1 /*
   2  * Copyright (c) 2012, 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.prism.es2;
  27 
  28 import com.sun.glass.ui.monocle.NativePlatformFactory;
  29 import com.sun.prism.es2.GLPixelFormat.Attributes;
  30 import java.util.HashMap;
  31 import com.sun.glass.ui.monocle.EGL;
  32 import com.sun.glass.ui.monocle.NativeScreen;
  33 
  34 
  35 class MonocleGLFactory extends GLFactory {
  36 
  37     private static native long nInitialize(int[] attrArr);
  38     private static native int nGetAdapterOrdinal(long nativeScreen);
  39     private static native int nGetAdapterCount();
  40     private static native int nGetDefaultScreen(long nativeCtxInfo);
  41     private static native long nGetDisplay(long nativeCtxInfo);
  42     private static native long nGetVisualID(long nativeCtxInfo);
  43     private static native boolean nGetIsGL2(long nativeCtxInfo);
  44 
  45     // Entries must be in lowercase and null string is a wild card
  46     // For Linux Beta release we will limit es2 pipe qualification check to NVidia GPUs only
  47     private GLGPUInfo preQualificationFilter[] = null;
  48     private GLGPUInfo blackList[] = null;
  49 
  50     @Override
  51     GLGPUInfo[] getPreQualificationFilter() {
  52         return preQualificationFilter;
  53     }
  54 
  55     @Override
  56     GLGPUInfo[] getBlackList() {
  57         return blackList;
  58     }
  59 
  60     @Override
  61     GLContext createGLContext(long nativeCtxInfo) {
  62         return new MonocleGLContext(nativeCtxInfo);
  63     }
  64 
  65     @Override
  66     GLContext createGLContext(GLDrawable drawable, GLPixelFormat pixelFormat,
  67                                      GLContext shareCtx, boolean vSyncRequest) {
  68         // No need to pass down shareCtx as we don't use shared ctx on Monocle
  69         return new MonocleGLContext(drawable, pixelFormat, vSyncRequest);
  70     }
  71 
  72     @Override
  73     GLDrawable createDummyGLDrawable(GLPixelFormat pixelFormat) {
  74         return new MonocleGLDrawable(pixelFormat);
  75     }
  76 
  77     @Override
  78     GLDrawable createGLDrawable(long nativeWindow, GLPixelFormat pixelFormat) {
  79         return new MonocleGLDrawable(nativeWindow, pixelFormat);
  80     }
  81 
  82     @Override
  83     GLPixelFormat createGLPixelFormat(long nativeScreen, Attributes attributes) {
  84         return new MonocleGLPixelFormat(nativeScreen, attributes);
  85     }
  86 
  87     @Override
  88     boolean initialize(Class psClass, Attributes attrs) {
  89 
  90         // holds the list of attributes to be translated for native call
  91         int attrArr[] = new int[GLPixelFormat.Attributes.NUM_ITEMS];
  92 
  93         attrArr[GLPixelFormat.Attributes.RED_SIZE] = attrs.getRedSize();
  94         attrArr[GLPixelFormat.Attributes.GREEN_SIZE] = attrs.getGreenSize();
  95         attrArr[GLPixelFormat.Attributes.BLUE_SIZE] = attrs.getBlueSize();
  96         attrArr[GLPixelFormat.Attributes.ALPHA_SIZE] = attrs.getAlphaSize();
  97         attrArr[GLPixelFormat.Attributes.DEPTH_SIZE] = attrs.getDepthSize();
  98         attrArr[GLPixelFormat.Attributes.DOUBLEBUFFER] = attrs.isDoubleBuffer() ? 1 : 0;
  99         attrArr[GLPixelFormat.Attributes.ONSCREEN] = attrs.isOnScreen() ? 1 : 0;
 100 
 101         // return the context info object create on the default screen
 102         nativeCtxInfo = nInitialize(attrArr);
 103 
 104         EGL.eglGetDisplay(NativeScreen.getNativeDisplay());
 105 
 106         if (nativeCtxInfo == 0) {
 107             // current pipe doesn't support this pixelFormat request
 108             return false;
 109         } else {
 110             gl2 = nGetIsGL2(nativeCtxInfo);
 111             return true;
 112         }
 113     }
 114 
 115     @Override
 116     int getAdapterCount() {
 117         return nGetAdapterCount();
 118     }
 119 
 120     @Override
 121     int getAdapterOrdinal(long nativeScreen) {
 122         return nGetAdapterOrdinal(nativeScreen);
 123     }
 124 
 125     @Override
 126     void updateDeviceDetails(HashMap deviceDetails) {
 127     }
 128 }