Home | History | Annotate | Download | only in noisefield
      1 package com.android.noisefield;
      2 
      3 import android.content.Context;
      4 import android.renderscript.RSSurfaceView;
      5 import android.renderscript.RenderScriptGL;
      6 import android.view.SurfaceHolder;
      7 
      8 public class NoiseFieldView extends RSSurfaceView {
      9 
     10     private RenderScriptGL mRS;
     11     private NoiseFieldRS mRender;
     12 
     13     public NoiseFieldView(Context context) {
     14         super(context);
     15         setFocusable(true);
     16         setFocusableInTouchMode(true);
     17     }
     18 
     19     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
     20         super.surfaceChanged(holder, format, w, h);
     21 
     22         if (mRS == null) {
     23             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
     24             mRS = createRenderScriptGL(sc);
     25             mRS.setSurface(holder, w, h);
     26 
     27             mRender = new NoiseFieldRS();
     28             mRender.init(240, mRS, getResources(), w, h);
     29         }
     30     }
     31 
     32     @Override
     33     protected void onDetachedFromWindow() {
     34         if (mRS != null) {
     35             mRS.setSurface(null, 0, 0);
     36             mRS = null;
     37             destroyRenderScriptGL();
     38         }
     39     }
     40 
     41 }