blob: af3258a7090d95e7c94755d65a155c896f260f0e [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 */
31public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener {
32 private RenderScriptGL mRS;
33 private SurfaceTexture mSurfaceTexture;
34
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070035 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070036 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -070037 * Standard View constructor. In order to render something, you
38 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
39 * register a renderer.
40 */
41 public RSTextureView(Context context) {
42 super(context);
43 init();
44 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
45 }
46
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070047 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070048 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -070049 * Standard View constructor. In order to render something, you
50 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
51 * register a renderer.
52 */
53 public RSTextureView(Context context, AttributeSet attrs) {
54 super(context, attrs);
55 init();
56 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
57 }
58
59 private void init() {
60 setSurfaceTextureListener(this);
61 //android.util.Log.e("rs", "getSurfaceTextureListerner " + getSurfaceTextureListener());
62 }
63
Jason Samsd4ca9912012-05-08 19:02:07 -070064 /**
65 * @deprecated in API 16
66 */
Jason Samsfaa32b32011-06-20 16:58:04 -070067 @Override
68 public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
69 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureAvailable");
70 mSurfaceTexture = surface;
71
72 if (mRS != null) {
73 mRS.setSurfaceTexture(mSurfaceTexture, width, height);
74 }
75 }
76
Jason Samsd4ca9912012-05-08 19:02:07 -070077 /**
78 * @deprecated in API 16
79 */
Jason Samsfaa32b32011-06-20 16:58:04 -070080 @Override
81 public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
82 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureSizeChanged");
83 mSurfaceTexture = surface;
84
85 if (mRS != null) {
86 mRS.setSurfaceTexture(mSurfaceTexture, width, height);
87 }
88 }
89
Jason Samsd4ca9912012-05-08 19:02:07 -070090 /**
91 * @deprecated in API 16
92 */
Jason Samsfaa32b32011-06-20 16:58:04 -070093 @Override
Grace Kloba402f0552011-08-09 18:47:17 -070094 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Jason Samsfaa32b32011-06-20 16:58:04 -070095 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed");
96 mSurfaceTexture = surface;
97
98 if (mRS != null) {
99 mRS.setSurfaceTexture(null, 0, 0);
100 }
Grace Kloba402f0552011-08-09 18:47:17 -0700101
102 return true;
Jason Samsfaa32b32011-06-20 16:58:04 -0700103 }
104
Jason Samsd4ca9912012-05-08 19:02:07 -0700105 /**
106 * @deprecated in API 16
107 */
Grace Klobacf559372011-06-22 23:05:40 -0700108 @Override
109 public void onSurfaceTextureUpdated(SurfaceTexture surface) {
110 //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated");
111 mSurfaceTexture = surface;
112 }
113
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700114 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700115 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700116 * Inform the view that the activity is paused. The owner of this view must
117 * call this method when the activity is paused. Calling this method will
118 * pause the rendering thread.
119 * Must not be called before a renderer has been set.
120 */
121 public void pause() {
122 if(mRS != null) {
123 mRS.pause();
124 }
125 }
126
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700127 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700128 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700129 * Inform the view that the activity is resumed. The owner of this view must
130 * call this method when the activity is resumed. Calling this method will
131 * recreate the OpenGL display and resume the rendering
132 * thread.
133 * Must not be called before a renderer has been set.
134 */
135 public void resume() {
136 if(mRS != null) {
137 mRS.resume();
138 }
139 }
140
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700141 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700142 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700143 * Create a new RenderScriptGL object and attach it to the
144 * TextureView if present.
145 *
146 *
147 * @param sc The RS surface config to create.
148 *
149 * @return RenderScriptGL The new object created.
150 */
151 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
152 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
153 setRenderScriptGL(rs);
154 if (mSurfaceTexture != null) {
155 mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
156 }
157 return rs;
158 }
159
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700160 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700161 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700162 * Destroy the RenderScriptGL object associated with this
163 * TextureView.
164 */
165 public void destroyRenderScriptGL() {
166 mRS.destroy();
167 mRS = null;
168 }
169
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700170 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700171 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700172 * Set a new RenderScriptGL object. This also will attach the
173 * new object to the TextureView if present.
174 *
175 * @param rs The new RS object.
176 */
177 public void setRenderScriptGL(RenderScriptGL rs) {
178 mRS = rs;
179 if (mSurfaceTexture != null) {
180 mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
181 }
182 }
183
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700184 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700185 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700186 * Returns the previously set RenderScriptGL object.
187 *
188 * @return RenderScriptGL
189 */
190 public RenderScriptGL getRenderScriptGL() {
191 return mRS;
192 }
193}
194