aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/egl/EGLUpstreamSurfaceHook.java
blob: 42c6e100e11cb90f2e1da85d0a18aaa993d9c5fe (plain)
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
package jogamp.opengl.egl;

import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.ProxySurface;
import javax.media.opengl.GLException;

import com.jogamp.nativewindow.egl.EGLGraphicsDevice;

public class EGLUpstreamSurfaceHook implements ProxySurface.UpstreamSurfaceHook {
    private final NativeSurface upstreamSurface;
    
    public EGLUpstreamSurfaceHook(NativeSurface upstream) {
        upstreamSurface = upstream;
    }
    
    public final NativeSurface getUpstreamSurface() { return upstreamSurface; }
    
    @Override
    public final void create(ProxySurface surface) {
        if(upstreamSurface instanceof ProxySurface) {
            ((ProxySurface)upstreamSurface).createNotify();
            if(NativeSurface.LOCK_SURFACE_NOT_READY >= upstreamSurface.lockSurface()) {
                throw new GLException("Could not lock: "+upstreamSurface);
            }
        }
        final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) surface.getGraphicsConfiguration().getScreen().getDevice();
        eglDevice.open();
    }

    @Override
    public final void destroy(ProxySurface surface) {
        final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) surface.getGraphicsConfiguration().getScreen().getDevice();
        eglDevice.close();
        if(upstreamSurface instanceof ProxySurface) {
            upstreamSurface.unlockSurface();
            ((ProxySurface)upstreamSurface).destroyNotify();
        }
    }

    @Override
    public final int getWidth(ProxySurface s) {
        return upstreamSurface.getWidth();
    }

    @Override
    public final int getHeight(ProxySurface s) {
        return upstreamSurface.getHeight();
    }
    
    @Override
    public String toString() {
        final String us_s = null != upstreamSurface ? ( upstreamSurface.getClass().getName() + ": " + upstreamSurface ) : "nil"; 
        return "EGLUpstreamSurfaceHook[upstream: "+us_s+"]";
    }

}