Project

General

Profile

« Previous | Next » 

Revision b0ebdf5e

Added by Leszek Koltunski about 7 years ago

Major:

1) in the Library, fix the fact that some applications (those that were creating their DistortedSurface objects outside of onSurfaceCreated or onSurfaceChanged) would not render after the activity went to background (press POWER to see that).
2) in the Apps, call the new 'Distorted.onPause()' API to fix the above problem

The above fixes the problem, but it still leaks memory if an App creates its Surface in onSurfaceCreated/Changed (precisely: it leaves the old Surface in the DistortedSurface Map). Thus

3) Fix the first 15 Apps to avoid the memory leak. Next Apps coming.

View differences:

src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldActivity.java
58 58
      {
59 59
      AroundTheWorldSurfaceView view = (AroundTheWorldSurfaceView) this.findViewById(R.id.aroundTheWorldSurfaceView);
60 60
      view.onPause();
61

  
61
      Distorted.onPause();
62 62
      super.onPause();
63 63
      }
64 64

  
src/main/java/org/distorted/examples/bean/BeanActivity.java
45 45
    @Override
46 46
    protected void onPause() 
47 47
      {
48
      Distorted.onPause();
48 49
      mView.onPause();  
49 50
      super.onPause();
50 51
      }
src/main/java/org/distorted/examples/bean/BeanRenderer.java
40 40

  
41 41
import android.graphics.Bitmap;
42 42
import android.graphics.BitmapFactory;
43
import android.opengl.GLES30;
44 43
import android.opengl.GLSurfaceView;
45 44

  
46 45
///////////////////////////////////////////////////////////////////////////////////////////////////
......
50 49
   private GLSurfaceView mView;
51 50
   private DistortedEffects mEffects;
52 51
   private DistortedScreen mScreen;
52
   private DistortedTexture mTexture;
53 53
   private int bmpHeight, bmpWidth;
54 54
    
55 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
147 147
      bmpHeight = bitmap.getHeight();
148 148
      bmpWidth  = bitmap.getWidth();
149 149
      
150
      DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
151
      texture.setTexture(bitmap);
152
      MeshFlat mesh = new MeshFlat(25,25*bmpHeight/bmpWidth);
150
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
151
      mTexture.setTexture(bitmap);
153 152

  
154 153
      mScreen.detachAll();
155
      mScreen.attach(texture,mEffects,mesh);
154
      mScreen.attach(mTexture,mEffects,new MeshFlat(25,25*bmpHeight/bmpWidth));
156 155

  
157 156
      DistortedEffects.enableEffect(EffectNames.DISTORT);
158 157

  
src/main/java/org/distorted/examples/blur/BlurActivity.java
59 59
      {
60 60
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.blurSurfaceView);
61 61
      view.onPause();
62
      
62
      Distorted.onPause();
63 63
      super.onPause();
64 64
      }
65 65

  
src/main/java/org/distorted/examples/catanddog/CatAndDogActivity.java
45 45
    @Override
46 46
    protected void onPause() 
47 47
      {
48
      Distorted.onPause();
48 49
      mView.onPause();
49 50
      super.onPause();
50 51
      }
src/main/java/org/distorted/examples/catanddog/CatAndDogRenderer.java
41 41

  
42 42
import android.graphics.Bitmap;
43 43
import android.graphics.BitmapFactory;
44
import android.opengl.GLES30;
45 44
import android.opengl.GLSurfaceView;
46 45

  
47 46
///////////////////////////////////////////////////////////////////////////////////////////////////
......
51 50
    private GLSurfaceView mView;
52 51
    private DistortedEffects mEffects;
53 52
    private MeshFlat mMesh;
53
    private DistortedTexture mTexture;
54 54
    private DistortedScreen mScreen;
55 55
    private int bmpHeight, bmpWidth;
56 56

  
......
111 111
      bmpHeight = bitmap.getHeight();
112 112
      bmpWidth  = bitmap.getWidth();
