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 |
|
|
154 |
Toolkit(ToolkitInvoker aInvoker)
|
|
155 |
{
|
|
156 |
iInvoker = aInvoker;
|
|
157 |
tmpDisplayables = new Vector();
|
|
158 |
|
|
159 |
iStartingInBackground = iInvoker.iStartInBackGround;
|
|
160 |
|
|
161 |
ApplicationUtils.getInstance().addShutdownListener(new ShutdownListener()
|
|
162 |
{
|
|
163 |
public final void shuttingDown()
|
|
164 |
{
|
|
165 |
dispose();
|
|
166 |
}
|
|
167 |
});
|
|
168 |
|
|
169 |
}
|
|
170 |
|
|
171 |
/**
|
|
172 |
* Initializes the Toolkit, if it is uninitialized.
|
|
173 |
*/
|
|
174 |
private void ensureInitialized()
|
|
175 |
{
|
|
176 |
if (iEventServer == null)
|
|
177 |
{
|
|
178 |
initialize();
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
|
182 |
/**
|
|
183 |
* Initializes the Toolkit.
|
|
184 |
*/
|
|
185 |
synchronized private void initialize()
|
|
186 |
{
|
|
187 |
if (iEventServer != null)
|
|
188 |
{
|
|
189 |
return;
|
|
190 |
}
|
|
191 |
/**
|
|
192 |
* get UI server instance number
|
|
193 |
*/
|
|
194 |
final String serverNumber = getServerNumber();
|
|
195 |
|
|
196 |
/**
|
|
197 |
* create mangled server name
|
|
198 |
*/
|
|
199 |
final String serverName = SERVER_NAME.concat(serverNumber);
|
|
200 |
|
|
201 |
ApplicationInfo appInfo = ApplicationInfo.getInstance();
|
|
202 |
String appName = appInfo.getLocalizedName();
|
|
203 |
if (null == appName)
|
|
204 |
{
|
|
205 |
appName = DEFAULT_MIDLET_NAME.concat(serverNumber);
|
|
206 |
}
|
|
207 |
|
|
208 |
int appUid = LegacyRtPort.getMidletUid();
|
|
209 |
if (appUid == 0)
|
|
210 |
{
|
|
211 |
appUid = DEFAULT_MIDLET_UID;
|
|
212 |
}
|
|
213 |
|
|
214 |
String appHome = appInfo.getRootPath();
|
|
215 |
if (appHome.endsWith("\\"))
|
|
216 |
{
|
|
217 |
appHome = appHome.substring(0, appHome.length() - 1);
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Create native event server + thread. This will run until shutdown
|
|
222 |
* in Toolkit.dispose().
|
|
223 |
*/
|
|
224 |
iEventServer = new UiEventServer(serverName, appUid);
|
|
225 |
iCallbackLock = new Object();
|
|
226 |
|
|
227 |
final Hashtable properties = iInvoker.iMidletArgs;
|
|
228 |
final String[] attributes = new String [properties.size() * 2];
|
|
229 |
int count = -1;
|
|
230 |
for (final Enumeration keys = properties.keys(); keys.hasMoreElements();)
|
|
231 |
{
|
|
232 |
final String key = (String)keys.nextElement();
|
|
233 |
attributes[++count] = key;
|
|
234 |
attributes[++count] = (String)properties.get(key);
|
|
235 |
}
|
|
236 |
|
|
237 |
final int server = iEventServer.getHandle();
|
|
238 |
|
|
239 |
// NGA specific change.
|
|
240 |
// Array that will be filled with native flag macros
|
|
241 |
int[] flags = new int[Toolkit.FLAG_COUNT];
|
|
242 |
iHandle = _create(server, appName, appUid, appHome, attributes, flags);
|
|
243 |
switch (iHandle)
|
|
244 |
{
|
|
245 |
case NativeError.KErrNotFound:
|
|
246 |
case NativeError.KErrPathNotFound:
|
|
247 |
throw new RuntimeException(RESOURCE_OR_PLUGIN_NOT_FOUND);
|
|
248 |
default:
|
|
249 |
checkHandle(iHandle); // leaves if error
|
|
250 |
break;
|
|
251 |
}
|
|
252 |
// NGA specific change.
|
|
253 |
// Update flags
|
|
254 |
if (flags[Toolkit.FLAG_NGA_INDEX] > 0)
|
|
255 |
{
|
|
256 |
this.iFlags |= Toolkit.FLAG_NGA;
|
|
257 |
}
|
|
258 |
|
|
259 |
iDevice = new Device(this);
|
|
260 |
iBuffer = new Buffer(this);
|
|
261 |
iFontCache = new Hashtable();
|
|
262 |
|
|
263 |
}
|
|
264 |
|
|
265 |
InputStream getResourceAsStream(String aResource)
|
|
266 |
throws
|
|
267 |
IOException
|
|
268 |
{
|
|
269 |
return getClass().getResourceAsStream(aResource);
|
|
270 |
}
|
|
271 |
|
|
272 |
synchronized void start(Display aDisplay)
|
|
273 |
{
|
|
274 |
ensureInitialized();
|
|
275 |
iDisplay = aDisplay;
|
|
276 |
NativeError.check(_activate(iHandle));
|
|
277 |
activated = true;
|
|
278 |
}
|
|
279 |
|
|
280 |
private static synchronized String getServerNumber()
|
|
281 |
{
|
|
282 |
return Integer.toString(++iServerCount);
|
|
283 |
}
|
|
284 |
|
|
285 |
/**
|
|
286 |
* NGA specific change.
|
|
287 |
* Check if flags are set.
|
|
288 |
* @param flags Flags indexes
|
|
289 |
* @return True if flags are on.
|
|
290 |
* @since S60 9.2
|
|
291 |
*/
|
|
292 |
boolean checkFlags(int flags)
|
|
293 |
{
|
|
294 |
return ((iFlags & flags) > 0);
|
|
295 |
}
|
|
296 |
|
|
297 |
public boolean isClosed()
|
|
298 |
{
|
|
299 |
return ((iHandle != HANDLE_UNINITIALIZED) &&
|
|
300 |
(iHandle <= 0));
|
|
301 |
}
|
|
302 |
|
|
303 |
public int getHandle()
|
|
304 |
{
|
|
305 |
ensureInitialized();
|
|
306 |
if (isClosed())
|
|
307 |
{
|
|
308 |
throw new RuntimeException("Toolkit closed");
|
|
309 |
}
|
|
310 |
return iHandle;
|
|
311 |
}
|
|
312 |
|
|
313 |
static Toolkit getToolkit()
|
|
314 |
{
|
|
315 |
ToolkitInvoker invoker = (ToolkitInvoker)ToolkitInvoker.getToolkitInvoker();
|
|
316 |
return invoker.getCurrentToolkit();
|
|
317 |
}
|
|
318 |
|
|
319 |
final Device getDevice()
|
|
320 |
{
|
|
321 |
ensureInitialized();
|
|
322 |
return iDevice;
|
|
323 |
}
|
|
324 |
|
|
325 |
final Display getDisplay()
|
|
326 |
{
|
|
327 |
ensureInitialized();
|
|
328 |
return iDisplay;
|
|
329 |
}
|
|
330 |
|
|
331 |
final Object getCallbackLock()
|
|
332 |
{
|
|
333 |
ensureInitialized();
|
|
334 |
return iCallbackLock;
|
|
335 |
}
|
|
336 |
|
|
337 |
final Hashtable getFontCache()
|
|
338 |
{
|
|
339 |
ensureInitialized();
|
|
340 |
return iFontCache;
|
|
341 |
}
|
|
342 |
|
|
343 |
final synchronized void addObserver(ToolkitObserver aObserver)
|
|
344 |
{
|
|
345 |
if (aObserver == null)
|
|
346 |
{
|
|
347 |
return;
|
|
348 |
}
|
|
349 |
|
|
350 |
if (iObservers == null)
|
|
351 |
{
|
|
352 |
iObservers = new Vector(2);
|
|
353 |
}
|
|
354 |
|
|
355 |
if (!iObservers.contains(aObserver))
|
|
356 |
{
|
|
357 |
iObservers.addElement(aObserver);
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
final synchronized void removeObserver(ToolkitObserver aObserver)
|
|
362 |
{
|
|
363 |
if ((iObservers != null) && (aObserver != null))
|
|
364 |
{
|
|
365 |
iObservers.removeElement(aObserver);
|
|
366 |
}
|
|
367 |
}
|
|
368 |
|
|
369 |
/**
|
|
370 |
* If toolkit is already disposed, then native object has already been deleted
|
|
371 |
* aHandle can be null if exception thrown in the object's constructor (where the handle
|
|
372 |
* is typically assigned
|
|
373 |
*/
|
|
374 |
final synchronized void disposeObject(int aHandle)
|
|
375 |
{
|
|
376 |
ensureInitialized();
|
|
377 |
|
|
378 |
if (aHandle == 0)
|
|
379 |
{
|
|
380 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
381 |
"disposeObject(" + aHandle + ") < ignoring NULL handle");
|
|
382 |
return;
|
|
383 |
}
|
|
384 |
|
|
385 |
if (iHandle <= 0)
|
|
386 |
{
|
|
387 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
388 |
"disposeObject(" + aHandle + ") < : Toolkit already closed!");
|
|
389 |
return;
|
|
390 |
}
|
|
391 |
|
|
392 |
//
|
|
393 |
// Lock buffer for duration of dispose.
|
|
394 |
//
|
|
395 |
synchronized (iBuffer)
|
|
396 |
{
|
|
397 |
iBuffer.sync();
|
|
398 |
_disposeObject(iHandle, aHandle);
|
|
399 |
}
|
|
400 |
|
|
401 |
}
|
|
402 |
|
|
403 |
private void doFinalize()
|
|
404 |
{
|
|
405 |
if (mFinalizer != null)
|
|
406 |
{
|
|
407 |
registeredFinalize();
|
|
408 |
mFinalizer = null;
|
|
409 |
}
|
|
410 |
}
|
|
411 |
|
|
412 |
void registeredFinalize()
|
|
413 |
{
|
|
414 |
dispose();
|
|
415 |
}
|
|
416 |
|
|
417 |
final synchronized void dispose()
|
|
418 |
{
|
|
419 |
if ((iHandle == HANDLE_UNINITIALIZED) || (iHandle > 0))
|
|
420 |
{
|
|
421 |
//
|
|
422 |
// Notify observers that toolkit is being destroyed.
|
|
423 |
//
|
|
424 |
if (null != iObservers)
|
|
425 |
{
|
|
426 |
final int lastIndex = iObservers.size() -1;
|
|
427 |
for (int ii=lastIndex; ii>=0; ii--)
|
|
428 |
{
|
|
429 |
final ToolkitObserver observer = (ToolkitObserver)iObservers.elementAt(ii);
|
|
430 |
try
|
|
431 |
{
|
|
432 |
observer.destroyNotify();
|
|
433 |
}
|
|
434 |
catch (Exception ex)
|
|
435 |
{
|
|
436 |
Logger.ELOG(Logger.EJavaUI,
|
|
437 |
"exception thrown in destroyNotify: ", ex);
|
|
438 |
// close must complete otherwise could get panic, so ignore
|
|
439 |
// any exception thrown by observers.
|
|
440 |
}
|
|
441 |
}
|
|
442 |
}
|
|
443 |
|
|
444 |
iInvoker.removeToolkit();
|
|
445 |
|
|
446 |
if (null != iDisplay)
|
|
447 |
{
|
|
448 |
iDisplay.dispose();
|
|
449 |
iDisplay = null;
|
|
450 |
}
|
|
451 |
|
|
452 |
//
|
|
453 |
// Close the graphics buffer if present.
|
|
454 |
//
|
|
455 |
if (null != iBuffer)
|
|
456 |
{
|
|
457 |
synchronized (iBuffer)
|
|
458 |
{
|
|
459 |
iBuffer.close();
|
|
460 |
}
|
|
461 |
iBuffer = null;
|
|
462 |
}
|
|
463 |
|
|
464 |
if (iHandle > 0)
|
|
465 |
{
|
|
466 |
_dispose(iHandle);
|
|
467 |
iHandle = 0;
|
|
468 |
}
|
|
469 |
|
|
470 |
//
|
|
471 |
// Shutdown the ui event thread.
|
|
472 |
//
|
|
473 |
if (iEventServer != null)
|
|
474 |
{
|
|
475 |
iEventServer.shutdown();
|
|
476 |
}
|
|
477 |
}
|
|
478 |
}
|
|
479 |
|
|
480 |
/* deprecated */
|
|
481 |
private void handleAsyncEvent(Object aSource, int aResult)
|
|
482 |
{
|
|
483 |
((AsyncCall)aSource).complete(aResult);
|
|
484 |
}
|
|
485 |
|
|
486 |
private boolean resetThread()
|
|
487 |
{
|
|
488 |
if (!isClosed())
|
|
489 |
{
|
|
490 |
return true;
|
|
491 |
}
|
|
492 |
return false;
|
|
493 |
}
|
|
494 |
|
|
495 |
private void handleItemEvent(Item aSource, int aEvent, int aParam0, int aParam1, int aParam2)
|
|
496 |
{
|
|
497 |
if (resetThread())
|
|
498 |
{
|
|
499 |
aSource.handleEvent(aEvent, aParam0, aParam1, aParam2);
|
|
500 |
}
|
|
501 |
}
|
|
502 |
|
|
503 |
private void handleDisplayableEvent(Displayable aSource, int aEvent, int aParam0, int aParam1, int aParam2)
|
|
504 |
{
|
|
505 |
synchronized (iDestroySync)
|
|
506 |
{
|
|
507 |
//S60 Modification ==>
|
|
508 |
try
|
|
509 |
{
|
|
510 |
if (resetThread())
|
|
511 |
{
|
|
512 |
aSource.handleEvent(aEvent, aParam0, aParam1);
|
|
513 |
}
|
|
514 |
}
|
|
515 |
catch (Throwable t)
|
|
516 |
{
|
|
517 |
String className = t.getClass().getName();
|
|
518 |
int index = className.lastIndexOf('.');
|
|
519 |
if (index != -1)
|
|
520 |
{
|
|
521 |
className = className.substring(index + 1, className.length());
|
|
522 |
}
|
|
523 |
String errStr= "Exception in handleDisplayableEvent. Reason: "+className+
|
|
524 |
"\n event is : "+aEvent+
|
|
525 |
"\n source is : "+aSource+"\n p0 is : "+aParam0+
|
|
526 |
"\n p1 is : "+aParam1+"\n p2 is : "+aParam2;
|
|
527 |
Logger.ELOG(Logger.EJavaUI,errStr, t);
|
|
528 |
|
|
529 |
//Removing Displayable if is exception thrown
|
|
530 |
if (tmpDisplayables.contains(this))
|
|
531 |
{
|
|
532 |
tmpDisplayables.removeElement(this);
|
|
533 |
}
|
|
534 |
}
|
|
535 |
}
|
|
536 |
}
|
|
537 |
|
|
538 |
private void handleDisplayEvent(Toolkit aToolkit, int aEvent, int aParam0, int aParam1, int aParam2)
|
|
539 |
{
|
|
540 |
synchronized (iDestroySync)
|
|
541 |
{
|
|
542 |
if (resetThread())
|
|
543 |
{
|
|
544 |
switch (aEvent)
|
|
545 |
{
|
|
546 |
case EVENT_EXIT_REQUESTED:
|
|
547 |
ApplicationUtils.getInstance().notifyExitCmd();
|
|
548 |
break;
|
|
549 |
case EVENT_DESTROY_REQUESTED:
|
|
550 |
ApplicationUtils.getInstance().notifyExitCmd();
|
|
551 |
break;
|
|
552 |
case EVENT_PAUSE_REQUESTED:
|
|
553 |
ApplicationUtils.getInstance().pauseApplication();
|
|
554 |
break;
|
|
555 |
case EVENT_START_REQUESTED:
|
|
556 |
ApplicationUtils.getInstance().resumeApplication();
|
|
557 |
break;
|
|
558 |
case EVENT_FOREGROUND:
|
|
559 |
iDisplay.handleForeground(true);
|
|
560 |
break;
|
|
561 |
case EVENT_BACKGROUND:
|
|
562 |
iDisplay.handleForeground(false);
|
|
563 |
notifyFreeGraphicsMemory();
|
|
564 |
break;
|
|
565 |
case EVENT_SET_CURRENT:
|
|
566 |
iDisplay.switchCurrent();
|
|
567 |
break;
|
|
568 |
case EVENT_SERIAL:
|
|
569 |
iDisplay.processSerialEvents();
|
|
570 |
break;
|
|
571 |
case EVENT_FREE_GPU_MEMORY:
|
|
572 |
notifyFreeGraphicsMemory();
|
|
573 |
break;
|
|
574 |
default:
|
|
575 |
throw new IllegalArgumentException();
|
|
576 |
}
|
|
577 |
}
|
|
578 |
}
|
|
579 |
}
|
|
580 |
|
|
581 |
private synchronized void notifyFreeGraphicsMemory()
|
|
582 |
{
|
|
583 |
if (null != iObservers)
|
|
584 |
{
|
|
585 |
final int lastIndex = iObservers.size() - 1;
|
|
586 |
for (int ii=lastIndex; ii>=0; ii--)
|
|
587 |
{
|
|
588 |
if (iObservers.elementAt(ii) instanceof ToolkitObserverNGAExtension)
|
|
589 |
{
|
|
590 |
final ToolkitObserverNGAExtension observer =
|
|
591 |
(ToolkitObserverNGAExtension)iObservers.elementAt(ii);
|
|
592 |
observer.freeGraphicsMemory();
|
|
593 |
}
|
|
594 |
}
|
|
595 |
}
|
|
596 |
}
|
|
597 |
|
|
598 |
private void handleCanvasGraphicsItemPainterEvent(CanvasGraphicsItemPainter aSource, int aEvent, int aParam0, int aParam1, int aParam2)
|
|
599 |
{
|
|
600 |
if (resetThread())
|
|
601 |
{
|
|
602 |
aSource.handleEvent(aEvent, aParam0, aParam1);
|
|
603 |
}
|
|
604 |
}
|
|
605 |
|
|
606 |
synchronized void setForeground(boolean aForeground)
|
|
607 |
{
|
|
608 |
if (iStartingInBackground)
|
|
609 |
{
|
|
610 |
NativeError.check(_setForeground(getHandle(), false));
|
|
611 |
iStartingInBackground = false;
|
|
612 |
}
|
|
613 |
else
|
|
614 |
{
|
|
615 |
NativeError.check(_setForeground(getHandle(), aForeground));
|
|
616 |
}
|
|
617 |
}
|
|
618 |
|
|
619 |
/**
|
|
620 |
* blocks until all drawing complete
|
|
621 |
*/
|
|
622 |
void sync()
|
|
623 |
{
|
|
624 |
ensureInitialized();
|
|
625 |
synchronized (iBuffer)
|
|
626 |
{
|
|
627 |
iBuffer.sync();
|
|
628 |
}
|
|
629 |
}
|
|
630 |
|
|
631 |
/*
|
|
632 |
* NGA specific change.
|
|
633 |
* Adds m3g content start op code to buffer,
|
|
634 |
* if Graphics's target is Canvas.
|
|
635 |
* The buffer is synchronized in any case.
|
|
636 |
* @param aGraphics Graphics instance
|
|
637 |
* @see ToolkitInvoker#toolkitSync(Object, Object)
|
|
638 |
* @since S60 9.2
|
|
639 |
*/
|
|
640 |
void sync(Object aObject)
|
|
641 |
{
|
|
642 |
ensureInitialized();
|
|
643 |
Graphics graphics = (Graphics)aObject;
|
|
644 |
if (checkFlags(FLAG_NGA) &&
|
|
645 |
graphics != null &&
|
|
646 |
graphics.iTarget instanceof Canvas)
|
|
647 |
{
|
|
648 |
Canvas canvas = (Canvas)graphics.iTarget;
|
|
649 |
canvas.setM3GContent(true);
|
|
650 |
synchronized (iBuffer)
|
|
651 |
{
|
|
652 |
iBuffer.write(canvas.getContentHandle(), M3G_CONTENT_START);
|
|
653 |
iBuffer.sync();
|
|
654 |
}
|
|
655 |
}
|
|
656 |
else
|
|
657 |
{
|
|
658 |
sync();
|
|
659 |
}
|
|
660 |
}
|
|
661 |
|
|
662 |
/**
|
|
663 |
* Write buffer command which when processed will draw to screen.
|
|
664 |
* Used by Canvas and CustomItem.
|
|
665 |
*/
|
|
666 |
void sync(int aDrawable)
|
|
667 |
{
|
|
668 |
ensureInitialized();
|
|
669 |
synchronized (iBuffer)
|
|
670 |
{
|
|
671 |
iBuffer.write(aDrawable, SYNC);
|
|
672 |
iBuffer.sync();
|
|
673 |
}
|
|
674 |
}
|
|
675 |
|
|
676 |
/**
|
|
677 |
* Write buffer command which when processed will draw to screen.
|
|
678 |
* Used by Canvas and CustomItem.
|
|
679 |
*/
|
|
680 |
void sync(int aDrawable, int aX, int aY, int aW, int aH)
|
|
681 |
{
|
|
682 |
ensureInitialized();
|
|
683 |
synchronized (iBuffer)
|
|
684 |
{
|
|
685 |
final int x2=aX+aW;
|
|
686 |
final int y2=aY+aH;
|
|
687 |
iBuffer.write(aDrawable, SYNC_RECT, aX, aY, x2, y2);
|
|
688 |
iBuffer.sync();
|
|
689 |
}
|
|
690 |
}
|
|
691 |
|
|
692 |
/**
|
|
693 |
JSR 135 Support
|
|
694 |
*/
|
|
695 |
final int getEventServerHandle()
|
|
696 |
{
|
|
697 |
ensureInitialized();
|
|
698 |
return iEventServer.getHandle();
|
|
699 |
}
|
|
700 |
|
|
701 |
void postEvent(int aEvent)
|
|
702 |
{
|
|
703 |
NativeError.check(_postEvent(getHandle(), 0, MIDLET, aEvent));
|
|
704 |
}
|
|
705 |
|
|
706 |
void postEvent(Item aItem, int aEvent)
|
|
707 |
{
|
|
708 |
NativeError.check(_postEvent(getHandle(), aItem.getHandle(), ITEM, aEvent));
|
|
709 |
}
|
|
710 |
|
|
711 |
void postEvent(Displayable aDisplayable, int aEvent)
|
|
712 |
{
|
|
713 |
NativeError.check(_postEvent(getHandle(), aDisplayable.getContainerHandle(), DISPLAYABLE, aEvent));
|
|
714 |
}
|
|
715 |
|
|
716 |
void postEvent(CanvasGraphicsItemPainter aCanvasGraphicsItem, int aEvent)
|
|
717 |
{
|
|
718 |
NativeError.check(_postEvent(getHandle(), aCanvasGraphicsItem.getHandle(), CANVAS_GRAPHICS_ITEM_PAINTER, aEvent));
|
|
719 |
}
|
|
720 |
|
|
721 |
static int checkHandle(int aHandle)
|
|
722 |
{
|
|
723 |
if (NativeError.check(aHandle) == 0)
|
|
724 |
{
|
|
725 |
throw new OutOfMemoryError();
|
|
726 |
}
|
|
727 |
return aHandle;
|
|
728 |
}
|
|
729 |
|
|
730 |
/**
|
|
731 |
* NGA specific change.
|
|
732 |
* Create native peer on server thread reference by aContext.
|
|
733 |
* @param aFlags The array that is filled according to native
|
|
734 |
* side's macro definitions
|
|
735 |
*/
|
|
736 |
native int _create(
|
|
737 |
int aContext,String aName, int aUid, String aHomeDir, String[] aAttributes, int[] aFlags);
|
|
738 |
|
|
739 |
/**
|
|
740 |
* Open toolkit - enable events.
|
|
741 |
*/
|
|
742 |
native int _activate(int aToolkit);
|
|
743 |
|
|
744 |
/**
|
|
745 |
* Delete toolkit - invalidates handle so no remaining threads must be
|
|
746 |
* holding the toolkit handle.
|
|
747 |
*/
|
|
748 |
native void _dispose(int aToolkit);
|
|
749 |
|
|
750 |
/**
|
|
751 |
* Deletion native UI object with handle aObject
|
|
752 |
*/
|
|
753 |
native void _disposeObject(int aToolkit,int aObject);
|
|
754 |
|
|
755 |
native int _postEvent(int aToolkit, int aSource, int aType, int aEvent);
|
|
756 |
native int _setCurrent(int aToolkit,int aDisplayable);
|
|
757 |
native int _setForeground(int aToolkit, boolean aForeground);
|
|
758 |
}
|