Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.renderscript; |
| 18 | |
| 19 | import java.io.Writer; |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.concurrent.Semaphore; |
| 22 | |
| 23 | import android.content.Context; |
| 24 | import android.graphics.SurfaceTexture; |
| 25 | import android.os.Handler; |
| 26 | import android.os.Message; |
| 27 | import android.util.AttributeSet; |
| 28 | import android.util.Log; |
| 29 | import android.view.TextureView; |
| 30 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 31 | /** |
Tim Murray | a908422 | 2013-04-05 22:06:43 +0000 | [diff] [blame] | 32 | * @hide |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 33 | * @deprecated in API 16 |
Jason Sams | 684b235 | 2011-07-26 14:07:19 -0700 | [diff] [blame] | 34 | * The Texture View for a graphics renderscript (RenderScriptGL) |
| 35 | * to draw on. |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 36 | * |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 37 | */ |
| 38 | public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener { |
| 39 | private RenderScriptGL mRS; |
| 40 | private SurfaceTexture mSurfaceTexture; |
| 41 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 42 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 43 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 44 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 54 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 55 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 56 | * 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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 71 | /** |
| 72 | * @deprecated in API 16 |
| 73 | */ |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 74 | @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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 84 | /** |
| 85 | * @deprecated in API 16 |
| 86 | */ |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 87 | @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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 97 | /** |
| 98 | * @deprecated in API 16 |
| 99 | */ |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 100 | @Override |
Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 101 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 102 | //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed"); |
| 103 | mSurfaceTexture = surface; |
| 104 | |
| 105 | if (mRS != null) { |
| 106 | mRS.setSurfaceTexture(null, 0, 0); |
| 107 | } |
Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 108 | |
| 109 | return true; |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 112 | /** |
| 113 | * @deprecated in API 16 |
| 114 | */ |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 115 | @Override |
| 116 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
| 117 | //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated"); |
| 118 | mSurfaceTexture = surface; |
| 119 | } |
| 120 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 121 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 122 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 123 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 134 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 135 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 136 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 148 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 149 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 150 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 167 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 168 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 169 | * Destroy the RenderScriptGL object associated with this |
| 170 | * TextureView. |
| 171 | */ |
| 172 | public void destroyRenderScriptGL() { |
| 173 | mRS.destroy(); |
| 174 | mRS = null; |
| 175 | } |
| 176 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 177 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 178 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 179 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 191 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 192 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 193 | * Returns the previously set RenderScriptGL object. |
| 194 | * |
| 195 | * @return RenderScriptGL |
| 196 | */ |
| 197 | public RenderScriptGL getRenderScriptGL() { |
| 198 | return mRS; |
| 199 | } |
| 200 | } |
| 201 | |