1 /* 2 * Copyright (C) 2008 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.rs.test_v11; 18 19 import java.io.Writer; 20 import java.util.ArrayList; 21 import java.util.concurrent.Semaphore; 22 23 import android.renderscript.RSSurfaceView; 24 import android.renderscript.RenderScript; 25 import android.renderscript.RenderScriptGL; 26 27 import android.content.Context; 28 import android.content.res.Resources; 29 import android.graphics.Bitmap; 30 import android.graphics.drawable.BitmapDrawable; 31 import android.graphics.drawable.Drawable; 32 import android.os.Handler; 33 import android.os.Message; 34 import android.util.AttributeSet; 35 import android.util.Log; 36 import android.view.Surface; 37 import android.view.SurfaceHolder; 38 import android.view.SurfaceView; 39 import android.view.KeyEvent; 40 import android.view.MotionEvent; 41 42 public class RSTestView extends RSSurfaceView { 43 44 private Context mCtx; 45 46 public RSTestView(Context context) { 47 super(context); 48 mCtx = context; 49 //setFocusable(true); 50 } 51 52 private RenderScriptGL mRS; 53 private RSTestCore mRender; 54 55 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 56 super.surfaceChanged(holder, format, w, h); 57 if (mRS == null) { 58 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); 59 mRS = createRenderScriptGL(sc); 60 mRS.setSurface(holder, w, h); 61 mRender = new RSTestCore(mCtx); 62 mRender.init(mRS, getResources(), w, h); 63 } 64 } 65 66 @Override 67 protected void onDetachedFromWindow() { 68 if(mRS != null) { 69 mRender.cleanup(); 70 mRS = null; 71 destroyRenderScriptGL(); 72 } 73 } 74 75 @Override 76 public boolean onKeyDown(int keyCode, KeyEvent event) 77 { 78 return super.onKeyDown(keyCode, event); 79 } 80 81 @Override 82 public boolean onTouchEvent(MotionEvent ev) 83 { 84 boolean ret = false; 85 int act = ev.getAction(); 86 if (act == ev.ACTION_DOWN) { 87 mRender.onActionDown((int)ev.getX(), (int)ev.getY()); 88 ret = true; 89 } 90 else if (act == ev.ACTION_MOVE) { 91 mRender.onActionMove((int)ev.getX(), (int)ev.getY()); 92 ret = true; 93 } 94 95 return ret; 96 } 97 } 98