From 0b9bbb6dc5d7dabecf23e8c6bb4a267ba8c34fe8 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 11 Feb 2010 18:16:21 -0800 Subject: DO NOT MERGE. Merge Froyo renderscript to Eclair to support live wallpapers on droid. This gives the necessary CPU reduction to allow the wallpapers to work on the slower CPU. Committer: Jason Sams On branch droid Changes to be committed: (use "git reset HEAD ..." to unstage) modified: libs/rs/rsAllocation.cpp modified: libs/rs/rsAllocation.h modified: libs/rs/rsContext.cpp modified: libs/rs/rsContext.h modified: libs/rs/rsProgram.cpp modified: libs/rs/rsProgram.h Delete the old rollo sample which is obsolete. Fix film init Begin gl2 support. Renderscript still uses GL1.1 by default. However, 2.0 can be enabled and will render most tests correctly. Fix film Beging GL2 user shaders. Switch master to using GL2 by default. Implement RS tracked defered texture and buffer object uploads. Committer: Jason Sams On branch droid Changes to be committed: (use "git reset HEAD ..." to unstage) modified: libs/rs/rsAllocation.cpp modified: libs/rs/rsAllocation.h modified: libs/rs/rsContext.h modified: libs/rs/rsProgramFragment.cpp modified: libs/rs/rsSimpleMesh.cpp Remove check for surface valid that is no longer valid. Continue development of es2.0 user shader support for renderscript. This change cleans up ProgramVertex creation and adds support for passing input, output, and constant type info. Continue es2 shader dev Conflicts: graphics/java/android/renderscript/Program.java graphics/java/android/renderscript/ProgramVertex.java Place shader logging behind prop to declutter logs. Fix emulated glColor in es2 mode. Fix live wallpaper many. Z coordinate was being ignored for draw quad call. Add argument checking to sampler builder to disallow illegal modes. Move texture bindings to base program object. Change ProgramFragment creation to require a texture format in 1.0 mode. Element restructuring. Add support for new basic Element types including the RS objects and vectors(2-4). In theory this paves the way for maintaining type info for RS objects, passing elements for GLSL uiforms/attribs/varyings, and supporting nested structures. This will break some apps, checkings for other projects will follow to unbreak them. Disable excessive RS logging. Add RS support for generic attribs as input to vertex programs. More complete support for named attribs. Adds user typed attribs as available to programVertex. Non user attribs are not treated like user for GL2 for simplicity. Support npot on es 2.0 HW. Change user attribs to look for empty slot rather than using them in order. Prevents conflict with numbered legacy slots. Fix npot but where mipmap level sizes were rounding in the wrong direction. Should always be floor. Implement type generation for user uniforms in vertex shader. Remove excessive logging, fix error in GLSL uniform generation. Fix RS mipmap generation for 8 bit alpha textures. Cleanup seperation of Legacy and user attribs. All user programs now use the new names. Legacy vertex attribs are given default names. Fix some minor bugs with GL state setup that were exposed by Droids driver. Implement drawSpriteCropped on es2.0 --- libs/rs/rsElement.cpp | 265 +++++++++++++++++++++----------------------------- 1 file changed, 112 insertions(+), 153 deletions(-) (limited to 'libs/rs/rsElement.cpp') diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp index 67e4f14..207ad15 100644 --- a/libs/rs/rsElement.cpp +++ b/libs/rs/rsElement.cpp @@ -24,19 +24,13 @@ using namespace android::renderscript; Element::Element(Context *rsc) : ObjectBase(rsc) { + mBits = 0; mAllocFile = __FILE__; mAllocLine = __LINE__; - mComponents = NULL; - mComponentCount = 0; + mFields = NULL; + mFieldCount = 0; } -Element::Element(Context *rsc, uint32_t count) : ObjectBase(rsc) -{ - mAllocFile = __FILE__; - mAllocLine = __LINE__; - mComponents = new ObjectBaseRef [count]; - mComponentCount = count; -} Element::~Element() { @@ -45,153 +39,129 @@ Element::~Element() void Element::clear() { - delete [] mComponents; - mComponents = NULL; - mComponentCount = 0; + delete [] mFields; + mFields = NULL; + mFieldCount = 0; } -void Element::setComponent(uint32_t idx, Component *c) -{ - rsAssert(!mComponents[idx].get()); - rsAssert(idx < mComponentCount); - mComponents[idx].set(c); - -// Fixme: This should probably not be here - c->incUserRef(); -} - - size_t Element::getSizeBits() const { + if (!mFieldCount) { + return mBits; + } + size_t total = 0; - for (size_t ct=0; ct < mComponentCount; ct++) { - total += mComponents[ct]->getBits(); + for (size_t ct=0; ct < mFieldCount; ct++) { + total += mFields[ct].e->mBits; } return total; } -size_t Element::getComponentOffsetBits(uint32_t componentNumber) const +size_t Element::getFieldOffsetBits(uint32_t componentNumber) const { size_t offset = 0; for (uint32_t ct = 0; ct < componentNumber; ct++) { - offset += mComponents[ct]->getBits(); + offset += mFields[ct].e->mBits; } return offset; } -uint32_t Element::getGLType() const +void Element::dumpLOGV(const char *prefix) const { - int bits[4]; + ObjectBase::dumpLOGV(prefix); + LOGV("%s Element: components %i, size %i", prefix, mFieldCount, mBits); + for (uint32_t ct = 0; ct < mFieldCount; ct++) { + char buf[1024]; + sprintf(buf, "%s component %i: ", prefix, ct); + //mComponents[ct]->dumpLOGV(buf); + } +} + + +Element * Element::create(Context *rsc, RsDataType dt, RsDataKind dk, + bool isNorm, uint32_t vecSize) +{ + Element *e = new Element(rsc); + e->mComponent.set(dt, dk, isNorm, vecSize); + e->mBits = e->mComponent.getBits(); + return e; +} + +Element * Element::create(Context *rsc, size_t count, const Element **ein, + const char **nin, const size_t * lengths) +{ + Element *e = new Element(rsc); + e->mFields = new ElementField_t [count]; + e->mFieldCount = count; - if (mComponentCount > 4) { - return 0; + for (size_t ct=0; ct < count; ct++) { + e->mFields[ct].e.set(ein[ct]); + e->mFields[ct].name.setTo(nin[ct], lengths[ct]); } - for (uint32_t ct=0; ct < mComponentCount; ct++) { - bits[ct] = mComponents[ct]->getBits(); - if (mComponents[ct]->getType() != Component::UNSIGNED) { - return 0; - } - if (!mComponents[ct]->getIsNormalized()) { - return 0; - } + return e; +} + +String8 Element::getCStructBody(uint32_t indent) const +{ + String8 si; + for (uint32_t ct=0; ct < indent; ct++) { + si.append(" "); } - switch(mComponentCount) { - case 1: - if (bits[0] == 8) { - return GL_UNSIGNED_BYTE; - } - return 0; - case 2: - if ((bits[0] == 8) && - (bits[1] == 8)) { - return GL_UNSIGNED_BYTE; - } - return 0; - case 3: - if ((bits[0] == 8) && - (bits[1] == 8) && - (bits[2] == 8)) { - return GL_UNSIGNED_BYTE; - } - if ((bits[0] == 5) && - (bits[1] == 6) && - (bits[2] == 5)) { - return GL_UNSIGNED_SHORT_5_6_5; - } - return 0; - case 4: - if ((bits[0] == 8) && - (bits[1] == 8) && - (bits[2] == 8) && - (bits[3] == 8)) { - return GL_UNSIGNED_BYTE; - } - if ((bits[0] == 4) && - (bits[1] == 4) && - (bits[2] == 4) && - (bits[3] == 4)) { - return GL_UNSIGNED_SHORT_4_4_4_4; - } - if ((bits[0] == 5) && - (bits[1] == 5) && - (bits[2] == 5) && - (bits[3] == 1)) { - return GL_UNSIGNED_SHORT_5_5_5_1; - } + String8 s(si); + s.append("{\n"); + for (uint32_t ct = 0; ct < mFieldCount; ct++) { + s.append(si); + s.append(mFields[ct].e->getCType(indent+4)); + s.append(" "); + s.append(mFields[ct].name); + s.append(";\n"); } - return 0; + s.append(si); + s.append("}"); + return s; } -uint32_t Element::getGLFormat() const +String8 Element::getCType(uint32_t indent) const { - switch(mComponentCount) { - case 1: - if (mComponents[0]->getKind() == Component::ALPHA) { - return GL_ALPHA; - } - if (mComponents[0]->getKind() == Component::LUMINANCE) { - return GL_LUMINANCE; - } - break; - case 2: - if ((mComponents[0]->getKind() == Component::LUMINANCE) && - (mComponents[1]->getKind() == Component::ALPHA)) { - return GL_LUMINANCE_ALPHA; - } - break; - case 3: - if ((mComponents[0]->getKind() == Component::RED) && - (mComponents[1]->getKind() == Component::GREEN) && - (mComponents[2]->getKind() == Component::BLUE)) { - return GL_RGB; - } - break; - case 4: - if ((mComponents[0]->getKind() == Component::RED) && - (mComponents[1]->getKind() == Component::GREEN) && - (mComponents[2]->getKind() == Component::BLUE) && - (mComponents[3]->getKind() == Component::ALPHA)) { - return GL_RGBA; - } - break; + String8 s; + for (uint32_t ct=0; ct < indent; ct++) { + s.append(" "); + } + + if (!mFieldCount) { + // Basic component. + s.append(mComponent.getCType()); + } else { + s.append("struct "); + s.append(getCStructBody(indent)); } - return 0; -} + return s; +} -void Element::dumpLOGV(const char *prefix) const +String8 Element::getGLSLType(uint32_t indent) const { - ObjectBase::dumpLOGV(prefix); - LOGV("%s Element: components %i, size %i", prefix, mComponentCount, getSizeBytes()); - for (uint32_t ct = 0; ct < mComponentCount; ct++) { - char buf[1024]; - sprintf(buf, "%s component %i: ", prefix, ct); - mComponents[ct]->dumpLOGV(buf); + String8 s; + for (uint32_t ct=0; ct < indent; ct++) { + s.append(" "); } + + if (!mFieldCount) { + // Basic component. + s.append(mComponent.getGLSLType()); + } else { + rsAssert(0); + //s.append("struct "); + //s.append(getCStructBody(indent)); + } + + return s; } + + ElementState::ElementState() { } @@ -200,46 +170,35 @@ ElementState::~ElementState() { } + ///////////////////////////////////////// // namespace android { namespace renderscript { -void rsi_ElementBegin(Context *rsc) -{ - rsc->mStateElement.mComponentBuildList.clear(); -} - -void rsi_ElementAdd(Context *rsc, RsDataKind dk, RsDataType dt, bool isNormalized, size_t bits, const char *name) +RsElement rsi_ElementCreate(Context *rsc, + RsDataType dt, + RsDataKind dk, + bool norm, + uint32_t vecSize) { - ElementState * sec = &rsc->mStateElement; - - rsAssert(bits > 0); - - Component *c = new Component(rsc, - static_cast(dk), - static_cast(dt), - isNormalized, - bits, - name); - sec->mComponentBuildList.add(c); + //LOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize); + Element *e = Element::create(rsc, dt, dk, norm, vecSize); + e->incUserRef(); + return e; } -RsElement rsi_ElementCreate(Context *rsc) +RsElement rsi_ElementCreate2(Context *rsc, + size_t count, + const RsElement * ein, + const char ** names, + const size_t * nameLengths) { - ElementState * sec = &rsc->mStateElement; - Element *se = new Element(rsc, sec->mComponentBuildList.size()); - - rsAssert(se->getComponentCount() > 0); - - for (size_t ct = 0; ct < se->getComponentCount(); ct++) { - se->setComponent(ct, sec->mComponentBuildList[ct]); - } - - rsc->mStateElement.mComponentBuildList.clear(); - se->incUserRef(); - return se; + //LOGE("rsi_ElementCreate2 %i", count); + Element *e = Element::create(rsc, count, (const Element **)ein, names, nameLengths); + e->incUserRef(); + return e; } -- cgit v1.1