80
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 |
* \file
|
|
19 |
* \brief Target platform dependent Java module for Symbian.
|
|
20 |
*
|
|
21 |
*/
|
|
22 |
|
|
23 |
package com.nokia.microedition.m2g;
|
|
24 |
import javax.microedition.lcdui.Graphics;
|
|
25 |
import javax.microedition.lcdui.Image;
|
|
26 |
import org.eclipse.swt.widgets.Display;
|
|
27 |
|
|
28 |
import com.nokia.mj.impl.nokialcdui.LCDUIInvoker;
|
|
29 |
import org.eclipse.swt.internal.extension.DisplayExtension;
|
|
30 |
import org.eclipse.swt.internal.extension.Toolkit;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Implements platform-dependent functionality. At the moment, this
|
|
34 |
* includes native finalization and some helper methods for
|
|
35 |
* synchronizing 2D and 3D rendering.
|
|
36 |
*/
|
|
37 |
class Platform
|
|
38 |
{
|
|
39 |
/**
|
|
40 |
* eSWT display for ui thread access
|
|
41 |
*/
|
|
42 |
private static Display display = null;
|
|
43 |
private static boolean libraryLoaded = false;
|
|
44 |
|
|
45 |
//------------------------------------------------------------------
|
|
46 |
// Package private methods
|
|
47 |
//------------------------------------------------------------------
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Executes given runnable in UI thread if caller thread is not UI thread
|
|
51 |
*/
|
|
52 |
static void executeInUIThread(M2GRunnableQt obj)
|
|
53 |
{
|
|
54 |
if (display == null)
|
|
55 |
{
|
|
56 |
if (!uiThreadAvailable())
|
|
57 |
{
|
|
58 |
throw new Error("Ui thread not available");
|
|
59 |
}
|
|
60 |
}
|
|
61 |
if (display.isDisposed())
|
|
62 |
{
|
|
63 |
throw new Error("Display already disposed");
|
|
64 |
}
|
|
65 |
|
|
66 |
if (obj != null)
|
|
67 |
{
|
|
68 |
// If we are not in UI thread use display
|
|
69 |
if (Thread.currentThread() != display.getThread())
|
|
70 |
{
|
|
71 |
display.syncExec(obj);
|
|
72 |
}
|
|
73 |
else
|
|
74 |
{
|
|
75 |
// In this case we are in UI thread so just execute directly
|
|
76 |
obj.run();
|
|
77 |
}
|
|
78 |
// Check if any exceptions occured in execution
|
|
79 |
// and throw forward in caller thread
|
|
80 |
obj.checkAndThrow();
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
/**
|
|
85 |
* Check the UI thread / toolkit init status and store display if it is available
|
|
86 |
* @return true if either lcdui or eswt toolkit is initialized and ui thread is accessible
|
|
87 |
* otherwise false
|
|
88 |
*/
|
|
89 |
static boolean uiThreadAvailable()
|
|
90 |
{
|
|
91 |
if (display != null)
|
|
92 |
{
|
|
93 |
return true;
|
|
94 |
}
|
|
95 |
else
|
|
96 |
{
|
|
97 |
//display = DisplayExtension.getDisplayInstance();
|
87
|
98 |
//As now the thread is always available we are taking it from Toolkit.
|
|
99 |
display = Toolkit. getInternalDisplay();
|
|
100 |
|
|
101 |
|
|
102 |
if (display == null)
|
80
|
103 |
{
|
87
|
104 |
|
80
|
105 |
return false;
|
|
106 |
}
|
|
107 |
else
|
|
108 |
{
|
87
|
109 |
|
80
|
110 |
// UI thread is available, so load native library if not already loaded
|
|
111 |
if (!libraryLoaded)
|
|
112 |
{
|
87
|
113 |
|
80
|
114 |
com.nokia.mj.impl.rt.support.Jvm.loadSystemLibrary("javam2g");
|
|
115 |
libraryLoaded = true;
|
|
116 |
}
|
|
117 |
return true;
|
|
118 |
}
|
|
119 |
}
|
|
120 |
}
|
87
|
121 |
|
80
|
122 |
|
87
|
123 |
|
80
|
124 |
static final void finalizeObject(int handle)
|
|
125 |
{
|
|
126 |
try
|
|
127 |
{
|
|
128 |
final int finalHandle = handle;
|
|
129 |
executeInUIThread(
|
|
130 |
new M2GRunnableQt()
|
|
131 |
{
|
|
132 |
void doRun()
|
|
133 |
{
|
|
134 |
_finalizeObject(finalHandle);
|
|
135 |
}
|
|
136 |
});
|
|
137 |
}
|
|
138 |
catch (Exception e)
|
|
139 |
{
|
|
140 |
// do nothing
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
//------------------------------------------------------------------
|
|
145 |
// Private methods
|
|
146 |
//------------------------------------------------------------------
|
|
147 |
|
|
148 |
/**
|
|
149 |
* Trigger GC if minimum free memory limit has been exceeded in the native side
|
|
150 |
*/
|
|
151 |
static final void heuristicGC()
|
|
152 |
{
|
|
153 |
}
|
|
154 |
private static final native void _finalizeObject(int handle);
|
|
155 |
}
|
|
156 |
|