diff options
author | Alex Sakhartchouk <alexst@google.com> | 2010-12-17 11:41:08 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2010-12-17 11:41:08 -0800 |
commit | e27cdeeecba5b445e307d653d9cb7da007adfac3 (patch) | |
tree | 2bd196f42ef3d904c610f2b327642391a6724e20 | |
parent | 60e41fa4456ce6bc37a33b1e4b81a56e9411199b (diff) | |
download | frameworks_base-e27cdeeecba5b445e307d653d9cb7da007adfac3.zip frameworks_base-e27cdeeecba5b445e307d653d9cb7da007adfac3.tar.gz frameworks_base-e27cdeeecba5b445e307d653d9cb7da007adfac3.tar.bz2 |
API reaview cleanup
Change-Id: Ib1aaf81130ffa6b5e6c60096c27c969e8891db3f
17 files changed, 186 insertions, 120 deletions
diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java index ff3e22b..ed16451 100644 --- a/graphics/java/android/renderscript/FieldPacker.java +++ b/graphics/java/android/renderscript/FieldPacker.java @@ -248,24 +248,45 @@ public class FieldPacker { addU32(v.w); } + // to be removed on cleanup public void addObj(Matrix4f v) { for (int i=0; i < v.mMat.length; i++) { addF32(v.mMat[i]); } } + // to be removed on cleanup public void addObj(Matrix3f v) { for (int i=0; i < v.mMat.length; i++) { addF32(v.mMat[i]); } } + // to be removed on cleanup public void addObj(Matrix2f v) { for (int i=0; i < v.mMat.length; i++) { addF32(v.mMat[i]); } } + public void addMatrix(Matrix4f v) { + for (int i=0; i < v.mMat.length; i++) { + addF32(v.mMat[i]); + } + } + + public void addMatrix(Matrix3f v) { + for (int i=0; i < v.mMat.length; i++) { + addF32(v.mMat[i]); + } + } + + public void addMatrix(Matrix2f v) { + for (int i=0; i < v.mMat.length; i++) { + addF32(v.mMat[i]); + } + } + public void addBoolean(boolean v) { addI8((byte)(v ? 1 : 0)); } diff --git a/graphics/java/android/renderscript/FileA3D.java b/graphics/java/android/renderscript/FileA3D.java index af85d8e..c3e5faf 100644 --- a/graphics/java/android/renderscript/FileA3D.java +++ b/graphics/java/android/renderscript/FileA3D.java @@ -16,11 +16,12 @@ package android.renderscript; +import java.io.File; import java.io.IOException; import java.io.InputStream; -import android.content.res.Resources; import android.content.res.AssetManager; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; @@ -32,28 +33,33 @@ import android.util.TypedValue; **/ public class FileA3D extends BaseObj { + // This will go away in the clean up pass, + // trying to avoid multiproject submits public enum ClassID { UNKNOWN, - MESH, - TYPE, - ELEMENT, - ALLOCATION, - PROGRAM_VERTEX, - PROGRAM_RASTER, - PROGRAM_FRAGMENT, - PROGRAM_STORE, - SAMPLER, - ANIMATION, - ADAPTER_1D, - ADAPTER_2D, - SCRIPT_C; + MESH; public static ClassID toClassID(int intID) { return ClassID.values()[intID]; } } + public enum EntryType { + + UNKNOWN (0), + MESH (1); + + int mID; + EntryType(int id) { + mID = id; + } + + static EntryType toEntryType(int intID) { + return EntryType.values()[intID]; + } + } + // Read only class with index entries public static class IndexEntry { RenderScript mRS; @@ -61,6 +67,7 @@ public class FileA3D extends BaseObj { int mID; String mName; ClassID mClassID; + EntryType mEntryType; BaseObj mLoadedObj; public String getName() { @@ -71,18 +78,27 @@ public class FileA3D extends BaseObj { return mClassID; } + public EntryType getEntryType() { + return mEntryType; + } + public BaseObj getObject() { mRS.validate(); BaseObj obj = internalCreate(mRS, this); return obj; } + public Mesh getMesh() { + return (Mesh)getObject(); + } + static synchronized BaseObj internalCreate(RenderScript rs, IndexEntry entry) { if(entry.mLoadedObj != null) { return entry.mLoadedObj; } - if(entry.mClassID == ClassID.UNKNOWN) { + // to be purged on cleanup + if(entry.mEntryType == EntryType.UNKNOWN) { return null; } @@ -91,51 +107,23 @@ public class FileA3D extends BaseObj { return null; } - switch (entry.mClassID) { + switch (entry.mEntryType) { case MESH: entry.mLoadedObj = new Mesh(objectID, rs); break; - case TYPE: - entry.mLoadedObj = new Type(objectID, rs); - break; - case ELEMENT: - entry.mLoadedObj = null; - break; - case ALLOCATION: - entry.mLoadedObj = null; - break; - case PROGRAM_VERTEX: - entry.mLoadedObj = new ProgramVertex(objectID, rs); - break; - case PROGRAM_RASTER: - break; - case PROGRAM_FRAGMENT: - break; - case PROGRAM_STORE: - break; - case SAMPLER: - break; - case ANIMATION: - break; - case ADAPTER_1D: - break; - case ADAPTER_2D: - break; - case SCRIPT_C: - break; } entry.mLoadedObj.updateFromNative(); - return entry.mLoadedObj; } - IndexEntry(RenderScript rs, int index, int id, String name, ClassID classID) { + IndexEntry(RenderScript rs, int index, int id, String name, EntryType type) { mRS = rs; mIndex = index; mID = id; mName = name; - mClassID = classID; + mEntryType = type; + mClassID = mEntryType == EntryType.MESH ? ClassID.MESH : ClassID.UNKNOWN; mLoadedObj = null; } } @@ -161,11 +149,11 @@ public class FileA3D extends BaseObj { mRS.nFileA3DGetIndexEntries(getID(), numFileEntries, ids, names); for(int i = 0; i < numFileEntries; i ++) { - mFileEntries[i] = new IndexEntry(mRS, i, getID(), names[i], ClassID.toClassID(ids[i])); + mFileEntries[i] = new IndexEntry(mRS, i, getID(), names[i], EntryType.toEntryType(ids[i])); } } - public int getNumIndexEntries() { + public int getIndexEntryCount() { if(mFileEntries == null) { return 0; } @@ -173,12 +161,29 @@ public class FileA3D extends BaseObj { } public IndexEntry getIndexEntry(int index) { - if(getNumIndexEntries() == 0 || index < 0 || index >= mFileEntries.length) { + if(getIndexEntryCount() == 0 || index < 0 || index >= mFileEntries.length) { return null; } return mFileEntries[index]; } + // API cleanup stand-ins + // TODO: implement ermaining loading mechanisms + static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path) + throws IllegalArgumentException { + return null; + } + + static public FileA3D createFromFile(RenderScript rs, String path) + throws IllegalArgumentException { + return null; + } + + static public FileA3D createFromFile(RenderScript rs, File path) + throws IllegalArgumentException { + return createFromFile(rs, path.getAbsolutePath()); + } + static public FileA3D createFromResource(RenderScript rs, Resources res, int id) throws IllegalArgumentException { diff --git a/graphics/java/android/renderscript/Font.java b/graphics/java/android/renderscript/Font.java index de25014..0f7c24d 100644 --- a/graphics/java/android/renderscript/Font.java +++ b/graphics/java/android/renderscript/Font.java @@ -16,13 +16,16 @@ package android.renderscript; +import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import java.util.HashMap; +import java.util.Map; + +import android.os.Environment; -import android.content.res.Resources; import android.content.res.AssetManager; +import android.content.res.Resources; import android.util.Log; import android.util.TypedValue; @@ -126,13 +129,13 @@ public class Font extends BaseObj { /** * Takes a specific file name as an argument */ - static public Font create(RenderScript rs, Resources res, String fileName, int size) + static public Font createFromFile(RenderScript rs, Resources res, String path, float pointSize) throws IllegalArgumentException { rs.validate(); try { int dpi = res.getDisplayMetrics().densityDpi; - int fontId = rs.nFontCreateFromFile(fileName, size, dpi); + int fontId = rs.nFontCreateFromFile(path, pointSize, dpi); if(fontId == 0) { throw new IllegalStateException("Failed loading a font"); @@ -148,6 +151,21 @@ public class Font extends BaseObj { return null; } + static public Font createFromFile(RenderScript rs, Resources res, File path, float pointSize) + throws IllegalArgumentException { + return createFromFile(rs, res, path.getAbsolutePath(), pointSize); + } + + static public Font createFromAsset(RenderScript rs, Resources res, AssetManager mgr, String path, float pointSize) + throws IllegalArgumentException { + return null; + } + + static public Font createFromResource(RenderScript rs, Resources res, int id, float pointSize) + throws IllegalArgumentException { + return null; + } + /** * Accepts one of the following family names as an argument * and will attemp to produce the best match with a system font @@ -157,9 +175,12 @@ public class Font extends BaseObj { * "monospace" "courier" "courier new" "monaco" * Returns default font if no match could be found */ - static public Font createFromFamily(RenderScript rs, Resources res, String familyName, Style fontStyle, int size) + static public Font create(RenderScript rs, Resources res, String familyName, Style fontStyle, float pointSize) throws IllegalArgumentException { String fileName = getFontFileName(familyName, fontStyle); - return create(rs, res, fileName, size); + String fontPath = Environment.getRootDirectory().getAbsolutePath(); + fontPath += "/fonts/" + fileName; + return createFromFile(rs, res, fontPath, pointSize); } + } diff --git a/graphics/java/android/renderscript/Matrix2f.java b/graphics/java/android/renderscript/Matrix2f.java index 99d23db..4654c48 100644 --- a/graphics/java/android/renderscript/Matrix2f.java +++ b/graphics/java/android/renderscript/Matrix2f.java @@ -31,6 +31,15 @@ public class Matrix2f { loadIdentity(); } + public Matrix2f(float[] dataArray) { + mMat = new float[2]; + System.arraycopy(dataArray, 0, mMat, 0, mMat.length); + } + + public float[] getArray() { + return mMat; + } + public float get(int i, int j) { return mMat[i*2 + j]; } diff --git a/graphics/java/android/renderscript/Matrix3f.java b/graphics/java/android/renderscript/Matrix3f.java index 961bc5d..15e5ce6 100644 --- a/graphics/java/android/renderscript/Matrix3f.java +++ b/graphics/java/android/renderscript/Matrix3f.java @@ -31,6 +31,15 @@ public class Matrix3f { loadIdentity(); } + public Matrix3f(float[] dataArray) { + mMat = new float[9]; + System.arraycopy(dataArray, 0, mMat, 0, mMat.length); + } + + public float[] getArray() { + return mMat; + } + public float get(int i, int j) { return mMat[i*3 + j]; } diff --git a/graphics/java/android/renderscript/Matrix4f.java b/graphics/java/android/renderscript/Matrix4f.java index 5ffc21a..ea97509 100644 --- a/graphics/java/android/renderscript/Matrix4f.java +++ b/graphics/java/android/renderscript/Matrix4f.java @@ -31,6 +31,15 @@ public class Matrix4f { loadIdentity(); } + public Matrix4f(float[] dataArray) { + mMat = new float[16]; + System.arraycopy(dataArray, 0, mMat, 0, mMat.length); + } + + public float[] getArray() { + return mMat; + } + public float get(int i, int j) { return mMat[i*4 + j]; } @@ -147,6 +156,10 @@ public class Matrix4f { mMat[14]= -(f + n) / (f - n); } + public void loadOrthoWindow(int w, int h) { + loadOrtho(0,w, h,0, -1,1); + } + public void loadFrustum(float l, float r, float b, float t, float n, float f) { loadIdentity(); mMat[0] = 2 * n / (r - l); @@ -159,6 +172,14 @@ public class Matrix4f { mMat[15]= 0; } + public void loadPerspective(float fovy, float aspect, float near, float far) { + float top = near * (float)Math.tan((float) (fovy * Math.PI / 360.0f)); + float bottom = -top; + float left = bottom * aspect; + float right = top * aspect; + loadFrustum(left, right, bottom, top, near, far); + } + public void multiply(Matrix4f rhs) { Matrix4f tmp = new Matrix4f(); tmp.loadMultiply(this, rhs); diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 5f93f5b..0b7262b 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -305,8 +305,8 @@ public class RenderScript { return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index); } - native int rsnFontCreateFromFile(int con, String fileName, int size, int dpi); - synchronized int nFontCreateFromFile(String fileName, int size, int dpi) { + native int rsnFontCreateFromFile(int con, String fileName, float size, int dpi); + synchronized int nFontCreateFromFile(String fileName, float size, int dpi) { return rsnFontCreateFromFile(mContext, fileName, size, dpi); } diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index a8343b3..493653a 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -623,7 +623,7 @@ nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D // ----------------------------------- static int -nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName, jint fontSize, jint dpi) +nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName, jfloat fontSize, jint dpi) { const char* fileNameUTF = _env->GetStringUTFChars(fileName, NULL); @@ -1239,7 +1239,7 @@ static JNINativeMethod methods[] = { {"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, {"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex }, -{"rsnFontCreateFromFile", "(ILjava/lang/String;II)I", (void*)nFontCreateFromFile }, +{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile }, {"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, {"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 }, diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java index 6cb50b8..7d99686 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java @@ -23,6 +23,7 @@ import java.util.Vector; import android.content.res.Resources; import android.renderscript.*; import android.renderscript.Element.Builder; +import android.renderscript.Font.Style; import android.renderscript.ProgramStore.DepthFunc; import android.util.Log; @@ -186,22 +187,20 @@ public class SceneGraphRS { FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot); FileA3D.IndexEntry entry = model.getIndexEntry(0); - if (entry == null || entry.getClassID() != FileA3D.ClassID.MESH) { + if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) { Log.e("rs", "could not load model"); } else { mMesh = (Mesh)entry.getObject(); mScript.set_gTestMesh(mMesh); } - mItalic = Font.create(mRS, mRes, "DroidSerif-Italic.ttf", 8); + mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8); mScript.set_gItalic(mItalic); initTextAllocation(); initTransformHierarchy(); - Log.v("========SceneGraph========", "transform hierarchy initialized"); - mScript.bind_gRootNode(mRootTransform.getField()); mScript.bind_gGroup(mGroup1.mParent.mChildField); diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java index 747463a..5451ca1 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java @@ -148,14 +148,14 @@ public class SimpleModelRS { FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot); FileA3D.IndexEntry entry = model.getIndexEntry(0); - if (entry == null || entry.getClassID() != FileA3D.ClassID.MESH) { + if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) { Log.e("rs", "could not load model"); } else { mMesh = (Mesh)entry.getObject(); mScript.set_gTestMesh(mMesh); } - mItalic = Font.create(mRS, mRes, "DroidSerif-Italic.ttf", 8); + mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8); mScript.set_gItalic(mItalic); initTextAllocation(); diff --git a/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java b/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java index ddb05b3..b3e8026 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java @@ -315,22 +315,15 @@ public class RsBenchRS { private void initFonts() { // Sans font by family name - mFontSans = Font.createFromFamily(mRS, mRes, "sans-serif", - Font.Style.NORMAL, 8); - // Create font by file name - mFontSerif = Font.create(mRS, mRes, "DroidSerif-Regular.ttf", 8); + mFontSans = Font.create(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8); + mFontSerif = Font.create(mRS, mRes, "serif", Font.Style.NORMAL, 8); // Create fonts by family and style - mFontSerifBold = Font.createFromFamily(mRS, mRes, "serif", - Font.Style.BOLD, 8); - mFontSerifItalic = Font.createFromFamily(mRS, mRes, "serif", - Font.Style.ITALIC, 8); - mFontSerifBoldItalic = Font.createFromFamily(mRS, mRes, "serif", - Font.Style.BOLD_ITALIC, 8); - mFontMono = Font.createFromFamily(mRS, mRes, "mono", - Font.Style.NORMAL, 8); - - mTextAlloc = Allocation.createFromString(mRS, "String from allocation", - Allocation.USAGE_SCRIPT); + mFontSerifBold = Font.create(mRS, mRes, "serif", Font.Style.BOLD, 8); + mFontSerifItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8); + mFontSerifBoldItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8); + mFontMono = Font.create(mRS, mRes, "mono", Font.Style.NORMAL, 8); + + mTextAlloc = Allocation.createFromString(mRS, "String from allocation", Allocation.USAGE_SCRIPT); mScript.set_gFontSans(mFontSans); mScript.set_gFontSerif(mFontSerif); @@ -351,7 +344,7 @@ public class RsBenchRS { FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus); FileA3D.IndexEntry entry = model.getIndexEntry(0); - if (entry == null || entry.getClassID() != FileA3D.ClassID.MESH) { + if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) { Log.e("rs", "could not load model"); } else { mTorus = (Mesh)entry.getObject(); diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java index 223f552..8e2d51f 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java @@ -134,7 +134,7 @@ public class RsListRS { mScript.bind_gList(mListAllocs); - mItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8); + mItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8); mScript.set_gItalic(mItalic); mRS.bindRootScript(mScript); diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java index 75e8d99..636a486 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java @@ -23,6 +23,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.renderscript.*; import android.renderscript.Allocation.CubemapLayout; +import android.renderscript.Font.Style; import android.renderscript.Program.TextureType; import android.renderscript.ProgramStore.DepthFunc; import android.renderscript.Sampler.Value; @@ -304,14 +305,13 @@ public class RsRenderStatesRS { private void initFonts() { // Sans font by family name - mFontSans = Font.createFromFamily(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8); - // Create font by file name - mFontSerif = Font.create(mRS, mRes, "DroidSerif-Regular.ttf", 8); + mFontSans = Font.create(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8); + mFontSerif = Font.create(mRS, mRes, "serif", Font.Style.NORMAL, 8); // Create fonts by family and style - mFontSerifBold = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD, 8); - mFontSerifItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.ITALIC, 8); - mFontSerifBoldItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8); - mFontMono = Font.createFromFamily(mRS, mRes, "mono", Font.Style.NORMAL, 8); + mFontSerifBold = Font.create(mRS, mRes, "serif", Font.Style.BOLD, 8); + mFontSerifItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8); + mFontSerifBoldItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8); + mFontMono = Font.create(mRS, mRes, "mono", Font.Style.NORMAL, 8); mTextAlloc = Allocation.createFromString(mRS, "String from allocation", Allocation.USAGE_SCRIPT); @@ -330,7 +330,7 @@ public class RsRenderStatesRS { FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus); FileA3D.IndexEntry entry = model.getIndexEntry(0); - if (entry == null || entry.getClassID() != FileA3D.ClassID.MESH) { + if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) { Log.e("rs", "could not load model"); } else { mTorus = (Mesh)entry.getObject(); diff --git a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java index 265e1d6..a50321e 100644 --- a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java +++ b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java @@ -94,7 +94,7 @@ public class RSTestCore { mScript.bind_gList(mListAllocs); - mFont = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD, 8); + mFont = Font.create(mRS, mRes, "serif", Font.Style.BOLD, 8); mScript.set_gFont(mFont); mRS.bindRootScript(mScript); diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 5daba08..cf94060 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -420,7 +420,7 @@ FileOpen { FontCreateFromFile { param const char *name - param uint32_t fontSize + param float fontSize param uint32_t dpi ret RsFont } diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp index 2fa1f0a..80bca43 100644 --- a/libs/rs/rsFont.cpp +++ b/libs/rs/rsFont.cpp @@ -40,20 +40,15 @@ Font::Font(Context *rsc) : ObjectBase(rsc), mCachedGlyphs(NULL) { mFace = NULL; } -bool Font::init(const char *name, uint32_t fontSize, uint32_t dpi) { +bool Font::init(const char *name, float fontSize, uint32_t dpi) { if (mInitialized) { LOGE("Reinitialization of fonts not supported"); return false; } - String8 fontsDir("/fonts/"); - String8 fullPath(getenv("ANDROID_ROOT")); - fullPath += fontsDir; - fullPath += name; - - FT_Error error = FT_New_Face(mRSC->mStateFont.getLib(), fullPath.string(), 0, &mFace); + FT_Error error = FT_New_Face(mRSC->mStateFont.getLib(), name, 0, &mFace); if (error) { - LOGE("Unable to initialize font %s", fullPath.string()); + LOGE("Unable to initialize font %s", name); return false; } @@ -61,9 +56,9 @@ bool Font::init(const char *name, uint32_t fontSize, uint32_t dpi) { mFontSize = fontSize; mDpi = dpi; - error = FT_Set_Char_Size(mFace, fontSize * 64, 0, dpi, 0); + error = FT_Set_Char_Size(mFace, (FT_F26Dot6)(fontSize * 64.0f), 0, dpi, 0); if (error) { - LOGE("Unable to set font size on %s", fullPath.string()); + LOGE("Unable to set font size on %s", name); return false; } @@ -278,7 +273,7 @@ Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) { return newGlyph; } -Font * Font::create(Context *rsc, const char *name, uint32_t fontSize, uint32_t dpi) { +Font * Font::create(Context *rsc, const char *name, float fontSize, uint32_t dpi) { rsc->mStateFont.checkInit(); Vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts; @@ -332,31 +327,20 @@ FontState::FontState() { // Get the gamma float gamma = DEFAULT_TEXT_GAMMA; if (property_get(PROPERTY_TEXT_GAMMA, property, NULL) > 0) { - LOGD(" Setting text gamma to %s", property); gamma = atof(property); - } else { - LOGD(" Using default text gamma of %.2f", DEFAULT_TEXT_GAMMA); } // Get the black gamma threshold int32_t blackThreshold = DEFAULT_TEXT_BLACK_GAMMA_THRESHOLD; if (property_get(PROPERTY_TEXT_BLACK_GAMMA_THRESHOLD, property, NULL) > 0) { - LOGD(" Setting text black gamma threshold to %s", property); blackThreshold = atoi(property); - } else { - LOGD(" Using default text black gamma threshold of %d", - DEFAULT_TEXT_BLACK_GAMMA_THRESHOLD); } mBlackThreshold = (float)(blackThreshold) / 255.0f; // Get the white gamma threshold int32_t whiteThreshold = DEFAULT_TEXT_WHITE_GAMMA_THRESHOLD; if (property_get(PROPERTY_TEXT_WHITE_GAMMA_THRESHOLD, property, NULL) > 0) { - LOGD(" Setting text white gamma threshold to %s", property); whiteThreshold = atoi(property); - } else { - LOGD(" Using default white black gamma threshold of %d", - DEFAULT_TEXT_WHITE_GAMMA_THRESHOLD); } mWhiteThreshold = (float)(whiteThreshold) / 255.0f; @@ -735,7 +719,11 @@ void FontState::renderText(const char *text, uint32_t len, int32_t x, int32_t y, Font *currentFont = mRSC->getFont(); if (!currentFont) { if (!mDefault.get()) { - mDefault.set(Font::create(mRSC, "DroidSans.ttf", 16, 96)); + String8 fontsDir("/fonts/DroidSans.ttf"); + String8 fullPath(getenv("ANDROID_ROOT")); + fullPath += fontsDir; + + mDefault.set(Font::create(mRSC, fullPath.string(), 16, 96)); } currentFont = mDefault.get(); } @@ -815,7 +803,7 @@ void FontState::deinit(Context *rsc) { namespace android { namespace renderscript { -RsFont rsi_FontCreateFromFile(Context *rsc, char const *name, uint32_t fontSize, uint32_t dpi) { +RsFont rsi_FontCreateFromFile(Context *rsc, char const *name, float fontSize, uint32_t dpi) { Font *newFont = Font::create(rsc, name, fontSize, dpi); if (newFont) { newFont->incUserRef(); diff --git a/libs/rs/rsFont.h b/libs/rs/rsFont.h index 0f6815d..c24c9f1 100644 --- a/libs/rs/rsFont.h +++ b/libs/rs/rsFont.h @@ -73,7 +73,7 @@ public: return RS_A3D_CLASS_ID_UNKNOWN; } - static Font * create(Context *rsc, const char *name, uint32_t fontSize, uint32_t dpi); + static Font * create(Context *rsc, const char *name, float fontSize, uint32_t dpi); protected: @@ -112,11 +112,11 @@ protected: }; String8 mFontName; - uint32_t mFontSize; + float mFontSize; uint32_t mDpi; Font(Context *rsc); - bool init(const char *name, uint32_t fontSize, uint32_t dpi); + bool init(const char *name, float fontSize, uint32_t dpi); FT_Face mFace; bool mInitialized; |