blob: ed68fc39ddce4f26ff1473aaa521b2b7489ac78d [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
Jason Samsfaa32b32011-06-20 16:58:04 -070019import android.content.Context;
20import android.graphics.SurfaceTexture;
Jason Samsfaa32b32011-06-20 16:58:04 -070021import android.util.AttributeSet;
Jason Samsfaa32b32011-06-20 16:58:04 -070022import android.view.TextureView;
23
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070024/**
Tim Murraya9084222013-04-05 22:06:43 +000025 * @hide
Jason Samsd4ca9912012-05-08 19:02:07 -070026 * @deprecated in API 16
Jason Sams684b2352011-07-26 14:07:19 -070027 * The Texture View for a graphics renderscript (RenderScriptGL)
28 * to draw on.
Jason Samsfaa32b32011-06-20 16:58:04 -070029 *
Jason Samsfaa32b32011-06-20 16:58:04 -070030 */
Xusong Wang8b4548c2021-01-05 10:09:52 -080031@Deprecated
Jason Samsfaa32b32011-06-20 16:58:04 -070032public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener {
33 private RenderScriptGL mRS;
34 private SurfaceTexture mSurfaceTexture;
35
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070036 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070037 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -070038 * Standard View constructor. In order to render something, you
39 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
40 * register a renderer.
41 */
42 public RSTextureView(Context context) {
43 super(context);
44 init();
45 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
46 }
47
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070048 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070049 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -070050 * Standard View constructor. In order to render something, you
51 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
52 * register a renderer.
53 */
54 public RSTextureView(Context context, AttributeSet attrs) {
55 super(context, attrs);
56 init();
57 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
58 }
59
60 private void init() {
61 setSurfaceTextureListener(this);
62 //android.util.Log.e("rs", "getSurfaceTextureListerner " + getSurfaceTextureListener());
63 }
64
Jason Samsd4ca9912012-05-08 19:02:07 -070065 /**
66 * @deprecated in API 16
67 */
Jason Samsfaa32b32011-06-20 16:58:04 -070068 @Override
69 public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
70 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureAvailable");
71 mSurfaceTexture = surface;
72
73 if (mRS != null) {
74 mRS.setSurfaceTexture(mSurfaceTexture, width, height);
75 }
76 }
77
Jason Samsd4ca9912012-05-08 19:02:07 -070078 /**
79 * @deprecated in API 16
80 */
Jason Samsfaa32b32011-06-20 16:58:04 -070081 @Override
82 public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
83 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureSizeChanged");
84 mSurfaceTexture = surface;
85
86 if (mRS != null) {
87 mRS.setSurfaceTexture(mSurfaceTexture, width, height);
88 }
89 }
90
Jason Samsd4ca9912012-05-08 19:02:07 -070091 /**
92 * @deprecated in API 16
93 */
Jason Samsfaa32b32011-06-20 16:58:04 -070094 @Override
Grace Kloba402f0552011-08-09 18:47:17 -070095 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Jason Samsfaa32b32011-06-20 16:58:04 -070096 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed");
97 mSurfaceTexture = surface;
98
99 if (mRS != null) {
100 mRS.setSurfaceTexture(null, 0, 0);
101 }
Grace Kloba402f0552011-08-09 18:47:17 -0700102
103 return true;
Jason Samsfaa32b32011-06-20 16:58:04 -0700104 }
105
Jason Samsd4ca9912012-05-08 19:02:07 -0700106 /**
107 * @deprecated in API 16
108 */
Grace Klobacf559372011-06-22 23:05:40 -0700109 @Override
110 public void onSurfaceTextureUpdated(SurfaceTexture surface) {
111 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated");
112 mSurfaceTexture = surface;
113 }
114
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700115 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700116 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700117 * Inform the view that the activity is paused. The owner of this view must
118 * call this method when the activity is paused. Calling this method will
119 * pause the rendering thread.
120 * Must not be called before a renderer has been set.
121 */
122 public void pause() {
123 if(mRS != null) {
124 mRS.pause();
125 }
126 }
127
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700128 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700129 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700130 * Inform the view that the activity is resumed. The owner of this view must
131 * call this method when the activity is resumed. Calling this method will
132 * recreate the OpenGL display and resume the rendering
133 * thread.
134 * Must not be called before a renderer has been set.
135 */
136 public void resume() {
137 if(mRS != null) {
138 mRS.resume();
139 }
140 }
141
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700142 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700143 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700144 * Create a new RenderScriptGL object and attach it to the
145 * TextureView if present.
146 *
147 *
148 * @param sc The RS surface config to create.
149 *
150 * @return RenderScriptGL The new object created.
151 */
152 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
153 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
154 setRenderScriptGL(rs);
155 if (mSurfaceTexture != null) {
156 mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
157 }
158 return rs;
159 }
160
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700161 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700162 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700163 * Destroy the RenderScriptGL object associated with this
164 * TextureView.
165 */
166 public void destroyRenderScriptGL() {
167 mRS.destroy();
168 mRS = null;
169 }
170
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700171 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700172 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700173 * Set a new RenderScriptGL object. This also will attach the
174 * new object to the TextureView if present.
175 *
176 * @param rs The new RS object.
177 */
178 public void setRenderScriptGL(RenderScriptGL rs) {
179 mRS = rs;
180 if (mSurfaceTexture != null) {
181 mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
182 }
183 }
184
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700185 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700186 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700187 * Returns the previously set RenderScriptGL object.
188 *
189 * @return RenderScriptGL
190 */
191 public RenderScriptGL getRenderScriptGL() {
192 return mRS;
193 }
194}
195