blob: 6c1b1ed6cc11949628f73cc7130fc490cee0baa5 [file] [log] [blame]
Jason Sams49a05d72010-12-29 14:31:29 -08001/*
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
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070019/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070020 * Only intended for use by generated reflected code.
Jason Sams49a05d72010-12-29 14:31:29 -080021 *
22 **/
23public class AllocationAdapter extends Allocation {
Tim Murray460a0492013-11-19 12:45:54 -080024 AllocationAdapter(long id, RenderScript rs, Allocation alloc) {
Jason Samsba862d12011-07-07 15:24:42 -070025 super(id, rs, alloc.mType, alloc.mUsage);
26 mAdaptedAllocation = alloc;
Jason Sams49a05d72010-12-29 14:31:29 -080027 }
28
Tim Murray460a0492013-11-19 12:45:54 -080029 long getID(RenderScript rs) {
Jason Sams48fe5342011-07-08 13:52:30 -070030 throw new RSInvalidStateException(
31 "This operation is not supported with adapters at this time.");
Jason Samsee2d8092011-06-21 16:42:42 -070032 }
33
Jason Samsba862d12011-07-07 15:24:42 -070034 /**
35 * @hide
36 */
Jason Sams49a05d72010-12-29 14:31:29 -080037 public void subData(int xoff, FieldPacker fp) {
Jason Samsba862d12011-07-07 15:24:42 -070038 super.setFromFieldPacker(xoff, fp);
Jason Sams49a05d72010-12-29 14:31:29 -080039 }
Jason Samsba862d12011-07-07 15:24:42 -070040 /**
41 * @hide
42 */
Jason Sams49a05d72010-12-29 14:31:29 -080043 public void subElementData(int xoff, int component_number, FieldPacker fp) {
Jason Samsba862d12011-07-07 15:24:42 -070044 super.setFromFieldPacker(xoff, component_number, fp);
Jason Sams49a05d72010-12-29 14:31:29 -080045 }
Jason Samsba862d12011-07-07 15:24:42 -070046 /**
47 * @hide
48 */
Jason Sams49a05d72010-12-29 14:31:29 -080049 public void subData1D(int off, int count, int[] d) {
Jason Samsba862d12011-07-07 15:24:42 -070050 super.copy1DRangeFrom(off, count, d);
Jason Sams49a05d72010-12-29 14:31:29 -080051 }
Jason Samsba862d12011-07-07 15:24:42 -070052 /**
53 * @hide
54 */
Jason Sams49a05d72010-12-29 14:31:29 -080055 public void subData1D(int off, int count, short[] d) {
Jason Samsba862d12011-07-07 15:24:42 -070056 super.copy1DRangeFrom(off, count, d);
Jason Sams49a05d72010-12-29 14:31:29 -080057 }
Jason Samsba862d12011-07-07 15:24:42 -070058 /**
59 * @hide
60 */
Jason Sams49a05d72010-12-29 14:31:29 -080061 public void subData1D(int off, int count, byte[] d) {
Jason Samsba862d12011-07-07 15:24:42 -070062 super.copy1DRangeFrom(off, count, d);
Jason Sams49a05d72010-12-29 14:31:29 -080063 }
Jason Samsba862d12011-07-07 15:24:42 -070064 /**
65 * @hide
66 */
Jason Sams49a05d72010-12-29 14:31:29 -080067 public void subData1D(int off, int count, float[] d) {
Jason Samsba862d12011-07-07 15:24:42 -070068 super.copy1DRangeFrom(off, count, d);
Jason Sams49a05d72010-12-29 14:31:29 -080069 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -070070 /**
Jason Samsba862d12011-07-07 15:24:42 -070071 * @hide
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -070072 */
Jason Sams49a05d72010-12-29 14:31:29 -080073 public void subData2D(int xoff, int yoff, int w, int h, int[] d) {
Jason Samsba862d12011-07-07 15:24:42 -070074 super.copy2DRangeFrom(xoff, yoff, w, h, d);
Jason Sams49a05d72010-12-29 14:31:29 -080075 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -070076 /**
Jason Samsba862d12011-07-07 15:24:42 -070077 * @hide
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -070078 */
Jason Samsba862d12011-07-07 15:24:42 -070079 public void subData2D(int xoff, int yoff, int w, int h, float[] d) {
80 super.copy2DRangeFrom(xoff, yoff, w, h, d);
Jason Sams49a05d72010-12-29 14:31:29 -080081 }
Jason Samsba862d12011-07-07 15:24:42 -070082 /**
83 * @hide
84 */
Jason Sams49a05d72010-12-29 14:31:29 -080085 public void readData(int[] d) {
Jason Samsba862d12011-07-07 15:24:42 -070086 super.copyTo(d);
Jason Sams49a05d72010-12-29 14:31:29 -080087 }
Jason Samsba862d12011-07-07 15:24:42 -070088 /**
89 * @hide
90 */
Jason Sams49a05d72010-12-29 14:31:29 -080091 public void readData(float[] d) {
Jason Samsba862d12011-07-07 15:24:42 -070092 super.copyTo(d);
Jason Sams49a05d72010-12-29 14:31:29 -080093 }
94
Jason Samsba862d12011-07-07 15:24:42 -070095 void initLOD(int lod) {
Jason Samsee2d8092011-06-21 16:42:42 -070096 if (lod < 0) {
97 throw new RSIllegalArgumentException("Attempting to set negative lod (" + lod + ").");
98 }
99
Jason Samsba862d12011-07-07 15:24:42 -0700100 int tx = mAdaptedAllocation.mType.getX();
101 int ty = mAdaptedAllocation.mType.getY();
102 int tz = mAdaptedAllocation.mType.getZ();
Jason Samsee2d8092011-06-21 16:42:42 -0700103
104 for (int ct=0; ct < lod; ct++) {
105 if ((tx==1) && (ty == 1) && (tz == 1)) {
106 throw new RSIllegalArgumentException("Attempting to set lod (" + lod + ") out of range.");
107 }
108
109 if (tx > 1) tx >>= 1;
110 if (ty > 1) ty >>= 1;
111 if (tz > 1) tz >>= 1;
112 }
113
Jason Samsba862d12011-07-07 15:24:42 -0700114 mCurrentDimX = tx;
115 mCurrentDimY = ty;
116 mCurrentDimZ = tz;
117 mCurrentCount = mCurrentDimX;
118 if (mCurrentDimY > 1) {
119 mCurrentCount *= mCurrentDimY;
Jason Samsee2d8092011-06-21 16:42:42 -0700120 }
Jason Samsba862d12011-07-07 15:24:42 -0700121 if (mCurrentDimZ > 1) {
122 mCurrentCount *= mCurrentDimZ;
Jason Samsee2d8092011-06-21 16:42:42 -0700123 }
Jason Samsba862d12011-07-07 15:24:42 -0700124 mSelectedY = 0;
125 mSelectedZ = 0;
Jason Samsee2d8092011-06-21 16:42:42 -0700126 }
127
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700128 /**
Jason Samsee2d8092011-06-21 16:42:42 -0700129 * Set the active LOD. The LOD must be within the range for the
Jason Samsba862d12011-07-07 15:24:42 -0700130 * type being adapted. The base allocation must have mipmaps.
131 *
132 * Because this changes the dimensions of the adapter the
133 * current Y and Z will be reset.
Jason Samsee2d8092011-06-21 16:42:42 -0700134 *
135 * @param lod The LOD to make active.
136 */
Jason Sams49a05d72010-12-29 14:31:29 -0800137 public void setLOD(int lod) {
Jason Samsba862d12011-07-07 15:24:42 -0700138 if (!mAdaptedAllocation.getType().hasMipmaps()) {
Jason Samsee2d8092011-06-21 16:42:42 -0700139 throw new RSInvalidStateException("Cannot set LOD when the allocation type does not include mipmaps.");
140 }
141 if (!mConstrainedLOD) {
142 throw new RSInvalidStateException("Cannot set LOD when the adapter includes mipmaps.");
143 }
144
145 initLOD(lod);
Jason Sams49a05d72010-12-29 14:31:29 -0800146 }
147
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700148 /**
Jason Samsba862d12011-07-07 15:24:42 -0700149 * Set the active Face. The base allocation must be of a type
150 * that includes faces.
151 *
152 * @param cf The face to make active.
153 */
Jason Sams49a05d72010-12-29 14:31:29 -0800154 public void setFace(Type.CubemapFace cf) {
Jason Samsba862d12011-07-07 15:24:42 -0700155 if (!mAdaptedAllocation.getType().hasFaces()) {
156 throw new RSInvalidStateException("Cannot set Face when the allocation type does not include faces.");
157 }
158 if (!mConstrainedFace) {
159 throw new RSInvalidStateException("Cannot set LOD when the adapter includes mipmaps.");
160 }
161 if (cf == null) {
162 throw new RSIllegalArgumentException("Cannot set null face.");
163 }
164
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700165 mSelectedFace = cf;
Jason Sams49a05d72010-12-29 14:31:29 -0800166 }
167
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700168 /**
Jason Samsba862d12011-07-07 15:24:42 -0700169 * Set the active Y. The y value must be within the range for
170 * the allocation being adapted. The base allocation must
171 * contain the Y dimension.
172 *
173 * @param y The y to make active.
174 */
Jason Sams49a05d72010-12-29 14:31:29 -0800175 public void setY(int y) {
Jason Samsba862d12011-07-07 15:24:42 -0700176 if (mAdaptedAllocation.getType().getY() == 0) {
177 throw new RSInvalidStateException("Cannot set Y when the allocation type does not include Y dim.");
178 }
179 if (mAdaptedAllocation.getType().getY() <= y) {
180 throw new RSInvalidStateException("Cannot set Y greater than dimension of allocation.");
181 }
182 if (!mConstrainedY) {
183 throw new RSInvalidStateException("Cannot set Y when the adapter includes Y.");
184 }
185
186 mSelectedY = y;
Jason Sams49a05d72010-12-29 14:31:29 -0800187 }
188
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700189 /**
Jason Samsba862d12011-07-07 15:24:42 -0700190 * Set the active Z. The z value must be within the range for
191 * the allocation being adapted. The base allocation must
192 * contain the Z dimension.
193 *
194 * @param z The z to make active.
195 */
Jason Sams49a05d72010-12-29 14:31:29 -0800196 public void setZ(int z) {
Jason Samsba862d12011-07-07 15:24:42 -0700197 if (mAdaptedAllocation.getType().getZ() == 0) {
198 throw new RSInvalidStateException("Cannot set Z when the allocation type does not include Z dim.");
199 }
200 if (mAdaptedAllocation.getType().getZ() <= z) {
201 throw new RSInvalidStateException("Cannot set Z greater than dimension of allocation.");
202 }
203 if (!mConstrainedZ) {
204 throw new RSInvalidStateException("Cannot set Z when the adapter includes Z.");
205 }
206
207 mSelectedZ = z;
Jason Sams49a05d72010-12-29 14:31:29 -0800208 }
209
Jason Samsba862d12011-07-07 15:24:42 -0700210 static public AllocationAdapter create1D(RenderScript rs, Allocation a) {
211 rs.validate();
212 AllocationAdapter aa = new AllocationAdapter(0, rs, a);
213 aa.mConstrainedLOD = true;
214 aa.mConstrainedFace = true;
215 aa.mConstrainedY = true;
216 aa.mConstrainedZ = true;
217 aa.initLOD(0);
218 return aa;
219 }
Jason Sams49a05d72010-12-29 14:31:29 -0800220
221 static public AllocationAdapter create2D(RenderScript rs, Allocation a) {
Jason Samsba862d12011-07-07 15:24:42 -0700222 android.util.Log.e("rs", "create2d " + a);
Jason Sams49a05d72010-12-29 14:31:29 -0800223 rs.validate();
224 AllocationAdapter aa = new AllocationAdapter(0, rs, a);
Jason Samsee2d8092011-06-21 16:42:42 -0700225 aa.mConstrainedLOD = true;
226 aa.mConstrainedFace = true;
227 aa.mConstrainedY = false;
228 aa.mConstrainedZ = true;
229 aa.initLOD(0);
Jason Sams49a05d72010-12-29 14:31:29 -0800230 return aa;
231 }
232
233
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700234 /**
Jason Samsba862d12011-07-07 15:24:42 -0700235 * Override the Allocation resize. Resizing adapters is not
236 * allowed and will throw a RSInvalidStateException.
237 *
238 * @param dimX ignored.
239 */
240 public synchronized void resize(int dimX) {
241 throw new RSInvalidStateException("Resize not allowed for Adapters.");
242 }
243
Jason Sams49a05d72010-12-29 14:31:29 -0800244}
245
246