Added ability to set font color.
Propagating the name of meshes and allocations from native a3d to java
Change-Id: If781f55340b5369459610e5e92ea69e240dcd24e
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 87735b5..46f3eae 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -48,6 +48,7 @@
@Override
void updateFromNative() {
mRS.validate();
+ mName = mRS.nGetName(mID);
int typeID = mRS.nAllocationGetType(mID);
if(typeID != 0) {
mType = new Type(typeID, mRS);
diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java
index 4bee97a..bf02319 100644
--- a/graphics/java/android/renderscript/Mesh.java
+++ b/graphics/java/android/renderscript/Mesh.java
@@ -61,6 +61,7 @@
@Override
void updateFromNative() {
+ mName = mRS.nGetName(mID);
int vtxCount = mRS.nMeshGetVertexBufferCount(mID);
int idxCount = mRS.nMeshGetIndexCount(mID);
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 1135a75..4eeb4d3 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -83,6 +83,7 @@
native void nContextDeinitToClient();
native void nAssignName(int obj, byte[] name);
+ native String nGetName(int obj);
native void nObjDestroy(int id);
native void nObjDestroyOOB(int id);
native int nFileOpen(byte[] name);
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 888c76a..8968dfb 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -104,6 +104,17 @@
_env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
}
+static jstring
+nGetName(JNIEnv *_env, jobject _this, jint obj)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
+
+ const char *name = NULL;
+ rsGetName(con, (void *)obj, &name);
+ return _env->NewStringUTF(name);
+}
+
static void
nObjDestroy(JNIEnv *_env, jobject _this, jint obj)
{
@@ -1518,6 +1529,7 @@
{"nContextPause", "()V", (void*)nContextPause },
{"nContextResume", "()V", (void*)nContextResume },
{"nAssignName", "(I[B)V", (void*)nAssignName },
+{"nGetName", "(I)Ljava/lang/String;", (void*)nGetName },
{"nObjDestroy", "(I)V", (void*)nObjDestroy },
{"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB },
{"nContextGetMessage", "([IZ)I", (void*)nContextGetMessage },
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 1b81591..571b145 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -58,6 +58,11 @@
param size_t len
}
+GetName {
+ param void *obj
+ param const char **name
+ }
+
ObjDestroy {
param void *obj
}
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 61ef5d4..1c03954 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -944,13 +944,18 @@
rsc->setFont(font);
}
-
void rsi_AssignName(Context *rsc, void * obj, const char *name, uint32_t len)
{
ObjectBase *ob = static_cast<ObjectBase *>(obj);
rsc->assignName(ob, name, len);
}
+void rsi_GetName(Context *rsc, void * obj, const char **name)
+{
+ ObjectBase *ob = static_cast<ObjectBase *>(obj);
+ (*name) = ob->getName();
+}
+
void rsi_ObjDestroy(Context *rsc, void *obj)
{
ObjectBase *ob = static_cast<ObjectBase *>(obj);
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index d1346fc..e58d8b1 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -259,6 +259,7 @@
mCurrentQuadIndex = 0;
mRSC = NULL;
mLibrary = NULL;
+ setFontColor(0.0f, 0.0f, 0.0f, 1.0f);
}
FontState::~FontState()
@@ -660,6 +661,14 @@
renderText(text, allocSize, start, len, x, y);
}
+void FontState::setFontColor(float r, float g, float b, float a) {
+ mFontColor[0] = r;
+ mFontColor[1] = g;
+ mFontColor[2] = b;
+ mFontColor[3] = a;
+ mFontColorDirty = true;
+}
+
void FontState::deinit(Context *rsc)
{
mInitialized = false;
diff --git a/libs/rs/rsFont.h b/libs/rs/rsFont.h
index e1a957a..2d9a34a 100644
--- a/libs/rs/rsFont.h
+++ b/libs/rs/rsFont.h
@@ -116,6 +116,8 @@
void renderText(Allocation *alloc, int x, int y);
void renderText(Allocation *alloc, uint32_t start, int len, int x, int y);
+ void setFontColor(float r, float g, float b, float a);
+
protected:
friend class Font;
@@ -151,6 +153,9 @@
Context *mRSC;
+ float mFontColor[4];
+ bool mFontColorDirty;
+
// Free type library, we only need one copy
FT_Library mLibrary;
FT_Library getLib();
diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp
index 06638ac..22b0945 100644
--- a/libs/rs/rsScriptC_LibGL.cpp
+++ b/libs/rs/rsScriptC_LibGL.cpp
@@ -332,6 +332,12 @@
rsi_ContextBindFont(rsc, font);
}
+static void SC_FontColor(float r, float g, float b, float a)
+{
+ GET_TLS();
+ rsc->mStateFont.setFontColor(r, g, b, a);
+}
+
//////////////////////////////////////////////////////////////////////////////
// Class implementation
//////////////////////////////////////////////////////////////////////////////
@@ -388,6 +394,7 @@
{ "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc },
{ "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont },
+ { "_Z12rsgFontColorffff", (void *)&SC_FontColor },
// misc
{ "_Z5colorffff", (void *)&SC_color },
diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh
index 8f89cba..4f53963 100644
--- a/libs/rs/scriptc/rs_graphics.rsh
+++ b/libs/rs/scriptc/rs_graphics.rsh
@@ -71,6 +71,8 @@
rsgDrawText(rs_allocation, int x, int y);
extern void __attribute__((overloadable))
rsgBindFont(rs_font);
+extern void __attribute__((overloadable))
+ rsgFontColor(float, float, float, float);
///////////////////////////////////////////////////////
// misc