Project

General

Profile

« Previous | Next » 

Revision f28fffc2

Added by Leszek Koltunski about 7 years ago

A Lot of fixes for the issues uncovered by Olimpic.

Still at least 1 known issue: sometimes, when we re-add a Surface, some garbage pops up on the screen for a brief split second. Visible in Olimpic.

View differences:

src/main/java/org/distorted/library/DistortedSurface.java
19 19

  
20 20
package org.distorted.library;
21 21

  
22
import java.util.HashMap;
22 23
import java.util.LinkedList;
23 24

  
24 25
///////////////////////////////////////////////////////////////////////////////////////////////////
......
40 41
  static final int TYPE_TREE = 1;
41 42
  static final int TYPE_SYST = 2;
42 43

  
44
  private static final int JOB_CREATE = 0;
45
  private static final int JOB_DELETE = 1;
46

  
47
  private class Job
48
    {
49
    DistortedSurface surface;
50
    int action;
51

  
52
    Job(DistortedSurface s, int a)
53
      {
54
      surface = s;
55
      action  = a;
56
      }
57
    }
58

  
43 59
  private static boolean mToDo = false;
44 60
  private static LinkedList<DistortedSurface> mDoneList = new LinkedList<>();
45
  private static LinkedList<DistortedSurface> mToDoList = new LinkedList<>();
61
  private static HashMap<Long,Job> mToDoList = new HashMap<>();
46 62
  private static long mNextClientID = 0;
47 63
  private static long mNextSystemID = 0;
48 64

  
49 65
  private long mID;
50
  private boolean mMarked;
51 66
  private int mType;
52 67
  int mColorCreated;
53 68
  int[] mColorH = new int[1];
......
66 81
    {
67 82
    if( mToDo )
68 83
      {
84
      Job job;
69 85
      DistortedSurface surface;
70 86

  
71
      int num = mToDoList.size();
72

  
73
      for(int i=0; i<num; i++)
87
      for(Long key: mToDoList.keySet())
74 88
        {
75
        surface = mToDoList.removeFirst();
89
        job = mToDoList.get(key);
90
        surface = job.surface;
76 91

  
77
        if(surface.mMarked)
78
          {
79
          surface.delete();
80
          surface.mMarked = false;
81
          }
82
        else
92
        android.util.Log.d("SURFACE", "  ---> need to "+(job.action==JOB_CREATE ? "create":"delete")+" surfaceID="+surface.getID() );
93

  
94
        if( job.action==JOB_CREATE )
83 95
          {
84 96
          surface.create();
85 97
          mDoneList.add(surface);
86 98
          }
99
        else if( job.action==JOB_DELETE )
100
          {
101
          surface.delete();
102
          }
87 103
        }
88 104

  
105
      mToDoList.clear();
89 106
      mToDo = false;
90 107
      }
91 108
    }
......
94 111

  
95 112
  static synchronized void onDestroy()
96 113
    {
114
    Job job;
97 115
    DistortedSurface surface;
98 116

  
99
    int num = mDoneList.size();
100

  
101
    for(int i=0; i<num; i++)
117
    for(Long key: mToDoList.keySet())
102 118
      {
103
      surface = mDoneList.removeFirst();
119
      job = mToDoList.get(key);
104 120

  
105
      if( surface.mType==TYPE_SYST )
121
      if( job.surface.mType==TYPE_SYST )
106 122
        {
107
        mToDoList.add(surface);
108
        surface.recreate();
123
        mDoneList.add(job.surface);
109 124
        }
110 125
      }
111 126

  
112
    num = mToDoList.size();
127
    mToDoList.clear();
128

  
129
    int num = mDoneList.size();
113 130

  
114 131
    for(int i=0; i<num; i++)
115 132
      {
116
      surface = mToDoList.get(i);
133
      surface = mDoneList.removeFirst();
117 134

  
118
      if( surface.mType!=TYPE_SYST )
135
      if( surface.mType==TYPE_SYST )
119 136
        {
120
        mDoneList.remove(i);
121
        i--;
122
        num--;
137
        mToDoList.put(surface.getID(), surface.new Job(surface,JOB_CREATE) );
138
        surface.recreate();
123 139
        }
124 140
      }
125 141

  
126
    mToDo = (num>0);
142
    mToDo = true;
127 143
    mNextClientID = 0;
128 144
    }
129 145

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

  
132
  synchronized void moveToToDo()
133
    {
134
    if ( mDoneList.remove(this) )
135
      {
136
      mToDoList.add(this);
137
      mToDo = true;
138
      }
139
    }
