blob: 7dffa54299f81c8a8f2dc786879546603b815dd3 [file] [log] [blame]
Jason Sams044e2ee2011-08-08 16:52:30 -07001/*
2 * Copyright (C) 2011 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/** @file rs_allocation.rsh
18 * \brief Allocation routines
19 *
20 *
21 */
22
23#ifndef __RS_ALLOCATION_RSH__
24#define __RS_ALLOCATION_RSH__
25
26/**
27 * Returns the Allocation for a given pointer. The pointer should point within
28 * a valid allocation. The results are undefined if the pointer is not from a
29 * valid allocation.
Jason Sams08695a92012-09-20 18:30:21 -070030 *
31 * This function is deprecated and will be removed in the SDK from a future
32 * release.
Jason Sams044e2ee2011-08-08 16:52:30 -070033 */
34extern rs_allocation __attribute__((overloadable))
35 rsGetAllocation(const void *);
36
37/**
38 * Query the dimension of an allocation.
39 *
40 * @return uint32_t The X dimension of the allocation.
41 */
42extern uint32_t __attribute__((overloadable))
43 rsAllocationGetDimX(rs_allocation);
44
45/**
46 * Query the dimension of an allocation.
47 *
48 * @return uint32_t The Y dimension of the allocation.
49 */
50extern uint32_t __attribute__((overloadable))
51 rsAllocationGetDimY(rs_allocation);
52
53/**
54 * Query the dimension of an allocation.
55 *
56 * @return uint32_t The Z dimension of the allocation.
57 */
58extern uint32_t __attribute__((overloadable))
59 rsAllocationGetDimZ(rs_allocation);
60
61/**
62 * Query an allocation for the presence of more than one LOD.
63 *
64 * @return uint32_t Returns 1 if more than one LOD is present, 0 otherwise.
65 */
66extern uint32_t __attribute__((overloadable))
67 rsAllocationGetDimLOD(rs_allocation);
68
69/**
70 * Query an allocation for the presence of more than one face.
71 *
72 * @return uint32_t Returns 1 if more than one face is present, 0 otherwise.
73 */
74extern uint32_t __attribute__((overloadable))
75 rsAllocationGetDimFaces(rs_allocation);
76
Alex Sakhartchouk43253872011-09-28 15:23:18 -070077#if (defined(RS_VERSION) && (RS_VERSION >= 14))
78
Jason Sams044e2ee2011-08-08 16:52:30 -070079/**
80 * Copy part of an allocation from another allocation.
81 *
82 * @param dstAlloc Allocation to copy data into.
83 * @param dstOff The offset of the first element to be copied in
84 * the destination allocation.
85 * @param dstMip Mip level in the destination allocation.
86 * @param count The number of elements to be copied.
87 * @param srcAlloc The source data allocation.
88 * @param srcOff The offset of the first element in data to be
89 * copied in the source allocation.
90 * @param srcMip Mip level in the source allocation.
91 */
92extern void __attribute__((overloadable))
93 rsAllocationCopy1DRange(rs_allocation dstAlloc,
94 uint32_t dstOff, uint32_t dstMip,
95 uint32_t count,
96 rs_allocation srcAlloc,
97 uint32_t srcOff, uint32_t srcMip);
98
99/**
100 * Copy a rectangular region into the allocation from another
101 * allocation.
102 *
103 * @param dstAlloc allocation to copy data into.
104 * @param dstXoff X offset of the region to update in the
105 * destination allocation.
106 * @param dstYoff Y offset of the region to update in the
107 * destination allocation.
108 * @param dstMip Mip level in the destination allocation.
109 * @param dstFace Cubemap face of the destination allocation,
110 * ignored for allocations that aren't cubemaps.
111 * @param width Width of the incoming region to update.
112 * @param height Height of the incoming region to update.
113 * @param srcAlloc The source data allocation.
114 * @param srcXoff X offset in data of the source allocation.
115 * @param srcYoff Y offset in data of the source allocation.
116 * @param srcMip Mip level in the source allocation.
117 * @param srcFace Cubemap face of the source allocation,
118 * ignored for allocations that aren't cubemaps.
119 */
120extern void __attribute__((overloadable))
121 rsAllocationCopy2DRange(rs_allocation dstAlloc,
122 uint32_t dstXoff, uint32_t dstYoff,
123 uint32_t dstMip,
124 rs_allocation_cubemap_face dstFace,
125 uint32_t width, uint32_t height,
126 rs_allocation srcAlloc,
127 uint32_t srcXoff, uint32_t srcYoff,
128 uint32_t srcMip,
129 rs_allocation_cubemap_face srcFace);
130
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700131#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
Jason Sams044e2ee2011-08-08 16:52:30 -0700132
133/**
134 * Extract a single element from an allocation.
135 */
136extern const void * __attribute__((overloadable))
Stephen Hinese7812282013-06-19 00:07:04 -0700137 rsGetElementAt(rs_allocation a, uint32_t x);
Jason Sams044e2ee2011-08-08 16:52:30 -0700138/**
139 * \overload
140 */
141extern const void * __attribute__((overloadable))
Stephen Hinese7812282013-06-19 00:07:04 -0700142 rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y);
Jason Sams044e2ee2011-08-08 16:52:30 -0700143/**
144 * \overload
145 */
146extern const void * __attribute__((overloadable))
Stephen Hinese7812282013-06-19 00:07:04 -0700147 rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y, uint32_t z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700148
Jason Sams9c7d4c42012-09-24 17:00:05 -0700149
Jason Sams988bfc42013-02-26 13:11:28 -0800150#if (defined(RS_VERSION) && (RS_VERSION >= 18))
151 #define GET_ELEMENT_AT(T) \
152 extern T __attribute__((overloadable)) \
153 rsGetElementAt_##T(rs_allocation a, uint32_t x); \
154 extern T __attribute__((overloadable)) \
155 rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y); \
156 extern T __attribute__((overloadable)) \
157 rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z);
158#else
159 #define GET_ELEMENT_AT(T) \
160 static inline T __attribute__((overloadable)) \
161 rsGetElementAt_##T(rs_allocation a, uint32_t x) { \
162 return ((T *)rsGetElementAt(a, x))[0]; \
163 } \
164 static inline T __attribute__((overloadable)) \
165 rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y) { \
166 return ((T *)rsGetElementAt(a, x, y))[0]; \
167 } \
168 static inline T __attribute__((overloadable)) \
169 rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) { \
170 return ((T *)rsGetElementAt(a, x, y, z))[0]; \
171 }
172#endif
Jason Sams9c7d4c42012-09-24 17:00:05 -0700173
174GET_ELEMENT_AT(char)
175GET_ELEMENT_AT(char2)
176GET_ELEMENT_AT(char3)
177GET_ELEMENT_AT(char4)
178GET_ELEMENT_AT(uchar)
179GET_ELEMENT_AT(uchar2)
180GET_ELEMENT_AT(uchar3)
181GET_ELEMENT_AT(uchar4)
182GET_ELEMENT_AT(short)
183GET_ELEMENT_AT(short2)
184GET_ELEMENT_AT(short3)
185GET_ELEMENT_AT(short4)
186GET_ELEMENT_AT(ushort)
187GET_ELEMENT_AT(ushort2)
188GET_ELEMENT_AT(ushort3)
189GET_ELEMENT_AT(ushort4)
190GET_ELEMENT_AT(int)
191GET_ELEMENT_AT(int2)
192GET_ELEMENT_AT(int3)
193GET_ELEMENT_AT(int4)
194GET_ELEMENT_AT(uint)
195GET_ELEMENT_AT(uint2)
196GET_ELEMENT_AT(uint3)
197GET_ELEMENT_AT(uint4)
198GET_ELEMENT_AT(long)
199GET_ELEMENT_AT(long2)
200GET_ELEMENT_AT(long3)
201GET_ELEMENT_AT(long4)
202GET_ELEMENT_AT(ulong)
203GET_ELEMENT_AT(ulong2)
204GET_ELEMENT_AT(ulong3)
205GET_ELEMENT_AT(ulong4)
206GET_ELEMENT_AT(float)
207GET_ELEMENT_AT(float2)
208GET_ELEMENT_AT(float3)
209GET_ELEMENT_AT(float4)
210GET_ELEMENT_AT(double)
211GET_ELEMENT_AT(double2)
212GET_ELEMENT_AT(double3)
213GET_ELEMENT_AT(double4)
214
215#undef GET_ELEMENT_AT
216
Tim Murraycc63efe2012-10-17 11:43:50 -0700217// Jelly Bean
Alex Sakhartchouk3c0c6062012-03-22 16:59:38 -0700218#if (defined(RS_VERSION) && (RS_VERSION >= 16))
219
Alex Sakhartchouk8d0f59e2011-12-16 14:15:07 -0800220/**
Jason Samsb3220332012-04-02 14:41:54 -0700221 * Send the contents of the Allocation to the queue.
Alex Sakhartchouk340d15a2012-04-16 13:50:40 -0700222 * @param a allocation to work on
Jason Samsb3220332012-04-02 14:41:54 -0700223 */
224extern const void __attribute__((overloadable))
Alex Sakhartchouk340d15a2012-04-16 13:50:40 -0700225 rsAllocationIoSend(rs_allocation a);
Jason Samsb3220332012-04-02 14:41:54 -0700226
227/**
228 * Receive a new set of contents from the queue.
Alex Sakhartchouk340d15a2012-04-16 13:50:40 -0700229 * @param a allocation to work on
Jason Samsb3220332012-04-02 14:41:54 -0700230 */
231extern const void __attribute__((overloadable))
Alex Sakhartchouk340d15a2012-04-16 13:50:40 -0700232 rsAllocationIoReceive(rs_allocation a);
Jason Samsb3220332012-04-02 14:41:54 -0700233
234
235/**
Alex Sakhartchouk340d15a2012-04-16 13:50:40 -0700236 * Get the element object describing the allocation's layout
Alex Sakhartchouk8d0f59e2011-12-16 14:15:07 -0800237 * @param a allocation to get data from
238 * @return element describing allocation layout
239 */
Alex Sakhartchoukb0fa3a62011-12-16 09:44:26 -0800240extern rs_element __attribute__((overloadable))
Alex Sakhartchouk8d0f59e2011-12-16 14:15:07 -0800241 rsAllocationGetElement(rs_allocation a);
Alex Sakhartchouk253325d2011-12-15 09:56:10 -0800242
Alex Sakhartchouk8d0f59e2011-12-16 14:15:07 -0800243/**
Alex Sakhartchouk09db9072012-02-29 16:43:24 -0800244 * Fetch allocation in a way described by the sampler
245 * @param a 1D allocation to sample from
246 * @param s sampler state
247 * @param location to sample from
248 */
249extern const float4 __attribute__((overloadable))
250 rsSample(rs_allocation a, rs_sampler s, float location);
251/**
252 * Fetch allocation in a way described by the sampler
253 * @param a 1D allocation to sample from
254 * @param s sampler state
255 * @param location to sample from
256 * @param lod mip level to sample from, for fractional values
257 * mip levels will be interpolated if
258 * RS_SAMPLER_LINEAR_MIP_LINEAR is used
259 */
260extern const float4 __attribute__((overloadable))
261 rsSample(rs_allocation a, rs_sampler s, float location, float lod);
262
263/**
264 * Fetch allocation in a way described by the sampler
265 * @param a 2D allocation to sample from
266 * @param s sampler state
267 * @param location to sample from
268 */
269extern const float4 __attribute__((overloadable))
270 rsSample(rs_allocation a, rs_sampler s, float2 location);
271
272/**
273 * Fetch allocation in a way described by the sampler
274 * @param a 2D allocation to sample from
275 * @param s sampler state
276 * @param location to sample from
277 * @param lod mip level to sample from, for fractional values
278 * mip levels will be interpolated if
279 * RS_SAMPLER_LINEAR_MIP_LINEAR is used
280 */
281extern const float4 __attribute__((overloadable))
282 rsSample(rs_allocation a, rs_sampler s, float2 location, float lod);
283
Alex Sakhartchouk3c0c6062012-03-22 16:59:38 -0700284#endif // (defined(RS_VERSION) && (RS_VERSION >= 16))
Alex Sakhartchouk09db9072012-02-29 16:43:24 -0800285
Tim Murraycc63efe2012-10-17 11:43:50 -0700286#if (defined(RS_VERSION) && (RS_VERSION >= 18))
287
288/**
289 * Set single element of an allocation.
290 */
291extern void __attribute__((overloadable))
292 rsSetElementAt(rs_allocation a, void* ptr, uint32_t x);
293
294/**
295 * \overload
296 */
297extern void __attribute__((overloadable))
298 rsSetElementAt(rs_allocation a, void* ptr, uint32_t x, uint32_t y);
Tim Murray1a569762012-12-11 15:25:12 -0800299
300#define SET_ELEMENT_AT(T) \
301 extern void __attribute__((overloadable)) \
Jason Sams988bfc42013-02-26 13:11:28 -0800302 rsSetElementAt_##T(rs_allocation a, T val, uint32_t x); \
Tim Murray1a569762012-12-11 15:25:12 -0800303 extern void __attribute__((overloadable)) \
Jason Sams988bfc42013-02-26 13:11:28 -0800304 rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y); \
305 extern void __attribute__((overloadable)) \
306 rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y, uint32_t z);
307
Tim Murray1a569762012-12-11 15:25:12 -0800308
309SET_ELEMENT_AT(char)
310SET_ELEMENT_AT(char2)
311SET_ELEMENT_AT(char3)
312SET_ELEMENT_AT(char4)
313SET_ELEMENT_AT(uchar)
314SET_ELEMENT_AT(uchar2)
315SET_ELEMENT_AT(uchar3)
316SET_ELEMENT_AT(uchar4)
317SET_ELEMENT_AT(short)
318SET_ELEMENT_AT(short2)
319SET_ELEMENT_AT(short3)
320SET_ELEMENT_AT(short4)
321SET_ELEMENT_AT(ushort)
322SET_ELEMENT_AT(ushort2)
323SET_ELEMENT_AT(ushort3)
324SET_ELEMENT_AT(ushort4)
325SET_ELEMENT_AT(int)
326SET_ELEMENT_AT(int2)
327SET_ELEMENT_AT(int3)
328SET_ELEMENT_AT(int4)
329SET_ELEMENT_AT(uint)
330SET_ELEMENT_AT(uint2)
331SET_ELEMENT_AT(uint3)
332SET_ELEMENT_AT(uint4)
333SET_ELEMENT_AT(long)
334SET_ELEMENT_AT(long2)
335SET_ELEMENT_AT(long3)
336SET_ELEMENT_AT(long4)
337SET_ELEMENT_AT(ulong)
338SET_ELEMENT_AT(ulong2)
339SET_ELEMENT_AT(ulong3)
340SET_ELEMENT_AT(ulong4)
341SET_ELEMENT_AT(float)
342SET_ELEMENT_AT(float2)
343SET_ELEMENT_AT(float3)
344SET_ELEMENT_AT(float4)
345SET_ELEMENT_AT(double)
346SET_ELEMENT_AT(double2)
347SET_ELEMENT_AT(double3)
348SET_ELEMENT_AT(double4)
349
350#undef SET_ELEMENT_AT
351
352
Jason Sams4cb96872013-04-03 14:02:58 -0700353/**
354 * Extract a single element from an allocation.
355 */
356extern const uchar __attribute__((overloadable))
357 rsGetElementAtYuv_uchar_Y(rs_allocation a, uint32_t x, uint32_t y);
358
359/**
360 * Extract a single element from an allocation.
361 *
362 * Coordinates are in the dimensions of the Y plane
363 */
364extern const uchar __attribute__((overloadable))
365 rsGetElementAtYuv_uchar_U(rs_allocation a, uint32_t x, uint32_t y);
366
367/**
368 * Extract a single element from an allocation.
369 *
370 * Coordinates are in the dimensions of the Y plane
371 */
372extern const uchar __attribute__((overloadable))
373 rsGetElementAtYuv_uchar_V(rs_allocation a, uint32_t x, uint32_t y);
374
Tim Murraycc63efe2012-10-17 11:43:50 -0700375#endif // (defined(RS_VERSION) && (RS_VERSION >= 18))
376
Jason Sams044e2ee2011-08-08 16:52:30 -0700377#endif
378