Ying Wang | b335bb0 | 2011-11-29 10:23:55 -0800 | [diff] [blame] | 1 | /* |
| 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. |
Ying Wang | 6099914 | 2013-01-07 13:59:36 -0800 | [diff] [blame] | 30 | * |
| 31 | * This function is deprecated and will be removed in the SDK from a future |
| 32 | * release. |
Ying Wang | b335bb0 | 2011-11-29 10:23:55 -0800 | [diff] [blame] | 33 | */ |
| 34 | extern 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 | */ |
| 42 | extern 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 | */ |
| 50 | extern 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 | */ |
| 58 | extern 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 | */ |
| 66 | extern 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 | */ |
| 74 | extern uint32_t __attribute__((overloadable)) |
| 75 | rsAllocationGetDimFaces(rs_allocation); |
| 76 | |
| 77 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 78 | |
| 79 | /** |
| 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 | */ |
| 92 | extern 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 | */ |
| 120 | extern 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 | |
| 131 | #endif //defined(RS_VERSION) && (RS_VERSION >= 14) |
| 132 | |
| 133 | /** |
| 134 | * Extract a single element from an allocation. |
| 135 | */ |
| 136 | extern const void * __attribute__((overloadable)) |
Stephen Hines | 996e4dc | 2013-08-13 01:04:14 -0700 | [diff] [blame] | 137 | rsGetElementAt(rs_allocation a, uint32_t x); |
Ying Wang | b335bb0 | 2011-11-29 10:23:55 -0800 | [diff] [blame] | 138 | /** |
| 139 | * \overload |
| 140 | */ |
| 141 | extern const void * __attribute__((overloadable)) |
Stephen Hines | 996e4dc | 2013-08-13 01:04:14 -0700 | [diff] [blame] | 142 | rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y); |
Ying Wang | b335bb0 | 2011-11-29 10:23:55 -0800 | [diff] [blame] | 143 | /** |
| 144 | * \overload |
| 145 | */ |
| 146 | extern const void * __attribute__((overloadable)) |
Stephen Hines | 996e4dc | 2013-08-13 01:04:14 -0700 | [diff] [blame] | 147 | rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y, uint32_t z); |
Ying Wang | b335bb0 | 2011-11-29 10:23:55 -0800 | [diff] [blame] | 148 | |
Ying Wang | 6099914 | 2013-01-07 13:59:36 -0800 | [diff] [blame] | 149 | |
Tim Murray | 88a6d11 | 2013-03-05 10:02:12 -0800 | [diff] [blame] | 150 | #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 |
Ying Wang | 6099914 | 2013-01-07 13:59:36 -0800 | [diff] [blame] | 173 | |
| 174 | GET_ELEMENT_AT(char) |
| 175 | GET_ELEMENT_AT(char2) |
| 176 | GET_ELEMENT_AT(char3) |
| 177 | GET_ELEMENT_AT(char4) |
| 178 | GET_ELEMENT_AT(uchar) |
| 179 | GET_ELEMENT_AT(uchar2) |
| 180 | GET_ELEMENT_AT(uchar3) |
| 181 | GET_ELEMENT_AT(uchar4) |
| 182 | GET_ELEMENT_AT(short) |
| 183 | GET_ELEMENT_AT(short2) |
| 184 | GET_ELEMENT_AT(short3) |
| 185 | GET_ELEMENT_AT(short4) |
| 186 | GET_ELEMENT_AT(ushort) |
| 187 | GET_ELEMENT_AT(ushort2) |
| 188 | GET_ELEMENT_AT(ushort3) |
| 189 | GET_ELEMENT_AT(ushort4) |
| 190 | GET_ELEMENT_AT(int) |
| 191 | GET_ELEMENT_AT(int2) |
| 192 | GET_ELEMENT_AT(int3) |
| 193 | GET_ELEMENT_AT(int4) |
| 194 | GET_ELEMENT_AT(uint) |
| 195 | GET_ELEMENT_AT(uint2) |
| 196 | GET_ELEMENT_AT(uint3) |
| 197 | GET_ELEMENT_AT(uint4) |
| 198 | GET_ELEMENT_AT(long) |
| 199 | GET_ELEMENT_AT(long2) |
| 200 | GET_ELEMENT_AT(long3) |
| 201 | GET_ELEMENT_AT(long4) |
| 202 | GET_ELEMENT_AT(ulong) |
| 203 | GET_ELEMENT_AT(ulong2) |
| 204 | GET_ELEMENT_AT(ulong3) |
| 205 | GET_ELEMENT_AT(ulong4) |
| 206 | GET_ELEMENT_AT(float) |
| 207 | GET_ELEMENT_AT(float2) |
| 208 | GET_ELEMENT_AT(float3) |
| 209 | GET_ELEMENT_AT(float4) |
| 210 | GET_ELEMENT_AT(double) |
| 211 | GET_ELEMENT_AT(double2) |
| 212 | GET_ELEMENT_AT(double3) |
| 213 | GET_ELEMENT_AT(double4) |
| 214 | |
| 215 | #undef GET_ELEMENT_AT |
| 216 | |
| 217 | // Jelly Bean |
| 218 | #if (defined(RS_VERSION) && (RS_VERSION >= 16)) |
| 219 | |
| 220 | /** |
| 221 | * Send the contents of the Allocation to the queue. |
| 222 | * @param a allocation to work on |
| 223 | */ |
| 224 | extern const void __attribute__((overloadable)) |
| 225 | rsAllocationIoSend(rs_allocation a); |
| 226 | |
| 227 | /** |
| 228 | * Receive a new set of contents from the queue. |
| 229 | * @param a allocation to work on |
| 230 | */ |
| 231 | extern const void __attribute__((overloadable)) |
| 232 | rsAllocationIoReceive(rs_allocation a); |
| 233 | |
| 234 | |
| 235 | /** |
| 236 | * Get the element object describing the allocation's layout |
| 237 | * @param a allocation to get data from |
| 238 | * @return element describing allocation layout |
| 239 | */ |
| 240 | extern rs_element __attribute__((overloadable)) |
| 241 | rsAllocationGetElement(rs_allocation a); |
| 242 | |
| 243 | /** |
| 244 | * 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 | */ |
| 249 | extern 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 | */ |
| 260 | extern 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 | */ |
| 269 | extern 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 | */ |
| 281 | extern const float4 __attribute__((overloadable)) |
| 282 | rsSample(rs_allocation a, rs_sampler s, float2 location, float lod); |
| 283 | |
| 284 | #endif // (defined(RS_VERSION) && (RS_VERSION >= 16)) |
| 285 | |
| 286 | #if (defined(RS_VERSION) && (RS_VERSION >= 18)) |
| 287 | |
| 288 | /** |
| 289 | * Set single element of an allocation. |
| 290 | */ |
| 291 | extern void __attribute__((overloadable)) |
| 292 | rsSetElementAt(rs_allocation a, void* ptr, uint32_t x); |
| 293 | |
| 294 | /** |
| 295 | * \overload |
| 296 | */ |
| 297 | extern void __attribute__((overloadable)) |
| 298 | rsSetElementAt(rs_allocation a, void* ptr, uint32_t x, uint32_t y); |
| 299 | |
| 300 | #define SET_ELEMENT_AT(T) \ |
| 301 | extern void __attribute__((overloadable)) \ |
Tim Murray | 88a6d11 | 2013-03-05 10:02:12 -0800 | [diff] [blame] | 302 | rsSetElementAt_##T(rs_allocation a, T val, uint32_t x); \ |
Ying Wang | 6099914 | 2013-01-07 13:59:36 -0800 | [diff] [blame] | 303 | extern void __attribute__((overloadable)) \ |
Tim Murray | 88a6d11 | 2013-03-05 10:02:12 -0800 | [diff] [blame] | 304 | 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 | |
Ying Wang | 6099914 | 2013-01-07 13:59:36 -0800 | [diff] [blame] | 308 | |
| 309 | SET_ELEMENT_AT(char) |
| 310 | SET_ELEMENT_AT(char2) |
| 311 | SET_ELEMENT_AT(char3) |
| 312 | SET_ELEMENT_AT(char4) |
| 313 | SET_ELEMENT_AT(uchar) |
| 314 | SET_ELEMENT_AT(uchar2) |
| 315 | SET_ELEMENT_AT(uchar3) |
| 316 | SET_ELEMENT_AT(uchar4) |
| 317 | SET_ELEMENT_AT(short) |
| 318 | SET_ELEMENT_AT(short2) |
| 319 | SET_ELEMENT_AT(short3) |
| 320 | SET_ELEMENT_AT(short4) |
| 321 | SET_ELEMENT_AT(ushort) |
| 322 | SET_ELEMENT_AT(ushort2) |
| 323 | SET_ELEMENT_AT(ushort3) |
| 324 | SET_ELEMENT_AT(ushort4) |
| 325 | SET_ELEMENT_AT(int) |
| 326 | SET_ELEMENT_AT(int2) |
| 327 | SET_ELEMENT_AT(int3) |
| 328 | SET_ELEMENT_AT(int4) |
| 329 | SET_ELEMENT_AT(uint) |
| 330 | SET_ELEMENT_AT(uint2) |
| 331 | SET_ELEMENT_AT(uint3) |
| 332 | SET_ELEMENT_AT(uint4) |
| 333 | SET_ELEMENT_AT(long) |
| 334 | SET_ELEMENT_AT(long2) |
| 335 | SET_ELEMENT_AT(long3) |
| 336 | SET_ELEMENT_AT(long4) |
| 337 | SET_ELEMENT_AT(ulong) |
| 338 | SET_ELEMENT_AT(ulong2) |
| 339 | SET_ELEMENT_AT(ulong3) |
| 340 | SET_ELEMENT_AT(ulong4) |
| 341 | SET_ELEMENT_AT(float) |
| 342 | SET_ELEMENT_AT(float2) |
| 343 | SET_ELEMENT_AT(float3) |
| 344 | SET_ELEMENT_AT(float4) |
| 345 | SET_ELEMENT_AT(double) |
| 346 | SET_ELEMENT_AT(double2) |
| 347 | SET_ELEMENT_AT(double3) |
| 348 | SET_ELEMENT_AT(double4) |
| 349 | |
| 350 | #undef SET_ELEMENT_AT |
| 351 | |
| 352 | |
Stephen Hines | aff0e8c | 2013-04-25 19:25:20 -0700 | [diff] [blame] | 353 | /** |
| 354 | * Extract a single element from an allocation. |
| 355 | */ |
| 356 | extern 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 | */ |
| 364 | extern 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 | */ |
| 372 | extern const uchar __attribute__((overloadable)) |
| 373 | rsGetElementAtYuv_uchar_V(rs_allocation a, uint32_t x, uint32_t y); |
| 374 | |
Ying Wang | 6099914 | 2013-01-07 13:59:36 -0800 | [diff] [blame] | 375 | #endif // (defined(RS_VERSION) && (RS_VERSION >= 18)) |
| 376 | |
Stephen Hines | 30047ab | 2014-04-24 10:38:22 -0700 | [diff] [blame] | 377 | |
Stephen Hines | 271efdf | 2014-10-01 20:25:12 -0700 | [diff] [blame] | 378 | #if (defined(RS_VERSION) && (RS_VERSION >= 999)) |
Stephen Hines | 30047ab | 2014-04-24 10:38:22 -0700 | [diff] [blame] | 379 | |
| 380 | #define VOP(T) \ |
| 381 | extern T __attribute__((overloadable)) \ |
| 382 | rsAllocationVLoadX_##T(rs_allocation a, uint32_t x); \ |
| 383 | extern T __attribute__((overloadable)) \ |
| 384 | rsAllocationVLoadX_##T(rs_allocation a, uint32_t x, uint32_t y); \ |
| 385 | extern T __attribute__((overloadable)) \ |
| 386 | rsAllocationVLoadX_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z); \ |
| 387 | extern void __attribute__((overloadable)) \ |
| 388 | rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x); \ |
| 389 | extern void __attribute__((overloadable)) \ |
| 390 | rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x, uint32_t y); \ |
| 391 | extern void __attribute__((overloadable)) \ |
| 392 | rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x, uint32_t y, uint32_t z); |
| 393 | |
| 394 | VOP(char2) |
| 395 | VOP(char3) |
| 396 | VOP(char4) |
| 397 | VOP(uchar2) |
| 398 | VOP(uchar3) |
| 399 | VOP(uchar4) |
| 400 | VOP(short2) |
| 401 | VOP(short3) |
| 402 | VOP(short4) |
| 403 | VOP(ushort2) |
| 404 | VOP(ushort3) |
| 405 | VOP(ushort4) |
| 406 | VOP(int2) |
| 407 | VOP(int3) |
| 408 | VOP(int4) |
| 409 | VOP(uint2) |
| 410 | VOP(uint3) |
| 411 | VOP(uint4) |
| 412 | VOP(long2) |
| 413 | VOP(long3) |
| 414 | VOP(long4) |
| 415 | VOP(ulong2) |
| 416 | VOP(ulong3) |
| 417 | VOP(ulong4) |
| 418 | VOP(float2) |
| 419 | VOP(float3) |
| 420 | VOP(float4) |
| 421 | VOP(double2) |
| 422 | VOP(double3) |
| 423 | VOP(double4) |
| 424 | |
| 425 | #undef VOP |
| 426 | |
| 427 | #endif //(defined(RS_VERSION) && (RS_VERSION >= 999)) |
| 428 | |
| 429 | |
Ying Wang | b335bb0 | 2011-11-29 10:23:55 -0800 | [diff] [blame] | 430 | #endif |
| 431 | |