1 /*
   2  * Copyright (c) 2012, 2015, 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         GLContext glassCtx = new MacGLContext(drawable, pixelFormat, shareCtx, vSyncRequest);
  67         GLContext prismCtx = new MacGLContext(drawable, pixelFormat, shareCtx, vSyncRequest);
  68 
  69         // NOTE: glassCtx isn't the prism rendering context. This glassCtx is created
  70         // and passed to Glass; prism never needs to switch or access it.
  71         HashMap devDetails = (HashMap) ES2Pipeline.getInstance().getDeviceDetails();
  72         devDetails.put("contextPtr", glassCtx.getNativeHandle());
  73 
  74         return prismCtx;
  75     }
  76 
  77     @Override
  78     GLDrawable createDummyGLDrawable(GLPixelFormat pixelFormat) {
  79         return new MacGLDrawable(pixelFormat);
  80     }
  81 
  82     @Override
  83     GLDrawable createGLDrawable(long nativeWindow, GLPixelFormat pixelFormat) {
  84         return new MacGLDrawable(nativeWindow, pixelFormat);
  85     }
  86 
  87     @Override
  88     GLPixelFormat createGLPixelFormat(long nativeScreen, Attributes attributes) {
  89         return new MacGLPixelFormat(nativeScreen, attributes);
  90     }
  91 
  92     @Override
  93     boolean initialize(Class psClass, Attributes attrs) {
  94 
  95         // holds the list of attributes to be translated for native call
  96         int attrArr[] = new int[GLPixelFormat.Attributes.NUM_ITEMS];
  97 
  98         attrArr[GLPixelFormat.Attributes.RED_SIZE] = attrs.getRedSize();
  99         attrArr[GLPixelFormat.Attributes.GREEN_SIZE] = attrs.getGreenSize();
 100         attrArr[GLPixelFormat.Attributes.BLUE_SIZE] = attrs.getBlueSize();
 101         attrArr[GLPixelFormat.Attributes.ALPHA_SIZE] = attrs.getAlphaSize();
 102         attrArr[GLPixelFormat.Attributes.DEPTH_SIZE] = attrs.getDepthSize();
 103         attrArr[GLPixelFormat.Attributes.DOUBLEBUFFER] = attrs.isDoubleBuffer() ? 1 : 0;
 104         attrArr[GLPixelFormat.Attributes.ONSCREEN] = attrs.isOnScreen() ? 1 : 0;
 105 
 106         // return the context info object create on the default screen
 107         nativeCtxInfo = nInitialize(attrArr);
 108 
 109         if (nativeCtxInfo == 0) {
 110             // current pipe doesn't support this pixelFormat request
 111             return false;
 112         } else {
 113             gl2 = nGetIsGL2(nativeCtxInfo);
 114             return true;
 115         }
 116     }
 117 
 118     @Override
 119     int getAdapterCount() {
 120         return nGetAdapterCount();
 121     }
 122 
 123     @Override
 124     int getAdapterOrdinal(long nativeScreen) {
 125         return nGetAdapterOrdinal(nativeScreen);
 126     }
 127 
 128     @Override
 129     void updateDeviceDetails(HashMap deviceDetails) {
 130            deviceDetails.put("shareContextPtr", getShareContext().getNativeHandle());
 131     }
 132 }