blob: ed04000e258860de2f6aa4e8787472add7989ae8 [file] [log] [blame]
Jason Samsfaa32b32011-06-20 16:58:04 -07001/*
2 * Copyright (C) 2011 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 android.renderscript;
18
19import java.io.Writer;
20import java.util.ArrayList;
21import java.util.concurrent.Semaphore;
22
23import android.content.Context;
24import android.graphics.SurfaceTexture;
25import android.os.Handler;
26import android.os.Message;
27import android.util.AttributeSet;
28import android.util.Log;
29import android.view.TextureView;
30
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070031/**
Jason Samsd4ca9912012-05-08 19:02:07 -070032 * @deprecated in API 16
Jason Sams684b2352011-07-26 14:07:19 -070033 * The Texture View for a graphics renderscript (RenderScriptGL)
34 * to draw on.
Jason Samsfaa32b32011-06-20 16:58:04 -070035 *
Jason Samsfaa32b32011-06-20 16:58:04 -070036 */
37public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener {
38 private RenderScriptGL mRS;
39 private SurfaceTexture mSurfaceTexture;
40
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070041 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070042 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -070043 * Standard View constructor. In order to render something, you
44 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
45 * register a renderer.
46 */
47 public RSTextureView(Context context) {
48 super(context);
49 init();
50 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
51 }
52
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070053 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070054 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -070055 * Standard View constructor. In order to render something, you
56 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
57 * register a renderer.
58 */
59 public RSTextureView(Context context, AttributeSet attrs) {
60 super(context, attrs);
61 init();
62 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
63 }
64
65 private void init() {
66 setSurfaceTextureListener(this);
67 //android.util.Log.e("rs", "getSurfaceTextureListerner " + getSurfaceTextureListener());
68 }
69
Jason Samsd4ca9912012-05-08 19:02:07 -070070 /**
71 * @deprecated in API 16
72 */
Jason Samsfaa32b32011-06-20 16:58:04 -070073 @Override
74 public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
75 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureAvailable");
76 mSurfaceTexture = surface;
77
78 if (mRS != null) {
79 mRS.setSurfaceTexture(mSurfaceTexture, width, height);
80 }
81 }
82
Jason Samsd4ca9912012-05-08 19:02:07 -070083 /**
84 * @deprecated in API 16
85 */
Jason Samsfaa32b32011-06-20 16:58:04 -070086 @Override
87 public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
88 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureSizeChanged");
89 mSurfaceTexture = surface;
90
91 if (mRS != null) {
92 mRS.setSurfaceTexture(mSurfaceTexture, width, height);
93 }
94 }
95
Jason Samsd4ca9912012-05-08 19:02:07 -070096 /**
97 * @deprecated in API 16
98 */
Jason Samsfaa32b32011-06-20 16:58:04 -070099 @Override
Grace Kloba402f0552011-08-09 18:47:17 -0700100 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Jason Samsfaa32b32011-06-20 16:58:04 -0700101 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed");
102 mSurfaceTexture = surface;
103
104 if (mRS != null) {
105 mRS.setSurfaceTexture(null, 0, 0);
106 }
Grace Kloba402f0552011-08-09 18:47:17 -0700107
108 return true;
Jason Samsfaa32b32011-06-20 16:58:04 -0700109 }
110
Jason Samsd4ca9912012-05-08 19:02:07 -0700111 /**
112 * @deprecated in API 16
113 */
Grace Klobacf559372011-06-22 23:05:40 -0700114 @Override
115 public void onSurfaceTextureUpdated(SurfaceTexture surface) {
116 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated");
117 mSurfaceTexture = surface;
118 }
119
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700120 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700121 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700122 * Inform the view that the activity is paused. The owner of this view must
123 * call this method when the activity is paused. Calling this method will
124 * pause the rendering thread.
125 * Must not be called before a renderer has been set.
126 */
127 public void pause() {
128 if(mRS != null) {
129 mRS.pause();
130 }
131 }
132
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700133 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700134 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700135 * Inform the view that the activity is resumed. The owner of this view must
136 * call this method when the activity is resumed. Calling this method will
137 * recreate the OpenGL display and resume the rendering
138 * thread.
139 * Must not be called before a renderer has been set.
140 */
141 public void resume() {
142 if(mRS != null) {
143 mRS.resume();
144 }
145 }
146
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700147 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700148 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700149 * Create a new RenderScriptGL object and attach it to the
150 * TextureView if present.
151 *
152 *
153 * @param sc The RS surface config to create.
154 *
155 * @return RenderScriptGL The new object created.
156 */
157 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
158 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
159 setRenderScriptGL(rs);
160 if (mSurfaceTexture != null) {
161 mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
162 }
163 return rs;
164 }
165
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700166 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700167 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700168 * Destroy the RenderScriptGL object associated with this
169 * TextureView.
170 */
171 public void destroyRenderScriptGL() {
172 mRS.destroy();
173 mRS = null;
174 }
175
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700176 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700177 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700178 * Set a new RenderScriptGL object. This also will attach the
179 * new object to the TextureView if present.
180 *
181 * @param rs The new RS object.
182 */
183 public void setRenderScriptGL(RenderScriptGL rs) {
184 mRS = rs;
185 if (mSurfaceTexture != null) {
186 mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
187 }
188 }
189
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700190 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700191 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700192 * Returns the previously set RenderScriptGL object.
193 *
194 * @return RenderScriptGL
195 */
196 public RenderScriptGL getRenderScriptGL() {
197 return mRS;
198 }
199}
200