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