Home | History | Annotate | Download | only in fountainfbo
      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.example.android.rs.fountainfbo;
     18 
     19 
     20 import android.renderscript.RSSurfaceView;
     21 import android.renderscript.RenderScriptGL;
     22 import android.content.Context;
     23 import android.view.SurfaceHolder;
     24 import android.view.MotionEvent;
     25 
     26 public class FountainFboView extends RSSurfaceView {
     27 
     28     public FountainFboView(Context context) {
     29         super(context);
     30     }
     31 
     32     private RenderScriptGL mRS;
     33     private FountainFboRS mRender;
     34 
     35     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
     36         super.surfaceChanged(holder, format, w, h);
     37         if (mRS == null) {
     38             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
     39             mRS = createRenderScriptGL(sc);
     40             mRS.setSurface(holder, w, h);
     41             mRender = new FountainFboRS();
     42             mRender.init(mRS, getResources());
     43         }
     44     }
     45 
     46     @Override
     47     protected void onDetachedFromWindow() {
     48         super.onDetachedFromWindow();
     49         android.util.Log.e("rs", "onDetachedFromWindow");
     50         if (mRS != null) {
     51             mRS = null;
     52             destroyRenderScriptGL();
     53         }
     54     }
     55 
     56 
     57     @Override
     58     public boolean onTouchEvent(MotionEvent ev)
     59     {
     60         int act = ev.getActionMasked();
     61         if (act == ev.ACTION_UP) {
     62             mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0));
     63             return false;
     64         } else if (act == MotionEvent.ACTION_POINTER_UP) {
     65             // only one pointer going up, we can get the index like this
     66             int pointerIndex = ev.getActionIndex();
     67             int pointerId = ev.getPointerId(pointerIndex);
     68             mRender.newTouchPosition(0, 0, 0, pointerId);
     69         }
     70         int count = ev.getHistorySize();
     71         int pcount = ev.getPointerCount();
     72 
     73         for (int p=0; p < pcount; p++) {
     74             int id = ev.getPointerId(p);
     75             mRender.newTouchPosition(ev.getX(p),
     76                                      ev.getY(p),
     77                                      ev.getPressure(p),
     78                                      id);
     79 
     80             for (int i=0; i < count; i++) {
     81                 mRender.newTouchPosition(ev.getHistoricalX(p, i),
     82                                          ev.getHistoricalY(p, i),
     83                                          ev.getHistoricalPressure(p, i),
     84                                          id);
     85             }
     86         }
     87         return true;
     88     }
     89 }
     90 
     91 
     92