blob: d46dbf68291bcc0e0cc9017b40a6195c918f3ac4 [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
Artur Satayev2ebb31c2020-01-08 12:24:36 +000019import android.compat.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 **/
Xusong Wang8b4548c2021-01-05 10:09:52 -080040@Deprecated
Jason Sams704ff642010-02-09 16:05:07 -080041public class RenderScriptGL extends RenderScript {
Jason Sams704ff642010-02-09 16:05:07 -080042 int mWidth;
43 int mHeight;
44
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070045 /**
Jason Samsd4ca9912012-05-08 19:02:07 -070046 * @deprecated in API 16
Jason Sams27676fe2010-11-10 17:00:59 -080047 * Class which is used to describe a pixel format for a graphical buffer.
48 * This is used to describe the intended format of the display surface.
49 *
Jason Samsbf6ef8d72010-12-06 15:59:59 -080050 * The configuration is described by pairs of minimum and preferred bit
51 * depths for each component within the config and additional structural
52 * information.
Jason Sams27676fe2010-11-10 17:00:59 -080053 */
Jason Sams2222aa92010-10-10 17:58:25 -070054 public static class SurfaceConfig {
55 int mDepthMin = 0;
56 int mDepthPref = 0;
57 int mStencilMin = 0;
58 int mStencilPref = 0;
59 int mColorMin = 8;
60 int mColorPref = 8;
61 int mAlphaMin = 0;
62 int mAlphaPref = 0;
63 int mSamplesMin = 1;
64 int mSamplesPref = 1;
65 float mSamplesQ = 1.f;
Jason Sams704ff642010-02-09 16:05:07 -080066
Jason Samsd4ca9912012-05-08 19:02:07 -070067 /**
68 * @deprecated in API 16
69 */
Mathew Inwood15324472018-08-06 11:18:49 +010070 @UnsupportedAppUsage
Jason Sams2222aa92010-10-10 17:58:25 -070071 public SurfaceConfig() {
72 }
73
Jason Samsd4ca9912012-05-08 19:02:07 -070074 /**
75 * @deprecated in API 16
76 */
Jason Sams2222aa92010-10-10 17:58:25 -070077 public SurfaceConfig(SurfaceConfig sc) {
78 mDepthMin = sc.mDepthMin;
79 mDepthPref = sc.mDepthPref;
80 mStencilMin = sc.mStencilMin;
81 mStencilPref = sc.mStencilPref;
82 mColorMin = sc.mColorMin;
83 mColorPref = sc.mColorPref;
84 mAlphaMin = sc.mAlphaMin;
85 mAlphaPref = sc.mAlphaPref;
86 mSamplesMin = sc.mSamplesMin;
87 mSamplesPref = sc.mSamplesPref;
88 mSamplesQ = sc.mSamplesQ;
89 }
90
91 private void validateRange(int umin, int upref, int rmin, int rmax) {
92 if (umin < rmin || umin > rmax) {
Jason Samsc1d62102010-11-04 14:32:19 -070093 throw new RSIllegalArgumentException("Minimum value provided out of range.");
Jason Sams2222aa92010-10-10 17:58:25 -070094 }
95 if (upref < umin) {
Jason Samsbf6ef8d72010-12-06 15:59:59 -080096 throw new RSIllegalArgumentException("preferred must be >= Minimum.");
Jason Sams2222aa92010-10-10 17:58:25 -070097 }
98 }
99
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700100 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700101 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800102 * Set the per-component bit depth for color (red, green, blue). This
103 * configures the surface for an unsigned integer buffer type.
104 *
105 * @param minimum
106 * @param preferred
107 */
108 public void setColor(int minimum, int preferred) {
109 validateRange(minimum, preferred, 5, 8);
Jason Sams2222aa92010-10-10 17:58:25 -0700110 mColorMin = minimum;
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800111 mColorPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700112 }
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800113
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700114 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700115 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800116 * Set the bit depth for alpha. This configures the surface for
117 * an unsigned integer buffer type.
118 *
119 * @param minimum
120 * @param preferred
121 */
122 public void setAlpha(int minimum, int preferred) {
123 validateRange(minimum, preferred, 0, 8);
Jason Sams2222aa92010-10-10 17:58:25 -0700124 mAlphaMin = minimum;
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800125 mAlphaPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700126 }
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800127
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700128 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700129 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800130 * Set the bit depth for the depth buffer. This configures the
131 * surface for an unsigned integer buffer type. If a minimum of 0
132 * is specified then its possible no depth buffer will be
133 * allocated.
134 *
135 * @param minimum
136 * @param preferred
137 */
Mathew Inwood15324472018-08-06 11:18:49 +0100138 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800139 public void setDepth(int minimum, int preferred) {
140 validateRange(minimum, preferred, 0, 24);
Jason Sams2222aa92010-10-10 17:58:25 -0700141 mDepthMin = minimum;
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800142 mDepthPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700143 }
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800144
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700145 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700146 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800147 * Configure the multisample rendering.
148 *
149 * @param minimum The required number of samples, must be at least 1.
150 * @param preferred The targe number of samples, must be at least
151 * minimum
152 * @param Q The quality of samples, range 0-1. Used to decide between
153 * different formats which have the same number of samples but
154 * different rendering quality.
155 */
156 public void setSamples(int minimum, int preferred, float Q) {
157 validateRange(minimum, preferred, 1, 32);
Jason Sams2222aa92010-10-10 17:58:25 -0700158 if (Q < 0.0f || Q > 1.0f) {
Jason Samsc1d62102010-11-04 14:32:19 -0700159 throw new RSIllegalArgumentException("Quality out of 0-1 range.");
Jason Sams2222aa92010-10-10 17:58:25 -0700160 }
161 mSamplesMin = minimum;
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800162 mSamplesPref = preferred;
Jason Sams2222aa92010-10-10 17:58:25 -0700163 mSamplesQ = Q;
164 }
165 };
166
167 SurfaceConfig mSurfaceConfig;
Jason Sams2222aa92010-10-10 17:58:25 -0700168
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700169 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700170 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800171 * Construct a new RenderScriptGL context.
172 *
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800173 * @param ctx The context.
Stephen Hines8cecbb52011-02-28 18:20:34 -0800174 * @param sc The desired format of the primary rendering surface.
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800175 */
Mathew Inwood15324472018-08-06 11:18:49 +0100176 @UnsupportedAppUsage
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800177 public RenderScriptGL(Context ctx, SurfaceConfig sc) {
178 super(ctx);
Jason Sams2222aa92010-10-10 17:58:25 -0700179 mSurfaceConfig = new SurfaceConfig(sc);
180
Jason Sams1a4e1f3e2012-02-24 17:51:24 -0800181 int sdkVersion = ctx.getApplicationInfo().targetSdkVersion;
Stephen Hines4382467a2011-08-01 15:02:34 -0700182
Jason Sams704ff642010-02-09 16:05:07 -0800183 mWidth = 0;
184 mHeight = 0;
Yang Ni4a70df52016-04-04 10:23:57 -0700185 long device = nDeviceCreate();
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700186 int dpi = ctx.getResources().getDisplayMetrics().densityDpi;
Yang Ni4a70df52016-04-04 10:23:57 -0700187 mContext = nContextCreateGL(device, 0, sdkVersion,
Jason Sams11c8af92010-10-13 15:31:10 -0700188 mSurfaceConfig.mColorMin, mSurfaceConfig.mColorPref,
189 mSurfaceConfig.mAlphaMin, mSurfaceConfig.mAlphaPref,
190 mSurfaceConfig.mDepthMin, mSurfaceConfig.mDepthPref,
191 mSurfaceConfig.mStencilMin, mSurfaceConfig.mStencilPref,
192 mSurfaceConfig.mSamplesMin, mSurfaceConfig.mSamplesPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700193 mSurfaceConfig.mSamplesQ, dpi);
Jason Samsd5f06302010-11-03 14:27:11 -0700194 if (mContext == 0) {
195 throw new RSDriverException("Failed to create RS context.");
196 }
Jason Sams704ff642010-02-09 16:05:07 -0800197 mMessageThread = new MessageThread(this);
198 mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -0800199 }
200
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700201 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700202 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800203 * Bind an os surface
204 *
205 *
206 * @param w
207 * @param h
208 * @param sur
209 */
Mathew Inwood15324472018-08-06 11:18:49 +0100210 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800211 public void setSurface(SurfaceHolder sur, int w, int h) {
212 validate();
Jason Samsfaa32b32011-06-20 16:58:04 -0700213 Surface s = null;
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800214 if (sur != null) {
Jason Samsfaa32b32011-06-20 16:58:04 -0700215 s = sur.getSurface();
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800216 }
Jason Sams704ff642010-02-09 16:05:07 -0800217 mWidth = w;
218 mHeight = h;
Jason Samsfaa32b32011-06-20 16:58:04 -0700219 nContextSetSurface(w, h, s);
220 }
221
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700222 /**
Jason Samse619de62012-05-08 18:40:58 -0700223 * @deprecated in API 16
Jason Samsfaa32b32011-06-20 16:58:04 -0700224 * Bind an os surface
225 *
Jason Samsfaa32b32011-06-20 16:58:04 -0700226 * @param w
227 * @param h
228 * @param sur
229 */
230 public void setSurfaceTexture(SurfaceTexture sur, int w, int h) {
231 validate();
232 //android.util.Log.v("rs", "set surface " + sur + " w=" + w + ", h=" + h);
233
Xiaofei Wan21e0af92014-03-31 14:26:20 +0800234 Surface s = null;
235 if (sur != null) {
236 s = new Surface(sur);
237 }
Jason Samsfaa32b32011-06-20 16:58:04 -0700238 mWidth = w;
239 mHeight = h;
Xiaofei Wan21e0af92014-03-31 14:26:20 +0800240 nContextSetSurface(w, h, s);
Jason Sams704ff642010-02-09 16:05:07 -0800241 }
242
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700243 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700244 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800245 * return the height of the last set surface.
246 *
247 * @return int
248 */
Jason Sams5585e362010-10-29 10:19:21 -0700249 public int getHeight() {
250 return mHeight;
251 }
252
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700253 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700254 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800255 * return the width of the last set surface.
256 *
257 * @return int
258 */
Jason Sams5585e362010-10-29 10:19:21 -0700259 public int getWidth() {
260 return mWidth;
261 }
Jason Sams704ff642010-02-09 16:05:07 -0800262
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700263 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700264 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800265 * Temporarly halt calls to the root rendering script.
266 *
267 */
268 public void pause() {
Jason Sams704ff642010-02-09 16:05:07 -0800269 validate();
270 nContextPause();
271 }
272
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700273 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700274 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800275 * Resume calls to the root rendering script.
276 *
277 */
278 public void resume() {
Jason Sams704ff642010-02-09 16:05:07 -0800279 validate();
280 nContextResume();
281 }
282
283
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700284 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700285 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800286 * Set the script to handle calls to render the primary surface.
287 *
288 * @param s Graphics script to process rendering requests.
289 */
Mathew Inwood15324472018-08-06 11:18:49 +0100290 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800291 public void bindRootScript(Script s) {
Jason Sams704ff642010-02-09 16:05:07 -0800292 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800293 nContextBindRootScript((int)safeID(s));
Jason Sams704ff642010-02-09 16:05:07 -0800294 }
295
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700296 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700297 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800298 * Set the default ProgramStore object seen as the parent state by the root
299 * rendering script.
300 *
301 * @param p
302 */
Mathew Inwood15324472018-08-06 11:18:49 +0100303 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800304 public void bindProgramStore(ProgramStore p) {
Jason Sams704ff642010-02-09 16:05:07 -0800305 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800306 nContextBindProgramStore((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 Samsbf6ef8d72010-12-06 15:59:59 -0800311 * Set the default ProgramFragment object seen as the parent state by the
312 * root rendering script.
313 *
314 * @param p
315 */
316 public void bindProgramFragment(ProgramFragment p) {
Jason Sams704ff642010-02-09 16:05:07 -0800317 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800318 nContextBindProgramFragment((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 Samsbf6ef8d72010-12-06 15:59:59 -0800323 * Set the default ProgramRaster object seen as the parent state by the
324 * root rendering script.
325 *
326 * @param p
327 */
Mathew Inwood15324472018-08-06 11:18:49 +0100328 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800329 public void bindProgramRaster(ProgramRaster p) {
Jason Sams704ff642010-02-09 16:05:07 -0800330 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800331 nContextBindProgramRaster((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800332 }
333
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700334 /**
Jason Samsd4ca9912012-05-08 19:02:07 -0700335 * @deprecated in API 16
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800336 * Set the default ProgramVertex object seen as the parent state by the
337 * root rendering script.
338 *
339 * @param p
340 */
Mathew Inwood15324472018-08-06 11:18:49 +0100341 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800342 public void bindProgramVertex(ProgramVertex p) {
Jason Sams704ff642010-02-09 16:05:07 -0800343 validate();
Tim Murray460a0492013-11-19 12:45:54 -0800344 nContextBindProgramVertex((int)safeID(p));
Jason Sams704ff642010-02-09 16:05:07 -0800345 }
346
Jason Sams704ff642010-02-09 16:05:07 -0800347}