1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.testapp; 18 19 import android.renderscript.RSSurfaceView; 20 import android.renderscript.RenderScript; 21 import android.renderscript.RenderScriptGL; 22 23 import android.content.Context; 24 import android.content.res.Resources; 25 import android.util.Log; 26 import android.view.Surface; 27 import android.view.SurfaceHolder; 28 import android.view.SurfaceView; 29 30 public class SimpleAppView extends RSSurfaceView { 31 32 public SimpleAppView(Context context) { 33 super(context); 34 } 35 36 private RenderScriptGL mRS; 37 SimpleAppRS mRender; 38 39 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 40 super.surfaceChanged(holder, format, w, h); 41 if (mRS == null) { 42 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); 43 sc.setDepth(16, 24); 44 sc.setSamples(1, 2, 1); 45 mRS = createRenderScriptGL(sc); 46 mRS.setSurface(holder, w, h); 47 mRender = new SimpleAppRS(); 48 mRender.init(mRS, getResources(), w, h); 49 } 50 } 51 52 @Override 53 protected void onDetachedFromWindow() { 54 if (mRS != null) { 55 mRender = null; 56 mRS = null; 57 destroyRenderScriptGL(); 58 } 59 } 60 } 61 62 63