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.graphics.Bitmap; 22 import android.graphics.BitmapFactory; 23 import android.util.Config; 24 import android.util.Log; 25 import android.view.Surface; 26 27 28 /** 29 * @hide 30 * 31 **/ 32 public class RenderScriptGL extends RenderScript { 33 private Surface mSurface; 34 int mWidth; 35 int mHeight; 36 37 38 public RenderScriptGL(boolean useDepth, boolean forceSW) { 39 mSurface = null; 40 mWidth = 0; 41 mHeight = 0; 42 mDev = nDeviceCreate(); 43 if(forceSW) { 44 nDeviceSetConfig(mDev, 0, 1); 45 } 46 mContext = nContextCreateGL(mDev, 0, useDepth); 47 mMessageThread = new MessageThread(this); 48 mMessageThread.start(); 49 Element.initPredefined(this); 50 } 51 52 public void contextSetSurface(int w, int h, Surface sur) { 53 mSurface = sur; 54 mWidth = w; 55 mHeight = h; 56 validate(); 57 nContextSetSurface(w, h, mSurface); 58 } 59 60 61 void pause() { 62 validate(); 63 nContextPause(); 64 } 65 66 void resume() { 67 validate(); 68 nContextResume(); 69 } 70 71 72 public void contextBindRootScript(Script s) { 73 validate(); 74 nContextBindRootScript(safeID(s)); 75 } 76 77 public void contextBindProgramFragmentStore(ProgramStore p) { 78 validate(); 79 nContextBindProgramFragmentStore(safeID(p)); 80 } 81 82 public void contextBindProgramFragment(ProgramFragment p) { 83 validate(); 84 nContextBindProgramFragment(safeID(p)); 85 } 86 87 public void contextBindProgramRaster(ProgramRaster p) { 88 validate(); 89 nContextBindProgramRaster(safeID(p)); 90 } 91 92 public void contextBindProgramVertex(ProgramVertex p) { 93 validate(); 94 nContextBindProgramVertex(safeID(p)); 95 } 96 97 98 99 100 ////////////////////////////////////////////////////////////////////////////////// 101 // File 102 103 public class File extends BaseObj { 104 File(int id) { 105 super(RenderScriptGL.this); 106 mID = id; 107 } 108 } 109 110 public File fileOpen(String s) throws IllegalStateException, IllegalArgumentException 111 { 112 if(s.length() < 1) { 113 throw new IllegalArgumentException("fileOpen does not accept a zero length string."); 114 } 115 116 try { 117 byte[] bytes = s.getBytes("UTF-8"); 118 int id = nFileOpen(bytes); 119 return new File(id); 120 } catch (java.io.UnsupportedEncodingException e) { 121 throw new RuntimeException(e); 122 } 123 } 124 125 } 126 127 128