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 import android.view.WindowManager; 10 import android.app.Service; 11 import android.util.Log; 12 import android.util.DisplayMetrics; 13 14 public class GalaxyView extends RSSurfaceView { 15 16 private RenderScriptGL mRS; 17 private GalaxyRS mRender; 18 GalaxyView(Context context)19 public GalaxyView(Context context) { 20 super(context); 21 setFocusable(true); 22 setFocusableInTouchMode(true); 23 } 24 surfaceChanged(SurfaceHolder holder, int format, int w, int h)25 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 26 super.surfaceChanged(holder, format, w, h); 27 if (mRS == null) { 28 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); 29 mRS = createRenderScriptGL(sc); 30 mRS.setSurface(holder, w, h); 31 32 DisplayMetrics metrics = new DisplayMetrics(); 33 ((WindowManager) getContext() 34 .getSystemService(Service.WINDOW_SERVICE)) 35 .getDefaultDisplay().getMetrics(metrics); 36 37 mRender = new GalaxyRS(); 38 mRender.init(metrics.densityDpi, mRS, getResources(), w, h); 39 } else { 40 mRender.createProgramVertex(); 41 } 42 } 43 44 @Override onDetachedFromWindow()45 protected void onDetachedFromWindow() { 46 if (mRS != null) { 47 mRS.setSurface(null, 0, 0); 48 mRS = null; 49 destroyRenderScriptGL(); 50 } 51 } 52 53 } 54