Source Code Cross Referenced for PiscesGCISurface.java in  » 6.0-JDK-Modules » j2me » com » sun » pisces » 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 » 6.0 JDK Modules » j2me » com.sun.pisces 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation. 
008:         * 
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt). 
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA 
019:         * 
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions. 
023:         *
024:         */
025:
026:        package com.sun.pisces;
027:
028:        import com.sun.me.gci.surface.GCIDrawingSurface;
029:        import com.sun.me.gci.surface.GCISurfaceInfo;
030:
031:        /**
032:         * Wrapper for GCIDrawingSurface for Pisces rendering. 
033:         * @see     PiscesShapeRenderer 
034:         */
035:        public final class PiscesGCISurface extends AbstractSurface {
036:            /** 
037:             * Pointer to native image data. Accessed from native code.
038:             * This field is used when GCISurface stores image data in a buffer allocated
039:             * by native code.         
040:             */
041:            private long nativeArray;
042:
043:            /**
044:             * Java image data arrays for different image-types. GCIDrawingSurface uses
045:             * different Java arrays to store data. The real data-type used depends on
046:             * image-type.        
047:             * Accessed from native code. 
048:             */
049:            private int[] javaArrayInt;
050:            private short[] javaArrayShort;
051:            private byte[] javaArrayByte;
052:
053:            /** 
054:             * This property says which of previously declared data arrays
055:             * (nativeArray, javaArrayInt, javaArrayShort, javaArrayByte) is
056:             * currently used to store image-data. This is set in acquireSurface()
057:             * accordingly to underlying GCIDrawingSurface properties. The value 
058:             * is also used in native code for acquirement of appropriate image memory
059:             * from java. Values must be one of the following TYPE_OF_ARRAY_. 
060:             * Another value is errorneous.
061:             */
062:            private int typeOfArray;
063:
064:            /** 
065:             * Field's @typeOfArray possible values. 
066:             * Corresponding #defines are used in native code. If you modify them here, 
067:             * please, make relevant changes to JPiscesGCISurface.c also.
068:             */
069:            public static final int TYPE_OF_ARRAY_NATIVE = 0;
070:            public static final int TYPE_OF_ARRAY_JAVA_INT = 1;
071:            public static final int TYPE_OF_ARRAY_JAVA_SHORT = 2;
072:            public static final int TYPE_OF_ARRAY_JAVA_BYTE = 3;
073:
074:            /** 
075:             * Underlying GCIDrawingSurface. This is destination of our rendering.    
076:             */
077:            private final GCIDrawingSurface gciSurface;
078:
079:            /**
080:             * The GCISurfaceInfo of gciSurface held between calls to acquireSurface
081:             * and releaseSurface.
082:             */
083:            private GCISurfaceInfo gciSurfaceInfo;
084:
085:            private final int imageType;
086:            /**
087:             * How much to right-shift value in bits to get value in pixels.
088:             */
089:            private final int bitsToPixelsShift;
090:
091:            private int offset;
092:            private int scanlineStride;
093:            private int pixelStride;
094:
095:            /** 
096:             * Instantiates wrapper class of GCIDrawingSurface for Pisces rendering.
097:             * It acquires all needed information from surface and ensures 
098:             * initialization of native pisces surface structures.          
099:             * @param surface 
100:             * @see GCIDrawingSurface            
101:             */
102:            public PiscesGCISurface(GCIDrawingSurface surface) {
103:                gciSurface = surface;
104:
105:                switch (surface.getFormat()) {
106:                case GCIDrawingSurface.FORMAT_RGB_888:
107:                case GCIDrawingSurface.FORMAT_XRGB_8888:
108:                case GCIDrawingSurface.FORMAT_ARGB_8888:
109:                    imageType = RendererBase.TYPE_INT_RGB;
110:                    bitsToPixelsShift = 5; // 2 ^ 5 = 32
111:                    break;
112:                case GCIDrawingSurface.FORMAT_RGB_565:
113:                    imageType = RendererBase.TYPE_USHORT_565_RGB;
114:                    bitsToPixelsShift = 4; // 2 ^ 4 = 16
115:                    break;
116:                case GCIDrawingSurface.FORMAT_GRAY_8:
117:                    imageType = RendererBase.TYPE_BYTE_GRAY;
118:                    bitsToPixelsShift = 3; // 2 ^ 3 = 8
119:                    break;
120:                case GCIDrawingSurface.FORMAT_ARGB_8888_PRE:
121:                    imageType = RendererBase.TYPE_INT_ARGB_PRE;
122:                    bitsToPixelsShift = 5; // 2 ^ 5 = 32
123:                    break;
124:                default:
125:                    throw new IllegalArgumentException(
126:                            "Pisces does not support" + " "
127:                                    + surface.getFormat() + " yet");
128:                }
129:
130:                int width = surface.getWidth();
131:                int height = surface.getHeight();
132:
133:                if (surface.isSurfaceInfoDynamic()) {
134:                    initialize(imageType, width, height, true);
135:                } else {
136:                    // acquire surface once
137:                    acquireSurface();
138:                    initialize(imageType, width, height, false);
139:                }
140:            }
141:
142:            /** 
143:             * Gets all neccessary information from GCIDrawingSurface.
144:             * Anytime surface changes at runtime. This method must be called to ensure      
145:             * pisces and GCI surfaces synchronization.
146:             */
147:            public void acquireSurface() {
148:                if (gciSurfaceInfo != null) {
149:                    // we have already acquired the surface
150:                    return;
151:                }
152:                gciSurfaceInfo = gciSurface.getSurfaceInfo();
153:                if (gciSurfaceInfo == null) {
154:                    throw new RuntimeException(
155:                            "Unable to get surface information");
156:                }
157:
158:                offset = gciSurfaceInfo.getBitOffset() >> bitsToPixelsShift;
159:                scanlineStride = gciSurfaceInfo.getYBitStride() >> bitsToPixelsShift;
160:                pixelStride = gciSurfaceInfo.getXBitStride() >> bitsToPixelsShift;
161:
162:                if (gciSurface.isNativeSurface()) {
163:                    typeOfArray = TYPE_OF_ARRAY_NATIVE;
164:                    nativeArray = gciSurfaceInfo.getBasePointer();
165:                } else {
166:                    switch (gciSurfaceInfo.getPixelArrayType()) {
167:                    case GCISurfaceInfo.TYPE_JAVA_ARRAY_INT:
168:                        javaArrayInt = (int[]) gciSurfaceInfo.getPixelArray();
169:                        typeOfArray = TYPE_OF_ARRAY_JAVA_INT;
170:                        break;
171:                    case GCISurfaceInfo.TYPE_JAVA_ARRAY_SHORT:
172:                        javaArrayShort = (short[]) gciSurfaceInfo
173:                                .getPixelArray();
174:                        typeOfArray = TYPE_OF_ARRAY_JAVA_SHORT;
175:                        break;
176:                    case GCISurfaceInfo.TYPE_JAVA_ARRAY_BYTE:
177:                        javaArrayByte = (byte[]) gciSurfaceInfo.getPixelArray();
178:                        typeOfArray = TYPE_OF_ARRAY_JAVA_BYTE;
179:                        break;
180:                    default:
181:                        break;
182:                    }
183:                }
184:            }
185:
186:            /** 
187:             * Detaches (releases) underlying GCIDrawing surface and resets Pisces
188:             * native surface structures. No rendering is possible after 
189:             * releaseSurface().     
190:             */
191:            public void releaseSurface() {
192:                if (gciSurfaceInfo != null) {
193:                    // allow garbage collection
194:                    javaArrayByte = null;
195:                    javaArrayInt = null;
196:                    javaArrayShort = null;
197:
198:                    nativeArray = 0;
199:
200:                    gciSurfaceInfo.release();
201:                    gciSurfaceInfo = null;
202:                }
203:            }
204:
205:            /**
206:             * This method initializes (C-native-code) underlying pisces 
207:             * surface/renderer structures. 
208:             * @see JPiscesGCISurface.c source on details.    
209:             */
210:            private native void initialize(int imageType, int width,
211:                    int height, boolean isDynamic);
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.