113 113

  
114
      DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
115
      texture.setTexture(bitmap);
114
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
115
      mTexture.setTexture(bitmap);
116 116

  
117 117
      mScreen.detachAll();
118
      mScreen.attach(texture,mEffects,mMesh);
118
      mScreen.attach(mTexture,mEffects,mMesh);
119 119

  
120 120
      DistortedEffects.enableEffect(EffectNames.SMOOTH_CHROMA);
121 121
      DistortedEffects.enableEffect(EffectNames.ALPHA);
src/main/java/org/distorted/examples/check/CheckActivity.java
78 78
      {
79 79
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.checkSurfaceView);
80 80
      if( mView!=null ) mView.onPause();
81
      
81

  
82
      Distorted.onPause();
82 83
      super.onPause();
83 84
      }
84 85

  
src/main/java/org/distorted/examples/check/CheckRenderer.java
58 58

  
59 59
    private GLSurfaceView mView;
60 60
    private DistortedEffects mEffects;
61
    private DistortedTexture mTexture;
61 62
    private DistortedScreen mScreen;
62 63
    private int bmpHeight, bmpWidth;
63 64

  
......
132 133
      bmpHeight = bitmap.getHeight();
133 134
      bmpWidth  = bitmap.getWidth();
134 135

  
135
      DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
136
      texture.setTexture(bitmap);
137
      MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
136
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
137
      mTexture.setTexture(bitmap);
138 138

  
139 139
      mScreen.detachAll();
140
      mScreen.attach(texture,mEffects,mesh);
140
      mScreen.attach(mTexture,mEffects,new MeshFlat(30,30*bmpHeight/bmpWidth));
141

  
142
      mEffects.abortEffects(EffectTypes.VERTEX);
143
      mEffects.abortEffects(EffectTypes.FRAGMENT);
141 144

  
142 145
      // Try adding 2 Vertex Effects to the Bitmap.
143 146
      // This will fail if we have set maxVertexEffects to something < 2.
src/main/java/org/distorted/examples/cubes/CubesActivity.java
166 166
      {
167 167
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.cubesSurfaceView);
168 168
      if( mView!=null ) mView.onPause();
169
        
169

  
170
      Distorted.onPause();
170 171
      super.onPause();
171 172
      }
172 173

  
src/main/java/org/distorted/examples/deform/DeformActivity.java
68 68
      {
69 69
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
70 70

  
71
      view.getRenderer().onPause();
71
      Distorted.onPause();
72 72
      view.onPause();
73 73
      super.onPause();
74 74
      }
src/main/java/org/distorted/examples/deform/DeformRenderer.java
79 79
   private float mRadius;
80 80

  
81 81
   private EffectNames mMode = EffectNames.DISTORT;
82
   private boolean bitmapCreated = false;
83 82
   private long mLastEffect = -1;
84 83

  
85 84
///////////////////////////////////////////////////////////////////////////////////////////////////
......
168 167
      mRegion.set3(mRadius*scrWidth);
169 168
      }
170 169

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
   public void onPause()
174
      {
175
      bitmapCreated = false;
176
      }
177
      
178 170
///////////////////////////////////////////////////////////////////////////////////////////////////
179 171
   
180 172
   public void onDrawFrame(GL10 glUnused)
......
200 192

  
201 193
     mRegion.set3(mRadius*scrWidth);
202 194

  
203
     if( !bitmapCreated )
204
       {
205
       createBitmap(scrWidth/2,scrHeight/2);
206
       stretchEffects.abortAllEffects();
207
       fpsEffects.abortAllEffects();
208
       stretchEffects.move( new Static3D(scrWidth/4,scrHeight/4,0) );
209
       fpsEffects.move( new Static3D(5,5,0) );
210
       bitmapCreated=true;
211

  
212
       mScreen.detachAll();
213
       mScreen.attach(stretchTexture,stretchEffects,stretchMesh);
214
       mScreen.attach(fpsTexture,fpsEffects,fpsMesh);
215
       }
