blob: 714e835ac14b284b4941cfd160cc21b20688ac51 [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
228 mWidth = w;
229 mHeight = h;
230 nContextSetSurfaceTexture(w, h, sur);
Jason Sams704ff642010-02-09 16:05:07 -0800231 }
232
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700233 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700234 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800235 * return the height of the last set surface.
236 *
237 * @return int
238 */
Jason Sams5585e362010-10-29 10:19:21 -0700239 public int getHeight() {
240 return mHeight;
241 }
242
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700243 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700244 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800245 * return the width of the last set surface.
246 *
247 * @return int
248 */
Jason Sams5585e362010-10-29 10:19:21 -0700249 public int getWidth() {
250 return mWidth;
251 }
Jason Sams704ff642010-02-09 16:05:07 -0800252
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700253 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700254 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800255 * Temporarly halt calls to the root rendering script.
256 *
257 */
258 public void pause() {
Jason Sams704ff642010-02-09 16:05:07 -0800259 validate();
260 nContextPause();
261 }
262
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700263 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700264 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800265 * Resume calls to the root rendering script.
266 *
267 */
268 public void resume() {
Jason Sams704ff642010-02-09 16:05:07 -0800269 validate();
270 nContextResume();
271 }
272
273
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700274 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700275 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800276 * Set the script to handle calls to render the primary surface.
277 *
278 * @param s Graphics script to process rendering requests.
279 */
280 public void bindRootScript(Script s) {
Jason Sams704ff642010-02-09 16:05:07 -0800281 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800282 nContextBindRootScript((int)safeID(s));
Jason Sams704ff642010-02-09 16:05:07 -0800283 }
284
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700285 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700286 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800287 * Set the default ProgramStore object seen as the parent state by the root
288 * rendering script.
289 *
290 * @param p
291 */
292 public void bindProgramStore(ProgramStore p) {
Jason Sams704ff642010-02-09 16:05:07 -0800293 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800294 nContextBindProgramStore((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800295 }
296
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700297 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700298 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800299 * Set the default ProgramFragment object seen as the parent state by the
300 * root rendering script.
301 *
302 * @param p
303 */
304 public void bindProgramFragment(ProgramFragment p) {
Jason Sams704ff642010-02-09 16:05:07 -0800305 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800306 nContextBindProgramFragment((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800307 }
308
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700309 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700310 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800311 * Set the default ProgramRaster object seen as the parent state by the
312 * root rendering script.
313 *
314 * @param p
315 */
316 public void bindProgramRaster(ProgramRaster p) {
Jason Sams704ff642010-02-09 16:05:07 -0800317 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800318 nContextBindProgramRaster((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800319 }
320
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700321 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700322 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800323 * Set the default ProgramVertex object seen as the parent state by the
324 * root rendering script.
325 *
326 * @param p
327 */
328 public void bindProgramVertex(ProgramVertex p) {
Jason Sams704ff642010-02-09 16:05:07 -0800329 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800330 nContextBindProgramVertex((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800331 }
332
Jason Sams704ff642010-02-09 16:05:07 -0800333}