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 IOSGLFactory 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     private GLGPUInfo blackList[] = {
  41     };
  42 
  43     @Override
  44     GLGPUInfo[] getPreQualificationFilter() {
  45         return preQualificationFilter;
  46     }
  47 
  48     @Override
  49     GLGPUInfo[] getBlackList() {
  50         return blackList;
  51     }
  52 
  53     @Override
  54     GLContext createGLContext(long nativeCtxInfo) {
  55         return new IOSGLContext(nativeCtxInfo);
  56     }
  57 
  58     @Override
  59     GLContext createGLContext(GLDrawable drawable, GLPixelFormat pixelFormat,
  60         GLContext shareCtx, boolean vSyncRequest) {
  61         GLContext glassCtx = new IOSGLContext(drawable, pixelFormat, shareCtx, vSyncRequest);
  62         GLContext prismCtx = new IOSGLContext(drawable, pixelFormat, shareCtx, vSyncRequest);
  63 
  64         // NOTE: glassCtx isn't the prism rendering context. This glassCtx is created
  65         // and passed to Glass; prism never needs to switch or access it.
  66         HashMap devDetails = (HashMap) ES2Pipeline.getInstance().getDeviceDetails();
  67         devDetails.put("contextPtr", glassCtx.getNativeHandle());
  68 
  69         return prismCtx;
  70     }
  71 
  72     @Override
  73     GLDrawable createDummyGLDrawable(GLPixelFormat pixelFormat) {
  74         return new IOSGLDrawable(pixelFormat);
  75     }
  76 
  77     @Override
  78     GLDrawable createGLDrawable(long nativeWindow, GLPixelFormat pixelFormat) {
  79         return new IOSGLDrawable(nativeWindow, pixelFormat);
  80     }
  81 
  82     @Override
  83     GLPixelFormat createGLPixelFormat(long nativeScreen, Attributes attributes) {
  84         return new IOSGLPixelFormat(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         System.err.println("  initialize() returns " + nativeCtxInfo);
 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            deviceDetails.put("shareContextPtr", getShareContext().getNativeHandle());
 128     }
 129 }