80
|
1 |
/*
|
87
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
80
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
package com.nokia.microedition.m2g;
|
|
20 |
|
|
21 |
import com.nokia.microedition.m2g.M2GRunnableQt;
|
|
22 |
import javax.microedition.m2g.*;
|
|
23 |
import javax.microedition.m2g.ScalableGraphics;
|
|
24 |
import javax.microedition.lcdui.Graphics;
|
|
25 |
import java.lang.StringBuffer;
|
|
26 |
import org.eclipse.swt.graphics.GC;
|
|
27 |
import org.eclipse.swt.graphics.Rectangle;
|
|
28 |
import com.nokia.mj.impl.utils.Logger;
|
|
29 |
import com.nokia.mj.impl.nokialcdui.LCDUIInvoker;
|
|
30 |
import org.eclipse.swt.internal.qt.GCData;
|
|
31 |
import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
|
87
|
32 |
import org.eclipse.swt.internal.extension.GraphicsUtil;
|
80
|
33 |
|
|
34 |
/*
|
|
35 |
* ScalableGraphics
|
|
36 |
*/
|
|
37 |
public class M2GScalableGraphics
|
|
38 |
extends M2GObject
|
|
39 |
{
|
|
40 |
//--------------------------------------------------
|
|
41 |
// STATIC CONSTANTS
|
|
42 |
//--------------------------------------------------
|
87
|
43 |
|
80
|
44 |
// Transparency alpha max and min limits
|
|
45 |
private static final float MAX_TRANSPARENCY_ALPHA = 1.0f;
|
|
46 |
private static final float MIN_TRANSPARENCY_ALPHA = 0.0f;
|
|
47 |
|
|
48 |
//--------------------------------------------------
|
|
49 |
// VARIABLES
|
|
50 |
//--------------------------------------------------
|
|
51 |
private GC iTargetGC = null;
|
|
52 |
private int iUseNativeClear = 0;
|
|
53 |
private Graphics iTargetGraphics;
|
|
54 |
private Rectangle iSurfaceRectangle;
|
|
55 |
private Rectangle iFinalESWTSurfaceRectangle;
|
87
|
56 |
|
|
57 |
int iSurfaceHandle;
|
80
|
58 |
|
|
59 |
//--------------------------------------------------
|
|
60 |
// METHODS
|
|
61 |
//--------------------------------------------------
|
|
62 |
/**
|
|
63 |
* Constructor
|
|
64 |
*/
|
|
65 |
public M2GScalableGraphics()
|
|
66 |
{
|
|
67 |
super();
|
87
|
68 |
|
80
|
69 |
doConstruct();
|
|
70 |
}
|
|
71 |
/**
|
|
72 |
* @see javax.microedition.m2g.ScalableGraphics#bindTarget()
|
|
73 |
*/
|
|
74 |
public synchronized void bindTarget(Object target)
|
|
75 |
{
|
87
|
76 |
if (target == null)
|
|
77 |
{
|
|
78 |
throw new NullPointerException(/*SF*/"The target is null"/*SF*/);
|
|
79 |
}
|
|
80 |
|
|
81 |
if (target instanceof org.eclipse.swt.graphics.GC)
|
|
82 |
{
|
|
83 |
final GC finalGc = (GC)target;
|
|
84 |
|
|
85 |
// Execute in UI thread
|
|
86 |
Platform.executeInUIThread(
|
|
87 |
new M2GRunnableQt()
|
|
88 |
{
|
|
89 |
public void doRun()
|
|
90 |
{
|
|
91 |
iFinalESWTSurfaceRectangle = GraphicsUtil.startExternalRendering(finalGc);
|
|
92 |
|
|
93 |
// Get GCData from GC
|
|
94 |
iSurfaceHandle = GraphicsUtil.getWindowSurface(finalGc).getHandle();
|
|
95 |
_bind(getHandle(), iSurfaceHandle);
|
|
96 |
}
|
|
97 |
});
|
80
|
98 |
|
87
|
99 |
iTargetGC = (GC)finalGc;
|
|
100 |
// Handling for LCDUI Graphics
|
|
101 |
}
|
|
102 |
else if (target instanceof javax.microedition.lcdui.Graphics)
|
|
103 |
{
|
|
104 |
Graphics g = (Graphics)target;
|
|
105 |
final Graphics finalG = g;
|
|
106 |
iSurfaceRectangle = LCDUIInvoker.startExternalRendering(finalG);
|
|
107 |
// Execute in UI thread
|
|
108 |
Platform.executeInUIThread(
|
|
109 |
new M2GRunnableQt()
|
|
110 |
{
|
|
111 |
public void doRun()
|
|
112 |
{
|
80
|
113 |
|
87
|
114 |
iSurfaceHandle = LCDUIInvoker.getWindowSurface(finalG).getHandle();
|
|
115 |
|
|
116 |
// Flush Canvas
|
|
117 |
//M2GManager.flushDisplayBuffer();
|
|
118 |
_bind(getHandle(), iSurfaceHandle);
|
|
119 |
}
|
|
120 |
});
|
80
|
121 |
|
87
|
122 |
iTargetGraphics = (Graphics)finalG;
|
|
123 |
}
|
|
124 |
|
|
125 |
else
|
|
126 |
{
|
|
127 |
throw new IllegalArgumentException();
|
|
128 |
}
|
|
129 |
}
|
80
|
130 |
|
|
131 |
/**
|
|
132 |
* @see com.nokia.microedition.m2g.M2GObject#doConstruct()
|
|
133 |
*/
|
|
134 |
public void doConstruct()
|
|
135 |
{
|
87
|
136 |
super.doConstruct();
|
|
137 |
|
|
138 |
// Execute in UI thread
|
|
139 |
Platform.executeInUIThread(
|
|
140 |
new M2GRunnableQt()
|
|
141 |
{
|
|
142 |
public void doRun()
|
|
143 |
{
|
|
144 |
setHandle(_createRenderContext(
|
|
145 |
getNativeSVGProxyHandle()));
|
|
146 |
// Add object to the live objects container
|
|
147 |
}
|
|
148 |
});
|
80
|
149 |
register(this);
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
* @see com.nokia.microedition.m2g.M2GObject#doCleanup()
|
|
154 |
*/
|
|
155 |
public synchronized void doCleanup()
|
|
156 |
{
|
87
|
157 |
|
|
158 |
// Execute in UI thread
|
|
159 |
Platform.executeInUIThread(
|
|
160 |
new M2GRunnableQt()
|
|
161 |
{
|
|
162 |
public void doRun()
|
|
163 |
{
|
|
164 |
_deleteRenderContext(
|
|
165 |
getHandle());
|
|
166 |
}
|
|
167 |
}
|
|
168 |
);
|
80
|
169 |
resetHandles();
|
|
170 |
iTargetGC = null;
|
|
171 |
iTargetGraphics = null;
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* @see javax.microedition.m2g.ScalableGraphics#releaseTarget()
|
|
176 |
*/
|
|
177 |
public synchronized void releaseTarget()
|
|
178 |
{
|
87
|
179 |
if (iTargetGC != null)
|
|
180 |
{
|
|
181 |
|
|
182 |
Platform.executeInUIThread(
|
|
183 |
new M2GRunnableQt()
|
|
184 |
{
|
|
185 |
public void doRun()
|
|
186 |
{
|
|
187 |
GraphicsUtil.endExternalRendering(iTargetGC);
|
|
188 |
_release(iSurfaceHandle, getHandle());
|
|
189 |
}
|
|
190 |
});
|
80
|
191 |
iTargetGC = null;
|
|
192 |
}
|
87
|
193 |
else if (iTargetGraphics != null)
|
|
194 |
{
|
|
195 |
final Graphics finalG = iTargetGraphics;
|
|
196 |
Platform.executeInUIThread(
|
|
197 |
new M2GRunnableQt()
|
|
198 |
{
|
|
199 |
public void doRun()
|
|
200 |
{
|
|
201 |
_release(iSurfaceHandle, getHandle());
|
|
202 |
}
|
|
203 |
});
|
|
204 |
LCDUIInvoker.endExternalRendering(iTargetGraphics);
|
|
205 |
|
|
206 |
iTargetGraphics = null;
|
80
|
207 |
}
|
87
|
208 |
else
|
|
209 |
{
|
80
|
210 |
throw new IllegalStateException(/*SF*/"Target is not bound"/*SF*/);
|
87
|
211 |
}
|
80
|
212 |
|
|
213 |
}
|
87
|
214 |
|
80
|
215 |
public synchronized void render(
|
|
216 |
int x, int y, ScalableImage image, boolean aUseNativeClear)
|
|
217 |
{
|
|
218 |
iUseNativeClear = aUseNativeClear ? 1 : 0;
|
|
219 |
render(x, y, image);
|
|
220 |
iUseNativeClear = 0;
|
87
|
221 |
|
80
|
222 |
}
|
|
223 |
|
|
224 |
/**
|
|
225 |
* @see javax.microedition.m2g.ScalableGraphics#render()
|
|
226 |
*/
|
|
227 |
public synchronized void render(int x, int y, ScalableImage image)
|
|
228 |
{
|
87
|
229 |
|
80
|
230 |
if (image == null)
|
|
231 |
{
|
|
232 |
Logger.ELOG(Logger.EJavaUI, "render() - exception: "
|
|
233 |
+ /*SF*/"The target is null"/*SF*/);
|
|
234 |
throw new NullPointerException(/*SF*/"The target is null"/*SF*/);
|
|
235 |
}
|
87
|
236 |
if (iTargetGC != null)
|
80
|
237 |
{
|
|
238 |
final M2GDocument finalDoc = (M2GDocument)((SVGImage)image).getDocument();
|
|
239 |
// Get synchronized svg image data
|
|
240 |
final int finalSvgW = image.getViewportWidth();
|
|
241 |
final int finalSvgH = image.getViewportHeight();
|
|
242 |
if ((finalSvgW == 0) || (finalSvgW == 0))
|
|
243 |
{
|
|
244 |
return;
|
|
245 |
}
|
87
|
246 |
|
80
|
247 |
Rectangle clipRect = iFinalESWTSurfaceRectangle;
|
87
|
248 |
|
80
|
249 |
final int finalClipX = clipRect.x;
|
|
250 |
final int finalClipY = clipRect.y;
|
|
251 |
final int finalClipW = clipRect.width;
|
|
252 |
final int finalClipH = clipRect.height;
|
87
|
253 |
|
|
254 |
|
80
|
255 |
// if none of the svg image is visible due to clipping then don't
|
|
256 |
// bother to call render
|
|
257 |
if ((x >= (finalClipX + finalClipW)) || (y >= (finalClipY + finalClipH)))
|
|
258 |
{
|
|
259 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
260 |
"render() - svg image isn't visible due to clipping");
|
|
261 |
return;
|
|
262 |
}
|
|
263 |
if (((x + finalSvgW) < finalClipX) || ((y + finalSvgW) < finalClipY))
|
|
264 |
{
|
|
265 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
266 |
"render() - svg image isn't visible due to clipping");
|
|
267 |
return;
|
|
268 |
}
|
87
|
269 |
|
|
270 |
|
|
271 |
final int finalX = x;
|
|
272 |
final int finalY = y;
|
|
273 |
|
|
274 |
// Execute in UI thread
|
|
275 |
Platform.executeInUIThread(
|
|
276 |
new M2GRunnableQt()
|
|
277 |
{
|
|
278 |
public void doRun()
|
|
279 |
{
|
|
280 |
|
|
281 |
final int[] finalData = _renderESWT(getHandle(),
|
|
282 |
finalDoc.getHandle(), finalX, finalY,
|
|
283 |
finalClipX, finalClipY, finalClipW, finalClipH, finalSvgW, finalSvgW,
|
|
284 |
finalDoc.getRootElement().getCurrentTime(),
|
|
285 |
iUseNativeClear);
|
80
|
286 |
|
87
|
287 |
int[] bitmapHandles;
|
|
288 |
bitmapHandles = new int[4];
|
|
289 |
for (int i = 0; i < 4; i++)
|
|
290 |
{
|
|
291 |
bitmapHandles[i] = finalData[i];
|
|
292 |
}
|
|
293 |
int[] renderData;
|
|
294 |
renderData = new int[6];
|
|
295 |
for (int i = 0; i < 6; i++)
|
|
296 |
{
|
|
297 |
renderData[i] = finalData[i+4];
|
|
298 |
}
|
80
|
299 |
|
87
|
300 |
}
|
|
301 |
});
|
|
302 |
|
80
|
303 |
}//if(true)
|
87
|
304 |
else if (iTargetGraphics != null)
|
|
305 |
{
|
|
306 |
|
|
307 |
|
80
|
308 |
final M2GDocument finalDoc = (M2GDocument)((SVGImage)image).getDocument();
|
|
309 |
// Get synchronized svg image data
|
|
310 |
final int finalSvgW = image.getViewportWidth();
|
|
311 |
final int finalSvgH = image.getViewportHeight();
|
|
312 |
if ((finalSvgW == 0) || (finalSvgH == 0))
|
87
|
313 |
{
|
|
314 |
|
80
|
315 |
return;
|
|
316 |
}
|
87
|
317 |
|
80
|
318 |
final int finalClipX = iSurfaceRectangle.x;
|
|
319 |
final int finalClipY = iSurfaceRectangle.y;
|
|
320 |
final int finalClipW = iSurfaceRectangle.width;
|
|
321 |
final int finalClipH = iSurfaceRectangle.height;
|
|
322 |
|
|
323 |
// if none of the svg image is visible due to clipping then don't
|
|
324 |
// bother to call render
|
|
325 |
if ((x >= (finalClipX + finalClipW)) || (y >= (finalClipY + finalClipH)))
|
|
326 |
{
|
|
327 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
328 |
"render() - svg image isn't visible due to clipping");
|
|
329 |
return;
|
|
330 |
}
|
|
331 |
if (((x + finalSvgW) < finalClipX) || ((y + finalSvgH) < finalClipY))
|
|
332 |
{
|
|
333 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
334 |
"render() - svg image isn't visible due to clipping");
|
|
335 |
return;
|
|
336 |
}
|
87
|
337 |
|
|
338 |
final int finalX = x;
|
|
339 |
final int finalY = y;
|
80
|
340 |
|
87
|
341 |
// Execute in UI thread
|
|
342 |
Platform.executeInUIThread(
|
|
343 |
new M2GRunnableQt()
|
|
344 |
{
|
|
345 |
public void doRun()
|
|
346 |
{
|
|
347 |
_renderLCDUI(getHandle(), finalDoc.getHandle(), finalX, finalY,
|
|
348 |
finalClipX, finalClipY, finalClipW, finalClipH, finalSvgW, finalSvgH,
|
|
349 |
finalDoc.getRootElement().getCurrentTime());
|
|
350 |
}
|
|
351 |
});
|
80
|
352 |
}
|
|
353 |
|
87
|
354 |
else
|
|
355 |
{
|
|
356 |
Logger.ELOG(Logger.EJavaUI, "render() - exception: "
|
|
357 |
+ /*SF*/"Target is not bound"/*SF*/);
|
|
358 |
throw new IllegalStateException(/*SF*/"Target is not bound"/*SF*/);
|
|
359 |
}
|
|
360 |
|
80
|
361 |
}
|
|
362 |
|
|
363 |
/**
|
|
364 |
* @see javax.microedition.m2g.ScalableGraphics#setRenderingQuality(int)
|
|
365 |
*/
|
|
366 |
public synchronized void setRenderingQuality(int mode)
|
|
367 |
{
|
|
368 |
if ((mode == ScalableGraphics.RENDERING_QUALITY_LOW) ||
|
|
369 |
(mode == ScalableGraphics.RENDERING_QUALITY_HIGH))
|
|
370 |
{
|
87
|
371 |
final int finalMode = mode;
|
|
372 |
// Execute in UI thread
|
|
373 |
Platform.executeInUIThread(
|
|
374 |
new M2GRunnableQt()
|
|
375 |
{
|
|
376 |
public void doRun()
|
|
377 |
{
|
|
378 |
_setRenderingQuality(getHandle(), finalMode);
|
|
379 |
}
|
|
380 |
});
|
80
|
381 |
}
|
|
382 |
else
|
|
383 |
{
|
|
384 |
Logger.ELOG(Logger.EJavaUI,
|
|
385 |
"setRenderingQuality() - exception: " + /*SF*/"The mode is invalid"/*SF*/);
|
|
386 |
throw new IllegalArgumentException(/*SF*/"The mode is invalid"/*SF*/);
|
|
387 |
}
|
|
388 |
}
|
|
389 |
|
|
390 |
/**
|
|
391 |
* @see javax.microedition.m2g.ScalableGraphics#setTransparency(float)
|
|
392 |
*/
|
|
393 |
public synchronized void setTransparency(float alpha)
|
|
394 |
{
|
|
395 |
if (alpha >= MIN_TRANSPARENCY_ALPHA && alpha <= MAX_TRANSPARENCY_ALPHA)
|
|
396 |
{
|
87
|
397 |
final float finalAlpha = alpha;
|
|
398 |
// Execute in UI thread
|
|
399 |
Platform.executeInUIThread(
|
|
400 |
new M2GRunnableQt()
|
|
401 |
{
|
|
402 |
public void doRun()
|
|
403 |
{
|
|
404 |
_setTransparency(getHandle(), finalAlpha);
|
|
405 |
}
|
|
406 |
}
|
|
407 |
);
|
80
|
408 |
}
|
|
409 |
else
|
|
410 |
{
|
|
411 |
Logger.ELOG(Logger.EJavaUI,
|
|
412 |
"setTransparency() - exception: " + /*SF*/"The alpha is out of range"/*SF*/);
|
|
413 |
throw new IllegalArgumentException(/*SF*/"The alpha is out of range"/*SF*/);
|
|
414 |
}
|
|
415 |
}
|
|
416 |
|
|
417 |
|
|
418 |
//--------------------------------------------------
|
|
419 |
// NATIVE METHODS
|
|
420 |
//--------------------------------------------------
|
|
421 |
private native int _bind(
|
|
422 |
int aRenderContextHandle, int aTargetHandle);
|
|
423 |
private native int _createRenderContext(
|
|
424 |
int aSVGProxyHandle);
|
|
425 |
private native void _deleteRenderContext(
|
|
426 |
int aRenderContextHandle);
|
|
427 |
private native int _release(
|
87
|
428 |
int aSurfaceHandle ,int aRenderContextHandle);
|
80
|
429 |
private native int _renderLCDUI(
|
87
|
430 |
int aRenderContextHandle, int aDocumentHandle,
|
80
|
431 |
int aX, int aY, int aClipX, int aClipY, int aClipW, int aClipH,
|
|
432 |
int aSvgW, int aSvgH, float aCurrentTime);
|
|
433 |
private native int[] _renderESWT(
|
87
|
434 |
int aRenderContextHandle, int aDocumentHandle,
|
80
|
435 |
int aX, int aY, int aClipX, int aClipY, int aClipW, int aClipH,
|
|
436 |
int aSvgW, int aSvgH, float aCurrentTime, int iUseNativeClear);
|
|
437 |
private native void _setRenderingQuality(
|
87
|
438 |
int aRenderContextHandle, int aMode);
|
80
|
439 |
private native void _setTransparency(
|
87
|
440 |
int aRenderContextHandle, float aAlpha);
|
80
|
441 |
}
|