216
     else
217
       {
218
       stretchEffects.abortEffects(EffectTypes.VERTEX);
219
       stretchEffects.abortEffects(EffectTypes.FRAGMENT);
220
       stretchEffects.abortEffects(EffectNames.SHEAR);
221
       }
222

  
223
     mScreen.resize(width, height);
224
     }
225

  
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227
    
228
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
229
     {
230
     DistortedEffects.enableEffect(EffectNames.DISTORT);
231
     DistortedEffects.enableEffect(EffectNames.DEFORM);
232

  
233
     try
234
       {
235
       Distorted.onCreate(mView.getContext());
236
       }
237
     catch(Exception ex)
238
       {
239
       android.util.Log.e("DeformRenderer", ex.toString() );
240
       }
241
     }
242
    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
   private void createBitmap(int w, int h)
246
     {
247 195
     Canvas stretchCanvas;
248
      
249
     stretchTexture = new DistortedTexture(w,h);
196
     int w=width/2;
197
     int h=height/2;
198

  
250 199
     stretchMesh = new MeshFlat(50,50*h/w);
251 200
     Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
252 201
     stretchCanvas = new Canvas(stretchBitmap);
253
      
202

  
254 203
     fpsW = scrWidth/5;
255 204
     fpsH = fpsW/2;
256 205

  
......
259 208
     mPaint.setStyle(Style.FILL);
260 209
     stretchCanvas.drawRect(0, 0, w, h, mPaint);
261 210
     mPaint.setColor(0xffffffff);
262
      
211

  
263 212
     for(int i=0; i<=NUM_LINES ; i++ )
264 213
       {
265 214
       stretchCanvas.drawRect(w*i/NUM_LINES - 1,                 0,  w*i/NUM_LINES + 1,  h                , mPaint);
266 215
       stretchCanvas.drawRect(                0, h *i/NUM_LINES -1,  w                ,  h*i/NUM_LINES + 1, mPaint);
267 216
       }
268
        
217

  
269 218
     touchPoint= new Static3D(0,0,0);
270
        
271
     fpsTexture = new DistortedTexture(fpsW,fpsH);
272 219
     fpsMesh = new MeshFlat(1,1);
273 220

  
274 221
     fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888);
275 222
     fpsCanvas = new Canvas(fpsBitmap);
276
        
223

  
224
     if( stretchTexture==null ) stretchTexture = new DistortedTexture(w,h);
277 225
     stretchTexture.setTexture(stretchBitmap);
226

  
227
     if( fpsTexture==null ) fpsTexture = new DistortedTexture(fpsW,fpsH);
278 228
     fpsTexture.setTexture(fpsBitmap);
229

  
230
     stretchEffects.abortAllEffects();
231
     fpsEffects.abortAllEffects();
232
     stretchEffects.move( new Static3D(scrWidth/4,scrHeight/4,0) );
233
     fpsEffects.move( new Static3D(5,5,0) );
234

  
235
     mScreen.detachAll();
236
     mScreen.attach(stretchTexture,stretchEffects,stretchMesh);
237
     mScreen.attach(fpsTexture,fpsEffects,fpsMesh);
238

  
239
     mScreen.resize(width, height);
240
     }
241

  
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
    
244
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
245
     {
246
     DistortedEffects.enableEffect(EffectNames.DISTORT);
247
     DistortedEffects.enableEffect(EffectNames.DEFORM);
248

  
249
     try
250
       {
251
       Distorted.onCreate(mView.getContext());
252
       }
253
     catch(Exception ex)
254
       {
255
       android.util.Log.e("DeformRenderer", ex.toString() );
256
       }
279 257
     }
280 258

  
281 259
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsActivity.java
45 45
    @Override
46 46
    protected void onPause() 
47 47
      {
48
      Distorted.onPause();
48 49
      mView.onPause();  
49 50
      super.onPause();
50 51
      }
