Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | #ifndef ANDROID_RS_ADAPTER_H |
| 18 | #define ANDROID_RS_ADAPTER_H |
| 19 | |
| 20 | #include "rsAllocation.h" |
| 21 | |
| 22 | // --------------------------------------------------------------------------- |
| 23 | namespace android { |
| 24 | namespace renderscript { |
| 25 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 26 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 27 | class Adapter1D : public ObjectBase { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | |
| 29 | public: |
| 30 | // By policy this allocation will hold a pointer to the type |
| 31 | // but will not destroy it on destruction. |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 32 | Adapter1D(Context *); |
| 33 | Adapter1D(Context *, Allocation *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 34 | void reset(); |
| 35 | void * getElement(uint32_t x); |
| 36 | |
| 37 | void setAllocation(Allocation *a) {mAllocation.set(a);} |
| 38 | |
| 39 | uint32_t getDimX() const {return mAllocation->getType()->getLODDimX(mLOD);} |
| 40 | |
| 41 | const Type * getBaseType() const {return mAllocation->getType();} |
| 42 | |
| 43 | inline void setY(uint32_t y) {mY = y;} |
| 44 | inline void setZ(uint32_t z) {mZ = z;} |
| 45 | inline void setLOD(uint32_t lod) {mLOD = lod;} |
| 46 | inline void setFace(uint32_t face) {mFace = face;} |
| 47 | //void setArray(uint32_t num, uint32_t value); |
| 48 | |
| 49 | void subData(uint32_t xoff, uint32_t count, const void *data); |
| 50 | void data(const void *data); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 51 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 52 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 53 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ADAPTER_1D; } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 54 | static Adapter1D *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 55 | |
| 56 | protected: |
| 57 | ObjectBaseRef<Allocation> mAllocation; |
| 58 | uint32_t mY; |
| 59 | uint32_t mZ; |
| 60 | uint32_t mLOD; |
| 61 | uint32_t mFace; |
| 62 | }; |
| 63 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 64 | class Adapter2D : public ObjectBase { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 65 | |
| 66 | public: |
| 67 | // By policy this allocation will hold a pointer to the type |
| 68 | // but will not destroy it on destruction. |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 69 | Adapter2D(Context *); |
| 70 | Adapter2D(Context *, Allocation *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 71 | void reset(); |
| 72 | void * getElement(uint32_t x, uint32_t y) const; |
| 73 | |
| 74 | uint32_t getDimX() const {return mAllocation->getType()->getLODDimX(mLOD);} |
| 75 | uint32_t getDimY() const {return mAllocation->getType()->getLODDimY(mLOD);} |
| 76 | const Type * getBaseType() const {return mAllocation->getType();} |
| 77 | |
| 78 | void setAllocation(Allocation *a) {mAllocation.set(a);} |
| 79 | inline void setZ(uint32_t z) {mZ = z;} |
| 80 | inline void setLOD(uint32_t lod) {mLOD = lod;} |
| 81 | inline void setFace(uint32_t face) {mFace = face;} |
| 82 | //void setArray(uint32_t num, uint32_t value); |
| 83 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 84 | void data(const void *data); |
| 85 | void subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 86 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 87 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 88 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ADAPTER_2D; } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 89 | static Adapter2D *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | |
| 91 | protected: |
| 92 | ObjectBaseRef<Allocation> mAllocation; |
| 93 | uint32_t mZ; |
| 94 | uint32_t mLOD; |
| 95 | uint32_t mFace; |
| 96 | }; |
| 97 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | #endif |
| 101 | |