Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 1 | /* |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 2 | * Copyright (C) 2012 The Android Open Source Project |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 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 | |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 17 | #ifndef __ANDROID_ALLOCATION_H__ |
| 18 | #define __ANDROID_ALLOCATION_H__ |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 19 | |
| 20 | #include <pthread.h> |
| 21 | #include <rs.h> |
| 22 | |
| 23 | #include "RenderScript.h" |
| 24 | #include "Type.h" |
| 25 | #include "Element.h" |
| 26 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 27 | namespace android { |
| 28 | namespace renderscriptCpp { |
| 29 | |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 30 | class Allocation : public BaseObj { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 31 | protected: |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 32 | android::sp<const Type> mType; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 33 | uint32_t mUsage; |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 34 | android::sp<Allocation> mAdaptedAllocation; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 35 | |
| 36 | bool mConstrainedLOD; |
| 37 | bool mConstrainedFace; |
| 38 | bool mConstrainedY; |
| 39 | bool mConstrainedZ; |
| 40 | bool mReadAllowed; |
| 41 | bool mWriteAllowed; |
| 42 | uint32_t mSelectedY; |
| 43 | uint32_t mSelectedZ; |
| 44 | uint32_t mSelectedLOD; |
| 45 | RsAllocationCubemapFace mSelectedFace; |
| 46 | |
| 47 | uint32_t mCurrentDimX; |
| 48 | uint32_t mCurrentDimY; |
| 49 | uint32_t mCurrentDimZ; |
| 50 | uint32_t mCurrentCount; |
| 51 | |
| 52 | |
| 53 | void * getIDSafe() const; |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 54 | void updateCacheInfo(sp<const Type> t); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 55 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 56 | Allocation(void *id, RenderScript *rs, sp<const Type> t, uint32_t usage); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 57 | |
| 58 | void validateIsInt32(); |
| 59 | void validateIsInt16(); |
| 60 | void validateIsInt8(); |
| 61 | void validateIsFloat32(); |
| 62 | void validateIsObject(); |
| 63 | |
| 64 | virtual void updateFromNative(); |
| 65 | |
| 66 | void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h); |
| 67 | |
| 68 | public: |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 69 | android::sp<const Type> getType() { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 70 | return mType; |
| 71 | } |
| 72 | |
| 73 | void syncAll(RsAllocationUsageType srcLocation); |
| 74 | void ioSendOutput(); |
| 75 | void ioGetInput(); |
| 76 | |
| 77 | //void copyFrom(BaseObj[] d); |
| 78 | //void copyFromUnchecked(int[] d); |
| 79 | //void copyFromUnchecked(short[] d); |
| 80 | //void copyFromUnchecked(byte[] d); |
| 81 | //void copyFromUnchecked(float[] d); |
| 82 | //void copyFrom(int[] d); |
| 83 | //void copyFrom(short[] d); |
| 84 | //void copyFrom(byte[] d); |
| 85 | //void copyFrom(float[] d); |
| 86 | //void setFromFieldPacker(int xoff, FieldPacker fp); |
| 87 | //void setFromFieldPacker(int xoff, int component_number, FieldPacker fp); |
| 88 | void generateMipmaps(); |
| 89 | void copy1DRangeFromUnchecked(uint32_t off, size_t count, const void *data, size_t dataLen); |
| 90 | void copy1DRangeFrom(uint32_t off, size_t count, const int32_t* d, size_t dataLen); |
| 91 | void copy1DRangeFrom(uint32_t off, size_t count, const int16_t* d, size_t dataLen); |
| 92 | void copy1DRangeFrom(uint32_t off, size_t count, const int8_t* d, size_t dataLen); |
| 93 | void copy1DRangeFrom(uint32_t off, size_t count, const float* d, size_t dataLen); |
| 94 | void copy1DRangeFrom(uint32_t off, size_t count, const Allocation *data, uint32_t dataOff); |
| 95 | |
| 96 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 97 | const int32_t *data, size_t dataLen); |
| 98 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 99 | const int16_t *data, size_t dataLen); |
| 100 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 101 | const int8_t *data, size_t dataLen); |
| 102 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 103 | const float *data, size_t dataLen); |
| 104 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 105 | const Allocation *data, size_t dataLen, |
| 106 | uint32_t dataXoff, uint32_t dataYoff); |
| 107 | |
| 108 | //void copyTo(byte[] d); |
| 109 | //void copyTo(short[] d); |
| 110 | //void copyTo(int[] d); |
| 111 | //void copyTo(float[] d); |
| 112 | void resize(int dimX); |
| 113 | void resize(int dimX, int dimY); |
| 114 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 115 | static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type, |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 116 | RsAllocationMipmapControl mips, uint32_t usage); |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 117 | static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type, |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 118 | RsAllocationMipmapControl mips, uint32_t usage, void * pointer); |
| 119 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 120 | static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type, |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 121 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 122 | static sp<Allocation> createSized(RenderScript *rs, sp<const Element> e, size_t count, |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 123 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| 124 | //SurfaceTexture *getSurfaceTexture(); |
| 125 | //void setSurfaceTexture(SurfaceTexture *sur); |
| 126 | |
| 127 | }; |
| 128 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 129 | } |
| 130 | } |
| 131 | |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 132 | #endif |