src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
41 41

  
42 42
import android.graphics.Bitmap;
43 43
import android.graphics.BitmapFactory;
44
import android.opengl.GLES30;
45 44
import android.opengl.GLSurfaceView;
46 45

  
47 46
///////////////////////////////////////////////////////////////////////////////////////////////////
......
52 51
   
53 52
   private GLSurfaceView mView;
54 53
   private DistortedEffects[] mEffects;
54
   private DistortedTexture[] mTexture;
55 55
   private DistortedScreen mScreen;
56 56
   private int bmpHeight, bmpWidth;
57 57
    
......
156 156
      
157 157
      bmpHeight = bitmap0.getHeight();
158 158
      bmpWidth  = bitmap0.getWidth();
159
      
160
      DistortedTexture[] texture = new DistortedTexture[NUM];
161
      for(int i=0; i<NUM; i++)
162
        texture[i] = new DistortedTexture(bmpWidth,bmpHeight);
163
      
164
      texture[0].setTexture(bitmap0);
165
      texture[1].setTexture(bitmap1);
166
      texture[2].setTexture(bitmap2);
159

  
160
      if( mTexture==null )
161
        {
162
        mTexture = new DistortedTexture[NUM];
163

  
164
        for(int i=0; i<NUM; i++)
165
          mTexture[i] = new DistortedTexture(bmpWidth,bmpHeight);
166
        }
167

  
168
      mTexture[0].setTexture(bitmap0);
169
      mTexture[1].setTexture(bitmap1);
170
      mTexture[2].setTexture(bitmap2);
167 171

  
168 172
      MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
169 173

  
170 174
      mScreen.detachAll();
171
      for(int i=NUM-1; i>=0; i--) mScreen.attach(texture[i], mEffects[i], mesh);
175
      for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mesh);
172 176

  
173 177
      DistortedEffects.enableEffect(EffectNames.SINK);
174 178
      DistortedEffects.enableEffect(EffectNames.DISTORT);
src/main/java/org/distorted/examples/differenteffects/DifferentEffectsActivity.java
45 45
    @Override
46 46
    protected void onPause() 
47 47
      {
48
      Distorted.onPause();
48 49
      mView.onPause();  
49 50
      super.onPause();
50 51
      }
src/main/java/org/distorted/examples/differenteffects/DifferentEffectsRenderer.java
42 42

  
43 43
import android.graphics.Bitmap;
44 44
import android.graphics.BitmapFactory;
45
import android.opengl.GLES30;
46 45
import android.opengl.GLSurfaceView;
47 46

  
48 47
///////////////////////////////////////////////////////////////////////////////////////////////////
......
53 52
   
54 53
   private GLSurfaceView mView;
55 54
   private DistortedEffects[] mEffects;
55
   private DistortedTexture mTexture;
56 56
   private DistortedScreen mScreen;
57 57
   private int bmpHeight, bmpWidth;
58 58
    
......
163 163
     bmpWidth  = bitmap.getWidth();
164 164

  
165 165
     MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
166
     DistortedTexture texture  = new DistortedTexture(bmpWidth,bmpHeight);
167
     texture.setTexture(bitmap);
166
     if( mTexture==null ) mTexture  = new DistortedTexture(bmpWidth,bmpHeight);
167
     mTexture.setTexture(bitmap);
168 168

  
169 169
     mScreen.detachAll();
170
     for(int i=NUM-1; i>=0; i--) mScreen.attach(texture, mEffects[i], mesh);
170
     for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture, mEffects[i], mesh);
171 171

  
172 172
     DistortedEffects.enableEffect(EffectNames.SINK);
173 173
     DistortedEffects.enableEffect(EffectNames.DISTORT);
src/main/java/org/distorted/examples/dynamic/DynamicActivity.java
87 87
      {
88 88
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
89 89
      view.onPause();
90
         
90

  
91
      Distorted.onPause();
91 92
      super.onPause();
92 93
      }
