65 |
65 |
private static long mNextClientID = 0;
|
66 |
66 |
private static long mNextSystemID = 0;
|
67 |
67 |
|
|
68 |
private final static Object mDoneLock = new Object();
|
|
69 |
private final static Object mToDoLock = new Object();
|
|
70 |
|
68 |
71 |
private long mID;
|
69 |
72 |
private int mType;
|
70 |
73 |
|
... | ... | |
78 |
81 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
82 |
// must be called from a thread holding OpenGL Context
|
80 |
83 |
|
81 |
|
static synchronized boolean toDo()
|
|
84 |
static boolean toDo()
|
82 |
85 |
{
|
83 |
86 |
if( mToDo )
|
84 |
87 |
{
|
85 |
88 |
Job job;
|
86 |
89 |
DistortedObject object;
|
87 |
90 |
|
88 |
|
for(Long key: mToDoMap.keySet())
|
|
91 |
synchronized(mToDoLock)
|
89 |
92 |
{
|
90 |
|
job = mToDoMap.get(key);
|
91 |
|
object = job.object;
|
92 |
|
|
93 |
|
//android.util.Log.d("Object", object.getClass().getSimpleName()+" ---> need to "
|
94 |
|
// +(job.action==JOB_CREATE ? "create":"delete")+" objectID="+object.mDistortedEffectsID );
|
95 |
|
|
96 |
|
if( job.action==JOB_CREATE )
|
97 |
|
{
|
98 |
|
object.create();
|
99 |
|
mDoneList.add(object);
|
100 |
|
}
|
101 |
|
else if( job.action==JOB_DELETE )
|
|
93 |
for(Long key: mToDoMap.keySet())
|
102 |
94 |
{
|
103 |
|
object.delete();
|
|
95 |
job = mToDoMap.get(key);
|
|
96 |
object = job.object;
|
|
97 |
|
|
98 |
if( job.action==JOB_CREATE )
|
|
99 |
{
|
|
100 |
object.create();
|
|
101 |
mDoneList.add(object);
|
|
102 |
}
|
|
103 |
else if( job.action==JOB_DELETE )
|
|
104 |
{
|
|
105 |
object.delete();
|
|
106 |
}
|
104 |
107 |
}
|
|
108 |
|
|
109 |
mToDoMap.clear();
|
|
110 |
mToDo = false;
|
105 |
111 |
}
|
106 |
112 |
|
107 |
|
mToDoMap.clear();
|
108 |
|
mToDo = false;
|
109 |
113 |
return true;
|
110 |
114 |
}
|
111 |
115 |
|
... | ... | |
114 |
118 |
|
115 |
119 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116 |
120 |
|
117 |
|
static synchronized void onPause()
|
|
121 |
static void onPause()
|
118 |
122 |
{
|
119 |
123 |
DistortedObject object;
|
120 |
|
int num = mDoneList.size();
|
121 |
124 |
|
122 |
|
try
|
|
125 |
synchronized(mDoneLock)
|
123 |
126 |
{
|
124 |
|
for (int i = 0; i < num; i++)
|
|
127 |
synchronized(mToDoLock)
|
125 |
128 |
{
|
126 |
|
object = mDoneList.removeFirst();
|
127 |
|
mToDoMap.put(object.mID, object.new Job(object, JOB_CREATE));
|
128 |
|
object.recreate();
|
|
129 |
int num = mDoneList.size();
|
|
130 |
|
|
131 |
try
|
|
132 |
{
|
|
133 |
for (int i = 0; i < num; i++)
|
|
134 |
{
|
|
135 |
object = mDoneList.removeFirst();
|
|
136 |
mToDoMap.put(object.mID, object.new Job(object, JOB_CREATE));
|
|
137 |
object.recreate();
|
|
138 |
}
|
|
139 |
}
|
|
140 |
catch( Exception ex )
|
|
141 |
{
|
|
142 |
// something else removed an object in the meantime; ignore
|
|
143 |
}
|
129 |
144 |
}
|
130 |
145 |
}
|
131 |
|
catch( Exception ex )
|
132 |
|
{
|
133 |
|
// something else removed an object in the meantime; ignore
|
134 |
|
}
|
135 |
146 |
|
136 |
147 |
mToDo = true;
|
137 |
148 |
}
|
138 |
149 |
|
139 |
150 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140 |
151 |
|
141 |
|
static synchronized void onDestroy()
|
|
152 |
static void onDestroy()
|
142 |
153 |
{
|
143 |
|
mToDoMap.clear();
|
144 |
|
mDoneList.clear();
|
|
154 |
synchronized(mToDoLock)
|
|
155 |
{
|
|
156 |
synchronized(mDoneLock)
|
|
157 |
{
|
|
158 |
mToDoMap.clear();
|
|
159 |
mDoneList.clear();
|
145 |
160 |
|
146 |
|
mToDo = true;
|
147 |
|
mNextClientID = 0;
|
|
161 |
mToDo = true;
|
|
162 |
mNextClientID = 0;
|
|
163 |
}
|
|
164 |
}
|
148 |
165 |
}
|
149 |
166 |
|
150 |
167 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
191 |
208 |
android.util.Log.e("Object", str+printDetails()+msg);
|
192 |
209 |
}
|
193 |
210 |
|
194 |
|
|
195 |
211 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196 |
212 |
|
197 |
213 |
DistortedObject(int create, int type)
|
... | ... | |
201 |
217 |
|
202 |
218 |
if( create!=DONT_CREATE )
|
203 |
219 |
{
|
204 |
|
mToDoMap.put(mID, new Job(this,JOB_CREATE) );
|
205 |
|
mToDo = true;
|
|
220 |
synchronized(mToDoLock)
|
|
221 |
{
|
|
222 |
mToDoMap.put(mID, new Job(this,JOB_CREATE) );
|
|
223 |
mToDo = true;
|
|
224 |
}
|
206 |
225 |
}
|
207 |
226 |
}
|
208 |
227 |
|
209 |
228 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
210 |
229 |
|
211 |
|
synchronized void markForCreation()
|
|
230 |
void markForCreation()
|
212 |
231 |
{
|
213 |
|
mDoneList.remove(this);
|
214 |
|
mToDoMap.put(mID, new Job(this,JOB_CREATE) );
|
215 |
|
mToDo = true;
|
|
232 |
synchronized(mDoneLock)
|
|
233 |
{
|
|
234 |
mDoneList.remove(this);
|
|
235 |
}
|
|
236 |
|
|
237 |
synchronized(mToDoLock)
|
|
238 |
{
|
|
239 |
mToDoMap.put(mID, new Job(this,JOB_CREATE) );
|
|
240 |
mToDo = true;
|
|
241 |
}
|
216 |
242 |
}
|
217 |
243 |
|
218 |
244 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
221 |
247 |
/**
|
222 |
248 |
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
|
223 |
249 |
*/
|
224 |
|
synchronized public void markForDeletion()
|
|
250 |
public void markForDeletion()
|
225 |
251 |
{
|
226 |
|
mDoneList.remove(this);
|
227 |
|
mToDoMap.put(mID, new Job(this,JOB_DELETE) );
|
228 |
|
mToDo = true;
|
|
252 |
synchronized(mDoneLock)
|
|
253 |
{
|
|
254 |
mDoneList.remove(this);
|
|
255 |
}
|
|
256 |
|
|
257 |
synchronized(mToDoLock)
|
|
258 |
{
|
|
259 |
mToDoMap.put(mID, new Job(this,JOB_DELETE) );
|
|
260 |
mToDo = true;
|
|
261 |
}
|
229 |
262 |
}
|
230 |
263 |
|
231 |
264 |
////////////////////////////////////////////////////////////////////////////////////////////////////
|
Improve locking in DistortedObject.
DistortedMaster: slaves can be NULL !