82 |
82 |
83 static final int OPAQUE_ALPHA = 0xff000000; |
83 static final int OPAQUE_ALPHA = 0xff000000; |
84 |
84 |
85 static final int COMPONENT_MASK = 0xFF; |
85 static final int COMPONENT_MASK = 0xFF; |
86 |
86 |
|
87 /** |
|
88 * Constants for sync strategy |
|
89 */ |
|
90 static final int SYNC_LEAVE_SURFACE_SESSION_CLOSED = 10; |
|
91 static final int SYNC_LEAVE_SURFACE_SESSION_OPEN = 11; |
|
92 |
|
93 // Set default sync strategy as closed |
|
94 private int syncStrategy = SYNC_LEAVE_SURFACE_SESSION_CLOSED; |
|
95 |
87 private DirectGraphics directGraphics; |
96 private DirectGraphics directGraphics; |
88 private Buffer graphicsBuffer; |
97 private Buffer graphicsBuffer; |
89 |
|
90 // Off-screen buffer. |
|
91 //private org.eclipse.swt.internal.qt.graphics.Image frameBuffer; |
|
92 |
98 |
93 // Current font for rendering texts. |
99 // Current font for rendering texts. |
94 Font currentFont; |
100 Font currentFont; |
95 int currentColor; |
101 int currentColor; |
96 int translateX; |
102 int translateX; |
97 int translateY; |
103 int translateY; |
98 int[] currentClip = new int[4]; |
104 int[] currentClip = new int[4]; |
99 int currentStrokeSyle; |
105 int currentStrokeStyle; |
100 |
106 |
101 private com.nokia.mj.impl.rt.support.Finalizer finalizer; |
107 private com.nokia.mj.impl.rt.support.Finalizer finalizer; |
102 // serialization lock for command buffering and flush |
|
103 private final Object flushLock = new Object(); |
|
104 private Canvas canvasParent; |
|
105 private CustomItem customItemParent; |
|
106 |
108 |
107 //Constructor |
109 //Constructor |
108 Graphics(Buffer buffer) |
110 Graphics(Buffer buffer, Rectangle clipRect) |
109 { |
111 { |
110 finalizer = ((finalizer != null) ? finalizer |
112 finalizer = ((finalizer != null) ? finalizer |
111 : new com.nokia.mj.impl.rt.support.Finalizer() |
113 : new com.nokia.mj.impl.rt.support.Finalizer() |
112 { |
114 { |
113 public void finalizeImpl() |
115 public void finalizeImpl() |
149 /** |
155 /** |
150 * Resets Graphics state to initial. |
156 * Resets Graphics state to initial. |
151 */ |
157 */ |
152 void reset() |
158 void reset() |
153 { |
159 { |
154 setColor(0, 0, 0); |
160 currentFont = Buffer.defaultFont; |
155 setFont(Font.getDefaultFont()); |
161 currentColor = Buffer.defaultColor; |
156 setStrokeStyle(Graphics.SOLID); |
162 currentStrokeStyle = Buffer.defaultStrokeStyle; |
157 this.translateX = 0; |
163 translateX = Buffer.defaultTranslateX; |
158 this.translateY = 0; |
164 translateY = Buffer.defaultTranslateY; |
159 } |
165 } |
160 |
166 |
161 /** |
167 /** |
162 * Cleans the Canvas background. |
168 * Cleans the Canvas background. |
163 */ |
169 */ |
178 setColor(255, 255, 255); |
184 setColor(255, 255, 255); |
179 fillRect(x, y, w, h); |
185 fillRect(x, y, w, h); |
180 setColor(savedColor); |
186 setColor(savedColor); |
181 } |
187 } |
182 |
188 |
183 |
189 /** |
|
190 * Sets the sync strategy for this instance. |
|
191 * This affects on the behavior of the sync method of this class |
|
192 * which is called via LCDUIInvoker |
|
193 */ |
|
194 void setSyncStrategy(int strategy) |
|
195 { |
|
196 if((strategy != SYNC_LEAVE_SURFACE_SESSION_CLOSED) && (strategy != SYNC_LEAVE_SURFACE_SESSION_OPEN)) |
|
197 { |
|
198 throw new IllegalArgumentException("Internal: Invalid strategy value"); |
|
199 } |
|
200 syncStrategy = strategy; |
|
201 } |
184 |
202 |
185 /** |
203 /** |
186 * Sets coordinate translation. Translations are cumulative. |
204 * Sets coordinate translation. Translations are cumulative. |
187 * |
205 * |
188 * @param xDelta x-shift for coordinates. |
206 * @param xDelta x-shift for coordinates. |
853 x = xPos - image.getWidth(); |
871 x = xPos - image.getWidth(); |
854 } |
872 } |
855 |
873 |
856 synchronized(image.graphicsBuffer) |
874 synchronized(image.graphicsBuffer) |
857 { |
875 { |
858 image.sync(); |
876 final Image localLcduiImage = image; |
859 graphicsBuffer.drawImage(Internal_GfxPackageSupport.getImage(Image.getESWTImage(image)), x, y, this); |
877 final org.eclipse.swt.internal.qt.graphics.Image localCgfxImage = |
|
878 Internal_GfxPackageSupport.getImage(Image.getESWTImage(image)); |
|
879 final int localX = x; |
|
880 final int localY = y; |
|
881 final Graphics self = this; |
|
882 |
|
883 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
|
884 { |
|
885 public void run() |
|
886 { |
|
887 localLcduiImage.sync(false); |
|
888 graphicsBuffer.drawImage(localCgfxImage, localX, localY, self); |
|
889 } |
|
890 }); |
|
891 |
860 } |
892 } |
861 } |
893 } |
862 } |
894 } |
863 |
895 |
864 /** |
896 /** |
921 { |
953 { |
922 throw new IllegalArgumentException( |
954 throw new IllegalArgumentException( |
923 MsgRepository.GRAPHICS_EXCEPTION_ILLEGAL_STROKE_STYLE); |
955 MsgRepository.GRAPHICS_EXCEPTION_ILLEGAL_STROKE_STYLE); |
924 } |
956 } |
925 graphicsBuffer.setStrokeStyle(styleToApply, newStyle, this); |
957 graphicsBuffer.setStrokeStyle(styleToApply, newStyle, this); |
926 currentStrokeSyle = newStyle; |
958 currentStrokeStyle = newStyle; |
927 } |
959 } |
928 } |
960 } |
929 |
961 |
930 /** |
962 /** |
931 * Returns current stroke style. |
963 * Returns current stroke style. |
1148 x = xDst - srcImage.getWidth(); |
1180 x = xDst - srcImage.getWidth(); |
1149 } |
1181 } |
1150 final int gcTransform = Image.getCgTransformValue(transform); |
1182 final int gcTransform = Image.getCgTransformValue(transform); |
1151 synchronized(srcImage.graphicsBuffer) |
1183 synchronized(srcImage.graphicsBuffer) |
1152 { |
1184 { |
1153 srcImage.sync(); |
1185 final Image localLcduiSrcImage = srcImage; |
1154 graphicsBuffer.drawImage(Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage)), |
1186 final org.eclipse.swt.internal.qt.graphics.Image localCgfxImage = |
1155 x, y, width, height, xSrc, ySrc, width, height, gcTransform, this); |
1187 Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage)); |
1156 } |
1188 final int localX = x; |
1157 } |
1189 final int localY = y; |
1158 } |
1190 final int localW = width; |
1159 |
1191 final int localH = height; |
|
1192 final int localXSrc = xSrc; |
|
1193 final int localYSrc = ySrc; |
|
1194 final int localGcTransform = gcTransform; |
|
1195 final Graphics self = this; |
|
1196 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
|
1197 { |
|
1198 public void run() |
|
1199 { |
|
1200 localLcduiSrcImage.sync(false); |
|
1201 graphicsBuffer.drawImage(localCgfxImage, |
|
1202 localX, localY, localW, localH, localXSrc, localYSrc, localW, localH, localGcTransform, self); |
|
1203 } |
|
1204 }); |
|
1205 } |
|
1206 } |
|
1207 } |
|
1208 |
|
1209 /** |
|
1210 * Performs synchronization on the graphics buffer, i.e. |
|
1211 * the buffered draw commands are rasterized to the surface. |
|
1212 */ |
|
1213 void sync() |
|
1214 { |
|
1215 synchronized(graphicsBuffer) |
|
1216 { |
|
1217 if(syncStrategy == SYNC_LEAVE_SURFACE_SESSION_OPEN) |
|
1218 { |
|
1219 // This instance is used only with paint callbacks, thus |
|
1220 // sync is called with the indication that surface paint |
|
1221 // session can be left open as it will be closed when the |
|
1222 // callback returns. |
|
1223 graphicsBuffer.sync(false); |
|
1224 } |
|
1225 else |
|
1226 { |
|
1227 graphicsBuffer.sync(true); |
|
1228 } |
|
1229 } |
|
1230 } |
|
1231 |
|
1232 |
1160 /** |
1233 /** |
1161 * Return DirectGraphics associated with this instance. |
1234 * Return DirectGraphics associated with this instance. |
1162 */ |
1235 */ |
1163 DirectGraphics getDirectGraphics() |
1236 DirectGraphics getDirectGraphics() |
1164 { |
1237 { |
1167 directGraphics = new DirectGraphicsImpl(this); |
1240 directGraphics = new DirectGraphicsImpl(this); |
1168 } |
1241 } |
1169 return directGraphics; |
1242 return directGraphics; |
1170 } |
1243 } |
1171 |
1244 |
|
1245 /** |
|
1246 * Getter for graphics buffer. |
|
1247 * @return The Buffer. |
|
1248 */ |
|
1249 Buffer getGraphicsBuffer() |
|
1250 { |
|
1251 return graphicsBuffer; |
|
1252 } |
|
1253 |
1172 /** |
1254 /** |
1173 * Maps stroke style constant from values used by |
1255 * Maps stroke style constant from values used by |
1174 * Graphics to values defined in GraphicsContext |
1256 * Graphics to values defined in GraphicsContext |
1175 */ |
1257 */ |
1176 static int mapStrokeStyle(int strokeStyle) |
1258 static int mapStrokeStyle(int strokeStyle) |