93 94
    
src/main/java/org/distorted/examples/dynamic/DynamicRenderer.java
26 26
import android.graphics.Canvas;
27 27
import android.graphics.Paint;
28 28
import android.graphics.Paint.Style;
29
import android.opengl.GLES30;
30 29
import android.opengl.GLSurfaceView;
31 30

  
32 31
import org.distorted.library.DistortedEffects;
......
87 86
     texW = width;
88 87
     texH = height;
89 88

  
89
     if( mTexture!=null ) mTexture.markForDeletion();
90 90
     mTexture= new DistortedTexture(texW,texH);
91 91
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
92 92
     mCanvas = new Canvas(mBitmap);
src/main/java/org/distorted/examples/effectqueue/EffectQueueActivity.java
121 121
    {
122 122
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
123 123
    mView.onPause();
124
      
124

  
125
    Distorted.onPause();
125 126
    super.onPause();
126 127
    }
127 128
    
src/main/java/org/distorted/examples/effectqueue/EffectQueueRenderer.java
26 26
import android.graphics.Canvas;
27 27
import android.graphics.Paint;
28 28
import android.graphics.Paint.Style;
29
import android.opengl.GLES30;
30 29
import android.opengl.GLSurfaceView;
31 30

  
32 31
import org.distorted.library.DistortedEffects;
src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
615 615
    {
616 616
    GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.effects3dSurfaceView);
617 617
    if( mView!=null ) mView.onPause();
618

  
619
    Distorted.onPause();
618 620
    super.onPause();
619 621
    }
620 622

  
src/main/java/org/distorted/examples/fbo/FBOActivity.java
54 54
      FBOSurfaceView view = (FBOSurfaceView) this.findViewById(R.id.fboSurfaceView);
55 55

  
56 56
      view.onPause();
57
      Distorted.onPause();
57 58
      super.onPause();
58 59
      }
59 60

  
src/main/java/org/distorted/examples/flag/FlagActivity.java
102 102
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView);
103 103
      mView.onPause();
104 104

  
105
      Distorted.onPause();
105 106
      super.onPause();
106 107
      }
107 108

  
src/main/java/org/distorted/examples/girl/GirlActivity.java
72 72
      {
73 73
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.girlSurfaceView);
74 74
      view.onPause();
75
      
75

  
76
      Distorted.onPause();
76 77
      super.onPause();
77 78
      }
78 79

  
src/main/java/org/distorted/examples/girl/GirlRenderer.java
42 42

  
43 43
import android.graphics.Bitmap;
44 44
import android.graphics.BitmapFactory;
45
import android.opengl.GLES30;
46 45
import android.opengl.GLSurfaceView;
47 46

  
48 47
///////////////////////////////////////////////////////////////////////////////////////////////////
......
52 51
    private GLSurfaceView mView;
53 52
    private DistortedEffects mEffects;
54 53
    private DistortedScreen mScreen;
54
    private DistortedTexture mTexture;
55 55
    private Static3D v0,v1,v2,v3;
56 56
    private Static1D dBegin, dMiddle, dEnd, s0;
57 57
    private int bmpHeight, bmpWidth;
......
204 204
      bmpHeight = bitmap.getHeight();
205 205
      bmpWidth  = bitmap.getWidth();
206 206

  
207
      MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
208
      DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
209
      texture.setTexture(bitmap);
207
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
208
      mTexture.setTexture(bitmap);
210 209

  
211 210
      mScreen.detachAll();
212
      mScreen.attach(texture,mEffects,mesh);
211
      mScreen.attach(mTexture,mEffects,new MeshFlat(30,30*bmpHeight/bmpWidth));
213 212

  
214 213
      DistortedEffects.enableEffect(EffectNames.DISTORT);
215 214
      DistortedEffects.enableEffect(EffectNames.SINK);
src/main/java/org/distorted/examples/listener/ListenerActivity.java
45 45
    @Override
