1 /*
2  * Copyright (C) 2008-2012 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.compat.annotation.UnsupportedAppUsage;
20 import android.content.Context;
21 import android.util.AttributeSet;
22 import android.view.SurfaceHolder;
23 import android.view.SurfaceView;
24 
25 /**
26  * @hide
27  * @deprecated in API 16
28  * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
29  *
30  * <div class="special reference">
31  * <h3>Developer Guides</h3>
32  * <p>For more information about creating an application that uses RenderScript, read the
33  * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
34  * </div>
35  */
36 @Deprecated
37 public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
38     private SurfaceHolder mSurfaceHolder;
39     private RenderScriptGL mRS;
40 
41     /**
42      * @deprecated in API 16
43      * Standard View constructor. In order to render something, you
44      * must call {@link android.opengl.GLSurfaceView#setRenderer} to
45      * register a renderer.
46      */
47     @UnsupportedAppUsage
RSSurfaceView(Context context)48     public RSSurfaceView(Context context) {
49         super(context);
50         init();
51         //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
52     }
53 
54     /**
55      * @deprecated in API 16
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     @UnsupportedAppUsage
RSSurfaceView(Context context, AttributeSet attrs)61     public RSSurfaceView(Context context, AttributeSet attrs) {
62         super(context, attrs);
63         init();
64         //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
65     }
66 
init()67     private void init() {
68         // Install a SurfaceHolder.Callback so we get notified when the
69         // underlying surface is created and destroyed
70         SurfaceHolder holder = getHolder();
71         holder.addCallback(this);
72     }
73 
74     /**
75      * @deprecated in API 16
76      * This method is part of the SurfaceHolder.Callback interface, and is
77      * not normally called or subclassed by clients of RSSurfaceView.
78      */
surfaceCreated(SurfaceHolder holder)79     public void surfaceCreated(SurfaceHolder holder) {
80         mSurfaceHolder = holder;
81     }
82 
83     /**
84      * @deprecated in API 16
85      * This method is part of the SurfaceHolder.Callback interface, and is
86      * not normally called or subclassed by clients of RSSurfaceView.
87      */
surfaceDestroyed(SurfaceHolder holder)88     public void surfaceDestroyed(SurfaceHolder holder) {
89         synchronized (this) {
90             // Surface will be destroyed when we return
91             if (mRS != null) {
92                 mRS.setSurface(null, 0, 0);
93             }
94         }
95     }
96 
97     /**
98      * @deprecated in API 16
99      * This method is part of the SurfaceHolder.Callback interface, and is
100      * not normally called or subclassed by clients of RSSurfaceView.
101      */
surfaceChanged(SurfaceHolder holder, int format, int w, int h)102     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
103         synchronized (this) {
104             if (mRS != null) {
105                 mRS.setSurface(holder, w, h);
106             }
107         }
108     }
109 
110    /**
111      * @deprecated in API 16
112      * Inform the view that the activity is paused. The owner of this view must
113      * call this method when the activity is paused. Calling this method will
114      * pause the rendering thread.
115      * Must not be called before a renderer has been set.
116      */
pause()117     public void pause() {
118         if(mRS != null) {
119             mRS.pause();
120         }
121     }
122 
123     /**
124      * @deprecated in API 16
125      * Inform the view that the activity is resumed. The owner of this view must
126      * call this method when the activity is resumed. Calling this method will
127      * recreate the OpenGL display and resume the rendering
128      * thread.
129      * Must not be called before a renderer has been set.
130      */
resume()131     public void resume() {
132         if(mRS != null) {
133             mRS.resume();
134         }
135     }
136 
137     /**
138      * @deprecated in API 16
139      **/
createRenderScriptGL(RenderScriptGL.SurfaceConfig sc)140     public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
141       RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
142         setRenderScriptGL(rs);
143         return rs;
144     }
145 
146     /**
147      * @deprecated in API 16
148      **/
destroyRenderScriptGL()149     public void destroyRenderScriptGL() {
150         synchronized (this) {
151             mRS.destroy();
152             mRS = null;
153         }
154     }
155 
156     /**
157      * @deprecated in API 16
158      **/
setRenderScriptGL(RenderScriptGL rs)159     public void setRenderScriptGL(RenderScriptGL rs) {
160         mRS = rs;
161     }
162 
163     /**
164      * @deprecated in API 16
165      **/
getRenderScriptGL()166     public RenderScriptGL getRenderScriptGL() {
167         return mRS;
168     }
169 }
170