blob: 6178994cfbe3af0bfca3738509ea605bdaf39848 [file] [log] [blame]
Jason Sams704ff642010-02-09 16:05:07 -08001/*
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
17package android.renderscript;
18
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080019import android.content.Context;
Jason Samsfaa32b32011-06-20 16:58:04 -070020import android.graphics.SurfaceTexture;
Jason Sams704ff642010-02-09 16:05:07 -080021import android.view.Surface;
Jason Sams2222aa92010-10-10 17:58:25 -070022import android.view.SurfaceHolder;
Jason Sams704ff642010-02-09 16:05:07 -080023
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070024/**
Tim Murraya9084222013-04-05 22:06:43 +000025 * @hide
Jason Samsd4ca9912012-05-08 19:02:07 -070026 * @deprecated in API 16
Tim Murrayc11e25c2013-04-09 11:01:01 -070027 * The Graphics derivitive of RenderScript. Extends the basic context to add a
Jason Sams27676fe2010-11-10 17:00:59 -080028 * 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.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080032 *
33 * <div class="special reference">
34 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070035 * <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>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080037 * </div>
Jason Sams704ff642010-02-09 16:05:07 -080038 **/
39public class RenderScriptGL extends RenderScript {
Jason Sams704ff642010-02-09 16:05:07 -080040 int mWidth;
41 int mHeight;
42
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070043 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070044 * @deprecated in API 16
Jason Sams27676fe2010-11-10 17:00:59 -080045 * 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 *
Jason Samsbf6ef8d2010-12-06 15:59:59 -080048 * The configuration is described by pairs of minimum and preferred bit
49 * depths for each component within the config and additional structural
50 * information.
Jason Sams27676fe2010-11-10 17:00:59 -080051 */
Jason Sams2222aa92010-10-10 17:58:25 -070052 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;
Jason Sams704ff642010-02-09 16:05:07 -080064
Jason Samsd4ca9912012-05-08 19:02:07 -070065 /**
66 * @deprecated in API 16
67 */
Jason Sams2222aa92010-10-10 17:58:25 -070068 public SurfaceConfig() {
69 }
70
Jason Samsd4ca9912012-05-08 19:02:07 -070071 /**
72 * @deprecated in API 16
73 */
Jason Sams2222aa92010-10-10 17:58:25 -070074 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
88 private void validateRange(int umin, int upref, int rmin, int rmax) {
89 if (umin < rmin || umin > rmax) {
Jason Samsc1d62102010-11-04 14:32:19 -070090 throw new RSIllegalArgumentException("Minimum value provided out of range.");
Jason Sams2222aa92010-10-10 17:58:25 -070091 }
92 if (upref < umin) {
Jason Samsbf6ef8d2010-12-06 15:59:59 -080093 throw new RSIllegalArgumentException("preferred must be >= Minimum.");
Jason Sams2222aa92010-10-10 17:58:25 -070094 }
95 }
96
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070097 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070098 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -080099 * 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 */
105 public void setColor(int minimum, int preferred) {
106 validateRange(minimum, preferred, 5, 8);
Jason Sams2222aa92010-10-10 17:58:25 -0700107 mColorMin = minimum;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800108 mColorPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700109 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800110
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700111 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700112 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800113 * 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 */
119 public void setAlpha(int minimum, int preferred) {
120 validateRange(minimum, preferred, 0, 8);
Jason Sams2222aa92010-10-10 17:58:25 -0700121 mAlphaMin = minimum;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800122 mAlphaPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700123 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800124
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700125 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700126 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800127 * 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 */
135 public void setDepth(int minimum, int preferred) {
136 validateRange(minimum, preferred, 0, 24);
Jason Sams2222aa92010-10-10 17:58:25 -0700137 mDepthMin = minimum;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800138 mDepthPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700139 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800140
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700141 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700142 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800143 * 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 */
152 public void setSamples(int minimum, int preferred, float Q) {
153 validateRange(minimum, preferred, 1, 32);
Jason Sams2222aa92010-10-10 17:58:25 -0700154 if (Q < 0.0f || Q > 1.0f) {
Jason Samsc1d62102010-11-04 14:32:19 -0700155 throw new RSIllegalArgumentException("Quality out of 0-1 range.");
Jason Sams2222aa92010-10-10 17:58:25 -0700156 }
157 mSamplesMin = minimum;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800158 mSamplesPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700159 mSamplesQ = Q;
160 }
161 };
162
163 SurfaceConfig mSurfaceConfig;
Jason Sams2222aa92010-10-10 17:58:25 -0700164
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700165 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700166 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800167 * Construct a new RenderScriptGL context.
168 *
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800169 * @param ctx The context.
Stephen Hines8cecbb52011-02-28 18:20:34 -0800170 * @param sc The desired format of the primary rendering surface.
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800171 */
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800172 public RenderScriptGL(Context ctx, SurfaceConfig sc) {
173 super(ctx);
Jason Sams2222aa92010-10-10 17:58:25 -0700174 mSurfaceConfig = new SurfaceConfig(sc);
175
Jason Sams1a4e1f32012-02-24 17:51:24 -0800176 int sdkVersion = ctx.getApplicationInfo().targetSdkVersion;
Stephen Hines4382467a2011-08-01 15:02:34 -0700177
Jason Sams704ff642010-02-09 16:05:07 -0800178 mWidth = 0;
179 mHeight = 0;
180 mDev = nDeviceCreate();
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700181 int dpi = ctx.getResources().getDisplayMetrics().densityDpi;
Stephen Hines4382467a2011-08-01 15:02:34 -0700182 mContext = nContextCreateGL(mDev, 0, sdkVersion,
Jason Sams11c8af92010-10-13 15:31:10 -0700183 mSurfaceConfig.mColorMin, mSurfaceConfig.mColorPref,
184 mSurfaceConfig.mAlphaMin, mSurfaceConfig.mAlphaPref,
185 mSurfaceConfig.mDepthMin, mSurfaceConfig.mDepthPref,
186 mSurfaceConfig.mStencilMin, mSurfaceConfig.mStencilPref,
187 mSurfaceConfig.mSamplesMin, mSurfaceConfig.mSamplesPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700188 mSurfaceConfig.mSamplesQ, dpi);
Jason Samsd5f06302010-11-03 14:27:11 -0700189 if (mContext == 0) {
190 throw new RSDriverException("Failed to create RS context.");
191 }
Jason Sams704ff642010-02-09 16:05:07 -0800192 mMessageThread = new MessageThread(this);
193 mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -0800194 }
195
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700196 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700197 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800198 * Bind an os surface
199 *
200 *
201 * @param w
202 * @param h
203 * @param sur
204 */
205 public void setSurface(SurfaceHolder sur, int w, int h) {
206 validate();
Jason Samsfaa32b32011-06-20 16:58:04 -0700207 Surface s = null;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800208 if (sur != null) {
Jason Samsfaa32b32011-06-20 16:58:04 -0700209 s = sur.getSurface();
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800210 }
Jason Sams704ff642010-02-09 16:05:07 -0800211 mWidth = w;
212 mHeight = h;
Jason Samsfaa32b32011-06-20 16:58:04 -0700213 nContextSetSurface(w, h, s);
214 }
215
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700216 /**
Jason Samse619de62012-05-08 18:40:58 -0700217 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700218 * Bind an os surface
219 *
Jason Samsfaa32b32011-06-20 16:58:04 -0700220 * @param w
221 * @param h
222 * @param sur
223 */
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
Xiaofei Wan21e0af92014-03-31 14:26:20 +0800228 Surface s = null;
229 if (sur != null) {
230 s = new Surface(sur);
231 }
Jason Samsfaa32b32011-06-20 16:58:04 -0700232 mWidth = w;
233 mHeight = h;
Xiaofei Wan21e0af92014-03-31 14:26:20 +0800234 nContextSetSurface(w, h, s);
Jason Sams704ff642010-02-09 16:05:07 -0800235 }
236
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700237 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700238 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800239 * return the height of the last set surface.
240 *
241 * @return int
242 */
Jason Sams5585e362010-10-29 10:19:21 -0700243 public int getHeight() {
244 return mHeight;
245 }
246
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700247 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700248 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800249 * return the width of the last set surface.
250 *
251 * @return int
252 */
Jason Sams5585e362010-10-29 10:19:21 -0700253 public int getWidth() {
254 return mWidth;
255 }
Jason Sams704ff642010-02-09 16:05:07 -0800256
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700257 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700258 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800259 * Temporarly halt calls to the root rendering script.
260 *
261 */
262 public void pause() {
Jason Sams704ff642010-02-09 16:05:07 -0800263 validate();
264 nContextPause();
265 }
266
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700267 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700268 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800269 * Resume calls to the root rendering script.
270 *
271 */
272 public void resume() {
Jason Sams704ff642010-02-09 16:05:07 -0800273 validate();
274 nContextResume();
275 }
276
277
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700278 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700279 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800280 * Set the script to handle calls to render the primary surface.
281 *
282 * @param s Graphics script to process rendering requests.
283 */
284 public void bindRootScript(Script s) {
Jason Sams704ff642010-02-09 16:05:07 -0800285 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800286 nContextBindRootScript((int)safeID(s));
Jason Sams704ff642010-02-09 16:05:07 -0800287 }
288
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700289 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700290 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800291 * Set the default ProgramStore object seen as the parent state by the root
292 * rendering script.
293 *
294 * @param p
295 */
296 public void bindProgramStore(ProgramStore p) {
Jason Sams704ff642010-02-09 16:05:07 -0800297 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800298 nContextBindProgramStore((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800299 }
300
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700301 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700302 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800303 * Set the default ProgramFragment object seen as the parent state by the
304 * root rendering script.
305 *
306 * @param p
307 */
308 public void bindProgramFragment(ProgramFragment p) {
Jason Sams704ff642010-02-09 16:05:07 -0800309 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800310 nContextBindProgramFragment((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800311 }
312
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700313 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700314 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800315 * Set the default ProgramRaster object seen as the parent state by the
316 * root rendering script.
317 *
318 * @param p
319 */
320 public void bindProgramRaster(ProgramRaster p) {
Jason Sams704ff642010-02-09 16:05:07 -0800321 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800322 nContextBindProgramRaster((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800323 }
324
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700325 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700326 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800327 * Set the default ProgramVertex object seen as the parent state by the
328 * root rendering script.
329 *
330 * @param p
331 */
332 public void bindProgramVertex(ProgramVertex p) {
Jason Sams704ff642010-02-09 16:05:07 -0800333 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800334 nContextBindProgramVertex((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800335 }
336
Jason Sams704ff642010-02-09 16:05:07 -0800337}