author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 15 Sep 2010 12:05:25 +0300 | |
branch | RCL_3 |
changeset 77 | 7cee158cb8cd |
parent 66 | 2455ef1f5bbc |
child 83 | 26b2b12093af |
permissions | -rw-r--r-- |
66 | 1 |
/* |
2 |
* Copyright (c) 1999 - 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
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 javax.microedition.lcdui; |
|
20 |
||
21 |
import java.util.Hashtable; |
|
22 |
import java.util.Vector; |
|
23 |
import java.util.Enumeration; |
|
24 |
import java.io.IOException; |
|
25 |
import java.io.InputStream; |
|
26 |
||
27 |
import com.nokia.mj.impl.rt.legacy.LegacyRtPort; |
|
28 |
import com.nokia.mj.impl.rt.legacy.LegacySupport; |
|
29 |
import com.nokia.mj.impl.rt.legacy.MIDEventServer; |
|
30 |
import com.nokia.mj.impl.rt.legacy.NativeError; |
|
31 |
import com.nokia.mj.impl.rt.legacy.ToolkitObserver; |
|
32 |
import com.nokia.mj.impl.rt.legacy.ToolkitObserverNGAExtension; |
|
33 |
||
34 |
import com.nokia.mj.impl.rt.support.ApplicationUtils; |
|
35 |
import com.nokia.mj.impl.rt.support.ApplicationInfo; |
|
36 |
import com.nokia.mj.impl.rt.support.Finalizer; |
|
37 |
import com.nokia.mj.impl.rt.support.ShutdownListener; |
|
38 |
import com.nokia.mj.impl.utils.Logger; |
|
39 |
||
40 |
final class Toolkit |
|
41 |
{ |
|
42 |
static |
|
43 |
{ |
|
44 |
com.nokia.mj.impl.rt.support.Jvm.loadSystemLibrary("javalcdui"); |
|
45 |
DirectGraphicsInvoker.createInvoker(); |
|
46 |
FreeSizeFontInvoker.createInvoker(); |
|
47 |
LcduiPropertyInvoker.createInvoker(); |
|
48 |
CanvasGraphicsItemPainterInvoker.createInvoker(); |
|
49 |
} |
|
50 |
||
51 |
private Finalizer mFinalizer = new Finalizer() |
|
52 |
{ |
|
53 |
public void finalizeImpl() |
|
54 |
{ |
|
55 |
doFinalize(); |
|
56 |
} |
|
57 |
}; |
|
58 |
// |
|
59 |
private static final String SERVER_NAME = "javax.microedition.lcdui"; |
|
60 |
private static final String DEFAULT_MIDLET_NAME = "MIDlet "; |
|
61 |
private static final int DEFAULT_MIDLET_UID = 0x101F9515; |
|
62 |
||
63 |
// NGA specific change. |
|
64 |
// Java side doesn't support native (c++) style macro flags and |
|
65 |
// that is why Toolkit & ToolkitInvoker have been harnessed to substitutes |
|
66 |
// NGA flag & its index |
|
67 |
static final int FLAG_NONE = 0; |
|
68 |
static final int FLAG_NGA_INDEX = 0; |
|
69 |
static final int FLAG_NGA = 1 << FLAG_NGA_INDEX; |
|
70 |
// Defines total flag count. Must be keep up to date. |
|
71 |
private static final int FLAG_COUNT = 1; |
|
72 |
||
73 |
private static final String RESOURCE_OR_PLUGIN_NOT_FOUND = |
|
74 |
"Cannot find lcdui dll, or lcdgr dll or lcdui resource file"; |
|
75 |
||
76 |
// |
|
77 |
private static int iServerCount; |
|
78 |
||
79 |
private ToolkitInvoker iInvoker; |
|
80 |
private Object iDestroySync = new Object(); |
|
81 |
private static final int HANDLE_UNINITIALIZED = -0xfffffe; |
|
82 |
private int iHandle = HANDLE_UNINITIALIZED; |
|
83 |
private Device iDevice; |
|
84 |
private Display iDisplay; |
|
85 |
private Image iIcon; |
|
86 |
private MIDEventServer iEventServer; |
|
87 |
private Hashtable iFontCache; |
|
88 |
Buffer iBuffer; |
|
89 |
private Object iCallbackLock; |
|
90 |
||
91 |
private Vector iObservers; |
|
92 |
private boolean iStartingInBackground = false; |
|
93 |
protected Vector tmpDisplayables; //temporary Vector of created Displayables |
|
94 |
protected boolean activated = false; //events are dispatched only if Toolkit is active, see Toolkit.start() |
|
95 |
||
96 |
// NGA specific change |
|
97 |
private int iFlags = FLAG_NONE; |
|
98 |
||
99 |
// |
|
100 |
// Event source : must keep in sync with TSourceType in lcdui.h |
|
101 |
// |
|
102 |
private static final int ITEM = 3; |
|
103 |
private static final int DISPLAYABLE = 4; |
|
104 |
private static final int MIDLET = 5; |
|
105 |
private static final int SERIAL = 6; // deprecated |
|
106 |
private static final int CANVAS_GRAPHICS_ITEM_PAINTER = 7; |
|
107 |
||
108 |
// |
|
109 |
// Event type : must keep in sync with TEventType in lcdui.h |
|
110 |
// |
|
111 |
static final int EVENT_PAINT = 10; |
|
112 |
static final int EVENT_KEY_PRESSED = 11; |
|
113 |
static final int EVENT_KEY_RELEASED = 12; |
|
114 |
static final int EVENT_KEY_REPEATED = 13; |
|
115 |
static final int EVENT_POINTER_PRESSED = 14; |
|
116 |
static final int EVENT_POINTER_RELEASED = 15; |
|
117 |
static final int EVENT_POINTER_DRAGGED = 16; |
|
118 |
static final int EVENT_SIZE_CHANGED = 17; |
|
119 |
||
120 |
static final int EVENT_EXIT_REQUESTED = 18; |
|
121 |
static final int EVENT_FOREGROUND = 19; |
|
122 |
static final int EVENT_BACKGROUND = 20; |
|
123 |
static final int EVENT_PAUSE_REQUESTED = 21; |
|
124 |
static final int EVENT_START_REQUESTED = 22; |
|
125 |
static final int EVENT_DESTROY_REQUESTED = 23; |
|
126 |
static final int EVENT_COMMAND = 24; |
|
127 |
static final int EVENT_VISIBLE = 25; |
|
128 |
static final int EVENT_TRAVERSE = 26; |
|
129 |
static final int EVENT_SET_CURRENT = 29; |
|
130 |
static final int EVENT_SERIAL = 30; |
|
131 |
||
132 |
static final int EVET_CANVAS_GRAPHICS_ITEM_REPAINT = 31; |
|
133 |
static final int EVENT_M3G_DRAW = 32 ; |
|
134 |
static final int EVENT_FORCED_PAINT = 33; |
|
135 |
static final int EVENT_FREE_GPU_MEMORY = 34; |
|
136 |
||
137 |
// IMPLICIT EVENT TYPES |
|
138 |
static final int EVENT_DISMISS = 0; // ALERT |
|
139 |
static final int EVENT_ITEM_CHANGED = 0; // ITEM(S) |
|
140 |
static final int EVENT_SELECT = 0; // LIST |
|
141 |
||
142 |
||
143 |
// |
|
144 |
// Op codes for syncing to screen |
|
145 |
// These must be kept in sync with MMIDCanvas::TDrawOp |
|
146 |
// |
|
147 |
private static final int SYNC = 0; |
|
148 |
private static final int SYNC_RECT = 1; |
|
149 |
||
150 |
// NGA specific change. |
|
151 |
// Op code indicating M3G content start |
|
152 |
private static final int M3G_CONTENT_START = 2; |
|
153 |
||
77
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
154 |
// Used for notifying native canvas about start of paint method, |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
155 |
// needed by video overlay implementation |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
156 |
private static final int PAINT_START = 3; |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
157 |
|
66 | 158 |
Toolkit(ToolkitInvoker aInvoker) |
159 |
{ |
|
160 |
iInvoker = aInvoker; |
|
161 |
tmpDisplayables = new Vector(); |
|
162 |
||
163 |
iStartingInBackground = iInvoker.iStartInBackGround; |
|
164 |
||
165 |
ApplicationUtils.getInstance().addShutdownListener(new ShutdownListener() |
|
166 |
{ |
|
167 |
public final void shuttingDown() |
|
168 |
{ |
|
169 |
dispose(); |
|
170 |
} |
|
171 |
}); |
|
172 |
||
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Initializes the Toolkit, if it is uninitialized. |
|
177 |
*/ |
|
178 |
private void ensureInitialized() |
|
179 |
{ |
|
180 |
if (iEventServer == null) |
|
181 |
{ |
|
182 |
initialize(); |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* Initializes the Toolkit. |
|
188 |
*/ |
|
189 |
synchronized private void initialize() |
|
190 |
{ |
|
191 |
if (iEventServer != null) |
|
192 |
{ |
|
193 |
return; |
|
194 |
} |
|
195 |
/** |
|
196 |
* get UI server instance number |
|
197 |
*/ |
|
198 |
final String serverNumber = getServerNumber(); |
|
199 |
||
200 |
/** |
|
201 |
* create mangled server name |
|
202 |
*/ |
|
203 |
final String serverName = SERVER_NAME.concat(serverNumber); |
|
204 |
||
205 |
ApplicationInfo appInfo = ApplicationInfo.getInstance(); |
|
206 |
String appName = appInfo.getLocalizedName(); |
|
207 |
if (null == appName) |
|
208 |
{ |
|
209 |
appName = DEFAULT_MIDLET_NAME.concat(serverNumber); |
|
210 |
} |
|
211 |
||
212 |
int appUid = LegacyRtPort.getMidletUid(); |
|
213 |
if (appUid == 0) |
|
214 |
{ |
|
215 |
appUid = DEFAULT_MIDLET_UID; |
|
216 |
} |
|
217 |
||
218 |
String appHome = appInfo.getRootPath(); |
|
219 |
if (appHome.endsWith("\\")) |
|
220 |
{ |
|
221 |
appHome = appHome.substring(0, appHome.length() - 1); |
|
222 |
} |
|
223 |
||
224 |
/** |
|
225 |
* Create native event server + thread. This will run until shutdown |
|
226 |
* in Toolkit.dispose(). |
|
227 |
*/ |
|
228 |
iEventServer = new UiEventServer(serverName, appUid); |
|
229 |
iCallbackLock = new Object(); |
|
230 |
||
231 |
final Hashtable properties = iInvoker.iMidletArgs; |
|
232 |
final String[] attributes = new String [properties.size() * 2]; |
|
233 |
int count = -1; |
|
234 |
for (final Enumeration keys = properties.keys(); keys.hasMoreElements();) |
|
235 |
{ |
|
236 |
final String key = (String)keys.nextElement(); |
|
237 |
attributes[++count] = key; |
|
238 |
attributes[++count] = (String)properties.get(key); |
|
239 |
} |
|
240 |
||
241 |
final int server = iEventServer.getHandle(); |
|
242 |
||
243 |
// NGA specific change. |
|
244 |
// Array that will be filled with native flag macros |
|
245 |
int[] flags = new int[Toolkit.FLAG_COUNT]; |
|
246 |
iHandle = _create(server, appName, appUid, appHome, attributes, flags); |
|
247 |
switch (iHandle) |
|
248 |
{ |
|
249 |
case NativeError.KErrNotFound: |
|
250 |
case NativeError.KErrPathNotFound: |
|
251 |
throw new RuntimeException(RESOURCE_OR_PLUGIN_NOT_FOUND); |
|
252 |
default: |
|
253 |
checkHandle(iHandle); // leaves if error |
|
254 |
break; |
|
255 |
} |
|
256 |
// NGA specific change. |
|
257 |
// Update flags |
|
258 |
if (flags[Toolkit.FLAG_NGA_INDEX] > 0) |
|
259 |
{ |
|
260 |
this.iFlags |= Toolkit.FLAG_NGA; |
|
261 |
} |
|
262 |
||
263 |
iDevice = new Device(this); |
|
264 |
iBuffer = new Buffer(this); |
|
265 |
iFontCache = new Hashtable(); |
|
266 |
||
267 |
} |
|
268 |
||
269 |
InputStream getResourceAsStream(String aResource) |
|
270 |
throws |
|
271 |
IOException |
|
272 |
{ |
|
273 |
return getClass().getResourceAsStream(aResource); |
|
274 |
} |
|
275 |
||
276 |
synchronized void start(Display aDisplay) |
|
277 |
{ |
|
278 |
ensureInitialized(); |
|
279 |
iDisplay = aDisplay; |
|
280 |
NativeError.check(_activate(iHandle)); |
|
281 |
activated = true; |
|
282 |
} |
|
283 |
||
284 |
private static synchronized String getServerNumber() |
|
285 |
{ |
|
286 |
return Integer.toString(++iServerCount); |
|
287 |
} |
|
288 |
||
289 |
/** |
|
290 |
* NGA specific change. |
|
291 |
* Check if flags are set. |
|
292 |
* @param flags Flags indexes |
|
293 |
* @return True if flags are on. |
|
294 |
* @since S60 9.2 |
|
295 |
*/ |
|
296 |
boolean checkFlags(int flags) |
|
297 |
{ |
|
298 |
return ((iFlags & flags) > 0); |
|
299 |
} |
|
300 |
||
301 |
public boolean isClosed() |
|
302 |
{ |
|
303 |
return ((iHandle != HANDLE_UNINITIALIZED) && |
|
304 |
(iHandle <= 0)); |
|
305 |
} |
|
306 |
||
307 |
public int getHandle() |
|
308 |
{ |
|
309 |
ensureInitialized(); |
|
310 |
if (isClosed()) |
|
311 |
{ |
|
312 |
throw new RuntimeException("Toolkit closed"); |
|
313 |
} |
|
314 |
return iHandle; |
|
315 |
} |
|
316 |
||
317 |
static Toolkit getToolkit() |
|
318 |
{ |
|
319 |
ToolkitInvoker invoker = (ToolkitInvoker)ToolkitInvoker.getToolkitInvoker(); |
|
320 |
return invoker.getCurrentToolkit(); |
|
321 |
} |
|
322 |
||
323 |
final Device getDevice() |
|
324 |
{ |
|
325 |
ensureInitialized(); |
|
326 |
return iDevice; |
|
327 |
} |
|
328 |
||
329 |
final Display getDisplay() |
|
330 |
{ |
|
331 |
ensureInitialized(); |
|
332 |
return iDisplay; |
|
333 |
} |
|
334 |
||
335 |
final Object getCallbackLock() |
|
336 |
{ |
|
337 |
ensureInitialized(); |
|
338 |
return iCallbackLock; |
|
339 |
} |
|
340 |
||
341 |
final Hashtable getFontCache() |
|
342 |
{ |
|
343 |
ensureInitialized(); |
|
344 |
return iFontCache; |
|
345 |
} |
|
346 |
||
347 |
final synchronized void addObserver(ToolkitObserver aObserver) |
|
348 |
{ |
|
349 |
if (aObserver == null) |
|
350 |
{ |
|
351 |
return; |
|
352 |
} |
|
353 |
||
354 |
if (iObservers == null) |
|
355 |
{ |
|
356 |
iObservers = new Vector(2); |
|
357 |
} |
|
358 |
||
359 |
if (!iObservers.contains(aObserver)) |
|
360 |
{ |
|
361 |
iObservers.addElement(aObserver); |
|
362 |
} |
|
363 |
} |
|
364 |
||
365 |
final synchronized void removeObserver(ToolkitObserver aObserver) |
|
366 |
{ |
|
367 |
if ((iObservers != null) && (aObserver != null)) |
|
368 |
{ |
|
369 |
iObservers.removeElement(aObserver); |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
/** |
|
374 |
* If toolkit is already disposed, then native object has already been deleted |
|
375 |
* aHandle can be null if exception thrown in the object's constructor (where the handle |
|
376 |
* is typically assigned |
|
377 |
*/ |
|
378 |
final synchronized void disposeObject(int aHandle) |
|
379 |
{ |
|
380 |
ensureInitialized(); |
|
381 |
||
382 |
if (aHandle == 0) |
|
383 |
{ |
|
384 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo, |
|
385 |
"disposeObject(" + aHandle + ") < ignoring NULL handle"); |
|
386 |
return; |
|
387 |
} |
|
388 |
||
389 |
if (iHandle <= 0) |
|
390 |
{ |
|
391 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo, |
|
392 |
"disposeObject(" + aHandle + ") < : Toolkit already closed!"); |
|
393 |
return; |
|
394 |
} |
|
395 |
||
396 |
// |
|
397 |
// Lock buffer for duration of dispose. |
|
398 |
// |
|
399 |
synchronized (iBuffer) |
|
400 |
{ |
|
401 |
iBuffer.sync(); |
|
402 |
_disposeObject(iHandle, aHandle); |
|
403 |
} |
|
404 |
||
405 |
} |
|
406 |
||
407 |
private void doFinalize() |
|
408 |
{ |
|
409 |
if (mFinalizer != null) |
|
410 |
{ |
|
411 |
registeredFinalize(); |
|
412 |
mFinalizer = null; |
|
413 |
} |
|
414 |
} |
|
415 |
||
416 |
void registeredFinalize() |
|
417 |
{ |
|
418 |
dispose(); |
|
419 |
} |
|
420 |
||
421 |
final synchronized void dispose() |
|
422 |
{ |
|
423 |
if ((iHandle == HANDLE_UNINITIALIZED) || (iHandle > 0)) |
|
424 |
{ |
|
425 |
// |
|
426 |
// Notify observers that toolkit is being destroyed. |
|
427 |
// |
|
428 |
if (null != iObservers) |
|
429 |
{ |
|
430 |
final int lastIndex = iObservers.size() -1; |
|
431 |
for (int ii=lastIndex; ii>=0; ii--) |
|
432 |
{ |
|
433 |
final ToolkitObserver observer = (ToolkitObserver)iObservers.elementAt(ii); |
|
434 |
try |
|
435 |
{ |
|
436 |
observer.destroyNotify(); |
|
437 |
} |
|
438 |
catch (Exception ex) |
|
439 |
{ |
|
440 |
Logger.ELOG(Logger.EJavaUI, |
|
441 |
"exception thrown in destroyNotify: ", ex); |
|
442 |
// close must complete otherwise could get panic, so ignore |
|
443 |
// any exception thrown by observers. |
|
444 |
} |
|
445 |
} |
|
446 |
} |
|
447 |
||
448 |
iInvoker.removeToolkit(); |
|
449 |
||
450 |
if (null != iDisplay) |
|
451 |
{ |
|
452 |
iDisplay.dispose(); |
|
453 |
iDisplay = null; |
|
454 |
} |
|
455 |
||
456 |
// |
|
457 |
// Close the graphics buffer if present. |
|
458 |
// |
|
459 |
if (null != iBuffer) |
|
460 |
{ |
|
461 |
synchronized (iBuffer) |
|
462 |
{ |
|
463 |
iBuffer.close(); |
|
464 |
} |
|
465 |
iBuffer = null; |
|
466 |
} |
|
467 |
||
468 |
if (iHandle > 0) |
|
469 |
{ |
|
470 |
_dispose(iHandle); |
|
471 |
iHandle = 0; |
|
472 |
} |
|
473 |
||
474 |
// |
|
475 |
// Shutdown the ui event thread. |
|
476 |
// |
|
477 |
if (iEventServer != null) |
|
478 |
{ |
|
479 |
iEventServer.shutdown(); |
|
480 |
} |
|
481 |
} |
|
482 |
} |
|
483 |
||
484 |
/* deprecated */ |
|
485 |
private void handleAsyncEvent(Object aSource, int aResult) |
|
486 |
{ |
|
487 |
((AsyncCall)aSource).complete(aResult); |
|
488 |
} |
|
489 |
||
490 |
private boolean resetThread() |
|
491 |
{ |
|
492 |
if (!isClosed()) |
|
493 |
{ |
|
494 |
return true; |
|
495 |
} |
|
496 |
return false; |
|
497 |
} |
|
498 |
||
499 |
private void handleItemEvent(Item aSource, int aEvent, int aParam0, int aParam1, int aParam2) |
|
500 |
{ |
|
501 |
if (resetThread()) |
|
502 |
{ |
|
503 |
aSource.handleEvent(aEvent, aParam0, aParam1, aParam2); |
|
504 |
} |
|
505 |
} |
|
506 |
||
507 |
private void handleDisplayableEvent(Displayable aSource, int aEvent, int aParam0, int aParam1, int aParam2) |
|
508 |
{ |
|
509 |
synchronized (iDestroySync) |
|
510 |
{ |
|
511 |
//S60 Modification ==> |
|
512 |
try |
|
513 |
{ |
|
514 |
if (resetThread()) |
|
515 |
{ |
|
516 |
aSource.handleEvent(aEvent, aParam0, aParam1); |
|
517 |
} |
|
518 |
} |
|
519 |
catch (Throwable t) |
|
520 |
{ |
|
521 |
String className = t.getClass().getName(); |
|
522 |
int index = className.lastIndexOf('.'); |
|
523 |
if (index != -1) |
|
524 |
{ |
|
525 |
className = className.substring(index + 1, className.length()); |
|
526 |
} |
|
527 |
String errStr= "Exception in handleDisplayableEvent. Reason: "+className+ |
|
528 |
"\n event is : "+aEvent+ |
|
529 |
"\n source is : "+aSource+"\n p0 is : "+aParam0+ |
|
530 |
"\n p1 is : "+aParam1+"\n p2 is : "+aParam2; |
|
531 |
Logger.ELOG(Logger.EJavaUI,errStr, t); |
|
532 |
||
533 |
//Removing Displayable if is exception thrown |
|
534 |
if (tmpDisplayables.contains(this)) |
|
535 |
{ |
|
536 |
tmpDisplayables.removeElement(this); |
|
537 |
} |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
||
542 |
private void handleDisplayEvent(Toolkit aToolkit, int aEvent, int aParam0, int aParam1, int aParam2) |
|
543 |
{ |
|
544 |
synchronized (iDestroySync) |
|
545 |
{ |
|
546 |
if (resetThread()) |
|
547 |
{ |
|
548 |
switch (aEvent) |
|
549 |
{ |
|
550 |
case EVENT_EXIT_REQUESTED: |
|
551 |
ApplicationUtils.getInstance().notifyExitCmd(); |
|
552 |
break; |
|
553 |
case EVENT_DESTROY_REQUESTED: |
|
554 |
ApplicationUtils.getInstance().notifyExitCmd(); |
|
555 |
break; |
|
556 |
case EVENT_PAUSE_REQUESTED: |
|
557 |
ApplicationUtils.getInstance().pauseApplication(); |
|
558 |
break; |
|
559 |
case EVENT_START_REQUESTED: |
|
560 |
ApplicationUtils.getInstance().resumeApplication(); |
|
561 |
break; |
|
562 |
case EVENT_FOREGROUND: |
|
563 |
iDisplay.handleForeground(true); |
|
564 |
break; |
|
565 |
case EVENT_BACKGROUND: |
|
566 |
iDisplay.handleForeground(false); |
|
567 |
notifyFreeGraphicsMemory(); |
|
568 |
break; |
|
569 |
case EVENT_SET_CURRENT: |
|
570 |
iDisplay.switchCurrent(); |
|
571 |
break; |
|
572 |
case EVENT_SERIAL: |
|
573 |
iDisplay.processSerialEvents(); |
|
574 |
break; |
|
575 |
case EVENT_FREE_GPU_MEMORY: |
|
576 |
notifyFreeGraphicsMemory(); |
|
577 |
break; |
|
578 |
default: |
|
579 |
throw new IllegalArgumentException(); |
|
580 |
} |
|
581 |
} |
|
582 |
} |
|
583 |
} |
|
584 |
||
585 |
private synchronized void notifyFreeGraphicsMemory() |
|
586 |
{ |
|
587 |
if (null != iObservers) |
|
588 |
{ |
|
589 |
final int lastIndex = iObservers.size() - 1; |
|
590 |
for (int ii=lastIndex; ii>=0; ii--) |
|
591 |
{ |
|
592 |
if (iObservers.elementAt(ii) instanceof ToolkitObserverNGAExtension) |
|
593 |
{ |
|
594 |
final ToolkitObserverNGAExtension observer = |
|
595 |
(ToolkitObserverNGAExtension)iObservers.elementAt(ii); |
|
596 |
observer.freeGraphicsMemory(); |
|
597 |
} |
|
598 |
} |
|
599 |
} |
|
600 |
} |
|
601 |
||
602 |
private void handleCanvasGraphicsItemPainterEvent(CanvasGraphicsItemPainter aSource, int aEvent, int aParam0, int aParam1, int aParam2) |
|
603 |
{ |
|
604 |
if (resetThread()) |
|
605 |
{ |
|
606 |
aSource.handleEvent(aEvent, aParam0, aParam1); |
|
607 |
} |
|
608 |
} |
|
609 |
||
610 |
synchronized void setForeground(boolean aForeground) |
|
611 |
{ |
|
612 |
if (iStartingInBackground) |
|
613 |
{ |
|
614 |
NativeError.check(_setForeground(getHandle(), false)); |
|
615 |
iStartingInBackground = false; |
|
616 |
} |
|
617 |
else |
|
618 |
{ |
|
619 |
NativeError.check(_setForeground(getHandle(), aForeground)); |
|
620 |
} |
|
621 |
} |
|
622 |
||
623 |
/** |
|
624 |
* blocks until all drawing complete |
|
625 |
*/ |
|
626 |
void sync() |
|
627 |
{ |
|
628 |
ensureInitialized(); |
|
629 |
synchronized (iBuffer) |
|
630 |
{ |
|
631 |
iBuffer.sync(); |
|
632 |
} |
|
633 |
} |
|
634 |
||
635 |
/* |
|
636 |
* NGA specific change. |
|
637 |
* Adds m3g content start op code to buffer, |
|
638 |
* if Graphics's target is Canvas. |
|
639 |
* The buffer is synchronized in any case. |
|
640 |
* @param aGraphics Graphics instance |
|
641 |
* @see ToolkitInvoker#toolkitSync(Object, Object) |
|
642 |
* @since S60 9.2 |
|
643 |
*/ |
|
644 |
void sync(Object aObject) |
|
645 |
{ |
|
646 |
ensureInitialized(); |
|
647 |
Graphics graphics = (Graphics)aObject; |
|
648 |
if (checkFlags(FLAG_NGA) && |
|
649 |
graphics != null && |
|
650 |
graphics.iTarget instanceof Canvas) |
|
651 |
{ |
|
652 |
Canvas canvas = (Canvas)graphics.iTarget; |
|
653 |
canvas.setM3GContent(true); |
|
654 |
synchronized (iBuffer) |
|
655 |
{ |
|
656 |
iBuffer.write(canvas.getContentHandle(), M3G_CONTENT_START); |
|
657 |
iBuffer.sync(); |
|
658 |
} |
|
659 |
} |
|
660 |
else |
|
661 |
{ |
|
662 |
sync(); |
|
663 |
} |
|
664 |
} |
|
665 |
||
666 |
/** |
|
667 |
* Write buffer command which when processed will draw to screen. |
|
668 |
* Used by Canvas and CustomItem. |
|
669 |
*/ |
|
670 |
void sync(int aDrawable) |
|
671 |
{ |
|
672 |
ensureInitialized(); |
|
673 |
synchronized (iBuffer) |
|
674 |
{ |
|
675 |
iBuffer.write(aDrawable, SYNC); |
|
676 |
iBuffer.sync(); |
|
677 |
} |
|
678 |
} |
|
679 |
||
680 |
/** |
|
681 |
* Write buffer command which when processed will draw to screen. |
|
682 |
* Used by Canvas and CustomItem. |
|
683 |
*/ |
|
684 |
void sync(int aDrawable, int aX, int aY, int aW, int aH) |
|
685 |
{ |
|
686 |
ensureInitialized(); |
|
687 |
synchronized (iBuffer) |
|
688 |
{ |
|
689 |
final int x2=aX+aW; |
|
690 |
final int y2=aY+aH; |
|
691 |
iBuffer.write(aDrawable, SYNC_RECT, aX, aY, x2, y2); |
|
692 |
iBuffer.sync(); |
|
693 |
} |
|
694 |
} |
|
695 |
||
77
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
696 |
void canvasPaintStarted(int aDrawable) |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
697 |
{ |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
698 |
if (checkFlags(FLAG_NGA)) |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
699 |
{ |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
700 |
synchronized (iBuffer) |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
701 |
{ |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
702 |
iBuffer.write(aDrawable, PAINT_START); |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
703 |
} |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
704 |
} |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
705 |
} |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
706 |
|
66 | 707 |
/** |
708 |
JSR 135 Support |
|
709 |
*/ |
|
710 |
final int getEventServerHandle() |
|
711 |
{ |
|
712 |
ensureInitialized(); |
|
713 |
return iEventServer.getHandle(); |
|
714 |
} |
|
715 |
||
716 |
void postEvent(int aEvent) |
|
717 |
{ |
|
718 |
NativeError.check(_postEvent(getHandle(), 0, MIDLET, aEvent)); |
|
719 |
} |
|
720 |
||
721 |
void postEvent(Item aItem, int aEvent) |
|
722 |
{ |
|
723 |
NativeError.check(_postEvent(getHandle(), aItem.getHandle(), ITEM, aEvent)); |
|
724 |
} |
|
725 |
||
726 |
void postEvent(Displayable aDisplayable, int aEvent) |
|
727 |
{ |
|
728 |
NativeError.check(_postEvent(getHandle(), aDisplayable.getContainerHandle(), DISPLAYABLE, aEvent)); |
|
729 |
} |
|
730 |
||
731 |
void postEvent(CanvasGraphicsItemPainter aCanvasGraphicsItem, int aEvent) |
|
732 |
{ |
|
733 |
NativeError.check(_postEvent(getHandle(), aCanvasGraphicsItem.getHandle(), CANVAS_GRAPHICS_ITEM_PAINTER, aEvent)); |
|
734 |
} |
|
735 |
||
736 |
static int checkHandle(int aHandle) |
|
737 |
{ |
|
738 |
if (NativeError.check(aHandle) == 0) |
|
739 |
{ |
|
740 |
throw new OutOfMemoryError(); |
|
741 |
} |
|
742 |
return aHandle; |
|
743 |
} |
|
744 |
||
745 |
/** |
|
746 |
* NGA specific change. |
|
747 |
* Create native peer on server thread reference by aContext. |
|
748 |
* @param aFlags The array that is filled according to native |
|
749 |
* side's macro definitions |
|
750 |
*/ |
|
751 |
native int _create( |
|
752 |
int aContext,String aName, int aUid, String aHomeDir, String[] aAttributes, int[] aFlags); |
|
753 |
||
754 |
/** |
|
755 |
* Open toolkit - enable events. |
|
756 |
*/ |
|
757 |
native int _activate(int aToolkit); |
|
758 |
||
759 |
/** |
|
760 |
* Delete toolkit - invalidates handle so no remaining threads must be |
|
761 |
* holding the toolkit handle. |
|
762 |
*/ |
|
763 |
native void _dispose(int aToolkit); |
|
764 |
||
765 |
/** |
|
766 |
* Deletion native UI object with handle aObject |
|
767 |
*/ |
|
768 |
native void _disposeObject(int aToolkit,int aObject); |
|
769 |
||
770 |
native int _postEvent(int aToolkit, int aSource, int aType, int aEvent); |
|
771 |
native int _setCurrent(int aToolkit,int aDisplayable); |
|
772 |
native int _setForeground(int aToolkit, boolean aForeground); |
|
773 |
} |