blob: 86367171d9f6d3d9b29b0165b5f426047dbbbf39 [file] [log] [blame]
Jason Samse5f2f662012-05-16 15:43:25 -07001/*
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
17package com.example.android.rs.fountainfbo;
18
19
Stephen Hines0e1207e2013-05-06 18:18:57 -070020import android.renderscript.RSSurfaceView;
Jason Samse5f2f662012-05-16 15:43:25 -070021import android.renderscript.RenderScriptGL;
22import android.content.Context;
Stephen Hines0e1207e2013-05-06 18:18:57 -070023import android.view.SurfaceHolder;
Jason Samse5f2f662012-05-16 15:43:25 -070024import android.view.MotionEvent;
25
Stephen Hines0e1207e2013-05-06 18:18:57 -070026public class FountainFboView extends RSSurfaceView {
Jason Samse5f2f662012-05-16 15:43:25 -070027
28 public FountainFboView(Context context) {
29 super(context);
30 }
31
32 private RenderScriptGL mRS;
33 private FountainFboRS mRender;
34
Stephen Hines0e1207e2013-05-06 18:18:57 -070035 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
36 super.surfaceChanged(holder, format, w, h);
Jason Samse5f2f662012-05-16 15:43:25 -070037 if (mRS == null) {
38 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
39 mRS = createRenderScriptGL(sc);
Stephen Hines0e1207e2013-05-06 18:18:57 -070040 mRS.setSurface(holder, w, h);
Jason Samse5f2f662012-05-16 15:43:25 -070041 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