| 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 | */ | 
| Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 31 | @Deprecated | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 32 | public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener { | 
|  | 33 | private RenderScriptGL mRS; | 
|  | 34 | private SurfaceTexture mSurfaceTexture; | 
|  | 35 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 36 | /** | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 37 | * @deprecated in API 16 | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 38 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 48 | /** | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 49 | * @deprecated in API 16 | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 50 | * 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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 65 | /** | 
|  | 66 | * @deprecated in API 16 | 
|  | 67 | */ | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 68 | @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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 78 | /** | 
|  | 79 | * @deprecated in API 16 | 
|  | 80 | */ | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 81 | @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 Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 91 | /** | 
|  | 92 | * @deprecated in API 16 | 
|  | 93 | */ | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 94 | @Override | 
| Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 95 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 96 | //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed"); | 
|  | 97 | mSurfaceTexture = surface; | 
|  | 98 |  | 
|  | 99 | if (mRS != null) { | 
|  | 100 | mRS.setSurfaceTexture(null, 0, 0); | 
|  | 101 | } | 
| Grace Kloba | 402f055 | 2011-08-09 18:47:17 -0700 | [diff] [blame] | 102 |  | 
|  | 103 | return true; | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 104 | } | 
|  | 105 |  | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 106 | /** | 
|  | 107 | * @deprecated in API 16 | 
|  | 108 | */ | 
| Grace Kloba | cf55937 | 2011-06-22 23:05:40 -0700 | [diff] [blame] | 109 | @Override | 
|  | 110 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { | 
|  | 111 | //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated"); | 
|  | 112 | mSurfaceTexture = surface; | 
|  | 113 | } | 
|  | 114 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 115 | /** | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 116 | * @deprecated in API 16 | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 117 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 128 | /** | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 129 | * @deprecated in API 16 | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 130 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 142 | /** | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 143 | * @deprecated in API 16 | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 144 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 161 | /** | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 162 | * @deprecated in API 16 | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 163 | * Destroy the RenderScriptGL object associated with this | 
|  | 164 | * TextureView. | 
|  | 165 | */ | 
|  | 166 | public void destroyRenderScriptGL() { | 
|  | 167 | mRS.destroy(); | 
|  | 168 | mRS = null; | 
|  | 169 | } | 
|  | 170 |  | 
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 171 | /** | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 172 | * @deprecated in API 16 | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 173 | * 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 185 | /** | 
| Jason Sams | d4ca991 | 2012-05-08 19:02:07 -0700 | [diff] [blame] | 186 | * @deprecated in API 16 | 
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 187 | * Returns the previously set RenderScriptGL object. | 
|  | 188 | * | 
|  | 189 | * @return RenderScriptGL | 
|  | 190 | */ | 
|  | 191 | public RenderScriptGL getRenderScriptGL() { | 
|  | 192 | return mRS; | 
|  | 193 | } | 
|  | 194 | } | 
|  | 195 |  |