Moving lod's into hal struct.

Change-Id: Iaec34fea7c002d7948d91df6b7a1af7f832f74ea
diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp
index 70ab7b7..9ac553e 100644
--- a/libs/rs/rsType.cpp
+++ b/libs/rs/rsType.cpp
@@ -20,9 +20,8 @@
 using namespace android::renderscript;
 
 Type::Type(Context *rsc) : ObjectBase(rsc) {
-    mLODs = 0;
-    mLODCount = 0;
-    clear();
+    memset(&mHal, 0, sizeof(mHal));
+    mDimLOD = false;
 }
 
 void Type::preDestroy() const {
@@ -35,16 +34,15 @@
 }
 
 Type::~Type() {
-    if (mLODs) {
-        delete [] mLODs;
-        mLODs = NULL;
-    }
+    clear();
 }
 
 void Type::clear() {
-    if (mLODs) {
-        delete [] mLODs;
-        mLODs = NULL;
+    if (mHal.state.lodCount) {
+        delete [] mHal.state.lodDimX;
+        delete [] mHal.state.lodDimY;
+        delete [] mHal.state.lodDimZ;
+        delete [] mHal.state.lodOffset;
     }
     mElement.clear();
     memset(&mHal, 0, sizeof(mHal));
@@ -63,33 +61,39 @@
 }
 
 void Type::compute() {
-    uint32_t oldLODCount = mLODCount;
-    if (mHal.state.dimLOD) {
+    uint32_t oldLODCount = mHal.state.lodCount;
+    if (mDimLOD) {
         uint32_t l2x = rsFindHighBit(mHal.state.dimX) + 1;
         uint32_t l2y = rsFindHighBit(mHal.state.dimY) + 1;
         uint32_t l2z = rsFindHighBit(mHal.state.dimZ) + 1;
 
-        mLODCount = rsMax(l2x, l2y);
-        mLODCount = rsMax(mLODCount, l2z);
+        mHal.state.lodCount = rsMax(l2x, l2y);
+        mHal.state.lodCount = rsMax(mHal.state.lodCount, l2z);
     } else {
-        mLODCount = 1;
+        mHal.state.lodCount = 1;
     }
-    if (mLODCount != oldLODCount) {
-        if (mLODs){
-            delete [] mLODs;
+    if (mHal.state.lodCount != oldLODCount) {
+        if (oldLODCount) {
+            delete [] mHal.state.lodDimX;
+            delete [] mHal.state.lodDimY;
+            delete [] mHal.state.lodDimZ;
+            delete [] mHal.state.lodOffset;
         }
-        mLODs = new LOD[mLODCount];
+        mHal.state.lodDimX = new uint32_t[mHal.state.lodCount];
+        mHal.state.lodDimY = new uint32_t[mHal.state.lodCount];
+        mHal.state.lodDimZ = new uint32_t[mHal.state.lodCount];
+        mHal.state.lodOffset = new uint32_t[mHal.state.lodCount];
     }
 
     uint32_t tx = mHal.state.dimX;
     uint32_t ty = mHal.state.dimY;
     uint32_t tz = mHal.state.dimZ;
     size_t offset = 0;
-    for (uint32_t lod=0; lod < mLODCount; lod++) {
-        mLODs[lod].mX = tx;
-        mLODs[lod].mY = ty;
-        mLODs[lod].mZ = tz;
-        mLODs[lod].mOffset = offset;
+    for (uint32_t lod=0; lod < mHal.state.lodCount; lod++) {
+        mHal.state.lodDimX[lod] = tx;
+        mHal.state.lodDimY[lod] = ty;
+        mHal.state.lodDimZ[lod]  = tz;
+        mHal.state.lodOffset[lod] = offset;
         offset += tx * rsMax(ty, 1u) * rsMax(tz, 1u) * mElement->getSizeBytes();
         if (tx > 1) tx >>= 1;
         if (ty > 1) ty >>= 1;
@@ -107,27 +111,29 @@
 }
 
 uint32_t Type::getLODOffset(uint32_t lod, uint32_t x) const {
-    uint32_t offset = mLODs[lod].mOffset;
+    uint32_t offset = mHal.state.lodOffset[lod];
     offset += x * mElement->getSizeBytes();
     return offset;
 }
 
 uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const {
-    uint32_t offset = mLODs[lod].mOffset;
-    offset += (x + y * mLODs[lod].mX) * mElement->getSizeBytes();
+    uint32_t offset = mHal.state.lodOffset[lod];
+    offset += (x + y * mHal.state.lodDimX[lod]) * mElement->getSizeBytes();
     return offset;
 }
 
 uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const {
-    uint32_t offset = mLODs[lod].mOffset;
-    offset += (x + y*mLODs[lod].mX + z*mLODs[lod].mX*mLODs[lod].mY) * mElement->getSizeBytes();
+    uint32_t offset = mHal.state.lodOffset[lod];
+    offset += (x +
+               y * mHal.state.lodDimX[lod] +
+               z * mHal.state.lodDimX[lod] * mHal.state.lodDimY[lod]) * mElement->getSizeBytes();
     return offset;
 }
 
 uint32_t Type::getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face,
                                 uint32_t x, uint32_t y) const {
-    uint32_t offset = mLODs[lod].mOffset;
-    offset += (x + y * mLODs[lod].mX) * mElement->getSizeBytes();
+    uint32_t offset = mHal.state.lodOffset[lod];
+    offset += (x + y * mHal.state.lodDimX[lod]) * mElement->getSizeBytes();
 
     if (face != 0) {
         uint32_t faceOffset = getSizeBytes() / 6;
@@ -143,7 +149,7 @@
                                                       mHal.state.dimX,
                                                       mHal.state.dimY,
                                                       mHal.state.dimZ,
-                                                      mHal.state.dimLOD,
+                                                      mHal.state.lodCount,
                                                       mHal.state.faces);
     snprintf(buf, sizeof(buf), "%s element: ", prefix);
     mElement->dumpLOGV(buf);
@@ -162,7 +168,7 @@
     stream->addU32(mHal.state.dimY);
     stream->addU32(mHal.state.dimZ);
 
-    stream->addU8((uint8_t)(mHal.state.dimLOD ? 1 : 0));
+    stream->addU8((uint8_t)(mHal.state.lodCount ? 1 : 0));
     stream->addU8((uint8_t)(mHal.state.faces ? 1 : 0));
 }
 
@@ -233,12 +239,12 @@
 
 
     Type *nt = new Type(rsc);
+    nt->mDimLOD = dimLOD;
     returnRef.set(nt);
     nt->mElement.set(e);
     nt->mHal.state.dimX = dimX;
     nt->mHal.state.dimY = dimY;
     nt->mHal.state.dimZ = dimZ;
-    nt->mHal.state.dimLOD = dimLOD;
     nt->mHal.state.faces = dimFaces;
     nt->compute();
 
@@ -251,14 +257,14 @@
 
 ObjectBaseRef<Type> Type::cloneAndResize1D(Context *rsc, uint32_t dimX) const {
     return getTypeRef(rsc, mElement.get(), dimX,
-                      mHal.state.dimY, mHal.state.dimZ, mHal.state.dimLOD, mHal.state.faces);
+                      mHal.state.dimY, mHal.state.dimZ, mHal.state.lodCount, mHal.state.faces);
 }
 
 ObjectBaseRef<Type> Type::cloneAndResize2D(Context *rsc,
                               uint32_t dimX,
                               uint32_t dimY) const {
     return getTypeRef(rsc, mElement.get(), dimX, dimY,
-                      mHal.state.dimZ, mHal.state.dimLOD, mHal.state.faces);
+                      mHal.state.dimZ, mHal.state.lodCount, mHal.state.faces);
 }
 
 
@@ -280,13 +286,13 @@
 void rsaTypeGetNativeData(RsContext con, RsType type, uint32_t *typeData, uint32_t typeDataSize) {
     rsAssert(typeDataSize == 6);
     // Pack the data in the follofing way mHal.state.dimX; mHal.state.dimY; mHal.state.dimZ;
-    // mHal.state.dimLOD; mHal.state.faces; mElement; into typeData
+    // mHal.state.lodCount; mHal.state.faces; mElement; into typeData
     Type *t = static_cast<Type *>(type);
 
     (*typeData++) = t->getDimX();
     (*typeData++) = t->getDimY();
     (*typeData++) = t->getDimZ();
-    (*typeData++) = t->getDimLOD();
+    (*typeData++) = t->getDimLOD() ? 1 : 0;
     (*typeData++) = t->getDimFaces() ? 1 : 0;
     (*typeData++) = (uint32_t)t->getElement();
     t->getElement()->incUserRef();
diff --git a/libs/rs/rsType.h b/libs/rs/rsType.h
index 3878156..f1aeb0a 100644
--- a/libs/rs/rsType.h
+++ b/libs/rs/rsType.h
@@ -44,7 +44,11 @@
             uint32_t dimX;
             uint32_t dimY;
             uint32_t dimZ;
-            bool dimLOD;
+            uint32_t *lodDimX;
+            uint32_t *lodDimY;
+            uint32_t *lodDimZ;
+            uint32_t *lodOffset;
+            uint32_t lodCount;
             bool faces;
         };
         State state;
@@ -62,15 +66,24 @@
     uint32_t getDimX() const {return mHal.state.dimX;}
     uint32_t getDimY() const {return mHal.state.dimY;}
     uint32_t getDimZ() const {return mHal.state.dimZ;}
-    uint32_t getDimLOD() const {return mHal.state.dimLOD;}
+    bool getDimLOD() const {return mDimLOD;}
     bool getDimFaces() const {return mHal.state.faces;}
 
-    uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;}
-    uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;}
-    uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;}
-
+    uint32_t getLODDimX(uint32_t lod) const {
+        rsAssert(lod < mHal.state.lodCount);
+        return mHal.state.lodDimX[lod];
+    }
+    uint32_t getLODDimY(uint32_t lod) const {
+        rsAssert(lod < mHal.state.lodCount);
+        return mHal.state.lodDimY[lod];
+    }
+    uint32_t getLODDimZ(uint32_t lod) const {
+        rsAssert(lod < mHal.state.lodCount);
+        return mHal.state.lodDimZ[lod];
+    }
     uint32_t getLODOffset(uint32_t lod) const {
-        rsAssert(lod < mLODCount); return mLODs[lod].mOffset;
+        rsAssert(lod < mHal.state.lodCount);
+        return mHal.state.lodOffset[lod];
     }
     uint32_t getLODOffset(uint32_t lod, uint32_t x) const;
     uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const;
@@ -79,7 +92,7 @@
     uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face,
                               uint32_t x, uint32_t y) const;
 
-    uint32_t getLODCount() const {return mLODCount;}
+    uint32_t getLODCount() const {return mHal.state.lodCount;}
     bool getIsNp2() const;
 
     void clear();
@@ -106,14 +119,8 @@
     }
 
 protected:
-    struct LOD {
-        size_t mX;
-        size_t mY;
-        size_t mZ;
-        size_t mOffset;
-    };
-
     void makeLODTable();
+    bool mDimLOD;
 
     // Internal structure from most to least significant.
     // * Array dimensions
@@ -127,9 +134,6 @@
 
     size_t mMipChainSizeBytes;
     size_t mTotalSizeBytes;
-    LOD *mLODs;
-    uint32_t mLODCount;
-
 protected:
     virtual void preDestroy() const;
     virtual ~Type();