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