Add support for YUV allocations.
Change-Id: I21a47c745a2f8435af4f37ec0ad624002f3db555
diff --git a/cpp/Type.cpp b/cpp/Type.cpp
index 6b9ac40..b2dfa23 100644
--- a/cpp/Type.cpp
+++ b/cpp/Type.cpp
@@ -147,7 +147,7 @@
}
void * id = rsTypeCreate(mRS->getContext(), mElement->getID(), mDimX, mDimY, mDimZ,
- mDimMipmaps, mDimFaces);
+ mDimMipmaps, mDimFaces, 0);
Type *t = new Type(id, mRS);
t->mElement = mElement;
t->mDimX = mDimX;
diff --git a/driver/rsdAllocation.cpp b/driver/rsdAllocation.cpp
index 2f0c0d8..3ad29b6 100644
--- a/driver/rsdAllocation.cpp
+++ b/driver/rsdAllocation.cpp
@@ -208,7 +208,7 @@
}
RSD_CALL_GL(glBindRenderbuffer, GL_RENDERBUFFER, drv->renderTargetID);
RSD_CALL_GL(glRenderbufferStorage, GL_RENDERBUFFER, drv->glFormat,
- alloc->mHal.state.dimensionX, alloc->mHal.state.dimensionY);
+ alloc->mHal.drvState.lod[0].dimX, alloc->mHal.drvState.lod[0].dimY);
}
rsdGLCheckError(rsc, "AllocateRenderTarget");
#endif
@@ -399,6 +399,9 @@
void rsdAllocationResize(const Context *rsc, const Allocation *alloc,
const Type *newType, bool zeroNew) {
+ const uint32_t oldDimX = alloc->mHal.drvState.lod[0].dimX;
+ const uint32_t dimX = newType->getDimX();
+
// can't resize Allocations with user-allocated buffers
if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SHARED) {
ALOGE("Resize cannot be called on a USAGE_SHARED allocation");
@@ -414,8 +417,6 @@
rsAssert(!"Size mismatch");
}
- const uint32_t oldDimX = alloc->mHal.state.dimensionX;
- const uint32_t dimX = newType->getDimX();
if (dimX > oldDimX) {
uint32_t stride = alloc->mHal.state.elementSizeBytes;
@@ -570,8 +571,8 @@
return;
}
- r = native_window_set_buffers_dimensions(nw, alloc->mHal.state.dimensionX,
- alloc->mHal.state.dimensionY);
+ r = native_window_set_buffers_dimensions(nw, alloc->mHal.drvState.lod[0].dimX,
+ alloc->mHal.drvState.lod[0].dimY);
if (r) {
rsc->setError(RS_ERROR_DRIVER, "Error setting IO output buffer dimensions.");
return;
diff --git a/rs.spec b/rs.spec
index 5802a0c..52950a2 100644
--- a/rs.spec
+++ b/rs.spec
@@ -34,6 +34,7 @@
param uint32_t dimZ
param bool mips
param bool faces
+ param uint32_t yuv
ret RsType
}
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index f928170..80a40d8 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -54,14 +54,11 @@
void Allocation::updateCache() {
const Type *type = mHal.state.type;
- mHal.state.dimensionX = type->getDimX();
- mHal.state.dimensionY = type->getDimY();
- mHal.state.dimensionZ = type->getDimZ();
+ mHal.state.yuv = type->getDimYuv();
mHal.state.hasFaces = type->getDimFaces();
mHal.state.hasMipmaps = type->getDimLOD();
mHal.state.elementSizeBytes = type->getElementSizeBytes();
mHal.state.hasReferences = mHal.state.type->getElement()->getHasReferences();
- mHal.state.eType = mHal.state.type->getElement()->getType();
}
Allocation::~Allocation() {
@@ -180,7 +177,7 @@
return;
}
- if (x >= mHal.state.dimensionX) {
+ if (x >= mHal.drvState.lod[0].dimX) {
ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
return;
@@ -202,13 +199,13 @@
const void *data, uint32_t cIdx, size_t sizeBytes) {
size_t eSize = mHal.state.elementSizeBytes;
- if (x >= mHal.state.dimensionX) {
+ if (x >= mHal.drvState.lod[0].dimX) {
ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
return;
}
- if (y >= mHal.state.dimensionY) {
+ if (y >= mHal.drvState.lod[0].dimY) {
ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
return;
@@ -447,7 +444,7 @@
}
void Allocation::resize1D(Context *rsc, uint32_t dimX) {
- uint32_t oldDimX = mHal.state.dimensionX;
+ uint32_t oldDimX = mHal.drvState.lod[0].dimX;
if (dimX == oldDimX) {
return;
}
diff --git a/rsAllocation.h b/rsAllocation.h
index 637bf4e..09ce104 100644
--- a/rsAllocation.h
+++ b/rsAllocation.h
@@ -54,9 +54,7 @@
// Cached fields from the Type and Element
// to prevent pointer chasing in critical loops.
- uint32_t dimensionX;
- uint32_t dimensionY;
- uint32_t dimensionZ;
+ uint32_t yuv;
uint32_t elementSizeBytes;
bool hasMipmaps;
bool hasFaces;
@@ -65,7 +63,6 @@
int32_t surfaceTextureID;
ANativeWindow *wndSurface;
GLConsumer *surfaceTexture;
- RsDataType eType;
};
State state;
diff --git a/rsFont.cpp b/rsFont.cpp
index 0d14d1b..3665a3d 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -507,7 +507,7 @@
builder.add(gammaElem.get(), "Gamma", 1);
ObjectBaseRef<const Element> constInput = builder.create(mRSC);
- ObjectBaseRef<Type> inputType = Type::getTypeRef(mRSC, constInput.get(), 1, 0, 0, false, false);
+ ObjectBaseRef<Type> inputType = Type::getTypeRef(mRSC, constInput.get(), 1, 0, 0, false, false, 0);
uint32_t tmp[4];
tmp[0] = RS_PROGRAM_PARAM_CONSTANT;
@@ -545,7 +545,7 @@
mCacheHeight = 256;
mCacheWidth = 1024;
ObjectBaseRef<Type> texType = Type::getTypeRef(mRSC, alphaElem.get(),
- mCacheWidth, mCacheHeight, 0, false, false);
+ mCacheWidth, mCacheHeight, 0, false, false, 0);
mCacheBuffer = new uint8_t[mCacheWidth * mCacheHeight];
@@ -575,7 +575,7 @@
// Now lets write index data
ObjectBaseRef<const Element> indexElem = Element::createRef(mRSC, RS_TYPE_UNSIGNED_16, RS_KIND_USER, false, 1);
uint32_t numIndicies = mMaxNumberOfQuads * 6;
- ObjectBaseRef<Type> indexType = Type::getTypeRef(mRSC, indexElem.get(), numIndicies, 0, 0, false, false);
+ ObjectBaseRef<Type> indexType = Type::getTypeRef(mRSC, indexElem.get(), numIndicies, 0, 0, false, false, 0);
Allocation *indexAlloc = Allocation::createAllocation(mRSC, indexType.get(),
RS_ALLOCATION_USAGE_SCRIPT |
@@ -608,7 +608,7 @@
ObjectBaseRef<Type> vertexDataType = Type::getTypeRef(mRSC, vertexDataElem.get(),
mMaxNumberOfQuads * 4,
- 0, 0, false, false);
+ 0, 0, false, false, 0);
Allocation *vertexAlloc = Allocation::createAllocation(mRSC, vertexDataType.get(),
RS_ALLOCATION_USAGE_SCRIPT);
diff --git a/rsProgramFragment.cpp b/rsProgramFragment.cpp
index 438b620..f2885a9 100644
--- a/rsProgramFragment.cpp
+++ b/rsProgramFragment.cpp
@@ -106,7 +106,7 @@
builder.add(colorElem.get(), "Color", 1);
ObjectBaseRef<const Element> constInput = builder.create(rsc);
- ObjectBaseRef<Type> inputType = Type::getTypeRef(rsc, constInput.get(), 1, 0, 0, false, false);
+ ObjectBaseRef<Type> inputType = Type::getTypeRef(rsc, constInput.get(), 1, 0, 0, false, false, 0);
uint32_t tmp[2];
tmp[0] = RS_PROGRAM_PARAM_CONSTANT;
diff --git a/rsProgramVertex.cpp b/rsProgramVertex.cpp
index c2ce7ee..5265216 100644
--- a/rsProgramVertex.cpp
+++ b/rsProgramVertex.cpp
@@ -188,7 +188,7 @@
inputBuilder.add(f2Elem.get(), "texture0", 1);
ObjectBaseRef<const Element> attrElem = inputBuilder.create(rsc);
- ObjectBaseRef<Type> inputType = Type::getTypeRef(rsc, constInput.get(), 1, 0, 0, false, false);
+ ObjectBaseRef<Type> inputType = Type::getTypeRef(rsc, constInput.get(), 1, 0, 0, false, false, 0);
String8 shaderString(RS_SHADER_INTERNAL);
shaderString.append("varying vec4 varColor;\n");
diff --git a/rsType.cpp b/rsType.cpp
index 7ed8d97..1fba2f9 100644
--- a/rsType.cpp
+++ b/rsType.cpp
@@ -193,7 +193,7 @@
uint32_t z = stream->loadU32();
uint8_t lod = stream->loadU8();
uint8_t faces = stream->loadU8();
- Type *type = Type::getType(rsc, elem, x, y, z, lod != 0, faces !=0 );
+ Type *type = Type::getType(rsc, elem, x, y, z, lod != 0, faces !=0, 0);
elem->decUserRef();
return type;
}
@@ -217,7 +217,7 @@
ObjectBaseRef<Type> Type::getTypeRef(Context *rsc, const Element *e,
uint32_t dimX, uint32_t dimY, uint32_t dimZ,
- bool dimLOD, bool dimFaces) {
+ bool dimLOD, bool dimFaces, uint32_t dimYuv) {
ObjectBaseRef<Type> returnRef;
TypeState * stc = &rsc->mStateType;
@@ -231,6 +231,7 @@
if (t->getDimZ() != dimZ) continue;
if (t->getDimLOD() != dimLOD) continue;
if (t->getDimFaces() != dimFaces) continue;
+ if (t->getDimYuv() != dimYuv) continue;
returnRef.set(t);
ObjectBase::asyncUnlock();
return returnRef;
@@ -246,6 +247,7 @@
nt->mHal.state.dimY = dimY;
nt->mHal.state.dimZ = dimZ;
nt->mHal.state.faces = dimFaces;
+ nt->mHal.state.dimYuv = dimYuv;
nt->compute();
ObjectBase::asyncLock();
@@ -257,14 +259,14 @@
ObjectBaseRef<Type> Type::cloneAndResize1D(Context *rsc, uint32_t dimX) const {
return getTypeRef(rsc, mElement.get(), dimX,
- getDimY(), getDimZ(), getDimLOD(), getDimFaces());
+ getDimY(), getDimZ(), getDimLOD(), getDimFaces(), getDimYuv());
}
ObjectBaseRef<Type> Type::cloneAndResize2D(Context *rsc,
uint32_t dimX,
uint32_t dimY) const {
return getTypeRef(rsc, mElement.get(), dimX, dimY,
- getDimZ(), getDimLOD(), getDimFaces());
+ getDimZ(), getDimLOD(), getDimFaces(), getDimYuv());
}
@@ -305,10 +307,10 @@
namespace renderscript {
RsType rsi_TypeCreate(Context *rsc, RsElement _e, uint32_t dimX,
- uint32_t dimY, uint32_t dimZ, bool mips, bool faces) {
+ uint32_t dimY, uint32_t dimZ, bool mips, bool faces, uint32_t yuv) {
Element *e = static_cast<Element *>(_e);
- return Type::getType(rsc, e, dimX, dimY, dimZ, mips, faces);
+ return Type::getType(rsc, e, dimX, dimY, dimZ, mips, faces, yuv);
}
}
diff --git a/rsType.h b/rsType.h
index 1d136b4..8ccf757 100644
--- a/rsType.h
+++ b/rsType.h
@@ -49,6 +49,7 @@
uint32_t *lodDimZ;
uint32_t *lodOffset;
uint32_t lodCount;
+ uint32_t dimYuv;
bool faces;
};
State state;
@@ -68,6 +69,7 @@
uint32_t getDimZ() const {return mHal.state.dimZ;}
bool getDimLOD() const {return mDimLOD;}
bool getDimFaces() const {return mHal.state.faces;}
+ uint32_t getDimYuv() const {return mHal.state.dimYuv;}
uint32_t getLODDimX(uint32_t lod) const {
rsAssert(lod < mHal.state.lodCount);
@@ -108,12 +110,12 @@
static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
uint32_t dimX, uint32_t dimY, uint32_t dimZ,
- bool dimLOD, bool dimFaces);
+ bool dimLOD, bool dimFaces, uint32_t dimYuv);
static Type* getType(Context *rsc, const Element *e,
uint32_t dimX, uint32_t dimY, uint32_t dimZ,
- bool dimLOD, bool dimFaces) {
- ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces);
+ bool dimLOD, bool dimFaces, uint32_t yuv) {
+ ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces, yuv);
type->incUserRef();
return type.get();
}