summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsAllocation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/rsAllocation.cpp')
-rw-r--r--libs/rs/rsAllocation.cpp135
1 files changed, 111 insertions, 24 deletions
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index ff8d29f..eb6c503 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -38,9 +38,9 @@ Allocation::Allocation(Context *rsc, const Type *type) : ObjectBase(rsc)
mIsTexture = false;
mTextureID = 0;
-
mIsVertexBuffer = false;
mBufferID = 0;
+ mUploadDefered = false;
mType.set(type);
rsAssert(type);
@@ -88,13 +88,26 @@ bool Allocation::fixAllocation()
return false;
}
-void Allocation::uploadToTexture(Context *rsc, uint32_t lodOffset)
+void Allocation::deferedUploadToTexture(const Context *rsc, uint32_t lodOffset)
{
- //rsAssert(!mTextureId);
rsAssert(lodOffset < mType->getLODCount());
+ mIsTexture = true;
+ mTextureLOD = lodOffset;
+ mUploadDefered = true;
+}
+
+void Allocation::uploadToTexture(const Context *rsc)
+{
+ //rsAssert(!mTextureId);
+
+ mIsTexture = true;
+ if (!rsc->checkDriver()) {
+ mUploadDefered = true;
+ return;
+ }
- GLenum type = mType->getElement()->getGLType();
- GLenum format = mType->getElement()->getGLFormat();
+ GLenum type = mType->getElement()->getComponent().getGLType();
+ GLenum format = mType->getElement()->getComponent().getGLFormat();
if (!type || !format) {
return;
@@ -109,15 +122,16 @@ void Allocation::uploadToTexture(Context *rsc, uint32_t lodOffset)
// Force a crash to 1: restart the app, 2: make sure we get a bugreport.
LOGE("Upload to texture failed to gen mTextureID");
rsc->dumpDebug();
- ((char *)0)[0] = 0;
+ mUploadDefered = true;
+ return;
}
}
glBindTexture(GL_TEXTURE_2D, mTextureID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Adapter2D adapt(getContext(), this);
- for(uint32_t lod = 0; (lod + lodOffset) < mType->getLODCount(); lod++) {
- adapt.setLOD(lod+lodOffset);
+ for(uint32_t lod = 0; (lod + mTextureLOD) < mType->getLODCount(); lod++) {
+ adapt.setLOD(lod+mTextureLOD);
uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0));
glTexImage2D(GL_TEXTURE_2D, lod, format,
@@ -126,19 +140,50 @@ void Allocation::uploadToTexture(Context *rsc, uint32_t lodOffset)
}
}
-void Allocation::uploadToBufferObject()
+void Allocation::deferedUploadToBufferObject(const Context *rsc)
+{
+ mIsVertexBuffer = true;
+ mUploadDefered = true;
+}
+
+void Allocation::uploadToBufferObject(const Context *rsc)
{
rsAssert(!mType->getDimY());
rsAssert(!mType->getDimZ());
+ mIsVertexBuffer = true;
+ if (!rsc->checkDriver()) {
+ mUploadDefered = true;
+ return;
+ }
+
if (!mBufferID) {
glGenBuffers(1, &mBufferID);
}
+ if (!mBufferID) {
+ LOGE("Upload to buffer object failed");
+ mUploadDefered = true;
+ return;
+ }
+
glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
glBufferData(GL_ARRAY_BUFFER, mType->getSizeBytes(), getPtr(), GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
+void Allocation::uploadCheck(const Context *rsc)
+{
+ if (mUploadDefered) {
+ mUploadDefered = false;
+ if (mIsVertexBuffer) {
+ uploadToBufferObject(rsc);
+ }
+ if (mIsTexture) {
+ uploadToTexture(rsc);
+ }
+ }
+}
+
void Allocation::data(const void *data, uint32_t sizeBytes)
{
@@ -148,6 +193,8 @@ void Allocation::data(const void *data, uint32_t sizeBytes)
return;
}
memcpy(mPtr, data, size);
+ sendDirty();
+ mUploadDefered = true;
}
void Allocation::read(void *data)
@@ -168,6 +215,8 @@ void Allocation::subData(uint32_t xoff, uint32_t count, const void *data, uint32
return;
}
memcpy(ptr, data, size);
+ sendDirty();
+ mUploadDefered = true;
}
void Allocation::subData(uint32_t xoff, uint32_t yoff,
@@ -192,6 +241,8 @@ void Allocation::subData(uint32_t xoff, uint32_t yoff,
src += lineSize;
dst += destW * eSize;
}
+ sendDirty();
+ mUploadDefered = true;
}
void Allocation::subData(uint32_t xoff, uint32_t yoff, uint32_t zoff,
@@ -214,10 +265,30 @@ void Allocation::dumpLOGV(const char *prefix) const
LOGV("%s allocation mIsTexture=%i mTextureID=%i, mIsVertexBuffer=%i, mBufferID=%i",
prefix, mIsTexture, mTextureID, mIsVertexBuffer, mBufferID);
+}
+void Allocation::addProgramToDirty(const Program *p)
+{
+ mToDirtyList.add(p);
+}
+void Allocation::removeProgramToDirty(const Program *p)
+{
+ for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
+ if (mToDirtyList[ct] == p) {
+ mToDirtyList.removeAt(ct);
+ return;
+ }
+ }
+ rsAssert(0);
}
+void Allocation::sendDirty() const
+{
+ for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
+ mToDirtyList[ct]->forceDirty();
+ }
+}
/////////////////
//
@@ -247,13 +318,13 @@ RsAllocation rsi_AllocationCreateSized(Context *rsc, RsElement e, size_t count)
void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, uint32_t baseMipLevel)
{
Allocation *alloc = static_cast<Allocation *>(va);
- alloc->uploadToTexture(rsc, baseMipLevel);
+ alloc->deferedUploadToTexture(rsc, baseMipLevel);
}
void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va)
{
Allocation *alloc = static_cast<Allocation *>(va);
- alloc->uploadToBufferObject();
+ alloc->deferedUploadToBufferObject(rsc);
}
static void mip565(const Adapter2D &out, const Adapter2D &in)
@@ -294,6 +365,25 @@ static void mip8888(const Adapter2D &out, const Adapter2D &in)
}
}
+static void mip8(const Adapter2D &out, const Adapter2D &in)
+{
+ uint32_t w = out.getDimX();
+ uint32_t h = out.getDimY();
+
+ for (uint32_t y=0; y < h; y++) {
+ uint8_t *oPtr = static_cast<uint8_t *>(out.getElement(0, y));
+ const uint8_t *i1 = static_cast<uint8_t *>(in.getElement(0, y*2));
+ const uint8_t *i2 = static_cast<uint8_t *>(in.getElement(0, y*2+1));
+
+ for (uint32_t x=0; x < w; x++) {
+ *oPtr = (uint8_t)(((uint32_t)i1[0] + i1[1] + i2[0] + i2[1]) * 0.25f);
+ oPtr ++;
+ i1 += 2;
+ i2 += 2;
+ }
+ }
+}
+
static void mip(const Adapter2D &out, const Adapter2D &in)
{
switch(out.getBaseType()->getElement()->getSizeBits()) {
@@ -303,6 +393,9 @@ static void mip(const Adapter2D &out, const Adapter2D &in)
case 16:
mip565(out, in);
break;
+ case 8:
+ mip8(out, in);
+ break;
}
@@ -350,10 +443,10 @@ static void elementConverter_8888_to_565(void *dst, const void *src, uint32_t co
static ElementConverter_t pickConverter(const Element *dst, const Element *src)
{
- GLenum srcGLType = src->getGLType();
- GLenum srcGLFmt = src->getGLFormat();
- GLenum dstGLType = dst->getGLType();
- GLenum dstGLFmt = dst->getGLFormat();
+ GLenum srcGLType = src->getComponent().getGLType();
+ GLenum srcGLFmt = src->getComponent().getGLFormat();
+ GLenum dstGLType = dst->getComponent().getGLType();
+ GLenum dstGLFmt = dst->getComponent().getGLFormat();
if (srcGLFmt == dstGLFmt && srcGLType == dstGLType) {
switch(dst->getSizeBytes()) {
@@ -391,8 +484,9 @@ RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h
{
const Element *src = static_cast<const Element *>(_src);
const Element *dst = static_cast<const Element *>(_dst);
- rsAssert(!(w & (w-1)));
- rsAssert(!(h & (h-1)));
+
+ // Check for pow2 on pre es 2.0 versions.
+ rsAssert(rsc->checkVersion2_0() || (!(w & (w-1)) && !(h & (h-1))));
//LOGE("rsi_AllocationCreateFromBitmap %i %i %i %i %i", w, h, dstFmt, srcFmt, genMips);
rsi_TypeBegin(rsc, _dst);
@@ -452,31 +546,24 @@ RsAllocation rsi_AllocationCreateFromBitmapBoxed(Context *rsc, uint32_t w, uint3
RsAllocation ret = rsi_AllocationCreateFromBitmap(rsc, w2, h2, _dst, _src, genMips, tmp);
free(tmp);
return ret;
-
-
-
-
}
void rsi_AllocationData(Context *rsc, RsAllocation va, const void *data, uint32_t sizeBytes)
{
Allocation *a = static_cast<Allocation *>(va);
a->data(data, sizeBytes);
- rsc->allocationCheck(a);
}
void rsi_Allocation1DSubData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes)
{
Allocation *a = static_cast<Allocation *>(va);
a->subData(xoff, count, data, sizeBytes);
- rsc->allocationCheck(a);
}
void rsi_Allocation2DSubData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes)
{
Allocation *a = static_cast<Allocation *>(va);
a->subData(xoff, yoff, w, h, data, sizeBytes);
- rsc->allocationCheck(a);
}
void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data)