blob: a5fc6037b0486d0bc7fe771b8ee782f03c9df910 [file] [log] [blame]
Jason Samsb8c5a842009-07-31 20:40:47 -07001/*
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
Jason Samsb8c5a842009-07-31 20:40:47 -070019import android.util.Config;
20import android.util.Log;
21
Jason Samsb8c5a842009-07-31 20:40:47 -070022
23/**
24 * @hide
25 *
26 **/
27public class Type extends BaseObj {
Jason Sams1bada8c2009-08-09 17:01:55 -070028 Dimension[] mDimensions;
29 int[] mValues;
30 Element mElement;
31
32
Jason Samsb8c5a842009-07-31 20:40:47 -070033 Type(int id, RenderScript rs) {
34 super(rs);
35 mID = id;
36 }
37
38 public void destroy() {
Jason Sams1bada8c2009-08-09 17:01:55 -070039 if(mDestroyed) {
40 throw new IllegalStateException("Object already destroyed.");
41 }
42 mDestroyed = true;
Jason Samsb8c5a842009-07-31 20:40:47 -070043 mRS.nTypeDestroy(mID);
Jason Samsb8c5a842009-07-31 20:40:47 -070044 }
45
46 public static class Builder {
47 RenderScript mRS;
Jason Sams22534172009-08-04 16:58:20 -070048 Entry[] mEntries;
49 int mEntryCount;
50 Element mElement;
Jason Samsb8c5a842009-07-31 20:40:47 -070051
Jason Sams22534172009-08-04 16:58:20 -070052 class Entry {
53 Dimension mDim;
54 int mValue;
Jason Samsb8c5a842009-07-31 20:40:47 -070055 }
56
Jason Sams22534172009-08-04 16:58:20 -070057 public Builder(RenderScript rs, Element e) {
58 mRS = rs;
59 mEntries = new Entry[4];
60 mElement = e;
Jason Samsb8c5a842009-07-31 20:40:47 -070061 }
62
63 public void add(Dimension d, int value) {
Jason Sams22534172009-08-04 16:58:20 -070064 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 Samsb8c5a842009-07-31 20:40:47 -070085 }
86
87 public Type create() {
Jason Sams1bada8c2009-08-09 17:01:55 -070088 Type t = internalCreate(mRS, this);
89 t.mElement = mElement;
90 t.mDimensions = new Dimension[mEntryCount];
91 t.mValues = new int[mEntryCount];
92 for(int ct=0; ct < mEntryCount; ct++) {
93 t.mDimensions[ct] = mEntries[ct].mDim;
94 t.mValues[ct] = mEntries[ct].mValue;
95 }
96 return t;
Jason Samsb8c5a842009-07-31 20:40:47 -070097 }
98 }
99
100}