Merge "Fix bug 4521549 - Crash in ScrollingTabContainerView, when using a tab with null text"
diff --git a/api/current.txt b/api/current.txt
index eb02ea6a..7c9c851 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5821,6 +5821,8 @@
field public static final java.lang.String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
field public static final java.lang.String FEATURE_MICROPHONE = "android.hardware.microphone";
field public static final java.lang.String FEATURE_NFC = "android.hardware.nfc";
+ field public static final java.lang.String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
+ field public static final java.lang.String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
field public static final java.lang.String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
field public static final java.lang.String FEATURE_SENSOR_BAROMETER = "android.hardware.sensor.barometer";
field public static final java.lang.String FEATURE_SENSOR_COMPASS = "android.hardware.sensor.compass";
@@ -8510,11 +8512,11 @@
method public int getMinimumWidth();
method public abstract int getOpacity();
method public boolean getPadding(android.graphics.Rect);
+ method public int getResolvedLayoutDirectionSelf();
method public int[] getState();
method public android.graphics.Region getTransparentRegion();
method public void inflate(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public void invalidateSelf();
- method public boolean isLayoutRtlSelf();
method public boolean isStateful();
method public final boolean isVisible();
method public void jumpToCurrentState();
@@ -8546,7 +8548,7 @@
}
public static abstract interface Drawable.Callback2 implements android.graphics.drawable.Drawable.Callback {
- method public abstract boolean isLayoutRtl(android.graphics.drawable.Drawable);
+ method public abstract int getResolvedLayoutDirection(android.graphics.drawable.Drawable);
}
public static abstract class Drawable.ConstantState {
@@ -20581,7 +20583,7 @@
method public static void apply(int, int, int, android.graphics.Rect, android.graphics.Rect);
method public static void apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect);
method public static void applyDisplay(int, android.graphics.Rect, android.graphics.Rect);
- method public static int getAbsoluteGravity(int, boolean);
+ method public static int getAbsoluteGravity(int, int);
method public static boolean isHorizontal(int);
method public static boolean isVertical(int);
field public static final int AXIS_CLIP = 8; // 0x8
@@ -21564,8 +21566,12 @@
ctor public TextureView(android.content.Context, android.util.AttributeSet);
ctor public TextureView(android.content.Context, android.util.AttributeSet, int);
method public final void draw(android.graphics.Canvas);
+ method public android.graphics.Bitmap getBitmap();
+ method public android.graphics.Bitmap getBitmap(int, int);
+ method public android.graphics.Bitmap getBitmap(android.graphics.Bitmap);
method public android.graphics.SurfaceTexture getSurfaceTexture();
method public android.view.TextureView.SurfaceTextureListener getSurfaceTextureListener();
+ method public boolean isAvailable();
method protected final void onDraw(android.graphics.Canvas);
method public void setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener);
}
@@ -21722,6 +21728,7 @@
method public final android.view.ViewParent getParent();
method public float getPivotX();
method public float getPivotY();
+ method public int getResolvedLayoutDirection(android.graphics.drawable.Drawable);
method public android.content.res.Resources getResources();
method public final int getRight();
method protected float getRightFadingEdgeStrength();
@@ -21787,8 +21794,6 @@
method public boolean isInEditMode();
method public boolean isInTouchMode();
method public boolean isLayoutRequested();
- method public boolean isLayoutRtl();
- method public boolean isLayoutRtl(android.graphics.drawable.Drawable);
method public boolean isLongClickable();
method public boolean isOpaque();
method protected boolean isPaddingOffsetRequired();
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java
index f2be9ad..557c871 100644
--- a/core/java/android/app/Fragment.java
+++ b/core/java/android/app/Fragment.java
@@ -244,12 +244,12 @@
* on {@link ListFragment} for most of its work. Note the implementation of
* clicking an item: depending on the current activity's layout, it can either
* create and display a new fragment to show the details in-place (more about
- * this later), or start a new activity show the details.</p>
+ * this later), or start a new activity to show the details.</p>
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
* titles}
*
- * <p>The details fragment showing the contents of selected item here just
+ * <p>The details fragment showing the contents of a selected item just
* displays a string of text based on an index of a string array built in to
* the app:</p>
*
@@ -257,7 +257,7 @@
* details}
*
* <p>In this case when the user clicks on a title, there is no details
- * container in the current activity, so the title title fragment's click code will
+ * container in the current activity, so the titles fragment's click code will
* launch a new activity to display the details fragment:</p>
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 33c2937..1cd8ec0 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -925,6 +925,26 @@
/**
* Feature for {@link #getSystemAvailableFeatures} and
+ * {@link #hasSystemFeature}: The device supports portrait orientation
+ * screens. For backwards compatibility, you can assume that if neither
+ * this nor {@link #FEATURE_SCREEN_LANDSCAPE} is set then the device supports
+ * both portrait and landscape.
+ */
+ @SdkConstant(SdkConstantType.FEATURE)
+ public static final String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
+
+ /**
+ * Feature for {@link #getSystemAvailableFeatures} and
+ * {@link #hasSystemFeature}: The device supports landscape orientation
+ * screens. For backwards compatibility, you can assume that if neither
+ * this nor {@link #FEATURE_SCREEN_PORTRAIT} is set then the device supports
+ * both portrait and landscape.
+ */
+ @SdkConstant(SdkConstantType.FEATURE)
+ public static final String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
+
+ /**
+ * Feature for {@link #getSystemAvailableFeatures} and
* {@link #hasSystemFeature}: The device supports live wallpapers.
*/
@SdkConstant(SdkConstantType.FEATURE)
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 3ccc814..1b28aa2 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -253,6 +253,26 @@
* later. Applications that don't support a screen size at least as
* large as the current screen will provide the user with a UI to
* switch them in to screen size compatibility mode.</p>
+ *
+ * <p>This version introduces new screen size resource qualifiers
+ * based on the screen size in dp: see
+ * {@link android.content.res.Configuration#screenWidthDp},
+ * {@link android.content.res.Configuration#screenHeightDp}, and
+ * {@link android.content.res.Configuration#smallestScreenWidthDp}.
+ * Supplying these in <supports-screens> as per
+ * {@link android.content.pm.ApplicationInfo#requiresSmallestWidthDp},
+ * {@link android.content.pm.ApplicationInfo#compatibleWidthLimitDp}, and
+ * {@link android.content.pm.ApplicationInfo#largestWidthLimitDp} is
+ * preferred over the older screen size buckets and for older devices
+ * the appropriate buckets will be inferred from them.</p>
+ *
+ * <p>New {@link android.content.pm.PackageManager#FEATURE_SCREEN_PORTRAIT}
+ * and {@link android.content.pm.PackageManager#FEATURE_SCREEN_LANDSCAPE}
+ * features are introduced in this release. Applications that target
+ * previous platform versions are assumed to require both portrait and
+ * landscape support in the device; when targeting Honeycomb MR1 or
+ * greater the application is responsible for specifying any specific
+ * orientation it requires.</p>
*/
public static final int HONEYCOMB_MR2 = 13;
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index d5cad96..383bfb3 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -166,6 +166,7 @@
static native void nUpdateTextureLayer(int layerId, int width, int height, int surface);
static native void nDestroyLayer(int layerId);
static native void nDestroyLayerDeferred(int layerId);
+ static native boolean nCopyLayer(int layerId, int bitmap);
///////////////////////////////////////////////////////////////////////////
// Canvas management
diff --git a/core/java/android/view/GLES20Layer.java b/core/java/android/view/GLES20Layer.java
index bc191a6..69dfc2b 100644
--- a/core/java/android/view/GLES20Layer.java
+++ b/core/java/android/view/GLES20Layer.java
@@ -17,6 +17,8 @@
package android.view;
+import android.graphics.Bitmap;
+
/**
* An OpenGL ES 2.0 implementation of {@link HardwareLayer}.
*/
@@ -40,7 +42,10 @@
return mLayer;
}
-
+ boolean copyInto(Bitmap bitmap) {
+ return GLES20Canvas.nCopyLayer(mLayer, bitmap.mNativeBitmap);
+ }
+
@Override
void destroy() {
if (mFinalizer != null) mFinalizer.destroy();
diff --git a/core/java/android/view/Gravity.java b/core/java/android/view/Gravity.java
index 69e6489..63f5ec1 100644
--- a/core/java/android/view/Gravity.java
+++ b/core/java/android/view/Gravity.java
@@ -151,13 +151,13 @@
* width and height of the object.
* @param outRect Receives the computed frame of the object in its
* container.
- * @param isRtl Whether the layout is right-to-left.
+ * @param layoutDirection The layout direction.
*
* @hide
*/
public static void apply(int gravity, int w, int h, Rect container,
- Rect outRect, boolean isRtl) {
- int absGravity = getAbsoluteGravity(gravity, isRtl);
+ Rect outRect, int layoutDirection) {
+ int absGravity = getAbsoluteGravity(gravity, layoutDirection);
apply(absGravity, w, h, container, 0, 0, outRect);
}
@@ -347,18 +347,19 @@
* if horizontal direction is LTR, then START will set LEFT and END will set RIGHT.
* if horizontal direction is RTL, then START will set RIGHT and END will set LEFT.
*
+ *
* @param gravity The gravity to convert to absolute (horizontal) values.
- * @param isRtl Whether the layout is right-to-left.
+ * @param layoutDirection The layout direction.
* @return gravity converted to absolute (horizontal) values.
*/
- public static int getAbsoluteGravity(int gravity, boolean isRtl) {
+ public static int getAbsoluteGravity(int gravity, int layoutDirection) {
int result = gravity;
// If layout is script specific and gravity is horizontal relative (START or END)
if ((result & RELATIVE_LAYOUT_DIRECTION) > 0) {
if ((result & Gravity.START) == Gravity.START) {
// Remove the START bit
result &= ~START;
- if (isRtl) {
+ if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
// Set the RIGHT bit
result |= RIGHT;
} else {
@@ -368,7 +369,7 @@
} else if ((result & Gravity.END) == Gravity.END) {
// Remove the END bit
result &= ~END;
- if (isRtl) {
+ if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
// Set the LEFT bit
result |= LEFT;
} else {
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java
index 2611ec0..5944bd4 100644
--- a/core/java/android/view/HardwareRenderer.java
+++ b/core/java/android/view/HardwareRenderer.java
@@ -17,6 +17,7 @@
package android.view;
+import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
@@ -204,8 +205,18 @@
* @param surface The surface to update
*/
abstract void updateTextureLayer(HardwareLayer layer, int width, int height,
- SurfaceTexture surface);
-
+ SurfaceTexture surface);
+
+ /**
+ * Copies the content of the specified layer into the specified bitmap.
+ *
+ * @param layer The hardware layer to copy
+ * @param bitmap The bitmap to copy the layer into
+ *
+ * @return True if the copy was successful, false otherwise
+ */
+ abstract boolean copyLayer(HardwareLayer layer, Bitmap bitmap);
+
/**
* Initializes the hardware renderer for the specified surface and setup the
* renderer for drawing, if needed. This is invoked when the ViewAncestor has
@@ -814,6 +825,11 @@
((GLES20TextureLayer) layer).update(width, height, surface.mSurfaceTexture);
}
+ @Override
+ boolean copyLayer(HardwareLayer layer, Bitmap bitmap) {
+ return ((GLES20Layer) layer).copyInto(bitmap);
+ }
+
static HardwareRenderer create(boolean translucent) {
if (GLES20Canvas.isAvailable()) {
return new Gl20Renderer(translucent);
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index bc1ad3c..4daa892 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -17,6 +17,7 @@
package android.view;
import android.content.Context;
+import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.SurfaceTexture;
@@ -89,6 +90,8 @@
* @see SurfaceTexture
*/
public class TextureView extends View {
+ private static final String LOG_TAG = "TextureView";
+
private HardwareLayer mLayer;
private SurfaceTexture mSurface;
private SurfaceTextureListener mListener;
@@ -148,7 +151,7 @@
super.onAttachedToWindow();
if (!isHardwareAccelerated()) {
- Log.w("TextureView", "A TextureView or a subclass can only be "
+ Log.w(LOG_TAG, "A TextureView or a subclass can only be "
+ "used with hardware acceleration enabled.");
}
}
@@ -293,8 +296,95 @@
}
/**
+ * <p>Returns a {@link android.graphics.Bitmap} representation of the content
+ * of the associated surface texture. If the surface texture is not available,
+ * this method returns null.</p>
+ *
+ * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
+ * pixel format and its dimensions are the same as this view's.</p>
+ *
+ * <p><strong>Do not</strong> invoke this method from a drawing method
+ * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
+ *
+ * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
+ * texture is not available or the width <= 0 or the height <= 0
+ *
+ * @see #isAvailable()
+ * @see #getBitmap(android.graphics.Bitmap)
+ * @see #getBitmap(int, int)
+ */
+ public Bitmap getBitmap() {
+ return getBitmap(getWidth(), getHeight());
+ }
+
+ /**
+ * <p>Returns a {@link android.graphics.Bitmap} representation of the content
+ * of the associated surface texture. If the surface texture is not available,
+ * this method returns null.</p>
+ *
+ * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
+ * pixel format.</p>
+ *
+ * <p><strong>Do not</strong> invoke this method from a drawing method
+ * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
+ *
+ * @param width The width of the bitmap to create
+ * @param height The height of the bitmap to create
+ *
+ * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
+ * texture is not available or width is <= 0 or height is <= 0
+ *
+ * @see #isAvailable()
+ * @see #getBitmap(android.graphics.Bitmap)
+ * @see #getBitmap()
+ */
+ public Bitmap getBitmap(int width, int height) {
+ if (isAvailable() && width > 0 && height > 0) {
+ return getBitmap(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888));
+ }
+ return null;
+ }
+
+ /**
+ * <p>Copies the content of this view's surface texture into the specified
+ * bitmap. If the surface texture is not available, the copy is not executed.
+ * The content of the surface texture will be scaled to fit exactly inside
+ * the specified bitmap.</p>
+ *
+ * <p><strong>Do not</strong> invoke this method from a drawing method
+ * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
+ *
+ * @param bitmap The bitmap to copy the content of the surface texture into,
+ * cannot be null, all configurations are supported
+ *
+ * @return The bitmap specified as a parameter
+ *
+ * @see #isAvailable()
+ * @see #getBitmap(int, int)
+ * @see #getBitmap()
+ */
+ public Bitmap getBitmap(Bitmap bitmap) {
+ if (bitmap != null && isAvailable()) {
+ mAttachInfo.mHardwareRenderer.copyLayer(mLayer, bitmap);
+ }
+ return bitmap;
+ }
+
+ /**
+ * Returns true if the {@link SurfaceTexture} associated with this
+ * TextureView is available for rendering. When this method returns
+ * true, {@link #getSurfaceTexture()} returns a valid surface texture.
+ */
+ public boolean isAvailable() {
+ return mSurface != null;
+ }
+
+ /**
* Returns the {@link SurfaceTexture} used by this view. This method
- * may return null if the view is not attached to a window.
+ * may return null if the view is not attached to a window or if the surface
+ * texture has not been initialized yet.
+ *
+ * @see #isAvailable()
*/
public SurfaceTexture getSurfaceTexture() {
return mSurface;
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 071905c..1dfb858 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4272,6 +4272,7 @@
* {@link #LAYOUT_DIRECTION_INHERIT} or
* {@link #LAYOUT_DIRECTION_LOCALE}.
* @attr ref android.R.styleable#View_layoutDirection
+ *
* @hide
*/
@ViewDebug.ExportedProperty(category = "layout", mapping = {
@@ -4292,6 +4293,7 @@
* {@link #LAYOUT_DIRECTION_INHERIT} or
* {@link #LAYOUT_DIRECTION_LOCALE}.
* @attr ref android.R.styleable#View_layoutDirection
+ *
* @hide
*/
@RemotableViewMethod
@@ -4300,6 +4302,37 @@
}
/**
+ * Returns the resolved layout direction for this view.
+ *
+ * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns
+ * {@link #LAYOUT_DIRECTION_LTR} id the layout direction is not RTL.
+ *
+ * @hide
+ */
+ @ViewDebug.ExportedProperty(category = "layout", mapping = {
+ @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"),
+ @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL")
+ })
+ public int getResolvedLayoutDirection() {
+ resolveLayoutDirection();
+ return ((mPrivateFlags2 & RESOLVED_LAYOUT_RTL) == RESOLVED_LAYOUT_RTL) ?
+ LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR;
+ }
+
+ /**
+ * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from
+ * layout attribute and/or the inherited value from the parent.</p>
+ *
+ * @return true if the layout is right-to-left.
+ *
+ * @hide
+ */
+ @ViewDebug.ExportedProperty(category = "layout")
+ public boolean isLayoutRtl() {
+ return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL);
+ }
+
+ /**
* If this view doesn't do any drawing on its own, set this flag to
* allow further optimizations. By default, this flag is not set on
* View, but could be set on some View subclasses such as ViewGroup.
@@ -8713,8 +8746,9 @@
switch (getLayoutDirection()) {
case LAYOUT_DIRECTION_INHERIT:
// If this is root view, no need to look at parent's layout dir.
- if (mParent != null && mParent instanceof ViewGroup &&
- ((ViewGroup) mParent).isLayoutRtl()) {
+ if (mParent != null &&
+ mParent instanceof ViewGroup &&
+ ((ViewGroup) mParent).getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
}
break;
@@ -10237,17 +10271,6 @@
}
/**
- * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from
- * layout attribute and/or the inherited value from the parent.</p>
- *
- * @return true if the layout is right-to-left.
- */
- @ViewDebug.ExportedProperty(category = "layout")
- public boolean isLayoutRtl() {
- return (mPrivateFlags2 & RESOLVED_LAYOUT_RTL) == RESOLVED_LAYOUT_RTL;
- }
-
- /**
* Assign a size and position to a view and all of its
* descendants
*
@@ -10459,13 +10482,15 @@
}
}
- /**
- * Check if a given Drawable is in RTL layout direction.
- *
- * @param who the recipient of the action
- */
- public boolean isLayoutRtl(Drawable who) {
- return (who == mBGDrawable) && isLayoutRtl();
+ /**
+ * Return the layout direction of a given Drawable.
+ *
+ * @param who the Drawable to query
+ *
+ * @hide
+ */
+ public int getResolvedLayoutDirection(Drawable who) {
+ return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT;
}
/**
diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java
index 6b498fe..5eba1a0 100644
--- a/core/java/android/widget/FrameLayout.java
+++ b/core/java/android/widget/FrameLayout.java
@@ -364,7 +364,8 @@
gravity = DEFAULT_CHILD_GRAVITY;
}
- final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, isLayoutRtl());
+ final int layoutDirection = getResolvedLayoutDirection();
+ final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
@@ -435,8 +436,10 @@
selfBounds.set(mPaddingLeft, mPaddingTop, w - mPaddingRight, h - mPaddingBottom);
}
+ final int layoutDirection = getResolvedLayoutDirection();
Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(),
- foreground.getIntrinsicHeight(), selfBounds, overlayBounds, isLayoutRtl());
+ foreground.getIntrinsicHeight(), selfBounds, overlayBounds,
+ layoutDirection);
foreground.setBounds(overlayBounds);
}
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java
index 732cedc..5d406de 100644
--- a/core/java/android/widget/GridView.java
+++ b/core/java/android/widget/GridView.java
@@ -1408,7 +1408,8 @@
int childLeft;
final int childTop = flow ? y : y - h;
- final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity,isLayoutRtl());
+ final int layoutDirection = getResolvedLayoutDirection();
+ final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT:
childLeft = childrenLeft;
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index 4b870ec..161b404 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -186,9 +186,13 @@
}
}
+ /**
+ * @hide
+ */
@Override
- public boolean isLayoutRtl(Drawable dr) {
- return (dr == mDrawable) ? isLayoutRtl() : super.isLayoutRtl(dr);
+ public int getResolvedLayoutDirection(Drawable dr) {
+ return (dr == mDrawable) ?
+ getResolvedLayoutDirection() : super.getResolvedLayoutDirection(dr);
}
@Override
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index 0cdbc5b..e3bc946 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -1446,7 +1446,8 @@
if (gravity < 0) {
gravity = minorGravity;
}
- final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, isLayoutRtl());
+ final int layoutDirection = getResolvedLayoutDirection();
+ final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = paddingLeft + ((childSpace - childWidth) / 2)
@@ -1509,7 +1510,8 @@
final int[] maxAscent = mMaxAscent;
final int[] maxDescent = mMaxDescent;
- switch (Gravity.getAbsoluteGravity(majorGravity, isLayoutRtl())) {
+ final int layoutDirection = getResolvedLayoutDirection();
+ switch (Gravity.getAbsoluteGravity(majorGravity, layoutDirection)) {
case Gravity.RIGHT:
// mTotalLength contains the padding already
childLeft = mPaddingLeft + mRight - mLeft - mTotalLength;
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index ed9114a..b2c3051 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -915,10 +915,13 @@
}
}
+ /**
+ * @hide
+ */
@Override
- public boolean isLayoutRtl(Drawable who) {
+ public int getResolvedLayoutDirection(Drawable who) {
return (who == mProgressDrawable || who == mIndeterminateDrawable) ?
- isLayoutRtl() : super.isLayoutRtl(who);
+ getResolvedLayoutDirection() : super.getResolvedLayoutDirection(who);
}
@Override
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java
index a4771d5..a5cf62e 100644
--- a/core/java/android/widget/RelativeLayout.java
+++ b/core/java/android/widget/RelativeLayout.java
@@ -495,8 +495,9 @@
height - mPaddingBottom);
final Rect contentBounds = mContentBounds;
+ final int layoutDirection = getResolvedLayoutDirection();
Gravity.apply(mGravity, right - left, bottom - top, selfBounds, contentBounds,
- isLayoutRtl());
+ layoutDirection);
final int horizontalOffset = contentBounds.left - left;
final int verticalOffset = contentBounds.top - top;
diff --git a/core/java/android/widget/TableRow.java b/core/java/android/widget/TableRow.java
index 5f20c85..3fd4631 100644
--- a/core/java/android/widget/TableRow.java
+++ b/core/java/android/widget/TableRow.java
@@ -224,7 +224,8 @@
final int childWidth = child.getMeasuredWidth();
lp.mOffset[LayoutParams.LOCATION_NEXT] = columnWidth - childWidth;
- final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, isLayoutRtl());
+ final int layoutDirection = getResolvedLayoutDirection();
+ final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT:
// don't offset on X axis
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 9a5977a..470a23d6 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -4145,17 +4145,20 @@
}
}
+ /**
+ * @hide
+ */
@Override
- public boolean isLayoutRtl(Drawable who) {
- if (who == null) return false;
+ public int getResolvedLayoutDirection(Drawable who) {
+ if (who == null) return View.LAYOUT_DIRECTION_LTR;
if (mDrawables != null) {
final Drawables drawables = mDrawables;
if (who == drawables.mDrawableLeft || who == drawables.mDrawableRight ||
who == drawables.mDrawableTop || who == drawables.mDrawableBottom) {
- return isLayoutRtl();
+ return getResolvedLayoutDirection();
}
}
- return super.isLayoutRtl(who);
+ return super.getResolvedLayoutDirection(who);
}
@Override
@@ -4397,7 +4400,8 @@
canvas.translate(compoundPaddingLeft, extendedPaddingTop + voffsetText);
}
- final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, isLayoutRtl());
+ final int layoutDirection = getResolvedLayoutDirection();
+ final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
if (mEllipsize == TextUtils.TruncateAt.MARQUEE) {
if (!mSingleLine && getLineCount() == 1 && canMarquee() &&
(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) != Gravity.LEFT) {
@@ -5545,8 +5549,10 @@
hintWidth = 0;
}
+ final int layoutDirection = getResolvedLayoutDirection();
+ final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
+
Layout.Alignment alignment;
- final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, isLayoutRtl());
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
alignment = Layout.Alignment.ALIGN_CENTER;
@@ -7582,7 +7588,8 @@
return 0.0f;
}
} else if (getLineCount() == 1) {
- final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, isLayoutRtl());
+ final int layoutDirection = getResolvedLayoutDirection();
+ final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT:
return 0.0f;
@@ -7606,7 +7613,8 @@
final Marquee marquee = mMarquee;
return (marquee.mMaxFadeScroll - marquee.mScroll) / getHorizontalFadingEdgeLength();
} else if (getLineCount() == 1) {
- final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, isLayoutRtl());
+ final int layoutDirection = getResolvedLayoutDirection();
+ final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT:
final int textWidth = (mRight - mLeft) - getCompoundPaddingLeft() -
diff --git a/core/java/com/android/internal/view/menu/IconMenuItemView.java b/core/java/com/android/internal/view/menu/IconMenuItemView.java
index c337a5d..a743cfa 100644
--- a/core/java/com/android/internal/view/menu/IconMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/IconMenuItemView.java
@@ -281,8 +281,10 @@
Rect tmpRect = mPositionIconOutput;
getLineBounds(0, tmpRect);
mPositionIconAvailable.set(0, 0, getWidth(), tmpRect.top);
+ final int layoutDirection = getResolvedLayoutDirection();
Gravity.apply(Gravity.CENTER_VERTICAL | Gravity.LEFT, mIcon.getIntrinsicWidth(), mIcon
- .getIntrinsicHeight(), mPositionIconAvailable, mPositionIconOutput, isLayoutRtl());
+ .getIntrinsicHeight(), mPositionIconAvailable, mPositionIconOutput,
+ layoutDirection);
mIcon.setBounds(mPositionIconOutput);
}
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index 57a97bd..7e82efb 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -667,6 +667,11 @@
renderer->drawLayer(layer, x, y, paint);
}
+static jboolean android_view_GLES20Canvas_copyLayer(JNIEnv* env, jobject clazz,
+ Layer* layer, SkBitmap* bitmap) {
+ return LayerRenderer::copyLayer(layer, bitmap);
+}
+
#endif // USE_OPENGL_RENDERER
// ----------------------------------------------------------------------------
@@ -792,6 +797,7 @@
{ "nDestroyLayer", "(I)V", (void*) android_view_GLES20Canvas_destroyLayer },
{ "nDestroyLayerDeferred", "(I)V", (void*) android_view_GLES20Canvas_destroyLayerDeferred },
{ "nDrawLayer", "(IIFFI)V", (void*) android_view_GLES20Canvas_drawLayer },
+ { "nCopyLayer", "(II)Z", (void*) android_view_GLES20Canvas_copyLayer },
#endif
};
diff --git a/core/tests/bluetoothtests/AndroidManifest.xml b/core/tests/bluetoothtests/AndroidManifest.xml
index 96db035..58f158c 100644
--- a/core/tests/bluetoothtests/AndroidManifest.xml
+++ b/core/tests/bluetoothtests/AndroidManifest.xml
@@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestRunner.java b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestRunner.java
index 64d2c12..56e691d 100644
--- a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestRunner.java
+++ b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestRunner.java
@@ -47,7 +47,7 @@
* [-e pan_address <address>] \
* [-e pair_pin <pin>] \
* [-e pair_passkey <passkey>] \
- * -w com.android.frameworks.coretests/android.bluetooth.BluetoothTestRunner
+ * -w com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner
* }
* </pre>
*/
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java
index 5f4c226..047481e 100644
--- a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java
+++ b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java
@@ -290,7 +290,7 @@
@Override
public void onReceive(Context context, Intent intent) {
- if (AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED.equals(intent.getAction())) {
+ if (AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED.equals(intent.getAction())) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,
AudioManager.SCO_AUDIO_STATE_ERROR);
assertNotSame(AudioManager.SCO_AUDIO_STATE_ERROR, state);
diff --git a/core/tests/coretests/src/android/view/GravityTest.java b/core/tests/coretests/src/android/view/GravityTest.java
index 2a7a64f..d8ef650 100644
--- a/core/tests/coretests/src/android/view/GravityTest.java
+++ b/core/tests/coretests/src/android/view/GravityTest.java
@@ -67,6 +67,8 @@
}
private void assertOneGravity(int expected, int initial, boolean isRtl) {
- assertEquals(expected, Gravity.getAbsoluteGravity(initial, isRtl));
+ final int layoutDirection = isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
+
+ assertEquals(expected, Gravity.getAbsoluteGravity(initial, layoutDirection));
}
}
diff --git a/data/etc/handheld_core_hardware.xml b/data/etc/handheld_core_hardware.xml
index 7f87b79..9d2a0cb 100644
--- a/data/etc/handheld_core_hardware.xml
+++ b/data/etc/handheld_core_hardware.xml
@@ -31,6 +31,8 @@
<feature name="android.hardware.bluetooth" />
<feature name="android.hardware.touchscreen" />
<feature name="android.hardware.microphone" />
+ <feature name="android.hardware.screen.portrait" />
+ <feature name="android.hardware.screen.landscape" />
<!-- devices with GPS must include android.hardware.location.gps.xml -->
<!-- devices with an autofocus camera and/or flash must include either
android.hardware.camera.autofocus.xml or
diff --git a/data/etc/tablet_core_hardware.xml b/data/etc/tablet_core_hardware.xml
index 952d0782..bf29fe4 100644
--- a/data/etc/tablet_core_hardware.xml
+++ b/data/etc/tablet_core_hardware.xml
@@ -32,6 +32,8 @@
<feature name="android.hardware.touchscreen.multitouch" />
<feature name="android.hardware.touchscreen.multitouch.distinct" />
<feature name="android.hardware.microphone" />
+ <feature name="android.hardware.screen.portrait" />
+ <feature name="android.hardware.screen.landscape" />
<!-- devices with GPS must include android.hardware.location.gps.xml -->
<!-- devices with a rear-facing camera must include one of these as appropriate:
android.hardware.camera.xml or
diff --git a/data/fonts/DroidSansFallback.ttf b/data/fonts/DroidSansFallback.ttf
index ba9d76f..03ceae5 100644
--- a/data/fonts/DroidSansFallback.ttf
+++ b/data/fonts/DroidSansFallback.ttf
Binary files differ
diff --git a/docs/html/guide/guide_toc.cs b/docs/html/guide/guide_toc.cs
index 916da09..55d711f 100644
--- a/docs/html/guide/guide_toc.cs
+++ b/docs/html/guide/guide_toc.cs
@@ -244,9 +244,6 @@
<li><a href="<?cs var:toroot ?>guide/topics/graphics/opengl.html">
<span class="en">3D with OpenGL</span>
</a></li>
- <li><a href="<?cs var:toroot ?>guide/topics/graphics/renderscript.html">
- <span class="en">3D with Renderscript</span>
- </a></li>
<li><a href="<?cs var:toroot ?>guide/topics/graphics/animation.html">
<span class="en">Property Animation</span>
</a></li>
@@ -255,6 +252,23 @@
</a></li>
</ul>
</li>
+ <li class="toggle-list">
+ <div><a href="<?cs var:toroot ?>guide/topics/renderscript/index.html">
+ <span class="en">RenderScript</span>
+ </a>
+ <span class="new-child">new!</span></div>
+ <ul>
+ <li><a href="<?cs var:toroot ?>guide/topics/renderscript/graphics.html">
+ <span class="en">3D Graphics</span>
+ </a>
+ </li>
+ <li><a href="<?cs var:toroot ?>guide/topics/renderscript/compute.html">
+ <span class="en">Compute</span>
+ </a>
+ </li>
+ </ul>
+ </li>
+
<li><a href="<?cs var:toroot ?>guide/topics/media/index.html">
<span class="en">Audio and Video</span>
</a></li>
diff --git a/docs/html/guide/topics/graphics/animation.jd b/docs/html/guide/topics/graphics/animation.jd
index 0b02ee76..31e7c4b 100644
--- a/docs/html/guide/topics/graphics/animation.jd
+++ b/docs/html/guide/topics/graphics/animation.jd
@@ -81,6 +81,12 @@
If view animation accomplishes everything that you need to do, or if your existing code already
works the way you want, there is no need to use the property animation system.</p>
+ <p class="note"><strong>Tip:</strong> To see how the ADT layout editor allows you to develop and
+preview animations in your layout, watch the <a
+href="http://www.youtube.com/watch?v=Oq05KqjXTvs&feature=player_detailpage#t=1709s">Android
+Developer Tools session</a> from Google I/O '11</p>
+
+
<h2 id="what">What is Property Animation?</h2>
A property animation changes a property's (a field in
an object) value over a specified length of time. To animate something, you specify the
@@ -108,6 +114,7 @@
default is set to refresh every 10 ms, but the speed in which your application can refresh frames is
ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer.</li>
</ul>
+
<h3 id="how">How the property animation system works</h3>
@@ -894,99 +901,5 @@
<li>{@link android.animation.AnimatorSet} - <code><set></code></li>
</ul>
- <p>Both <code><animator></code> ({@link android.animation.ValueAnimator}) and
- <code><objectAnimator></code> ({@link android.animation.ObjectAnimator}) have the following
- attributes:</p>
+<p>See <a href="{@docRoot}guide/topics/resources/animation-resource.html#Property">Animation Resources</a>
- <dl>
- <dt><code>android:duration</code></dt>
-
- <dd>The number of milliseconds that the animation runs. The default is 300 ms.</dd>
-
- <dt><code>android:valueFrom</code> and <code>android:valueTo</code></dt>
-
- <dd>The values being animated between. These are restricted to numbers (<code>float</code> or
- <code>int</code>) and color values (such as #00ff00). They can be <code>float</code>, <code>int</code>, colors,
- or any kind of <code>Object</code> when creating animations programmatically.</dd>
-
- <dt><code>android:valueType</code></dt>
-
- <dd>Set to either <code>"floatType"</code> or <code>"intType"</code>. The default is
- <code>"floatType"</code> unless you specify something else or if the <code>valuesFrom</code>
- and <code>valuesTo</code> values are colors.</dd>
-
- <dt><code>android:startOffset</code></dt>
-
- <dd>The delay, in milliseconds, before the animation begins playing (after calling {@link
- android.animation.ValueAnimator#start start()}).</dd>
-
- <dt><code>android:repeatCount</code></dt>
-
- <dd>How many times to repeat an animation. Set to <code>"-1"</code> to infinitely repeat or
- to a positive integer. For example, a value of <code>"1"</code> means that the animation is
- repeated once after the initial run of the animation, so the animation plays a total of two
- times. The default value is <code>"0"</code>, which means no repetition.</dd>
-
- <dt><code>android:repeatMode</code></dt>
-
- <dd>How an animation behaves when it reaches the end of the animation.
- <code>android:repeatCount</code> must be set to a positive integer or <code>"-1"</code> for
- this attribute to have an effect. Set to <code>"reverse"</code> to have the animation reverse
- direction with each iteration or <code>"repeat"</code> to have the animation loop from the
- beginning each time.</dd>
- </dl>
-
- <p>The <code><objectAnimator></code> ({@link android.animation.ObjectAnimator}) element has the
- additional attribute <code>android:propertyName</code>, that lets you specify the name of the
-property
- being animated. The <code><objectAnimator></code> element does not expose a <code>target</code>
- attribute, however, so you cannot set the object to animate in the XML declaration. You have to
- inflate the XML resource by calling {@link android.animation.AnimatorInflater#loadAnimator
- loadAnimator()} and call {@link android.animation.ObjectAnimator#setTarget setTarget()} to set
- the target object unlike the underlying {@link android.animation.ObjectAnimator},
- before calling {@link android.animation.ObjectAnimator#start start()}.</p>
-
- <p>The <code><set></code> element ({@link android.animation.AnimatorSet}) exposes a single
- attribute, <code>android:ordering</code>. Set this attribute to <code>"together"</code> (default)
-to play
- all the animations in this set at once. Set this attribute to <code>"sequentially"</code> to play
- the animations in the order they are declared.</p>
-
- <p>You can specify nested <code><set></code> elements to further group animations together.
-The
- animations that you want to group together should be children of the <code><set></code> tag and can
- define their own <code>ordering</code> attribute.</p>
-
- <p>As an example, this XML code creates an {@link android.animation.AnimatorSet} object that
- animates x and y at the same time, then runs an animation that fades an object out:</p>
- <pre>
-<set android:ordering="sequentially">
- <set>
- <objectAnimator
- android:propertyName="x"
- android:duration="500"
- android:valueTo="400"
- android:valueType="int"/>
- <objectAnimator
- android:propertyName="y"
- android:duration="500"
- android:valueTo="300"
- android:valueType="int"/>
- </set>
- <objectAnimator
- android:propertyName="alpha"
- android:duration="500"
- android:valueTo="0f"/>
-</set>
-</pre>
-
- <p>In order to run this animation, you must inflate the XML resources in your code to an {@link
- android.animation.AnimatorSet} object, and then set the target objects for all of the animations
- before starting the animation set. Calling {@link android.animation.AnimatorSet#setTarget
- setTarget()} sets a single target object for all children of the {@link
- android.animation.AnimatorSet}.</p>
-
-<p class="note"><strong>Tip:</strong> To see how the ADT layout editor allows you to develop and
-preview animations in your layout, watch the <a
-href="http://www.youtube.com/watch?v=Oq05KqjXTvs&feature=player_detailpage#t=1709s">Android
-Developer Tools session</a> from Google I/O '11</p>
diff --git a/docs/html/guide/topics/graphics/renderscript.html b/docs/html/guide/topics/graphics/renderscript.html
new file mode 100644
index 0000000..454d392
--- /dev/null
+++ b/docs/html/guide/topics/graphics/renderscript.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+<meta http-equiv="refresh" content="0;url=http://developer.android.com/guide/topics/renderscript/index.html">
+<title>Redirecting...</title>
+</head>
+<body>
+<p>You should be redirected. Please <a
+href="http://developer.android.com/guide/topics/renderscript/index.html">click here</a>.</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/docs/html/guide/topics/graphics/renderscript.jd b/docs/html/guide/topics/graphics/renderscript.jd
deleted file mode 100644
index 180322f..0000000
--- a/docs/html/guide/topics/graphics/renderscript.jd
+++ /dev/null
@@ -1,716 +0,0 @@
-page.title=3D Rendering and Computation with Renderscript
-parent.title=Graphics
-parent.link=index.html
-@jd:body
-
- <div id="qv-wrapper">
- <div id="qv">
- <h2>In this document</h2>
-
- <ol>
- <li><a href="#overview">Renderscript System Overview</a></li>
-
- <li>
- <a href="#api">API Overview</a>
-
- <ol>
- <li><a href="#native-api">Native Renderscript APIs</a></li>
-
- <li><a href="#reflective-api">Reflected layer APIs</a></li>
-
- <li><a href="#graphics-api">Graphics APIs</a></li>
- </ol>
- </li>
-
- <li>
- <a href="#developing">Developing a Renderscript application</a>
-
- <ol>
- <li><a href="#hello-graphics">The Hello Graphics application</a></li>
- </ol>
- </li>
- </ol>
- <h2>Related Samples</h2>
- <ol>
- <li><a href="{@docRoot}resources/samples/Renderscript/Balls/index.html">Balls</a></li>
- <li><a href="{@docRoot}resources/samples/Renderscript/Fountain/index.html">Fountain</a></li>
- <li><a href="{@docRoot}resources/samples/Renderscript/HelloCompute/index.html">Hello Compute</a></li>
- <li><a href="{@docRoot}resources/samples/Renderscript/HelloWorld/index.html">Hello World</a></li>
- <li><a href="{@docRoot}resources/samples/Renderscript/Samples/index.html">Samples</a></li>
- </ol>
- </div>
- </div>
-
- <p>The Renderscript system offers high performance 3D rendering and mathematical computation at
- the native level. The Renderscript APIs are intended for developers who are comfortable with
- developing in C (C99 standard) and want to maximize performance in their applications. The
- Renderscript system improves performance by running as native code on the device, but it also
- features cross-platform functionality. To achieve this, the Android build tools compile your
- Renderscript <code>.rs</code> file to intermediate bytecode and package it inside your
- application's <code>.apk</code> file. On the device, the bytecode is compiled (just-in-time) to
- machine code that is further optimized for the device that it is running on. This eliminates the
- need to target a specific architecture during the development process. The compiled code on the
- device is cached, so subsequent uses of the Renderscript enabled application do not recompile the
- intermediate code.</p>
-
- <p>The disadvantage of the Renderscript system is that it adds complexity to the development and
- debugging processes. Debugging visibility can be limited, because the
- Renderscript system can execute on processors other than the main CPU (such as the GPU), so if
- this occurs, debugging becomes more difficult. The target use is for performance
- critical code where the traditional framework APIs (such as using {@link android.opengl}) are not sufficient.
- If what you are rendering or computing is very simple and does not require much processing power, you should still use the
- traditional framework APIs for ease of development. Remember the tradeoffs between development and
- debugging complexity versus performance when deciding to use Renderscript. </p>
-
- <p>For an example of Renderscript in action, see the 3D carousel view in the Android 3.0 versions
- of Google Books and YouTube or install the Renderscript sample applications that are shipped with
- the SDK in <code><sdk_root>/samples/android-11/Renderscript</code>.</p>
-
- <h2 id="overview">Renderscript System Overview</h2>
-
- <p>The Renderscript system adopts a control and slave architecture where the low-level native
- code is controlled by the higher level Android system that runs in the virtual machine (VM). When
- you use the Renderscript system, there are three layers that exist:</p>
-
- <ul>
- <li>The native Renderscript layer consists of native libraries that are packaged with the SDK.
- The native Renderscript <code>.rs</code> files compute mathematical operations, render graphics,
- or both. This layer does the intensive computation or graphics rendering and returns the result
- back to the Android VM through the reflected layer.</li>
-
- <li>The reflected layer is a set of generated Android framework classes reflected from
- the native Renderscript code that you wrote. This layer acts as a bridge between the native
- Renderscript layer and the Android system layer. The Android build tools automatically generate
- the classes for this layer during the build process. This layer also includes a set of Android
- framework APIs that provide the memory and resource allocation classes to support this layer.</li>
-
- <li>The Android system layer consists of the traditional framework APIs, which include the Renderscript
- APIs in {@link android.renderscript}. This layer handles things such as the Activity lifecycle
- management of your application and calls the reflected layer to communicate with the native Renderscript code.</li>
- </ul>
-
- <p>To fully understand how the Renderscript system works, you must understand how the reflected
- layer is generated and how it interacts with the native Renderscript layer and Android system
- layer. The reflected layer provides the entry points into the native code, enabling the Android
- system to give high level commands like, "rotate the view" or "filter the bitmap" to the
- native layer, which does the heavy lifting. To accomplish this, you need to create logic
- to hook together all of these layers so that they can correctly communicate.</p>
-
- <p>At the root of everything is your Renderscript, which is the actual C code that you write and
- save to a <code>.rs</code> file in your project. There are two kinds of Renderscripts: compute
- and graphics. A compute Renderscript does not do any graphics rendering while a graphics
- Renderscript does.</p>
-
- <p>When you create Renderscript <code>.rs</code> files, equivalent, reflected classes
- are generated by the build tools and expose the native functions and data types and structures
- to the Android system. The following list describes the major components of your native Renderscript
- code that is reflected:</p>
-
- <ul>
- <li>The non-static functions in your Renderscript (<code>.rs</code> file) are reflected into
- <code><em>ScriptC_renderscript_filename</em></code> of type {@link
- android.renderscript.ScriptC}.</li>
-
- <li>Any non-static, global Renderscript variables are reflected into
- <code><em>ScriptC_renderscript_filename</em></code>.
- Accessor methods are generated, so the Android system layer can access the values.
- The <code>get</code> method comes with a one-way communication restriction.
- The Android system layer always caches the last value that is set and returns that during a call to a <code>get</code> method.
- If the native Renderscript code changes the value, the change does not propagate back to the Android system layer.
- If the global variables are initialized in the native Renderscript code, those values are used
- to initialize the corresponding values in the Android system. If global variables are marked as <code>const</code>,
- then a <code>set</code> method is not generated.
- </li>
-
- <li>Structs are reflected into their own classes, one for each struct, into a class named
- <code>ScriptField_<em>struct_name</em></code> of type {@link
- android.renderscript.Script.FieldBase}.</li>
-
- <li>Global pointers have a special property. They provide attachment points where the Android system can attach allocations.
- If the global pointer is a user defined structure type, it must be a type that is legal for reflection (primitives
- or Renderscript data types). The Android system can call the reflected class to allocate memory and
- optionally populate data, then attach it to the Renderscript.
- For arrays of basic types, the procedure is similar, except a reflected class is not needed.
- Renderscripts should not directly set the exported global pointers.</li>
- </ul>
-
- <p>The Android framework API also has a corresponding Renderscript context object, {@link
- android.renderscript.RenderScript} (for a compute Renderscript) or {@link
- android.renderscript.RenderScriptGL} (for a graphics Renderscript). This context object allows
- you to bind to the reflected Renderscript class, so that the Renderscript context knows what its
- corresponding native Renderscript is. If you have a graphics Renderscript context, you can also
- specify a variety of Programs (stages in the graphics pipeline) to tweek how your graphics are
- rendered. A graphics Renderscript context also needs a surface to render on, {@link
- android.renderscript.RSSurfaceView}, which gets passed into its constructor.</p>
-
- <h2 id="api">API overview</h2>
-
- <p>Renderscript code is compiled and executed in a compact and well defined runtime, which has
- access to a limited amount of functions. Renderscript cannot use the NDK or standard C functions,
- because these functions are assumed to be running on a standard CPU. The Renderscript runtime
- chooses the best processor to execute the code, which may not be the CPU, so it cannot guarantee
- support for standard C libraries. What Renderscript does offer is an API that supports intensive
- computation with an extensive collection of math APIs. The following sections group the APIs
- into three distinct categories.</p>
-
-
- <h3 id="native-api">Native Renderscript APIs</h3>
-
- <p>The Renderscript headers are located in the <code>include</code> and
- <code>clang-include</code> directories in the
- <code><sdk_root>/platforms/android-11/renderscript</code> directory of the Android SDK.
- The headers are automatically included for you, except for the graphics specific header,
- which you can define as follows:</p>
-
-<pre>#include "rs_graphics.rsh"</pre>
-
-<p>Some key features of the native Renderscript libraries include:
- <ul>
- <li>A large collection of math functions with both scalar and vector typed overloaded versions
- of many common routines. Operations such as adding, multiplying, dot product, and cross product
- are available.</li>
- <li>Conversion routines for primitive data types and vectors, matrix routines, date and time
- routines, and graphics routines.</li>
- <li>Logging functions</li>
- <li>Graphics rendering functions</li>
- <li>Memory allocation request features</li>
- <li>Data types and structures to support the Renderscript system such as
- Vector types for defining two-, three-, or four-vectors.</li>
- </ul>
-
- <h3 id="reflective-api">Reflected layer APIs</h3>
-
- <p>These classes are mainly used by the reflected classes that are generated from your native Renderscript
- code. They allocate and manage memory for your Renderscript on the Android system side.
- You normally do not need to call these classes directly.</p>
-
- <p>Because of the constraints of the Renderscript native layer, you cannot do any dynamic
- memory allocation in your Renderscript <code>.rs</code> file.
- The native Renderscript layer can request memory from the Android system layer, which allocates memory
- for you and does reference counting to figure out when to free the memory. A memory allocation
- is taken care of by the {@link android.renderscript.Allocation} class and memory is requested
- in your Renderscript code with the <code>the rs_allocation</code> type.
- All references to Renderscript objects are counted, so when your Renderscript native code
- or system code no longer references a particular {@link android.renderscript.Allocation}, it destroys itself.
- Alternatively, you can call {@link android.renderscript.Allocation#destroy destroy()} from the
- Android system level, which decreases the reference to the {@link android.renderscript.Allocation}.
- If no references exist after the decrease, the {@link android.renderscript.Allocation} destroys itself.
- The Android system object, which at this point is just an empty shell, is eventually garbage collected.
- </p>
-
- <p>The following classes are mainly used by the reflected layer classes:</p>
-
- <table>
- <tr>
- <th>Android Object Type</th>
-
- <th>Renderscript Native Type</th>
-
- <th>Description</th>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.Element}</td>
-
- <td>rs_element</td>
-
- <td>
- An {@link android.renderscript.Element} is the most basic element of a memory type. An
- element represents one cell of a memory allocation. An element can have two forms: Basic or
- Complex. They are typically created from C structures in your Renderscript
- code during the reflection process. Elements cannot contain pointers or nested arrays.
- The other common source of elements is bitmap formats.
-
- <p>A basic element contains a single component of data of any valid Renderscript data type.
- Examples of basic element data types include a single float value, a float4 vector, or a
- single RGB-565 color.</p>
-
- <p>Complex elements contain a list of sub-elements and names that is basically a reflection
- of a C struct. You access the sub-elements by name from a script or vertex program. The
- most basic primitive type determines the data alignment of the structure. For example, a
- float4 vector is alligned to <code>sizeof(float)</code> and not
- <code>sizeof(float4)</code>. The ordering of the elements in memory are the order in which
- they were added, with each component aligned as necessary.</p>
- </td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.Type}</td>
-
- <td>rs_type</td>
-
- <td>A Type is an allocation template that consists of an element and one or more dimensions.
- It describes the layout of the memory but does not allocate storage for the data that it
- describes. A Type consists of five dimensions: X, Y, Z, LOD (level of detail), and Faces (of
- a cube map). You can assign the X,Y,Z dimensions to any positive integer value within the
- constraints of available memory. A single dimension allocation has an X dimension of greater
- than zero while the Y and Z dimensions are zero to indicate not present. For example, an
- allocation of x=10, y=1 is considered two dimensional and x=10, y=0 is considered one
- dimensional. The LOD and Faces dimensions are booleans to indicate present or not
- present.</td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.Allocation}</td>
-
- <td>rs_allocation</td>
-
- <td>
- <p>An {@link android.renderscript.Allocation} provides the memory for applications. An {@link
- android.renderscript.Allocation} allocates memory based on a description of the memory that
- is represented by a {@link android.renderscript.Type}. The type describes an array of elements that
- represent the memory to be allocated. Allocations are the primary way data moves into and
- out of scripts.</p>
-
- <p>Memory is user-synchronized and it's possible for allocations to exist in multiple
- memory spaces concurrently. For example, if you make a call to the graphics card to load a
- bitmap, you give it the bitmap to load from in the system memory. After that call returns,
- the graphics memory contains its own copy of the bitmap so you can choose whether or not to
- maintain the bitmap in the system memory. If the Renderscript system modifies an allocation
- that is used by other targets, it must call {@link android.renderscript#syncAll syncAll()} to push the updates to
- the memory. Otherwise, the results are undefined.</p>
-
- <p>Allocation data is uploaded in one of two primary ways: type checked and type unchecked.
- For simple arrays there are <code>copyFrom()</code> functions that take an array from the
- Android system and copy it to the native layer memory store. Both type checked and
- unchecked copies are provided. The unchecked variants allow the Android system to copy over
- arrays of structures because it does not support structures. For example, if
- there is an allocation that is an array n floats, you can copy the data contained in a
- float[n] array or a byte[n*4] array.</p>
- </td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.Script}</td>
-
- <td>rs_script</td>
-
- <td>Renderscript scripts do much of the work in the native layer. This class is generated
- from a Renderscript file that has the <code>.rs</code> file extension. This class is named
- <code>ScriptC_<em>rendersript_filename</em></code> when it gets generated.</td>
- </tr>
- </table>
-
- <h3 id="graphics-api">Graphics API</h3>
-
- <p>Renderscript provides a number of graphics APIs for hardware-accelerated 3D rendering. The
- Renderscript graphics APIs include a stateful context, {@link
- android.renderscript.RenderScriptGL} that contains the current rendering state. The primary state
- consists of the objects that are attached to the rendering context, which are the graphics Renderscript
- and the four program types. The main working function of the graphics Renderscript is the code that is
- defined in the <code>root()</code> function. The <code>root()</code> function is called each time the surface goes through a frame
- refresh. The four program types mirror a traditional graphical rendering pipeline and are:</p>
-
- <ul>
- <li>Vertex</li>
-
- <li>Fragment</li>
-
- <li>Store</li>
-
- <li>Raster</li>
- </ul>
-
- <p>Graphical scripts have more properties beyond a basic computational script, and they call the
- 'rsg'-prefixed functions defined in the <code>rs_graphics.rsh</code> header file. A graphics
- Renderscript can also set four pragmas that control the default bindings to the {@link
- android.renderscript.RenderScriptGL} context when the script is executing:</p>
-
- <ul>
- <li>stateVertex</li>
-
- <li>stateFragment</li>
-
- <li>stateRaster</li>
-
- <li>stateStore</li>
- </ul>
-
- <p>The possible values are <code>parent</code> or <code>default</code> for each pragma. Using
- <code>default</code> says that when a script is executed, the bindings to the graphical context
- are the system defaults. Using <code>parent</code> says that the state should be the same as it
- is in the calling script. If this is a root script, the parent
- state is taken from the bind points as set in the {@link android.renderscript.RenderScriptGL}
- bind methods in the control environment (VM environment).</p>
-
- <p>For example, you can define this at the top of your native graphics Renderscript code:</p>
- <pre>
-#pragma stateVertex(parent)
-#pragma stateStore(parent)
-</pre>
-
- <p>The following table describes the major graphics specific APIs that are available to you:</p>
-
- <table>
- <tr>
- <th>Android Object Type</th>
-
- <th>Renderscript Native Type</th>
-
- <th>Description</th>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.ProgramVertex}</td>
-
- <td>rs_program_vertex</td>
-
- <td>
- <p>The Renderscript vertex program, also known as a vertex shader, describes the stage in the
- graphics pipeline responsible for manipulating geometric data in a user-defined way. The
- object is constructed by providing Renderscript with the following data:</p>
-
- <ul>
- <li>An Element describing its varying inputs or attributes</li>
-
- <li>GLSL shader string that defines the body of the program</li>
-
- <li>a Type that describes the layout of an Allocation containing constant or uniform
- inputs</li>
- </ul>
-
- <p>Once the program is created, bind it to the {@link android.renderscript.RenderScriptGL}
- graphics context by calling
- {@link android.renderscript.RenderScriptGL#bindProgramVertex bindProgramVertex()}. It is then used for all
- subsequent draw calls until you bind a new program. If the program has constant inputs, the
- user needs to bind an allocation containing those inputs. The allocation's type must match
- the one provided during creation. The Renderscript library then does all the necessary
- plumbing to send those constants to the graphics hardware. Varying inputs to the shader,
- such as position, normal, and texture coordinates are matched by name between the input
- Element and the Mesh object being drawn. The signatures don't have to be exact or in any
- strict order. As long as the input name in the shader matches a channel name and size
- available on the mesh, the run-time would take care of connecting the two. Unlike OpenGL,
- there is no need to link the vertex and fragment programs.</p>
- <p> To bind shader constructs to the Program, declare a struct containing the necessary shader constants in your native Renderscript code.
- This struct is generated into a reflected class that you can use as a constant input element
- during the Program's creation. It is an easy way to create an instance of this struct as an allocation.
- You would then bind this Allocation to the Program and the Renderscript system sends the data that
- is contained in the struct to the hardware when necessary. To update shader constants, you change the values
- in the Allocation and notify the native Renderscript code of the change.</p>
- </td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.ProgramFragment}</td>
-
- <td>rs_program_fragment</td>
-
- <td><p>The Renderscript fragment program, also known as the fragment shader, is responsible for
- manipulating pixel data in a user-defined way. It's constructed from a GLSL shader string
- containing the program body, textures inputs, and a Type object describing the constants used
- by the program. Like the vertex programs, when an allocation with constant input values is
- bound to the shader, its values are sent to the graphics program automatically. Note that the
- values inside the allocation are not explicitly tracked. If they change between two draw
- calls using the same program object, notify the runtime of that change by calling
- rsgAllocationSyncAll so it could send the new values to hardware. Communication between the
- vertex and fragment programs is handled internally in the GLSL code. For example, if the
- fragment program is expecting a varying input called varTex0, the GLSL code inside the
- program vertex must provide it.</p>
- <p> To bind shader constructs to the this Program, declare a struct containing the necessary shader constants in your native Renderscript code.
- This struct is generated into a reflected class that you can use as a constant input element
- during the Program's creation. It is an easy way to create an instance of this struct as an allocation.
- You would then bind this Allocation to the Program and the Renderscript system sends the data that
- is contained in the struct to the hardware when necessary. To update shader constants, you change the values
- in the Allocation and notify the native Renderscript code of the change.</p></td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.ProgramStore}</td>
-
- <td>rs_program_store</td>
-
- <td>The Renderscript ProgramStore contains a set of parameters that control how the graphics
- hardware writes to the framebuffer. It could be used to enable and disable depth writes and
- testing, setup various blending modes for effects like transparency and define write masks
- for color components.</td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.ProgramRaster}</td>
-
- <td>rs_program_raster</td>
-
- <td>Program raster is primarily used to specify whether point sprites are enabled and to
- control the culling mode. By default back faces are culled.</td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.Sampler}</td>
-
- <td>rs_sampler</td>
-
- <td>A Sampler object defines how data is extracted from textures. Samplers are bound to
- Program objects (currently only a Fragment Program) alongside the texture whose sampling they
- control. These objects are used to specify such things as edge clamping behavior, whether
- mip-maps are used and the amount of anisotropy required. There may be situations where
- hardware limitations prevent the exact behavior from being matched. In these cases, the
- runtime attempts to provide the closest possible approximation. For example, the user
- requested 16x anisotropy, but only 8x was set because it's the best available on the
- hardware.</td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.Mesh}</td>
-
- <td>rs_mesh</td>
-
- <td>A collection of allocations that represent vertex data (positions, normals, texture
- coordinates) and index data such as triangles and lines. Vertex data can be interleaved
- within one allocation, provided separately as multiple allocation objects, or done as a
- combination of the above. The layout of these allocations will be extracted from their
- Elements. When a vertex channel name matches an input in the vertex program, Renderscript
- automatically connects the two. Moreover, even allocations that cannot be directly mapped to
- graphics hardware can be stored as part of the mesh. Such allocations can be used as a
- working area for vertex-related computation and will be ignored by the hardware. Parts of the
- mesh could be rendered with either explicit index sets or primitive types.</td>
- </tr>
-
- <tr>
- <td>{@link android.renderscript.Font}</td>
-
- <td>rs_font</td>
-
- <td>
- <p>This class gives you a way to draw hardware accelerated text. Internally, the glyphs are
- rendered using the Freetype library, and an internal cache of rendered glyph bitmaps is
- maintained. Each font object represents a combination of a typeface and point sizes.
- Multiple font objects can be created to represent faces such as bold and italic and to
- create different font sizes. During creation, the framework determines the device screen's
- DPI to ensure proper sizing across multiple configurations.</p>
-
- <p>Font rendering can impact performance. Even though though the state changes are
- transparent to the user, they are happening internally. It is more efficient to render
- large batches of text in sequence, and it is also more efficient to render multiple
- characters at once instead of one by one.</p>
-
- <p>Font color and transparency are not part of the font object and can be freely modified
- in the script to suit the your needs. Font colors work as a state machine, and every new
- call to draw text will use the last color set in the script.</p>
- </td>
- </tr>
- </table>
-
-
- <h2 id="developing">Developing a Renderscript application</h2>
-
- <p>The basic workflow of developing a Renderscript application is:</p>
-
- <ol>
- <li>Analyze your application's requirements and figure out what you want to develop with
- Renderscript. To take full advantage of the Renderscript system, you want to use it when the computation
- or graphics performance you're getting with the traditional framework APIs is
- insufficient.</li>
-
- <li>Design the interface of your Renderscript code and implement it using the native
- Renderscript APIs that are included in the Android SDK in
- <code><sdk_root>/platforms/android-11/renderscript</code>.</li>
-
- <li>Create an Android project as you would normally, in Eclipse or with the
- <code>android</code> tool.</li>
-
- <li>Place your Renderscript files in <code>src</code> folder of the Android project so that the
- build tools can generate the reflected layer classes.</li>
-
- <li>Create your application, calling the Renderscript through the reflected class layer when
- you need to.</li>
-
- <li>Build, install, and run your application as you would normally.</li>
- </ol>
-
- <p>To see how a simple Renderscript application is put together, see the
- <a href="{@docRoot}resources/samples/Renderscript/index.html">Renderscript samples</a>
- and <a href="#hello-graphics">The Hello Graphics Application</a> section of the documentation.</p>
-
- <h3 id="hello-graphics">The Hello Graphics Application</h3>
-
- <p>This small application demonstrates the structure of a simple Renderscript application. You
- can model your Renderscript application after the basic structure of this application. You can
- find the complete source in the SDK in the
- <code><android-sdk>/samples/android-11/HelloWorldRS directory</code>. The
- application uses Renderscript to draw the string, "Hello World!" to the screen and redraws the
- text whenever the user touches the screen at the location of the touch. This application is only
- a demonstration and you should not use the Renderscript system to do something this trivial. The
- application contains the following source files:</p>
-
- <ul>
- <li><code>HelloWorld</code>: The main Activity for the application. This class is present to
- provide Activity lifecycle management. It mainly delegates work to HelloWorldView, which is the
- Renderscript surface that the sample actually draws on.</li>
-
- <li><code>HelloWorldView</code>: The Renderscript surface that the graphics render on. If you
- are using Renderscript for graphics rendering, you must have a surface to render on. If you are
- using it for computatational operations only, then you do not need this.</li>
-
- <li><code>HelloWorldRS</code>: The class that calls the native Renderscript code through high
- level entry points that are generated by the Android build tools.</li>
-
- <li><code>helloworld.rs</code>: The Renderscript native code that draws the text on the
- screen.</li>
-
- <li>
- <p>The <code><project_root>/gen</code> directory contains the reflected layer classes
- that are generated by the Android build tools. You will notice a
- <code>ScriptC_helloworld</code> class, which is the reflective version of the Renderscript
- and contains the entry points into the <code>helloworld.rs</code> native code. This file does
- not appear until you run a build.</p>
- </li>
- </ul>
-
- <p>Each file has its own distinct use. The following files comprise the main parts of the sample and
- demonstrate in detail how the sample works:</p>
-
- <dl>
- <dt><code>helloworld.rs</code></dt>
-
- <dd>
- The native Renderscript code is contained in the <code>helloworld.rs</code> file. Every
- <code>.rs</code> file must contain two pragmas that define the version of Renderscript
- that it is using (1 is the only version for now), and the package name that the reflected
- classes should be generated with. For example:
-<pre>
-#pragma version(1)
-
-#pragma rs java_package_name(com.my.package.name)
-</pre>
- <p>An <code>.rs</code> file can also declare two special functions:</p>
-
- <ul>
- <li>
- <code>init()</code>: This function is called once for each instance of this Renderscript
- file that is loaded on the device, before the script is accessed in any other way by the
- Renderscript system. The <code>init()</code> is ideal for doing one time setup after the
- machine code is loaded such as initializing complex constant tables. The
- <code>init()</code> function for the <code>helloworld.rs</code> script sets the initial
- location of the text that is rendered to the screen:
- <pre>
-void init(){
- gTouchX = 50.0f;
- gTouchY = 50.0f;
-}
-</pre>
- </li>
-
- <li>
- <code>root()</code>: This function is the default worker function for this Renderscript
- file. For graphics Renderscript applications, like this one, the Renderscript system
- expects this function to render the frame that is going to be displayed. It is called
- every time the frame refreshes. The <code>root()</code> function for the
- <code>helloworld.rs</code> script sets the background color of the frame, the color of
- the text, and then draws the text where the user last touched the screen:
-<pre>
-int root(int launchID) {
- // Clear the background color
- rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- // Tell the runtime what the font color should be
- rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
- // Introduce ourselves to the world by drawing a greeting
- // at the position that the user touched on the screen
- rsgDrawText("Hello World!", gTouchX, gTouchY);
-
- // Return value tells RS roughly how often to redraw
- // in this case 20 ms
- return 20;
-}
-</pre>
-
- <p>The return value, <code>20</code>, is the desired frame refresh rate in milliseconds.
- The real screen refresh rate depends on the hardware, computation, and rendering
- complexity that the <code>root()</code> function has to execute. A value of
- <code>0</code> tells the screen to render only once and to only render again when a
- change has been made to one of the properties that are being modified by the Renderscript
- code.</p>
-
- <p>Besides the <code>init()</code> and <code>root()</code> functions, you can define the
- other native functions, structs, data types, and any other logic for your Renderscript.
- You can even define separate header files as <code>.rsh</code> files.</p>
- </li>
- </ul>
- </dd>
-
- <dt><code>ScriptC_helloworld</code></dt>
-
- <dd>This class is generated by the Android build tools and is the reflected version of the
- <code>helloworld.rs</code> Renderscript. It provides a high level entry point into the
- <code>helloworld.rs</code> native code by defining the corresponding methods that you can call
- from the traditional framework APIs.</dd>
-
- <dt><code>helloworld.bc</code> bytecode</dt>
-
- <dd>This file is the intermediate, platform-independent bytecode that gets compiled on the
- device when the Renderscript application runs. It is generated by the Android build tools and
- is packaged with the <code>.apk</code> file and subsequently compiled on the device at runtime.
- This file is located in the <code><project_root>/res/raw/</code> directory and is named
- <code>rs_filename.bc</code>. You need to bind these files to your Renderscript context before
- call any Renderscript code from your Android application. You can reference them in your code
- with <code>R.id.rs_filename</code>.</dd>
-
- <dt><code>HelloWorldView</code> class</dt>
-
- <dd>
- This class represents the Surface View that the Renderscript graphics are drawn on. It does
- some administrative tasks in the <code>ensureRenderScript()</code> method that sets up the
- Renderscript system. This method creates a {@link android.renderscript.RenderScriptGL}
- object, which represents the context of the Renderscript and creates a default surface to
- draw on (you can set the surface properties such as alpha and bit depth in the {@link
- android.renderscript.RenderScriptGL.SurfaceConfig} class ). When a {@link
- android.renderscript.RenderScriptGL} is instantiated, this class calls the
- <code>HelloRS</code> class and creates the instance of the actual Renderscript graphics
- renderer.
- <pre>
-// Renderscipt context
-private RenderScriptGL mRS;
-// Script that does the rendering
-private HelloWorldRS mRender;
-
- private void ensureRenderScript() {
- if (mRS == null) {
- // Initialize Renderscript with desired surface characteristics.
- // In this case, just use the defaults
- RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
- mRS = createRenderScriptGL(sc);
-
- // Create an instance of the Renderscript that does the rendering
- mRender = new HelloWorldRS();
- mRender.init(mRS, getResources());
- }
- }
-</pre>
-
- <p>This class also handles the important lifecycle events and relays touch events to the
- Renderscript renderer. When a user touches the screen, it calls the renderer,
- <code>HelloWorldRS</code> and asks it to draw the text on the screen at the new location.</p>
- <pre>
-public boolean onTouchEvent(MotionEvent ev) {
- // Pass touch events from the system to the rendering script
- if (ev.getAction() == MotionEvent.ACTION_DOWN) {
- mRender.onActionDown((int)ev.getX(), (int)ev.getY());
- return true;
- }
- return false;
-}
-</pre>
- </dd>
-
- <dt><code>HelloWorldRS</code></dt>
-
- <dd>
- This class represents the Renderscript renderer for the <code>HelloWorldView</code> Surface
- View. It interacts with the native Renderscript code that is defined in
- <code>helloworld.rs</code> through the interfaces exposed by <code>ScriptC_helloworld</code>.
- To be able to call the native code, it creates an instance of the Renderscript reflected
- class, <code>ScriptC_helloworld</code>. The reflected Renderscript object binds the
- Renderscript bytecode (<code>R.raw.helloworld</code>) and the Renderscript context, {@link
- android.renderscript.RenderScriptGL}, so the context knows to use the right Renderscript to
- render its surface.
- <pre>
-private Resources mRes;
-private RenderScriptGL mRS;
-private ScriptC_helloworld mScript;
-
-private void initRS() {
- mScript = new ScriptC_helloworld(mRS, mRes, R.raw.helloworld);
- mRS.bindRootScript(mScript);
-}
-</pre>
- </dd>
- </dl>
\ No newline at end of file
diff --git a/docs/html/guide/topics/renderscript/compute.jd b/docs/html/guide/topics/renderscript/compute.jd
new file mode 100644
index 0000000..e4c2283
--- /dev/null
+++ b/docs/html/guide/topics/renderscript/compute.jd
@@ -0,0 +1,38 @@
+page.title=Compute
+parent.title=RenderScript
+parent.link=index.html
+@jd:body
+
+ <div id="qv-wrapper">
+ <div id="qv">
+
+ <h2>Related Samples</h2>
+
+ <ol>
+ <li><a href="{@docRoot}resources/samples/RenderScript/HelloCompute/index.html">Hello
+ Compute</a></li>
+ <li><a href="{@docRoot}resources/samples/RenderScript/Balls/index.html">Balls</a></li>
+ </ol>
+ </div>
+ </div>
+
+ <p>RenderScript exposes a set of compute APIs that you can use to do intensive computational operations.
+ You can use the compute APIs in the context of a graphics RenderScript such as calculating the
+ transformation of many geometric objects in a scene. You can also create a standalone compute RenderScript that does not
+ draw anything to the screen such as bitmap image processing for a photo editor application.
+ The RenderScript compute APIs are mainly defined in the <code>rs_cl.rsh</code> header</p>
+
+ <p>Compute RenderScripts are simpler to setup and implement as there is no graphics rendering involved.
+ You can offload computational aspects of your application to RenderScript by creating a native RenderScript
+ file (.rs) and using the generated reflected layer class to call functions in the <code>.rs</code> file.
+
+ <p>See the <a href="{@docRoot}resources/samples/RenderScript/HelloCompute/index.html">HelloCompute</a>
+ sample in the Android SDK for more
+ information on how to create a simple compute RenderScript.</p>
+ <p>
+ See the <a href="{@docRoot}resources/samples/RenderScript/Balls/index.html">Balls</a>
+ sample in the Android SDK for more
+ information on how to create a compute RenderScript that is used in a graphics RenderScript.
+ The compute RenderScript is contained in
+ <a href="{@docRoot}resources/samples/RenderScript/Balls/src/com/example/android/rs/balls/ball_physics.html">balls_physics.rs</a>.
+ </p>
\ No newline at end of file
diff --git a/docs/html/guide/topics/renderscript/graphics.jd b/docs/html/guide/topics/renderscript/graphics.jd
new file mode 100644
index 0000000..d8be85f
--- /dev/null
+++ b/docs/html/guide/topics/renderscript/graphics.jd
@@ -0,0 +1,619 @@
+page.title=3D Graphics
+parent.title=RenderScript
+parent.link=index.html
+@jd:body
+
+ <div id="qv-wrapper">
+ <div id="qv">
+ <h2>In this document</h2>
+
+ <ol>
+ <li>
+ <a href="#developing">Developing a RenderScript application</a>
+
+ <ol>
+ <li><a href="#hello-graphics">The Hello Graphics application</a></li>
+ </ol>
+ </li>
+ </ol>
+
+ <h2>Related Samples</h2>
+
+ <ol>
+ <li><a href="{@docRoot}resources/samples/RenderScript/Balls/index.html">Balls</a></li>
+
+ <li><a href=
+ "{@docRoot}resources/samples/Renderscript/Fountain/index.html">Fountain</a></li>
+
+ <li><a href="{@docRoot}resources/samples/RenderScript/HelloWorld/index.html">Hello
+ World</a></li>
+
+ <li><a href="{@docRoot}resources/samples/RenderScript/Samples/index.html">Samples</a></li>
+ </ol>
+ </div>
+ </div>
+
+ <p>RenderScript provides a number of graphics APIs for 3D rendering, both at the Android
+ framework level as well as at the native level. For instance, the Android framework APIs let you
+ create meshes and define shaders to customize the graphical rendering pipeline. The native
+ RenderScript graphics APIs lets you draw the actual meshes to render your scene. In general, you
+ will need to be familiar with APIs to appropriately render 3D graphics on an Android-powered
+ device.</p>
+
+ <h2>Creating a Graphics RenderScript</h2>
+
+ <p>Because of the various layers of code when writing a RenderScript application, it is useful to
+ create the following files for a scene that you want to render:</p>
+
+ <ul>
+ <li>The native RenderScript <code>.rs</code> file. This file contains the logic to do the
+ graphics rendering.</li>
+
+ <li>The RenderScript entry point class that allows your view to interact with the code defined
+ in the <code>.rs</code> file. This class contains a RenderScript object(instance of
+ <code>ScriptC_<em>renderscript_file</em></code>), which allows your Android framework code to
+ call the native RenderScript code. This class also creates the {@link
+ android.renderscript.RenderScriptGL} context object, which contains the current rendering state
+ of the RenderScript such as programs (vertex and fragment shaders, for example) that you want
+ to define and bind to the graphics pipeline. The context object attaches to the RenderScript
+ object (instance of <code><em>ScriptC_renderscript_file</em></code>) that does the rendering.
+ Our example names this class <code>HelloWorldRS</code>.</li>
+
+ <li>Create a class that extends {@link android.renderscript.RSSurfaceView} to provide a surface
+ to render on. If you want to implement callbacks from events inherited from {@link
+ android.view.View}, such as {@link android.view.View#onTouchEvent onTouchEvent()} and {@link
+ android.view.View#onKeyDown onKeyDown()}, do so in this class as well.</li>
+
+ <li>Create a class that is the main Activity class, like you would with any Android
+ application. This class sets your {@link android.renderscript.RSSurfaceView} as the content
+ view for this Activity.</li>
+ </ul>
+
+ <p>The following sections describe how to implement these three classes by using the HelloWorld
+ RenderScript sample that is provided in the SDK as a guide (some code has been modified from its
+ original form for simplicity).</p>
+
+ <h3>Creating the native RenderScript file</h3>
+
+ <p>Your native RenderScript code resides in a <code>.rs</code> file in the
+ <code><project_root>/src/</code> directory. You can also define <code>.rsh</code> header
+ files. This code contains the logic to render your graphics and declares all necessary variables
+ and pointers. Every graphics <code>.rs</code> file generally contains the following items:</p>
+
+ <ul>
+ <li>A pragma (<code>#pragma rs java_package_name(<em>package.name</em>)</code>) that declares
+ the package name of the <code>.java</code> reflection of this RenderScript.</li>
+
+ <li>A pragma (<code>#pragma version(1)</code>) that declares the version of RenderScript that
+ you are using (1 is the only value for now).</li>
+
+ <li>A <code>#include</code> of the rs_graphics.rsh header file.</li>
+
+ <li>A <code>root()</code> function. This is the main worker function for your RenderScript and
+ calls RenderScript graphics APIs to draw meshes to the surface. This function is called every
+ time a frame refresh occurs, which is specified as its return value. A <code>0</code> specified
+ for the return value says to only render the frame when a property of the scene that you are
+ rendering changes. A non-zero positive integer specifies the refresh rate of the frame in
+ milliseconds.
+
+ <p class="note"><strong>Note:</strong> The RenderScript runtime makes its best effort to
+ refresh the frame at the specified rate. For example, if you are creating a live wallpaper
+ and set the return value to 50, the runtime renders the wallpaper at 20fps if it has just
+ enough or more resources to do so, and renders as fast as it can if it does not.</p>
+
+ <p>For more
+ information on using the RenderScript graphics functions, see <a href=
+ "using-graphics-api">Using the Graphics APIs</a>.</p>
+ </li>
+
+ <li>An <code>init()</code> function. This allows you to do any initialization of your
+ RenderScript before the <code>root()</code> function runs, such as initializing variables. This
+ function runs once and is called automatically when the RenderScript starts, before anything
+ else in your RenderScript. Creating this function is optional.</li>
+
+ <li>Any variables, pointers, and structures that you wish to use in your RenderScript code (can
+ be declared in <code>.rsh</code> files if desired)</li>
+ </ul>
+
+ <p>The following code shows how the <code>helloworld.rs</code> file is implemented:</p>
+ <pre>
+#pragma version(1)
+
+// Tell which java package name the reflected files should belong to
+#pragma rs java_package_name(com.android.rs.helloworld)
+
+// Built-in header with graphics APIs
+#include "rs_graphics.rsh"
+
+// gTouchX and gTouchY are variables that are reflected for use
+// by the Android framework API. This RenderScript uses them to be notified of touch events.
+int gTouchX;
+int gTouchY;
+
+// This is invoked automatically when the script is created and initializes the variables
+// in the Android framework layer as well.
+void init() {
+ gTouchX = 50.0f;
+ gTouchY = 50.0f;
+}
+
+int root(int launchID) {
+
+ // Clear the background color
+ rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ // Tell the runtime what the font color should be
+ rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
+ // Introuduce ourselves to the world by drawing a greeting
+ // at the position user touched on the screen
+ rsgDrawText("Hello World!", gTouchX, gTouchY);
+
+ // Return value tells RS roughly how often to redraw
+ // in this case 20 ms
+ return 20;
+}
+</pre>
+
+ <h3>Creating the RenderScript entry point class</h3>
+
+ <p>When you create a RenderScript (<code>.rs</code>) file, it is helpful to create a
+ corresponding Android framework class that is an entry point into the <code>.rs</code> file. In
+ this entry point class, you create a RenderScript object by instantiating a
+ <code>ScriptC_<em>rs_filename</em></code> and binding it to the RenderScript context. The
+ RenderScript object is attached to the RenderScript bytecode, which is platform-independent and
+ gets compiled on the device when the RenderScript application runs. Both the
+ <code>ScriptC_<em>rs_filename</em></code> class and bytecode is generated by the Android build
+ tools and is packaged with the <code>.apk</code> file. The bytecode file is located in the
+ <code><project_root>/res/raw/</code> directory and is named <code>rs_filename.bc</code>.
+ You refer to the bytecode as a resource (<code>R.raw.<em>rs_filename</em></code>). when creating
+ the RenderScript object..</p>
+
+ <p>You then bind the RenderScript object to the RenderScript context, so that the surface view
+ knows what code to use to render graphics. The following code shows how the
+ <code>HelloWorldRS</code> class is implemented:</p>
+ <pre>
+package com.android.rs.helloworld;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+
+public class HelloWorldRS {
+ //context and resources are obtained from RSSurfaceView, which calls init()
+ private Resources mRes;
+ private RenderScriptGL mRS;
+
+ //Declare the RenderScript object
+ private ScriptC_helloworld mScript;
+
+ public HelloWorldRS() {
+ }
+
+ /**
+ * This provides us with the RenderScript context and resources
+ * that allow us to create the RenderScript object
+ */
+ public void init(RenderScriptGL rs, Resources res) {
+ mRS = rs;
+ mRes = res;
+ initRS();
+ }
+ /**
+ * Calls native RenderScript functions (set_gTouchX and set_gTouchY)
+ * through the reflected layer class ScriptC_helloworld to pass in
+ * touch point data.
+ */
+ public void onActionDown(int x, int y) {
+ mScript.set_gTouchX(x);
+ mScript.set_gTouchY(y);
+ }
+ /**
+ * Binds the RenderScript object to the RenderScript context
+ */
+ private void initRS() {
+ //create the RenderScript object
+ mScript = new ScriptC_helloworld(mRS, mRes, R.raw.helloworld);
+ //bind the RenderScript object to the RenderScript context
+ mRS.bindRootScript(mScript);
+ }
+}
+
+</pre>
+
+ <h3>Creating the surface view</h3>
+
+ <p>To create a surface view to render graphics on, create a class that extends {@link
+ android.renderscript.RSSurfaceView}. This class also creates a RenderScript context object
+ ({@link android.renderscript.RenderScriptGL} and passes it to the Rendscript entry point class to
+ bind the two. The following code shows how the <code>HelloWorldView</code> class is
+ implemented:</p>
+ <pre>
+package com.android.rs.helloworld;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScriptGL;
+import android.content.Context;
+import android.view.MotionEvent;
+
+public class HelloWorldView extends RSSurfaceView {
+ // RenderScript context
+ private RenderScriptGL mRS;
+ // RenderScript entry point object that does the rendering
+ private HelloWorldRS mRender;
+
+ public HelloWorldView(Context context) {
+ super(context);
+ initRS();
+ }
+
+ private void initRS() {
+ if (mRS == null) {
+ // Initialize RenderScript with default surface characteristics.
+ RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
+ //Create the RenderScript context
+ mRS = createRenderScriptGL(sc);
+ // Create an instance of the RenderScript entry point class
+ mRender = new HelloWorldRS();
+ // Call the entry point class to bind it to this context
+ mRender.init(mRS, getResources());
+ }
+ }
+
+ /**
+ * Rebind everything when the window becomes attached
+ */
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ initRS();
+ }
+
+ /**
+ * Stop rendering when window becomes detached
+ */
+ protected void onDetachedFromWindow() {
+ // Handle the system event and clean up
+ mRender = null;
+ if (mRS != null) {
+ mRS = null;
+ destroyRenderScriptGL();
+ }
+ }
+
+ /**
+ * Use callbacks to relay data to RenderScript entry point class
+ */
+ public boolean onTouchEvent(MotionEvent ev) {
+ // Pass touch events from the system to the rendering script
+ if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+ mRender.onActionDown((int)ev.getX(), (int)ev.getY());
+ return true;
+ }
+
+ return false;
+ }
+}
+
+</pre>
+
+ <h3>Creating the Activity</h3>
+
+ <p>Applications that use RenderScript still adhere to activity lifecyle, and are part of the same
+ view hierarchy as traditional Android applications, which is handled by the Android VM. This
+ Activity class sets its view to be the {@link android.renderscript.RSSurfaceView} and handles
+ lifecycle callback events appropriately. The following code shows how the <code>HelloWorld</code>
+ class is implemented:</p>
+ <pre>
+public class HelloWorldActivity extends Activity {
+
+ //Custom view to use with RenderScript
+ private HelloWorldView view;
+
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ // Create surface view and set it as the content of our Activity
+ mView = new HelloWorldView(this);
+ setContentView(view);
+ }
+
+ protected void onResume() {
+ // Ideally an app should implement onResume() and onPause()
+ // to take appropriate action when the activity loses focus
+ super.onResume();
+ view.resume();
+ }
+
+ protected void onPause() {
+ // Ideally an app should implement onResume() and onPause()
+ // to take appropriate action when the activity loses focus
+ super.onPause();
+ view.pause();
+ }
+}
+</pre>
+
+ <h2>Drawing</h2>
+
+ <h3>Drawing using the rsgDraw functions</h3>
+
+ <p>The native RenderScript APIs provide a few convenient functions to easily draw a polygon to
+ the screen. You call these in your <code>root()</code> function to have them render to the
+ surface view. These functions are available for simple drawing and should not be used for complex
+ graphics rendering:</p>
+
+ <ul>
+ <li><code>rsgDrawRect()</code>: Sets up a mesh and draws a rectangle to the screen. It uses the
+ top left vertex and bottom right vertex of the rectangle to draw.</li>
+
+ <li><code>rsgDrawQuad()</code>: Sets up a mesh and draws a quadrilateral to the screen.</li>
+
+ <li><code>rsgDrawQuadTexCoords()</code>: Sets up a mesh and draws a textured quadrilateral to
+ the screen.</li>
+ </ul>
+
+ <h3>Drawing with a mesh</h3>
+
+ <p>When you want to draw complex shapes and textures to the screen, instantiate a {@link
+ android.renderscript.Mesh} and draw it to the screen with <code>rsgDrawMesh()</code>. A {@link
+ android.renderscript.Mesh} is a collection of allocations that represent vertex data (positions,
+ normals, texture coordinates) and index data such as triangles and lines. You can build a Mesh in
+ three different ways:</p>
+
+ <ul>
+ <li>Build the mesh with the {@link android.renderscript.Mesh.TriangleMeshBuilder} class, which
+ allows you to specify a set of vertices and indices for each triangle that you want to draw.
+ The downside of doing it this way is there is no way to specify the vertices in your native
+ RenderScript code.</li>
+
+ <li>Build the mesh using an {@link android.renderscript.Allocation} or a set of {@link
+ android.renderscript.Allocation}s with the {@link android.renderscript.Mesh.AllocationBuilder}
+ class. This allows you to build a mesh with vertices already stored in memory, which allows you
+ to set the vertices in native or Android code.</li>
+
+ <li>Build the mesh with the {@link android.renderscript.Mesh.Builder} class. This is a
+ convenience method for when you know what data types you want to use to build your mesh, but
+ don't want to make separate memory allocations like with {@link
+ android.renderscript.Mesh.AllocationBuilder}. You can specify the types that you want and this
+ mesh builder automatically creates the memory allocations for you.</li>
+ </ul>
+
+ <p>To create a mesh using the {@link android.renderscript.Mesh.TriangleMeshBuilder}, you need to
+ supply it with a set of vertices and the indices for the vertices that comprise the triangle. For
+ example, the following code specifies three vertices, which are added to an internal array,
+ indexed in the order they were added. The call to {@link
+ android.renderscript.Mesh.TriangleMeshBuilder#addTriangle addTriangle()} draws the triangle with
+ vertex 0, 1, and 2 (the vertices are drawn counter-clockwise).</p>
+ <pre>
+int float2VtxSize = 2;
+Mesh.TriangleMeshBuilder triangle = new Mesh.TriangleMeshBuilder(renderscriptGL,
+float2VtxSize, Mesh.TriangleMeshBuilder.COLOR);
+triangles.addVertex(300.f, 300.f);
+triangles.addVertex(150.f, 450.f);
+triangles.addVertex(450.f, 450.f);
+triangles.addTriangle(0 , 1, 2);
+Mesh smP = triangle.create(true);
+script.set_mesh(smP);
+</pre>
+
+ <p>To draw a mesh using the {@link android.renderscript.Mesh.AllocationBuilder}, you need to
+ supply it with one or more allocations that contain the vertex data:</p>
+ <pre>
+Allocation vertices;
+
+...
+Mesh.AllocationBuilder triangle = new Mesh.AllocationBuilder(mRS);
+smb.addVertexAllocation(vertices.getAllocation());
+smb.addIndexSetType(Mesh.Primitive.TRIANGLE);
+Mesh smP = smb.create();
+script.set_mesh(smP);
+</pre>
+
+ <p>In your native RenderScript code, draw the built mesh to the screen:</p>
+ <pre>
+rs_mesh mesh;
+...
+
+int root(){
+...
+rsgDrawMesh(mesh);
+...
+return 0; //specify a non zero, positive integer to specify the frame refresh.
+ //0 refreshes the frame only when the mesh changes.
+}
+</pre>
+
+ <h2 id="shaders">Shaders</h2>
+
+ <p>You can attach four program objects to the {@link android.renderscript.RenderScriptGL} context
+ to customize the rendering pipeline. For example, you can create vertex and fragment shaders in
+ GLSL or build a raster program object with provided methods without writing GLSL code. The four
+ program objects mirror a traditional graphical rendering pipeline:</p>
+
+ <table>
+ <tr>
+ <th>Android Object Type</th>
+
+ <th>RenderScript Native Type</th>
+
+ <th>Description</th>
+ </tr>
+
+ <tr>
+ <td>{@link android.renderscript.ProgramVertex}</td>
+
+ <td>rs_program_vertex</td>
+
+ <td>
+ <p>The RenderScript vertex program, also known as a vertex shader, describes the stage in
+ the graphics pipeline responsible for manipulating geometric data in a user-defined way.
+ The object is constructed by providing RenderScript with the following data:</p>
+
+ <ul>
+ <li>An Element describing its varying inputs or attributes</li>
+
+ <li>GLSL shader string that defines the body of the program</li>
+
+ <li>a Type that describes the layout of an Allocation containing constant or uniform
+ inputs</li>
+ </ul>
+
+ <p>Once the program is created, bind it to the {@link android.renderscript.RenderScriptGL}
+ graphics context by calling {@link android.renderscript.RenderScriptGL#bindProgramVertex
+ bindProgramVertex()}. It is then used for all subsequent draw calls until you bind a new
+ program. If the program has constant inputs, the user needs to bind an allocation
+ containing those inputs. The allocation's type must match the one provided during creation.
+ The RenderScript library then does all the necessary plumbing to send those constants to
+ the graphics hardware. Varying inputs to the shader, such as position, normal, and texture
+ coordinates are matched by name between the input Element and the Mesh object being drawn.
+ The signatures don't have to be exact or in any strict order. As long as the input name in
+ the shader matches a channel name and size available on the mesh, the run-time would take
+ care of connecting the two. Unlike OpenGL, there is no need to link the vertex and fragment
+ programs.</p>
+
+ <p>To bind shader constructs to the Program, declare a struct containing the necessary
+ shader constants in your native RenderScript code. This struct is generated into a
+ reflected class that you can use as a constant input element during the Program's creation.
+ It is an easy way to create an instance of this struct as an allocation. You would then
+ bind this Allocation to the Program and the RenderScript system sends the data that is
+ contained in the struct to the hardware when necessary. To update shader constants, you
+ change the values in the Allocation and notify the native RenderScript code of the
+ change.</p>
+ </td>
+ </tr>
+
+ <tr>
+ <td>{@link android.renderscript.ProgramFragment}</td>
+
+ <td>rs_program_fragment</td>
+
+ <td>
+ <p>The RenderScript fragment program, also known as the fragment shader, is responsible for
+ manipulating pixel data in a user-defined way. It's constructed from a GLSL shader string
+ containing the program body, textures inputs, and a Type object describing the constants
+ used by the program. Like the vertex programs, when an allocation with constant input
+ values is bound to the shader, its values are sent to the graphics program automatically.
+ Note that the values inside the allocation are not explicitly tracked. If they change
+ between two draw calls using the same program object, notify the runtime of that change by
+ calling rsgAllocationSyncAll so it could send the new values to hardware. Communication
+ between the vertex and fragment programs is handled internally in the GLSL code. For
+ example, if the fragment program is expecting a varying input called varTex0, the GLSL code
+ inside the program vertex must provide it.</p>
+
+ <p>To bind shader constants to this program, declare a struct containing the necessary
+ shader constants in your native RenderScript code. This struct is generated into a
+ reflected class that you can use as a constant input element during the Program's creation.
+ It is an easy way to create an instance of this struct as an allocation. You would then
+ bind this Allocation to the Program and the RenderScript system sends the data that is
+ contained in the struct to the hardware when necessary. To update shader constants, you
+ change the values in the Allocation and notify the native RenderScript code of the
+ change.</p>
+ </td>
+ </tr>
+
+ <tr>
+ <td>{@link android.renderscript.ProgramStore}</td>
+
+ <td>rs_program_store</td>
+
+ <td>The RenderScript ProgramStore contains a set of parameters that control how the graphics
+ hardware writes to the framebuffer. It could be used to enable and disable depth writes and
+ testing, setup various blending modes for effects like transparency and define write masks
+ for color components.</td>
+ </tr>
+
+ <tr>
+ <td>{@link android.renderscript.ProgramRaster}</td>
+
+ <td>rs_program_raster</td>
+
+ <td>Program raster is primarily used to specify whether point sprites are enabled and to
+ control the culling mode. By default back faces are culled.</td>
+ </tr>
+ </table>
+
+ <p>The following example defines a vertex shader in GLSL and binds it to the RenderScript:</p>
+ <pre>
+ private RenderScriptGL glRenderer; //rendering context
+ private ScriptField_Point mPoints; //vertices
+ private ScriptField_VpConsts mVpConsts; //shader constants
+
+ ...
+
+ ProgramVertex.Builder sb = new ProgramVertex.Builder(glRenderer);
+ String t = "varying vec4 varColor;\n" +
+ "void main() {\n" +
+ " vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n" +
+ " pos.xy = ATTRIB_position;\n" +
+ " gl_Position = UNI_MVP * pos;\n" +
+ " varColor = vec4(1.0, 1.0, 1.0, 1.0);\n" +
+ " gl_PointSize = ATTRIB_size;\n" +
+ "}\n";
+ sb.setShader(t);
+ sb.addConstant(mVpConsts.getType());
+ sb.addInput(mPoints.getElement());
+ ProgramVertex pvs = sb.create();
+ pvs.bindConstants(mVpConsts.getAllocation(), 0);
+ glRenderer.bindProgramVertex(pvs);
+
+
+</pre>
+
+ <p>The <a href=
+ "{@docRoot}resources/samples/RenderScript/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesRS.html">
+ RsRenderStatesRS</a> sample has many examples on how to create a shader without writing GLSL.</p>
+
+ <h3>Shader bindings</h3>
+
+ <p>You can also set four pragmas that control the shaders' default bindings to the {@link
+ android.renderscript.RenderScriptGL} context when the script is executing:</p>
+
+ <ul>
+ <li>stateVertex</li>
+
+ <li>stateFragment</li>
+
+ <li>stateRaster</li>
+
+ <li>stateStore</li>
+ </ul>
+
+ <p>The possible values for each pragma are <code>parent</code> or <code>default</code>. Using
+ <code>default</code> binds the shaders to the graphical context with the system defaults. The
+ default shader is defined below:</p>
+ <pre>
+("varying vec4 varColor;\n");
+("varying vec2 varTex0;\n");
+("void main() {\n");
+(" gl_Position = UNI_MVP * ATTRIB_position;\n");
+(" gl_PointSize = 1.0;\n");
+(" varColor = ATTRIB_color;\n");
+(" varTex0 = ATTRIB_texture0;\n");
+("}\n");
+</pre>
+
+ <p>Using <code>parent</code> binds the shaders in the same manner as it is bound in the calling
+ script. If this is the root script, the parent state is taken from the bind points that are set
+ by the {@link android.renderscript.RenderScriptGL} bind methods.</p>
+
+ <p>For example, you can define this at the top of your native graphics RenderScript code to have
+ the Vertex and Store shaders inherent the bind properties from their parent scripts:</p>
+ <pre>
+#pragma stateVertex(parent)
+#pragma stateStore(parent)
+</pre>
+
+ <h3>Defining a sampler</h3>
+
+ <p>A {@link android.renderscript.Sampler} object defines how data is extracted from textures.
+ Samplers are bound to Program objects (currently only a Fragment Program) alongside the texture
+ whose sampling they control. These objects are used to specify such things as edge clamping
+ behavior, whether mip-maps are used, and the amount of anisotropy required. There might be
+ situations where hardware does not support the desired behavior of the sampler. In these cases,
+ the runtime attempts to provide the closest possible approximation. For example, the user
+ requested 16x anisotropy, but only 8x was set because it's the best available on the
+ hardware.</p>
+
+ <p>The <a href=
+ "{@docRoot}resources/samples/RenderScript/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesRS.html">
+ RsRenderStatesRS</a> sample has many examples on how to create a sampler and bind it to a
+ Fragment program.</p>
+
+</body>
+</html>
diff --git a/docs/html/guide/topics/renderscript/index.jd b/docs/html/guide/topics/renderscript/index.jd
new file mode 100644
index 0000000..eb77310
--- /dev/null
+++ b/docs/html/guide/topics/renderscript/index.jd
@@ -0,0 +1,640 @@
+page.title=RenderScript
+@jd:body
+
+ <div id="qv-wrapper">
+ <div id="qv">
+ <h2>In this document</h2>
+
+ <ol>
+ <li><a href="#overview">RenderScript System Overview</a></li>
+ <li>
+ <ol>
+ <li><a href="#native">Native RenderScript layer</a></li>
+
+ <li><a href="#reflected">Reflected layer</a></li>
+
+ <li><a href="#framework">Android framework layer</a></li>
+ </ol>
+ </li>
+
+ <li>
+ <a href="#mem-allocation">Memory Allocation APIs</a>
+ </li>
+ <li>
+ <a href="#dynamic">Dynamic Memory Allocations</a>
+ <ol>
+ <li><a href="#pointers">Declaring pointers</a></li>
+
+ <li><a href="#struct-pointer-reflection">How pointers are reflected</a></li>
+
+ <li><a href="#binding">Allocating and binding memory to the RenderScript</a></li>
+
+ <li><a href="#read-write-dynamic">Reading and writing to memory</a></li>
+
+ </ol>
+ </li>
+ <li>
+ <a href="#static">Static Memory Allocations</a>
+ </li>
+ </ol>
+ </div>
+ </div>
+
+ <p>RenderScript offers a high performance 3D graphics rendering and compute API at the native
+ level, which you write in the C (C99 standard). The main advantages of RenderScript are:</p>
+ <ul>
+ <li>Portability: RenderScript is designed to run on many types of devices with different CPU
+ and GPU architectures. It supports all of these architectures without having to target each
+ device, because the code is compiled and cached on the device at runtime.</li>
+
+ <li>Performance: RenderScript provides similar performance to OpenGL with the NDK while
+ offering the portability of the OpenGL APIs provided by the Android framework ({@link
+ android.opengl}). In addition, it also offers a high performance compute API that is not
+ offered by OpenGL.</li>
+
+ <li>Usability: RenderScript simplifies development when possible, such as eliminating JNI glue code
+ and simplifying mesh setup.</li>
+ </ul>
+
+ <p>The main disadvantages are:</p>
+
+ <ul>
+ <li>Development complexity: RenderScript introduces a new set of APIs that you have to learn.
+ RenderScript also handles memory differently compared to OpenGL with the Android framework APIs
+ or NDK.</li>
+
+ <li>Debugging visibility: RenderScript can potentially execute (planned feature for later releases)
+ on processors other than the main CPU (such as the GPU), so if this occurs, debugging becomes more difficult.
+ </li>
+
+ <li>Less features: RenderScript does not provide as many features as OpenGL such as all the compressed
+ texture formats or GL extensions.</li>
+ </ul>
+
+ <p>You need to consider all of the aspects of RenderScript before deciding when to use it. The following list describes
+ general guidelines on when to use OpenGL (framework APIs or NDK) or RenderScript:</p>
+ <ul>
+ <li>If you are doing simple graphics rendering and performance is not critical, you probably want to use the
+ Android framework OpenGL APIs, which still provide adequate performance, to eliminate the added coding and debugging complexity of
+ RenderScript.</li>
+
+ <li>If you want the most flexibility and features while maintaining relatively good debugging
+ support, you probably want to use OpenGL and the NDK. Applications that require this are high end
+ or complicated games, for example.</li>
+
+ <li>If you want a solution that is portable, has good performance,
+ and you don't need the full feature set of OpenGL, RenderScript is a good solution. If you also
+ need a high performance compute language, then RenderScript offers that as well.
+ Good candidates for RenderScript are graphics intensive UIs that require 3D rendering, live wallpapers,
+ or applications that require intensive mathematical computation.</li>
+ </ul>
+
+ <p>For an example of RenderScript in action, install the RenderScript sample applications that
+ are shipped with the SDK in <code><sdk_root>/samples/android-11/RenderScript</code>.
+ You can also see a typical use of RenderScript with the 3D carousel view in the Android 3.x
+ versions of Google Books and YouTube.</p>
+
+ <h2 id="overview">RenderScript System Overview</h2>
+
+ <p>The RenderScript system adopts a control and slave architecture where the low-level native
+ code is controlled by the higher level Android system that runs in a virtual machine (VM). The
+ Android VM still retains all control of memory and lifecycle management and calls the native
+ RenderScript code when necessary. The native code is compiled to intermediate bytecode (LLVM) and
+ packaged inside your application's <code>.apk</code> file. On the device, the bytecode is
+ compiled (just-in-time) to machine code that is further optimized for the device that it is
+ running on. The compiled code on the device is cached, so subsequent uses of the RenderScript
+ enabled application do not recompile the intermediate code. RenderScript has three layers of code
+ to enable communication between the native and Android framework code:</p>
+
+ <ul>
+ <li>The native RenderScript layer does the intensive computation or graphics rendering. You
+ define your native code in <code>.rs</code> and <code>.rsh</code> files.</li>
+
+ <li>The reflected layer is a set of classes that are reflected from the native code. It is basically
+ a wrapper around the native code that allows the Android framework to interact with native RenderScripts.
+ The Android build tools automatically generate the classes for this layer during
+ the build process and eliminates the need to write JNI glue code, like with the NDK.</li>
+
+ <li>The Android framework layer is comprised of the Android framework
+ APIs, which include the {@link android.renderscript} package. This layer gives high level commands
+ like, "rotate the view" or "filter the bitmap", by calling the reflected layer, which in turn calls
+ the native layer. </li>
+ </ul>
+
+ <h3 id="native">Native RenderScript layer</h3>
+
+ <p>The native RenderScript layer consists of your RenderScript code, which is compiled and
+ executed in a compact and well defined runtime. Your RenderScript code has access to a limited
+ amount of functions because it cannot access the NDK or standard C functions, since they must be guaranteed to
+ run on a standard CPU. The RenderScript runtime was designed to run on different types of processors,
+ which may not be the CPU, so it cannot guarantee support for standard C libraries. What
+ RenderScript does offer is an API that supports intensive computation and graphics rendering with a collection of math
+ and graphics APIs.</p>
+
+ <p>Some key features of the native RenderScript libraries include:</p>
+
+ <ul>
+ <li>A large collection of math functions with both scalar and vector typed overloaded versions
+ of many common routines. Operations such as adding, multiplying, dot product, and cross product
+ are available.</li>
+
+ <li>Conversion routines for primitive data types and vectors, matrix routines, date and time
+ routines, and graphics routines.</li>
+
+ <li>Logging functions</li>
+
+ <li>Graphics rendering functions</li>
+
+ <li>Memory allocation request features</li>
+
+ <li>Data types and structures to support the RenderScript system such as Vector types for
+ defining two-, three-, or four-vectors.</li>
+ </ul>
+
+ <p>The <a href="{@docRoot}guide/topics/renderscript/rs-api/files.html">RenderScript header files</a>
+ and LLVM front-end libraries are located in the <code>include</code> and
+ <code>clang-include</code> directories in the
+ <code><sdk_root>/platforms/android-11/renderscript</code> directory of the Android SDK. The
+ headers are automatically included for you, except for the RenderScript graphics specific header file, which
+ you can include as follows:</p>
+ <pre>
+#include "rs_graphics.rsh"
+</pre>
+
+ <h3 id="reflected">Reflected layer</h3>
+
+ <p>The reflected layer is a set of classes that the Android build tools generate to allow access
+ to the native RenderScript code from the Android VM. This layer defines entry points for
+ RenderScript functions and variables, so that you can interact with them with the Android
+ framework. This layer also provides methods and constructors that allow you to allocate memory
+ for pointers that are defined in your RenderScript code. The following list describes the major
+ components that are reflected:</p>
+
+ <ul>
+ <li>Every <code>.rs</code> file that you create is generated into a class named
+ <code>ScriptC_<em>renderscript_filename</em></code> of type {@link
+ android.renderscript.ScriptC}. This is the <code>.java</code> version of your <code>.rs</code>
+ file, which you can call from the Android framework. This class contains the following
+ reflections:
+
+ <ul>
+ <li>Non-static functions in your <code>.rs</code> file.</li>
+
+ <li>Non-static, global RenderScript variables. Accessor methods are generated for each
+ variable, so you can read and write the natively declared variables from the Android
+ framework. The <code>get</code> method comes with a one-way communication restriction. The
+ last value that is set from the Android framework is always returned during a call to a
+ <code>get</code> method. If the native RenderScript code changes the value, the change does
+ not propagate back to the Android framework layer.
+ If the global variables are initialized
+ in the native RenderScript code, those values are used to initialize the corresponding
+ values in the Android framework layer. If global variables are marked as
+ <code>const</code>, then a <code>set</code> method is not generated.</li>
+ <li>Global pointers generate a special method named <code>bind_<em>pointer_name</em></code>
+ instead of a <code>set()</code> method. This method allows you to bind the memory that is
+ allocated in the Android VM for the pointer to the native RenderScript (you cannot allocate
+ memory in your <code>.rs</code> file). You can read and write to this memory from both the
+ Android framework and RenderScript code. For more information, see <a href="mem-mgmt">Working
+ with Memory and Data</a></li>
+ </ul>
+ </li>
+
+ <li>A <code>struct</code> is reflected into its own class named
+ <code>ScriptField_<em>struct_name</em></code>, which extends {@link
+ android.renderscript.Script.FieldBase}. This class represents an array of the
+ <code>struct</code>, which allows you to allocate memory for one or more instances of this
+ <code>struct</code>.</li>
+ </ul>
+
+ <h3 id="framework">Android framework layer</h3>
+
+ <p>The Android framework layer consists of the usual Android framework APIs, which include the
+ RenderScript APIs in {@link android.renderscript}. This layer handles things such as the
+ Activity lifecycle and memory management of your application. It issues high level commands to
+ the native RenderScript code through the reflected layer and receives events from the user such
+ as touch and input events and relays them to your RenderScript code, if needed.
+ </p>
+
+ <h2 id="mem-allocation">Memory Allocation APIs</h2>
+
+ <p>Before you begin writing your first RenderScript application, you must understand how
+ memory is allocated for your RenderScript code and how data is shared between the native and VM
+ spaces. RenderScript allows you to access allocated memory in both the native layer
+ and Android system layer. All dynamic and static memory is allocated by the Android VM.
+ The Android VM also does reference counting and garbage collection for you.
+ You can also explicitly free memory that you no longer need.</p>
+
+ <p class="note"><strong>Note:</strong> To declare temporary memory in your native RenderScript
+ code without allocating it in the Android VM, you can still do things like instantiate a scratch
+ buffer using an array.</p>
+
+ <p>The following classes support the memory management features of RenderScript in the Android
+ VM. You normally do not need to work with these classes directly, because the reflected layer
+ classes provide constructors and methods that set up the memory allocation for you. There are
+ some situations where you would want to use these classes directly to allocate memory on your
+ own, such as loading a bitmap from a resource or when you want to allocate memory for pointers to
+ primitive types.</p>
+
+ <table id="mem-mgmt-table">
+ <tr>
+ <th>Android Object Type</th>
+
+ <th>Description</th>
+ </tr>
+
+ <tr>
+ <td>{@link android.renderscript.Element}</td>
+
+ <td>
+ <p>An element represents one cell of a memory allocation and can have two forms: Basic or
+ Complex.</p>
+
+ <p>A basic element contains a single component of data of any valid RenderScript data type.
+ Examples of basic element data types include a single float value, a float4 vector, or a
+ single RGB-565 color.</p>
+
+ <p>Complex elements contain a list of basic elements and are created from
+ <code>struct</code>s that you declare in your RenderScript code. The most basic primitive
+ type determines the data alignment of the memory. For example, a float4 vector subelement
+ is alligned to <code>sizeof(float)</code> and not <code>sizeof(float4)</code>. The ordering
+ of the elements in memory are the order in which they were added, with each component
+ aligned as necessary.</p>
+ </td>
+ </tr>
+
+ <tr>
+ <td>{@link android.renderscript.Type}</td>
+
+ <td>
+ A type is a memory allocation template and consists of an element and one or more
+ dimensions. It describes the layout of the memory (basically an array of {@link
+ android.renderscript.Element}s) but does not allocate the memory for the data that it
+ describes.
+
+ <p>A type consists of five dimensions: X, Y, Z, LOD (level of detail), and Faces (of a cube
+ map). You can assign the X,Y,Z dimensions to any positive integer value within the
+ constraints of available memory. A single dimension allocation has an X dimension of
+ greater than zero while the Y and Z dimensions are zero to indicate not present. For
+ example, an allocation of x=10, y=1 is considered two dimensional and x=10, y=0 is
+ considered one dimensional. The LOD and Faces dimensions are booleans to indicate present
+ or not present.</p>
+ </td>
+ </tr>
+
+ <tr>
+ <td>{@link android.renderscript.Allocation}</td>
+
+ <td>
+ <p>An allocation provides the memory for applications based on a description of the memory
+ that is represented by a {@link android.renderscript.Type}. Allocated memory can exist in
+ many memory spaces concurrently. If memory is modified in one space, you must explicitly
+ synchronize the memory, so that it is updated in all the other spaces that it exists
+ in.</p>
+
+ <p>Allocation data is uploaded in one of two primary ways: type checked and type unchecked.
+ For simple arrays there are <code>copyFrom()</code> functions that take an array from the
+ Android system and copy it to the native layer memory store. The unchecked variants allow
+ the Android system to copy over arrays of structures because it does not support
+ structures. For example, if there is an allocation that is an array of n floats, the data
+ contained in a float[n] array or a byte[n*4] array can be copied.</p>
+ </td>
+ </tr>
+ </table>
+
+ <h2 id="dynamic">Working with dynamic memory allocations</h2>
+
+ <p>RenderScript has support for pointers, but you must allocate the memory in your Android framework
+ code. When you declare a global pointer in your <code>.rs</code> file, you allocate memory
+ through the appropriate reflected layer class and bind that memory to the native
+ RenderScript layer. You can read and write to this memory from the Android framework layer as well as the
+ RenderScript layer, which offers you the flexibility to modify variables in the most appropriate
+ layer. The following sections show you how to work with pointers, allocate memory for them, and
+ read and write to the memory.</p>
+
+ <h3 id="pointers">Declaring pointers</h3>
+
+ <p>Because RenderScript is written in C99, declaring a pointer is done in a familiar way. You can
+ declare pointers to a <code>struct</code> or a primitive type, but a <code>struct</code> cannot
+ contain pointers or nested arrays. The following code declares a <code>struct</code>, a pointer
+ to that <code>struct</code>, and a pointer of primitive type <code>int32_t</code> in an <code>.rs</code> file:</p>
+ <pre>
+#pragma version(1)
+#pragma rs java_package_name(com.example.renderscript)
+
+...
+
+typedef struct Point {
+ float2 point;
+ } Point_t;
+
+ Point_t *touchPoints;
+ int32_t *intPointer;
+
+...
+</pre>
+
+<p>You cannot allocate memory for these pointers in your RenderScript code, but the Android
+build tools generate classes for you that allow you to allocate memory in the Android VM for use by
+your RenderScript code. These classes also let you read and write to the memory. The next section
+describes how these classes are generated through reflection.</p>
+
+ <h3>How pointers are reflected</h3>
+
+ <p>Global variables have a getter and setter method generated. A global pointer generates a
+ <code>bind_pointerName()</code> method instead of a set() method. This method allows you to bind
+ the memory that is allocated in the Android VM to the native RenderScript. For example, the two
+ pointers in the previous section generate the following accessor methods in the <code>ScriptC_<em>rs_filename</em></code> file:</p>
+ <pre>
+
+ private ScriptField_Point mExportVar_touchPoints;
+ public void bind_touchPoints(ScriptField_Point v) {
+ mExportVar_touchPoints = v;
+ if (v == null) bindAllocation(null, mExportVarIdx_touchPoints);
+ else bindAllocation(v.getAllocation(), mExportVarIdx_touchPoints);
+ }
+
+ public ScriptField_Point get_touchPoints() {
+ return mExportVar_touchPoints;
+ }
+
+ private Allocation mExportVar_intPointer;
+ public void bind_intPointer(Allocation v) {
+ mExportVar_intPointer = v;
+ if (v == null) bindAllocation(null, mExportVarIdx_intPointer);
+ else bindAllocation(v, mExportVarIdx_intPointer);
+ }
+
+ public Allocation get_intPointer() {
+ return mExportVar_intPointer;
+ }
+
+</pre>
+
+ <h3>Allocating and binding memory to the RenderScript</h3>
+
+ <p>When the build tools generate the reflected layer, you can use the appropriate class
+ (<code>ScriptField_Point</code>, in our example) to allocate memory for a pointer. To do this,
+ you call the constructor for the {@link android.renderscript.Script.FieldBase} class and specify
+ the amount of structures that you want to allocate memory for. To allocate memory for a primitive
+ type pointer, you must build an allocation manually, using the memory management classes
+ described in <a href="mem-mgmt-table">Table 1</a>. The example below allocates memory for both
+ the <code>intPointer</code> and <code>touchPoints</code> pointer and binds it to the
+ RenderScript:</p>
+ <pre>
+private RenderScriptGL glRenderer;
+private ScriptC_example script;
+private Resources resources;
+
+public void init(RenderScriptGL rs, Resources res) {
+ //get the rendering context and resources from the calling method
+ glRenderer = rs;
+ resources = res;
+
+ //allocate memory for the struct pointer, calling the constructor
+ ScriptField_Point touchPoints = new ScriptField_Point(glRenderer, 2);
+
+ //Create an element manually and allocate memory for the int pointer
+ intPointer = Allocation.createSized(glRenderer, Element.I32(glRenderer), 2);
+
+ //create an instance of the RenderScript, pointing it to the bytecode resource
+ mScript = new ScriptC_example(glRenderer, resources, R.raw.example);
+
+ // bind the struct and int pointers to the RenderScript
+ mScript.bind_touchPoints(touchPoints);
+ script.bind_intPointer(intPointer);
+
+ //bind the RenderScript to the rendering context
+ glRenderer.bindRootScript(script);
+}
+</pre>
+
+ <h3>Reading and writing to memory</h3>
+
+ <p>Although you have to allocate memory within the Android VM, you can work with the memory both
+ in your native RenderScript code and in your Android code. Once memory is bound, the native
+ RenderScript can read and write to the memory directly. You can also just use the accessor
+ methods in the reflected classes to access the memory. If you modify memory in the Android
+ framework, it gets automatically synchronized to the native layer. If you modify memory in the <code>.rs</code>
+ file, these changes do not get propagated back to the Android framework.
+ For example, you can modify the struct in your Android code like this:</p>
+ <pre>
+int index = 0;
+boolean copyNow = true;
+Float2 point = new Float2(0.0f, 0.0f);
+touchPoints.set_point(index, point, copyNow);
+</pre>then read it in your native RenderScript code like this:
+ <pre>
+rsDebug("Printing out a Point", touchPoints[0].point.x, touchPoints[0].point.y);
+</pre>
+
+ <h2>Working with statically allocated memory</h2>
+
+ <p>Non-static, global primitives and structs that you declare in your RenderScript are easier to work with,
+ because the memory is statically allocated at compile time. Accessor methods to set and get these
+ variables are generated when the Android build tools generate the reflected layer classes. You
+ can get and set these variables using the provided accessor methods.
+ <p class="note"><strong>Note:</strong> The <code>get</code> method comes with a one-way communication restriction. The last value
+ that is set from the Android framework is always returned during a call to a <code>get</code>
+ method. If the native RenderScript code changes the value, the change does not propagate back to
+ the Android framework layer. If the global variables are initialized in the native RenderScript
+ code, those values are used to initialize the corresponding values in the Android framework
+ layer. If global variables are marked as <code>const</code>, then a <code>set</code> method is
+ not generated.</p>
+ </p>
+
+ <p>For example, if you declare the following primitive in your RenderScript code:</p>
+ <pre>
+ uint32_t unsignedInteger = 1;
+
+</pre>
+<p>then the following code is generated in <code>ScriptC_<em>script_name</em>.java</code>:</p>
+ <pre>
+ private final static int mExportVarIdx_unsignedInteger = 9;
+ private long mExportVar_unsignedInteger;
+ public void set_unsignedInteger(long v) {
+ mExportVar_unsignedInteger = v;
+ setVar(mExportVarIdx_unsignedInteger, v);
+ }
+
+ public long get_unsignedInteger() {
+ return mExportVar_unsignedInteger;
+ }
+</pre>
+
+ <p class="note"><strong>Note:</strong> The mExportVarIdx_unsignedInteger variable represents the
+ index of the <code>unsignedInteger</code>'s in an array of statically allocated primitives. You do
+ not need to work with or be aware of this index.</p>
+
+ <p>For a <code>struct</code>, the Android build tools generate a class named
+ <code><project_root>/gen/com/example/renderscript/ScriptField_struct_name</code>. This
+ class represents an array of the <code>struct</code> and allows you to allocate memory for a
+ specified number of <code>struct</code>s. This class defines:</p>
+
+ <ul>
+ <li>Overloaded constructors that allow you to allocate memory. The
+ <code>ScriptField_<em>struct_name</em>(RenderScript rs, int count)</code> constructor allows
+ you to define the number of structures that you want to allocate memory for with the
+ <code>count</code> parameter. The <code>ScriptField_<em>struct_name</em>(RenderScript rs, int
+ count, int usages)</code> constructor defines an extra parameter, <code>usages</code>, that
+ lets you specify the memory space of this memory allocation. There are four memory space
+ possibilities:
+
+ <ul>
+ <li>{@link android.renderscript.Allocation#USAGE_SCRIPT}: Allocates in the script memory
+ space. This is the default memory space if you do not specify a memory space.</li>
+
+ <li>{@link android.renderscript.Allocation#USAGE_GRAPHICS_TEXTURE}: Allocates in the
+ texture memory space of the GPU.</li>
+
+ <li>{@link android.renderscript.Allocation#USAGE_GRAPHICS_VERTEX}: Allocates in the vertex
+ memory space of the GPU.</li>
+
+ <li>{@link android.renderscript.Allocation#USAGE_GRAPHICS_CONSTANTS}: Allocates in the
+ constants memory space of the GPU that is used by the various program objects.</li>
+ </ul>
+
+ <p>You can specify one or all of these memory spaces by OR'ing them together. Doing so notifies
+ the RenderScript runtime that you intend on accessing the data in the specified memory spaces. The following
+ example allocates memory for a custom data type in both the script and vertex memory spaces:</p>
+<pre>
+ScriptField_Point touchPoints = new ScriptField_Point(glRenderer, 2,
+Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_VERTEX);
+</pre>
+
+ <p>If you modify the memory in one memory space and want to push the updates to the rest of
+ the memory spaces, call <code>rsgAllocationSyncAll()</code> in your RenderScript code to
+ synchronize the memory.</p>
+ </li>
+
+ <li>A static nested class, <code>Item</code>, allows you to create an instance of the
+ <code>struct</code>, in the form of an object. This is useful if it makes more sense to work
+ with the <code>struct</code> in your Android code. When you are done manipulating the object,
+ you can push the object to the allocated memory by calling <code>set(Item i, int index, boolean
+ copyNow)</code> and setting the <code>Item</code> to the desired position in the array. The
+ native RenderScript code automatically has access to the newly written memory.
+
+ <li>Accessor methods to get and set the values of each field in a struct. Each of these
+ accessor methods have an <code>index</code> parameter to specify the <code>struct</code> in the
+ array that you want to read or write to. Each setter method also has a <code>copyNow</code>
+ parameter that specifies whether or not to immediately sync this memory to the native
+ RenderScript layer. To sync any memory that has not been synced, call <code>copyAll()</code>.</li>
+
+ <li>The createElement() method creates an object that describes the memory layout of the struct.</li>
+
+ <li>resize() works much like a <code>realloc</code>, allowing you to expand previously
+ allocated memory, maintaining the current values that were previously set.</li>
+
+ <li>copyAll() synchronizes memory that was set on the framework level to the native level. When you call
+ a set accessor method on a member, there is an optional <code>copyNow</code> boolean parameter that you can specify. Specifying
+ <code>true</code> synchronizes the memory when you call the method. If you specify false, you can call <code>copyAll()</code>
+ once, and it synchronizes memory for the all the properties that are not synchronized.</li>
+ </ul>
+
+ <p>The following example shows the reflected class, <code>ScriptField_Point.java</code> that is
+ generated from the Point <code>struct</code>.</p>
+ <pre>
+package com.example.renderscript;
+
+import android.renderscript.*;
+import android.content.res.Resources;
+
+
+public class ScriptField_Point extends android.renderscript.Script.FieldBase {
+ static public class Item {
+ public static final int sizeof = 8;
+
+ Float2 point;
+
+ Item() {
+ point = new Float2();
+ }
+
+ }
+
+ private Item mItemArray[];
+ private FieldPacker mIOBuffer;
+ public static Element createElement(RenderScript rs) {
+ Element.Builder eb = new Element.Builder(rs);
+ eb.add(Element.F32_2(rs), "point");
+ return eb.create();
+ }
+
+ public ScriptField_Point(RenderScript rs, int count) {
+ mItemArray = null;
+ mIOBuffer = null;
+ mElement = createElement(rs);
+ init(rs, count);
+ }
+
+ public ScriptField_Point(RenderScript rs, int count, int usages) {
+ mItemArray = null;
+ mIOBuffer = null;
+ mElement = createElement(rs);
+ init(rs, count, usages);
+ }
+
+ private void copyToArray(Item i, int index) {
+ if (mIOBuffer == null) mIOBuffer = new FieldPacker(Item.sizeof * getType().getX()/* count */);
+ mIOBuffer.reset(index * Item.sizeof);
+ mIOBuffer.addF32(i.point);
+ }
+
+ public void set(Item i, int index, boolean copyNow) {
+ if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */];
+ mItemArray[index] = i;
+ if (copyNow) {
+ copyToArray(i, index);
+ mAllocation.setFromFieldPacker(index, mIOBuffer);
+ }
+
+ }
+
+ public Item get(int index) {
+ if (mItemArray == null) return null;
+ return mItemArray[index];
+ }
+
+ public void set_point(int index, Float2 v, boolean copyNow) {
+ if (mIOBuffer == null) mIOBuffer = new FieldPacker(Item.sizeof * getType().getX()/* count */)fnati;
+ if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */];
+ if (mItemArray[index] == null) mItemArray[index] = new Item();
+ mItemArray[index].point = v;
+ if (copyNow) {
+ mIOBuffer.reset(index * Item.sizeof);
+ mIOBuffer.addF32(v);
+ FieldPacker fp = new FieldPacker(8);
+ fp.addF32(v);
+ mAllocation.setFromFieldPacker(index, 0, fp);
+ }
+
+ }
+
+ public Float2 get_point(int index) {
+ if (mItemArray == null) return null;
+ return mItemArray[index].point;
+ }
+
+ public void copyAll() {
+ for (int ct = 0; ct < mItemArray.length; ct++) copyToArray(mItemArray[ct], ct);
+ mAllocation.setFromFieldPacker(0, mIOBuffer);
+ }
+
+ public void resize(int newSize) {
+ if (mItemArray != null) {
+ int oldSize = mItemArray.length;
+ int copySize = Math.min(oldSize, newSize);
+ if (newSize == oldSize) return;
+ Item ni[] = new Item[newSize];
+ System.arraycopy(mItemArray, 0, ni, 0, copySize);
+ mItemArray = ni;
+ }
+
+ mAllocation.resize(newSize);
+ if (mIOBuffer != null) mIOBuffer = new FieldPacker(Item.sizeof * getType().getX()/* count */);
+ }
+
+}
+</pre>
+
+</body>
+</html>
diff --git a/docs/html/guide/topics/resources/animation-resource.jd b/docs/html/guide/topics/resources/animation-resource.jd
index 972dd72..3df669c 100644
--- a/docs/html/guide/topics/resources/animation-resource.jd
+++ b/docs/html/guide/topics/resources/animation-resource.jd
@@ -5,28 +5,348 @@
<div id="qv-wrapper">
<div id="qv">
+ <h2>In this document</h2>
+ <ol>
+ <li><a href="#Property">Property Animation</a></li>
+ <li><a href="#View">View Animation</a>
+ <ol>
+ <li><a href="Tween">Tween animation</li>
+ <li><a href="Frame">Frame animation</li>
+ </ol>
+ </li>
+ </ol>
<h2>See also</h2>
<ol>
- <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D
-Graphics</a></li>
+ <li><a href="{@docRoot}guide/topics/graphics/view-animation.html">View Animation</a></li>
+ <li><a href="{@docRoot}guide/topics/graphics/animation.html">Property Animation</a></li>
</ol>
</div>
</div>
<p>An animation resource can define one of two types of animations:</p>
+
<dl>
- <dt><a href="#Tween">Tween Animation</a></dt>
- <dd>Creates an animation by performing a series of transformations on a single image.
- An {@link android.view.animation.Animation}.</dd>
- <dt><a href="#Frame">Frame Animation</a></dt>
- <dd>Creates an animation by showing a sequence of images in order.
- An {@link android.graphics.drawable.AnimationDrawable}.</dd>
+ <dt><a href="#Property">Property Animation</a></dt>
+ <dd>Creates an animation by modifying an object's property values over a set period
+ of time with an {@link android.animation.Animator}.</dd>
+ <dt><a href="#View">View Animation</a></dt>
+ <dd>
+ <p>There are two types of animations that you can do with the view animation framework:</p>
+ <ul>
+ <li><a href="#Tween">Tween animation</a>: Creates an animation by performing a series of transformations on a single image
+ with an {@link android.view.animation.Animation}</li>
+ <li><a href="#Frame">Frame animation</a>: or creates an animation by showing a sequence of images in order
+ with an {@link android.graphics.drawable.AnimationDrawable}.</li>
+ </ul>
+ </dd>
</dl>
+<h2 id="Property">Property Animation</h2>
+<p>An animation defined in XML that modifies properties of the target object, such as
+background color or alpha value, over a set amount of time.</p>
-<h2 id="Tween">Tween Animation</h2>
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/animator/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.animation.ValueAnimator}, {@link android.animation.ObjectAnimator},
+or {@link android.animation.AnimatorSet}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.animator.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]animator/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<<a href="#animator-set-element">set</a>
+ android:ordering=["together" | "sequentially"]>
+
+ <<a href="#obj-animator-element">objectAnimator</a>
+ android:propertyName="<em>string</em>"
+ android:duration="<em>int</em>"
+ android:valueFrom="<em>float</em> | <em>int</em> | <em>color</em>"
+ android:valueTo="<em>float</em> | <em>int</em> | <em>color</em>"
+ android:startOffset="<em>int</em>"
+ android:repeatCount="<em>int</em>"
+ android:repeatMode=["repeat" | "reverse"]
+ android:valueType=["intType" | "floatType"]/>
+
+ <<a href="#val-animator-element">animator</a>
+ android:duration="<em>int</em>"
+ android:valueFrom="<em>float</em> | <em>int</em> | <em>color</em>"
+ android:valueTo="<em>float</em> | <em>int</em> | <em>color</em>"
+ android:startOffset="<em>int</em>"
+ android:repeatCount="<em>int</em>"
+ android:repeatMode=["repeat" | "reverse"]
+ android:valueType=["intType" | "floatType"]/>
+
+ <<a href="#animator-set-element">set</a>>
+ ...
+ </set>
+</set>
+</pre>
+
+<p>The file must have a single root element: either
+<code><set></code>, <code><objectAnimator></code>, or <code><valueAnimator></code>. You can
+group animation elements together inside the <code><set></code> element, including other
+<code><set></code> elements.
+</p>
+</dd>
+
+<dt>elements:</dt>
+ <dd>
+ <dl class="tag-list">
+ <dt id="animator-set-element"><code><set></code></dt>
+ <dd>A container that holds other animation elements (<code><objectAnimator></code>,
+ <code><valueAnimator></code>, or other <code><set></code> elements). Represents
+ an {@link android.animation.AnimatorSet}.
+ <p>You can specify nested <code><set></code> tags to further
+ group animations together. Each <code><set></code> can define its own
+ <code>ordering</code> attribute.</p>
+
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt>
+ <code>android:ordering</code>
+ </dt>
+ <dd>
+ <em>Keyword</em>. Specifies the play ordering of animations in this set.
+ <table>
+ <tr><th>Value</th><th>Description</th></tr>
+ <tr><td><code>sequentially</code></td><td>Play animations in this set sequentially</td></tr>
+ <tr><td><code>together</code> (default)</td><td>Play animations in this set at the same time.</td></tr>
+ </table>
+ </dd>
+ </dl>
+ </dd>
+
+ <dt id="obj-animator-element"><code><objectAnimator></code></dt>
+ <dd>Animates a specific property of an object over a specific amount of time. Represents
+ an {@link android.animation.ObjectAnimator}.</p>
+
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt>
+ <code>android:propertyName</code>
+ </dt>
+ <dd>
+ <em>String</em>. <strong>Required</strong>. The object's property to animate, referenced by its name. For example you can specify
+ <code>"alpha"</code> or <code>"backgroundColor"</code> for a View object.
+ The <code>objectAnimator</code> element does not expose a <code>target</code>
+ attribute, however, so you cannot set the object to animate in the XML declaration. You have to
+ inflate your animation XML resource by calling {@link android.animation.AnimatorInflater#loadAnimator
+ loadAnimator()} and call {@link android.animation.ObjectAnimator#setTarget setTarget()} to set
+ the target object that contains this property.
+ </dd>
+
+ <dt>
+ <code>android:valueTo</code>
+ </dt>
+ <dd>
+ <em>float, int, or color</em>. <strong>Required</strong>. The value where the animated property ends. Colors are represented
+ as six digit hexadecimal numbers (for example, #333333).
+ </dd>
+
+ <dt>
+ <code>android:valueFrom</code>
+ </dt>
+ <dd>
+ <em>float, int, or color</em>. The value where the animated property starts. If not
+ specified, the animation starts at the value obtained by the property's get method. Colors are represented
+ as six digit hexadecimal numbers (for example, #333333).
+ </dd>
+
+ <dt>
+ <code>android:duration</code>
+ </dt>
+ <dd>
+ <em>int</em>. The time in milliseconds of the animation. 300 milliseconds is the default.
+ </dd>
+
+ <dt>
+ <code>android:startOffset</code>
+ </dt>
+ <dd>
+ <em>int</em>. The amount of milliseconds the animation delays after
+ {@link android.animation.ObjectAnimator#start start()} is called.
+ </dd>
+
+ <dt>
+ <code>android:repeatCount</code>
+ </dt>
+ <dd>
+ <em>int</em>. How many times to repeat an animation. Set to <code>"-1"</code> to infinitely
+ repeat or to a positive integer. For example, a value of <code>"1"</code> means that the animation
+ is repeated once after the initial run of the animation, so the animation plays a total
+ of two times. The default value is <code>"0"</code>, which means no repetition.
+
+ </dd>
+
+ <dt>
+ <code>android:repeatMode</code>
+ </dt>
+ <dd>
+ <em>int</em>. How an animation behaves when it reaches the end of the animation. <code>android:repeatCount</code>
+ must be set to a positive integer or <code>"-1"</code> for this attribute to have an effect. Set to <code>"reverse"</code>
+ to have the animation reverse direction with each iteration or <code>"repeat"</code> to have the animation
+ loop from the beginning each time.
+ </dd>
+
+ <dt>
+ <code>android:valueType</code>
+ </dt>
+ <dd>
+ <em>Keyword</em>. Do not specify this attribute if the value is a color. The animation framework automatically handles color
+ values
+ <table>
+ <tr><th>Value</th><th>Description</th></tr>
+ <tr><td><code>intType</code></td><td>Specifies that the animated values are integers</td></tr>
+ <tr><td><code>floatType</code> (default)</td><td>Specifies that the animated values are floats</td></tr>
+ </table>
+ </dd>
+
+ </dl>
+ </dd>
+
+<dt id="val-animator-element"><code><animator></code></dt>
+ <dd>Animates a over a specified amount of time.
+ Represents a {@link android.animation.ValueAnimator}.
+
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt>
+ <code>android:valueTo</code>
+ </dt>
+ <dd>
+ <em>float, int, or color</em>. <strong>Required</strong>. The value where the animation ends. Colors are represented
+ as six digit hexadecimal numbers (for example, #333333).
+ </dd>
+
+ <dt>
+ <code>android:valueFrom</code>
+ </dt>
+ <dd>
+ <em>float, int, or color</em>. <strong>Required</strong>. The value where the animation starts. Colors are represented
+ as six digit hexadecimal numbers (for example, #333333).
+ </dd>
+
+ <dt>
+ <code>android:duration</code>
+ </dt>
+ <dd>
+ <em>int</em>. The time in milliseconds of the animation. 300ms is the default.
+ </dd>
+
+ <dt>
+ <code>android:startOffset</code>
+ </dt>
+ <dd>
+ <em>int</em>. The amount of milliseconds the animation delays after
+ {@link android.animation.ValueAnimator#start start()} is called.
+ </dd>
+
+ <dt>
+ <code>android:repeatCount</code>
+ </dt>
+ <dd>
+ <em>int</em>. How many times to repeat an animation. Set to <code>"-1"</code> to infinitely
+ repeat or to a positive integer. For example, a value of <code>"1"</code> means that the animation
+ is repeated once after the initial run of the animation, so the animation plays a total
+ of two times. The default value is <code>"0"</code>, which means no repetition.
+ </dd>
+
+ <dt>
+ <code>android:repeatMode</code>
+ </dt>
+ <dd>
+ <em>int</em>. How an animation behaves when it reaches the end of the animation. <code>android:repeatCount</code>
+ must be set to a positive integer or <code>"-1"</code> for this attribute to have an effect. Set to <code>"reverse"</code>
+ to have the animation reverse direction with each iteration or <code>"repeat"</code> to have the animation
+ loop from the beginning each time.
+ </dd>
+
+ <dt>
+ <code>android:valueType</code>
+ </dt>
+ <dd>
+ <em>Keyword</em>. Do not specify this attribute if the value is a color. The animation framework automatically handles color
+ values.
+ <table>
+ <tr><th>Value</th><th>Description</th></tr>
+ <tr><td><code>intType</code></td><td>Specifies that the animated values are integers</td></tr>
+ <tr><td><code>floatType</code> (default)</td><td>Specifies that the animated values are floats</td></tr>
+ </table>
+ </dd>
+
+ </dl>
+ </dd>
+ </dl>
+
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>
+ <pp>XML file saved at <code>res/animator/property_animator.xml</code>:</p>
+<pre>
+<set android:ordering="sequentially">
+ <set>
+ <objectAnimator
+ android:propertyName="x"
+ android:duration="500"
+ android:valueTo="400"
+ android:valueType="intType"/>
+ <objectAnimator
+ android:propertyName="y"
+ android:duration="500"
+ android:valueTo="300"
+ android:valueType="intType"/>
+ </set>
+ <objectAnimator
+ android:propertyName="alpha"
+ android:duration="500"
+ android:valueTo="1f"/>
+</set>
+</pre>
+ <p>In order to run this animation, you must inflate the XML resources in your code to an {@link
+ android.animation.AnimatorSet} object, and then set the target objects for all of the animations
+ before starting the animation set. Calling {@link android.animation.AnimatorSet#setTarget
+ setTarget()} sets a single target object for all children of the {@link
+ android.animation.AnimatorSet} as a convenience. The following code shows how to do this:</p>
+
+<pre>
+AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
+ R.anim.property_animator);
+set.setTarget(myObject);
+set.start();
+</pre>
+
+
+</dd> <!-- end example -->
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li><a href="{@docRoot}guide/topics/graphics/animation.html">Property Animation</a></li>
+ <li><a href="http://zoso:8080/resources/samples/ApiDemos/src/com/example/android/apis/animation/index.html">API Demos</a> for examples
+ on how to use the property animation system.</li>
+</ul>
+</dd>
+
+</dl>
+
+<h2 id="View">View Animation</h2>
+The view animation framework supports both tween and frame by frame animations, which can both be declared
+in XML. The following sections describe how to use both methods.
+
+<h3 id="Tween">Tween animation</h3>
<p>An animation defined in XML that performs transitions such as rotating,
fading, moving, and stretching on a graphic.
@@ -254,18 +574,14 @@
<dt>see also:</dt>
<dd>
<ul>
- <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D
+ <li><a href="{@docRoot}guide/topics/graphics/view-animation.html#tween-animation">2D
Graphics: Tween Animation</a></li>
</ul>
</dd>
</dl>
-
-
-
-
-<h3 id="Interpolators">Interpolators</h3>
+<h4 id="Interpolators">Interpolators</h4>
<p>An interpolator is an animation modifier defined in XML that affects the rate of change in an
animation. This allows your existing animation effects to be accelerated, decelerated, repeated,
@@ -456,22 +772,7 @@
</dl>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-<h2 id="Frame">Frame Animation</h2>
+<h3 id="Frame">Frame animation</h3>
<p>An animation defined in XML that shows a sequence of images in order (like a film).
</p>
@@ -562,7 +863,11 @@
</dl>
</dd> <!-- end example -->
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li><a href="{@docRoot}guide/topics/graphics/view-animation.html#frame-animation">2D
+Graphics: Frame Animation</a></li>
+</ul>
+</dd>
</dl>
-
-
-
diff --git a/docs/html/guide/topics/resources/providing-resources.jd b/docs/html/guide/topics/resources/providing-resources.jd
index 59f2e73..a996ccc 100644
--- a/docs/html/guide/topics/resources/providing-resources.jd
+++ b/docs/html/guide/topics/resources/providing-resources.jd
@@ -333,6 +333,86 @@
indicates the current locale.</p>
</td>
</tr>
+ <tr id="SmallestScreenWidthQualifier">
+ <td>Smallest screen width</td>
+ <td>Examples:<br/>
+ <code>sw320dp</code><br/>
+ <code>sw600dp</code><br/>
+ <code>sw720dp</code><br/>
+ etc.
+ </td>
+ <td>
+ <p>Specifies a minimum "smallest screen width," in "dp" units, at which the resource
+ should be used. This configuration value represents the base screen size
+ of the device, regardless of the orientation of the display. It is based
+ on the smallest width the application will have in which to perform its
+ UI layout (in dp units) regardless of the orientation of the screen. The
+ value here takes into account screen decorations so if the device has some
+ persistent UI elements on the left or right edge of the display it must
+ present a value here that is smaller than the real screen size, accounting
+ for these UI elements reducing the application's available space.</p>
+ <p>Some values you may use here for common screen sizes:</p>
+ <ul>
+ <li>240x320 ldpi (QVGA phone): 320
+ <li>320x480 mdpi (phone): 320
+ <li>480x800 hdpi (high density phone): 320
+ <li>480x800 mdpi (tablet/phone): 480
+ <li>600x1024 mdpi (7" tablet): 600
+ <li>720x1280 mdpi (10" tablet): 720
+ </ul>
+ <p><em>Added in API Level 13.</em></p>
+ <p>Also see the {@link android.content.res.Configuration#smallestScreenWidthDp}
+ configuration field, which holds the current smallest screen width.</p>
+ </td>
+ </tr>
+ <tr id="ScreenWidthQualifier">
+ <td>Screen width</td>
+ <td>Examples:<br/>
+ <code>w720dp</code><br/>
+ <code>w1024dp</code><br/>
+ etc.
+ </td>
+ <td>
+ <p>Specifies a minimum screen width, in "dp" units, at which the resource
+ should be used. This configuration value will change when the orientation
+ changes between landscape and portrait to match the current actual width.
+ When multiple screen width configurations are available, the closest to
+ the current screen width will be used. The
+ value here takes into account screen decorations so if the device has some
+ persistent UI elements on the left or right edge of the display it must
+ present a value here that is smaller than the real screen size, accounting
+ for these UI elements reducing the application's available space.</p>
+ <p><em>Added in API Level 13.</em></p>
+ <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
+ configuration field, which holds the current screen width.</p>
+ </td>
+ </tr>
+ <tr id="ScreenHeightQualifier">
+ <td>Screen height</td>
+ <td>Examples:<br/>
+ <code>h720dp</code><br/>
+ <code>h1024dp</code><br/>
+ etc.
+ </td>
+ <td>
+ <p>Specifies a minimum screen height, in "dp" units, at which the resource
+ should be used. This configuration value will change when the orientation
+ changes between landscape and portrait to match the current actual height.
+ When multiple screen height configurations are available, the closest to
+ the current screen height will be used. The
+ value here takes into account screen decorations so if the device has some
+ persistent UI elements on the left or right edge of the display it must
+ present a value here that is smaller than the real screen size, accounting
+ for these UI elements reducing the application's available space. Screen
+ decorations that are not fixed (such as a phone status bar that can be
+ hidden when full screen) are <em>not</em> accounted for here, nor are
+ window decorations like title bar, so applications must be prepared to
+ deal with a somewhat smaller space than they specify.
+ <p><em>Added in API Level 13.</em></p>
+ <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
+ configuration field, which holds the current screen width.</p>
+ </td>
+ </tr>
<tr id="ScreenSizeQualifier">
<td>Screen size</td>
<td>
@@ -392,46 +472,6 @@
which indicates whether the screen is long.</p>
</td>
</tr>
- <tr id="ScreenWidthQualifier">
- <td>Screen width</td>
- <td>Examples:<br/>
- <code>w720dp</code><br/>
- <code>w1024dp</code><br/>
- etc.
- </td>
- <td>
- <p>Specifies a minimum screen width, in "dp" units, at which the resource
- should be used. This configuration value will change when the orientation
- changes between landscape and portrait to match the current actual width.
- When multiple screen width configurations are available, the closest to
- the current screen width will be used. The value specified here is
- approximate; screen decorations like a status bar or system bar may cause
- the actual space available in your UI to be slightly smaller.
- <p><em>Added in API Level 13.</em></p>
- <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
- configuration field, which holds the current screen width.</p>
- </td>
- </tr>
- <tr id="ScreenHeightQualifier">
- <td>Screen height</td>
- <td>Examples:<br/>
- <code>h720dp</code><br/>
- <code>h1024dp</code><br/>
- etc.
- </td>
- <td>
- <p>Specifies a minimum screen height, in "dp" units, at which the resource
- should be used. This configuration value will change when the orientation
- changes between landscape and portrait to match the current actual height.
- When multiple screen height configurations are available, the closest to
- the current screen height will be used. The value specified here is
- approximate; screen decorations like a status bar or system bar may cause
- the actual space available in your UI to be slightly smaller.
- <p><em>Added in API Level 13.</em></p>
- <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
- configuration field, which holds the current screen width.</p>
- </td>
- </tr>
<tr id="OrientationQualifier">
<td>Screen orientation</td>
<td>
diff --git a/docs/html/guide/topics/usb/adk.jd b/docs/html/guide/topics/usb/adk.jd
index 8aaa65c..6f23a174 100644
--- a/docs/html/guide/topics/usb/adk.jd
+++ b/docs/html/guide/topics/usb/adk.jd
@@ -55,9 +55,7 @@
</ol>
</li>
</ol>
-
-
<h2>See also</h2>
<ol>
@@ -68,6 +66,12 @@
<h2>Where to buy</h2>
<ol>
+ <li><a href="http://shop.moderndevice.com/products/freeduino-usb-host-board">
+ Modern Device</a></li>
+
+ <li><a href="http://www.seeedstudio.com/depot/seeeduino-adk-main-board-p-846.html">
+ Seeed Studio</a></li>
+
<li><a href=
"http://www.rt-net.jp/shop/index.php?main_page=product_info&cPath=3_4&products_id=1">
RT Corp</a></li>
@@ -78,6 +82,7 @@
<li><a href="https://store.diydrones.com/ProductDetails.asp?ProductCode=BR-PhoneDrone">
DIY Drones</a></li>
+
</ol>
</div>
</div>
@@ -105,13 +110,25 @@
development boards:</p>
<ul>
+ <li><a href="http://shop.moderndevice.com/products/freeduino-usb-host-board">Modern
+ Device</a> provides an Arduino-compatible board that supports the ADK firmware.</li>
+
+ <li><a href="http://www.seeedstudio.com/depot/seeeduino-adk-main-board-p-846.html">
+ Seeed Studio</a> provides an Arduino-compatible board that supports the ADK firmware.</li>
+
<li><a href="http://www.rt-net.jp/shop/index.php?main_page=product_info&cPath=3_4&products_id=1">
RT Corp</a> provides an Arduino-compatible board based on the Android ADK board design.</li>
+
<li><a href="http://www.microchip.com/android">Microchip</a> provides a A PIC based USB
microcontroller board.</li>
+
<li><a href="https://store.diydrones.com/ProductDetails.asp?ProductCode=BR-PhoneDrone">DIY
Drones</a> provides an Arduino-compatible board geared towards RC (radio controlled) and UAV
(unmanned aerial vehicle) enthusiasts.</li>
+<<<<<<< HEAD
+=======
+
+>>>>>>> c38ed22... doc change: add link to seeedstudio board
</ul>
<p>We expect more hardware distributers to create a variety of kits, so please stay tuned for
@@ -122,7 +139,7 @@
accessory that is based on the <a href="http://www.arduino.cc/">Arduino open source electronics
prototyping platform</a>, the accessory's hardware design files, code that implements the
accessory's firmware, and the Android application that interacts with the accessory. The hardware
- design files and firmware code are contained in the <a href=
+ design files and firmware code are contained in the <a href=ctive
"https://dl-ssl.google.com/android/adk/adk_release_0512.zip">ADK package download</a>.</p>
<p>The main hardware and software components of the ADK include:</p>
diff --git a/docs/html/sdk/sdk_toc.cs b/docs/html/sdk/sdk_toc.cs
index 5b90551..d02c13d 100644
--- a/docs/html/sdk/sdk_toc.cs
+++ b/docs/html/sdk/sdk_toc.cs
@@ -175,7 +175,8 @@
<span style="display:none" class="zh-TW"></span>
</h2>
<ul>
- <li><a href="<?cs var:toroot ?>sdk/ndk/index.html">Android NDK, r5b</a>
+ <li><a href="<?cs var:toroot ?>sdk/ndk/index.html">Android NDK, r5c <span
+ class="new">new!</span></a>
</li>
<li><a href="<?cs var:toroot ?>sdk/ndk/overview.html">What is the NDK?</a></li>
</ul>
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
index 3cbd8f1..07b3b47 100644
--- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
+++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
@@ -53,11 +53,11 @@
}
FwdLockEngine::FwdLockEngine() {
- LOGD("FwdLockEngine Construction");
+ LOGV("FwdLockEngine Construction");
}
FwdLockEngine::~FwdLockEngine() {
- LOGD("FwdLockEngine Destruction");
+ LOGV("FwdLockEngine Destruction");
convertSessionMap.destroyMap();
decodeSessionMap.destroyMap();
@@ -91,7 +91,7 @@
DrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* path, int action) {
DrmConstraints* drmConstraints = NULL;
- LOGD("FwdLockEngine::onGetConstraints");
+ LOGV("FwdLockEngine::onGetConstraints");
if (NULL != path &&
(RightsStatus::RIGHTS_VALID == onCheckRightsStatus(uniqueId, *path, action))) {
@@ -105,7 +105,7 @@
DrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) {
DrmMetadata* drmMetadata = NULL;
- LOGD("FwdLockEngine::onGetMetadata");
+ LOGV("FwdLockEngine::onGetMetadata");
if (NULL != path) {
// Returns empty metadata to show no error condition.
@@ -116,11 +116,11 @@
}
android::status_t FwdLockEngine::onInitialize(int uniqueId) {
- LOGD("FwdLockEngine::onInitialize");
+ LOGV("FwdLockEngine::onInitialize");
if (FwdLockGlue_InitializeKeyEncryption()) {
- LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded");
+ LOGV("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded");
} else {
LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:"
"errno = %d", errno);
@@ -132,13 +132,13 @@
android::status_t
FwdLockEngine::onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener) {
// Not used
- LOGD("FwdLockEngine::onSetOnInfoListener");
+ LOGV("FwdLockEngine::onSetOnInfoListener");
return DRM_NO_ERROR;
}
android::status_t FwdLockEngine::onTerminate(int uniqueId) {
- LOGD("FwdLockEngine::onTerminate");
+ LOGV("FwdLockEngine::onTerminate");
return DRM_NO_ERROR;
}
@@ -146,7 +146,7 @@
DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) {
DrmSupportInfo* pSupportInfo = new DrmSupportInfo();
- LOGD("FwdLockEngine::onGetSupportInfo");
+ LOGV("FwdLockEngine::onGetSupportInfo");
// fill all Forward Lock mimetypes and extensions
if (NULL != pSupportInfo) {
@@ -182,7 +182,7 @@
drmInfoStatus = new DrmInfoStatus((int)DrmInfoStatus::STATUS_OK, 0, NULL, String8(""));
- LOGD("FwdLockEngine::onProcessDrmInfo");
+ LOGV("FwdLockEngine::onProcessDrmInfo");
return drmInfoStatus;
}
@@ -193,7 +193,7 @@
const String8& rightsPath,
const String8& contentPath) {
// No rights to save. Return
- LOGD("FwdLockEngine::onSaveRights");
+ LOGV("FwdLockEngine::onSaveRights");
return DRM_ERROR_UNKNOWN;
}
@@ -201,7 +201,7 @@
DrmInfo* drmInfo = NULL;
// Nothing to be done for Forward Lock file
- LOGD("FwdLockEngine::onAcquireDrmInfo");
+ LOGV("FwdLockEngine::onAcquireDrmInfo");
return drmInfo;
}
@@ -211,7 +211,7 @@
int action) {
int result = RightsStatus::RIGHTS_INVALID;
- LOGD("FwdLockEngine::onCheckRightsStatus");
+ LOGV("FwdLockEngine::onCheckRightsStatus");
// Only Transfer action is not allowed for forward Lock files.
if (onCanHandle(uniqueId, path)) {
@@ -241,7 +241,7 @@
int action,
bool reserve) {
// No rights consumption
- LOGD("FwdLockEngine::onConsumeRights");
+ LOGV("FwdLockEngine::onConsumeRights");
return DRM_NO_ERROR;
}
@@ -249,14 +249,14 @@
const String8& path,
int action,
const ActionDescription& description) {
- LOGD("FwdLockEngine::onValidateAction");
+ LOGV("FwdLockEngine::onValidateAction");
// For the forwardlock engine checkRights and ValidateAction are the same.
return (onCheckRightsStatus(uniqueId, path, action) == RightsStatus::RIGHTS_VALID);
}
String8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path) {
- LOGD("FwdLockEngine::onGetOriginalMimeType");
+ LOGV("FwdLockEngine::onGetOriginalMimeType");
String8 mimeString = String8("");
int fileDesc = FwdLockFile_open(path.string());
@@ -280,7 +280,7 @@
const String8& mimeType) {
String8 mimeStr = String8(mimeType);
- LOGD("FwdLockEngine::onGetDrmObjectType");
+ LOGV("FwdLockEngine::onGetDrmObjectType");
mimeStr.toLower();
@@ -301,13 +301,13 @@
status_t FwdLockEngine::onRemoveRights(int uniqueId, const String8& path) {
// No Rights to remove
- LOGD("FwdLockEngine::onRemoveRights");
+ LOGV("FwdLockEngine::onRemoveRights");
return DRM_NO_ERROR;
}
status_t FwdLockEngine::onRemoveAllRights(int uniqueId) {
// No rights to remove
- LOGD("FwdLockEngine::onRemoveAllRights");
+ LOGV("FwdLockEngine::onRemoveAllRights");
return DRM_NO_ERROR;
}
@@ -319,14 +319,14 @@
int playbackStatus, int position) {
#endif
// Not used
- LOGD("FwdLockEngine::onSetPlaybackStatus");
+ LOGV("FwdLockEngine::onSetPlaybackStatus");
return DRM_NO_ERROR;
}
status_t FwdLockEngine::onOpenConvertSession(int uniqueId,
int convertId) {
status_t result = DRM_ERROR_UNKNOWN;
- LOGD("FwdLockEngine::onOpenConvertSession");
+ LOGV("FwdLockEngine::onOpenConvertSession");
if (!convertSessionMap.isCreated(convertId)) {
ConvertSession *newSession = new ConvertSession();
if (FwdLockConv_Status_OK ==
@@ -383,7 +383,7 @@
DrmBuffer *convResult = new DrmBuffer(NULL, 0);
int offset = -1;
- LOGD("FwdLockEngine::onCloseConvertSession");
+ LOGV("FwdLockEngine::onCloseConvertSession");
if (convertSessionMap.isCreated(convertId)) {
ConvertSession *convSession = convertSessionMap.getValue(convertId);
@@ -424,7 +424,7 @@
status_t result = DRM_ERROR_CANNOT_HANDLE;
int fileDesc = -1;
- LOGD("FwdLockEngine::onOpenDecryptSession");
+ LOGV("FwdLockEngine::onOpenDecryptSession");
if ((-1 < fd) &&
(NULL != decryptHandle) &&
@@ -463,7 +463,7 @@
::close(fileDesc);
}
- LOGD("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result);
+ LOGV("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result);
return result;
}
@@ -500,7 +500,7 @@
status_t FwdLockEngine::onCloseDecryptSession(int uniqueId,
DecryptHandle* decryptHandle) {
status_t result = DRM_ERROR_UNKNOWN;
- LOGD("FwdLockEngine::onCloseDecryptSession");
+ LOGV("FwdLockEngine::onCloseDecryptSession");
if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) {
DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId);
@@ -512,7 +512,7 @@
}
}
- LOGD("FwdLockEngine::onCloseDecryptSession Exit");
+ LOGV("FwdLockEngine::onCloseDecryptSession Exit");
return result;
}
@@ -520,13 +520,13 @@
DecryptHandle* decryptHandle,
int decryptUnitId,
const DrmBuffer* headerInfo) {
- LOGD("FwdLockEngine::onInitializeDecryptUnit");
+ LOGV("FwdLockEngine::onInitializeDecryptUnit");
return DRM_ERROR_UNKNOWN;
}
status_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
- LOGD("FwdLockEngine::onDecrypt");
+ LOGV("FwdLockEngine::onDecrypt");
return DRM_ERROR_UNKNOWN;
}
@@ -535,14 +535,14 @@
int decryptUnitId,
const DrmBuffer* encBuffer,
DrmBuffer** decBuffer) {
- LOGD("FwdLockEngine::onDecrypt");
+ LOGV("FwdLockEngine::onDecrypt");
return DRM_ERROR_UNKNOWN;
}
status_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId,
DecryptHandle* decryptHandle,
int decryptUnitId) {
- LOGD("FwdLockEngine::onFinalizeDecryptUnit");
+ LOGV("FwdLockEngine::onFinalizeDecryptUnit");
return DRM_ERROR_UNKNOWN;
}
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index 311f024..a4734ff 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -30,6 +30,7 @@
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
+import android.view.View;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -386,8 +387,9 @@
Shader shader = state.mPaint.getShader();
if (shader == null) {
if (mApplyGravity) {
+ final int layoutDirection = getResolvedLayoutDirectionSelf();
Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight,
- getBounds(), mDstRect, isLayoutRtlSelf());
+ getBounds(), mDstRect, layoutDirection);
mApplyGravity = false;
}
canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint);
diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java
index 83020aa..29edc04 100644
--- a/graphics/java/android/graphics/drawable/ClipDrawable.java
+++ b/graphics/java/android/graphics/drawable/ClipDrawable.java
@@ -24,6 +24,7 @@
import android.graphics.*;
import android.view.Gravity;
import android.util.AttributeSet;
+import android.view.View;
import java.io.IOException;
@@ -209,7 +210,8 @@
if ((mClipState.mOrientation & VERTICAL) != 0) {
h -= (h - ih) * (10000 - level) / 10000;
}
- Gravity.apply(mClipState.mGravity, w, h, bounds, r, isLayoutRtlSelf());
+ final int layoutDirection = getResolvedLayoutDirectionSelf();
+ Gravity.apply(mClipState.mGravity, w, h, bounds, r, layoutDirection);
if (w > 0 && h > 0) {
canvas.save();
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index 8994efc..72d233a3 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -36,6 +36,7 @@
import android.util.StateSet;
import android.util.TypedValue;
import android.util.Xml;
+import android.view.View;
import java.io.IOException;
import java.io.InputStream;
@@ -292,11 +293,11 @@
*/
public static interface Callback2 extends Callback {
/**
- * A Drawable can call this to know whether the <var>who</var> is in RTL layout direction.
+ * A Drawable can call this to get the resolved layout direction of the <var>who</var>.
*
- * @param who The drawable being unscheduled.
+ * @param who The drawable being queried.
*/
- public boolean isLayoutRtl(Drawable who);
+ public int getResolvedLayoutDirection(Drawable who);
}
/**
@@ -376,15 +377,15 @@
}
/**
- * Use the current {@link android.graphics.drawable.Drawable.Callback2} implementation to know
- * if this Drawable is having a layout in RTL direction.
+ * Use the current {@link android.graphics.drawable.Drawable.Callback2} implementation to get
+ * the resolved layout direction of this Drawable.
*/
- public boolean isLayoutRtlSelf() {
+ public int getResolvedLayoutDirectionSelf() {
final Callback callback = getCallback();
if (callback == null || !(callback instanceof Callback2)) {
- return false;
+ return View.LAYOUT_DIRECTION_LTR;
}
- return ((Callback2) callback).isLayoutRtl(this);
+ return ((Callback2) callback).getResolvedLayoutDirection(this);
}
/**
diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java
index cbe1f2d..5fd5a16 100644
--- a/graphics/java/android/graphics/drawable/ScaleDrawable.java
+++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java
@@ -24,6 +24,7 @@
import android.graphics.*;
import android.view.Gravity;
import android.util.AttributeSet;
+import android.view.View;
import java.io.IOException;
@@ -221,7 +222,8 @@
final int ih = min ? mScaleState.mDrawable.getIntrinsicHeight() : 0;
h -= (int) ((h - ih) * (10000 - level) * mScaleState.mScaleHeight / 10000);
}
- Gravity.apply(mScaleState.mGravity, w, h, bounds, r, isLayoutRtlSelf());
+ final int layoutDirection = getResolvedLayoutDirectionSelf();
+ Gravity.apply(mScaleState.mGravity, w, h, bounds, r, layoutDirection);
if (w > 0 && h > 0) {
mScaleState.mDrawable.setBounds(r.left, r.top, r.right, r.bottom);
diff --git a/libs/gui/tests/SurfaceTextureClient_test.cpp b/libs/gui/tests/SurfaceTextureClient_test.cpp
index 33fc21f..a4c5b36 100644
--- a/libs/gui/tests/SurfaceTextureClient_test.cpp
+++ b/libs/gui/tests/SurfaceTextureClient_test.cpp
@@ -32,6 +32,7 @@
virtual void SetUp() {
mST = new SurfaceTexture(123);
mSTC = new SurfaceTextureClient(mST);
+ mANW = mSTC;
// We need a valid GL context so we can test updateTexImage()
// This initializes EGL and create a dummy GL context with a
@@ -69,6 +70,8 @@
virtual void TearDown() {
mST.clear();
mSTC.clear();
+ mANW.clear();
+
eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(mEglDisplay, mEglContext);
eglDestroySurface(mEglDisplay, mEglSurface);
@@ -86,6 +89,8 @@
sp<SurfaceTexture> mST;
sp<SurfaceTextureClient> mSTC;
+ sp<ANativeWindow> mANW;
+
EGLDisplay mEglDisplay;
EGLSurface mEglSurface;
EGLContext mEglContext;
@@ -97,31 +102,26 @@
}
TEST_F(SurfaceTextureClientTest, QueuesToWindowCompositorIsFalse) {
- sp<ANativeWindow> anw(mSTC);
int result = -123;
- int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
+ int err = mANW->query(mANW.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
&result);
EXPECT_EQ(NO_ERROR, err);
EXPECT_EQ(0, result);
}
TEST_F(SurfaceTextureClientTest, ConcreteTypeIsSurfaceTextureClient) {
- sp<ANativeWindow> anw(mSTC);
int result = -123;
- int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
+ int err = mANW->query(mANW.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
EXPECT_EQ(NO_ERROR, err);
EXPECT_EQ(NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT, result);
}
TEST_F(SurfaceTextureClientTest, ANativeWindowLockFails) {
- sp<ANativeWindow> anw(mSTC);
ANativeWindow_Buffer buf;
- ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(anw.get(), &buf, NULL));
+ ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(mANW.get(), &buf, NULL));
}
TEST_F(SurfaceTextureClientTest, EglCreateWindowSurfaceSucceeds) {
- sp<ANativeWindow> anw(mSTC);
-
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
ASSERT_EQ(EGL_SUCCESS, eglGetError());
ASSERT_NE(EGL_NO_DISPLAY, dpy);
@@ -147,7 +147,7 @@
&numConfigs));
ASSERT_EQ(EGL_SUCCESS, eglGetError());
- EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, anw.get(),
+ EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, mANW.get(),
NULL);
EXPECT_NE(EGL_NO_SURFACE, eglSurface);
EXPECT_EQ(EGL_SUCCESS, eglGetError());
@@ -156,269 +156,246 @@
}
TEST_F(SurfaceTextureClientTest, BufferGeometryInvalidSizesFail) {
- sp<ANativeWindow> anw(mSTC);
-
- EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), -1, 0, 0));
- EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), 0, -1, 0));
- EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, -1));
- EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), -1, -1, 0));
- EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), 0, 8, 0));
- EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), 8, 0, 0));
+ EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), -1, 0, 0));
+ EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), 0, -1, 0));
+ EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, -1));
+ EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), -1, -1, 0));
+ EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), 0, 8, 0));
+ EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), 8, 0, 0));
}
TEST_F(SurfaceTextureClientTest, DefaultGeometryValues) {
- sp<ANativeWindow> anw(mSTC);
ANativeWindowBuffer* buf;
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(1, buf->width);
EXPECT_EQ(1, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
}
TEST_F(SurfaceTextureClientTest, BufferGeometryCanBeSet) {
- sp<ANativeWindow> anw(mSTC);
ANativeWindowBuffer* buf;
- EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, PIXEL_FORMAT_RGB_565));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, PIXEL_FORMAT_RGB_565));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(16, buf->width);
EXPECT_EQ(8, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
}
TEST_F(SurfaceTextureClientTest, BufferGeometryDefaultSizeSetFormat) {
- sp<ANativeWindow> anw(mSTC);
ANativeWindowBuffer* buf;
- EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, PIXEL_FORMAT_RGB_565));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, PIXEL_FORMAT_RGB_565));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(1, buf->width);
EXPECT_EQ(1, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
}
TEST_F(SurfaceTextureClientTest, BufferGeometrySetSizeDefaultFormat) {
- sp<ANativeWindow> anw(mSTC);
ANativeWindowBuffer* buf;
- EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(16, buf->width);
EXPECT_EQ(8, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
}
TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeUnset) {
- sp<ANativeWindow> anw(mSTC);
ANativeWindowBuffer* buf;
- EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(16, buf->width);
EXPECT_EQ(8, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
- EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, 0));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
+ EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, 0));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(1, buf->width);
EXPECT_EQ(1, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
}
TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeChangedWithoutFormat) {
- sp<ANativeWindow> anw(mSTC);
ANativeWindowBuffer* buf;
- EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, PIXEL_FORMAT_RGB_565));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, PIXEL_FORMAT_RGB_565));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(1, buf->width);
EXPECT_EQ(1, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
- EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
+ EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(16, buf->width);
EXPECT_EQ(8, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
}
TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSize) {
- sp<ANativeWindow> anw(mSTC);
sp<SurfaceTexture> st(mST);
ANativeWindowBuffer* buf;
EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
EXPECT_EQ(16, buf->width);
EXPECT_EQ(8, buf->height);
EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
}
TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeAfterDequeue) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
ANativeWindowBuffer* buf[2];
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
EXPECT_NE(buf[0], buf[1]);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
- EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
+ EXPECT_EQ(OK, mST->setDefaultBufferSize(16, 8));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
EXPECT_NE(buf[0], buf[1]);
EXPECT_EQ(16, buf[0]->width);
EXPECT_EQ(16, buf[1]->width);
EXPECT_EQ(8, buf[0]->height);
EXPECT_EQ(8, buf[1]->height);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
}
TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeVsGeometry) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
ANativeWindowBuffer* buf[2];
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
- EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+ EXPECT_EQ(OK, mST->setDefaultBufferSize(16, 8));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
EXPECT_NE(buf[0], buf[1]);
EXPECT_EQ(16, buf[0]->width);
EXPECT_EQ(16, buf[1]->width);
EXPECT_EQ(8, buf[0]->height);
EXPECT_EQ(8, buf[1]->height);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
- EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 12, 24, 0));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
+ EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 12, 24, 0));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
EXPECT_NE(buf[0], buf[1]);
EXPECT_EQ(12, buf[0]->width);
EXPECT_EQ(12, buf[1]->width);
EXPECT_EQ(24, buf[0]->height);
EXPECT_EQ(24, buf[1]->height);
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
}
TEST_F(SurfaceTextureClientTest, SurfaceTextureTooManyUpdateTexImage) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
- ASSERT_EQ(OK, st->setSynchronousMode(false));
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
+ ASSERT_EQ(OK, mST->setSynchronousMode(false));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(OK, st->updateTexImage());
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(OK, mST->updateTexImage());
- ASSERT_EQ(OK, st->setSynchronousMode(true));
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(OK, st->updateTexImage());
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(OK, mST->updateTexImage());
}
TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeSlowRetire) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
- ASSERT_EQ(OK, st->setSynchronousMode(true));
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
EXPECT_NE(buf[0], buf[1]);
EXPECT_NE(buf[1], buf[2]);
EXPECT_NE(buf[2], buf[0]);
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
}
TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeFastRetire) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
- ASSERT_EQ(OK, st->setSynchronousMode(true));
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
EXPECT_NE(buf[0], buf[1]);
EXPECT_NE(buf[1], buf[2]);
EXPECT_NE(buf[2], buf[0]);
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
}
TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeDQQR) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
- ASSERT_EQ(OK, st->setSynchronousMode(true));
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
EXPECT_NE(buf[0], buf[1]);
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
EXPECT_NE(buf[1], buf[2]);
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
}
// XXX: We currently have no hardware that properly handles dequeuing the
// buffer that is currently bound to the texture.
TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeDequeueCurrent) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
android_native_buffer_t* firstBuf;
- ASSERT_EQ(OK, st->setSynchronousMode(true));
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &firstBuf));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), firstBuf));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), firstBuf);
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &firstBuf));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), firstBuf));
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), firstBuf);
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
EXPECT_NE(buf[0], buf[1]);
EXPECT_NE(buf[1], buf[2]);
EXPECT_NE(buf[2], buf[0]);
@@ -426,41 +403,36 @@
}
TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeMinUndequeued) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
- ASSERT_EQ(OK, st->setSynchronousMode(true));
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
- // We should be able to dequeue all the buffers before we've queued any.
- EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
- EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+ // We should be able to dequeue all the buffers before we've queued mANWy.
+ EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+ EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[2]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[2]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
- EXPECT_EQ(OK, st->updateTexImage());
- EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
+ EXPECT_EQ(OK, mST->updateTexImage());
+ EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
- EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+ EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
// Once we've queued a buffer, however we should not be able to dequeue more
// than (buffer-count - MIN_UNDEQUEUED_BUFFERS), which is 2 in this case.
- EXPECT_EQ(-EBUSY, anw->dequeueBuffer(anw.get(), &buf[1]));
+ EXPECT_EQ(-EBUSY, mANW->dequeueBuffer(mANW.get(), &buf[1]));
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[2]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[2]));
}
// XXX: This is not expected to pass until the synchronization hacks are removed
// from the SurfaceTexture class.
TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeWaitRetire) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
-
class MyThread : public Thread {
- sp<SurfaceTexture> st;
+ sp<SurfaceTexture> mST;
EGLContext ctx;
EGLSurface sur;
EGLDisplay dpy;
@@ -470,14 +442,14 @@
eglMakeCurrent(dpy, sur, sur, ctx);
usleep(20000);
Mutex::Autolock _l(mLock);
- st->updateTexImage();
+ mST->updateTexImage();
mBufferRetired = true;
eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
return false;
}
public:
- MyThread(const sp<SurfaceTexture>& st)
- : st(st), mBufferRetired(false) {
+ MyThread(const sp<SurfaceTexture>& mST)
+ : mST(mST), mBufferRetired(false) {
ctx = eglGetCurrentContext();
sur = eglGetCurrentSurface(EGL_DRAW);
dpy = eglGetCurrentDisplay();
@@ -493,37 +465,35 @@
};
android_native_buffer_t* buf[3];
- ASSERT_EQ(OK, st->setSynchronousMode(true));
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
// dequeue/queue/update so we have a current buffer
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- st->updateTexImage();
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ mST->updateTexImage();
- MyThread* thread = new MyThread(st);
+ MyThread* thread = new MyThread(mST);
sp<Thread> threadBase(thread);
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
thread->run();
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
- //ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
- //ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+ //ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
+ //ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
thread->bufferDequeued();
thread->requestExitAndWait();
}
TEST_F(SurfaceTextureClientTest, GetTransformMatrixReturnsVerticalFlip) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
float mtx[16] = {};
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, st->updateTexImage());
- st->getTransformMatrix(mtx);
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mST->updateTexImage());
+ mST->getTransformMatrix(mtx);
EXPECT_EQ(1.f, mtx[0]);
EXPECT_EQ(0.f, mtx[1]);
@@ -547,16 +517,14 @@
}
TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffers) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
float mtx[16] = {};
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, st->updateTexImage());
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 6)); // frees buffers
- st->getTransformMatrix(mtx);
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mST->updateTexImage());
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
+ mST->getTransformMatrix(mtx);
EXPECT_EQ(1.f, mtx[0]);
EXPECT_EQ(0.f, mtx[1]);
@@ -580,8 +548,6 @@
}
TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffersWithCrop) {
- sp<ANativeWindow> anw(mSTC);
- sp<SurfaceTexture> st(mST);
android_native_buffer_t* buf[3];
float mtx[16] = {};
android_native_rect_t crop;
@@ -590,14 +556,14 @@
crop.right = 5;
crop.bottom = 5;
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
- ASSERT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 8, 8, 0));
- ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
- ASSERT_EQ(OK, native_window_set_crop(anw.get(), &crop));
- ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
- ASSERT_EQ(OK, st->updateTexImage());
- ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 6)); // frees buffers
- st->getTransformMatrix(mtx);
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+ ASSERT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 8, 8, 0));
+ ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+ ASSERT_EQ(OK, native_window_set_crop(mANW.get(), &crop));
+ ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+ ASSERT_EQ(OK, mST->updateTexImage());
+ ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
+ mST->getTransformMatrix(mtx);
// This accounts for the 1 texel shrink for each edge that's included in the
// transform matrix to avoid texturing outside the crop region.
diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp
index 56c1702..50af3bb 100644
--- a/libs/gui/tests/SurfaceTexture_test.cpp
+++ b/libs/gui/tests/SurfaceTexture_test.cpp
@@ -46,8 +46,6 @@
}
virtual void SetUp() {
- EGLBoolean returnValue;
-
mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
ASSERT_EQ(EGL_SUCCESS, eglGetError());
ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
@@ -59,9 +57,8 @@
RecordProperty("EglVersionMajor", majorVersion);
RecordProperty("EglVersionMajor", minorVersion);
- EGLConfig myConfig = {0};
EGLint numConfigs = 0;
- EXPECT_TRUE(eglChooseConfig(mEglDisplay, getConfigAttribs(), &myConfig,
+ EXPECT_TRUE(eglChooseConfig(mEglDisplay, getConfigAttribs(), &mGlConfig,
1, &numConfigs));
ASSERT_EQ(EGL_SUCCESS, eglGetError());
@@ -88,12 +85,12 @@
ASSERT_TRUE(mSurfaceControl->isValid());
ASSERT_EQ(NO_ERROR, mComposerClient->openTransaction());
- ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(30000));
+ ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(0x7FFFFFFF));
ASSERT_EQ(NO_ERROR, mSurfaceControl->show());
ASSERT_EQ(NO_ERROR, mComposerClient->closeTransaction());
sp<ANativeWindow> window = mSurfaceControl->getSurface();
- mEglSurface = eglCreateWindowSurface(mEglDisplay, myConfig,
+ mEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
window.get(), NULL);
} else {
EGLint pbufferAttribs[] = {
@@ -101,13 +98,13 @@
EGL_HEIGHT, getSurfaceHeight(),
EGL_NONE };
- mEglSurface = eglCreatePbufferSurface(mEglDisplay, myConfig,
+ mEglSurface = eglCreatePbufferSurface(mEglDisplay, mGlConfig,
pbufferAttribs);
}
ASSERT_EQ(EGL_SUCCESS, eglGetError());
ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
- mEglContext = eglCreateContext(mEglDisplay, myConfig, EGL_NO_CONTEXT,
+ mEglContext = eglCreateContext(mEglDisplay, mGlConfig, EGL_NO_CONTEXT,
getContextAttribs());
ASSERT_EQ(EGL_SUCCESS, eglGetError());
ASSERT_NE(EGL_NO_CONTEXT, mEglContext);
@@ -329,6 +326,7 @@
EGLDisplay mEglDisplay;
EGLSurface mEglSurface;
EGLContext mEglContext;
+ EGLConfig mGlConfig;
};
// XXX: Code above this point should live elsewhere
@@ -401,6 +399,18 @@
glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID);
ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+ // XXX: These calls are not needed for GL_TEXTURE_EXTERNAL_OES as
+ // they're setting the defautls for that target, but when hacking things
+ // to use GL_TEXTURE_2D they are needed to achieve the same behavior.
+ glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+ glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+ glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+ glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+
GLfloat texMatrix[16];
mST->getTransformMatrix(texMatrix);
glUniformMatrix4fv(mTexMatrixHandle, 1, GL_FALSE, texMatrix);
@@ -474,12 +484,26 @@
}
}
+void fillRGBA8Buffer(uint8_t* buf, int w, int h, int stride) {
+ const size_t PIXEL_SIZE = 4;
+ for (int x = 0; x < w; x++) {
+ for (int y = 0; y < h; y++) {
+ off_t offset = (y * stride + x) * PIXEL_SIZE;
+ for (int c = 0; c < 4; c++) {
+ int parityX = (x / (1 << (c+2))) & 1;
+ int parityY = (y / (1 << (c+2))) & 1;
+ buf[offset + c] = (parityX ^ parityY) ? 231 : 35;
+ }
+ }
+ }
+}
+
TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferNpot) {
- const int yuvTexWidth = 64;
- const int yuvTexHeight = 66;
+ const int texWidth = 64;
+ const int texHeight = 66;
ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
- yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+ texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
@@ -493,7 +517,7 @@
// Fill the buffer with the a checkerboard pattern
uint8_t* img = NULL;
buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
- fillYV12Buffer(img, yuvTexWidth, yuvTexHeight, buf->getStride());
+ fillYV12Buffer(img, texWidth, texHeight, buf->getStride());
buf->unlock();
ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
@@ -523,11 +547,11 @@
// I just copied them from the npot test above and haven't bothered to figure
// out the correct values.
TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledYV12BufferPow2) {
- const int yuvTexWidth = 64;
- const int yuvTexHeight = 64;
+ const int texWidth = 64;
+ const int texHeight = 64;
ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
- yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+ texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
@@ -541,7 +565,7 @@
// Fill the buffer with the a checkerboard pattern
uint8_t* img = NULL;
buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
- fillYV12Buffer(img, yuvTexWidth, yuvTexHeight, buf->getStride());
+ fillYV12Buffer(img, texWidth, texHeight, buf->getStride());
buf->unlock();
ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
@@ -567,11 +591,11 @@
}
TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferWithCrop) {
- const int yuvTexWidth = 64;
- const int yuvTexHeight = 66;
+ const int texWidth = 64;
+ const int texHeight = 66;
ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
- yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+ texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
@@ -579,8 +603,8 @@
{4, 6, 22, 36},
{0, 6, 22, 36},
{4, 0, 22, 36},
- {4, 6, yuvTexWidth, 36},
- {4, 6, 22, yuvTexHeight},
+ {4, 6, texWidth, 36},
+ {4, 6, 22, texHeight},
};
for (int i = 0; i < 5; i++) {
@@ -599,7 +623,7 @@
uint8_t* img = NULL;
buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
- fillYV12BufferRect(img, yuvTexWidth, yuvTexHeight, buf->getStride(), crop);
+ fillYV12BufferRect(img, texWidth, texHeight, buf->getStride(), crop);
buf->unlock();
ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
@@ -625,6 +649,189 @@
}
}
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferNpot) {
+ const int texWidth = 64;
+ const int texHeight = 66;
+
+ ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+ texWidth, texHeight, HAL_PIXEL_FORMAT_RGBA_8888));
+ ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ android_native_buffer_t* anb;
+ ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
+ ASSERT_TRUE(anb != NULL);
+
+ sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
+ ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(), buf->getNativeBuffer()));
+
+ // Fill the buffer with the a checkerboard pattern
+ uint8_t* img = NULL;
+ buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
+ fillRGBA8Buffer(img, texWidth, texHeight, buf->getStride());
+ buf->unlock();
+ ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
+
+ mST->updateTexImage();
+
+ glClearColor(0.2, 0.2, 0.2, 0.2);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ drawTexture();
+
+ EXPECT_TRUE(checkPixel( 0, 0, 35, 35, 35, 35));
+ EXPECT_TRUE(checkPixel(63, 0, 231, 231, 231, 231));
+ EXPECT_TRUE(checkPixel(63, 63, 231, 231, 231, 231));
+ EXPECT_TRUE(checkPixel( 0, 63, 35, 35, 35, 35));
+
+ EXPECT_TRUE(checkPixel(15, 10, 35, 231, 231, 231));
+ EXPECT_TRUE(checkPixel(24, 63, 35, 231, 231, 35));
+ EXPECT_TRUE(checkPixel(19, 40, 87, 179, 35, 35));
+ EXPECT_TRUE(checkPixel(38, 30, 231, 35, 35, 35));
+ EXPECT_TRUE(checkPixel(42, 54, 35, 35, 35, 231));
+ EXPECT_TRUE(checkPixel(37, 33, 35, 231, 231, 231));
+ EXPECT_TRUE(checkPixel(31, 8, 231, 35, 35, 231));
+ EXPECT_TRUE(checkPixel(36, 47, 231, 35, 231, 231));
+ EXPECT_TRUE(checkPixel(24, 63, 35, 231, 231, 35));
+ EXPECT_TRUE(checkPixel(48, 3, 231, 231, 35, 35));
+ EXPECT_TRUE(checkPixel(54, 50, 35, 231, 231, 231));
+ EXPECT_TRUE(checkPixel(24, 25, 191, 191, 231, 231));
+ EXPECT_TRUE(checkPixel(10, 9, 93, 93, 231, 231));
+ EXPECT_TRUE(checkPixel(29, 4, 35, 35, 35, 231));
+ EXPECT_TRUE(checkPixel(56, 31, 35, 231, 231, 35));
+ EXPECT_TRUE(checkPixel(58, 55, 35, 35, 231, 231));
+}
+
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferPow2) {
+ const int texWidth = 64;
+ const int texHeight = 64;
+
+ ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+ texWidth, texHeight, HAL_PIXEL_FORMAT_RGBA_8888));
+ ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ android_native_buffer_t* anb;
+ ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
+ ASSERT_TRUE(anb != NULL);
+
+ sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
+ ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(), buf->getNativeBuffer()));
+
+ // Fill the buffer with the a checkerboard pattern
+ uint8_t* img = NULL;
+ buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
+ fillRGBA8Buffer(img, texWidth, texHeight, buf->getStride());
+ buf->unlock();
+ ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
+
+ mST->updateTexImage();
+
+ glClearColor(0.2, 0.2, 0.2, 0.2);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ drawTexture();
+
+ EXPECT_TRUE(checkPixel( 0, 0, 231, 231, 231, 231));
+ EXPECT_TRUE(checkPixel(63, 0, 35, 35, 35, 35));
+ EXPECT_TRUE(checkPixel(63, 63, 231, 231, 231, 231));
+ EXPECT_TRUE(checkPixel( 0, 63, 35, 35, 35, 35));
+
+ EXPECT_TRUE(checkPixel(12, 46, 231, 231, 231, 35));
+ EXPECT_TRUE(checkPixel(16, 1, 231, 231, 35, 231));
+ EXPECT_TRUE(checkPixel(21, 12, 231, 35, 35, 231));
+ EXPECT_TRUE(checkPixel(26, 51, 231, 35, 231, 35));
+ EXPECT_TRUE(checkPixel( 5, 32, 35, 231, 231, 35));
+ EXPECT_TRUE(checkPixel(13, 8, 35, 231, 231, 231));
+ EXPECT_TRUE(checkPixel(46, 3, 35, 35, 231, 35));
+ EXPECT_TRUE(checkPixel(30, 33, 35, 35, 35, 35));
+ EXPECT_TRUE(checkPixel( 6, 52, 231, 231, 35, 35));
+ EXPECT_TRUE(checkPixel(55, 33, 35, 231, 35, 231));
+ EXPECT_TRUE(checkPixel(16, 29, 35, 35, 231, 231));
+ EXPECT_TRUE(checkPixel( 1, 30, 35, 35, 35, 231));
+ EXPECT_TRUE(checkPixel(41, 37, 35, 35, 231, 231));
+ EXPECT_TRUE(checkPixel(46, 29, 231, 231, 35, 35));
+ EXPECT_TRUE(checkPixel(15, 25, 35, 231, 35, 231));
+ EXPECT_TRUE(checkPixel( 3, 52, 35, 231, 35, 35));
+}
+
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromGLFilledRGBABufferPow2) {
+ const int texWidth = 64;
+ const int texHeight = 64;
+
+ mST->setDefaultBufferSize(texWidth, texHeight);
+
+ // Do the producer side of things
+ EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
+ mANW.get(), NULL);
+ ASSERT_EQ(EGL_SUCCESS, eglGetError());
+ ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
+
+ EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface,
+ mEglContext));
+ ASSERT_EQ(EGL_SUCCESS, eglGetError());
+
+ glClearColor(0.6, 0.6, 0.6, 0.6);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glEnable(GL_SCISSOR_TEST);
+ glScissor(4, 4, 4, 4);
+ glClearColor(1.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glScissor(24, 48, 4, 4);
+ glClearColor(0.0, 1.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glScissor(37, 17, 4, 4);
+ glClearColor(0.0, 0.0, 1.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ eglSwapBuffers(mEglDisplay, stcEglSurface);
+
+ // Do the consumer side of things
+ EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
+ mEglContext));
+ ASSERT_EQ(EGL_SUCCESS, eglGetError());
+
+ glDisable(GL_SCISSOR_TEST);
+
+ mST->updateTexImage();
+
+ glClearColor(0.2, 0.2, 0.2, 0.2);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ drawTexture();
+
+ EXPECT_TRUE(checkPixel( 0, 0, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(63, 0, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(63, 63, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel( 0, 63, 153, 153, 153, 153));
+
+ EXPECT_TRUE(checkPixel( 4, 7, 255, 0, 0, 255));
+ EXPECT_TRUE(checkPixel(25, 51, 0, 255, 0, 255));
+ EXPECT_TRUE(checkPixel(40, 19, 0, 0, 255, 255));
+ EXPECT_TRUE(checkPixel(29, 51, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel( 5, 32, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(13, 8, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(46, 3, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(30, 33, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel( 6, 52, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(55, 33, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(16, 29, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel( 1, 30, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(41, 37, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(46, 29, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel(15, 25, 153, 153, 153, 153));
+ EXPECT_TRUE(checkPixel( 3, 52, 153, 153, 153, 153));
+}
+
/*
* This test is for testing GL -> GL texture streaming via SurfaceTexture. It
* contains functionality to create a producer thread that will perform GL
diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp
index f316ba7..146e789 100644
--- a/libs/hwui/LayerRenderer.cpp
+++ b/libs/hwui/LayerRenderer.cpp
@@ -315,5 +315,95 @@
}
}
+bool LayerRenderer::copyLayer(Layer* layer, SkBitmap* bitmap) {
+ Caches& caches = Caches::getInstance();
+ if (layer && layer->isTextureLayer && bitmap->width() <= caches.maxTextureSize &&
+ bitmap->height() <= caches.maxTextureSize) {
+
+ GLuint fbo = caches.fboCache.get();
+ if (!fbo) {
+ LOGW("Could not obtain an FBO");
+ return false;
+ }
+
+ GLuint texture;
+ GLuint previousFbo;
+
+ GLenum format;
+ GLenum type;
+
+ switch (bitmap->config()) {
+ case SkBitmap::kA8_Config:
+ format = GL_ALPHA;
+ type = GL_UNSIGNED_BYTE;
+ break;
+ case SkBitmap::kRGB_565_Config:
+ format = GL_RGB;
+ type = GL_UNSIGNED_SHORT_5_6_5;
+ break;
+ case SkBitmap::kARGB_4444_Config:
+ format = GL_RGBA;
+ type = GL_UNSIGNED_SHORT_4_4_4_4;
+ break;
+ case SkBitmap::kARGB_8888_Config:
+ default:
+ format = GL_RGBA;
+ type = GL_UNSIGNED_BYTE;
+ break;
+ }
+
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*) &previousFbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+ glGenTextures(1, &texture);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, format, bitmap->width(), bitmap->height(),
+ 0, format, type, NULL);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, texture, 0);
+
+ glBindTexture(GL_TEXTURE_2D, layer->texture);
+
+ float alpha = layer->alpha;
+ SkXfermode::Mode mode = layer->mode;
+
+ layer->mode = SkXfermode::kSrc_Mode;
+ layer->alpha = 255;
+ layer->fbo = fbo;
+
+ LayerRenderer renderer(layer);
+ renderer.setViewport(bitmap->width(), bitmap->height());
+ renderer.OpenGLRenderer::prepareDirty(0.0f, 0.0f,
+ bitmap->width(), bitmap->height(), !layer->blend);
+
+ Rect bounds;
+ bounds.set(0.0f, 0.0f, bitmap->width(), bitmap->height());
+ renderer.drawTextureLayer(layer, bounds);
+
+ SkAutoLockPixels alp(*bitmap);
+ glReadPixels(0, 0, bitmap->width(), bitmap->height(), format, type, bitmap->getPixels());
+
+ glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
+
+ layer->mode = mode;
+ layer->alpha = alpha;
+ layer->fbo = 0;
+ glDeleteTextures(1, &texture);
+ caches.fboCache.put(fbo);
+
+ return true;
+ }
+ return false;
+}
+
}; // namespace uirenderer
}; // namespace android
diff --git a/libs/hwui/LayerRenderer.h b/libs/hwui/LayerRenderer.h
index 59cab96..797dfc6 100644
--- a/libs/hwui/LayerRenderer.h
+++ b/libs/hwui/LayerRenderer.h
@@ -20,6 +20,8 @@
#include "OpenGLRenderer.h"
#include "Layer.h"
+#include <SkBitmap.h>
+
namespace android {
namespace uirenderer {
@@ -60,6 +62,7 @@
GLenum renderTarget, float* transform);
static void destroyLayer(Layer* layer);
static void destroyLayerDeferred(Layer* layer);
+ static bool copyLayer(Layer* layer, SkBitmap* bitmap);
private:
void generateMesh();
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index b9e3ddc..0a3d5090 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -178,6 +178,14 @@
return 0;
}
+ /**
+ * Renders the specified layer as a textured quad.
+ *
+ * @param layer The layer to render
+ * @param rect The bounds of the layer
+ */
+ void drawTextureLayer(Layer* layer, const Rect& rect);
+
private:
/**
* Saves the current state of the renderer as a new snapshot.
@@ -256,14 +264,6 @@
void clearLayerRegions();
/**
- * Renders the specified layer as a textured quad.
- *
- * @param layer The layer to render
- * @param rect The bounds of the layer
- */
- void drawTextureLayer(Layer* layer, const Rect& rect);
-
- /**
* Mark the layer as dirty at the specified coordinates. The coordinates
* are transformed with the supplied matrix.
*/
diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp
index c748228..15bb1d2 100644
--- a/libs/utils/Threads.cpp
+++ b/libs/utils/Threads.cpp
@@ -335,10 +335,17 @@
pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup);
if (gDoSchedulingGroup) {
+ // set_sched_policy does not support tid == 0
+ int policy_tid;
+ if (tid == 0) {
+ policy_tid = androidGetTid();
+ } else {
+ policy_tid = tid;
+ }
if (pri >= ANDROID_PRIORITY_BACKGROUND) {
- rc = set_sched_policy(tid, SP_BACKGROUND);
+ rc = set_sched_policy(policy_tid, SP_BACKGROUND);
} else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) {
- rc = set_sched_policy(tid, SP_FOREGROUND);
+ rc = set_sched_policy(policy_tid, SP_FOREGROUND);
}
}
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index e34d75cc..2557730 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -52,6 +52,7 @@
* <li><a href="#StateDiagram">State Diagram</a>
* <li><a href="#Valid_and_Invalid_States">Valid and Invalid States</a>
* <li><a href="#Permissions">Permissions</a>
+ * <li><a href="#Callbacks">Register informational and error callbacks</a>
* </ol>
*
* <a name="StateDiagram"></a>
@@ -459,6 +460,25 @@
* android.R.styleable#AndroidManifestUsesPermission <uses-permission>}
* element.
*
+ * <a name="Callbacks"></a>
+ * <h3>Callbacks</h3>
+ * <p>Applications may want to register for informational and error
+ * events in order to be informed of some internal state update and
+ * possible runtime errors during playback or streaming. Registration for
+ * these events is done by properly setting the appropriate listeners (via calls
+ * to
+ * {@link #setOnPreparedListener(OnPreparedListener)}setOnPreparedListener,
+ * {@link #setOnVideoSizeChangedListener(OnVideoSizeChangedListener)}setOnVideoSizeChangedListener,
+ * {@link #setOnSeekCompleteListener(OnSeekCompleteListener)}setOnSeekCompleteListener,
+ * {@link #setOnCompletionListener(OnCompletionListener)}setOnCompletionListener,
+ * {@link #setOnBufferingUpdateListener(OnBufferingUpdateListener)}setOnBufferingUpdateListener,
+ * {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener,
+ * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener, etc).
+ * In order to receive the respective callback
+ * associated with these listeners, applications are required to create
+ * MediaPlayer objects on a thread with its own Looper running (main UI
+ * thread by default has a Looper running).
+ *
*/
public class MediaPlayer
{
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 1478a6d..dd45111 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -51,6 +51,16 @@
* recorder.release(); // Now the object cannot be reused
* </pre>
*
+ * <p>Applications may want to register for informational and error
+ * events in order to be informed of some internal update and possible
+ * runtime errors during recording. Registration for such events is
+ * done by setting the appropriate listeners (via calls
+ * (to {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener and/or
+ * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener).
+ * In order to receive the respective callback associated with these listeners,
+ * applications are required to create MediaRecorder objects on threads with a
+ * Looper running (the main UI thread by default already has a Looper running).
+ *
* <p>See the <a href="{@docRoot}guide/topics/media/index.html">Audio and Video</a>
* documentation for additional help with using MediaRecorder.
* <p>Note: Currently, MediaRecorder does not work on the emulator.
diff --git a/media/libstagefright/CameraSourceTimeLapse.cpp b/media/libstagefright/CameraSourceTimeLapse.cpp
index 3689557..cc22574 100644
--- a/media/libstagefright/CameraSourceTimeLapse.cpp
+++ b/media/libstagefright/CameraSourceTimeLapse.cpp
@@ -486,7 +486,8 @@
if (mForceRead) {
LOGV("dataCallbackTimestamp timelapse: forced read");
mForceRead = false;
- *timestampUs = mLastFrameTimestampUs;
+ *timestampUs =
+ mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
return false;
}
}
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index b8ae79c..28add18 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -1981,7 +1981,7 @@
} else {
prctl(PR_SET_NAME, (unsigned long)"VideoTrackEncoding", 0, 0, 0);
}
- setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
+ androidSetThreadPriority(0, ANDROID_PRIORITY_AUDIO);
sp<MetaData> meta_data;
diff --git a/media/libstagefright/TimedEventQueue.cpp b/media/libstagefright/TimedEventQueue.cpp
index 5a453e9..a08eb7b 100644
--- a/media/libstagefright/TimedEventQueue.cpp
+++ b/media/libstagefright/TimedEventQueue.cpp
@@ -210,8 +210,7 @@
vm->AttachCurrentThread(&env, NULL);
#endif
- setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_FOREGROUND);
- set_sched_policy(androidGetTid(), SP_FOREGROUND);
+ androidSetThreadPriority(0, ANDROID_PRIORITY_FOREGROUND);
static_cast<TimedEventQueue *>(me)->threadEntry();
diff --git a/media/libstagefright/omx/OMX.cpp b/media/libstagefright/omx/OMX.cpp
index 4b1c3a7..14968e8 100644
--- a/media/libstagefright/omx/OMX.cpp
+++ b/media/libstagefright/omx/OMX.cpp
@@ -116,7 +116,7 @@
}
void OMX::CallbackDispatcher::threadEntry() {
- setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
+ androidSetThreadPriority(0, ANDROID_PRIORITY_AUDIO);
prctl(PR_SET_NAME, (unsigned long)"OMXCallbackDisp", 0, 0, 0);
for (;;) {
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
index 2c26f62..977b412 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
@@ -145,8 +145,10 @@
public static final String APN_TYPE_KEY = "apnType";
- /** Delay between APN attempts */
- protected static final int APN_DELAY_MILLIS = 5000;
+ /** Delay between APN attempts.
+ Note the property override mechanism is there just for testing purpose only. */
+ protected static final int APN_DELAY_MILLIS =
+ SystemProperties.getInt("persist.radio.apn_delay", 5000);
// responds to the setInternalDataEnabled call - used internally to turn off data
// for example during emergency calls
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
index abd87b8..318cf37 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
@@ -125,6 +125,8 @@
}
}
+ // Not sure if this is needed in CDMALTE phone.
+ // mDataRoaming = regCodeIsRoaming(regState);
mLteSS.setRadioTechnology(type);
mLteSS.setState(regCodeToServiceState(regState));
} else {
@@ -210,12 +212,6 @@
if (DBG) log("pollStateDone: oldSS=[" + ss + "] newSS=[" + newSS + "]");
- if (cm.getSimState().isSIMReady()) {
- // If CSIM is used, check roaming status according to SID/NID
- // on EFcdmahome record.
- newSS.setRoaming(!isInHomeSidNid(newSS.getSystemId(), newSS.getNetworkId()));
- }
-
boolean hasRegistered = ss.getState() != ServiceState.STATE_IN_SERVICE
&& newSS.getState() == ServiceState.STATE_IN_SERVICE;
@@ -468,33 +464,6 @@
return provisioningState;
}
- /**
- * Check whether the specified SID and NID pair appears in the HOME SID/NID list
- * read from NV or SIM.
- *
- * @return true if provided sid/nid pair belongs to operator's home network.
- */
- private boolean isInHomeSidNid(int sid, int nid) {
- // if SID/NID is not available, do not declare roaming.
- if (isSidsAllZeros()) return true;
-
- // length of SID/NID shold be same
- if (mHomeSystemId.length != mHomeNetworkId.length) return true;
-
- if (sid == 0) return true;
-
- for (int i = 0; i < mHomeSystemId.length; i++) {
- // Use SID only if NID is a reserved value.
- // SID 0 and NID 0 and 65535 are reserved. (C.0005 2.6.5.2)
- if ((mHomeSystemId[i] == sid) &&
- ((mHomeNetworkId[i] == 0) || (mHomeNetworkId[i] == 65535) ||
- (nid == 0) || (nid == 65535) || (mHomeNetworkId[i] == nid))) {
- return true;
- }
- }
- return false;
- }
-
@Override
protected void log(String s) {
Log.d(LOG_TAG, "[CdmaLteSST] " + s);
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
index 58ef747..73b5d97 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
@@ -17,6 +17,7 @@
import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA;
import com.android.internal.telephony.GsmAlphabet;
+import com.android.internal.telephony.IccCardApplication.AppType;
import com.android.internal.telephony.IccFileHandler;
import com.android.internal.telephony.IccUtils;
import com.android.internal.telephony.MccTable;
@@ -438,9 +439,14 @@
@Override
public boolean isProvisioned() {
- // Look for MDN and MIN field to determine if the SIM is provisioned.
- if ((mMdn != null) && (mMin != null)) return true;
-
- return false;
+ // If UICC card has CSIM app, look for MDN and MIN field
+ // to determine if the SIM is provisioned. Otherwise,
+ // consider the SIM is provisioned. (for case of ordinal
+ // USIM only UICC.)
+ if (phone.mIccCard.isApplicationOnIcc(AppType.APPTYPE_CSIM) &&
+ ((mMdn == null) || (mMin == null))) {
+ return false;
+ }
+ return true;
}
}
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
index e41985e..5ebdd22 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
@@ -130,8 +130,8 @@
private String curPlmn = null;
protected String mMdn;
- protected int mHomeSystemId[] = null;
- protected int mHomeNetworkId[] = null;
+ private int mHomeSystemId[] = null;
+ private int mHomeNetworkId[] = null;
protected String mMin;
protected String mPrlVersion;
protected boolean mIsMinInfoReady = false;
@@ -1481,7 +1481,7 @@
}
}
- protected boolean isSidsAllZeros() {
+ private boolean isSidsAllZeros() {
if (mHomeSystemId != null) {
for (int i=0; i < mHomeSystemId.length; i++) {
if (mHomeSystemId[i] != 0) {
diff --git a/tests/BiDiTests/res/layout/frame_layout_rtl.xml b/tests/BiDiTests/res/layout/frame_layout_rtl.xml
index 258d44a..a84904c 100644
--- a/tests/BiDiTests/res/layout/frame_layout_rtl.xml
+++ b/tests/BiDiTests/res/layout/frame_layout_rtl.xml
@@ -21,7 +21,7 @@
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layoutDirection="ltr"
+ android:layoutDirection="rtl"
android:background="#FF000000">
<FrameLayout
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 01d30eb..3e7ca08 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
index 3ba6ba4..b568781 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
@@ -44,6 +44,7 @@
public class RsBenchRS {
private static final String TAG = "RsBenchRS";
+ private static final String SAMPLE_TEXT = "Bench Test";
int mWidth;
int mHeight;
@@ -125,7 +126,8 @@
Font mFontSerif;
private Allocation mTextAlloc;
- private ScriptField_TexAllocs_s mTextureAllocs;
+ private ScriptField_ListAllocs_s mTextureAllocs;
+ private ScriptField_ListAllocs_s mSampleTextAllocs;
private ScriptC_rsbench mScript;
@@ -445,7 +447,7 @@
mScript.set_g100by100Mesh(m100by100Mesh);
mWbyHMesh= getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, mBenchmarkDimX/4, mBenchmarkDimY/4);
mScript.set_gWbyHMesh(mWbyHMesh);
- mSingleMesh = getSingleMesh(50, 50);
+ mSingleMesh = getSingleMesh(1, 1); // a unit size mesh
mScript.set_gSingleMesh(mSingleMesh);
FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
@@ -547,15 +549,24 @@
mScript.set_gRenderBufferDepth(offscreen);
- mTextureAllocs = new ScriptField_TexAllocs_s(mRS, 100);
+ mTextureAllocs = new ScriptField_ListAllocs_s(mRS, 100);
for (int i = 0; i < 100; i++) {
- ScriptField_TexAllocs_s.Item texElem = new ScriptField_TexAllocs_s.Item();
- texElem.texture = loadTextureRGB(R.drawable.globe);
+ ScriptField_ListAllocs_s.Item texElem = new ScriptField_ListAllocs_s.Item();
+ texElem.item = loadTextureRGB(R.drawable.globe);
mTextureAllocs.set(texElem, i, false);
}
mTextureAllocs.copyAll();
mScript.bind_gTexList100(mTextureAllocs);
+ mSampleTextAllocs = new ScriptField_ListAllocs_s(mRS, 100);
+ for (int i = 0; i < 100; i++) {
+ ScriptField_ListAllocs_s.Item textElem = new ScriptField_ListAllocs_s.Item();
+ textElem.item = Allocation.createFromString(mRS, SAMPLE_TEXT, Allocation.USAGE_SCRIPT);
+ mSampleTextAllocs.set(textElem, i, false);
+ }
+ mSampleTextAllocs.copyAll();
+ mScript.bind_gSampleTextList100(mSampleTextAllocs);
+
mRS.bindRootScript(mScript);
}
}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
index b6572fb..0294b31 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
@@ -23,7 +23,7 @@
const int RS_MSG_TEST_DONE = 100;
const int RS_MSG_RESULTS_READY = 101;
-const int gMaxModes = 27;
+const int gMaxModes = 29;
int gMaxLoops;
// Allocation to send test names back to java
@@ -46,11 +46,12 @@
rs_allocation gTexChecker;
rs_allocation gTexGlobe;
-typedef struct TexAllocs_s {
- rs_allocation texture;
-} TexAllocs;
+typedef struct ListAllocs_s {
+ rs_allocation item;
+} ListAllocs;
-TexAllocs *gTexList100;
+ListAllocs *gTexList100;
+ListAllocs *gSampleTextList100;
rs_mesh g10by10Mesh;
rs_mesh g100by100Mesh;
@@ -195,6 +196,7 @@
rsgBindProgramStore(gProgStoreBlendNone);
rsgBindProgramFragment(gProgFragmentTexture);
rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
+
rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
if (meshNum == 0) {
@@ -207,7 +209,7 @@
}
// Display sample images in a mesh with different texture
-static void displayMeshWithMultiTexture(int meshMode) {
+static void displayIcons(int meshMode) {
bindProgramVertexOrtho();
// Fragment shader with texture
@@ -217,22 +219,90 @@
int meshCount = (int)pow(10.0f, (float)(meshMode + 1));
+ float size = 50.0;
+ rs_matrix4x4 matrix;
+ rsMatrixLoadScale(&matrix, size, size, 1.0);
+
float yPos = 0;
for (int y = 0; y < meshCount; y++) {
yPos = (y + 1) * 50;
float xPos = 0;
for (int x = 0; x < meshCount; x++) {
xPos = (x + 1) * 50;
- rs_matrix4x4 matrix;
- rsMatrixLoadTranslate(&matrix, xPos, yPos, 0);
- rsgProgramVertexLoadModelMatrix(&matrix);
+ rs_matrix4x4 transMatrix;
+ rsMatrixLoadTranslate(&transMatrix, xPos, yPos, 0);
+ rsMatrixMultiply(&transMatrix, &matrix);
+ rsgProgramVertexLoadModelMatrix(&transMatrix);
int i = (x + y * meshCount) % 100;
- rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].texture);
+ rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].item);
rsgDrawMesh(gSingleMesh);
}
}
}
+// Draw meshes in a single page with top left corner coordinates (xStart, yStart)
+static void drawMeshInPage(float xStart, float yStart, int wResolution, int hResolution) {
+ // Draw wResolution * hResolution meshes in one page
+ float wMargin = 100.0f;
+ float hMargin = 100.0f;
+ float xPad = 50.0f;
+ float yPad = 20.0f;
+ float size = 100.0f; // size of images
+
+ // font info
+ rs_font font = gFontSans;
+ rsgBindFont(font);
+ rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
+
+ // Measure text size
+ int left = 0, right = 0, top = 0, bottom = 0;
+ rsgMeasureText(gSampleTextList100[0].item, &left, &right, &top, &bottom);
+ float textHeight = (float)(top - bottom);
+ float textWidth = (float)(right - left);
+
+ rs_matrix4x4 matrix;
+ rsMatrixLoadScale(&matrix, size, size, 1.0);
+
+ for (int y = 0; y < hResolution; y++) {
+ float yPos = yStart + hMargin + y * size + y * yPad;
+ for (int x = 0; x < wResolution; x++) {
+ float xPos = xStart + wMargin + x * size + x * xPad;
+
+ rs_matrix4x4 transMatrix;
+ rsMatrixLoadTranslate(&transMatrix, xPos + size/2, yPos + size/2, 0);
+ rsMatrixMultiply(&transMatrix, &matrix); // scale the mesh
+ rsgProgramVertexLoadModelMatrix(&transMatrix);
+
+ int i = (y * wResolution + x) % 100;
+ rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].item);
+ rsgDrawMesh(gSingleMesh);
+ rsgDrawText(gSampleTextList100[i].item, xPos, yPos + size + yPad/2 + textHeight);
+ }
+ }
+}
+
+// Display both images and text as shown in launcher and homepage
+// meshMode will decide how many pages we draw
+// meshMode = 0: draw 3 pages of meshes
+// meshMode = 1: draw 5 pages of meshes
+static void displayImageWithText(int wResolution, int hResolution, int meshMode) {
+ bindProgramVertexOrtho();
+
+ // Fragment shader with texture
+ rsgBindProgramStore(gProgStoreBlendAlpha);
+ rsgBindProgramFragment(gProgFragmentTexture);
+ rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
+
+ drawMeshInPage(0, 0, wResolution, hResolution);
+ drawMeshInPage(-1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+ drawMeshInPage(1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+ if (meshMode == 1) {
+ // draw another two pages of meshes
+ drawMeshInPage(-2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+ drawMeshInPage(2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+ }
+}
+
static float gTorusRotation = 0;
static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) {
if (buffer == 0) {
@@ -532,8 +602,14 @@
"Geo test 25.6k heavy fragment heavy vertex",
"Geo test 51.2k heavy fragment heavy vertex",
"Geo test 204.8k small tries heavy fragment heavy vertex",
- "Mesh with 10 by 10 texture",
- "Mesh with 100 by 100 texture",
+ "UI test with icon display 10 by 10", // 25
+ "UI test with icon display 100 by 100", // 26
+ "UI test with image and text display 3 pages", // 27
+ "UI test with image and text display 5 pages", // 28
+ "UI test with list view", // 29
+// "UI test with live wallpaper", // 30
+// "Mesh with 10 by 10 texture",
+// "Mesh with 100 by 100 texture",
};
void getTestName(int testIndex) {
@@ -627,10 +703,16 @@
displayPixelLightSamples(8, true);
break;
case 25:
- displayMeshWithMultiTexture(0);
+ displayIcons(0);
break;
case 26:
- displayMeshWithMultiTexture(1);
+ displayIcons(1);
+ break;
+ case 27:
+ displayImageWithText(7, 5, 0);
+ break;
+ case 28:
+ displayImageWithText(7, 5, 1);
break;
}
}
@@ -683,6 +765,7 @@
gRenderSurfaceW = rsgGetWidth();
gRenderSurfaceH = rsgGetHeight();
int size = 8;
+ // draw each frame at (8, 3/4 gRenderSurfaceH) with size
drawOffscreenResult((drawPos+=size)%gRenderSurfaceW, (gRenderSurfaceH * 3) / 4, size, size);
}
@@ -692,11 +775,9 @@
float fps = (float)(frameCount) / ((float)(end - start)*0.001f);
rsDebug(testNames[benchMode], fps);
gResultBuffer[benchMode] = fps;
-
drawOffscreenResult(0, 0,
gRenderSurfaceW / 2,
gRenderSurfaceH / 2);
-
const char* text = testNames[benchMode];
int left = 0, right = 0, top = 0, bottom = 0;
uint width = rsgGetWidth();
diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp
index 8ac7590..223b1fa 100644
--- a/tools/aapt/Command.cpp
+++ b/tools/aapt/Command.cpp
@@ -343,6 +343,9 @@
REQUIRED_ATTR = 0x0101028e,
SCREEN_SIZE_ATTR = 0x010102ca,
SCREEN_DENSITY_ATTR = 0x010102cb,
+ REQUIRES_SMALLEST_WIDTH_DP_ATTR = 0x01010364,
+ COMPATIBLE_WIDTH_LIMIT_DP_ATTR = 0x01010365,
+ LARGEST_WIDTH_LIMIT_DP_ATTR = 0x01010366,
};
const char *getComponentName(String8 &pkgName, String8 &componentName) {
@@ -423,6 +426,24 @@
return 1;
}
+ // Make a dummy config for retrieving resources... we need to supply
+ // non-default values for some configs so that we can retrieve resources
+ // in the app that don't have a default. The most important of these is
+ // the API version because key resources like icons will have an implicit
+ // version if they are using newer config types like density.
+ ResTable_config config;
+ config.language[0] = 'e';
+ config.language[1] = 'n';
+ config.country[0] = 'U';
+ config.country[1] = 'S';
+ config.orientation = ResTable_config::ORIENTATION_PORT;
+ config.density = ResTable_config::DENSITY_MEDIUM;
+ config.sdkVersion = 10000; // Very high.
+ config.screenWidthDp = 320;
+ config.screenHeightDp = 480;
+ config.smallestScreenWidthDp = 320;
+ assets.setConfiguration(config);
+
const ResTable& res = assets.getResources(false);
if (&res == NULL) {
fprintf(stderr, "ERROR: dump failed because no resource table was found\n");
@@ -542,6 +563,19 @@
}
}
} else if (strcmp("badging", option) == 0) {
+ Vector<String8> locales;
+ res.getLocales(&locales);
+
+ Vector<ResTable_config> configs;
+ res.getConfigurations(&configs);
+ SortedVector<int> densities;
+ const size_t NC = configs.size();
+ for (size_t i=0; i<NC; i++) {
+ int dens = configs[i].density;
+ if (dens == 0) dens = 160;
+ densities.add(dens);
+ }
+
size_t len;
ResXMLTree::event_code_t code;
int depth = 0;
@@ -598,6 +632,8 @@
bool specTouchscreenFeature = false; // touchscreen-related
bool specMultitouchFeature = false;
bool reqDistinctMultitouchFeature = false;
+ bool specScreenPortraitFeature = false;
+ bool specScreenLandscapeFeature = false;
// 2.2 also added some other features that apps can request, but that
// have no corresponding permission, so we cannot implement any
// back-compatibility heuristic for them. The below are thus unnecessary
@@ -614,6 +650,9 @@
int largeScreen = 1;
int xlargeScreen = 1;
int anyDensity = 1;
+ int requiresSmallestWidthDp = 0;
+ int compatibleWidthLimitDp = 0;
+ int largestWidthLimitDp = 0;
String8 pkg;
String8 activityName;
String8 activityLabel;
@@ -628,10 +667,11 @@
} else if (depth < 3) {
if (withinActivity && isMainActivity && isLauncherActivity) {
const char *aName = getComponentName(pkg, activityName);
+ printf("launchable-activity:");
if (aName != NULL) {
- printf("launchable activity name='%s'", aName);
+ printf(" name='%s' ", aName);
}
- printf("label='%s' icon='%s'\n",
+ printf(" label='%s' icon='%s'\n",
activityLabel.string(),
activityIcon.string());
}
@@ -696,23 +736,51 @@
withinApplication = false;
if (tag == "application") {
withinApplication = true;
- String8 label = getResolvedAttribute(&res, tree, LABEL_ATTR, &error);
- if (error != "") {
- fprintf(stderr, "ERROR getting 'android:label' attribute: %s\n", error.string());
- goto bail;
+
+ String8 label;
+ const size_t NL = locales.size();
+ for (size_t i=0; i<NL; i++) {
+ const char* localeStr = locales[i].string();
+ assets.setLocale(localeStr != NULL ? localeStr : "");
+ String8 llabel = getResolvedAttribute(&res, tree, LABEL_ATTR, &error);
+ if (llabel != "") {
+ if (localeStr == NULL || strlen(localeStr) == 0) {
+ label = llabel;
+ printf("application-label:'%s'\n", llabel.string());
+ } else {
+ if (label == "") {
+ label = llabel;
+ }
+ printf("application-label-%s:'%s'\n", localeStr,
+ llabel.string());
+ }
+ }
}
- printf("application: label='%s' ", label.string());
+
+ ResTable_config tmpConfig = config;
+ const size_t ND = densities.size();
+ for (size_t i=0; i<ND; i++) {
+ tmpConfig.density = densities[i];
+ assets.setConfiguration(tmpConfig);
+ String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error);
+ if (icon != "") {
+ printf("application-icon-%d:'%s'\n", densities[i], icon.string());
+ }
+ }
+ assets.setConfiguration(config);
+
String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error);
if (error != "") {
fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string());
goto bail;
}
- printf("icon='%s'\n", icon.string());
int32_t testOnly = getIntegerAttribute(tree, TEST_ONLY_ATTR, &error, 0);
if (error != "") {
fprintf(stderr, "ERROR getting 'android:testOnly' attribute: %s\n", error.string());
goto bail;
}
+ printf("application: label='%s' ", label.string());
+ printf("icon='%s'\n", icon.string());
if (testOnly != 0) {
printf("testOnly='%d'\n", testOnly);
}
@@ -792,6 +860,12 @@
XLARGE_SCREEN_ATTR, NULL, 1);
anyDensity = getIntegerAttribute(tree,
ANY_DENSITY_ATTR, NULL, 1);
+ requiresSmallestWidthDp = getIntegerAttribute(tree,
+ REQUIRES_SMALLEST_WIDTH_DP_ATTR, NULL, 0);
+ compatibleWidthLimitDp = getIntegerAttribute(tree,
+ COMPATIBLE_WIDTH_LIMIT_DP_ATTR, NULL, 0);
+ largestWidthLimitDp = getIntegerAttribute(tree,
+ LARGEST_WIDTH_LIMIT_DP_ATTR, NULL, 0);
} else if (tag == "uses-feature") {
String8 name = getAttribute(tree, NAME_ATTR, &error);
@@ -837,6 +911,10 @@
// these have no corresponding permission to check for,
// but should imply the foundational telephony permission
reqTelephonySubFeature = true;
+ } else if (name == "android.hardware.screen.portrait") {
+ specScreenPortraitFeature = true;
+ } else if (name == "android.hardware.screen.landscape") {
+ specScreenLandscapeFeature = true;
}
printf("uses-feature%s:'%s'\n",
req ? "" : "-not-required", name.string());
@@ -1103,6 +1181,15 @@
printf("uses-feature:'android.hardware.touchscreen.multitouch'\n");
}
+ // Landscape/portrait-related compatibility logic
+ if (!specScreenLandscapeFeature && !specScreenPortraitFeature && (targetSdk < 13)) {
+ // If app has not specified whether it requires portrait or landscape
+ // and is targeting an API before Honeycomb MR2, then assume it requires
+ // both.
+ printf("uses-feature:'android.hardware.screen.portrait'\n");
+ printf("uses-feature:'android.hardware.screen.landscape'\n");
+ }
+
if (hasMainActivity) {
printf("main\n");
}
@@ -1128,6 +1215,34 @@
printf("other-services\n");
}
+ // For modern apps, if screen size buckets haven't been specified
+ // but the new width ranges have, then infer the buckets from them.
+ if (smallScreen > 0 && normalScreen > 0 && largeScreen > 0 && xlargeScreen > 0
+ && requiresSmallestWidthDp > 0) {
+ int compatWidth = compatibleWidthLimitDp;
+ if (compatWidth <= 0) compatWidth = requiresSmallestWidthDp;
+ if (requiresSmallestWidthDp <= 240 && compatWidth >= 240) {
+ smallScreen = -1;
+ } else {
+ smallScreen = 0;
+ }
+ if (requiresSmallestWidthDp <= 320 && compatWidth >= 320) {
+ normalScreen = -1;
+ } else {
+ normalScreen = 0;
+ }
+ if (requiresSmallestWidthDp <= 480 && compatWidth >= 480) {
+ largeScreen = -1;
+ } else {
+ largeScreen = 0;
+ }
+ if (requiresSmallestWidthDp <= 720 && compatWidth >= 720) {
+ xlargeScreen = -1;
+ } else {
+ xlargeScreen = 0;
+ }
+ }
+
// Determine default values for any unspecified screen sizes,
// based on the target SDK of the package. As of 4 (donut)
// the screen size support was introduced, so all default to
@@ -1146,7 +1261,8 @@
xlargeScreen = targetSdk >= 9 ? -1 : 0;
}
if (anyDensity > 0) {
- anyDensity = targetSdk >= 4 ? -1 : 0;
+ anyDensity = (targetSdk >= 4 || requiresSmallestWidthDp > 0
+ || compatibleWidthLimitDp > 0) ? -1 : 0;
}
printf("supports-screens:");
if (smallScreen != 0) printf(" 'small'");
@@ -1154,12 +1270,18 @@
if (largeScreen != 0) printf(" 'large'");
if (xlargeScreen != 0) printf(" 'xlarge'");
printf("\n");
-
printf("supports-any-density: '%s'\n", anyDensity ? "true" : "false");
+ if (requiresSmallestWidthDp > 0) {
+ printf("requires-smallest-width:'%d'\n", requiresSmallestWidthDp);
+ }
+ if (compatibleWidthLimitDp > 0) {
+ printf("compatible-width-limit:'%d'\n", compatibleWidthLimitDp);
+ }
+ if (largestWidthLimitDp > 0) {
+ printf("largest-width-limit:'%d'\n", largestWidthLimitDp);
+ }
printf("locales:");
- Vector<String8> locales;
- res.getLocales(&locales);
const size_t NL = locales.size();
for (size_t i=0; i<NL; i++) {
const char* localeStr = locales[i].string();
@@ -1170,16 +1292,6 @@
}
printf("\n");
- Vector<ResTable_config> configs;
- res.getConfigurations(&configs);
- SortedVector<int> densities;
- const size_t NC = configs.size();
- for (size_t i=0; i<NC; i++) {
- int dens = configs[i].density;
- if (dens == 0) dens = 160;
- densities.add(dens);
- }
-
printf("densities:");
const size_t ND = densities.size();
for (size_t i=0; i<ND; i++) {