1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/**
* Copyright 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
package com.jogamp.nativewindow;
/**
* Provides low-level information required for
* hardware-accelerated rendering using a surface in a platform-independent manner.
* <p>
* All values of this interface are represented in pixel units, if not stated otherwise.
* See {@link NativeWindow}.
* </p>
* <p>
* A NativeSurface created for a particular on- or offscreen component is
* expected to have the same lifetime as that component. As long as
* the component is alive and realized/visible, NativeSurface must be able
* provide information such as the surface handle while it is locked.
* </p>
*/
public interface NativeSurface extends SurfaceUpdatedListener {
/** Unlocked state, {@value}. */
public static final int LOCK_SURFACE_UNLOCKED = 0;
/** Returned by {@link #lockSurface()} if the surface is not ready to be locked, {@value}. */
public static final int LOCK_SURFACE_NOT_READY = 1;
/** Returned by {@link #lockSurface()} if the surface is locked, but has changed, {@value}. */
public static final int LOCK_SURFACE_CHANGED = 2;
/** Returned by {@link #lockSurface()} if the surface is locked, and is unchanged, {@value}. */
public static final int LOCK_SUCCESS = 3;
/**
* Lock the surface of this native window.
* <p>
* The surface handle shall be valid after a successfull call,
* ie return a value other than {@link #LOCK_SURFACE_UNLOCKED} and {@link #LOCK_SURFACE_NOT_READY},
* which is
* <pre>
* boolean ok = LOCK_SURFACE_NOT_READY < lockSurface();
* </pre>
* </p>
* <p>
* The caller may need to take care of the result {@link #LOCK_SURFACE_CHANGED},
* where the surface handle is valid but has changed.
* </p>
* <p>
* This call is blocking until the surface has been locked
* or a timeout is reached. The latter will throw a runtime exception.
* </p>
* <p>
* This call allows recursion from the same thread.
* </p>
* <p>
* The implementation may want to aquire the
* application level {@link com.jogamp.common.util.locks.RecursiveLock}
* first before proceeding with a native surface lock.
* </p>
* <p>
* The implementation shall also invoke {@link AbstractGraphicsDevice#lock()}
* for the initial lock (recursive count zero).
* </p>
*
* @return {@link #LOCK_SUCCESS}, {@link #LOCK_SURFACE_CHANGED} or {@link #LOCK_SURFACE_NOT_READY}.
*
* @throws RuntimeException after timeout when waiting for the surface lock
* @throws NativeWindowException if native locking failed, maybe platform related
*
* @see com.jogamp.common.util.locks.RecursiveLock
*/
public int lockSurface() throws NativeWindowException, RuntimeException;
/**
* Unlock the surface of this native window
*
* Shall not modify the surface handle, see {@link #lockSurface()} <P>
*
* The implementation shall also invoke {@link AbstractGraphicsDevice#unlock()}
* for the final unlock (recursive count zero).<P>
*
* The implementation shall be fail safe, i.e. tolerant in case the native resources
* are already released / unlocked. In this case the implementation shall simply ignore the call.
*
* @see #lockSurface
* @see com.jogamp.common.util.locks.RecursiveLock
*/
public void unlockSurface();
/**
* Query if surface is locked by another thread, i.e. not the current one.
* <br>
* Convenient shortcut for:
* <pre>
* final Thread o = getSurfaceLockOwner();
* if( null != o && Thread.currentThread() != o ) { .. }
* </pre>
*/
public boolean isSurfaceLockedByOtherThread();
/**
* Return the locking owner's Thread, or null if not locked.
*/
public Thread getSurfaceLockOwner();
/**
* Provide a mechanism to utilize custom (pre-) swap surface
* code. This method is called before the render toolkit (e.g. JOGL)
* swaps the buffer/surface if double buffering is enabled.
* <p>
* The implementation may itself apply the swapping,
* in which case true shall be returned.
* </p>
*
* @return true if this method completed swapping the surface,
* otherwise false, in which case eg the GLDrawable
* implementation has to swap the code.
*/
public boolean surfaceSwap();
/** Appends the given {@link SurfaceUpdatedListener} to the end of the list. */
public void addSurfaceUpdatedListener(SurfaceUpdatedListener l);
/**
* Inserts the given {@link SurfaceUpdatedListener} at the
* specified position in the list.<br>
*
* @param index Position where the listener will be inserted.
* Should be within (0 <= index && index <= size()).
* An index value of -1 is interpreted as the end of the list, size().
* @param l The listener object to be inserted
* @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1
*/
public void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) throws IndexOutOfBoundsException;
/** Remove the specified {@link SurfaceUpdatedListener} from the list. */
public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l);
/**
* Returns the handle to the surface for this NativeSurface. <P>
*
* The surface handle should be set/update by {@link #lockSurface()},
* where {@link #unlockSurface()} is not allowed to modify it.
* After {@link #unlockSurface()} it is no more guaranteed
* that the surface handle is still valid.
*
* The surface handle shall reflect the platform one
* for all drawable surface operations, e.g. opengl, swap-buffer. <P>
*
* On X11 this returns an entity of type Window,
* since there is no differentiation of surface and window there. <BR>
* On Microsoft Windows this returns an entity of type HDC.
*/
public long getSurfaceHandle();
/**
* Returns the width of the client area excluding insets (window decorations) in pixel units.
* @return width of the client area in pixel units
* @see NativeWindow#getWidth()
* @see #convertToWindowUnits(int[])
*/
public int getSurfaceWidth();
/**
* Returns the height of the client area excluding insets (window decorations) in pixel units.
* @return height of the client area in pixel units
* @see NativeWindow#getHeight()
* @see #convertToWindowUnits(int[])
*/
public int getSurfaceHeight();
/**
* Converts the given pixel units into window units <i>in place</i>.
* @param pixelUnitsAndResult int[2] storage holding the pixel units for the x- and y-coord to convert
* and the resulting values.
* @return result int[2] storage pixelUnitsAndResult for chaining holding the converted values
* @see ScalableSurface
*/
public int[] convertToWindowUnits(final int[] pixelUnitsAndResult);
/**
* Converts the given window units into pixel units <i>in place</i>.
* @param windowUnitsAndResult int[2] storage holding the window units for the x- and y-coord to convert
* and the resulting values.
* @return result int[2] storage windowUnitsAndResult for chaining holding the converted values
* @see ScalableSurface
*/
public int[] convertToPixelUnits(final int[] windowUnitsAndResult);
/**
* Returns the graphics configuration corresponding to this window.
* <p>
* In case the implementation utilizes a delegation pattern to wrap abstract toolkits,
* this method shall return the native {@link AbstractGraphicsConfiguration} via {@link AbstractGraphicsConfiguration#getNativeGraphicsConfiguration()}.
* </p>
* @see AbstractGraphicsConfiguration#getNativeGraphicsConfiguration()
* @see com.jogamp.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
*/
public AbstractGraphicsConfiguration getGraphicsConfiguration();
/**
* Convenience: Get display handle from
* AbstractGraphicsConfiguration . AbstractGraphicsScreen . AbstractGraphicsDevice
*/
public long getDisplayHandle();
/**
* Convenience: Get display handle from
* AbstractGraphicsConfiguration . AbstractGraphicsScreen
*/
public int getScreenIndex();
}
|