diff options
author | Jason Sams <rjsams@android.com> | 2011-04-06 11:23:54 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2011-04-06 11:23:54 -0700 |
commit | 331bf9b14b1c5c1e88f5c4092b6e24fae887fb3b (patch) | |
tree | a9472a72e2d08c45deb03741a0ff6ad3b33c0583 | |
parent | 48f505657adba4d9156856e7d5593f23af5d5d5a (diff) | |
download | frameworks_base-331bf9b14b1c5c1e88f5c4092b6e24fae887fb3b.zip frameworks_base-331bf9b14b1c5c1e88f5c4092b6e24fae887fb3b.tar.gz frameworks_base-331bf9b14b1c5c1e88f5c4092b6e24fae887fb3b.tar.bz2 |
Seperate ProgramRaster.
Cleanup ProgramRaster and ProgramStore creation.
Change-Id: If25ea74355238d405340f0ccfb8117ad6e1307b7
-rw-r--r-- | graphics/java/android/renderscript/ProgramRaster.java | 23 | ||||
-rw-r--r-- | graphics/java/android/renderscript/ProgramStore.java | 20 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 58 | ||||
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 85 | ||||
-rw-r--r-- | libs/rs/Android.mk | 1 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.cpp | 7 | ||||
-rw-r--r-- | libs/rs/driver/rsdProgramRaster.cpp | 55 | ||||
-rw-r--r-- | libs/rs/driver/rsdProgramRaster.h | 31 | ||||
-rw-r--r-- | libs/rs/rs.spec | 48 | ||||
-rw-r--r-- | libs/rs/rsContext.cpp | 6 | ||||
-rw-r--r-- | libs/rs/rsFont.cpp | 9 | ||||
-rw-r--r-- | libs/rs/rsProgramRaster.cpp | 69 | ||||
-rw-r--r-- | libs/rs/rsProgramRaster.h | 26 | ||||
-rw-r--r-- | libs/rs/rsProgramStore.cpp | 99 | ||||
-rw-r--r-- | libs/rs/rsProgramStore.h | 19 | ||||
-rw-r--r-- | libs/rs/rs_hal.h | 6 |
16 files changed, 221 insertions, 341 deletions
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java index b89d36d..cf8749b 100644 --- a/graphics/java/android/renderscript/ProgramRaster.java +++ b/graphics/java/android/renderscript/ProgramRaster.java @@ -55,18 +55,6 @@ public class ProgramRaster extends BaseObj { mCullMode = CullMode.BACK; } - void setLineWidth(float w) { - mRS.validate(); - mLineWidth = w; - mRS.nProgramRasterSetLineWidth(getID(), w); - } - - void setCullMode(CullMode m) { - mRS.validate(); - mCullMode = m; - mRS.nProgramRasterSetCullMode(getID(), m.mID); - } - public static ProgramRaster CULL_BACK(RenderScript rs) { if(rs.mProgramRaster_CULL_BACK == null) { ProgramRaster.Builder builder = new ProgramRaster.Builder(rs); @@ -119,16 +107,11 @@ public class ProgramRaster extends BaseObj { return this; } - static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) { - int id = rs.nProgramRasterCreate(b.mPointSmooth, b.mLineSmooth, b.mPointSprite); - ProgramRaster pr = new ProgramRaster(id, rs); - pr.setCullMode(b.mCullMode); - return pr; - } - public ProgramRaster create() { mRS.validate(); - return internalCreate(mRS, this); + int id = mRS.nProgramRasterCreate(mPointSmooth, mLineSmooth, mPointSprite, + 1.f, mCullMode.mID); + return new ProgramRaster(id, mRS); } } diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java index c46e6b9..7a84d8b 100644 --- a/graphics/java/android/renderscript/ProgramStore.java +++ b/graphics/java/android/renderscript/ProgramStore.java @@ -333,27 +333,15 @@ public class ProgramStore extends BaseObj { return this; } - static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) { - rs.nProgramStoreBegin(0, 0); - rs.nProgramStoreDepthFunc(b.mDepthFunc.mID); - rs.nProgramStoreDepthMask(b.mDepthMask); - rs.nProgramStoreColorMask(b.mColorMaskR, - b.mColorMaskG, - b.mColorMaskB, - b.mColorMaskA); - rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID); - rs.nProgramStoreDither(b.mDither); - - int id = rs.nProgramStoreCreate(); - return new ProgramStore(id, rs); - } - /** * Creates a program store from the current state of the builder */ public ProgramStore create() { mRS.validate(); - return internalCreate(mRS, this); + int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA, + mDepthMask, mDither, + mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID); + return new ProgramStore(id, mRS); } } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index f577532..700c432 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -485,56 +485,22 @@ public class RenderScript { return rsnSamplerCreate(mContext); } - native void rsnProgramStoreBegin(int con, int in, int out); - synchronized void nProgramStoreBegin(int in, int out) { + native int rsnProgramStoreCreate(int con, boolean r, boolean g, boolean b, boolean a, + boolean depthMask, boolean dither, + int srcMode, int dstMode, int depthFunc); + synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a, + boolean depthMask, boolean dither, + int srcMode, int dstMode, int depthFunc) { validate(); - rsnProgramStoreBegin(mContext, in, out); - } - native void rsnProgramStoreDepthFunc(int con, int func); - synchronized void nProgramStoreDepthFunc(int func) { - validate(); - rsnProgramStoreDepthFunc(mContext, func); - } - native void rsnProgramStoreDepthMask(int con, boolean enable); - synchronized void nProgramStoreDepthMask(boolean enable) { - validate(); - rsnProgramStoreDepthMask(mContext, enable); - } - native void rsnProgramStoreColorMask(int con, boolean r, boolean g, boolean b, boolean a); - synchronized void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a) { - validate(); - rsnProgramStoreColorMask(mContext, r, g, b, a); - } - native void rsnProgramStoreBlendFunc(int con, int src, int dst); - synchronized void nProgramStoreBlendFunc(int src, int dst) { - validate(); - rsnProgramStoreBlendFunc(mContext, src, dst); - } - native void rsnProgramStoreDither(int con, boolean enable); - synchronized void nProgramStoreDither(boolean enable) { - validate(); - rsnProgramStoreDither(mContext, enable); - } - native int rsnProgramStoreCreate(int con); - synchronized int nProgramStoreCreate() { - validate(); - return rsnProgramStoreCreate(mContext); + return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode, dstMode, depthFunc); } - native int rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, boolean pointSprite); - synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite) { - validate(); - return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite); - } - native void rsnProgramRasterSetLineWidth(int con, int pr, float v); - synchronized void nProgramRasterSetLineWidth(int pr, float v) { - validate(); - rsnProgramRasterSetLineWidth(mContext, pr, v); - } - native void rsnProgramRasterSetCullMode(int con, int pr, int mode); - synchronized void nProgramRasterSetCullMode(int pr, int mode) { + native int rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, + boolean pointSprite, float lineWidth, int cullMode); + synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, + boolean pointSprite, float lineWidth, int cullMode) { validate(); - rsnProgramRasterSetCullMode(mContext, pr, mode); + return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite, lineWidth, cullMode); } native void rsnProgramBindConstants(int con, int pv, int slot, int mID); diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index c7f4809..12c5940 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -897,53 +897,17 @@ exit: // --------------------------------------------------------------------------- -static void -nProgramStoreBegin(JNIEnv *_env, jobject _this, RsContext con, jint in, jint out) -{ - LOG_API("nProgramStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); - rsProgramStoreBegin(con, (RsElement)in, (RsElement)out); -} - -static void -nProgramStoreDepthFunc(JNIEnv *_env, jobject _this, RsContext con, jint func) -{ - LOG_API("nProgramStoreDepthFunc, con(%p), func(%i)", con, func); - rsProgramStoreDepthFunc(con, (RsDepthFunc)func); -} - -static void -nProgramStoreDepthMask(JNIEnv *_env, jobject _this, RsContext con, jboolean enable) -{ - LOG_API("nProgramStoreDepthMask, con(%p), enable(%i)", con, enable); - rsProgramStoreDepthMask(con, enable); -} - -static void -nProgramStoreColorMask(JNIEnv *_env, jobject _this, RsContext con, jboolean r, jboolean g, jboolean b, jboolean a) -{ - LOG_API("nProgramStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a); - rsProgramStoreColorMask(con, r, g, b, a); -} - -static void -nProgramStoreBlendFunc(JNIEnv *_env, jobject _this, RsContext con, int src, int dst) -{ - LOG_API("nProgramStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst); - rsProgramStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst); -} - -static void -nProgramStoreDither(JNIEnv *_env, jobject _this, RsContext con, jboolean enable) -{ - LOG_API("nProgramStoreDither, con(%p), enable(%i)", con, enable); - rsProgramStoreDither(con, enable); -} - static jint -nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con) +nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con, + jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA, + jboolean depthMask, jboolean ditherEnable, + jint srcFunc, jint destFunc, + jint depthFunc) { LOG_API("nProgramStoreCreate, con(%p)", con); - return (jint)rsProgramStoreCreate(con); + return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA, + depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc, + (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc); } // --------------------------------------------------------------------------- @@ -1005,25 +969,12 @@ nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, // --------------------------------------------------------------------------- static jint -nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite) +nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth, + jboolean lineSmooth, jboolean pointSprite, jfloat lineWidth, jint cull) { LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)", con, pointSmooth, lineSmooth, pointSprite); - return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite); -} - -static void -nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jfloat v) -{ - LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v); - rsProgramRasterSetLineWidth(con, (RsProgramRaster)vpr, v); -} - -static void -nProgramRasterSetCullMode(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jint v) -{ - LOG_API("nProgramRasterSetCullMode, con(%p), vpf(%p), value(%i)", con, (RsProgramRaster)vpr, v); - rsProgramRasterSetCullMode(con, (RsProgramRaster)vpr, (RsCullMode)v); + return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite, lineWidth, (RsCullMode)cull); } @@ -1270,24 +1221,14 @@ static JNINativeMethod methods[] = { {"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate }, -{"rsnProgramStoreBegin", "(III)V", (void*)nProgramStoreBegin }, -{"rsnProgramStoreDepthFunc", "(II)V", (void*)nProgramStoreDepthFunc }, -{"rsnProgramStoreDepthMask", "(IZ)V", (void*)nProgramStoreDepthMask }, -{"rsnProgramStoreColorMask", "(IZZZZ)V", (void*)nProgramStoreColorMask }, -{"rsnProgramStoreBlendFunc", "(III)V", (void*)nProgramStoreBlendFunc }, -{"rsnProgramStoreDither", "(IZ)V", (void*)nProgramStoreDither }, -{"rsnProgramStoreCreate", "(I)I", (void*)nProgramStoreCreate }, +{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate }, {"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants }, {"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture }, {"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler }, {"rsnProgramFragmentCreate", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate }, - -{"rsnProgramRasterCreate", "(IZZZ)I", (void*)nProgramRasterCreate }, -{"rsnProgramRasterSetLineWidth", "(IIF)V", (void*)nProgramRasterSetLineWidth }, -{"rsnProgramRasterSetCullMode", "(III)V", (void*)nProgramRasterSetCullMode }, - +{"rsnProgramRasterCreate", "(IZZZFI)I", (void*)nProgramRasterCreate }, {"rsnProgramVertexCreate", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate }, {"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript }, diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index a07955a..3362c7d 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -117,6 +117,7 @@ LOCAL_SRC_FILES:= \ rsVertexArray.cpp \ driver/rsdBcc.cpp \ driver/rsdCore.cpp \ + driver/rsdProgramRaster.cpp \ driver/rsdProgramStore.cpp diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index 448be6a..00d62ba 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -17,6 +17,7 @@ #include "rsdCore.h" #include "rsdBcc.h" #include "rsdProgramStore.h" +#include "rsdProgramRaster.h" #include <malloc.h> #include "rsContext.h" @@ -56,6 +57,12 @@ static RsdHalFunctions FunctionTable = { rsdProgramStoreInit, rsdProgramStoreSetActive, rsdProgramStoreDestroy + }, + + { + rsdProgramRasterInit, + rsdProgramRasterSetActive, + rsdProgramRasterDestroy } }; diff --git a/libs/rs/driver/rsdProgramRaster.cpp b/libs/rs/driver/rsdProgramRaster.cpp new file mode 100644 index 0000000..65995be --- /dev/null +++ b/libs/rs/driver/rsdProgramRaster.cpp @@ -0,0 +1,55 @@ +/* + * 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; + +bool rsdProgramRasterInit(const Context *, const ProgramRaster *) { + return true; +} + +void rsdProgramRasterSetActive(const Context *, const ProgramRaster *pr) { + switch (pr->mHal.state.cull) { + case RS_CULL_BACK: + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + break; + case RS_CULL_FRONT: + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + break; + case RS_CULL_NONE: + glDisable(GL_CULL_FACE); + break; + } + +} + +void rsdProgramRasterDestroy(const Context *, const ProgramRaster *) { +} + + diff --git a/libs/rs/driver/rsdProgramRaster.h b/libs/rs/driver/rsdProgramRaster.h new file mode 100644 index 0000000..20adaad --- /dev/null +++ b/libs/rs/driver/rsdProgramRaster.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_RASTER_H +#define RSD_PROGRAM_RASTER_H + +#include <rs_hal.h> + + +bool rsdProgramRasterInit(const android::renderscript::Context *rsc, + const android::renderscript::ProgramRaster *); +void rsdProgramRasterSetActive(const android::renderscript::Context *rsc, + const android::renderscript::ProgramRaster *); +void rsdProgramRasterDestroy(const android::renderscript::Context *rsc, + const android::renderscript::ProgramRaster *); + + +#endif diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index bbb6200..a7f473c 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -251,36 +251,16 @@ ScriptCCreate { } -ProgramStoreBegin { - param RsElement in - param RsElement out - } - -ProgramStoreColorMask { - param bool r - param bool g - param bool b - param bool a - } - -ProgramStoreBlendFunc { +ProgramStoreCreate { + param bool colorMaskR + param bool colorMaskG + param bool colorMaskB + param bool colorMaskA + param bool depthMask + param bool ditherEnable param RsBlendSrcFunc srcFunc param RsBlendDstFunc destFunc - } - -ProgramStoreDepthMask { - param bool enable -} - -ProgramStoreDither { - param bool enable -} - -ProgramStoreDepthFunc { - param RsDepthFunc func -} - -ProgramStoreCreate { + param RsDepthFunc depthFunc ret RsProgramStore } @@ -288,19 +268,11 @@ ProgramRasterCreate { param bool pointSmooth param bool lineSmooth param bool pointSprite + param float lineWidth + param RsCullMode cull ret RsProgramRaster } -ProgramRasterSetLineWidth { - param RsProgramRaster pr - param float lw -} - -ProgramRasterSetCullMode { - param RsProgramRaster pr - param RsCullMode mode -} - ProgramBindConstants { param RsProgram vp param uint32_t slot diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index d727ba1..c9a7060 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -405,16 +405,16 @@ bool Context::setupCheck() { return false; } - mFragmentStore->setupGL2(this, &mStateFragmentStore); + mFragmentStore->setup(this, &mStateFragmentStore); mFragment->setupGL2(this, &mStateFragment, &mShaderCache); - mRaster->setupGL2(this, &mStateRaster); + mRaster->setup(this, &mStateRaster); mVertex->setupGL2(this, &mStateVertex, &mShaderCache); mFBOCache.setupGL2(this); return true; } void Context::setupProgramStore() { - mFragmentStore->setupGL2(this, &mStateFragmentStore); + mFragmentStore->setup(this, &mStateFragmentStore); } static bool getProp(const char *str) { diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp index 0871d2f..cb83435 100644 --- a/libs/rs/rsFont.cpp +++ b/libs/rs/rsFont.cpp @@ -507,12 +507,11 @@ void FontState::initRenderState() { mFontSampler.set(sampler); mFontShaderF->bindSampler(mRSC, 0, sampler); - ProgramStore *fontStore = new ProgramStore(mRSC); + ProgramStore *fontStore = new ProgramStore(mRSC, true, true, true, true, + false, false, + RS_BLEND_SRC_SRC_ALPHA, RS_BLEND_DST_ONE_MINUS_SRC_ALPHA, + RS_DEPTH_FUNC_ALWAYS); mFontProgramStore.set(fontStore); - mFontProgramStore->setDepthFunc(RS_DEPTH_FUNC_ALWAYS); - mFontProgramStore->setBlendFunc(RS_BLEND_SRC_SRC_ALPHA, RS_BLEND_DST_ONE_MINUS_SRC_ALPHA); - mFontProgramStore->setDitherEnable(false); - mFontProgramStore->setDepthMask(false); mFontProgramStore->init(); } diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp index ace1572..9617c4d 100644 --- a/libs/rs/rsProgramRaster.cpp +++ b/libs/rs/rsProgramRaster.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 "rsProgramRaster.h" using namespace android; @@ -27,49 +22,33 @@ using namespace android::renderscript; ProgramRaster::ProgramRaster(Context *rsc, bool pointSmooth, - bool lineSmooth, bool pointSprite) + bool lineSmooth, bool pointSprite, + float lineWidth, RsCullMode cull) : Program(rsc) { - mPointSmooth = pointSmooth; - mLineSmooth = lineSmooth; - mPointSprite = pointSprite; - mLineWidth = 1.0f; - mCull = RS_CULL_BACK; -} + memset(&mHal, 0, sizeof(mHal)); -ProgramRaster::~ProgramRaster() { -} + mHal.state.pointSmooth = pointSmooth; + mHal.state.lineSmooth = lineSmooth; + mHal.state.pointSprite = pointSprite; + mHal.state.lineWidth = lineWidth; + mHal.state.cull = cull; -void ProgramRaster::setLineWidth(float s) { - mLineWidth = s; - mDirty = true; + rsc->mHal.funcs.raster.init(rsc, this); } -void ProgramRaster::setCullMode(RsCullMode mode) { - mCull = mode; - mDirty = true; +ProgramRaster::~ProgramRaster() { + mRSC->mHal.funcs.raster.destroy(mRSC, this); } -void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) { +void ProgramRaster::setup(const Context *rsc, ProgramRasterState *state) { if (state->mLast.get() == this && !mDirty) { return; } state->mLast.set(this); mDirty = false; - switch (mCull) { - case RS_CULL_BACK: - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - break; - case RS_CULL_FRONT: - glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT); - break; - case RS_CULL_NONE: - glDisable(GL_CULL_FACE); - break; - } + rsc->mHal.funcs.raster.setActive(rsc, this); } void ProgramRaster::serialize(OStream *stream) const { @@ -86,7 +65,7 @@ ProgramRasterState::~ProgramRasterState() { } void ProgramRasterState::init(Context *rsc) { - ProgramRaster *pr = new ProgramRaster(rsc, false, false, false); + ProgramRaster *pr = new ProgramRaster(rsc, false, false, false, 1.f, RS_CULL_BACK); mDefault.set(pr); } @@ -101,27 +80,15 @@ namespace renderscript { RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, bool pointSmooth, bool lineSmooth, - bool pointSprite) { + bool pointSprite, + float lineWidth, + RsCullMode cull) { ProgramRaster *pr = new ProgramRaster(rsc, pointSmooth, - lineSmooth, pointSprite); + lineSmooth, pointSprite, lineWidth, cull); pr->incUserRef(); return pr; } -void rsi_ProgramRasterSetLineWidth(Context * rsc, - RsProgramRaster vpr, - float s) { - ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); - pr->setLineWidth(s); -} - -void rsi_ProgramRasterSetCullMode(Context * rsc, - RsProgramRaster vpr, - RsCullMode mode) { - ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); - pr->setCullMode(mode); -} - } } diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h index 7958af9..045a7c1 100644 --- a/libs/rs/rsProgramRaster.h +++ b/libs/rs/rsProgramRaster.h @@ -30,23 +30,31 @@ public: ProgramRaster(Context *rsc, bool pointSmooth, bool lineSmooth, - bool pointSprite); + bool pointSprite, + float lineWidth, + RsCullMode cull); virtual ~ProgramRaster(); - virtual void setupGL2(const Context *, ProgramRasterState *); + virtual void setup(const Context *, ProgramRasterState *); virtual void serialize(OStream *stream) const; virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; } static ProgramRaster *createFromStream(Context *rsc, IStream *stream); - void setLineWidth(float w); - void setCullMode(RsCullMode mode); + struct Hal { + mutable void *drv; + + struct State { + bool pointSmooth; + bool lineSmooth; + bool pointSprite; + float lineWidth; + RsCullMode cull; + }; + State state; + }; + Hal mHal; protected: - bool mPointSmooth; - bool mLineSmooth; - bool mPointSprite; - float mLineWidth; - RsCullMode mCull; }; class ProgramRasterState { diff --git a/libs/rs/rsProgramStore.cpp b/libs/rs/rsProgramStore.cpp index 087414a..2ad65e9 100644 --- a/libs/rs/rsProgramStore.cpp +++ b/libs/rs/rsProgramStore.cpp @@ -21,27 +21,31 @@ using namespace android; using namespace android::renderscript; -ProgramStore::ProgramStore(Context *rsc) : Program(rsc) { +ProgramStore::ProgramStore(Context *rsc, + bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA, + bool depthMask, bool ditherEnable, + RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, + RsDepthFunc depthFunc) : Program(rsc) { memset(&mHal, 0, sizeof(mHal)); - mHal.state.ditherEnable = true; + mHal.state.ditherEnable = ditherEnable; - 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.colorRWriteEnable = colorMaskR; + mHal.state.colorGWriteEnable = colorMaskG; + mHal.state.colorBWriteEnable = colorMaskB; + mHal.state.colorAWriteEnable = colorMaskA; + mHal.state.blendSrc = srcFunc; + mHal.state.blendDst = destFunc; - mHal.state.depthWriteEnable = true; - mHal.state.depthFunc = RS_DEPTH_FUNC_LESS; + mHal.state.depthWriteEnable = depthMask; + mHal.state.depthFunc = depthFunc; } ProgramStore::~ProgramStore() { mRSC->mHal.funcs.store.destroy(mRSC, this); } -void ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state) { +void ProgramStore::setup(const Context *rsc, ProgramStoreState *state) { if (state->mLast.get() == this) { return; } @@ -50,10 +54,6 @@ void ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state) { rsc->mHal.funcs.store.setActive(rsc, this); } -void ProgramStore::setDitherEnable(bool enable) { - mHal.state.ditherEnable = enable; -} - void ProgramStore::serialize(OStream *stream) const { } @@ -61,43 +61,24 @@ ProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream) { return NULL; } -void ProgramStore::setDepthFunc(RsDepthFunc func) { - mHal.state.depthFunc = func; -} - -void ProgramStore::setDepthMask(bool mask) { - mHal.state.depthWriteEnable = mask; -} - -void ProgramStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst) { - mHal.state.blendSrc = src; - mHal.state.blendDst = dst; -} - -void ProgramStore::setColorMask(bool r, bool g, bool b, bool 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() { - mPFS = NULL; } ProgramStoreState::~ProgramStoreState() { - ObjectBase::checkDelete(mPFS); - mPFS = NULL; } void ProgramStoreState::init(Context *rsc) { - ProgramStore *pfs = new ProgramStore(rsc); - pfs->init(); - mDefault.set(pfs); + ProgramStore *ps = new ProgramStore(rsc, + true, true, true, true, + true, true, + RS_BLEND_SRC_ONE, RS_BLEND_DST_ZERO, + RS_DEPTH_FUNC_LESS); + ps->init(); + mDefault.set(ps); } void ProgramStoreState::deinit(Context *rsc) { @@ -109,38 +90,20 @@ void ProgramStoreState::deinit(Context *rsc) { namespace android { namespace renderscript { -void rsi_ProgramStoreBegin(Context * rsc, RsElement in, RsElement out) { - ObjectBase::checkDelete(rsc->mStateFragmentStore.mPFS); - rsc->mStateFragmentStore.mPFS = new ProgramStore(rsc); -} - -void rsi_ProgramStoreDepthFunc(Context *rsc, RsDepthFunc func) { - rsc->mStateFragmentStore.mPFS->setDepthFunc(func); -} +RsProgramStore rsi_ProgramStoreCreate(Context *rsc, + bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA, + bool depthMask, bool ditherEnable, + RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, + RsDepthFunc depthFunc) { -void rsi_ProgramStoreDepthMask(Context *rsc, bool mask) { - rsc->mStateFragmentStore.mPFS->setDepthMask(mask); -} - -void rsi_ProgramStoreColorMask(Context *rsc, bool r, bool g, bool b, bool a) { - rsc->mStateFragmentStore.mPFS->setColorMask(r, g, b, a); -} - -void rsi_ProgramStoreBlendFunc(Context *rsc, RsBlendSrcFunc src, RsBlendDstFunc dst) { - rsc->mStateFragmentStore.mPFS->setBlendFunc(src, dst); -} - -RsProgramStore rsi_ProgramStoreCreate(Context *rsc) { - ProgramStore *pfs = rsc->mStateFragmentStore.mPFS; + ProgramStore *pfs = new ProgramStore(rsc, + colorMaskR, colorMaskG, colorMaskB, colorMaskA, + depthMask, ditherEnable, + srcFunc, destFunc, depthFunc); pfs->init(); pfs->incUserRef(); - rsc->mStateFragmentStore.mPFS = 0; return pfs; } -void rsi_ProgramStoreDither(Context *rsc, bool enable) { - rsc->mStateFragmentStore.mPFS->setDitherEnable(enable); -} - } } diff --git a/libs/rs/rsProgramStore.h b/libs/rs/rsProgramStore.h index 38e88e3..bfe276d 100644 --- a/libs/rs/rsProgramStore.h +++ b/libs/rs/rsProgramStore.h @@ -28,18 +28,14 @@ class ProgramStoreState; class ProgramStore : public Program { public: - ProgramStore(Context *); + ProgramStore(Context *, + bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA, + bool depthMask, bool ditherEnable, + RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, + RsDepthFunc depthFunc); virtual ~ProgramStore(); - virtual void setupGL2(const Context *, ProgramStoreState *); - - void setDepthFunc(RsDepthFunc); - void setDepthMask(bool); - - void setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst); - void setColorMask(bool, bool, bool, bool); - - void setDitherEnable(bool); + virtual void setup(const Context *, ProgramStoreState *); virtual void serialize(OStream *stream) const; virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; } @@ -83,9 +79,6 @@ public: ObjectBaseRef<ProgramStore> mDefault; ObjectBaseRef<ProgramStore> mLast; - - - ProgramStore *mPFS; }; } diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h index 6d7a5b1..93d7476 100644 --- a/libs/rs/rs_hal.h +++ b/libs/rs/rs_hal.h @@ -30,6 +30,7 @@ class Allocation; class Script; class ScriptC; class ProgramStore; +class ProgramRaster; typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); @@ -93,6 +94,11 @@ typedef struct { void (*destroy)(const Context *rsc, const ProgramStore *ps); } store; + struct { + bool (*init)(const Context *rsc, const ProgramRaster *ps); + void (*setActive)(const Context *rsc, const ProgramRaster *ps); + void (*destroy)(const Context *rsc, const ProgramRaster *ps); + } raster; } RsdHalFunctions; |