• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.view.Surface;
22 import android.view.SurfaceHolder;
23 
24 /**
25  * @hide
26  * @deprecated in API 16
27  * The Graphics derivitive of RenderScript.  Extends the basic context to add a
28  * root script which is the display window for graphical output.  When the
29  * system needs to update the display the currently bound root script will be
30  * called.  This script is expected to issue the rendering commands to repaint
31  * the screen.
32  *
33  * <div class="special reference">
34  * <h3>Developer Guides</h3>
35  * <p>For more information about creating an application that uses RenderScript, read the
36  * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
37  * </div>
38  **/
39 public class RenderScriptGL extends RenderScript {
40     int mWidth;
41     int mHeight;
42 
43     /**
44      * @deprecated in API 16
45      * Class which is used to describe a pixel format for a graphical buffer.
46      * This is used to describe the intended format of the display surface.
47      *
48      * The configuration is described by pairs of minimum and preferred bit
49      * depths for each component within the config and additional structural
50      * information.
51      */
52     public static class SurfaceConfig {
53         int mDepthMin       = 0;
54         int mDepthPref      = 0;
55         int mStencilMin     = 0;
56         int mStencilPref    = 0;
57         int mColorMin       = 8;
58         int mColorPref      = 8;
59         int mAlphaMin       = 0;
60         int mAlphaPref      = 0;
61         int mSamplesMin     = 1;
62         int mSamplesPref    = 1;
63         float mSamplesQ     = 1.f;
64 
65         /**
66          * @deprecated in API 16
67          */
SurfaceConfig()68         public SurfaceConfig() {
69         }
70 
71         /**
72          * @deprecated in API 16
73          */
SurfaceConfig(SurfaceConfig sc)74         public SurfaceConfig(SurfaceConfig sc) {
75             mDepthMin = sc.mDepthMin;
76             mDepthPref = sc.mDepthPref;
77             mStencilMin = sc.mStencilMin;
78             mStencilPref = sc.mStencilPref;
79             mColorMin = sc.mColorMin;
80             mColorPref = sc.mColorPref;
81             mAlphaMin = sc.mAlphaMin;
82             mAlphaPref = sc.mAlphaPref;
83             mSamplesMin = sc.mSamplesMin;
84             mSamplesPref = sc.mSamplesPref;
85             mSamplesQ = sc.mSamplesQ;
86         }
87 
validateRange(int umin, int upref, int rmin, int rmax)88         private void validateRange(int umin, int upref, int rmin, int rmax) {
89             if (umin < rmin || umin > rmax) {
90                 throw new RSIllegalArgumentException("Minimum value provided out of range.");
91             }
92             if (upref < umin) {
93                 throw new RSIllegalArgumentException("preferred must be >= Minimum.");
94             }
95         }
96 
97         /**
98          * @deprecated in API 16
99          * Set the per-component bit depth for color (red, green, blue).  This
100          * configures the surface for an unsigned integer buffer type.
101          *
102          * @param minimum
103          * @param preferred
104          */
setColor(int minimum, int preferred)105         public void setColor(int minimum, int preferred) {
106             validateRange(minimum, preferred, 5, 8);
107             mColorMin = minimum;
108             mColorPref = preferred;
109         }
110 
111         /**
112          * @deprecated in API 16
113          * Set the bit depth for alpha. This configures the surface for
114          * an unsigned integer buffer type.
115          *
116          * @param minimum
117          * @param preferred
118          */
setAlpha(int minimum, int preferred)119         public void setAlpha(int minimum, int preferred) {
120             validateRange(minimum, preferred, 0, 8);
121             mAlphaMin = minimum;
122             mAlphaPref = preferred;
123         }
124 
125          /**
126          * @deprecated in API 16
127          * Set the bit depth for the depth buffer. This configures the
128          * surface for an unsigned integer buffer type.  If a minimum of 0
129          * is specified then its possible no depth buffer will be
130          * allocated.
131          *
132          * @param minimum
133          * @param preferred
134          */
setDepth(int minimum, int preferred)135         public void setDepth(int minimum, int preferred) {
136             validateRange(minimum, preferred, 0, 24);
137             mDepthMin = minimum;
138             mDepthPref = preferred;
139         }
140 
141         /**
142          * @deprecated in API 16
143          * Configure the multisample rendering.
144          *
145          * @param minimum The required number of samples, must be at least 1.
146          * @param preferred The targe number of samples, must be at least
147          *                  minimum
148          * @param Q  The quality of samples, range 0-1.  Used to decide between
149          *           different formats which have the same number of samples but
150          *           different rendering quality.
151          */
setSamples(int minimum, int preferred, float Q)152         public void setSamples(int minimum, int preferred, float Q) {
153             validateRange(minimum, preferred, 1, 32);
154             if (Q < 0.0f || Q > 1.0f) {
155                 throw new RSIllegalArgumentException("Quality out of 0-1 range.");
156             }
157             mSamplesMin = minimum;
158             mSamplesPref = preferred;
159             mSamplesQ = Q;
160         }
161     };
162 
163     SurfaceConfig mSurfaceConfig;
164 
165     /**
166      * @deprecated in API 16
167      * Construct a new RenderScriptGL context.
168      *
169      * @param ctx The context.
170      * @param sc The desired format of the primary rendering surface.
171      */
RenderScriptGL(Context ctx, SurfaceConfig sc)172     public RenderScriptGL(Context ctx, SurfaceConfig sc) {
173         super(ctx);
174         mSurfaceConfig = new SurfaceConfig(sc);
175 
176         int sdkVersion = ctx.getApplicationInfo().targetSdkVersion;
177 
178         mWidth = 0;
179         mHeight = 0;
180         mDev = nDeviceCreate();
181         int dpi = ctx.getResources().getDisplayMetrics().densityDpi;
182         mContext = nContextCreateGL(mDev, 0, sdkVersion,
183                                     mSurfaceConfig.mColorMin, mSurfaceConfig.mColorPref,
184                                     mSurfaceConfig.mAlphaMin, mSurfaceConfig.mAlphaPref,
185                                     mSurfaceConfig.mDepthMin, mSurfaceConfig.mDepthPref,
186                                     mSurfaceConfig.mStencilMin, mSurfaceConfig.mStencilPref,
187                                     mSurfaceConfig.mSamplesMin, mSurfaceConfig.mSamplesPref,
188                                     mSurfaceConfig.mSamplesQ, dpi);
189         if (mContext == 0) {
190             throw new RSDriverException("Failed to create RS context.");
191         }
192         mMessageThread = new MessageThread(this);
193         mMessageThread.start();
194     }
195 
196     /**
197      * @deprecated in API 16
198      * Bind an os surface
199      *
200      *
201      * @param w
202      * @param h
203      * @param sur
204      */
setSurface(SurfaceHolder sur, int w, int h)205     public void setSurface(SurfaceHolder sur, int w, int h) {
206         validate();
207         Surface s = null;
208         if (sur != null) {
209             s = sur.getSurface();
210         }
211         mWidth = w;
212         mHeight = h;
213         nContextSetSurface(w, h, s);
214     }
215 
216     /**
217      * @deprecated in API 16
218      * Bind an os surface
219      *
220      * @param w
221      * @param h
222      * @param sur
223      */
setSurfaceTexture(SurfaceTexture sur, int w, int h)224     public void setSurfaceTexture(SurfaceTexture sur, int w, int h) {
225         validate();
226         //android.util.Log.v("rs", "set surface " + sur + " w=" + w + ", h=" + h);
227 
228         Surface s = null;
229         if (sur != null) {
230             s = new Surface(sur);
231         }
232         mWidth = w;
233         mHeight = h;
234         nContextSetSurface(w, h, s);
235     }
236 
237     /**
238      * @deprecated in API 16
239      * return the height of the last set surface.
240      *
241      * @return int
242      */
getHeight()243     public int getHeight() {
244         return mHeight;
245     }
246 
247     /**
248      * @deprecated in API 16
249      * return the width of the last set surface.
250      *
251      * @return int
252      */
getWidth()253     public int getWidth() {
254         return mWidth;
255     }
256 
257     /**
258      * @deprecated in API 16
259      * Temporarly halt calls to the root rendering script.
260      *
261      */
pause()262     public void pause() {
263         validate();
264         nContextPause();
265     }
266 
267     /**
268      * @deprecated in API 16
269      * Resume calls to the root rendering script.
270      *
271      */
resume()272     public void resume() {
273         validate();
274         nContextResume();
275     }
276 
277 
278     /**
279      * @deprecated in API 16
280      * Set the script to handle calls to render the primary surface.
281      *
282      * @param s Graphics script to process rendering requests.
283      */
bindRootScript(Script s)284     public void bindRootScript(Script s) {
285         validate();
286         nContextBindRootScript((int)safeID(s));
287     }
288 
289     /**
290      * @deprecated in API 16
291      * Set the default ProgramStore object seen as the parent state by the root
292      * rendering script.
293      *
294      * @param p
295      */
bindProgramStore(ProgramStore p)296     public void bindProgramStore(ProgramStore p) {
297         validate();
298         nContextBindProgramStore((int)safeID(p));
299     }
300 
301     /**
302      * @deprecated in API 16
303      * Set the default ProgramFragment object seen as the parent state by the
304      * root rendering script.
305      *
306      * @param p
307      */
bindProgramFragment(ProgramFragment p)308     public void bindProgramFragment(ProgramFragment p) {
309         validate();
310         nContextBindProgramFragment((int)safeID(p));
311     }
312 
313     /**
314      * @deprecated in API 16
315      * Set the default ProgramRaster object seen as the parent state by the
316      * root rendering script.
317      *
318      * @param p
319      */
bindProgramRaster(ProgramRaster p)320     public void bindProgramRaster(ProgramRaster p) {
321         validate();
322         nContextBindProgramRaster((int)safeID(p));
323     }
324 
325     /**
326      * @deprecated in API 16
327      * Set the default ProgramVertex object seen as the parent state by the
328      * root rendering script.
329      *
330      * @param p
331      */
bindProgramVertex(ProgramVertex p)332     public void bindProgramVertex(ProgramVertex p) {
333         validate();
334         nContextBindProgramVertex((int)safeID(p));
335     }
336 
337 }
338