| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 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 | |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 77 | public void contextBindProgramStore(ProgramStore p) { |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 78 | validate(); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 79 | nContextBindProgramStore(safeID(p)); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 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) { |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 105 | super(id, RenderScriptGL.this); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | public File fileOpen(String s) throws IllegalStateException, IllegalArgumentException |
| 110 | { |
| 111 | if(s.length() < 1) { |
| 112 | throw new IllegalArgumentException("fileOpen does not accept a zero length string."); |
| 113 | } |
| 114 | |
| 115 | try { |
| 116 | byte[] bytes = s.getBytes("UTF-8"); |
| 117 | int id = nFileOpen(bytes); |
| 118 | return new File(id); |
| 119 | } catch (java.io.UnsupportedEncodingException e) { |
| 120 | throw new RuntimeException(e); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | |