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 MacGLFactory extends GLFactory {
  32     private static native long nInitialize(int[] attrArr);
  33     private static native int nGetAdapterOrdinal(long nativeScreen);
  34     private static native int nGetAdapterCount();
  35     private static native boolean nGetIsGL2(long nativeCtxInfo);
  36 
  37     // Entries must be in lowercase and null string is a wild card
  38     private GLGPUInfo preQualificationFilter[] = null;
  39 
  40     // These are older GPUs that users have reported problem in using the es2 pipe.
  41     // We don't have these units in-house to verify or maintain.
  42     private GLGPUInfo blackList[] = {
  43         new GLGPUInfo("ati", "radeon x1600 opengl engine"),
  44         new GLGPUInfo("ati", "radeon x1900 opengl engine"),
  45         new GLGPUInfo("intel", "gma x3100 opengl engine")
  46     };
  47 
  48     @Override
  49     GLGPUInfo[] getPreQualificationFilter() {
  50         return preQualificationFilter;
  51     }
  52 
  53     @Override
  54     GLGPUInfo[] getBlackList() {
  55         return blackList;
  56     }
  57 
  58     @Override
  59     GLContext createGLContext(long nativeCtxInfo) {
  60         return new MacGLContext(nativeCtxInfo);
  61     }
  62 
  63     @Override
  64     GLContext createGLContext(GLDrawable drawable, GLPixelFormat pixelFormat,
  65         GLContext shareCtx, boolean vSyncRequest) {
  66         return new MacGLContext(drawable, pixelFormat, shareCtx, vSyncRequest);
  67     }
  68 
  69     @Override
  70     GLDrawable createDummyGLDrawable(GLPixelFormat pixelFormat) {
  71         return new MacGLDrawable(pixelFormat);
  72     }
  73 
  74     @Override
  75     GLDrawable createGLDrawable(long nativeWindow, GLPixelFormat pixelFormat) {
  76         return new MacGLDrawable(nativeWindow, pixelFormat);
  77     }
  78 
  79     @Override
  80     GLPixelFormat createGLPixelFormat(long nativeScreen, Attributes attributes) {
  81         return new MacGLPixelFormat(nativeScreen, attributes);
  82     }
  83 
  84     @Override
  85     boolean initialize(Class psClass, Attributes attrs) {
  86 
  87         // holds the list of attributes to be translated for native call
  88         int attrArr[] = new int[GLPixelFormat.Attributes.NUM_ITEMS];
  89 
  90         attrArr[GLPixelFormat.Attributes.RED_SIZE] = attrs.getRedSize();
  91         attrArr[GLPixelFormat.Attributes.GREEN_SIZE] = attrs.getGreenSize();
  92         attrArr[GLPixelFormat.Attributes.BLUE_SIZE] = attrs.getBlueSize();
  93         attrArr[GLPixelFormat.Attributes.ALPHA_SIZE] = attrs.getAlphaSize();
  94         attrArr[GLPixelFormat.Attributes.DEPTH_SIZE] = attrs.getDepthSize();
  95         attrArr[GLPixelFormat.Attributes.DOUBLEBUFFER] = attrs.isDoubleBuffer() ? 1 : 0;
  96         attrArr[GLPixelFormat.Attributes.ONSCREEN] = attrs.isOnScreen() ? 1 : 0;
  97 
  98         // return the context info object create on the default screen
  99         nativeCtxInfo = nInitialize(attrArr);
 100 
 101         if (nativeCtxInfo == 0) {
 102             // current pipe doesn't support this pixelFormat request
 103             return false;
 104         } else {
 105             gl2 = nGetIsGL2(nativeCtxInfo);
 106             return true;
 107         }
 108     }
 109 
 110     @Override
 111     int getAdapterCount() {
 112         return nGetAdapterCount();
 113     }
 114 
 115     @Override
 116     int getAdapterOrdinal(long nativeScreen) {
 117         return nGetAdapterOrdinal(nativeScreen);
 118     }
 119 
 120     @Override
 121     void updateDeviceDetails(HashMap deviceDetails) {
 122            deviceDetails.put("shareContextPtr", getShareContext().getNativeHandle());
 123     }
 124 
 125     // JIRA: RT-21739
 126     // TODO: This is a temporary mechanism to work well with Glass on Mac due
 127     // to the CALayer work. Need to be removed in the early future for 3.0
 128     @Override
 129     void updateDeviceDetails(HashMap deviceDetails, GLContext glContext) {
 130            deviceDetails.put("contextPtr", glContext.getNativeHandle());
 131     }
 132 }