Loading libs/rs/rsAllocation.cpp +63 −35 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages) : Object mUsageFlags = usages; mPtr = malloc(mType->getSizeBytes()); allocScriptMemory(); if (mType->getElement()->getHasReferences()) { memset(mPtr, 0, mType->getSizeBytes()); } Loading Loading @@ -75,10 +75,9 @@ void Allocation::init(Context *rsc, const Type *type) { Allocation::~Allocation() { if (mUserBitmapCallback != NULL) { mUserBitmapCallback(mUserBitmapCallbackData); } else { free(mPtr); } mPtr = NULL; } freeScriptMemory(); if (mBufferID) { // Causes a SW crash.... Loading Loading @@ -108,12 +107,9 @@ bool Allocation::fixAllocation() { return false; } void Allocation::deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset) { rsAssert(lodOffset < mType->getLODCount()); void Allocation::deferedUploadToTexture(const Context *rsc) { mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; mTextureLOD = lodOffset; mUploadDefered = true; mTextureGenMipmap = !mType->getDimLOD() && genMipmap; } uint32_t Allocation::getGLTarget() const { Loading @@ -130,6 +126,20 @@ uint32_t Allocation::getGLTarget() const { return 0; } void Allocation::allocScriptMemory() { rsAssert(!mPtr); mPtr = malloc(mType->getSizeBytes()); } void Allocation::freeScriptMemory() { rsAssert(!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)); if (mPtr) { free(mPtr); mPtr = NULL; } } void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) { rsAssert(src == RS_ALLOCATION_USAGE_SCRIPT); Loading @@ -153,6 +163,10 @@ void Allocation::uploadToTexture(const Context *rsc) { return; } if (!mPtr) { return; } bool isFirstUpload = false; if (!mTextureID) { Loading @@ -171,41 +185,46 @@ void Allocation::uploadToTexture(const Context *rsc) { } GLenum target = (GLenum)getGLTarget(); glBindTexture(target, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if (target == GL_TEXTURE_2D) { upload2DTexture(isFirstUpload); upload2DTexture(isFirstUpload, mPtr); } else if (target == GL_TEXTURE_CUBE_MAP) { uploadCubeTexture(isFirstUpload); } if (mTextureGenMipmap) { if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) { #ifndef ANDROID_RS_BUILD_FOR_HOST glGenerateMipmap(target); #endif //ANDROID_RS_BUILD_FOR_HOST } if (!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)) { freeScriptMemory(); } rsc->checkError("Allocation::uploadToTexture"); } void Allocation::upload2DTexture(bool isFirstUpload) { void Allocation::upload2DTexture(bool isFirstUpload, const void *ptr) { GLenum type = mType->getElement()->getComponent().getGLType(); GLenum format = mType->getElement()->getComponent().getGLFormat(); Adapter2D adapt(getContext(), this); for (uint32_t lod = 0; (lod + mTextureLOD) < mType->getLODCount(); lod++) { adapt.setLOD(lod+mTextureLOD); GLenum target = (GLenum)getGLTarget(); glBindTexture(target, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) { const uint8_t *p = (const uint8_t *)ptr; p += mType->getLODOffset(lod); uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0)); if (isFirstUpload) { glTexImage2D(GL_TEXTURE_2D, lod, format, adapt.getDimX(), adapt.getDimY(), 0, format, type, ptr); mType->getLODDimX(lod), mType->getLODDimY(lod), 0, format, type, p); } else { glTexSubImage2D(GL_TEXTURE_2D, lod, 0, 0, adapt.getDimX(), adapt.getDimY(), format, type, ptr); mType->getLODDimX(lod), mType->getLODDimY(lod), format, type, p); } } } Loading @@ -214,6 +233,10 @@ void Allocation::uploadCubeTexture(bool isFirstUpload) { GLenum type = mType->getElement()->getComponent().getGLType(); GLenum format = mType->getElement()->getComponent().getGLFormat(); GLenum target = (GLenum)getGLTarget(); glBindTexture(target, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); GLenum faceOrder[] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, Loading @@ -227,8 +250,8 @@ void Allocation::uploadCubeTexture(bool isFirstUpload) { for (uint32_t face = 0; face < 6; face ++) { adapt.setFace(face); for (uint32_t lod = 0; (lod + mTextureLOD) < mType->getLODCount(); lod++) { adapt.setLOD(lod+mTextureLOD); for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) { adapt.setLOD(lod); uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0)); Loading Loading @@ -585,7 +608,7 @@ namespace renderscript { void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel) { Allocation *alloc = static_cast<Allocation *>(va); alloc->deferedUploadToTexture(rsc, genmip, baseMipLevel); alloc->deferedUploadToTexture(rsc); } void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va) { Loading Loading @@ -681,6 +704,7 @@ void rsi_AllocationCopyFromBitmap(Context *rsc, RsAllocation va, const void *dat return; } if (texAlloc->getIsScript()) { memcpy(texAlloc->getPtr(), data, s); if (genMips) { Adapter2D adapt(rsc, texAlloc); Loading @@ -691,6 +715,10 @@ void rsi_AllocationCopyFromBitmap(Context *rsc, RsAllocation va, const void *dat mip(adapt2, adapt); } } } else { texAlloc->upload2DTexture(false, data); } } void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t dataLen) { Loading Loading @@ -792,7 +820,7 @@ RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype, } } texAlloc->deferedUploadToTexture(rsc, false, 0); texAlloc->deferedUploadToTexture(rsc); return texAlloc; } Loading Loading @@ -836,6 +864,6 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype, } } texAlloc->deferedUploadToTexture(rsc, false, 0); texAlloc->deferedUploadToTexture(rsc); return texAlloc; } libs/rs/rsAllocation.h +13 −5 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ public: void syncAll(Context *rsc, RsAllocationUsageType src); void deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset); void deferedUploadToTexture(const Context *rsc); void uploadToTexture(const Context *rsc); uint32_t getTextureID() const {return mTextureID;} Loading Loading @@ -87,6 +87,9 @@ public: virtual void uploadCheck(Context *rsc); bool getIsScript() const { return (mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT) != 0; } bool getIsTexture() const { return (mUsageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) != 0; } Loading @@ -98,7 +101,11 @@ public: void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const; void sendDirty() const; bool getHasGraphicsMipmaps() const {return mTextureGenMipmap;} bool getHasGraphicsMipmaps() const { return mMipmapControl != RS_ALLOCATION_MIPMAP_NONE; } void upload2DTexture(bool isFirstUpload, const void *ptr); protected: ObjectBaseRef<const Type> mType; Loading Loading @@ -129,8 +136,6 @@ protected: // Is this a legal structure to be used as a texture source. // Initially this will require 1D or 2D and color data bool mTextureGenMipmap; uint32_t mTextureLOD; uint32_t mTextureID; // Is this a legal structure to be used as a vertex source. Loading @@ -142,8 +147,11 @@ protected: private: void init(Context *rsc, const Type *); void upload2DTexture(bool isFirstUpload); void uploadCubeTexture(bool isFirstUpload); void allocScriptMemory(); void freeScriptMemory(); }; } Loading libs/rs/rsFont.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -463,7 +463,7 @@ bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *r // This will dirty the texture and the shader so next time // we draw it will upload the data mTextTexture->deferedUploadToTexture(mRSC, false, 0); mTextTexture->deferedUploadToTexture(mRSC); mFontShaderF->bindTexture(mRSC, 0, mTextTexture.get()); // Some debug code Loading Loading @@ -529,7 +529,7 @@ void FontState::initTextTexture() { Allocation *cacheAlloc = new Allocation(mRSC, texType, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE); mTextTexture.set(cacheAlloc); mTextTexture->deferedUploadToTexture(mRSC, false, 0); mTextTexture->deferedUploadToTexture(mRSC); // Split up our cache texture into lines of certain widths int32_t nextLine = 0; Loading Loading
libs/rs/rsAllocation.cpp +63 −35 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages) : Object mUsageFlags = usages; mPtr = malloc(mType->getSizeBytes()); allocScriptMemory(); if (mType->getElement()->getHasReferences()) { memset(mPtr, 0, mType->getSizeBytes()); } Loading Loading @@ -75,10 +75,9 @@ void Allocation::init(Context *rsc, const Type *type) { Allocation::~Allocation() { if (mUserBitmapCallback != NULL) { mUserBitmapCallback(mUserBitmapCallbackData); } else { free(mPtr); } mPtr = NULL; } freeScriptMemory(); if (mBufferID) { // Causes a SW crash.... Loading Loading @@ -108,12 +107,9 @@ bool Allocation::fixAllocation() { return false; } void Allocation::deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset) { rsAssert(lodOffset < mType->getLODCount()); void Allocation::deferedUploadToTexture(const Context *rsc) { mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; mTextureLOD = lodOffset; mUploadDefered = true; mTextureGenMipmap = !mType->getDimLOD() && genMipmap; } uint32_t Allocation::getGLTarget() const { Loading @@ -130,6 +126,20 @@ uint32_t Allocation::getGLTarget() const { return 0; } void Allocation::allocScriptMemory() { rsAssert(!mPtr); mPtr = malloc(mType->getSizeBytes()); } void Allocation::freeScriptMemory() { rsAssert(!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)); if (mPtr) { free(mPtr); mPtr = NULL; } } void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) { rsAssert(src == RS_ALLOCATION_USAGE_SCRIPT); Loading @@ -153,6 +163,10 @@ void Allocation::uploadToTexture(const Context *rsc) { return; } if (!mPtr) { return; } bool isFirstUpload = false; if (!mTextureID) { Loading @@ -171,41 +185,46 @@ void Allocation::uploadToTexture(const Context *rsc) { } GLenum target = (GLenum)getGLTarget(); glBindTexture(target, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if (target == GL_TEXTURE_2D) { upload2DTexture(isFirstUpload); upload2DTexture(isFirstUpload, mPtr); } else if (target == GL_TEXTURE_CUBE_MAP) { uploadCubeTexture(isFirstUpload); } if (mTextureGenMipmap) { if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) { #ifndef ANDROID_RS_BUILD_FOR_HOST glGenerateMipmap(target); #endif //ANDROID_RS_BUILD_FOR_HOST } if (!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)) { freeScriptMemory(); } rsc->checkError("Allocation::uploadToTexture"); } void Allocation::upload2DTexture(bool isFirstUpload) { void Allocation::upload2DTexture(bool isFirstUpload, const void *ptr) { GLenum type = mType->getElement()->getComponent().getGLType(); GLenum format = mType->getElement()->getComponent().getGLFormat(); Adapter2D adapt(getContext(), this); for (uint32_t lod = 0; (lod + mTextureLOD) < mType->getLODCount(); lod++) { adapt.setLOD(lod+mTextureLOD); GLenum target = (GLenum)getGLTarget(); glBindTexture(target, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) { const uint8_t *p = (const uint8_t *)ptr; p += mType->getLODOffset(lod); uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0)); if (isFirstUpload) { glTexImage2D(GL_TEXTURE_2D, lod, format, adapt.getDimX(), adapt.getDimY(), 0, format, type, ptr); mType->getLODDimX(lod), mType->getLODDimY(lod), 0, format, type, p); } else { glTexSubImage2D(GL_TEXTURE_2D, lod, 0, 0, adapt.getDimX(), adapt.getDimY(), format, type, ptr); mType->getLODDimX(lod), mType->getLODDimY(lod), format, type, p); } } } Loading @@ -214,6 +233,10 @@ void Allocation::uploadCubeTexture(bool isFirstUpload) { GLenum type = mType->getElement()->getComponent().getGLType(); GLenum format = mType->getElement()->getComponent().getGLFormat(); GLenum target = (GLenum)getGLTarget(); glBindTexture(target, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); GLenum faceOrder[] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, Loading @@ -227,8 +250,8 @@ void Allocation::uploadCubeTexture(bool isFirstUpload) { for (uint32_t face = 0; face < 6; face ++) { adapt.setFace(face); for (uint32_t lod = 0; (lod + mTextureLOD) < mType->getLODCount(); lod++) { adapt.setLOD(lod+mTextureLOD); for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) { adapt.setLOD(lod); uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0)); Loading Loading @@ -585,7 +608,7 @@ namespace renderscript { void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel) { Allocation *alloc = static_cast<Allocation *>(va); alloc->deferedUploadToTexture(rsc, genmip, baseMipLevel); alloc->deferedUploadToTexture(rsc); } void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va) { Loading Loading @@ -681,6 +704,7 @@ void rsi_AllocationCopyFromBitmap(Context *rsc, RsAllocation va, const void *dat return; } if (texAlloc->getIsScript()) { memcpy(texAlloc->getPtr(), data, s); if (genMips) { Adapter2D adapt(rsc, texAlloc); Loading @@ -691,6 +715,10 @@ void rsi_AllocationCopyFromBitmap(Context *rsc, RsAllocation va, const void *dat mip(adapt2, adapt); } } } else { texAlloc->upload2DTexture(false, data); } } void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t dataLen) { Loading Loading @@ -792,7 +820,7 @@ RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype, } } texAlloc->deferedUploadToTexture(rsc, false, 0); texAlloc->deferedUploadToTexture(rsc); return texAlloc; } Loading Loading @@ -836,6 +864,6 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype, } } texAlloc->deferedUploadToTexture(rsc, false, 0); texAlloc->deferedUploadToTexture(rsc); return texAlloc; }
libs/rs/rsAllocation.h +13 −5 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ public: void syncAll(Context *rsc, RsAllocationUsageType src); void deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset); void deferedUploadToTexture(const Context *rsc); void uploadToTexture(const Context *rsc); uint32_t getTextureID() const {return mTextureID;} Loading Loading @@ -87,6 +87,9 @@ public: virtual void uploadCheck(Context *rsc); bool getIsScript() const { return (mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT) != 0; } bool getIsTexture() const { return (mUsageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) != 0; } Loading @@ -98,7 +101,11 @@ public: void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const; void sendDirty() const; bool getHasGraphicsMipmaps() const {return mTextureGenMipmap;} bool getHasGraphicsMipmaps() const { return mMipmapControl != RS_ALLOCATION_MIPMAP_NONE; } void upload2DTexture(bool isFirstUpload, const void *ptr); protected: ObjectBaseRef<const Type> mType; Loading Loading @@ -129,8 +136,6 @@ protected: // Is this a legal structure to be used as a texture source. // Initially this will require 1D or 2D and color data bool mTextureGenMipmap; uint32_t mTextureLOD; uint32_t mTextureID; // Is this a legal structure to be used as a vertex source. Loading @@ -142,8 +147,11 @@ protected: private: void init(Context *rsc, const Type *); void upload2DTexture(bool isFirstUpload); void uploadCubeTexture(bool isFirstUpload); void allocScriptMemory(); void freeScriptMemory(); }; } Loading
libs/rs/rsFont.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -463,7 +463,7 @@ bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *r // This will dirty the texture and the shader so next time // we draw it will upload the data mTextTexture->deferedUploadToTexture(mRSC, false, 0); mTextTexture->deferedUploadToTexture(mRSC); mFontShaderF->bindTexture(mRSC, 0, mTextTexture.get()); // Some debug code Loading Loading @@ -529,7 +529,7 @@ void FontState::initTextTexture() { Allocation *cacheAlloc = new Allocation(mRSC, texType, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE); mTextTexture.set(cacheAlloc); mTextTexture->deferedUploadToTexture(mRSC, false, 0); mTextTexture->deferedUploadToTexture(mRSC); // Split up our cache texture into lines of certain widths int32_t nextLine = 0; Loading