diff options
author | Jason Sams <rjsams@android.com> | 2011-04-06 11:30:24 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-04-06 11:30:24 -0700 |
commit | d57a93b27d43ac46960be6276a208da0b686bcf4 (patch) | |
tree | e01d6fefda1d390ba5a84702f17a149f9889db36 /libs | |
parent | 3fc982f41fda1f254bfbc35490d81cd82a0ed90a (diff) | |
parent | 48f505657adba4d9156856e7d5593f23af5d5d5a (diff) | |
download | frameworks_base-d57a93b27d43ac46960be6276a208da0b686bcf4.zip frameworks_base-d57a93b27d43ac46960be6276a208da0b686bcf4.tar.gz frameworks_base-d57a93b27d43ac46960be6276a208da0b686bcf4.tar.bz2 |
Merge "Seperate GL from RS program store."
Diffstat (limited to 'libs')
-rw-r--r-- | libs/rs/Android.mk | 3 | ||||
-rw-r--r-- | libs/rs/driver/rsdBcc.h | 2 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.cpp | 9 | ||||
-rw-r--r-- | libs/rs/driver/rsdProgramStore.cpp | 204 | ||||
-rw-r--r-- | libs/rs/driver/rsdProgramStore.h | 31 | ||||
-rw-r--r-- | libs/rs/rsFont.cpp | 1 | ||||
-rw-r--r-- | libs/rs/rsProgramStore.cpp | 179 | ||||
-rw-r--r-- | libs/rs/rsProgramStore.h | 37 | ||||
-rw-r--r-- | libs/rs/rsScriptC.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rs_hal.h | 23 |
10 files changed, 319 insertions, 172 deletions
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index 9100693..a07955a 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -116,7 +116,8 @@ LOCAL_SRC_FILES:= \ rsType.cpp \ rsVertexArray.cpp \ driver/rsdBcc.cpp \ - driver/rsdCore.cpp + driver/rsdCore.cpp \ + driver/rsdProgramStore.cpp LOCAL_SHARED_LIBRARIES += libz libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libbcc diff --git a/libs/rs/driver/rsdBcc.h b/libs/rs/driver/rsdBcc.h index 6723a36..ae7a7af 100644 --- a/libs/rs/driver/rsdBcc.h +++ b/libs/rs/driver/rsdBcc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index 6546110..448be6a 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -16,6 +16,7 @@ #include "rsdCore.h" #include "rsdBcc.h" +#include "rsdProgramStore.h" #include <malloc.h> #include "rsContext.h" @@ -48,7 +49,15 @@ static RsdHalFunctions FunctionTable = { rsdScriptSetGlobalBind, rsdScriptSetGlobalObj, rsdScriptDestroy + }, + + + { + rsdProgramStoreInit, + rsdProgramStoreSetActive, + rsdProgramStoreDestroy } + }; diff --git a/libs/rs/driver/rsdProgramStore.cpp b/libs/rs/driver/rsdProgramStore.cpp new file mode 100644 index 0000000..e591453 --- /dev/null +++ b/libs/rs/driver/rsdProgramStore.cpp @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "rsdCore.h" +#include "rsdProgramStore.h" + +#include "rsContext.h" +#include "rsProgramStore.h" + +#include <GLES/gl.h> +#include <GLES/glext.h> + + +using namespace android; +using namespace android::renderscript; + +struct DrvProgramStore { + GLenum blendSrc; + GLenum blendDst; + bool blendEnable; + + GLenum depthFunc; + bool depthTestEnable; +}; + +bool rsdProgramStoreInit(const Context *rsc, const ProgramStore *ps) { + DrvProgramStore *drv = (DrvProgramStore *)calloc(1, sizeof(DrvProgramStore)); + if (drv == NULL) { + return false; + } + + ps->mHal.drv = drv; + drv->depthTestEnable = true; + + switch (ps->mHal.state.depthFunc) { + case RS_DEPTH_FUNC_ALWAYS: + drv->depthTestEnable = false; + drv->depthFunc = GL_ALWAYS; + break; + case RS_DEPTH_FUNC_LESS: + drv->depthFunc = GL_LESS; + break; + case RS_DEPTH_FUNC_LEQUAL: + drv->depthFunc = GL_LEQUAL; + break; + case RS_DEPTH_FUNC_GREATER: + drv->depthFunc = GL_GREATER; + break; + case RS_DEPTH_FUNC_GEQUAL: + drv->depthFunc = GL_GEQUAL; + break; + case RS_DEPTH_FUNC_EQUAL: + drv->depthFunc = GL_EQUAL; + break; + case RS_DEPTH_FUNC_NOTEQUAL: + drv->depthFunc = GL_NOTEQUAL; + break; + default: + LOGE("Unknown depth function."); + goto error; + } + + + + drv->blendEnable = true; + if ((ps->mHal.state.blendSrc == RS_BLEND_SRC_ONE) && + (ps->mHal.state.blendDst == RS_BLEND_DST_ZERO)) { + drv->blendEnable = false; + } + + switch (ps->mHal.state.blendSrc) { + case RS_BLEND_SRC_ZERO: + drv->blendSrc = GL_ZERO; + break; + case RS_BLEND_SRC_ONE: + drv->blendSrc = GL_ONE; + break; + case RS_BLEND_SRC_DST_COLOR: + drv->blendSrc = GL_DST_COLOR; + break; + case RS_BLEND_SRC_ONE_MINUS_DST_COLOR: + drv->blendSrc = GL_ONE_MINUS_DST_COLOR; + break; + case RS_BLEND_SRC_SRC_ALPHA: + drv->blendSrc = GL_SRC_ALPHA; + break; + case RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA: + drv->blendSrc = GL_ONE_MINUS_SRC_ALPHA; + break; + case RS_BLEND_SRC_DST_ALPHA: + drv->blendSrc = GL_DST_ALPHA; + break; + case RS_BLEND_SRC_ONE_MINUS_DST_ALPHA: + drv->blendSrc = GL_ONE_MINUS_DST_ALPHA; + break; + case RS_BLEND_SRC_SRC_ALPHA_SATURATE: + drv->blendSrc = GL_SRC_ALPHA_SATURATE; + break; + default: + LOGE("Unknown blend src mode."); + goto error; + } + + switch (ps->mHal.state.blendDst) { + case RS_BLEND_DST_ZERO: + drv->blendDst = GL_ZERO; + break; + case RS_BLEND_DST_ONE: + drv->blendDst = GL_ONE; + break; + case RS_BLEND_DST_SRC_COLOR: + drv->blendDst = GL_SRC_COLOR; + break; + case RS_BLEND_DST_ONE_MINUS_SRC_COLOR: + drv->blendDst = GL_ONE_MINUS_SRC_COLOR; + break; + case RS_BLEND_DST_SRC_ALPHA: + drv->blendDst = GL_SRC_ALPHA; + break; + case RS_BLEND_DST_ONE_MINUS_SRC_ALPHA: + drv->blendDst = GL_ONE_MINUS_SRC_ALPHA; + break; + case RS_BLEND_DST_DST_ALPHA: + drv->blendDst = GL_DST_ALPHA; + break; + case RS_BLEND_DST_ONE_MINUS_DST_ALPHA: + drv->blendDst = GL_ONE_MINUS_DST_ALPHA; + break; + default: + LOGE("Unknown blend dst mode."); + goto error; + } + + return true; + +error: + free(drv); + ps->mHal.drv = NULL; + return false; +} + +void rsdProgramStoreSetActive(const Context *rsc, const ProgramStore *ps) { + DrvProgramStore *drv = (DrvProgramStore *)ps->mHal.drv; + + glColorMask(ps->mHal.state.colorRWriteEnable, + ps->mHal.state.colorGWriteEnable, + ps->mHal.state.colorBWriteEnable, + ps->mHal.state.colorAWriteEnable); + + if (drv->blendEnable) { + glEnable(GL_BLEND); + glBlendFunc(drv->blendSrc, drv->blendDst); + } else { + glDisable(GL_BLEND); + } + + if (rsc->mUserSurfaceConfig.depthMin > 0) { + glDepthMask(ps->mHal.state.depthWriteEnable); + if (drv->depthTestEnable || ps->mHal.state.depthWriteEnable) { + glEnable(GL_DEPTH_TEST); + glDepthFunc(drv->depthFunc); + } else { + glDisable(GL_DEPTH_TEST); + } + } else { + glDepthMask(false); + glDisable(GL_DEPTH_TEST); + } + + /* + if (rsc->mUserSurfaceConfig.stencilMin > 0) { + } else { + glStencilMask(0); + glDisable(GL_STENCIL_TEST); + } + */ + + if (ps->mHal.state.ditherEnable) { + glEnable(GL_DITHER); + } else { + glDisable(GL_DITHER); + } +} + +void rsdProgramStoreDestroy(const Context *rsc, const ProgramStore *ps) { + free(ps->mHal.drv); + ps->mHal.drv = NULL; +} + + diff --git a/libs/rs/driver/rsdProgramStore.h b/libs/rs/driver/rsdProgramStore.h new file mode 100644 index 0000000..217a0ce --- /dev/null +++ b/libs/rs/driver/rsdProgramStore.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RSD_PROGRAM_STORE_H +#define RSD_PROGRAM_STORE_H + +#include <rs_hal.h> + + +bool rsdProgramStoreInit(const android::renderscript::Context *rsc, + const android::renderscript::ProgramStore *ps); +void rsdProgramStoreSetActive(const android::renderscript::Context *rsc, + const android::renderscript::ProgramStore *ps); +void rsdProgramStoreDestroy(const android::renderscript::Context *rsc, + const android::renderscript::ProgramStore *ps); + + +#endif diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp index 595c89a..0871d2f 100644 --- a/libs/rs/rsFont.cpp +++ b/libs/rs/rsFont.cpp @@ -513,6 +513,7 @@ void FontState::initRenderState() { mFontProgramStore->setBlendFunc(RS_BLEND_SRC_SRC_ALPHA, RS_BLEND_DST_ONE_MINUS_SRC_ALPHA); mFontProgramStore->setDitherEnable(false); mFontProgramStore->setDepthMask(false); + mFontProgramStore->init(); } void FontState::initTextTexture() { diff --git a/libs/rs/rsProgramStore.cpp b/libs/rs/rsProgramStore.cpp index 09b759d..087414a 100644 --- a/libs/rs/rsProgramStore.cpp +++ b/libs/rs/rsProgramStore.cpp @@ -15,11 +15,6 @@ */ #include "rsContext.h" -#ifndef ANDROID_RS_SERIALIZE -#include <GLES/gl.h> -#include <GLES/glext.h> -#endif //ANDROID_RS_SERIALIZE - #include "rsProgramStore.h" using namespace android; @@ -27,21 +22,23 @@ using namespace android::renderscript; ProgramStore::ProgramStore(Context *rsc) : Program(rsc) { - mDitherEnable = true; - mBlendEnable = false; - mColorRWriteEnable = true; - mColorGWriteEnable = true; - mColorBWriteEnable = true; - mColorAWriteEnable = true; - mBlendSrc = GL_ONE; - mBlendDst = GL_ZERO; - - mDepthTestEnable = false; - mDepthWriteEnable = true; - mDepthFunc = GL_LESS; + memset(&mHal, 0, sizeof(mHal)); + + mHal.state.ditherEnable = true; + + mHal.state.colorRWriteEnable = true; + mHal.state.colorGWriteEnable = true; + mHal.state.colorBWriteEnable = true; + mHal.state.colorAWriteEnable = true; + mHal.state.blendSrc = RS_BLEND_SRC_ONE; + mHal.state.blendDst = RS_BLEND_DST_ZERO; + + mHal.state.depthWriteEnable = true; + mHal.state.depthFunc = RS_DEPTH_FUNC_LESS; } ProgramStore::~ProgramStore() { + mRSC->mHal.funcs.store.destroy(mRSC, this); } void ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state) { @@ -50,47 +47,11 @@ void ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state) { } state->mLast.set(this); - glColorMask(mColorRWriteEnable, - mColorGWriteEnable, - mColorBWriteEnable, - mColorAWriteEnable); - if (mBlendEnable) { - glEnable(GL_BLEND); - glBlendFunc(mBlendSrc, mBlendDst); - } else { - glDisable(GL_BLEND); - } - - //LOGE("pfs %i, %i, %x", mDepthWriteEnable, mDepthTestEnable, mDepthFunc); - - if (rsc->mUserSurfaceConfig.depthMin > 0) { - glDepthMask(mDepthWriteEnable); - if (mDepthTestEnable || mDepthWriteEnable) { - glEnable(GL_DEPTH_TEST); - glDepthFunc(mDepthFunc); - } else { - glDisable(GL_DEPTH_TEST); - } - } else { - glDepthMask(false); - glDisable(GL_DEPTH_TEST); - } - - if (rsc->mUserSurfaceConfig.stencilMin > 0) { - } else { - glStencilMask(0); - glDisable(GL_STENCIL_TEST); - } - - if (mDitherEnable) { - glEnable(GL_DITHER); - } else { - glDisable(GL_DITHER); - } + rsc->mHal.funcs.store.setActive(rsc, this); } void ProgramStore::setDitherEnable(bool enable) { - mDitherEnable = enable; + mHal.state.ditherEnable = enable; } void ProgramStore::serialize(OStream *stream) const { @@ -101,108 +62,27 @@ ProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream) { } void ProgramStore::setDepthFunc(RsDepthFunc func) { - mDepthTestEnable = true; - - switch (func) { - case RS_DEPTH_FUNC_ALWAYS: - mDepthTestEnable = false; - mDepthFunc = GL_ALWAYS; - break; - case RS_DEPTH_FUNC_LESS: - mDepthFunc = GL_LESS; - break; - case RS_DEPTH_FUNC_LEQUAL: - mDepthFunc = GL_LEQUAL; - break; - case RS_DEPTH_FUNC_GREATER: - mDepthFunc = GL_GREATER; - break; - case RS_DEPTH_FUNC_GEQUAL: - mDepthFunc = GL_GEQUAL; - break; - case RS_DEPTH_FUNC_EQUAL: - mDepthFunc = GL_EQUAL; - break; - case RS_DEPTH_FUNC_NOTEQUAL: - mDepthFunc = GL_NOTEQUAL; - break; - } + mHal.state.depthFunc = func; } void ProgramStore::setDepthMask(bool mask) { - mDepthWriteEnable = mask; + mHal.state.depthWriteEnable = mask; } void ProgramStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst) { - mBlendEnable = true; - if ((src == RS_BLEND_SRC_ONE) && - (dst == RS_BLEND_DST_ZERO)) { - mBlendEnable = false; - } - - switch (src) { - case RS_BLEND_SRC_ZERO: - mBlendSrc = GL_ZERO; - break; - case RS_BLEND_SRC_ONE: - mBlendSrc = GL_ONE; - break; - case RS_BLEND_SRC_DST_COLOR: - mBlendSrc = GL_DST_COLOR; - break; - case RS_BLEND_SRC_ONE_MINUS_DST_COLOR: - mBlendSrc = GL_ONE_MINUS_DST_COLOR; - break; - case RS_BLEND_SRC_SRC_ALPHA: - mBlendSrc = GL_SRC_ALPHA; - break; - case RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA: - mBlendSrc = GL_ONE_MINUS_SRC_ALPHA; - break; - case RS_BLEND_SRC_DST_ALPHA: - mBlendSrc = GL_DST_ALPHA; - break; - case RS_BLEND_SRC_ONE_MINUS_DST_ALPHA: - mBlendSrc = GL_ONE_MINUS_DST_ALPHA; - break; - case RS_BLEND_SRC_SRC_ALPHA_SATURATE: - mBlendSrc = GL_SRC_ALPHA_SATURATE; - break; - } - - switch (dst) { - case RS_BLEND_DST_ZERO: - mBlendDst = GL_ZERO; - break; - case RS_BLEND_DST_ONE: - mBlendDst = GL_ONE; - break; - case RS_BLEND_DST_SRC_COLOR: - mBlendDst = GL_SRC_COLOR; - break; - case RS_BLEND_DST_ONE_MINUS_SRC_COLOR: - mBlendDst = GL_ONE_MINUS_SRC_COLOR; - break; - case RS_BLEND_DST_SRC_ALPHA: - mBlendDst = GL_SRC_ALPHA; - break; - case RS_BLEND_DST_ONE_MINUS_SRC_ALPHA: - mBlendDst = GL_ONE_MINUS_SRC_ALPHA; - break; - case RS_BLEND_DST_DST_ALPHA: - mBlendDst = GL_DST_ALPHA; - break; - case RS_BLEND_DST_ONE_MINUS_DST_ALPHA: - mBlendDst = GL_ONE_MINUS_DST_ALPHA; - break; - } + mHal.state.blendSrc = src; + mHal.state.blendDst = dst; } void ProgramStore::setColorMask(bool r, bool g, bool b, bool a) { - mColorRWriteEnable = r; - mColorGWriteEnable = g; - mColorBWriteEnable = b; - mColorAWriteEnable = a; + mHal.state.colorRWriteEnable = r; + mHal.state.colorGWriteEnable = g; + mHal.state.colorBWriteEnable = b; + mHal.state.colorAWriteEnable = a; +} + +void ProgramStore::init() { + mRSC->mHal.funcs.store.init(mRSC, this); } ProgramStoreState::ProgramStoreState() { @@ -216,6 +96,7 @@ ProgramStoreState::~ProgramStoreState() { void ProgramStoreState::init(Context *rsc) { ProgramStore *pfs = new ProgramStore(rsc); + pfs->init(); mDefault.set(pfs); } @@ -224,6 +105,7 @@ void ProgramStoreState::deinit(Context *rsc) { mLast.clear(); } + namespace android { namespace renderscript { @@ -250,6 +132,7 @@ void rsi_ProgramStoreBlendFunc(Context *rsc, RsBlendSrcFunc src, RsBlendDstFunc RsProgramStore rsi_ProgramStoreCreate(Context *rsc) { ProgramStore *pfs = rsc->mStateFragmentStore.mPFS; + pfs->init(); pfs->incUserRef(); rsc->mStateFragmentStore.mPFS = 0; return pfs; diff --git a/libs/rs/rsProgramStore.h b/libs/rs/rsProgramStore.h index f8eb7cf..38e88e3 100644 --- a/libs/rs/rsProgramStore.h +++ b/libs/rs/rsProgramStore.h @@ -45,22 +45,33 @@ public: virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; } static ProgramStore *createFromStream(Context *rsc, IStream *stream); -protected: - bool mDitherEnable; + void init(); + + struct Hal { + mutable void *drv; + + struct State { + bool ditherEnable; - bool mBlendEnable; - bool mColorRWriteEnable; - bool mColorGWriteEnable; - bool mColorBWriteEnable; - bool mColorAWriteEnable; - int32_t mBlendSrc; - int32_t mBlendDst; + //bool blendEnable; + bool colorRWriteEnable; + bool colorGWriteEnable; + bool colorBWriteEnable; + bool colorAWriteEnable; + RsBlendSrcFunc blendSrc; + RsBlendDstFunc blendDst; - bool mDepthTestEnable; - bool mDepthWriteEnable; - int32_t mDepthFunc; + //bool depthTestEnable; + bool depthWriteEnable; + RsDepthFunc depthFunc; + }; + State state; - bool mStencilTestEnable; + + }; + Hal mHal; + +protected: }; class ProgramStoreState { diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index d5c486b..8e95891 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -185,7 +185,7 @@ bool ScriptC::runCompiler(Context *rsc, //LOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen); - rsc->mHal.funcs.script.scriptInit(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0, symbolLookup); + rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0, symbolLookup); mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h index 17983ce..6d7a5b1 100644 --- a/libs/rs/rs_hal.h +++ b/libs/rs/rs_hal.h @@ -29,7 +29,7 @@ class Type; class Allocation; class Script; class ScriptC; - +class ProgramStore; typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); @@ -50,13 +50,13 @@ typedef struct { struct { - bool (*scriptInit)(const Context *rsc, ScriptC *s, - char const *resName, - char const *cacheDir, - uint8_t const *bitcode, - size_t bitcodeSize, - uint32_t flags, - RsHalSymbolLookupFunc lookupFunc); + bool (*init)(const Context *rsc, ScriptC *s, + char const *resName, + char const *cacheDir, + uint8_t const *bitcode, + size_t bitcodeSize, + uint32_t flags, + RsHalSymbolLookupFunc lookupFunc); void (*invokeFunction)(const Context *rsc, Script *s, uint32_t slot, @@ -87,6 +87,13 @@ typedef struct { } script; + struct { + bool (*init)(const Context *rsc, const ProgramStore *ps); + void (*setActive)(const Context *rsc, const ProgramStore *ps); + void (*destroy)(const Context *rsc, const ProgramStore *ps); + } store; + + } RsdHalFunctions; |