diff options
Diffstat (limited to 'graphics')
4 files changed, 180 insertions, 3 deletions
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java new file mode 100644 index 0000000..ab327f1 --- /dev/null +++ b/graphics/java/android/renderscript/ProgramRaster.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2008 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. + */ + +package android.renderscript; + + +import android.util.Config; +import android.util.Log; + + +/** + * @hide + * + **/ +public class ProgramRaster extends BaseObj { + boolean mPointSmooth; + boolean mLineSmooth; + boolean mPointSprite; + float mPointSize; + float mLineWidth; + Element mIn; + Element mOut; + + ProgramRaster(int id, RenderScript rs) { + super(rs); + mID = id; + + mPointSize = 1.0f; + mLineWidth = 1.0f; + mPointSmooth = false; + mLineSmooth = false; + mPointSprite = false; + } + + public void setLineWidth(float w) { + mLineWidth = w; + mRS.nProgramRasterSetLineWidth(mID, w); + } + + public void setPointSize(float s) { + mPointSize = s; + mRS.nProgramRasterSetPointSize(mID, s); + } + + void internalInit() { + int inID = 0; + int outID = 0; + if (mIn != null) { + inID = mIn.mID; + } + if (mOut != null) { + outID = mOut.mID; + } + mID = mRS.nProgramRasterCreate(inID, outID, mPointSmooth, mLineSmooth, mPointSprite); + } + + + public static class Builder { + RenderScript mRS; + ProgramRaster mPR; + + public Builder(RenderScript rs, Element in, Element out) { + mRS = rs; + mPR = new ProgramRaster(0, rs); + } + + public void setPointSpriteEnable(boolean enable) { + mPR.mPointSprite = enable; + } + + public void setPointSmoothEnable(boolean enable) { + mPR.mPointSmooth = enable; + } + + public void setLineSmoothEnable(boolean enable) { + mPR.mLineSmooth = enable; + } + + + static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) { + b.mPR.internalInit(); + ProgramRaster pr = b.mPR; + b.mPR = new ProgramRaster(0, b.mRS); + return pr; + } + + public ProgramRaster create() { + return internalCreate(mRS, this); + } + } + +} + + + + + diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java index a3f1ded..3d6acc9 100644 --- a/graphics/java/android/renderscript/RSSurfaceView.java +++ b/graphics/java/android/renderscript/RSSurfaceView.java @@ -133,14 +133,19 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback // ---------------------------------------------------------------------- - public RenderScript createRenderScript(boolean useDepth) { + public RenderScript createRenderScript(boolean useDepth, boolean forceSW) { Surface sur = null; while ((sur == null) || (mSurfaceHolder == null)) { sur = getHolder().getSurface(); } - RenderScript rs = new RenderScript(sur, useDepth); + RenderScript rs = new RenderScript(sur, useDepth, forceSW); return rs; } + public RenderScript createRenderScript(boolean useDepth) { + return createRenderScript(useDepth, false); + } + + } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 5831d13..1ce7083 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -61,6 +61,7 @@ public class RenderScript { native int nDeviceCreate(); native void nDeviceDestroy(int dev); + native void nDeviceSetConfig(int dev, int param, int value); native int nContextCreate(int dev, Surface sur, int ver, boolean useDepth); native void nContextDestroy(int con); @@ -71,6 +72,7 @@ public class RenderScript { native void nContextBindProgramFragmentStore(int pfs); native void nContextBindProgramFragment(int pf); native void nContextBindProgramVertex(int pf); + native void nContextBindProgramRaster(int pr); native void nContextAddDefineI32(String name, int value); native void nContextAddDefineF(String name, float value); @@ -163,6 +165,10 @@ public class RenderScript { native void nProgramFragmentStoreDither(boolean enable); native int nProgramFragmentStoreCreate(); + native int nProgramRasterCreate(int in, int out, boolean pointSmooth, boolean lineSmooth, boolean pointSprite); + native void nProgramRasterSetLineWidth(int pr, float v); + native void nProgramRasterSetPointSize(int pr, float v); + native void nProgramFragmentBegin(int in, int out, boolean pointSpriteEnable); native void nProgramFragmentBindTexture(int vpf, int slot, int a); native void nProgramFragmentBindSampler(int vpf, int slot, int s); @@ -200,9 +206,12 @@ public class RenderScript { /////////////////////////////////////////////////////////////////////////////////// // - public RenderScript(Surface sur, boolean useDepth) { + public RenderScript(Surface sur, boolean useDepth, boolean forceSW) { mSurface = sur; mDev = nDeviceCreate(); + if(forceSW) { + nDeviceSetConfig(mDev, 0, 1); + } mContext = nContextCreate(mDev, mSurface, 0, useDepth); // TODO: This should be protected by a lock @@ -312,6 +321,10 @@ public class RenderScript { nContextBindProgramFragment(pf.mID); } + public void contextBindProgramRaster(ProgramRaster pf) { + nContextBindProgramRaster(pf.mID); + } + public void contextBindProgramVertex(ProgramVertex pf) { nContextBindProgramVertex(pf.mID); } diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 56a4223..4a8f8a3 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -143,6 +143,13 @@ nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) return rsDeviceDestroy((RsDevice)dev); } +static void +nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) +{ + LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); + return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); +} + static jint nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver, jboolean useDepth) { @@ -1132,6 +1139,34 @@ nProgramVertexCreate(JNIEnv *_env, jobject _this) } +// --------------------------------------------------------------------------- + +static jint +nProgramRasterCreate(JNIEnv *_env, jobject _this, jint in, jint out, + jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + LOG_API("nProgramRasterCreate, con(%p), in(%p), out(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)", + con, (RsElement)in, (RsElement)out, pointSmooth, lineSmooth, pointSprite); + return (jint)rsProgramRasterCreate(con, (RsElement)in, (RsElement)out, pointSmooth, lineSmooth, pointSprite); +} + +static void +nProgramRasterSetPointSize(JNIEnv *_env, jobject _this, jint vpr, jfloat v) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + LOG_API("nProgramRasterSetPointSize, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v); + rsProgramRasterSetPointSize(con, (RsProgramFragment)vpr, v); +} + +static void +nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, jint vpr, jfloat v) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v); + rsProgramRasterSetLineWidth(con, (RsProgramFragment)vpr, v); +} + // --------------------------------------------------------------------------- @@ -1168,6 +1203,14 @@ nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf) } static void +nContextBindProgramRaster(JNIEnv *_env, jobject _this, jint pf) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf); + rsContextBindProgramRaster(con, (RsProgramRaster)pf); +} + +static void nContextAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); @@ -1306,6 +1349,7 @@ static JNINativeMethod methods[] = { {"nDeviceCreate", "()I", (void*)nDeviceCreate }, {"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, +{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, {"nContextCreate", "(ILandroid/view/Surface;IZ)I", (void*)nContextCreate }, {"nContextDestroy", "(I)V", (void*)nContextDestroy }, {"nAssignName", "(I[B)V", (void*)nAssignName }, @@ -1396,6 +1440,10 @@ static JNINativeMethod methods[] = { {"nProgramFragmentSetSlot", "(IZII)V", (void*)nProgramFragmentSetSlot }, {"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate }, +{"nProgramRasterCreate", "(IIZZZ)I", (void*)nProgramRasterCreate }, +{"nProgramRasterSetPointSize", "(IF)V", (void*)nProgramRasterSetPointSize }, +{"nProgramRasterSetLineWidth", "(IF)V", (void*)nProgramRasterSetLineWidth }, + {"nProgramVertexBindAllocation", "(II)V", (void*)nProgramVertexBindAllocation }, {"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin }, {"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable }, @@ -1413,6 +1461,7 @@ static JNINativeMethod methods[] = { {"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore }, {"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment }, {"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex }, +{"nContextBindProgramRaster", "(I)V", (void*)nContextBindProgramRaster }, {"nSamplerBegin", "()V", (void*)nSamplerBegin }, {"nSamplerSet", "(II)V", (void*)nSamplerSet }, |
