blob: 91ccbd19b9f49869c68f18ca454486d547743cdd [file] [log] [blame]
Jason Sams221a4b12012-02-22 15:22:41 -08001/*
Tim Murray10913a52013-08-20 17:19:47 -07002 * Copyright (C) 2013 The Android Open Source Project
Jason Sams221a4b12012-02-22 15:22:41 -08003 *
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
Jason Sams221a4b12012-02-22 15:22:41 -080017#include "RenderScript.h"
Tim Murray10913a52013-08-20 17:19:47 -070018#include "rsCppInternal.h"
Jason Sams221a4b12012-02-22 15:22:41 -080019
Jason Sams69cccdf2012-04-02 19:11:49 -070020using namespace android;
Tim Murray9eb7f4b2012-11-16 14:02:18 -080021using namespace RSC;
Jason Sams221a4b12012-02-22 15:22:41 -080022
23void * Allocation::getIDSafe() const {
Jason Sams221a4b12012-02-22 15:22:41 -080024 return getID();
25}
26
Jason Sams69cccdf2012-04-02 19:11:49 -070027void Allocation::updateCacheInfo(sp<const Type> t) {
Jason Sams221a4b12012-02-22 15:22:41 -080028 mCurrentDimX = t->getX();
29 mCurrentDimY = t->getY();
30 mCurrentDimZ = t->getZ();
31 mCurrentCount = mCurrentDimX;
32 if (mCurrentDimY > 1) {
33 mCurrentCount *= mCurrentDimY;
34 }
35 if (mCurrentDimZ > 1) {
36 mCurrentCount *= mCurrentDimZ;
37 }
38}
39
Tim Murray84bf2b82012-10-31 16:03:16 -070040Allocation::Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage) :
Tim Murraybaca6c32012-11-14 16:51:46 -080041 BaseObj(id, rs), mSelectedY(0), mSelectedZ(0), mSelectedLOD(0),
42 mSelectedFace(RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X) {
Jason Sams69cccdf2012-04-02 19:11:49 -070043
Jason Sams221a4b12012-02-22 15:22:41 -080044 if ((usage & ~(RS_ALLOCATION_USAGE_SCRIPT |
45 RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE |
46 RS_ALLOCATION_USAGE_GRAPHICS_VERTEX |
47 RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS |
48 RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET |
Jason Sams221a4b12012-02-22 15:22:41 -080049 RS_ALLOCATION_USAGE_IO_INPUT |
Tim Murray96267c22013-02-12 11:25:12 -080050 RS_ALLOCATION_USAGE_IO_OUTPUT |
51 RS_ALLOCATION_USAGE_SHARED)) != 0) {
Jason Sams221a4b12012-02-22 15:22:41 -080052 ALOGE("Unknown usage specified.");
53 }
54
Jason Sams3522f402012-03-23 11:47:26 -070055 if ((usage & RS_ALLOCATION_USAGE_IO_INPUT) != 0) {
Jason Sams221a4b12012-02-22 15:22:41 -080056 mWriteAllowed = false;
Jason Sams3522f402012-03-23 11:47:26 -070057 if ((usage & ~(RS_ALLOCATION_USAGE_IO_INPUT |
Jason Sams221a4b12012-02-22 15:22:41 -080058 RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE |
59 RS_ALLOCATION_USAGE_SCRIPT)) != 0) {
60 ALOGE("Invalid usage combination.");
61 }
62 }
63
64 mType = t;
65 mUsage = usage;
66
Tim Murray89daad62013-07-29 14:30:02 -070067 if (t != NULL) {
Jason Sams221a4b12012-02-22 15:22:41 -080068 updateCacheInfo(t);
69 }
Tim Murray89daad62013-07-29 14:30:02 -070070
Jason Sams221a4b12012-02-22 15:22:41 -080071}
72
Tim Murray89daad62013-07-29 14:30:02 -070073
74
Jason Sams221a4b12012-02-22 15:22:41 -080075void Allocation::validateIsInt32() {
76 RsDataType dt = mType->getElement()->getDataType();
77 if ((dt == RS_TYPE_SIGNED_32) || (dt == RS_TYPE_UNSIGNED_32)) {
78 return;
79 }
80 ALOGE("32 bit integer source does not match allocation type %i", dt);
81}
82
83void Allocation::validateIsInt16() {
84 RsDataType dt = mType->getElement()->getDataType();
85 if ((dt == RS_TYPE_SIGNED_16) || (dt == RS_TYPE_UNSIGNED_16)) {
86 return;
87 }
88 ALOGE("16 bit integer source does not match allocation type %i", dt);
89}
90
91void Allocation::validateIsInt8() {
92 RsDataType dt = mType->getElement()->getDataType();
93 if ((dt == RS_TYPE_SIGNED_8) || (dt == RS_TYPE_UNSIGNED_8)) {
94 return;
95 }
96 ALOGE("8 bit integer source does not match allocation type %i", dt);
97}
98
99void Allocation::validateIsFloat32() {
100 RsDataType dt = mType->getElement()->getDataType();
101 if (dt == RS_TYPE_FLOAT_32) {
102 return;
103 }
104 ALOGE("32 bit float source does not match allocation type %i", dt);
105}
106
107void Allocation::validateIsObject() {
108 RsDataType dt = mType->getElement()->getDataType();
109 if ((dt == RS_TYPE_ELEMENT) ||
110 (dt == RS_TYPE_TYPE) ||
111 (dt == RS_TYPE_ALLOCATION) ||
112 (dt == RS_TYPE_SAMPLER) ||
113 (dt == RS_TYPE_SCRIPT) ||
114 (dt == RS_TYPE_MESH) ||
115 (dt == RS_TYPE_PROGRAM_FRAGMENT) ||
116 (dt == RS_TYPE_PROGRAM_VERTEX) ||
117 (dt == RS_TYPE_PROGRAM_RASTER) ||
118 (dt == RS_TYPE_PROGRAM_STORE)) {
119 return;
120 }
121 ALOGE("Object source does not match allocation type %i", dt);
122}
123
124void Allocation::updateFromNative() {
125 BaseObj::updateFromNative();
126
Tim Murraya4230962013-07-17 16:50:10 -0700127 const void *typeID = RS::dispatch->AllocationGetType(mRS->getContext(), getID());
Jason Sams221a4b12012-02-22 15:22:41 -0800128 if(typeID != NULL) {
Jason Sams69cccdf2012-04-02 19:11:49 -0700129 sp<const Type> old = mType;
130 sp<Type> t = new Type((void *)typeID, mRS);
Jason Sams221a4b12012-02-22 15:22:41 -0800131 t->updateFromNative();
132 updateCacheInfo(t);
133 mType = t;
Jason Sams221a4b12012-02-22 15:22:41 -0800134 }
135}
136
137void Allocation::syncAll(RsAllocationUsageType srcLocation) {
138 switch (srcLocation) {
139 case RS_ALLOCATION_USAGE_SCRIPT:
140 case RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS:
141 case RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE:
142 case RS_ALLOCATION_USAGE_GRAPHICS_VERTEX:
Tim Murray10913a52013-08-20 17:19:47 -0700143 case RS_ALLOCATION_USAGE_SHARED:
Jason Sams221a4b12012-02-22 15:22:41 -0800144 break;
145 default:
Tim Murray10913a52013-08-20 17:19:47 -0700146 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Source must be exactly one usage type.");
147 return;
Jason Sams221a4b12012-02-22 15:22:41 -0800148 }
Tim Murray10913a52013-08-20 17:19:47 -0700149 tryDispatch(mRS, RS::dispatch->AllocationSyncAll(mRS->getContext(), getIDSafe(), srcLocation));
Jason Sams221a4b12012-02-22 15:22:41 -0800150}
151
152void Allocation::ioSendOutput() {
Tim Murray0b575de2013-03-15 15:56:43 -0700153#ifndef RS_COMPATIBILITY_LIB
Jason Sams221a4b12012-02-22 15:22:41 -0800154 if ((mUsage & RS_ALLOCATION_USAGE_IO_OUTPUT) == 0) {
Tim Murray10913a52013-08-20 17:19:47 -0700155 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only send buffer if IO_OUTPUT usage specified.");
156 return;
Jason Sams221a4b12012-02-22 15:22:41 -0800157 }
Tim Murray10913a52013-08-20 17:19:47 -0700158 tryDispatch(mRS, RS::dispatch->AllocationIoSend(mRS->getContext(), getID()));
Tim Murray0b575de2013-03-15 15:56:43 -0700159#endif
Jason Sams221a4b12012-02-22 15:22:41 -0800160}
161
162void Allocation::ioGetInput() {
Tim Murray0b575de2013-03-15 15:56:43 -0700163#ifndef RS_COMPATIBILITY_LIB
Jason Sams221a4b12012-02-22 15:22:41 -0800164 if ((mUsage & RS_ALLOCATION_USAGE_IO_INPUT) == 0) {
Tim Murray10913a52013-08-20 17:19:47 -0700165 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only send buffer if IO_OUTPUT usage specified.");
166 return;
Jason Sams221a4b12012-02-22 15:22:41 -0800167 }
Tim Murray10913a52013-08-20 17:19:47 -0700168 tryDispatch(mRS, RS::dispatch->AllocationIoReceive(mRS->getContext(), getID()));
Tim Murray0b575de2013-03-15 15:56:43 -0700169#endif
Jason Sams221a4b12012-02-22 15:22:41 -0800170}
171
Jason Samsb8a94e22014-02-24 17:52:32 -0800172void * Allocation::getPointer(size_t *stride) {
173 void *p = NULL;
174 if (!(mUsage & RS_ALLOCATION_USAGE_SHARED)) {
175 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Allocation does not support USAGE_SHARED.");
176 return NULL;
177 }
178
179 // FIXME: decide if lack of getPointer should cause compat mode
180 if (RS::dispatch->AllocationGetPointer == NULL) {
181 mRS->throwError(RS_ERROR_RUNTIME_ERROR, "Can't use getPointer on older APIs");
182 return NULL;
183 }
184
185 p = RS::dispatch->AllocationGetPointer(mRS->getContext(), getIDSafe(), 0,
186 RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 0, 0, stride);
187 if (mRS->getError() != RS_SUCCESS) {
188 mRS->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation lock failed");
189 p = NULL;
190 }
191 return p;
Jason Sams221a4b12012-02-22 15:22:41 -0800192}
193
Tim Murray0b93e302012-11-15 14:56:54 -0800194void Allocation::copy1DRangeFrom(uint32_t off, size_t count, const void *data) {
Jason Sams69cccdf2012-04-02 19:11:49 -0700195
Jason Sams221a4b12012-02-22 15:22:41 -0800196 if(count < 1) {
Tim Murray10913a52013-08-20 17:19:47 -0700197 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Count must be >= 1.");
Jason Sams221a4b12012-02-22 15:22:41 -0800198 return;
199 }
200 if((off + count) > mCurrentCount) {
Tim Murraye195a3f2014-03-13 15:04:58 -0700201 ALOGE("Overflow, Available count %u, got %zu at offset %u.", mCurrentCount, count, off);
Tim Murray10913a52013-08-20 17:19:47 -0700202 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Invalid copy specified");
Jason Sams221a4b12012-02-22 15:22:41 -0800203 return;
204 }
Jason Sams221a4b12012-02-22 15:22:41 -0800205
Tim Murray10913a52013-08-20 17:19:47 -0700206 tryDispatch(mRS, RS::dispatch->Allocation1DData(mRS->getContext(), getIDSafe(), off, mSelectedLOD,
207 count, data, count * mType->getElement()->getSizeBytes()));
Jason Sams221a4b12012-02-22 15:22:41 -0800208}
209
Tim Murray0b93e302012-11-15 14:56:54 -0800210void Allocation::copy1DRangeTo(uint32_t off, size_t count, void *data) {
Tim Murray509ea5c2012-11-13 11:56:40 -0800211 if(count < 1) {
Tim Murray10913a52013-08-20 17:19:47 -0700212 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Count must be >= 1.");
Tim Murray509ea5c2012-11-13 11:56:40 -0800213 return;
214 }
215 if((off + count) > mCurrentCount) {
Tim Murraye195a3f2014-03-13 15:04:58 -0700216 ALOGE("Overflow, Available count %u, got %zu at offset %u.", mCurrentCount, count, off);
Tim Murray10913a52013-08-20 17:19:47 -0700217 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Invalid copy specified");
Tim Murray509ea5c2012-11-13 11:56:40 -0800218 return;
219 }
Tim Murray0b93e302012-11-15 14:56:54 -0800220
Tim Murray10913a52013-08-20 17:19:47 -0700221 tryDispatch(mRS, RS::dispatch->Allocation1DRead(mRS->getContext(), getIDSafe(), off, mSelectedLOD,
222 count, data, count * mType->getElement()->getSizeBytes()));
Tim Murray509ea5c2012-11-13 11:56:40 -0800223}
224
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800225void Allocation::copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data,
226 uint32_t dataOff) {
Jason Sams69cccdf2012-04-02 19:11:49 -0700227
Tim Murray10913a52013-08-20 17:19:47 -0700228 tryDispatch(mRS, RS::dispatch->AllocationCopy2DRange(mRS->getContext(), getIDSafe(), off, 0,
229 mSelectedLOD, mSelectedFace,
230 count, 1, data->getIDSafe(), dataOff, 0,
231 data->mSelectedLOD, data->mSelectedFace));
Jason Sams221a4b12012-02-22 15:22:41 -0800232}
233
Tim Murray0b93e302012-11-15 14:56:54 -0800234void Allocation::copy1DFrom(const void* data) {
235 copy1DRangeFrom(0, mCurrentCount, data);
236}
237
238void Allocation::copy1DTo(void* data) {
239 copy1DRangeTo(0, mCurrentCount, data);
240}
241
242
Jason Sams221a4b12012-02-22 15:22:41 -0800243void Allocation::validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h) {
244 if (mAdaptedAllocation != NULL) {
245
246 } else {
247 if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) {
Tim Murray10913a52013-08-20 17:19:47 -0700248 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Updated region larger than allocation.");
Jason Sams221a4b12012-02-22 15:22:41 -0800249 }
250 }
251}
252
253void Allocation::copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800254 const void *data) {
Jason Sams221a4b12012-02-22 15:22:41 -0800255 validate2DRange(xoff, yoff, w, h);
Tim Murray10913a52013-08-20 17:19:47 -0700256 tryDispatch(mRS, RS::dispatch->Allocation2DData(mRS->getContext(), getIDSafe(), xoff,
257 yoff, mSelectedLOD, mSelectedFace,
258 w, h, data, w * h * mType->getElement()->getSizeBytes(),
259 w * mType->getElement()->getSizeBytes()));
Jason Sams221a4b12012-02-22 15:22:41 -0800260}
261
262void Allocation::copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800263 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff) {
Jason Sams221a4b12012-02-22 15:22:41 -0800264 validate2DRange(xoff, yoff, w, h);
Tim Murray10913a52013-08-20 17:19:47 -0700265 tryDispatch(mRS, RS::dispatch->AllocationCopy2DRange(mRS->getContext(), getIDSafe(), xoff, yoff,
266 mSelectedLOD, mSelectedFace,
267 w, h, data->getIDSafe(), dataXoff, dataYoff,
268 data->mSelectedLOD, data->mSelectedFace));
Jason Sams221a4b12012-02-22 15:22:41 -0800269}
270
Tim Murray7b3e3092012-11-16 13:32:24 -0800271void Allocation::copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
272 void* data) {
273 validate2DRange(xoff, yoff, w, h);
Tim Murray10913a52013-08-20 17:19:47 -0700274 tryDispatch(mRS, RS::dispatch->Allocation2DRead(mRS->getContext(), getIDSafe(), xoff, yoff,
275 mSelectedLOD, mSelectedFace, w, h, data,
276 w * h * mType->getElement()->getSizeBytes(),
277 w * mType->getElement()->getSizeBytes()));
Tim Murray7b3e3092012-11-16 13:32:24 -0800278}
279
Tim Murray358747a2012-11-26 13:52:04 -0800280void Allocation::copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
281 const void *data, size_t stride) {
282 validate2DRange(xoff, yoff, w, h);
Tim Murray10913a52013-08-20 17:19:47 -0700283 tryDispatch(mRS, RS::dispatch->Allocation2DData(mRS->getContext(), getIDSafe(), xoff, yoff,
284 mSelectedLOD, mSelectedFace, w, h, data,
285 w * h * mType->getElement()->getSizeBytes(), stride));
Tim Murray358747a2012-11-26 13:52:04 -0800286}
287
288void Allocation::copy2DStridedFrom(const void* data, size_t stride) {
289 copy2DStridedFrom(0, 0, mCurrentDimX, mCurrentDimY, data, stride);
290}
291
292void Allocation::copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
293 void *data, size_t stride) {
294 validate2DRange(xoff, yoff, w, h);
Tim Murray10913a52013-08-20 17:19:47 -0700295 tryDispatch(mRS, RS::dispatch->Allocation2DRead(mRS->getContext(), getIDSafe(), xoff, yoff,
296 mSelectedLOD, mSelectedFace, w, h, data,
297 w * h * mType->getElement()->getSizeBytes(), stride));
Tim Murray358747a2012-11-26 13:52:04 -0800298}
299
300void Allocation::copy2DStridedTo(void* data, size_t stride) {
301 copy2DStridedTo(0, 0, mCurrentDimX, mCurrentDimY, data, stride);
302}
303
Tim Murray9d24ae62013-08-30 12:17:14 -0700304void Allocation::validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
305 uint32_t h, uint32_t d) {
306 if (mAdaptedAllocation != NULL) {
307
308 } else {
309 if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY) || ((zoff + d) > mCurrentDimZ)) {
310 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Updated region larger than allocation.");
311 }
312 }
313}
314
315void Allocation::copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
316 uint32_t h, uint32_t d, const void* data) {
317 validate3DRange(xoff, yoff, zoff, w, h, d);
318 tryDispatch(mRS, RS::dispatch->Allocation3DData(mRS->getContext(), getIDSafe(), xoff, yoff, zoff,
319 mSelectedLOD, w, h, d, data,
320 w * h * d * mType->getElement()->getSizeBytes(),
321 w * mType->getElement()->getSizeBytes()));
322}
323
324void Allocation::copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, uint32_t h, uint32_t d,
325 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff) {
326 validate3DRange(xoff, yoff, zoff, dataXoff, dataYoff, dataZoff);
327 tryDispatch(mRS, RS::dispatch->AllocationCopy3DRange(mRS->getContext(), getIDSafe(), xoff, yoff, zoff,
328 mSelectedLOD, w, h, d, data->getIDSafe(),
329 dataXoff, dataYoff, dataZoff, data->mSelectedLOD));
330}
331
332
Tim Murray89daad62013-07-29 14:30:02 -0700333sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800334 RsAllocationMipmapControl mipmaps, uint32_t usage) {
Tim Murray10913a52013-08-20 17:19:47 -0700335 void *id = 0;
336 if (rs->getError() == RS_SUCCESS) {
Stephen Hines8f615d62013-12-20 12:23:32 -0800337 id = RS::dispatch->AllocationCreateTyped(rs->getContext(), type->getID(), mipmaps, usage, 0);
Tim Murray10913a52013-08-20 17:19:47 -0700338 }
Jason Sams221a4b12012-02-22 15:22:41 -0800339 if (id == 0) {
Tim Murray10913a52013-08-20 17:19:47 -0700340 rs->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation creation failed");
Jason Sams221a4b12012-02-22 15:22:41 -0800341 return NULL;
342 }
343 return new Allocation(id, rs, type, usage);
344}
345
Tim Murray89daad62013-07-29 14:30:02 -0700346sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800347 RsAllocationMipmapControl mipmaps, uint32_t usage,
Tim Murray89daad62013-07-29 14:30:02 -0700348 void *pointer) {
Tim Murray10913a52013-08-20 17:19:47 -0700349 void *id = 0;
350 if (rs->getError() == RS_SUCCESS) {
Stephen Hines8f615d62013-12-20 12:23:32 -0800351 id = RS::dispatch->AllocationCreateTyped(rs->getContext(), type->getID(), mipmaps, usage,
Tim Murray10913a52013-08-20 17:19:47 -0700352 (uintptr_t)pointer);
353 }
Jason Sams221a4b12012-02-22 15:22:41 -0800354 if (id == 0) {
Tim Murray10913a52013-08-20 17:19:47 -0700355 rs->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation creation failed");
356 return NULL;
Jason Sams221a4b12012-02-22 15:22:41 -0800357 }
358 return new Allocation(id, rs, type, usage);
359}
360
Tim Murray89daad62013-07-29 14:30:02 -0700361sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type,
362 uint32_t usage) {
Jason Sams221a4b12012-02-22 15:22:41 -0800363 return createTyped(rs, type, RS_ALLOCATION_MIPMAP_NONE, usage);
364}
365
Tim Murray89daad62013-07-29 14:30:02 -0700366sp<Allocation> Allocation::createSized(sp<RS> rs, sp<const Element> e,
367 size_t count, uint32_t usage) {
Jason Sams221a4b12012-02-22 15:22:41 -0800368 Type::Builder b(rs, e);
369 b.setX(count);
Jason Sams69cccdf2012-04-02 19:11:49 -0700370 sp<const Type> t = b.create();
Jason Sams221a4b12012-02-22 15:22:41 -0800371
Tim Murray684726c2012-11-14 11:57:42 -0800372 return createTyped(rs, t, usage);
373}
374
Tim Murray89daad62013-07-29 14:30:02 -0700375sp<Allocation> Allocation::createSized2D(sp<RS> rs, sp<const Element> e,
376 size_t x, size_t y, uint32_t usage) {
Tim Murray684726c2012-11-14 11:57:42 -0800377 Type::Builder b(rs, e);
378 b.setX(x);
379 b.setY(y);
380 sp<const Type> t = b.create();
381
382 return createTyped(rs, t, usage);
Jason Sams221a4b12012-02-22 15:22:41 -0800383}