diff options
Diffstat (limited to 'libs/rs/rsAllocation.cpp')
-rw-r--r-- | libs/rs/rsAllocation.cpp | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index 4e8278d..6560101 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -13,12 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#ifndef ANDROID_RS_BUILD_FOR_HOST #include "rsContext.h" #include <GLES/gl.h> #include <GLES2/gl2.h> #include <GLES/glext.h> +#else +#include "rsContextHostStub.h" + +#include <OpenGL/gl.h> +#include <OpenGl/glext.h> +#endif using namespace android; using namespace android::renderscript; @@ -167,9 +173,12 @@ void Allocation::uploadToTexture(const Context *rsc) 0, format, type, ptr); } if (mTextureGenMipmap) { +#ifndef ANDROID_RS_BUILD_FOR_HOST glGenerateMipmap(GL_TEXTURE_2D); +#endif //ANDROID_RS_BUILD_FOR_HOST } + rsc->checkError("Allocation::uploadToTexture"); } void Allocation::deferedUploadToBufferObject(const Context *rsc) @@ -201,6 +210,7 @@ void Allocation::uploadToBufferObject(const Context *rsc) glBindBuffer(GL_ARRAY_BUFFER, mBufferID); glBufferData(GL_ARRAY_BUFFER, mType->getSizeBytes(), getPtr(), GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); + rsc->checkError("Allocation::uploadToBufferObject"); } void Allocation::uploadCheck(const Context *rsc) @@ -284,7 +294,7 @@ void Allocation::subData(uint32_t xoff, uint32_t yoff, uint32_t zoff, void Allocation::addProgramToDirty(const Program *p) { - mToDirtyList.add(p); + mToDirtyList.push(p); } void Allocation::removeProgramToDirty(const Program *p) @@ -316,6 +326,60 @@ void Allocation::dumpLOGV(const char *prefix) const } +void Allocation::serialize(OStream *stream) const +{ + // Need to identify ourselves + stream->addU32((uint32_t)getClassId()); + + String8 name(getName()); + stream->addString(&name); + + // First thing we need to serialize is the type object since it will be needed + // to initialize the class + mType->serialize(stream); + + uint32_t dataSize = mType->getSizeBytes(); + // Write how much data we are storing + stream->addU32(dataSize); + // Now write the data + stream->addByteArray(mPtr, dataSize); +} + +Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) +{ + // First make sure we are reading the correct object + RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); + if(classID != RS_A3D_CLASS_ID_ALLOCATION) { + LOGE("allocation loading skipped due to invalid class id\n"); + return NULL; + } + + String8 name; + stream->loadString(&name); + + Type *type = Type::createFromStream(rsc, stream); + if(!type) { + return NULL; + } + type->compute(); + + // Number of bytes we wrote out for this allocation + uint32_t dataSize = stream->loadU32(); + if(dataSize != type->getSizeBytes()) { + LOGE("failed to read allocation because numbytes written is not the same loaded type wants\n"); + delete type; + return NULL; + } + + Allocation *alloc = new Allocation(rsc, type); + alloc->setName(name.string(), name.size()); + + // Read in all of our allocation data + stream->loadByteArray(alloc->getPtr(), dataSize); + + return alloc; +} + void Allocation::sendDirty() const { for (size_t ct=0; ct < mToDirtyList.size(); ct++) { @@ -495,7 +559,7 @@ static ElementConverter_t pickConverter(const Element *dst, const Element *src) if (srcGLType == GL_UNSIGNED_BYTE && srcGLFmt == GL_RGB && dstGLType == GL_UNSIGNED_SHORT_5_6_5 && - dstGLType == GL_RGB) { + dstGLFmt == GL_RGB) { return elementConverter_888_to_565; } @@ -503,15 +567,21 @@ static ElementConverter_t pickConverter(const Element *dst, const Element *src) if (srcGLType == GL_UNSIGNED_BYTE && srcGLFmt == GL_RGBA && dstGLType == GL_UNSIGNED_SHORT_5_6_5 && - dstGLType == GL_RGB) { + dstGLFmt == GL_RGB) { return elementConverter_8888_to_565; } LOGE("pickConverter, unsuported combo, src %p, dst %p", src, dst); + LOGE("pickConverter, srcGLType = %x, srcGLFmt = %x", srcGLType, srcGLFmt); + LOGE("pickConverter, dstGLType = %x, dstGLFmt = %x", dstGLType, dstGLFmt); + src->dumpLOGV("SRC "); + dst->dumpLOGV("DST "); return 0; } +#ifndef ANDROID_RS_BUILD_FOR_HOST + RsAllocation rsi_AllocationCreateBitmapRef(Context *rsc, RsType vtype, void *bmp, void *callbackData, RsBitmapCallback_t callback) { @@ -613,6 +683,15 @@ void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data) a->read(data); } +const void* rsi_AllocationGetType(Context *rsc, RsAllocation va) +{ + Allocation *a = static_cast<Allocation *>(va); + a->getType()->incUserRef(); + + return a->getType(); +} + +#endif //ANDROID_RS_BUILD_FOR_HOST } } |