Jogamp
moved com.jogamp.javafx.* to com.jogamp.*.
[jogl.git] / src / newt / classes / com / jogamp / newt / opengl / broadcom / egl / Window.java
CommitLineData
8949675c 1/*
2 * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Sun Microsystems, Inc. or the names of
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 *
32 */
33
2d57c252 34package com.jogamp.newt.opengl.broadcom.egl;
8949675c 35
f3bc93b0 36import com.jogamp.opengl.impl.egl.*;
8949675c 37import javax.media.nativewindow.*;
38import javax.media.opengl.GLCapabilities;
8949675c 39import javax.media.nativewindow.NativeWindowException;
40
2d57c252 41public class Window extends com.jogamp.newt.Window {
8949675c 42 static {
9fd3c095 43 Display.initSingleton();
8949675c 44 }
45
9fd3c095 46 public Window() {
8949675c 47 }
48
3cc7335e
SG
49 protected void createNative(long parentWindowHandle, Capabilities caps) {
50 if(0!=parentWindowHandle) {
51 throw new RuntimeException("Window parenting not supported (yet)");
52 }
0a92a475 53 // query a good configuration .. even thought we drop this one
54 // and reuse the EGLUtil choosen one later.
55 config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen());
56 if (config == null) {
57 throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
58 }
b5ce9cce 59 setSizeImpl(getScreen().getWidth(), getScreen().getHeight());
8949675c 60 }
61
62 protected void closeNative() {
63 if(0!=windowHandleClose) {
64 CloseWindow(getDisplayHandle(), windowHandleClose);
65 }
66 }
67
68 public void setVisible(boolean visible) {
69 if(this.visible!=visible) {
70 this.visible=visible;
71 if ( 0==windowHandle ) {
72 windowHandle = realizeWindow(true, width, height);
73 if (0 == windowHandle) {
74 throw new NativeWindowException("Error native Window Handle is null");
75 }
76 }
77 clearEventMask();
78 }
79 }
80
81 public void setSize(int width, int height) {
b5ce9cce 82 System.err.println("setSize "+width+"x"+height+" n/a in BroadcomEGL");
83 }
84
85 void setSizeImpl(int width, int height) {
8949675c 86 if(0!=windowHandle) {
87 // n/a in BroadcomEGL
9fd3c095 88 System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window");
8949675c 89 } else {
219abab4 90 if(DEBUG_IMPLEMENTATION) {
9fd3c095 91 Exception e = new Exception("BCEGL Window.setSizeImpl() "+this.width+"x"+this.height+" -> "+width+"x"+height);
219abab4 92 e.printStackTrace();
93 }
8949675c 94 this.width = width;
95 this.height = height;
96 }
97 }
98
99 public void setPosition(int x, int y) {
100 // n/a in BroadcomEGL
101 System.err.println("setPosition n/a in BroadcomEGL");
102 }
103
104 public boolean setFullscreen(boolean fullscreen) {
105 // n/a in BroadcomEGL
106 System.err.println("setFullscreen n/a in BroadcomEGL");
107 return false;
108 }
109
8883fa88 110 public boolean surfaceSwap() {
111 if ( 0!=windowHandle ) {
112 SwapWindow(getDisplayHandle(), windowHandle);
113 return true;
114 }
115 return false;
116 }
117
8949675c 118 //----------------------------------------------------------------------
119 // Internals only
120 //
121
122 protected static native boolean initIDs();
123 private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height);
124 private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle);
8883fa88 125 private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle);
8949675c 126
127
128 private long realizeWindow(boolean chromaKey, int width, int height) {
219abab4 129 if(DEBUG_IMPLEMENTATION) {
9fd3c095 130 System.out.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config);
219abab4 131 }
8949675c 132 long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height);
133 if (0 == handle) {
134 throw new NativeWindowException("Error native Window Handle is null");
135 }
136 windowHandleClose = handle;
137 return handle;
138 }
139
140 private void windowCreated(int cfgID, int width, int height) {
141 this.width = width;
142 this.height = height;
0a92a475 143 GLCapabilities capsReq = (GLCapabilities) config.getRequestedCapabilities();
144 config = EGLGraphicsConfiguration.create(capsReq, screen.getGraphicsScreen(), cfgID);
8949675c 145 if (config == null) {
146 throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this);
147 }
4b5e1a0f 148 if(DEBUG_IMPLEMENTATION) {
2268a6ce 149 System.out.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config);
4b5e1a0f 150 }
8949675c 151 }
152
153 private long windowHandleClose;
8949675c 154}
http://JogAmp.org git info: FAQ, tutorial and man pages.