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