140

  
141 146
///////////////////////////////////////////////////////////////////////////////////////////////////
142 147

  
143 148
  @SuppressWarnings("unused")
144 149
  static void debugLists()
145 150
    {
146 151
    android.util.Log.e("Surface", "Done list:");
147
    debugList(mDoneList);
152

  
153
    DistortedSurface surface;
154
    int num = mDoneList.size();
155

  
156
    for(int i=0; i<num; i++)
157
      {
158
      surface = mDoneList.get(i);
159
      surface.print(i, "");
160
      }
161

  
148 162
    android.util.Log.e("Surface", "ToDo list:");
149
    debugList(mToDoList);
163

  
164
    Job job;
165
    int i=0;
166

  
167
    for(Long key: mToDoList.keySet())
168
      {
169
      job = mToDoList.get(key);
170
      job.surface.print(i++, job.action==JOB_CREATE ? " create":" delete");
171
      }
150 172
    }
151 173

  
152 174
///////////////////////////////////////////////////////////////////////////////////////////////////
153 175

  
154
  private static void debugList(LinkedList<DistortedSurface> list)
176
  private void print(int i, String extra)
155 177
    {
156
    DistortedSurface surface;
157 178
    String str;
158 179

  
159
    int num = list.size();
180
    if( this instanceof DistortedFramebuffer ) str = (i+": Framebuffer ");
181
    else if( this instanceof DistortedTexture) str = (i+": Texture     ");
182
    else if( this instanceof DistortedScreen ) str = (i+": Screen      ");
183
    else                                       str = (i+": UNKNOWN     ");
160 184

  
161
    for(int i=0; i<num; i++)
162
      {
163
      surface = list.get(i);
164

  
165
      if( surface instanceof DistortedFramebuffer ) str = (i+": Framebuffer ");
166
      else if( surface instanceof DistortedTexture) str = (i+": Texture     ");
167
      else if( surface instanceof DistortedScreen ) str = (i+": Screen      ");
168
      else                                          str = (i+": UNKNOWN     ");
169

  
170
      str += ("("+surface.getWidth()+","+surface.getHeight()+") surfaceID:"+surface.getID());
185
    str += ("("+getWidth()+","+getHeight()+") surfaceID:"+getID());
171 186

  
172
      switch(surface.mType)
173
        {
174
        case TYPE_SYST: str+=" SYSTEM"; break;
175
        case TYPE_USER: str+=" USER"  ; break;
176
        case TYPE_TREE: str+=" TREE"  ; break;
177
        default       : str+=" ERROR??";
178
        }
179

  
180
      android.util.Log.e("Surface", str);
187
    switch(mType)
188
      {
189
      case TYPE_SYST: str+=" SYSTEM"; break;
190
      case TYPE_USER: str+=" USER"  ; break;
191
      case TYPE_TREE: str+=" TREE"  ; break;
192
      default       : str+=" ERROR??";
181 193
      }
194

  
195
    android.util.Log.e("Surface", str+extra);
182 196
    }
183 197

  
184 198
///////////////////////////////////////////////////////////////////////////////////////////////////
......
189 203
    mSizeY        = height;
190 204
    mColorCreated = create;
191 205
    mColorH[0]    = 0;
192
    mMarked       = false;
193 206
    mID           = type==TYPE_SYST ? --mNextSystemID : ++mNextClientID;
194 207
    mType         = type;
195 208

  
196 209
    if( create!=DONT_CREATE )
197 210
      {
198
      mToDoList.add(this);
211
      mToDoList.put(mID, new Job(this,JOB_CREATE) );
199 212
      mToDo = true;
200 213
      }
201 214
    }
202 215

  
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

  
218
  synchronized void markForCreation()
219
    {
220
    mDoneList.remove(this);
221
    mToDoList.put(mID, new Job(this,JOB_CREATE) );
222
    mToDo = true;
223
    }
224

  
203 225
///////////////////////////////////////////////////////////////////////////////////////////////////
204 226
// PUBLIC API
205 227
///////////////////////////////////////////////////////////////////////////////////////////////////
206 228
/**
207 229
 * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
208 230
 */
209
  public void markForDeletion()
231
  synchronized public void markForDeletion()
210 232
    {
211
    if( !mMarked )
212
      {
213
      mToDo   = true;
214
      mMarked = true;
215
      mDoneList.remove(this);
216
      mToDoList.add(this);
217
      }
233
    mDoneList.remove(this);
234
    mToDoList.put(mID, new Job(this,JOB_DELETE) );
235
    mToDo = true;
218 236
    }
219 237

  
220 238
////////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff