diff options
25 files changed, 616 insertions, 24 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 12e5ada..7e542ad 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -870,7 +870,31 @@ public class Allocation extends BaseObj { if (type.getID() == 0) { throw new RSInvalidStateException("Bad Type"); } - int id = rs.nAllocationCreateTyped(type.getID(), mips.mID, usage); + int id = rs.nAllocationCreateTyped(type.getID(), mips.mID, usage, 0); + if (id == 0) { + throw new RSRuntimeException("Allocation creation failed."); + } + return new Allocation(id, rs, type, usage); + } + + /** + * @hide + * This API is hidden and only intended to be used for + * transitional purposes. + * + * @param type renderscript type describing data layout + * @param mips specifies desired mipmap behaviour for the + * allocation + * @param usage bit field specifying how the allocation is + * utilized + */ + static public Allocation createTyped(RenderScript rs, Type type, MipmapControl mips, + int usage, int pointer) { + rs.validate(); + if (type.getID() == 0) { + throw new RSInvalidStateException("Bad Type"); + } + int id = rs.nAllocationCreateTyped(type.getID(), mips.mID, usage, pointer); if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); } @@ -925,7 +949,7 @@ public class Allocation extends BaseObj { b.setX(count); Type t = b.create(); - int id = rs.nAllocationCreateTyped(t.getID(), MipmapControl.MIPMAP_NONE.mID, usage); + int id = rs.nAllocationCreateTyped(t.getID(), MipmapControl.MIPMAP_NONE.mID, usage, 0); if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); } diff --git a/graphics/java/android/renderscript/Path.java b/graphics/java/android/renderscript/Path.java new file mode 100644 index 0000000..83ae150 --- /dev/null +++ b/graphics/java/android/renderscript/Path.java @@ -0,0 +1,90 @@ +/* + * 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 java.util.Vector; +import android.util.Log; + +/** + * @hide + * + */ +public class Path extends BaseObj { + + public enum Primitive { + QUADRATIC_BEZIER(0), + CUBIC_BEZIER(1); + + int mID; + Primitive(int id) { + mID = id; + } + } + + Allocation mVertexBuffer; + Allocation mLoopBuffer; + Primitive mPrimitive; + float mQuality; + boolean mCoverageToAlpha; + + Path(int id, RenderScript rs, Primitive p, Allocation vtx, Allocation loop, float q) { + super(id, rs); + mVertexBuffer = vtx; + mLoopBuffer = loop; + mPrimitive = p; + mQuality = q; + } + + public Allocation getVertexAllocation() { + return mVertexBuffer; + } + + public Allocation getLoopAllocation() { + return mLoopBuffer; + } + + public Primitive getPrimitive() { + return mPrimitive; + } + + @Override + void updateFromNative() { + } + + + public static Path createStaticPath(RenderScript rs, Primitive p, float quality, Allocation vtx) { + int id = rs.nPathCreate(p.mID, false, vtx.getID(), 0, quality); + Path newPath = new Path(id, rs, p, null, null, quality); + return newPath; + } + + public static Path createStaticPath(RenderScript rs, Primitive p, float quality, Allocation vtx, Allocation loops) { + return null; + } + + public static Path createDynamicPath(RenderScript rs, Primitive p, float quality, Allocation vtx) { + return null; + } + + public static Path createDynamicPath(RenderScript rs, Primitive p, float quality, Allocation vtx, Allocation loops) { + return null; + } + + +} + + diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 1305633..c0cb324 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -228,10 +228,10 @@ public class RenderScript { rsnTypeGetNativeData(mContext, id, typeData); } - native int rsnAllocationCreateTyped(int con, int type, int mip, int usage); - synchronized int nAllocationCreateTyped(int type, int mip, int usage) { + native int rsnAllocationCreateTyped(int con, int type, int mip, int usage, int pointer); + synchronized int nAllocationCreateTyped(int type, int mip, int usage, int pointer) { validate(); - return rsnAllocationCreateTyped(mContext, type, mip, usage); + return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer); } native int rsnAllocationCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage); synchronized int nAllocationCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) { @@ -581,6 +581,11 @@ public class RenderScript { rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount); } + native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q); + synchronized int nPathCreate(int prim, boolean isStatic, int vtx, int loop, float q) { + validate(); + return rsnPathCreate(mContext, prim, isStatic, vtx, loop, q); + } int mDev; int mContext; diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index c4ef993..2856437 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -430,10 +430,10 @@ nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArra // ----------------------------------- static jint -nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage) +nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer) { - LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i)", con, (RsElement)type, mips, usage); - return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage); + LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer); + return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer); } static void @@ -1122,6 +1122,17 @@ nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint // --------------------------------------------------------------------------- +//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q); +static jint +nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) { + LOG_API("nPathCreate, con(%p)", con); + + int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic, + (RsAllocation)_vtx, + (RsAllocation)_loop, q); + return id; +} + static jint nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim) { @@ -1250,7 +1261,7 @@ static JNINativeMethod methods[] = { {"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate }, {"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData }, -{"rsnAllocationCreateTyped", "(IIII)I", (void*)nAllocationCreateTyped }, +{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped }, {"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap }, {"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap }, @@ -1310,6 +1321,7 @@ static JNINativeMethod methods[] = { {"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate }, +{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate }, {"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate }, {"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount }, diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index 58d3e5c..7f0cbeb 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -96,6 +96,7 @@ LOCAL_SRC_FILES:= \ rsMatrix4x4.cpp \ rsMesh.cpp \ rsMutex.cpp \ + rsPath.cpp \ rsProgram.cpp \ rsProgramFragment.cpp \ rsProgramStore.cpp \ @@ -118,6 +119,7 @@ LOCAL_SRC_FILES:= \ driver/rsdGL.cpp \ driver/rsdMesh.cpp \ driver/rsdMeshObj.cpp \ + driver/rsdPath.cpp \ driver/rsdProgram.cpp \ driver/rsdProgramRaster.cpp \ driver/rsdProgramStore.cpp \ @@ -203,6 +205,7 @@ LOCAL_SRC_FILES:= \ rsMatrix4x4.cpp \ rsMesh.cpp \ rsMutex.cpp \ + rsPath.cpp \ rsProgram.cpp \ rsProgramFragment.cpp \ rsProgramStore.cpp \ diff --git a/libs/rs/RenderScriptDefines.h b/libs/rs/RenderScriptDefines.h index d092520..728b27a 100644 --- a/libs/rs/RenderScriptDefines.h +++ b/libs/rs/RenderScriptDefines.h @@ -41,6 +41,7 @@ typedef void * RsFont; typedef void * RsSampler; typedef void * RsScript; typedef void * RsMesh; +typedef void * RsPath; typedef void * RsType; typedef void * RsObjectBase; @@ -258,6 +259,11 @@ enum RsPrimitive { RS_PRIMITIVE_TRIANGLE_FAN }; +enum RsPathPrimitive { + RS_PATH_PRIMITIVE_QUADRATIC_BEZIER, + RS_PATH_PRIMITIVE_CUBIC_BEZIER +}; + enum RsError { RS_ERROR_NONE = 0, RS_ERROR_BAD_SHADER = 1, diff --git a/libs/rs/driver/rsdAllocation.cpp b/libs/rs/driver/rsdAllocation.cpp index e79cd0f..e072dab 100644 --- a/libs/rs/driver/rsdAllocation.cpp +++ b/libs/rs/driver/rsdAllocation.cpp @@ -212,10 +212,13 @@ bool rsdAllocationInit(const Context *rsc, Allocation *alloc, bool forceZero) { return false; } - void * ptr = malloc(alloc->mHal.state.type->getSizeBytes()); + void * ptr = alloc->mHal.state.usrPtr; if (!ptr) { - free(drv); - return false; + ptr = malloc(alloc->mHal.state.type->getSizeBytes()); + if (!ptr) { + free(drv); + return false; + } } drv->glTarget = GL_NONE; @@ -269,7 +272,7 @@ void rsdAllocationDestroy(const Context *rsc, Allocation *alloc) { drv->renderTargetID = 0; } - if (drv->mallocPtr) { + if (drv->mallocPtr && !alloc->mHal.state.usrPtr) { free(drv->mallocPtr); drv->mallocPtr = NULL; } diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index 9292fa1..a65e23b 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -18,6 +18,7 @@ #include "rsdAllocation.h" #include "rsdBcc.h" #include "rsdGL.h" +#include "rsdPath.h" #include "rsdProgramStore.h" #include "rsdProgramRaster.h" #include "rsdProgramVertex.h" @@ -115,6 +116,13 @@ static RsdHalFunctions FunctionTable = { }, { + rsdPathInitStatic, + rsdPathInitDynamic, + rsdPathDraw, + rsdPathDestroy + }, + + { rsdSamplerInit, rsdSamplerDestroy }, diff --git a/libs/rs/driver/rsdPath.cpp b/libs/rs/driver/rsdPath.cpp new file mode 100644 index 0000000..d475beb --- /dev/null +++ b/libs/rs/driver/rsdPath.cpp @@ -0,0 +1,185 @@ +/* + * 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 <GLES/gl.h> +#include <GLES2/gl2.h> +#include <GLES/glext.h> + +#include <rs_hal.h> +#include <rsContext.h> +#include <rsPath.h> + +#include "rsdCore.h" +#include "rsdPath.h" +#include "rsdAllocation.h" +#include "rsdGL.h" +#include "rsdVertexArray.h" +#include "rsdShaderCache.h" + +using namespace android; +using namespace android::renderscript; + +class DrvPath { +protected: + DrvPath(); +public: + virtual ~DrvPath(); + virtual void draw(Context *) = 0; +}; + +class DrvPathStatic : public DrvPath { +public: + typedef struct { + float x1, xc, x2; + float y1, yc, y2; + } segment_t; + + segment_t *mSegments; + uint32_t mSegmentCount; + + DrvPathStatic(const Allocation *vtx, const Allocation *loops); + virtual ~DrvPathStatic(); + + virtual void draw(Context *); +}; + +class DrvPathDynamic : public DrvPath { +public: + DrvPathDynamic(); + virtual ~DrvPathDynamic(); +}; + +static void cleanup(const Context *rsc, const Path *m) { + DrvPath *dp = (DrvPath *)m->mHal.drv; + if (dp) { + delete dp; + } +} + +bool rsdPathInitStatic(const Context *rsc, const Path *m, + const Allocation *vtx, const Allocation *loops) { + DrvPathStatic *drv = NULL; + cleanup(rsc, m); + + DrvPathStatic *dps = new DrvPathStatic(vtx, loops); + LOGE("init path m %p, %p", m, dps); + m->mHal.drv = dps; + return dps != NULL; +} + +bool rsdPathInitDynamic(const Context *rsc, const Path *m) { + return false; +} + + +void rsdPathDraw(const Context *rsc, const Path *m) { + LOGE("render m=%p", m); + + DrvPath *drv = (DrvPath *)m->mHal.drv; + if(drv) { + LOGE("render 2 drv=%p", drv); + drv->draw((Context *)rsc); + } +} + +void rsdPathDestroy(const Context *rsc, const Path *m) { + cleanup(rsc, m); + m->mHal.drv = NULL; +} + + + + +DrvPath::DrvPath() { +} + +DrvPath::~DrvPath() { +} + +DrvPathStatic::DrvPathStatic(const Allocation *vtx, const Allocation *loops) { + mSegmentCount = vtx->getType()->getDimX() / 3; + mSegments = new segment_t[mSegmentCount]; + + const float *fin = (const float *)vtx->getPtr(); + for (uint32_t ct=0; ct < mSegmentCount; ct++) { + segment_t *s = &mSegments[ct]; + s->x1 = fin[0]; + s->y1 = fin[1]; + + s->xc = fin[2]; + s->yc = fin[3]; + + s->x2 = fin[4]; + s->y2 = fin[5]; + fin += 6; + } +} + +DrvPathStatic::~DrvPathStatic() { +} + +void DrvPathStatic::draw(Context *rsc) { + const static float color[24] = { + 1.f, 0.f, 0.f, 1.f, 0.5f, 0.f, 0.f, 1.f, + 1.f, 0.f, 0.f, 1.f, 0.5f, 0.f, 0.f, 1.f, + 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f}; + float vtx[12]; + + LOGE("draw"); + if (!rsc->setupCheck()) { + return; + } + + RsdHal *dc = (RsdHal *)rsc->mHal.drv; + if (!dc->gl.shaderCache->setup(rsc)) { + return; + } + + RsdVertexArray::Attrib attribs[2]; + attribs[0].set(GL_FLOAT, 2, 8, false, (uint32_t)vtx, "ATTRIB_position"); + attribs[1].set(GL_FLOAT, 4, 16, false, (uint32_t)color, "ATTRIB_color"); + RsdVertexArray va(attribs, 2); + va.setup(rsc); + + LOGE("mSegmentCount %i", mSegmentCount); + for (uint32_t ct=0; ct < mSegmentCount; ct++) { + segment_t *s = &mSegments[ct]; + + vtx[0] = s->x1; + vtx[1] = s->y1; + vtx[2] = s->xc; + vtx[3] = s->yc; + + vtx[4] = s->x2; + vtx[5] = s->y2; + vtx[6] = s->xc; + vtx[7] = s->yc; + + vtx[8] = s->x1; + vtx[9] = s->y1; + vtx[10] = s->x2; + vtx[11] = s->y2; + + RSD_CALL_GL(glDrawArrays, GL_LINES, 0, 6); + } + +} + +DrvPathDynamic::DrvPathDynamic() { +} + +DrvPathDynamic::~DrvPathDynamic() { +} diff --git a/libs/rs/driver/rsdPath.h b/libs/rs/driver/rsdPath.h new file mode 100644 index 0000000..fa00972 --- /dev/null +++ b/libs/rs/driver/rsdPath.h @@ -0,0 +1,35 @@ +/* + * 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_PATH_H +#define RSD_PATH_H + +#include <rs_hal.h> + + +bool rsdPathInitStatic(const android::renderscript::Context *rsc, + const android::renderscript::Path *m, + const android::renderscript::Allocation *vertex, + const android::renderscript::Allocation *loops); +bool rsdPathInitDynamic(const android::renderscript::Context *rsc, + const android::renderscript::Path *m); +void rsdPathDraw(const android::renderscript::Context *rsc, + const android::renderscript::Path *m); +void rsdPathDestroy(const android::renderscript::Context *rsc, + const android::renderscript::Path *m); + + +#endif diff --git a/libs/rs/driver/rsdRuntimeStubs.cpp b/libs/rs/driver/rsdRuntimeStubs.cpp index 90c8928..c2201be 100644 --- a/libs/rs/driver/rsdRuntimeStubs.cpp +++ b/libs/rs/driver/rsdRuntimeStubs.cpp @@ -25,6 +25,7 @@ #include "rsdCore.h" #include "rsdRuntime.h" +#include "rsdPath.h" #include <time.h> @@ -204,6 +205,12 @@ static void SC_DrawRect(float x1, float y1, float x2, float y2, float z) { rsrDrawRect(rsc, sc, x1, y1, x2, y2, z); } +static void SC_DrawPath(Path *p) { + GET_TLS(); + //rsrDrawPath(rsc, sc, p); + rsdPathDraw(rsc, p); +} + static void SC_DrawMesh(Mesh *m) { GET_TLS(); rsrDrawMesh(rsc, sc, m); @@ -533,6 +540,10 @@ static RsdSymbolTable gSyms[] = { { "_Z13rsClearObjectP9rs_script", (void *)&SC_ClearObject, true }, { "_Z10rsIsObject9rs_script", (void *)&SC_IsObject, true }, + { "_Z11rsSetObjectP7rs_pathS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP7rs_path", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject7rs_path", (void *)&SC_IsObject, true }, + { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_SetObject, true }, { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_ClearObject, true }, { "_Z10rsIsObject7rs_mesh", (void *)&SC_IsObject, true }, @@ -603,6 +614,8 @@ static RsdSymbolTable gSyms[] = { { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_DrawMeshPrimitiveRange, false }, { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_MeshComputeBoundingBox, false }, + { "_Z11rsgDrawPath7rs_path", (void *)&SC_DrawPath, false }, + { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false }, { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false }, diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 20b1f52..d60db7e 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -42,6 +42,7 @@ AllocationCreateTyped { param RsType vtype param RsAllocationMipmapControl mips param uint32_t usages + param uint32_t ptr ret RsAllocation } @@ -388,3 +389,13 @@ MeshCreate { param uint32_t *primType ret RsMesh } + +PathCreate { + param RsPathPrimitive pp + param bool isStatic + param RsAllocation vertex + param RsAllocation loops + param float quality + ret RsPath + } + diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index c1192fe..2c360fb 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -22,21 +22,22 @@ using namespace android; using namespace android::renderscript; Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages, - RsAllocationMipmapControl mc) + RsAllocationMipmapControl mc, void * ptr) : ObjectBase(rsc) { memset(&mHal, 0, sizeof(mHal)); mHal.state.mipmapControl = RS_ALLOCATION_MIPMAP_NONE; mHal.state.usageFlags = usages; mHal.state.mipmapControl = mc; + mHal.state.usrPtr = ptr; setType(type); updateCache(); } Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32_t usages, - RsAllocationMipmapControl mc) { - Allocation *a = new Allocation(rsc, type, usages, mc); + RsAllocationMipmapControl mc, void * ptr) { + Allocation *a = new Allocation(rsc, type, usages, mc, ptr); if (!rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences())) { rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure"); @@ -570,8 +571,8 @@ static void AllocationGenerateScriptMips(RsContext con, RsAllocation va) { RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype, RsAllocationMipmapControl mips, - uint32_t usages) { - Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips); + uint32_t usages, uint32_t ptr) { + Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips, (void *)ptr); if (!alloc) { return NULL; } @@ -584,7 +585,7 @@ RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype, const void *data, size_t data_length, uint32_t usages) { Type *t = static_cast<Type *>(vtype); - RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages); + RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0); Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); if (texAlloc == NULL) { LOGE("Memory allocation failure"); @@ -608,7 +609,7 @@ RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype, // Cubemap allocation's faces should be Width by Width each. // Source data should have 6 * Width by Width pixels // Error checking is done in the java layer - RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages); + RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0); Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); if (texAlloc == NULL) { LOGE("Memory allocation failure"); diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index 4ce863a..0f7ed42 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -55,6 +55,8 @@ public: bool hasMipmaps; bool hasFaces; bool hasReferences; + + void * usrPtr; }; State state; @@ -66,7 +68,8 @@ public: Hal mHal; static Allocation * createAllocation(Context *rsc, const Type *, uint32_t usages, - RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE); + RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE, + void *ptr = 0); virtual ~Allocation(); void updateCache(); @@ -134,7 +137,7 @@ protected: private: void freeChildrenUnlocked(); - Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc); + Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc, void *ptr); uint32_t getPackedSize() const; static void writePackedData(const Type *type, uint8_t *dst, const uint8_t *src, bool dstPadded); diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index c6582c9..9f8cc4a 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -32,6 +32,7 @@ #include "rsAdapter.h" #include "rsSampler.h" #include "rsFont.h" +#include "rsPath.h" #include "rsProgramFragment.h" #include "rsProgramStore.h" #include "rsProgramRaster.h" diff --git a/libs/rs/rsPath.cpp b/libs/rs/rsPath.cpp new file mode 100644 index 0000000..89a0770 --- /dev/null +++ b/libs/rs/rsPath.cpp @@ -0,0 +1,78 @@ +/* + * 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 "rsContext.h" + +using namespace android; +using namespace android::renderscript; + + +Path::Path(Context *rsc) : ObjectBase(rsc) { +} + +Path::Path(Context *rsc, RsPathPrimitive pp, bool isStatic, + Allocation *vtx, Allocation *loops, float quality) +: ObjectBase(rsc) { + + memset(&mHal, 0, sizeof(mHal)); + mHal.state.quality = quality; + mHal.state.primitive = pp; + + LOGE("i1"); + rsc->mHal.funcs.path.initStatic(rsc, this, vtx, loops); + + LOGE("i2"); +} + +Path::Path(Context *rsc, uint32_t vertexBuffersCount, uint32_t primitivesCount) +: ObjectBase(rsc) { + +} + +Path::~Path() { + +} + + +void Path::rasterize(const BezierSegment_t *s, uint32_t num, Allocation *alloc) { + + for (uint32_t i=0; i < num; i++) { + + } + +} + +void Path::render(Context *rsc) { +} + +void Path::serialize(OStream *stream) const { + +} + +RsA3DClassID Path::getClassId() const { + return RS_A3D_CLASS_ID_UNKNOWN; +} + +namespace android { +namespace renderscript { + +RsPath rsi_PathCreate(Context *rsc, RsPathPrimitive pp, bool isStatic, + RsAllocation vtx, RsAllocation loops, float quality) { + return new Path(rsc, pp, isStatic, (Allocation *)vtx, (Allocation *)loops, quality); +} + +} +} diff --git a/libs/rs/rsPath.h b/libs/rs/rsPath.h new file mode 100644 index 0000000..dac795e --- /dev/null +++ b/libs/rs/rsPath.h @@ -0,0 +1,69 @@ +/* + * 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 ANDROID_RS_PATH_H +#define ANDROID_RS_PATH_H + + +#include "RenderScript.h" + +// --------------------------------------------------------------------------- +namespace android { +namespace renderscript { + +class Path : public ObjectBase { +public: + struct { + mutable void * drv; + + struct State { + RsPathPrimitive primitive; + float quality; + }; + State state; + } mHal; + + Path(Context *); + Path(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount); + Path(Context *, RsPathPrimitive pp, bool isStatic, Allocation *vtx, Allocation *loop, float q); + + ~Path(); + + void render(Context *); + virtual void serialize(OStream *stream) const; + virtual RsA3DClassID getClassId() const; + +private: + + + typedef struct { + float x[4]; + float y[4]; + } BezierSegment_t; + + bool subdivideCheck(const BezierSegment_t *s, float u1, float u2); + + void rasterize(const BezierSegment_t *s, uint32_t num, Allocation *alloc); + + +}; + +} +} +#endif //ANDROID_RS_PATH_H + + + diff --git a/libs/rs/rsRuntime.h b/libs/rs/rsRuntime.h index cb962a8..b0869f6 100644 --- a/libs/rs/rsRuntime.h +++ b/libs/rs/rsRuntime.h @@ -68,6 +68,7 @@ void rsrDrawQuad(Context *, Script *, void rsrDrawSpriteScreenspace(Context *, Script *, float x, float y, float z, float w, float h); void rsrDrawRect(Context *, Script *, float x1, float y1, float x2, float y2, float z); +void rsrDrawPath(Context *, Script *, Path *); void rsrDrawMesh(Context *, Script *, Mesh *); void rsrDrawMeshPrimitive(Context *, Script *, Mesh *, uint32_t primIndex); void rsrDrawMeshPrimitiveRange(Context *, Script *, Mesh *, diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp index 26e2374..a79c3cb 100644 --- a/libs/rs/rsScriptC_LibGL.cpp +++ b/libs/rs/rsScriptC_LibGL.cpp @@ -200,6 +200,14 @@ void rsrDrawRect(Context *rsc, Script *sc, float x1, float y1, float x2, float y rsrDrawQuad(rsc, sc, x1, y2, z, x2, y2, z, x2, y1, z, x1, y1, z); } +void rsrDrawPath(Context *rsc, Script *sc, Path *sm) { + CHECK_OBJ(sm); + if (!rsc->setupCheck()) { + return; + } + sm->render(rsc); +} + void rsrDrawMesh(Context *rsc, Script *sc, Mesh *sm) { CHECK_OBJ(sm); if (!rsc->setupCheck()) { diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h index b8d7351..a5df600 100644 --- a/libs/rs/rs_hal.h +++ b/libs/rs/rs_hal.h @@ -29,6 +29,7 @@ class Type; class Allocation; class Script; class ScriptC; +class Path; class Program; class ProgramStore; class ProgramRaster; @@ -189,6 +190,13 @@ typedef struct { } mesh; struct { + bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops); + bool (*initDynamic)(const Context *rsc, const Path *m); + void (*draw)(const Context *rsc, const Path *m); + void (*destroy)(const Context *rsc, const Path *m); + } path; + + struct { bool (*init)(const Context *rsc, const Sampler *m); void (*destroy)(const Context *rsc, const Sampler *m); } sampler; diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh index 2581953..06a2772 100644 --- a/libs/rs/scriptc/rs_graphics.rsh +++ b/libs/rs/scriptc/rs_graphics.rsh @@ -288,6 +288,9 @@ extern void __attribute__((overloadable)) extern void __attribute__((overloadable)) rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h); +extern void __attribute__((overloadable)) + rsgDrawPath(rs_path p); + /** * Draw a mesh using the current context state. The whole mesh is * rendered. diff --git a/libs/rs/scriptc/rs_object.rsh b/libs/rs/scriptc/rs_object.rsh index a431219..1fc3f83 100644 --- a/libs/rs/scriptc/rs_object.rsh +++ b/libs/rs/scriptc/rs_object.rsh @@ -56,6 +56,11 @@ extern void __attribute__((overloadable)) * \overload */ extern void __attribute__((overloadable)) + rsSetObject(rs_path *dst, rs_path src); +/** + * \overload + */ +extern void __attribute__((overloadable)) rsSetObject(rs_mesh *dst, rs_mesh src); /** * \overload @@ -114,6 +119,11 @@ extern void __attribute__((overloadable)) * \overload */ extern void __attribute__((overloadable)) + rsClearObject(rs_path *dst); +/** + * \overload + */ +extern void __attribute__((overloadable)) rsClearObject(rs_mesh *dst); /** * \overload @@ -175,6 +185,11 @@ extern bool __attribute__((overloadable)) * \overload */ extern bool __attribute__((overloadable)) + rsIsObject(rs_path); +/** + * \overload + */ +extern bool __attribute__((overloadable)) rsIsObject(rs_mesh); /** * \overload diff --git a/libs/rs/scriptc/rs_types.rsh b/libs/rs/scriptc/rs_types.rsh index 84bca9c..a01807e 100644 --- a/libs/rs/scriptc/rs_types.rsh +++ b/libs/rs/scriptc/rs_types.rsh @@ -138,6 +138,12 @@ typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_sc */ typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_mesh; /** + * \brief Opaque handle to a Renderscript Path object. + * + * See: android.renderscript.Path + */ +typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_path; +/** * \brief Opaque handle to a Renderscript ProgramFragment object. * * See: android.renderscript.ProgramFragment diff --git a/tests/RenderScriptTests/ComputePerf/src/com/example/android/rs/computeperf/mandelbrot.rs b/tests/RenderScriptTests/ComputePerf/src/com/example/android/rs/computeperf/mandelbrot.rs index a7987b3..0ffb0e5 100644 --- a/tests/RenderScriptTests/ComputePerf/src/com/example/android/rs/computeperf/mandelbrot.rs +++ b/tests/RenderScriptTests/ComputePerf/src/com/example/android/rs/computeperf/mandelbrot.rs @@ -25,13 +25,14 @@ void root(uchar4 *v_out, uint32_t x, uint32_t y) { p.y = -1.f + ((float)y / gDimY) * 2.f; float2 t = 0; + float2 t2 = t * t; int iteration = 0; - while((t.x*t.x + t.y*t.y < 4.f) && (iteration < gMaxIteration)) { - float2 t2 = t * t; + while((t2.x + t2.y < 4.f) && (iteration < gMaxIteration)) { float xtemp = t2.x - t2.y + p.x; t.y = 2 * t.x * t.y + p.y; t.x = xtemp; iteration++; + t2 = t * t; } if(iteration >= gMaxIteration) { diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java index 3615f60..7368260 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java @@ -283,6 +283,9 @@ public class ImageProcessingActivity extends Activity mRadius = MAX_RADIUS; mScript.set_radius(mRadius); + mScript.invoke_filter(); + mRS.finish(); + long t = java.lang.System.currentTimeMillis(); mScript.invoke_filter(); |