46 46
    protected void onPause() 
47 47
      {
48
      mView.onPause();  
48
      mView.onPause();
49
      Distorted.onPause();
49 50
      super.onPause();
50 51
      }
51 52

  
src/main/java/org/distorted/examples/listener/ListenerRenderer.java
43 43

  
44 44
import android.graphics.Bitmap;
45 45
import android.graphics.BitmapFactory;
46
import android.opengl.GLES30;
47 46
import android.opengl.GLSurfaceView;
48 47

  
49 48
///////////////////////////////////////////////////////////////////////////////////////////////////
......
55 54
   private GLSurfaceView mView;
56 55
   private DistortedEffects mEffects;
57 56
   private DistortedScreen mScreen;
57
   private DistortedTexture mTexture;
58 58
   private int bmpHeight, bmpWidth;
59 59
   private Random mRnd;
60 60

  
......
155 155
      bmpHeight = bitmap.getHeight();
156 156
      bmpWidth  = bitmap.getWidth();
157 157

  
158
      MeshFlat mesh = new MeshFlat(50,50*bmpHeight/bmpWidth);
159
      DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
160
      texture.setTexture(bitmap);
158
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
159
      mTexture.setTexture(bitmap);
161 160

  
162 161
      mScreen.detachAll();
163
      mScreen.attach(texture,mEffects,mesh);
162
      mScreen.attach(mTexture,mEffects,new MeshFlat(50,50*bmpHeight/bmpWidth));
164 163

  
165 164
      for(int i=0; i<NUM_BUBBLES; i++) randomizeNewBubble();
166 165

  
src/main/java/org/distorted/examples/matrix3d/Matrix3DActivity.java
318 318
    {
319 319
    GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.matrix3dSurfaceView);
320 320
    if( mView!=null ) mView.onPause();
321

  
322
    Distorted.onPause();
321 323
    super.onPause();
322 324
    }
323 325

  
src/main/java/org/distorted/examples/mirror/MirrorActivity.java
54 54
      {
55 55
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.mirrorSurfaceView);
56 56
      view.onPause();
57

  
58
      Distorted.onPause();
57 59
      super.onPause();
58 60
      }
59 61

  
src/main/java/org/distorted/examples/monalisa/MonaLisaActivity.java
45 45
    @Override
46 46
    protected void onPause() 
47 47
      {
48
      mView.onPause();  
48
      mView.onPause();
49
      Distorted.onPause();
49 50
      super.onPause();
50 51
      }
51 52

  
src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
39 39

  
40 40
import android.graphics.Bitmap;
41 41
import android.graphics.BitmapFactory;
42
import android.opengl.GLES30;
43 42
import android.opengl.GLSurfaceView;
44 43

  
45 44
///////////////////////////////////////////////////////////////////////////////////////////////////
......
48 47
{
49 48
    private GLSurfaceView mView;
50 49
    private DistortedEffects mEffects;
50
    private DistortedTexture mTexture;
51 51
    private DistortedScreen mScreen;
52 52
    private int bmpHeight, bmpWidth;
53 53

  
......
130 130
      bmpHeight = bitmap.getHeight();
131 131
      bmpWidth  = bitmap.getWidth();
132 132

  
133
      MeshFlat mesh = new MeshFlat(9,9*bmpHeight/bmpWidth);
134
      DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
135
      texture.setTexture(bitmap);
133
      // We could have gotten here after the activity went to the background
134
      // for a brief amount of time; in this case mTexture is already created.
135
      // Do not leak memory by creating it the second time around.
136
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
137

  
138
      // even if mTexture wasn't null, we still need to call setTexture() on it
139
      // because every time activity goes to background, its OpenGL resources
140
      // - including Textures - get deleted. We always need to call setTexture()
141
      // to recreate the internal OpenGL textures.
142
      mTexture.setTexture(bitmap);
136 143

  
137 144
      mScreen.detachAll();
138
      mScreen.attach(texture,mEffects,mesh);
145
      mScreen.attach(mTexture,mEffects,new MeshFlat(9,9*bmpHeight/bmpWidth));
139 146

  
140 147
      DistortedEffects.enableEffect(EffectNames.DISTORT);
141 148

  
src/main/java/org/distorted/examples/movingeffects/MovingEffectsActivity.java
85 85
      
86 86
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.movingeffectsSurfaceView);
87 87
      view.onPause();
