1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// Distorted is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Distorted is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.library;
|
21
|
|
22
|
import android.opengl.GLES30;
|
23
|
import android.opengl.Matrix;
|
24
|
import java.util.ArrayList;
|
25
|
|
26
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27
|
|
28
|
abstract class DistortedOutputSurface extends DistortedSurface implements DistortedSlave
|
29
|
{
|
30
|
/**
|
31
|
* Do not create DEPTH or STENCIL attachment
|
32
|
*/
|
33
|
public static final int NO_DEPTH_STENCIL = 0;
|
34
|
/**
|
35
|
* Create DEPTH, but not STENCIL
|
36
|
*/
|
37
|
public static final int DEPTH_NO_STENCIL = 1;
|
38
|
/**
|
39
|
* Create both DEPTH and STENCIL
|
40
|
*/
|
41
|
public static final int BOTH_DEPTH_STENCIL= 2;
|
42
|
|
43
|
private static final int ATTACH = 0;
|
44
|
private static final int DETACH = 1;
|
45
|
private static final int DETALL = 2;
|
46
|
private static final int SORT = 3;
|
47
|
|
48
|
private ArrayList<DistortedNode> mChildren;
|
49
|
private int mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added
|
50
|
|
51
|
private class Job
|
52
|
{
|
53
|
int type;
|
54
|
DistortedNode node;
|
55
|
DistortedEffectsPostprocess dep;
|
56
|
|
57
|
Job(int t, DistortedNode n, DistortedEffectsPostprocess d)
|
58
|
{
|
59
|
type = t;
|
60
|
node = n;
|
61
|
dep = d;
|
62
|
}
|
63
|
}
|
64
|
|
65
|
private ArrayList<Job> mJobs = new ArrayList<>();
|
66
|
|
67
|
DistortedFramebuffer[] mBuffer1, mBuffer2;
|
68
|
|
69
|
private long mTime;
|
70
|
private float mFOV;
|
71
|
float mDistance, mNear;
|
72
|
float[] mProjectionMatrix;
|
73
|
|
74
|
int mDepthStencilCreated;
|
75
|
int mDepthStencil;
|
76
|
int[] mDepthStencilH = new int[1];
|
77
|
int[] mFBOH = new int[1];
|
78
|
|
79
|
private float mClearR, mClearG, mClearB, mClearA;
|
80
|
private float mClearDepth;
|
81
|
private int mClear;
|
82
|
|
83
|
//private String sNew="", sOld="";
|
84
|
|
85
|
float mMipmap;
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
|
89
|
DistortedOutputSurface(int width, int height, int createColor, int depthStencil, int fbo, int type)
|
90
|
{
|
91
|
super(width,height,createColor,type);
|
92
|
|
93
|
mProjectionMatrix = new float[16];
|
94
|
|
95
|
mFOV = 60.0f;
|
96
|
mNear= 0.5f;
|
97
|
|
98
|
mDepthStencilCreated= (depthStencil==NO_DEPTH_STENCIL ? DONT_CREATE:NOT_CREATED_YET);
|
99
|
mDepthStencil = depthStencil;
|
100
|
|
101
|
mFBOH[0] = fbo;
|
102
|
mDepthStencilH[0]= 0;
|
103
|
|
104
|
mTime = 0;
|
105
|
|
106
|
mClearR = 0.0f;
|
107
|
mClearG = 0.0f;
|
108
|
mClearB = 0.0f;
|
109
|
mClearA = 0.0f;
|
110
|
|
111
|
mClearDepth = 1.0f;
|
112
|
mClear = GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT;
|
113
|
|
114
|
mBuffer1 = new DistortedFramebuffer[EffectQuality.LENGTH];
|
115
|
mBuffer2 = new DistortedFramebuffer[EffectQuality.LENGTH];
|
116
|
|
117
|
mMipmap = 1.0f;
|
118
|
|
119
|
createProjection();
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
private void createProjection()
|
125
|
{
|
126
|
if( mWidth>0 && mHeight>1 )
|
127
|
{
|
128
|
if( mFOV>0.0f ) // perspective projection
|
129
|
{
|
130
|
float a = 2.0f*(float)Math.tan(mFOV*Math.PI/360);
|
131
|
float q = mWidth*mNear;
|
132
|
float c = mHeight*mNear;
|
133
|
|
134
|
float left = -q/2;
|
135
|
float right = +q/2;
|
136
|
float bottom = -c/2;
|
137
|
float top = +c/2;
|
138
|
float near = c/a;
|
139
|
|
140
|
mDistance = mHeight/a;
|
141
|
float far = 2*mDistance-near;
|
142
|
|
143
|
Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
|
144
|
}
|
145
|
else // parallel projection
|
146
|
{
|
147
|
float left = -mWidth/2.0f;
|
148
|
float right = +mWidth/2.0f;
|
149
|
float bottom = -mHeight/2.0f;
|
150
|
float top = +mHeight/2.0f;
|
151
|
float near = mWidth+mHeight-mHeight*(1.0f-mNear);
|
152
|
mDistance = mWidth+mHeight;
|
153
|
float far = mWidth+mHeight+mHeight*(1.0f-mNear);
|
154
|
|
155
|
Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
|
156
|
}
|
157
|
}
|
158
|
}
|
159
|
|
160
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161
|
// Render all children, one by one. If there are no postprocessing effects, just render to THIS.
|
162
|
// Otherwise, render to a buffer and on each change of Postprocessing Bucket, apply the postprocessing
|
163
|
// to a whole buffer and merge it.
|
164
|
|
165
|
int renderChildren(long time, int num, ArrayList<DistortedNode> children)
|
166
|
{
|
167
|
int numRenders = 0;
|
168
|
DistortedNode child;
|
169
|
DistortedEffectsPostprocess lastP=null, currP;
|
170
|
long lastB=0, currB;
|
171
|
|
172
|
//sNew = "";
|
173
|
|
174
|
for(int i=0; i<num; i++)
|
175
|
{
|
176
|
child = children.get(i);
|
177
|
currP = child.getEffectsPostprocess();
|
178
|
currB = currP==null ? 0 : currP.getBucket();
|
179
|
|
180
|
//sNew += currB;
|
181
|
|
182
|
if( lastB!=currB && lastB!=0 )
|
183
|
{
|
184
|
numRenders += lastP.postprocess(time,this);
|
185
|
}
|
186
|
|
187
|
if( currB==0 )
|
188
|
{
|
189
|
numRenders += child.draw(time,this);
|
190
|
}
|
191
|
else
|
192
|
{
|
193
|
if( mBuffer1[0]==null )
|
194
|
{
|
195
|
float mipmap=1.0f;
|
196
|
|
197
|
for(int j=0; j<EffectQuality.LENGTH; j++)
|
198
|
{
|
199
|
mBuffer1[j] = new DistortedFramebuffer( mDepthStencil , DistortedObject.TYPE_SYST,
|
200
|
(int)(mWidth*mipmap), (int)(mHeight*mipmap) );
|
201
|
mBuffer2[j] = new DistortedFramebuffer( NO_DEPTH_STENCIL, DistortedObject.TYPE_SYST,
|
202
|
(int)(mWidth*mipmap), (int)(mHeight*mipmap) );
|
203
|
mBuffer1[j].mMipmap = mipmap;
|
204
|
mipmap *= EffectQuality.MULTIPLIER;
|
205
|
}
|
206
|
DistortedObject.toDo(); // create immediately
|
207
|
}
|
208
|
|
209
|
numRenders += child.draw(time,mBuffer1[currP.getQuality()]);
|
210
|
|
211
|
if( i==num-1 )
|
212
|
{
|
213
|
numRenders += currP.postprocess(time,this);
|
214
|
}
|
215
|
}
|
216
|
|
217
|
lastP = currP;
|
218
|
lastB = currB;
|
219
|
}
|
220
|
/*
|
221
|
if( !sNew.equals(sOld) )
|
222
|
{
|
223
|
sOld = sNew;
|
224
|
android.util.Log.e("surface", "Surface"+getID()+": "+sOld);
|
225
|
}
|
226
|
*/
|
227
|
return numRenders;
|
228
|
}
|
229
|
|
230
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
231
|
|
232
|
void newJob(int t, DistortedNode n, DistortedEffectsPostprocess d)
|
233
|
{
|
234
|
mJobs.add(new Job(t,n,d));
|
235
|
}
|
236
|
|
237
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
238
|
// PUBLIC API
|
239
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
240
|
/**
|
241
|
* Draws all the attached children to this OutputSurface.
|
242
|
* <p>
|
243
|
* Must be called from a thread holding OpenGL Context.
|
244
|
*
|
245
|
* @param time Current time, in milliseconds. This will be passed to all the Effects stored in the children Nodes.
|
246
|
* @return Number of objects rendered.
|
247
|
*/
|
248
|
public int render(long time)
|
249
|
{
|
250
|
// change tree topology (attach and detach children)
|
251
|
/*
|
252
|
boolean changed1 =
|
253
|
*/
|
254
|
DistortedMaster.toDo();
|
255
|
/*
|
256
|
if( changed1 )
|
257
|
{
|
258
|
for(int i=0; i<mNumChildren; i++)
|
259
|
{
|
260
|
mChildren.get(i).debug(0);
|
261
|
}
|
262
|
|
263
|
DistortedNode.debugMap();
|
264
|
}
|
265
|
*/
|
266
|
// create and delete all underlying OpenGL resources
|
267
|
// Watch out: FIRST change topology, only then deal
|
268
|
// with OpenGL resources. That's because changing Tree
|
269
|
// can result in additional Framebuffers that would need
|
270
|
// to be created immediately, before the calls to drawRecursive()
|
271
|
/*
|
272
|
boolean changed2 =
|
273
|
*/
|
274
|
toDo();
|
275
|
/*
|
276
|
if( changed2 )
|
277
|
{
|
278
|
DistortedObject.debugLists();
|
279
|
}
|
280
|
*/
|
281
|
// mark OpenGL state as unknown
|
282
|
DistortedRenderState.reset();
|
283
|
|
284
|
int numRenders=0;
|
285
|
|
286
|
for(int i=0; i<mNumChildren; i++)
|
287
|
{
|
288
|
numRenders += mChildren.get(i).renderRecursive(time);
|
289
|
}
|
290
|
|
291
|
setAsOutput(time);
|
292
|
numRenders += renderChildren(time,mNumChildren,mChildren);
|
293
|
|
294
|
return numRenders;
|
295
|
}
|
296
|
|
297
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
298
|
/**
|
299
|
* Bind this Surface as a Framebuffer we can render to.
|
300
|
*
|
301
|
* @param time Present time, in milliseconds. The point: looking at this param the library can figure
|
302
|
* out if this is the first time during present frame that this FBO is being set as output.
|
303
|
* If so, the library, in addition to binding the Surface for output, also clears the
|
304
|
* Surface's color and depth attachments.
|
305
|
*/
|
306
|
public void setAsOutput(long time)
|
307
|
{
|
308
|
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
|
309
|
|
310
|
if( mTime!=time )
|
311
|
{
|
312
|
mTime = time;
|
313
|
DistortedRenderState.colorDepthOn();
|
314
|
GLES30.glClearColor(mClearR, mClearG, mClearB, mClearA);
|
315
|
GLES30.glClearDepthf(mClearDepth);
|
316
|
GLES30.glClear(mClear);
|
317
|
}
|
318
|
}
|
319
|
|
320
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
321
|
/**
|
322
|
* Set mipmap level.
|
323
|
* <p>
|
324
|
* Trick for speeding up your renders - one can create a pyramid of OutputSurface objects, each next
|
325
|
* one some constant FACTOR smaller than the previous (0.5 is the common value), then set the Mipmap
|
326
|
* Level of the i-th object to be FACTOR^i (we start counting from 0). When rendering any scene into
|
327
|
* such prepared OutputSurface, the library will make sure to scale any Effects used so that the end
|
328
|
* scene will end up looking identical no matter which object we render to. Identical, that is, except
|
329
|
* for the loss of quality and gain in speed associated with rendering to a smaller Surface.
|
330
|
* <p>
|
331
|
* Example: if you create two FBOs, one 1000x1000 and another 500x500 in size, and set the second one
|
332
|
* mipmap to 0.5 (the first one's is 1.0 by default), define Effects to be a single move by (100,100),
|
333
|
* and render a skinned Mesh into both FBO, the end result will look proportionally the same, because
|
334
|
* in the second case the move vector (100,100) will be auto-scaled to (50,50).
|
335
|
*
|
336
|
* @param mipmap The mipmap level. Acceptable range: 0<mipmap<infinity, although mipmap>1
|
337
|
* does not make any sense (that would result in loss of speed and no gain in quality)
|
338
|
*/
|
339
|
public void setMipmap(float mipmap)
|
340
|
{
|
341
|
mMipmap = mipmap;
|
342
|
}
|
343
|
|
344
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
345
|
/**
|
346
|
* Set the (R,G,B,A) values of GLES30.glClearColor() to set up color with which to clear
|
347
|
* this Surface at the beginning of each frame.
|
348
|
*
|
349
|
* @param r the Red component. Default: 0.0f
|
350
|
* @param g the Green component. Default: 0.0f
|
351
|
* @param b the Blue component. Default: 0.0f
|
352
|
* @param a the Alpha component. Default: 0.0f
|
353
|
*/
|
354
|
public void glClearColor(float r, float g, float b, float a)
|
355
|
{
|
356
|
mClearR = r;
|
357
|
mClearG = g;
|
358
|
mClearB = b;
|
359
|
mClearA = a;
|
360
|
}
|
361
|
|
362
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
363
|
/**
|
364
|
* Set the Depth value of GLES30.glClearDepthf() to set up depth with which to clear
|
365
|
* the Depth buffer of Surface at the beginning of each frame.
|
366
|
*
|
367
|
* @param d the Depth. Default: 1.0f
|
368
|
*/
|
369
|
public void glClearDepthf(float d)
|
370
|
{
|
371
|
mClearDepth = d;
|
372
|
}
|
373
|
|
374
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
375
|
/**
|
376
|
* Which buffers to Clear at the beginning of each frame?
|
377
|
* <p>
|
378
|
* Valid values: 0, or bitwise OR of one or more values from the set GL_COLOR_BUFFER_BIT,
|
379
|
* GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
|
380
|
* Default: GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT.
|
381
|
*
|
382
|
* @param mask bitwise OR of BUFFER_BITs to clear.
|
383
|
*/
|
384
|
public void glClear(int mask)
|
385
|
{
|
386
|
mClear = mask;
|
387
|
}
|
388
|
|
389
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
390
|
/**
|
391
|
* Create new Projection matrix.
|
392
|
*
|
393
|
* @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
|
394
|
* Valid values: 0<=fov<180. FOV==0 means 'parallel projection'.
|
395
|
* @param near Distance between the screen plane and the near plane.
|
396
|
* Valid vaules: 0<near<1. When near==0, the Near Plane is exactly at the tip of the
|
397
|
* pyramid. When near==1 (illegal!) the near plane is equivalent to the screen plane.
|
398
|
*/
|
399
|
public void setProjection(float fov, float near)
|
400
|
{
|
401
|
if( fov < 180.0f && fov >=0.0f )
|
402
|
{
|
403
|
mFOV = fov;
|
404
|
}
|
405
|
|
406
|
if( near< 1.0f && near> 0.0f )
|
407
|
{
|
408
|
mNear= near;
|
409
|
}
|
410
|
else if( near<=0.0f )
|
411
|
{
|
412
|
mNear = 0.01f;
|
413
|
}
|
414
|
else if( near>=1.0f )
|
415
|
{
|
416
|
mNear=0.99f;
|
417
|
}
|
418
|
|
419
|
createProjection();
|
420
|
}
|
421
|
|
422
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
423
|
/**
|
424
|
* Resize the underlying Framebuffer.
|
425
|
* <p>
|
426
|
* This method can be safely called mid-render as it doesn't interfere with rendering.
|
427
|
*
|
428
|
* @param width The new width.
|
429
|
* @param height The new height.
|
430
|
*/
|
431
|
public void resize(int width, int height)
|
432
|
{
|
433
|
if( mWidth!=width || mHeight!=height )
|
434
|
{
|
435
|
mWidth = width;
|
436
|
mHeight= height;
|
437
|
|
438
|
createProjection();
|
439
|
|
440
|
if( mColorCreated==CREATED )
|
441
|
{
|
442
|
markForCreation();
|
443
|
recreate();
|
444
|
}
|
445
|
}
|
446
|
}
|
447
|
|
448
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
449
|
/**
|
450
|
* Return true if the Surface contains a DEPTH attachment.
|
451
|
*
|
452
|
* @return <bold>true</bold> if the Surface contains a DEPTH attachment.
|
453
|
*/
|
454
|
public boolean hasDepth()
|
455
|
{
|
456
|
return mDepthStencilCreated==CREATED;
|
457
|
}
|
458
|
|
459
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
460
|
/**
|
461
|
* Return true if the Surface contains a STENCIL attachment.
|
462
|
*
|
463
|
* @return <bold>true</bold> if the Surface contains a STENCIL attachment.
|
464
|
*/
|
465
|
public boolean hasStencil()
|
466
|
{
|
467
|
return (mDepthStencilCreated==CREATED && mDepthStencil==BOTH_DEPTH_STENCIL);
|
468
|
}
|
469
|
|
470
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
471
|
/**
|
472
|
* Adds a new child to the last position in the list of our Surface's children.
|
473
|
* <p>
|
474
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
475
|
* DistortedMaster (by calling doWork())
|
476
|
*
|
477
|
* @param node The new Node to add.
|
478
|
*/
|
479
|
public void attach(DistortedNode node)
|
480
|
{
|
481
|
mJobs.add(new Job(ATTACH,node,null));
|
482
|
DistortedMaster.newSlave(this);
|
483
|
}
|
484
|
|
485
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
486
|
/**
|
487
|
* Adds a new child to the last position in the list of our Surface's children.
|
488
|
* <p>
|
489
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
490
|
* DistortedMaster (by calling doWork())
|
491
|
*
|
492
|
* @param surface InputSurface to initialize our child Node with.
|
493
|
* @param effects DistortedEffects to initialize our child Node with.
|
494
|
* @param mesh MeshObject to initialize our child Node with.
|
495
|
* @return the newly constructed child Node, or null if we couldn't allocate resources.
|
496
|
*/
|
497
|
public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
|
498
|
{
|
499
|
DistortedNode node = new DistortedNode(surface,effects,mesh);
|
500
|
mJobs.add(new Job(ATTACH,node,null));
|
501
|
DistortedMaster.newSlave(this);
|
502
|
return node;
|
503
|
}
|
504
|
|
505
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
506
|
/**
|
507
|
* Removes the first occurrence of a specified child from the list of children of our Surface.
|
508
|
* <p>
|
509
|
* A bit questionable method as there can be many different Nodes attached as children, some
|
510
|
* of them having the same Effects but - for instance - different Mesh. Use with care.
|
511
|
* <p>
|
512
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
513
|
* DistortedMaster (by calling doWork())
|
514
|
*
|
515
|
* @param effects DistortedEffects to remove.
|
516
|
*/
|
517
|
public void detach(DistortedEffects effects)
|
518
|
{
|
519
|
long id = effects.getID();
|
520
|
DistortedNode node;
|
521
|
boolean detached = false;
|
522
|
|
523
|
for(int i=0; i<mNumChildren; i++)
|
524
|
{
|
525
|
node = mChildren.get(i);
|
526
|
|
527
|
if( node.getEffects().getID()==id )
|
528
|
{
|
529
|
detached = true;
|
530
|
mJobs.add(new Job(DETACH,node,null));
|
531
|
DistortedMaster.newSlave(this);
|
532
|
break;
|
533
|
}
|
534
|
}
|
535
|
|
536
|
if( !detached )
|
537
|
{
|
538
|
// if we failed to detach any, it still might be the case that
|
539
|
// there's an ATTACH job that we need to cancel.
|
540
|
int num = mJobs.size();
|
541
|
Job job;
|
542
|
|
543
|
for(int i=0; i<num; i++)
|
544
|
{
|
545
|
job = mJobs.get(i);
|
546
|
|
547
|
if( job.type==ATTACH && job.node.getEffects()==effects )
|
548
|
{
|
549
|
mJobs.remove(i);
|
550
|
break;
|
551
|
}
|
552
|
}
|
553
|
}
|
554
|
}
|
555
|
|
556
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
557
|
/**
|
558
|
* Removes the first occurrence of a specified child from the list of children of our Surface.
|
559
|
* <p>
|
560
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
561
|
* DistortedMaster (by calling doWork())
|
562
|
*
|
563
|
* @param node The Node to remove.
|
564
|
*/
|
565
|
public void detach(DistortedNode node)
|
566
|
{
|
567
|
mJobs.add(new Job(DETACH,node,null));
|
568
|
DistortedMaster.newSlave(this);
|
569
|
}
|
570
|
|
571
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
572
|
/**
|
573
|
* Removes all children Nodes.
|
574
|
* <p>
|
575
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
576
|
* DistortedMaster (by calling doWork())
|
577
|
*/
|
578
|
public void detachAll()
|
579
|
{
|
580
|
mJobs.add(new Job(DETALL,null,null));
|
581
|
DistortedMaster.newSlave(this);
|
582
|
}
|
583
|
|
584
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
585
|
/**
|
586
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
587
|
* DistortedSlave interface, which should really be a class that we extend here instead but
|
588
|
* Java has no multiple inheritance.
|
589
|
*
|
590
|
* @y.exclude
|
591
|
*/
|
592
|
public void doWork()
|
593
|
{
|
594
|
int num = mJobs.size();
|
595
|
Job job;
|
596
|
|
597
|
for(int i=0; i<num; i++)
|
598
|
{
|
599
|
job = mJobs.remove(0);
|
600
|
|
601
|
switch(job.type)
|
602
|
{
|
603
|
case ATTACH: if( mChildren==null ) mChildren = new ArrayList<>(2);
|
604
|
job.node.setSurfaceParent(this);
|
605
|
DistortedMaster.addSorted(mChildren,job.node);
|
606
|
mNumChildren++;
|
607
|
break;
|
608
|
case DETACH: if( mNumChildren>0 && mChildren.remove(job.node) )
|
609
|
{
|
610
|
job.node.setSurfaceParent(null);
|
611
|
mNumChildren--;
|
612
|
}
|
613
|
break;
|
614
|
case DETALL: if( mNumChildren>0 )
|
615
|
{
|
616
|
DistortedNode tmp;
|
617
|
|
618
|
for(int j=mNumChildren-1; j>=0; j--)
|
619
|
{
|
620
|
tmp = mChildren.remove(j);
|
621
|
tmp.setSurfaceParent(null);
|
622
|
}
|
623
|
|
624
|
mNumChildren = 0;
|
625
|
}
|
626
|
break;
|
627
|
case SORT : job.node.setPost(job.dep);
|
628
|
mChildren.remove(job.node);
|
629
|
DistortedMaster.addSorted(mChildren,job.node);
|
630
|
break;
|
631
|
}
|
632
|
}
|
633
|
}
|
634
|
}
|