blob: 6fac83e8c4a805a1de56d2d883ef2a3e8dcccad8 [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
Mathew Inwoodf0c90b12018-08-01 10:05:11 +010019import android.annotation.UnsupportedAppUsage;
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080020import android.content.Context;
Jason Samsfaa32b32011-06-20 16:58:04 -070021import android.graphics.SurfaceTexture;
Jason Sams704ff642010-02-09 16:05:07 -080022import android.view.Surface;
Jason Sams2222aa92010-10-10 17:58:25 -070023import android.view.SurfaceHolder;
Jason Sams704ff642010-02-09 16:05:07 -080024
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070025/**
Tim Murraya9084222013-04-05 22:06:43 +000026 * @hide
Jason Samsd4ca9912012-05-08 19:02:07 -070027 * @deprecated in API 16
Tim Murrayc11e25c2013-04-09 11:01:01 -070028 * The Graphics derivitive of RenderScript. Extends the basic context to add a
Jason Sams27676fe2010-11-10 17:00:59 -080029 * root script which is the display window for graphical output. When the
30 * system needs to update the display the currently bound root script will be
31 * called. This script is expected to issue the rendering commands to repaint
32 * the screen.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080033 *
34 * <div class="special reference">
35 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070036 * <p>For more information about creating an application that uses RenderScript, read the
37 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080038 * </div>
Jason Sams704ff642010-02-09 16:05:07 -080039 **/
40public class RenderScriptGL extends RenderScript {
Jason Sams704ff642010-02-09 16:05:07 -080041 int mWidth;
42 int mHeight;
43
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070044 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070045 * @deprecated in API 16
Jason Sams27676fe2010-11-10 17:00:59 -080046 * Class which is used to describe a pixel format for a graphical buffer.
47 * This is used to describe the intended format of the display surface.
48 *
Jason Samsbf6ef8d2010-12-06 15:59:59 -080049 * The configuration is described by pairs of minimum and preferred bit
50 * depths for each component within the config and additional structural
51 * information.
Jason Sams27676fe2010-11-10 17:00:59 -080052 */
Jason Sams2222aa92010-10-10 17:58:25 -070053 public static class SurfaceConfig {
54 int mDepthMin = 0;
55 int mDepthPref = 0;
56 int mStencilMin = 0;
57 int mStencilPref = 0;
58 int mColorMin = 8;
59 int mColorPref = 8;
60 int mAlphaMin = 0;
61 int mAlphaPref = 0;
62 int mSamplesMin = 1;
63 int mSamplesPref = 1;
64 float mSamplesQ = 1.f;
Jason Sams704ff642010-02-09 16:05:07 -080065
Jason Samsd4ca9912012-05-08 19:02:07 -070066 /**
67 * @deprecated in API 16
68 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +010069 @UnsupportedAppUsage
Jason Sams2222aa92010-10-10 17:58:25 -070070 public SurfaceConfig() {
71 }
72
Jason Samsd4ca9912012-05-08 19:02:07 -070073 /**
74 * @deprecated in API 16
75 */
Jason Sams2222aa92010-10-10 17:58:25 -070076 public SurfaceConfig(SurfaceConfig sc) {
77 mDepthMin = sc.mDepthMin;
78 mDepthPref = sc.mDepthPref;
79 mStencilMin = sc.mStencilMin;
80 mStencilPref = sc.mStencilPref;
81 mColorMin = sc.mColorMin;
82 mColorPref = sc.mColorPref;
83 mAlphaMin = sc.mAlphaMin;
84 mAlphaPref = sc.mAlphaPref;
85 mSamplesMin = sc.mSamplesMin;
86 mSamplesPref = sc.mSamplesPref;
87 mSamplesQ = sc.mSamplesQ;
88 }
89
90 private void validateRange(int umin, int upref, int rmin, int rmax) {
91 if (umin < rmin || umin > rmax) {
Jason Samsc1d62102010-11-04 14:32:19 -070092 throw new RSIllegalArgumentException("Minimum value provided out of range.");
Jason Sams2222aa92010-10-10 17:58:25 -070093 }
94 if (upref < umin) {
Jason Samsbf6ef8d2010-12-06 15:59:59 -080095 throw new RSIllegalArgumentException("preferred must be >= Minimum.");
Jason Sams2222aa92010-10-10 17:58:25 -070096 }
97 }
98
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070099 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700100 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800101 * Set the per-component bit depth for color (red, green, blue). This
102 * configures the surface for an unsigned integer buffer type.
103 *
104 * @param minimum
105 * @param preferred
106 */
107 public void setColor(int minimum, int preferred) {
108 validateRange(minimum, preferred, 5, 8);
Jason Sams2222aa92010-10-10 17:58:25 -0700109 mColorMin = minimum;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800110 mColorPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700111 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800112
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700113 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700114 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800115 * Set the bit depth for alpha. This configures the surface for
116 * an unsigned integer buffer type.
117 *
118 * @param minimum
119 * @param preferred
120 */
121 public void setAlpha(int minimum, int preferred) {
122 validateRange(minimum, preferred, 0, 8);
Jason Sams2222aa92010-10-10 17:58:25 -0700123 mAlphaMin = minimum;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800124 mAlphaPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700125 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800126
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700127 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700128 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800129 * Set the bit depth for the depth buffer. This configures the
130 * surface for an unsigned integer buffer type. If a minimum of 0
131 * is specified then its possible no depth buffer will be
132 * allocated.
133 *
134 * @param minimum
135 * @param preferred
136 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100137 @UnsupportedAppUsage
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800138 public void setDepth(int minimum, int preferred) {
139 validateRange(minimum, preferred, 0, 24);
Jason Sams2222aa92010-10-10 17:58:25 -0700140 mDepthMin = minimum;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800141 mDepthPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700142 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800143
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700144 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700145 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800146 * Configure the multisample rendering.
147 *
148 * @param minimum The required number of samples, must be at least 1.
149 * @param preferred The targe number of samples, must be at least
150 * minimum
151 * @param Q The quality of samples, range 0-1. Used to decide between
152 * different formats which have the same number of samples but
153 * different rendering quality.
154 */
155 public void setSamples(int minimum, int preferred, float Q) {
156 validateRange(minimum, preferred, 1, 32);
Jason Sams2222aa92010-10-10 17:58:25 -0700157 if (Q < 0.0f || Q > 1.0f) {
Jason Samsc1d62102010-11-04 14:32:19 -0700158 throw new RSIllegalArgumentException("Quality out of 0-1 range.");
Jason Sams2222aa92010-10-10 17:58:25 -0700159 }
160 mSamplesMin = minimum;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800161 mSamplesPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700162 mSamplesQ = Q;
163 }
164 };
165
166 SurfaceConfig mSurfaceConfig;
Jason Sams2222aa92010-10-10 17:58:25 -0700167
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700168 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700169 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800170 * Construct a new RenderScriptGL context.
171 *
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800172 * @param ctx The context.
Stephen Hines8cecbb52011-02-28 18:20:34 -0800173 * @param sc The desired format of the primary rendering surface.
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800174 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100175 @UnsupportedAppUsage
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800176 public RenderScriptGL(Context ctx, SurfaceConfig sc) {
177 super(ctx);
Jason Sams2222aa92010-10-10 17:58:25 -0700178 mSurfaceConfig = new SurfaceConfig(sc);
179
Jason Sams1a4e1f32012-02-24 17:51:24 -0800180 int sdkVersion = ctx.getApplicationInfo().targetSdkVersion;
Stephen Hines4382467a2011-08-01 15:02:34 -0700181
Jason Sams704ff642010-02-09 16:05:07 -0800182 mWidth = 0;
183 mHeight = 0;
Yang Ni4a70df52016-04-04 10:23:57 -0700184 long device = nDeviceCreate();
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700185 int dpi = ctx.getResources().getDisplayMetrics().densityDpi;
Yang Ni4a70df52016-04-04 10:23:57 -0700186 mContext = nContextCreateGL(device, 0, sdkVersion,
Jason Sams11c8af92010-10-13 15:31:10 -0700187 mSurfaceConfig.mColorMin, mSurfaceConfig.mColorPref,
188 mSurfaceConfig.mAlphaMin, mSurfaceConfig.mAlphaPref,
189 mSurfaceConfig.mDepthMin, mSurfaceConfig.mDepthPref,
190 mSurfaceConfig.mStencilMin, mSurfaceConfig.mStencilPref,
191 mSurfaceConfig.mSamplesMin, mSurfaceConfig.mSamplesPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700192 mSurfaceConfig.mSamplesQ, dpi);
Jason Samsd5f06302010-11-03 14:27:11 -0700193 if (mContext == 0) {
194 throw new RSDriverException("Failed to create RS context.");
195 }
Jason Sams704ff642010-02-09 16:05:07 -0800196 mMessageThread = new MessageThread(this);
197 mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -0800198 }
199
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700200 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700201 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800202 * Bind an os surface
203 *
204 *
205 * @param w
206 * @param h
207 * @param sur
208 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100209 @UnsupportedAppUsage
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800210 public void setSurface(SurfaceHolder sur, int w, int h) {
211 validate();
Jason Samsfaa32b32011-06-20 16:58:04 -0700212 Surface s = null;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800213 if (sur != null) {
Jason Samsfaa32b32011-06-20 16:58:04 -0700214 s = sur.getSurface();
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800215 }
Jason Sams704ff642010-02-09 16:05:07 -0800216 mWidth = w;
217 mHeight = h;
Jason Samsfaa32b32011-06-20 16:58:04 -0700218 nContextSetSurface(w, h, s);
219 }
220
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700221 /**
Jason Samse619de62012-05-08 18:40:58 -0700222 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700223 * Bind an os surface
224 *
Jason Samsfaa32b32011-06-20 16:58:04 -0700225 * @param w
226 * @param h
227 * @param sur
228 */
229 public void setSurfaceTexture(SurfaceTexture sur, int w, int h) {
230 validate();
231 //android.util.Log.v("rs", "set surface " + sur + " w=" + w + ", h=" + h);
232
Xiaofei Wan21e0af92014-03-31 14:26:20 +0800233 Surface s = null;
234 if (sur != null) {
235 s = new Surface(sur);
236 }
Jason Samsfaa32b32011-06-20 16:58:04 -0700237 mWidth = w;
238 mHeight = h;
Xiaofei Wan21e0af92014-03-31 14:26:20 +0800239 nContextSetSurface(w, h, s);
Jason Sams704ff642010-02-09 16:05:07 -0800240 }
241
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700242 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700243 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800244 * return the height of the last set surface.
245 *
246 * @return int
247 */
Jason Sams5585e362010-10-29 10:19:21 -0700248 public int getHeight() {
249 return mHeight;
250 }
251
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700252 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700253 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800254 * return the width of the last set surface.
255 *
256 * @return int
257 */
Jason Sams5585e362010-10-29 10:19:21 -0700258 public int getWidth() {
259 return mWidth;
260 }
Jason Sams704ff642010-02-09 16:05:07 -0800261
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700262 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700263 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800264 * Temporarly halt calls to the root rendering script.
265 *
266 */
267 public void pause() {
Jason Sams704ff642010-02-09 16:05:07 -0800268 validate();
269 nContextPause();
270 }
271
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700272 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700273 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800274 * Resume calls to the root rendering script.
275 *
276 */
277 public void resume() {
Jason Sams704ff642010-02-09 16:05:07 -0800278 validate();
279 nContextResume();
280 }
281
282
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700283 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700284 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800285 * Set the script to handle calls to render the primary surface.
286 *
287 * @param s Graphics script to process rendering requests.
288 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100289 @UnsupportedAppUsage
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800290 public void bindRootScript(Script s) {
Jason Sams704ff642010-02-09 16:05:07 -0800291 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800292 nContextBindRootScript((int)safeID(s));
Jason Sams704ff642010-02-09 16:05:07 -0800293 }
294
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700295 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700296 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800297 * Set the default ProgramStore object seen as the parent state by the root
298 * rendering script.
299 *
300 * @param p
301 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100302 @UnsupportedAppUsage
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800303 public void bindProgramStore(ProgramStore p) {
Jason Sams704ff642010-02-09 16:05:07 -0800304 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800305 nContextBindProgramStore((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800306 }
307
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700308 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700309 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800310 * Set the default ProgramFragment object seen as the parent state by the
311 * root rendering script.
312 *
313 * @param p
314 */
315 public void bindProgramFragment(ProgramFragment p) {
Jason Sams704ff642010-02-09 16:05:07 -0800316 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800317 nContextBindProgramFragment((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800318 }
319
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700320 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700321 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800322 * Set the default ProgramRaster object seen as the parent state by the
323 * root rendering script.
324 *
325 * @param p
326 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100327 @UnsupportedAppUsage
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800328 public void bindProgramRaster(ProgramRaster p) {
Jason Sams704ff642010-02-09 16:05:07 -0800329 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800330 nContextBindProgramRaster((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800331 }
332
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700333 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700334 * @deprecated in API 16
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800335 * Set the default ProgramVertex object seen as the parent state by the
336 * root rendering script.
337 *
338 * @param p
339 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100340 @UnsupportedAppUsage
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800341 public void bindProgramVertex(ProgramVertex p) {
Jason Sams704ff642010-02-09 16:05:07 -0800342 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800343 nContextBindProgramVertex((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800344 }
345
Jason Sams704ff642010-02-09 16:05:07 -0800346}