JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
AWTGraphicsConfiguration.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright (c) 2010 JogAmp Community. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * - Redistribution of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistribution in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any kind. ALL
21 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
22 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
24 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
25 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
27 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
28 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
29 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
30 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
31 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that this software is not designed or intended for use
34 * in the design, construction, operation or maintenance of any nuclear
35 * facility.
36 *
37 * Sun gratefully acknowledges that this software was originally authored
38 * and developed by Kenneth Bradley Russell and Christopher John Kline.
39 */
40
41package com.jogamp.nativewindow.awt;
42
43import com.jogamp.nativewindow.*;
44
45import java.awt.Component;
46import java.awt.GraphicsConfiguration;
47import java.awt.GraphicsDevice;
48import java.awt.image.ColorModel;
49import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
50
51import jogamp.nativewindow.Debug;
52
53/** A wrapper for an AWT GraphicsConfiguration allowing it to be
54 handled in a toolkit-independent manner. */
55
56public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable {
57 private final GraphicsConfiguration config;
59
61 final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested,
62 final GraphicsConfiguration config, final AbstractGraphicsConfiguration encapsulated) {
63 super(screen, capsChosen, capsRequested);
64 this.config = config;
65 this.encapsulated=encapsulated;
66 }
67
68 private AWTGraphicsConfiguration(final AWTGraphicsScreen screen, final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested,
69 final GraphicsConfiguration config) {
70 super(screen, capsChosen, capsRequested);
71 this.config = config;
72 this.encapsulated=null;
73 }
74
75 /**
76 * Method constructs a new {@link AWTGraphicsConfiguration} primarily based
77 * on the given {@link GraphicsConfiguration}.
78 * @param gc the {@link GraphicsConfiguration} for the resulting {@link AWTGraphicsConfiguration}
79 * @param capsChosen if null, <code>capsRequested</code> is copied and aligned
80 * with the graphics {@link Capabilities} of the AWT Component to produce the chosen {@link Capabilities}.
81 * Otherwise the <code>capsChosen</code> is used.
82 * @param capsRequested if null, default {@link Capabilities} are used, otherwise the given values.
83 */
84 public static AWTGraphicsConfiguration create(final GraphicsConfiguration gc, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) {
85 if(null==gc) {
86 throw new IllegalArgumentException("Null AWT GraphicsConfiguration");
87 }
88 final GraphicsDevice awtGraphicsDevice = gc.getDevice();
89 if(null==awtGraphicsDevice) {
90 throw new NativeWindowException("Null AWT GraphicsDevice @ "+gc);
91 }
92
93 // Create Device/Screen
94 final AWTGraphicsDevice awtDevice = new AWTGraphicsDevice(awtGraphicsDevice, AbstractGraphicsDevice.DEFAULT_UNIT);
95 final AWTGraphicsScreen awtScreen = new AWTGraphicsScreen(awtDevice);
96
97 if(null==capsRequested) {
98 capsRequested = new Capabilities();
99 }
100 if(null==capsChosen) {
101 capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsRequested, gc);
102 }
103 final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(awtDevice, capsChosen);
104 final AbstractGraphicsConfiguration config = factory.chooseGraphicsConfiguration(capsChosen, capsRequested, null, awtScreen, VisualIDHolder.VID_UNDEFINED);
105 if(config instanceof AWTGraphicsConfiguration) {
106 return (AWTGraphicsConfiguration) config;
107 }
108 // System.err.println("Info: AWTGraphicsConfiguration.create: Expected AWTGraphicsConfiguration got: "+config.getClass()+" w/ factory "+factory.getClass()+" - Unable to encapsulate native GraphicsConfiguration.");
109 return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, gc);
110 }
111
112 // open access to superclass method
113 @Override
114 public void setChosenCapabilities(final CapabilitiesImmutable capsChosen) {
115 super.setChosenCapabilities(capsChosen);
116 }
117
118 @Override
119 public Object clone() {
120 return super.clone();
121 }
122
123 /** Return the AWT {@link GraphicsConfiguration}. */
124 public GraphicsConfiguration getAWTGraphicsConfiguration() {
125 return config;
126 }
127
128 @Override
130 return (null!=encapsulated)?encapsulated:this;
131 }
132
133 /**
134 * Sets up the Capabilities' RGBA size based on the given GraphicsConfiguration's ColorModel.
135 *
136 * @param capabilities the Capabilities object whose red, green, blue, and alpha bits will be set
137 * @param gc the GraphicsConfiguration from which to derive the RGBA bit depths
138 * @return the passed Capabilities
139 */
140 public static CapabilitiesImmutable setupCapabilitiesRGBABits(final CapabilitiesImmutable capabilitiesIn, final GraphicsConfiguration gc) {
141 final Capabilities capabilities = (Capabilities) capabilitiesIn.cloneMutable();
142
143 final ColorModel cm = gc.getColorModel();
144 if(null==cm) {
145 throw new NativeWindowException("Could not determine AWT ColorModel");
146 }
147 final int cmBitsPerPixel = cm.getPixelSize();
148 int bitsPerPixel = 0;
149 final int[] bitesPerComponent = cm.getComponentSize();
150 if(bitesPerComponent.length>=3) {
151 capabilities.setRedBits(bitesPerComponent[0]);
152 bitsPerPixel += bitesPerComponent[0];
153 capabilities.setGreenBits(bitesPerComponent[1]);
154 bitsPerPixel += bitesPerComponent[1];
155 capabilities.setBlueBits(bitesPerComponent[2]);
156 bitsPerPixel += bitesPerComponent[2];
157 }
158 if(bitesPerComponent.length>=4) {
159 capabilities.setAlphaBits(bitesPerComponent[3]);
160 bitsPerPixel += bitesPerComponent[3];
161 } else {
162 capabilities.setAlphaBits(0);
163 }
164 if(Debug.debugAll()) {
165 if(cmBitsPerPixel!=bitsPerPixel) {
166 System.err.println("AWT Colormodel bits per components/pixel mismatch: "+bitsPerPixel+" != "+cmBitsPerPixel);
167 }
168 }
169 return capabilities;
170 }
171
172 @Override
173 public String toString() {
174 return getClass().getSimpleName()+"[" + getScreen() +
175 ",\n\tchosen " + capabilitiesChosen+
176 ",\n\trequested " + capabilitiesRequested+
177 ",\n\t" + config +
178 ",\n\tencapsulated "+encapsulated+"]";
179 }
180}
Specifies a set of capabilities that a window's rendering context must support, such as color depth p...
void setRedBits(final int redBits)
Sets the number of bits requested for the color buffer's red component.
void setGreenBits(final int greenBits)
Sets the number of bits requested for the color buffer's green component.
void setBlueBits(final int blueBits)
Sets the number of bits requested for the color buffer's blue component.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
final AbstractGraphicsScreen getScreen()
Return the screen this graphics configuration is valid for.
Provides the mechanism by which the graphics configuration for a window can be chosen before the wind...
final AbstractGraphicsConfiguration chooseGraphicsConfiguration(final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested, final CapabilitiesChooser chooser, final AbstractGraphicsScreen screen, final int nativeVisualID)
static GraphicsConfigurationFactory getFactory(final AbstractGraphicsDevice device, final CapabilitiesImmutable caps)
Returns the graphics configuration factory for use with the given device and capability.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
A wrapper for an AWT GraphicsConfiguration allowing it to be handled in a toolkit-independent manner.
AWTGraphicsConfiguration(final AWTGraphicsScreen screen, final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested, final GraphicsConfiguration config, final AbstractGraphicsConfiguration encapsulated)
GraphicsConfiguration getAWTGraphicsConfiguration()
Return the AWT GraphicsConfiguration.
static CapabilitiesImmutable setupCapabilitiesRGBABits(final CapabilitiesImmutable capabilitiesIn, final GraphicsConfiguration gc)
Sets up the Capabilities' RGBA size based on the given GraphicsConfiguration's ColorModel.
AbstractGraphicsConfiguration getNativeGraphicsConfiguration()
In case the implementation utilizes a delegation pattern to wrap abstract toolkits,...
void setChosenCapabilities(final CapabilitiesImmutable capsChosen)
Set the capabilities to a new value.
static AWTGraphicsConfiguration create(final GraphicsConfiguration gc, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested)
Method constructs a new AWTGraphicsConfiguration primarily based on the given GraphicsConfiguration.
A wrapper for an AWT GraphicsDevice allowing it to be handled in a toolkit-independent manner.
A wrapper for an AWT GraphicsDevice (screen) allowing it to be handled in a toolkit-independent manne...
A marker interface describing a graphics configuration, visual, or pixel format in a toolkit-independ...
A interface describing a graphics device in a toolkit-independent manner.
static int DEFAULT_UNIT
Default unit id for the 1st device: 0.
Specifies an immutable set of capabilities that a window's rendering context must support,...
static final int VID_UNDEFINED
getVisualID(VIDType) result indicating an undefined value, which could be cause by an unsupported que...