88
      
88

  
89
      Distorted.onPause();
89 90
      super.onPause();
90 91
      }
91 92
    
src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java
26 26
import android.graphics.Canvas;
27 27
import android.graphics.Paint;
28 28
import android.graphics.Paint.Style;
29
import android.opengl.GLES30;
30 29
import android.opengl.GLSurfaceView;
31 30

  
32 31
import org.distorted.library.DistortedScreen;
......
132 131
     texW = width;
133 132
     texH = height;
134 133

  
134
     if( mTexture!=null ) mTexture.markForDeletion();
135 135
     mTexture = new DistortedTexture(texW,texH);
136 136
     mBitmap  = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
137 137
     mCanvas  = new Canvas(mBitmap);
src/main/java/org/distorted/examples/multiblur/MultiblurActivity.java
61 61
      {
62 62
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.multiblurSurfaceView);
63 63
      view.onPause();
64
      Distorted.onPause();
64 65
      super.onPause();
65 66
      }
66 67

  
src/main/java/org/distorted/examples/olimpic/OlimpicActivity.java
143 143
      {
144 144
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.olimpicSurfaceView);
145 145
      view.onPause();
146
      Distorted.onPause();
146 147
      super.onPause();
147 148
      }
148 149

  
src/main/java/org/distorted/examples/plainmonalisa/PlainMonaLisaActivity.java
46 46
    protected void onPause() 
47 47
      {
48 48
      mView.onPause();
49
      Distorted.onPause();
49 50
      super.onPause();
50 51
      }
51 52

  
src/main/java/org/distorted/examples/projection/ProjectionActivity.java
71 71
      {
72 72
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.surfaceViewProjection);
73 73
      mView.onPause();
74
      
74

  
75
      Distorted.onPause();
75 76
      super.onPause();
76 77
      }
77 78

  
src/main/java/org/distorted/examples/projection/ProjectionRenderer.java
35 35
import android.graphics.Canvas;
36 36
import android.graphics.Paint;
37 37
import android.graphics.Paint.Style;
38
import android.opengl.GLES30;
39 38
import android.opengl.GLSurfaceView;
40 39

  
41 40
///////////////////////////////////////////////////////////////////////////////////////////////////
......
45 44
   private GLSurfaceView mView;
46 45
   private DistortedEffects mEffects;
47 46
   private DistortedScreen mScreen;
48

  
47
   private DistortedTexture mTexture;
49 48
   private float mF, mNear;
50 49

  
51 50
///////////////////////////////////////////////////////////////////////////////////////////////////
......
90 89
      mEffects.abortAllEffects();
91 90

  
92 91
      Paint paint = new Paint();
93
      DistortedTexture texture= new DistortedTexture(width,height);
94
      MeshFlat mesh = new MeshFlat(50,50*height/width);
95 92
      Bitmap bmp  = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
96 93
      Canvas bmpCanvas = new Canvas(bmp);
97 94

  
......
108 105
        bmpCanvas.drawRect(                   0, height*i/NUMLINES -1,  width               ,  height*i/NUMLINES + 1, paint);
109 106
        }
110 107

  
111
      texture.setTexture(bmp);
112

  
113 108
      int min = width<height ? width:height;
114 109

  
115 110
      Static3D vector = new Static3D(0,0,min/5);
......
120 115
      mEffects.distort(vector, new Static3D(  width/4, 3*height/4, 0), region);
