Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [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 | |
| 20 | import java.io.IOException; |
| 21 | import java.io.InputStream; |
| 22 | |
| 23 | import android.content.res.Resources; |
| 24 | import android.os.Bundle; |
| 25 | import android.util.Config; |
| 26 | import android.util.Log; |
| 27 | |
| 28 | import android.graphics.Bitmap; |
| 29 | import android.graphics.BitmapFactory; |
| 30 | |
| 31 | /** |
| 32 | * @hide |
| 33 | * |
| 34 | **/ |
| 35 | public class Type extends BaseObj { |
| 36 | Type(int id, RenderScript rs) { |
| 37 | super(rs); |
| 38 | mID = id; |
| 39 | } |
| 40 | |
| 41 | public void destroy() { |
| 42 | mRS.nTypeDestroy(mID); |
| 43 | mID = 0; |
| 44 | } |
| 45 | |
| 46 | public static class Builder { |
| 47 | RenderScript mRS; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame^] | 48 | Entry[] mEntries; |
| 49 | int mEntryCount; |
| 50 | Element mElement; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 51 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame^] | 52 | class Entry { |
| 53 | Dimension mDim; |
| 54 | int mValue; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame^] | 57 | public Builder(RenderScript rs, Element e) { |
| 58 | mRS = rs; |
| 59 | mEntries = new Entry[4]; |
| 60 | mElement = e; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | public void add(Dimension d, int value) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame^] | 64 | if(mEntries.length >= mEntryCount) { |
| 65 | Entry[] en = new Entry[mEntryCount + 8]; |
| 66 | for(int ct=0; ct < mEntries.length; ct++) { |
| 67 | en[ct] = mEntries[ct]; |
| 68 | } |
| 69 | mEntries = en; |
| 70 | } |
| 71 | mEntries[mEntryCount] = new Entry(); |
| 72 | mEntries[mEntryCount].mDim = d; |
| 73 | mEntries[mEntryCount].mValue = value; |
| 74 | mEntryCount++; |
| 75 | } |
| 76 | |
| 77 | static synchronized Type internalCreate(RenderScript rs, Builder b) { |
| 78 | rs.nTypeBegin(b.mElement.mID); |
| 79 | for (int ct=0; ct < b.mEntryCount; ct++) { |
| 80 | Entry en = b.mEntries[ct]; |
| 81 | rs.nTypeAdd(en.mDim.mID, en.mValue); |
| 82 | } |
| 83 | int id = rs.nTypeCreate(); |
| 84 | return new Type(id, rs); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | public Type create() { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame^] | 88 | return internalCreate(mRS, this); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | } |