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