Source Code Cross Referenced for XGraphicsDevice.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » gl » linux » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.awt.gl.linux 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Oleg V. Khaschansky
019:         * @version $Revision$
020:         *
021:         * @date: Nov 15, 2005
022:         */package org.apache.harmony.awt.gl.linux;
023:
024:        import java.awt.*;
025:        import java.lang.reflect.InvocationTargetException;
026:
027:        import org.apache.harmony.awt.gl.GLGraphicsDevice;
028:        import org.apache.harmony.awt.gl.Utils;
029:        import org.apache.harmony.awt.nativebridge.Int32Pointer;
030:        import org.apache.harmony.awt.nativebridge.NativeBridge;
031:        import org.apache.harmony.awt.nativebridge.linux.X11;
032:        import org.apache.harmony.awt.nativebridge.linux.X11Defs;
033:        import org.apache.harmony.awt.ContextStorage;
034:
035:        public class XGraphicsDevice extends GLGraphicsDevice {
036:            private static final X11 x11 = X11.getInstance();
037:
038:            long display;
039:            int screen;
040:
041:            //private X11.Display xdisplay = null;
042:            private X11.Screen xscreen = null;
043:
044:            private XGraphicsConfiguration configs[] = null;
045:            private int defaultConfigIdx;
046:
047:            private DisplayMode displayMode;
048:
049:            XGraphicsDevice(long display, int screen) {
050:                this .display = display;
051:                this .screen = screen;
052:
053:                displayMode = new DisplayMode(getDisplayWidth(),
054:                        getDisplayHeight(), DisplayMode.BIT_DEPTH_MULTI,
055:                        DisplayMode.REFRESH_RATE_UNKNOWN);
056:            }
057:
058:            private final X11.Screen getXscreen() {
059:                if (xscreen == null)
060:                    xscreen = x11.createScreen(x11.XScreenOfDisplay(display,
061:                            screen));
062:
063:                return xscreen;
064:            }
065:
066:            private final XGraphicsConfiguration[] getConfigs() {
067:                if (configs == null) {
068:                    //createConfigs();
069:
070:                    if (true || EventQueue.isDispatchThread()) {
071:                        createConfigs();
072:                    } else {
073:                        boolean wasAWTLocked = false;
074:                        try {
075:                            // XXX - todo - This is a hack actually, should be discussed further
076:                            try {
077:                                ContextStorage.getSynchronizer()
078:                                        .storeStateAndFree();
079:                                wasAWTLocked = true;
080:                            } catch (RuntimeException e) {
081:                            }
082:
083:                            try {
084:                                EventQueue.invokeAndWait(new Runnable() {
085:                                    public void run() {
086:                                        createConfigs();
087:                                    }
088:                                });
089:                            } catch (InterruptedException e) {
090:                                e.printStackTrace();
091:                            } catch (InvocationTargetException e) {
092:                                e.printStackTrace();
093:                            }
094:                        } finally {
095:                            if (wasAWTLocked)
096:                                ContextStorage.getSynchronizer()
097:                                        .lockAndRestoreState();
098:                        }
099:                    }
100:                }
101:
102:                return configs;
103:            }
104:
105:            void createConfigs() {
106:                // First get default visual ID
107:                long defVisualPtr = x11.XDefaultVisual(display, screen);
108:                long defVisId = x11.XVisualIDFromVisual(defVisualPtr);
109:
110:                // Allocate one int to get number of visual infos by ref
111:                Int32Pointer numVisualInfosPtr = NativeBridge.getInstance()
112:                        .createInt32Pointer(1, true);
113:
114:                // Create template visual to obtain visuals for current screen only
115:                X11.XVisualInfo vinfo_template = x11.createXVisualInfo(true);
116:                vinfo_template.set_screen(screen);
117:
118:                // Obtain infos
119:                X11.XVisualInfo infosPtr = x11.XGetVisualInfo(display,
120:                        X11Defs.VisualScreenMask, vinfo_template,
121:                        numVisualInfosPtr);
122:                vinfo_template.free(); // Free template data
123:
124:                int numVisualInfos = numVisualInfosPtr.get(0);
125:                numVisualInfosPtr.free();
126:
127:                // Allocate array for configurations
128:                configs = new XGraphicsConfiguration[numVisualInfos];
129:
130:                String opengl = System.getProperty("java2d.opengl"); //$NON-NLS-1$
131:                boolean useOpenGL = opengl != null && opengl.equals("true"); //$NON-NLS-1$
132:
133:                for (int i = 0; i < numVisualInfos; i++) {
134:                    X11.XVisualInfo info = x11.createXVisualInfo(infosPtr
135:                            .getElementPointer(i * infosPtr.size()));
136:                    configs[i] = useOpenGL ? new GLXGraphicsConfiguration(this ,
137:                            info) : new XGraphicsConfiguration(this , info);
138:
139:                    if (info.get_visualid() == defVisId)
140:                        defaultConfigIdx = i;
141:                }
142:
143:                if (useOpenGL) {
144:                    //defVisId = 36;
145:                    defVisId = GLXGraphicsConfiguration.GlxConfigsRec
146:                            .getBestGLXVisualId(display, screen);
147:                    for (int i = 0; i < numVisualInfos; i++) {
148:                        if (configs[i].info.get_visualid() == defVisId) {
149:                            defaultConfigIdx = i;
150:                            break;
151:                        }
152:                    }
153:                }
154:            }
155:
156:            public int getType() {
157:                return TYPE_RASTER_SCREEN;
158:            }
159:
160:            public GraphicsConfiguration getDefaultConfiguration() {
161:                return getConfigs()[defaultConfigIdx];
162:            }
163:
164:            public GraphicsConfiguration[] getConfigurations() {
165:                return getConfigs();
166:            }
167:
168:            public String getIDstring() {
169:                long strPtr = x11.XDisplayString(display);
170:                return Utils.straccess.createStringUTF(strPtr);
171:            }
172:
173:            int getDisplayWidth() {
174:                return getXscreen().get_width();
175:            }
176:
177:            int getDisplayHeight() {
178:                return getXscreen().get_height();
179:            }
180:
181:            protected void finalize() {
182:                // Here we have to XFree all XVisualInfo's allocated by createConfigs
183:                // First info contains a pointer to memory allocated by XGetVisualInfo
184:                if (configs != null && configs.length != 0) {
185:                    x11.XFree(configs[0].info);
186:                }
187:            }
188:
189:            public int getScreen() {
190:                return screen;
191:            }
192:
193:            public DisplayMode getDisplayMode() {
194:                return displayMode;
195:            }
196:
197:            public DisplayMode[] getDisplayModes() {
198:                DisplayMode[] dms = { displayMode };
199:                return dms;
200:            }
201:
202:            public Dimension getResolution() {
203:                return new Dimension(
204:                        (int) (x11.XDisplayWidth(display, screen) * 25.4 / x11
205:                                .XDisplayWidthMM(display, screen)), (int) (x11
206:                                .XDisplayHeight(display, screen) * 25.4 / x11
207:                                .XDisplayHeightMM(display, screen)));
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.