• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.galaxy4;
2 
3 import android.content.Context;
4 import android.graphics.PixelFormat;
5 import android.renderscript.RSSurfaceView;
6 import android.renderscript.RenderScriptGL;
7 import android.renderscript.RenderScriptGL.SurfaceConfig;
8 import android.view.SurfaceHolder;
9 
10 public class GalaxyView extends RSSurfaceView {
11 
12     private RenderScriptGL mRS;
13     private GalaxyRS mRender;
14 
GalaxyView(Context context)15     public GalaxyView(Context context) {
16         super(context);
17         setFocusable(true);
18         setFocusableInTouchMode(true);
19         // getHolder().setFormat(PixelFormat.TRANSPARENT);
20     }
21 
surfaceChanged(SurfaceHolder holder, int format, int w, int h)22     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
23         super.surfaceChanged(holder, format, w, h);
24 
25         if (mRS == null) {
26             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
27             mRS = createRenderScriptGL(sc);
28             mRS.setSurface(holder, w, h);
29 
30             mRender = new GalaxyRS();
31             mRender.init(mRS, getResources(), w, h);
32         }
33 
34     }
35 
36     @Override
onDetachedFromWindow()37     protected void onDetachedFromWindow() {
38         if (mRS != null) {
39             mRS.setSurface(null, 0, 0);
40             mRS = null;
41             destroyRenderScriptGL();
42         }
43     }
44 
45 }
46