blob: 7eeeeae6c352efb063efa47126b61930d6f496b6 [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/**
Tim Murraya9084222013-04-05 22:06:43 +000032 * @hide
Jason Samsd4ca9912012-05-08 19:02:07 -070033 * @deprecated in API 16
Jason Sams684b2352011-07-26 14:07:19 -070034 * The Texture View for a graphics renderscript (RenderScriptGL)
35 * to draw on.
Jason Samsfaa32b32011-06-20 16:58:04 -070036 *
Jason Samsfaa32b32011-06-20 16:58:04 -070037 */
38public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener {
39 private RenderScriptGL mRS;
40 private SurfaceTexture mSurfaceTexture;
41
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070042 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070043 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -070044 * Standard View constructor. In order to render something, you
45 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
46 * register a renderer.
47 */
48 public RSTextureView(Context context) {
49 super(context);
50 init();
51 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
52 }
53
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070054 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070055 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -070056 * Standard View constructor. In order to render something, you
57 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
58 * register a renderer.
59 */
60 public RSTextureView(Context context, AttributeSet attrs) {
61 super(context, attrs);
62 init();
63 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
64 }
65
66 private void init() {
67 setSurfaceTextureListener(this);
68 //android.util.Log.e("rs", "getSurfaceTextureListerner " + getSurfaceTextureListener());
69 }
70
Jason Samsd4ca9912012-05-08 19:02:07 -070071 /**
72 * @deprecated in API 16
73 */
Jason Samsfaa32b32011-06-20 16:58:04 -070074 @Override
75 public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
76 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureAvailable");
77 mSurfaceTexture = surface;
78
79 if (mRS != null) {
80 mRS.setSurfaceTexture(mSurfaceTexture, width, height);
81 }
82 }
83
Jason Samsd4ca9912012-05-08 19:02:07 -070084 /**
85 * @deprecated in API 16
86 */
Jason Samsfaa32b32011-06-20 16:58:04 -070087 @Override
88 public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
89 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureSizeChanged");
90 mSurfaceTexture = surface;
91
92 if (mRS != null) {
93 mRS.setSurfaceTexture(mSurfaceTexture, width, height);
94 }
95 }
96
Jason Samsd4ca9912012-05-08 19:02:07 -070097 /**
98 * @deprecated in API 16
99 */
Jason Samsfaa32b32011-06-20 16:58:04 -0700100 @Override
Grace Kloba402f0552011-08-09 18:47:17 -0700101 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Jason Samsfaa32b32011-06-20 16:58:04 -0700102 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed");
103 mSurfaceTexture = surface;
104
105 if (mRS != null) {
106 mRS.setSurfaceTexture(null, 0, 0);
107 }
Grace Kloba402f0552011-08-09 18:47:17 -0700108
109 return true;
Jason Samsfaa32b32011-06-20 16:58:04 -0700110 }
111
Jason Samsd4ca9912012-05-08 19:02:07 -0700112 /**
113 * @deprecated in API 16
114 */
Grace Klobacf559372011-06-22 23:05:40 -0700115 @Override
116 public void onSurfaceTextureUpdated(SurfaceTexture surface) {
117 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated");
118 mSurfaceTexture = surface;
119 }
120
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700121 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700122 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700123 * Inform the view that the activity is paused. The owner of this view must
124 * call this method when the activity is paused. Calling this method will
125 * pause the rendering thread.
126 * Must not be called before a renderer has been set.
127 */
128 public void pause() {
129 if(mRS != null) {
130 mRS.pause();
131 }
132 }
133
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700134 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700135 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700136 * Inform the view that the activity is resumed. The owner of this view must
137 * call this method when the activity is resumed. Calling this method will
138 * recreate the OpenGL display and resume the rendering
139 * thread.
140 * Must not be called before a renderer has been set.
141 */
142 public void resume() {
143 if(mRS != null) {
144 mRS.resume();
145 }
146 }
147
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700148 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700149 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700150 * Create a new RenderScriptGL object and attach it to the
151 * TextureView if present.
152 *
153 *
154 * @param sc The RS surface config to create.
155 *
156 * @return RenderScriptGL The new object created.
157 */
158 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
159 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
160 setRenderScriptGL(rs);
161 if (mSurfaceTexture != null) {
162 mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
163 }
164 return rs;
165 }
166
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700167 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700168 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700169 * Destroy the RenderScriptGL object associated with this
170 * TextureView.
171 */
172 public void destroyRenderScriptGL() {
173 mRS.destroy();
174 mRS = null;
175 }
176
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700177 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700178 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700179 * Set a new RenderScriptGL object. This also will attach the
180 * new object to the TextureView if present.
181 *
182 * @param rs The new RS object.
183 */
184 public void setRenderScriptGL(RenderScriptGL rs) {
185 mRS = rs;
186 if (mSurfaceTexture != null) {
187 mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
188 }
189 }
190
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700191 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700192 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700193 * Returns the previously set RenderScriptGL object.
194 *
195 * @return RenderScriptGL
196 */
197 public RenderScriptGL getRenderScriptGL() {
198 return mRS;
199 }
200}
201