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         new GLGPUInfo("x.org", null)
  48     };
  49 
  50     private GLGPUInfo blackList[] = null;
  51 
  52     @Override
  53     GLGPUInfo[] getPreQualificationFilter() {
  54         return preQualificationFilter;
  55     }
  56 
  57     @Override
  58     GLGPUInfo[] getBlackList() {
  59         return blackList;
  60     }
  61 
  62     @Override
  63     GLContext createGLContext(long nativeCtxInfo) {
  64         return new X11GLContext(nativeCtxInfo);
  65     }
  66 
  67     @Override
  68     GLContext createGLContext(GLDrawable drawable, GLPixelFormat pixelFormat,
  69             GLContext shareCtx, boolean vSyncRequest) {
  70         // No need to pass down shareCtx as we don't use shared ctx on X11
  71         return new X11GLContext(drawable, pixelFormat, vSyncRequest);
  72     }
  73 
  74     @Override
  75     GLDrawable createDummyGLDrawable(GLPixelFormat pixelFormat) {
  76         return new X11GLDrawable(pixelFormat);
  77     }
  78 
  79     @Override
  80     GLDrawable createGLDrawable(long nativeWindow, GLPixelFormat pixelFormat) {
  81         return new X11GLDrawable(nativeWindow, pixelFormat);
  82     }
  83 
  84     @Override
  85     GLPixelFormat createGLPixelFormat(long nativeScreen, Attributes attributes) {
  86         return new X11GLPixelFormat(nativeScreen, attributes);
  87     }
  88 
  89     @Override
  90     boolean initialize(Class psClass, Attributes attrs) {
  91 
  92         // holds the list of attributes to be translated for native call
  93         int attrArr[] = new int[GLPixelFormat.Attributes.NUM_ITEMS];
  94 
  95         attrArr[GLPixelFormat.Attributes.RED_SIZE] = attrs.getRedSize();
  96         attrArr[GLPixelFormat.Attributes.GREEN_SIZE] = attrs.getGreenSize();
  97         attrArr[GLPixelFormat.Attributes.BLUE_SIZE] = attrs.getBlueSize();
  98         attrArr[GLPixelFormat.Attributes.ALPHA_SIZE] = attrs.getAlphaSize();
  99         attrArr[GLPixelFormat.Attributes.DEPTH_SIZE] = attrs.getDepthSize();
 100         attrArr[GLPixelFormat.Attributes.DOUBLEBUFFER] = attrs.isDoubleBuffer() ? 1 : 0;
 101         attrArr[GLPixelFormat.Attributes.ONSCREEN] = attrs.isOnScreen() ? 1 : 0;
 102 
 103         // return the context info object create on the default screen
 104         nativeCtxInfo = nInitialize(attrArr);
 105 
 106         if (nativeCtxInfo == 0) {
 107             // current pipe doesn't support this pixelFormat request
 108             return false;
 109         } else {
 110             gl2 = true;
 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         deviceDetails.put("XVisualID", new Long(nGetVisualID(nativeCtxInfo)));
 128         deviceDetails.put("XDisplay", new Long(nGetDisplay(nativeCtxInfo)));
 129         deviceDetails.put("XScreenID", new Integer(nGetDefaultScreen(nativeCtxInfo)));
 130     }
 131 }