• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.content.Context;
20 import android.graphics.SurfaceTexture;
21 import android.util.AttributeSet;
22 import android.view.TextureView;
23 
24 /**
25  * @hide
26  * @deprecated in API 16
27  * The Texture View for a graphics renderscript (RenderScriptGL)
28  * to draw on.
29  *
30  */
31 public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener {
32     private RenderScriptGL mRS;
33     private SurfaceTexture mSurfaceTexture;
34 
35     /**
36      * @deprecated in API 16
37      * Standard View constructor. In order to render something, you
38      * must call {@link android.opengl.GLSurfaceView#setRenderer} to
39      * register a renderer.
40      */
RSTextureView(Context context)41     public RSTextureView(Context context) {
42         super(context);
43         init();
44         //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
45     }
46 
47     /**
48      * @deprecated in API 16
49      * Standard View constructor. In order to render something, you
50      * must call {@link android.opengl.GLSurfaceView#setRenderer} to
51      * register a renderer.
52      */
RSTextureView(Context context, AttributeSet attrs)53     public RSTextureView(Context context, AttributeSet attrs) {
54         super(context, attrs);
55         init();
56         //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
57     }
58 
init()59     private void init() {
60         setSurfaceTextureListener(this);
61         //android.util.Log.e("rs", "getSurfaceTextureListerner " + getSurfaceTextureListener());
62     }
63 
64     /**
65      * @deprecated in API 16
66      */
67     @Override
onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)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 
77     /**
78      * @deprecated in API 16
79      */
80     @Override
onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)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 
90     /**
91      * @deprecated in API 16
92      */
93     @Override
onSurfaceTextureDestroyed(SurfaceTexture surface)94     public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
95         //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed");
96         mSurfaceTexture = surface;
97 
98         if (mRS != null) {
99             mRS.setSurfaceTexture(null, 0, 0);
100         }
101 
102         return true;
103     }
104 
105     /**
106      * @deprecated in API 16
107      */
108     @Override
onSurfaceTextureUpdated(SurfaceTexture surface)109     public void onSurfaceTextureUpdated(SurfaceTexture surface) {
110         //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated");
111         mSurfaceTexture = surface;
112     }
113 
114    /**
115      * @deprecated in API 16
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      */
pause()121     public void pause() {
122         if(mRS != null) {
123             mRS.pause();
124         }
125     }
126 
127     /**
128      * @deprecated in API 16
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      */
resume()135     public void resume() {
136         if(mRS != null) {
137             mRS.resume();
138         }
139     }
140 
141     /**
142      * @deprecated in API 16
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      */
createRenderScriptGL(RenderScriptGL.SurfaceConfig sc)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 
160     /**
161      * @deprecated in API 16
162      * Destroy the RenderScriptGL object associated with this
163      * TextureView.
164      */
destroyRenderScriptGL()165     public void destroyRenderScriptGL() {
166         mRS.destroy();
167         mRS = null;
168     }
169 
170     /**
171      * @deprecated in API 16
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      */
setRenderScriptGL(RenderScriptGL rs)177     public void setRenderScriptGL(RenderScriptGL rs) {
178         mRS = rs;
179         if (mSurfaceTexture != null) {
180             mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
181         }
182     }
183 
184     /**
185      * @deprecated in API 16
186      * Returns the previously set RenderScriptGL object.
187      *
188      * @return RenderScriptGL
189      */
getRenderScriptGL()190     public RenderScriptGL getRenderScriptGL() {
191         return mRS;
192     }
193 }
194 
195