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 | |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.graphics.SurfaceTexture; |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 22 | import android.view.TextureView; |
| 23 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 24 | /** |
Tim Murray | a908422 | 2013-04-05 22:06:43 +0000 | [diff] [blame] | 25 | * @hide |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 26 | * @deprecated in API 16 |
Jason Sams | 684b235 | 2011-07-26 14:07:19 -0700 | [diff] [blame] | 27 | * The Texture View for a graphics renderscript (RenderScriptGL) |
| 28 | * to draw on. |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 29 | * |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 30 | */ |
| 31 | public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener { |
| 32 | private RenderScriptGL mRS; |
| 33 | private SurfaceTexture mSurfaceTexture; |
| 34 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 35 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 36 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 37 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 47 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 48 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 49 | * 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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 64 | /** |
| 65 | * @deprecated in API 16 |
| 66 | */ |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 67 | @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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 77 | /** |
| 78 | * @deprecated in API 16 |
| 79 | */ |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 80 | @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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 90 | /** |
| 91 | * @deprecated in API 16 |
| 92 | */ |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 93 | @Override |
Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 94 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 95 | //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed"); |
| 96 | mSurfaceTexture = surface; |
| 97 | |
| 98 | if (mRS != null) { |
| 99 | mRS.setSurfaceTexture(null, 0, 0); |
| 100 | } |
Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 101 | |
| 102 | return true; |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 105 | /** |
| 106 | * @deprecated in API 16 |
| 107 | */ |
Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 108 | @Override |
| 109 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
| 110 | //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated"); |
| 111 | mSurfaceTexture = surface; |
| 112 | } |
| 113 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 114 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 115 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 116 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 127 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 128 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 129 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 141 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 142 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 143 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 160 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 161 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 162 | * Destroy the RenderScriptGL object associated with this |
| 163 | * TextureView. |
| 164 | */ |
| 165 | public void destroyRenderScriptGL() { |
| 166 | mRS.destroy(); |
| 167 | mRS = null; |
| 168 | } |
| 169 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 170 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 171 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 172 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 184 | /** |
Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 185 | * @deprecated in API 16 |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 186 | * Returns the previously set RenderScriptGL object. |
| 187 | * |
| 188 | * @return RenderScriptGL |
| 189 | */ |
| 190 | public RenderScriptGL getRenderScriptGL() { |
| 191 | return mRS; |
| 192 | } |
| 193 | } |
| 194 | |