1 /** 2 * Copyright 2012 JogAmp Community. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are 5 * permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * 24 * The views and conclusions contained in the software and documentation are those of the 25 * authors and should not be interpreted as representing official policies, either expressed 26 * or implied, of JogAmp Community. 27 */ 28 29 package com.jogamp.nativewindow; 30 31 import java.util.Comparator; 32 33 /** 34 * Visual ID holder interface. 35 * <p> 36 * Allows queries of different types of native visual IDs, 37 * see {@link #getVisualID(int)}. 38 * </p> 39 */ 40 public interface VisualIDHolder { 41 42 public enum VIDType { 43 // Generic Values 44 INTRINSIC(0), NATIVE(1), 45 // EGL Values 46 EGL_CONFIG(10), 47 // X11 Values 48 X11_XVISUAL(20), X11_FBCONFIG(21), 49 // Windows Values 50 WIN32_PFD(30); 51 52 public final int id; 53 VIDType(final int id)54 VIDType(final int id){ 55 this.id = id; 56 } 57 } 58 59 /** 60 * Returns the native visual ID of the given <code>type</code> 61 * if supported, or {@link #VID_UNDEFINED} if not supported. 62 * <p> 63 * Depending on the native windowing system, <code>type</code> is handled as follows: 64 * <ul> 65 * <li>X11 throws NativeWindowException on <code>EGL_CONFIG</code>, <code>WIN32_PFD</code> 66 * <ul> 67 * <li><code>INTRINSIC</code>: <i>X11 XVisual ID</i></li> 68 * <li><code>NATIVE</code>: <i>X11 XVisual ID</i></li> 69 * <li><code>X11_XVISUAL</code>: <i>X11 XVisual ID</i></li> 70 * <li><code>X11_FBCONFIG</code>: <code>VID_UNDEFINED</code></li> 71 * </ul></li> 72 * <li>X11/GL throws NativeWindowException on <code>EGL_CONFIG</code>, <code>WIN32_PFD</code> 73 * <ul> 74 * <li><code>INTRINSIC</code>: <i>X11 XVisual ID</i></li> 75 * <li><code>NATIVE</code>: <i>X11 XVisual ID</i></li> 76 * <li><code>X11_XVISUAL</code>: <i>X11 XVisual ID</i></li> 77 * <li><code>X11_FBCONFIG</code>: <i>X11 FBConfig ID</i> or <code>VID_UNDEFINED</code></li> 78 * </ul></li> 79 * <li>Windows/GL throws NativeWindowException on <code>EGL_CONFIG</code>, <code>X11_XVISUAL</code>, <code>X11_FBCONFIG</code> 80 * <ul> 81 * <li><code>INTRINSIC</code>: <i>Win32 PIXELFORMATDESCRIPTOR ID</i></li> 82 * <li><code>NATIVE</code>: <i>Win32 PIXELFORMATDESCRIPTOR ID</i></li> 83 * <li><code>WIN32_PFD</code>: <i>Win32 PIXELFORMATDESCRIPTOR ID</i></li> 84 * </ul></li> 85 * <li>EGL/GL throws NativeWindowException on <code>X11_XVISUAL</code>, <code>X11_FBCONFIG</code>, <code>WIN32_PFD</code> 86 * <ul> 87 * <li><code>INTRINSIC</code>: <i>EGL Config ID</i></li> 88 * <li><code>NATIVE</code>: <i>EGL NativeVisual ID</i> (<i>X11 XVisual ID</i>, <i>Win32 PIXELFORMATDESCRIPTOR ID</i>, ...)</li> 89 * <li><code>EGL_CONFIG</code>: <i>EGL Config ID</i></li> 90 * </ul></li> 91 * </ul> 92 * </p> 93 * Note: <code>INTRINSIC</code> and <code>NATIVE</code> are always handled, 94 * but may result in {@link #VID_UNDEFINED}. The latter is true if 95 * the native value are actually undefined or the corresponding object is not 96 * mapped to a native visual object. 97 * 98 * @throws NativeWindowException if <code>type</code> is neither 99 * <code>INTRINSIC</code> nor <code>NATIVE</code> 100 * and does not match the native implementation. 101 */ getVisualID(VIDType type)102 int getVisualID(VIDType type) throws NativeWindowException ; 103 104 /** 105 * {@link #getVisualID(VIDType)} result indicating an undefined value, 106 * which could be cause by an unsupported query. 107 * <p> 108 * We assume the const value <code>0</code> doesn't reflect a valid native visual ID 109 * and is interpreted as <i>no value</i> on all platforms. 110 * This is currently true for Android, X11 and Windows. 111 * </p> 112 */ 113 static final int VID_UNDEFINED = 0; 114 115 /** Comparing {@link VIDType#NATIVE} */ 116 public static class VIDComparator implements Comparator<VisualIDHolder> { 117 private final VIDType type; 118 VIDComparator(final VIDType type)119 public VIDComparator(final VIDType type) { 120 this.type = type; 121 } 122 123 @Override compare(final VisualIDHolder vid1, final VisualIDHolder vid2)124 public int compare(final VisualIDHolder vid1, final VisualIDHolder vid2) { 125 final int id1 = vid1.getVisualID(type); 126 final int id2 = vid2.getVisualID(type); 127 128 if(id1 > id2) { 129 return 1; 130 } else if(id1 < id2) { 131 return -1; 132 } 133 return 0; 134 } 135 } 136 } 137