121 116
      mEffects.distort(vector, new Static3D(3*width/4, 3*height/4, 0), region);
122 117

  
118
      // Avoid memory leaks: delete old texture if it exists (it might if we
119
      // got here after a brief amount of time spent in the background)
120
      if( mTexture!=null ) mTexture.markForDeletion();
121

  
122
      mTexture= new DistortedTexture(width,height);
123
      mTexture.setTexture(bmp);
124

  
123 125
      mScreen.detachAll();
124
      mScreen.attach(texture,mEffects,mesh);
126
      mScreen.attach(mTexture,mEffects,new MeshFlat(50,50*height/width));
125 127
      mScreen.resize(width, height);
126 128
      }
127 129

  
src/main/java/org/distorted/examples/quaternion/QuaternionActivity.java
45 45
  @Override
46 46
  protected void onPause() 
47 47
    {
48
    mView.onPause();  
48
    mView.onPause();
49
    Distorted.onPause();
49 50
    super.onPause();
50 51
    }
51 52

  
src/main/java/org/distorted/examples/save/SaveActivity.java
81 81
    {
82 82
    GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
83 83
    view.onPause();
84
      
84

  
85
    Distorted.onPause();
85 86
    super.onPause();
86 87
    }
87 88

  
src/main/java/org/distorted/examples/sink/SinkActivity.java
45 45
  @Override
46 46
  protected void onPause() 
47 47
    {
48
    mView.onPause();  
48
    mView.onPause();
49
    Distorted.onPause();
49 50
    super.onPause();
50 51
    }
51 52

  
src/main/java/org/distorted/examples/sink/SinkRenderer.java
40 40

  
41 41
import android.graphics.Bitmap;
42 42
import android.graphics.BitmapFactory;
43
import android.opengl.GLES30;
44 43
import android.opengl.GLSurfaceView;
45 44

  
46 45
///////////////////////////////////////////////////////////////////////////////////////////////////
......
50 49
  private GLSurfaceView mView;
51 50
  private DistortedEffects mEffects;
52 51
  private DistortedScreen mScreen;
52
  private DistortedTexture mTexture;
53 53
  private int bmpHeight, bmpWidth;
54 54
    
55 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
124 124
    bmpHeight = bitmap.getHeight();
125 125
    bmpWidth  = bitmap.getWidth();
126 126

  
127
    MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
128
    DistortedTexture texture = new DistortedTexture(bmpWidth,bmpHeight);
129
    texture.setTexture(bitmap);
127
    if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
128
    mTexture.setTexture(bitmap);
130 129

  
131 130
    mScreen.detachAll();
132
    mScreen.attach(texture,mEffects,mesh);
131
    mScreen.attach(mTexture,mEffects,new MeshFlat(30,30*bmpHeight/bmpWidth));
133 132

  
134 133
    DistortedEffects.enableEffect(EffectNames.SINK);
135 134

  
src/main/java/org/distorted/examples/starwars/StarWarsActivity.java
47 47
    {
48 48
    mView.onPause();
49 49
    mView.getRenderer().onPause();
50
    Distorted.onPause();
50 51
    super.onPause();
51 52
    }
52 53

  
src/main/java/org/distorted/examples/wind/WindActivity.java
60 60
      {
61 61
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.windSurfaceView);
62 62
      view.onPause();
63
      Distorted.onPause();
63 64
      super.onPause();
64 65
      }
65 66

  
src/main/res/values/strings.xml
78 78

  
79 79
    <string name="example_monalisa">Mona Lisa</string>  
80 80
    <string name="example_monalisa_subtitle">The basics of Distortions.</string>
81
    <string name="example_sink">Cat</string>
81
    <string name="example_sink">Sink</string>
82 82
    <string name="example_sink_subtitle">Learn about sinks.</string>
83 83
    <string name="example_bean">Mr. Bean</string>  
84 84
    <string name="example_bean_subtitle">Interpolation between more than two Points.</string>

Also available in: Unified diff