summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2010-08-18 15:46:43 -0700
committerAlex Sakhartchouk <alexst@google.com>2010-08-18 15:46:43 -0700
commit27f50523a45100f3b4861762b6263e0b9ba6e22e (patch)
treeaec97923b179337917c09bdf09c5880417ca52d2
parent468c3230dafc2d131bdeded7b5a6825988166244 (diff)
downloadframeworks_base-27f50523a45100f3b4861762b6263e0b9ba6e22e.zip
frameworks_base-27f50523a45100f3b4861762b6263e0b9ba6e22e.tar.gz
frameworks_base-27f50523a45100f3b4861762b6263e0b9ba6e22e.tar.bz2
Renderscript samples. Merged two model related projects. Cleanup.
Change-Id: I6fdc70420eee7dfecf0b051fd687e5797c6580ce
-rw-r--r--graphics/java/android/renderscript/Font.java109
-rw-r--r--libs/rs/java/ModelViewer/AndroidManifest.xml8
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraph.java (renamed from libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraph.java)2
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java (renamed from libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraphRS.java)2
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphView.java (renamed from libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraphView.java)2
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/SgTransform.java (renamed from libs/rs/java/SceneGraph/src/com/android/scenegraph/SgTransform.java)2
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/scenegraph.rs (renamed from libs/rs/java/SceneGraph/src/com/android/scenegraph/scenegraph.rs)2
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/transform.rs (renamed from libs/rs/java/SceneGraph/src/com/android/scenegraph/transform.rs)2
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/transform_def.rsh (renamed from libs/rs/java/SceneGraph/src/com/android/scenegraph/transform_def.rsh)2
-rw-r--r--libs/rs/java/Samples/Android.mk (renamed from libs/rs/java/SceneGraph/Android.mk)2
-rw-r--r--libs/rs/java/Samples/AndroidManifest.xml (renamed from libs/rs/java/SceneGraph/AndroidManifest.xml)7
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsList.java71
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsListRS.java145
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsListView.java98
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/rslist.rs73
-rw-r--r--libs/rs/java/SceneGraph/res/drawable/robot.pngbin292580 -> 0 bytes
-rw-r--r--libs/rs/java/SceneGraph/res/raw/robot.a3dbin144500 -> 0 bytes
-rw-r--r--libs/rs/rsFont.cpp15
18 files changed, 523 insertions, 19 deletions
diff --git a/graphics/java/android/renderscript/Font.java b/graphics/java/android/renderscript/Font.java
index d79909e..de25014 100644
--- a/graphics/java/android/renderscript/Font.java
+++ b/graphics/java/android/renderscript/Font.java
@@ -18,6 +18,8 @@ package android.renderscript;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Map;
+import java.util.HashMap;
import android.content.res.Resources;
import android.content.res.AssetManager;
@@ -30,10 +32,100 @@ import android.util.TypedValue;
**/
public class Font extends BaseObj {
+ //These help us create a font by family name
+ private static final String[] sSansNames = {
+ "sans-serif", "arial", "helvetica", "tahoma", "verdana"
+ };
+
+ private static final String[] sSerifNames = {
+ "serif", "times", "times new roman", "palatino", "georgia", "baskerville",
+ "goudy", "fantasy", "cursive", "ITC Stone Serif"
+ };
+
+ private static final String[] sMonoNames = {
+ "monospace", "courier", "courier new", "monaco"
+ };
+
+ private static class FontFamily {
+ String[] mNames;
+ String mNormalFileName;
+ String mBoldFileName;
+ String mItalicFileName;
+ String mBoldItalicFileName;
+ }
+
+ private static Map<String, FontFamily> sFontFamilyMap;
+
+ public enum Style {
+ NORMAL,
+ BOLD,
+ ITALIC,
+ BOLD_ITALIC;
+ }
+
+ private static void addFamilyToMap(FontFamily family) {
+ for(int i = 0; i < family.mNames.length; i ++) {
+ sFontFamilyMap.put(family.mNames[i], family);
+ }
+ }
+
+ private static void initFontFamilyMap() {
+ sFontFamilyMap = new HashMap<String, FontFamily>();
+
+ FontFamily sansFamily = new FontFamily();
+ sansFamily.mNames = sSansNames;
+ sansFamily.mNormalFileName = "DroidSans.ttf";
+ sansFamily.mBoldFileName = "DroidSans-Bold.ttf";
+ sansFamily.mItalicFileName = "DroidSans.ttf";
+ sansFamily.mBoldItalicFileName = "DroidSans-Bold.ttf";
+ addFamilyToMap(sansFamily);
+
+ FontFamily serifFamily = new FontFamily();
+ serifFamily.mNames = sSerifNames;
+ serifFamily.mNormalFileName = "DroidSerif-Regular.ttf";
+ serifFamily.mBoldFileName = "DroidSerif-Bold.ttf";
+ serifFamily.mItalicFileName = "DroidSerif-Italic.ttf";
+ serifFamily.mBoldItalicFileName = "DroidSerif-BoldItalic.ttf";
+ addFamilyToMap(serifFamily);
+
+ FontFamily monoFamily = new FontFamily();
+ monoFamily.mNames = sMonoNames;
+ monoFamily.mNormalFileName = "DroidSansMono.ttf";
+ monoFamily.mBoldFileName = "DroidSansMono.ttf";
+ monoFamily.mItalicFileName = "DroidSansMono.ttf";
+ monoFamily.mBoldItalicFileName = "DroidSansMono.ttf";
+ addFamilyToMap(monoFamily);
+ }
+
+ static {
+ initFontFamilyMap();
+ }
+
+ static String getFontFileName(String familyName, Style style) {
+ FontFamily family = sFontFamilyMap.get(familyName);
+ if(family != null) {
+ switch(style) {
+ case NORMAL:
+ return family.mNormalFileName;
+ case BOLD:
+ return family.mBoldFileName;
+ case ITALIC:
+ return family.mItalicFileName;
+ case BOLD_ITALIC:
+ return family.mBoldItalicFileName;
+ }
+ }
+ // Fallback if we could not find the desired family
+ return "DroidSans.ttf";
+ }
+
Font(int id, RenderScript rs) {
super(id, rs);
}
+ /**
+ * Takes a specific file name as an argument
+ */
static public Font create(RenderScript rs, Resources res, String fileName, int size)
throws IllegalArgumentException {
@@ -43,7 +135,7 @@ public class Font extends BaseObj {
int fontId = rs.nFontCreateFromFile(fileName, size, dpi);
if(fontId == 0) {
- throw new IllegalStateException("Load loading a font");
+ throw new IllegalStateException("Failed loading a font");
}
Font rsFont = new Font(fontId, rs);
@@ -55,4 +147,19 @@ public class Font extends BaseObj {
return null;
}
+
+ /**
+ * Accepts one of the following family names as an argument
+ * and will attemp to produce the best match with a system font
+ * "sans-serif" "arial" "helvetica" "tahoma" "verdana"
+ * "serif" "times" "times new roman" "palatino" "georgia" "baskerville"
+ * "goudy" "fantasy" "cursive" "ITC Stone Serif"
+ * "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)
+ throws IllegalArgumentException {
+ String fileName = getFontFileName(familyName, fontStyle);
+ return create(rs, res, fileName, size);
+ }
}
diff --git a/libs/rs/java/ModelViewer/AndroidManifest.xml b/libs/rs/java/ModelViewer/AndroidManifest.xml
index ebbe743..39976d2 100644
--- a/libs/rs/java/ModelViewer/AndroidManifest.xml
+++ b/libs/rs/java/ModelViewer/AndroidManifest.xml
@@ -10,5 +10,13 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity android:name="SceneGraph"
+ android:label="SceneGraph"
+ android:theme="@android:style/Theme.Black.NoTitleBar">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
</application>
</manifest>
diff --git a/libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraph.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraph.java
index 5daa4ac..557e0cc 100644
--- a/libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraph.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraph.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.scenegraph;
+package com.android.modelviewer;
import android.renderscript.RSSurfaceView;
import android.renderscript.RenderScript;
diff --git a/libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraphRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java
index 3db4a2b..3f4d930 100644
--- a/libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraphRS.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.scenegraph;
+package com.android.modelviewer;
import java.io.Writer;
import java.util.Map;
diff --git a/libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraphView.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphView.java
index ae94869..44a59b2 100644
--- a/libs/rs/java/SceneGraph/src/com/android/scenegraph/SceneGraphView.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphView.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.scenegraph;
+package com.android.modelviewer;
import java.io.Writer;
import java.util.ArrayList;
diff --git a/libs/rs/java/SceneGraph/src/com/android/scenegraph/SgTransform.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SgTransform.java
index e81f1a7..bfc9bb7 100644
--- a/libs/rs/java/SceneGraph/src/com/android/scenegraph/SgTransform.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SgTransform.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.scenegraph;
+package com.android.modelviewer;
import java.io.Writer;
import java.util.Map;
diff --git a/libs/rs/java/SceneGraph/src/com/android/scenegraph/scenegraph.rs b/libs/rs/java/ModelViewer/src/com/android/modelviewer/scenegraph.rs
index e6ae6df..8053306 100644
--- a/libs/rs/java/SceneGraph/src/com/android/scenegraph/scenegraph.rs
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/scenegraph.rs
@@ -14,7 +14,7 @@
#pragma version(1)
-#pragma rs java_package_name(com.android.scenegraph)
+#pragma rs java_package_name(com.android.modelviewer)
#include "rs_graphics.rsh"
#include "transform_def.rsh"
diff --git a/libs/rs/java/SceneGraph/src/com/android/scenegraph/transform.rs b/libs/rs/java/ModelViewer/src/com/android/modelviewer/transform.rs
index a62d12b..7b9cd1c 100644
--- a/libs/rs/java/SceneGraph/src/com/android/scenegraph/transform.rs
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/transform.rs
@@ -14,7 +14,7 @@
#pragma version(1)
-#pragma rs java_package_name(com.android.scenegraph)
+#pragma rs java_package_name(com.android.modelviewer)
#include "transform_def.rsh"
diff --git a/libs/rs/java/SceneGraph/src/com/android/scenegraph/transform_def.rsh b/libs/rs/java/ModelViewer/src/com/android/modelviewer/transform_def.rsh
index 10aac37..a66e6c5 100644
--- a/libs/rs/java/SceneGraph/src/com/android/scenegraph/transform_def.rsh
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/transform_def.rsh
@@ -14,7 +14,7 @@
#pragma version(1)
-#pragma rs java_package_name(com.android.scenegraph)
+#pragma rs java_package_name(com.android.modelviewer)
#define TRANSFORM_NONE 0
#define TRANSFORM_TRANSLATE 1
diff --git a/libs/rs/java/SceneGraph/Android.mk b/libs/rs/java/Samples/Android.mk
index 5520446..65ae734 100644
--- a/libs/rs/java/SceneGraph/Android.mk
+++ b/libs/rs/java/Samples/Android.mk
@@ -24,7 +24,7 @@ LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
-LOCAL_PACKAGE_NAME := SceneGraph
+LOCAL_PACKAGE_NAME := Samples
include $(BUILD_PACKAGE)
diff --git a/libs/rs/java/SceneGraph/AndroidManifest.xml b/libs/rs/java/Samples/AndroidManifest.xml
index 8a8f87a..85d7547 100644
--- a/libs/rs/java/SceneGraph/AndroidManifest.xml
+++ b/libs/rs/java/Samples/AndroidManifest.xml
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.scenegraph">
- <application android:label="SceneGraph">
- <activity android:name="SceneGraph"
+ package="com.android.samples">
+ <application android:label="Samples">
+ <activity android:name="RsList"
+ android:label="RsList"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsList.java b/libs/rs/java/Samples/src/com/android/samples/RsList.java
new file mode 100644
index 0000000..d8c733d
--- /dev/null
+++ b/libs/rs/java/Samples/src/com/android/samples/RsList.java
@@ -0,0 +1,71 @@
+/*
+ * 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 com.android.samples;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.provider.Settings.System;
+import android.util.Config;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+import android.widget.Button;
+import android.widget.ListView;
+
+import java.lang.Runtime;
+
+public class RsList extends Activity {
+
+ private RsListView mView;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ // Create our Preview view and set it as the content of our
+ // Activity
+ mView = new RsListView(this);
+ setContentView(mView);
+ }
+
+ @Override
+ protected void onResume() {
+ // Ideally a game should implement onResume() and onPause()
+ // to take appropriate action when the activity looses focus
+ super.onResume();
+ mView.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ // Ideally a game should implement onResume() and onPause()
+ // to take appropriate action when the activity looses focus
+ super.onPause();
+ mView.onPause();
+ }
+
+}
+
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java
new file mode 100644
index 0000000..a782e0e
--- /dev/null
+++ b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java
@@ -0,0 +1,145 @@
+/*
+ * 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 com.android.samples;
+
+import java.io.Writer;
+import java.util.Vector;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.renderscript.ProgramStore.DepthFunc;
+import android.util.Log;
+
+
+public class RsListRS {
+
+ private final int STATE_LAST_FOCUS = 1;
+
+ private static final String[] DATA_LIST = {
+ "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
+ "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
+ "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
+ "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
+ "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
+ "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
+ "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria",
+ "Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
+ "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
+ "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
+ "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
+ "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
+ "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
+ "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
+ "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
+ "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
+ "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
+ "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
+ "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
+ "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
+ "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
+ "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
+ "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
+ "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
+ "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
+ "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
+ "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
+ "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
+ "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
+ "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
+ "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
+ "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
+ "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
+ "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
+ "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
+ "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
+ "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
+ "Ukraine", "United Arab Emirates", "United Kingdom",
+ "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
+ "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
+ "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
+ };
+
+ int mWidth;
+ int mHeight;
+
+ public RsListRS() {
+ }
+
+ public void init(RenderScriptGL rs, Resources res, int width, int height) {
+ mRS = rs;
+ mRes = res;
+ mWidth = width;
+ mHeight = height;
+ initRS();
+ }
+
+ private Resources mRes;
+ private RenderScriptGL mRS;
+ private Font mItalic;
+
+ ScriptField_ListAllocs_s mListAllocs;
+
+ private ScriptC_Rslist mScript;
+
+ int mLastX;
+ int mLastY;
+
+ public void onActionDown(int x, int y) {
+ mScript.set_gDY(0.0f);
+
+ mLastX = x;
+ mLastY = y;
+ }
+
+ public void onActionMove(int x, int y) {
+ int dx = mLastX - x;
+ int dy = mLastY - y;
+
+ if(Math.abs(dy) <= 2) {
+ dy = 0;
+ }
+
+ mScript.set_gDY(dy);
+
+ mLastX = x;
+ mLastY = y;
+ }
+
+ private void initRS() {
+
+ mScript = new ScriptC_Rslist(mRS, mRes, R.raw.rslist, true);
+
+ mListAllocs = new ScriptField_ListAllocs_s(mRS, DATA_LIST.length);
+ for(int i = 0; i < DATA_LIST.length; i ++) {
+ ScriptField_ListAllocs_s.Item listElem = new ScriptField_ListAllocs_s.Item();
+ listElem.text = Allocation.createFromString(mRS, DATA_LIST[i]);
+ mListAllocs.set(listElem, i, false);
+ }
+
+ mListAllocs.copyAll();
+
+ mScript.bind_gList(mListAllocs);
+
+ mItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
+ mScript.set_gItalic(mItalic);
+
+ mRS.contextBindRootScript(mScript);
+ }
+}
+
+
+
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListView.java b/libs/rs/java/Samples/src/com/android/samples/RsListView.java
new file mode 100644
index 0000000..b98ea08
--- /dev/null
+++ b/libs/rs/java/Samples/src/com/android/samples/RsListView.java
@@ -0,0 +1,98 @@
+/*
+ * 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 com.android.samples;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.concurrent.Semaphore;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+import android.renderscript.RenderScriptGL;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.Handler;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+
+public class RsListView extends RSSurfaceView {
+
+ public RsListView(Context context) {
+ super(context);
+ //setFocusable(true);
+ }
+
+ private RenderScriptGL mRS;
+ private RsListRS mRender;
+
+
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ super.surfaceChanged(holder, format, w, h);
+ if (mRS == null) {
+ mRS = createRenderScript(true);
+ mRS.contextSetSurface(w, h, holder.getSurface());
+ mRender = new RsListRS();
+ mRender.init(mRS, getResources(), w, h);
+ }
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ if(mRS != null) {
+ mRS = null;
+ destroyRenderScript();
+ }
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event)
+ {
+ // break point at here
+ // this method doesn't work when 'extends View' include 'extends ScrollView'.
+ return super.onKeyDown(keyCode, event);
+ }
+
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev)
+ {
+ boolean ret = false;
+ int act = ev.getAction();
+ if (act == ev.ACTION_DOWN) {
+ mRender.onActionDown((int)ev.getX(), (int)ev.getY());
+ ret = true;
+ }
+ else if (act == ev.ACTION_MOVE) {
+ mRender.onActionMove((int)ev.getX(), (int)ev.getY());
+ ret = true;
+ }
+
+ return ret;
+ }
+}
+
+
diff --git a/libs/rs/java/Samples/src/com/android/samples/rslist.rs b/libs/rs/java/Samples/src/com/android/samples/rslist.rs
new file mode 100644
index 0000000..3c3f463
--- /dev/null
+++ b/libs/rs/java/Samples/src/com/android/samples/rslist.rs
@@ -0,0 +1,73 @@
+// Copyright (C) 2009 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.
+
+#pragma version(1)
+
+#pragma rs java_package_name(com.android.samples)
+
+#include "rs_graphics.rsh"
+
+float gDY;
+
+rs_font gItalic;
+
+typedef struct ListAllocs_s {
+ rs_allocation text;
+} ListAllocs;
+
+ListAllocs *gList;
+
+#pragma rs export_var(gDY, gItalic, gList)
+
+void init() {
+ gDY = 0.0f;
+}
+
+int textPos = 0;
+
+int root(int launchID) {
+
+ rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ rsgClearDepth(1.0f);
+
+ textPos -= (int)gDY*2;
+ gDY *= 0.95;
+
+ rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
+ rsgBindFont(gItalic);
+ color(0.2, 0.2, 0.2, 0);
+
+ rs_allocation listAlloc = rsGetAllocation(gList);
+ int allocSize = rsAllocationGetDimX(listAlloc);
+
+ int width = rsgGetWidth();
+ int height = rsgGetHeight();
+
+ int itemHeight = 80;
+ int currentYPos = itemHeight + textPos;
+
+ for(int i = 0; i < allocSize; i ++) {
+ if(currentYPos - itemHeight > height) {
+ break;
+ }
+
+ if(currentYPos > 0) {
+ rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0);
+ rsgDrawText(gList[i].text, 30, currentYPos - 32);
+ }
+ currentYPos += itemHeight;
+ }
+
+ return 10;
+}
diff --git a/libs/rs/java/SceneGraph/res/drawable/robot.png b/libs/rs/java/SceneGraph/res/drawable/robot.png
deleted file mode 100644
index f7353fd..0000000
--- a/libs/rs/java/SceneGraph/res/drawable/robot.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/SceneGraph/res/raw/robot.a3d b/libs/rs/java/SceneGraph/res/raw/robot.a3d
deleted file mode 100644
index 2d7d32b..0000000
--- a/libs/rs/java/SceneGraph/res/raw/robot.a3d
+++ /dev/null
Binary files differ
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index 1ef9c93..7661d49 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -218,6 +218,7 @@ Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph)
Font * Font::create(Context *rsc, const char *name, uint32_t fontSize, uint32_t dpi)
{
+ rsc->mStateFont.checkInit();
Vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts;
for(uint32_t i = 0; i < activeFonts.size(); i ++) {
@@ -513,6 +514,12 @@ void FontState::checkInit()
initVertexArrayBuffers();
+ // We store a string with letters in a rough frequency of occurrence
+ mLatinPrecache = String8(" eisarntolcdugpmhbyfvkwzxjq");
+ mLatinPrecache += String8("EISARNTOLCDUGPMHBYFVKWZXJQ");
+ mLatinPrecache += String8(",.?!()-+@;:`'");
+ mLatinPrecache += String8("0123456789");
+
mInitialized = true;
}
@@ -622,7 +629,7 @@ void FontState::appendMeshQuad(float x1, float y1, float z1,
uint32_t FontState::getRemainingCacheCapacity() {
uint32_t remainingCapacity = 0;
- float totalPixels = 0;
+ uint32_t totalPixels = 0;
for(uint32_t i = 0; i < mCacheLines.size(); i ++) {
remainingCapacity += (mCacheLines[i]->mMaxWidth - mCacheLines[i]->mCurrentCol);
totalPixels += mCacheLines[i]->mMaxWidth;
@@ -666,12 +673,6 @@ void FontState::renderText(const char *text, uint32_t len, uint32_t startIndex,
issueDrawCommand();
mCurrentQuadIndex = 0;
}
-
- // We store a string with letters in a rough frequency of occurrence
- mLatinPrecache = String8(" eisarntolcdugpmhbyfvkwzxjq");
- mLatinPrecache += String8("EISARNTOLCDUGPMHBYFVKWZXJQ");
- mLatinPrecache += String8(",.?!()-+@;:`'");
- mLatinPrecache += String8("0123456789");
}
void FontState::renderText(const char *text, int x, int y)