summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/BitmapFactory.java74
-rw-r--r--graphics/java/android/graphics/BitmapRegionDecoder.java7
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java19
-rw-r--r--graphics/java/android/renderscript/Allocation.java13
-rw-r--r--graphics/java/android/renderscript/RenderScript.java14
5 files changed, 81 insertions, 46 deletions
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
index 1c426fd..1721bee 100644
--- a/graphics/java/android/graphics/BitmapFactory.java
+++ b/graphics/java/android/graphics/BitmapFactory.java
@@ -23,7 +23,6 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
-import java.io.BufferedInputStream;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
@@ -545,28 +544,28 @@ public class BitmapFactory {
return null;
}
- Bitmap bm;
+ Bitmap bm = null;
Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap");
try {
- // we need mark/reset to work properly
- if (!is.markSupported()) {
- is = new BufferedInputStream(is, DECODE_BUFFER_SIZE);
- }
-
- // so we can call reset() if a given codec gives up after reading up to
- // this many bytes. FIXME: need to find out from the codecs what this
- // value should be.
- is.mark(1024);
-
+ boolean decodeGenericStream = true;
if (is instanceof AssetManager.AssetInputStream) {
final int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
bm = nativeDecodeAsset(asset, outPadding, opts);
- } else {
- // pass some temp storage down to the native code. 1024 is made up,
- // but should be large enough to avoid too many small calls back
- // into is.read(...) This number is not related to the value passed
- // to mark(...) above.
+ // Do not follow the normal case.
+ decodeGenericStream = false;
+ } else if (is instanceof FileInputStream) {
+ try {
+ FileDescriptor fd = ((FileInputStream) is).getFD();
+ // decodeFileDescriptor will take care of throwing the IAE and
+ // calling setDensityFromOptions.
+ return decodeFileDescriptor(fd, outPadding, opts);
+ } catch (IOException e) {
+ // Fall through to nativeDecodeStream.
+ }
+ }
+
+ if (decodeGenericStream) {
byte [] tempStorage = null;
if (opts != null) tempStorage = opts.inTempStorage;
if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE];
@@ -610,26 +609,41 @@ public class BitmapFactory {
* no bitmap is returned (null) then padding is
* unchanged.
* @param opts null-ok; Options that control downsampling and whether the
- * image should be completely decoded, or just is size returned.
+ * image should be completely decoded, or just its size returned.
* @return the decoded bitmap, or null
*/
public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) {
- if (nativeIsSeekable(fd)) {
- Bitmap bm = nativeDecodeFileDescriptor(fd, outPadding, opts);
+ Bitmap bm;
+
+ Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeFileDescriptor");
+ try {
+ if (nativeIsSeekable(fd)) {
+ bm = nativeDecodeFileDescriptor(fd, outPadding, opts);
+ } else {
+ FileInputStream fis = new FileInputStream(fd);
+ // FIXME: If nativeDecodeStream grabbed the pointer to tempStorage
+ // from Options, this code would not need to be duplicated.
+ byte [] tempStorage = null;
+ if (opts != null) tempStorage = opts.inTempStorage;
+ if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE];
+ try {
+ bm = nativeDecodeStream(fis, tempStorage, outPadding, opts);
+ } finally {
+ try {
+ fis.close();
+ } catch (Throwable t) {/* ignore */}
+ }
+ }
+
if (bm == null && opts != null && opts.inBitmap != null) {
throw new IllegalArgumentException("Problem decoding into existing bitmap");
}
- return bm;
- } else {
- FileInputStream fis = new FileInputStream(fd);
- try {
- return decodeStream(fis, outPadding, opts);
- } finally {
- try {
- fis.close();
- } catch (Throwable t) {/* ignore */}
- }
+
+ setDensityFromOptions(bm, opts);
+ } finally {
+ Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS);
}
+ return bm;
}
/**
diff --git a/graphics/java/android/graphics/BitmapRegionDecoder.java b/graphics/java/android/graphics/BitmapRegionDecoder.java
index b38d107..3524b25 100644
--- a/graphics/java/android/graphics/BitmapRegionDecoder.java
+++ b/graphics/java/android/graphics/BitmapRegionDecoder.java
@@ -17,7 +17,6 @@ package android.graphics;
import android.content.res.AssetManager;
-import java.io.BufferedInputStream;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
@@ -108,12 +107,6 @@ public final class BitmapRegionDecoder {
*/
public static BitmapRegionDecoder newInstance(InputStream is,
boolean isShareable) throws IOException {
- // we need mark/reset to work properly in JNI
-
- if (!is.markSupported()) {
- is = new BufferedInputStream(is, 16 * 1024);
- }
-
if (is instanceof AssetManager.AssetInputStream) {
return nativeNewInstance(
((AssetManager.AssetInputStream) is).getAssetInt(),
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index d226c8c..b340777 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -19,6 +19,7 @@ package android.graphics.drawable;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.DashPathEffect;
import android.graphics.LinearGradient;
@@ -747,9 +748,6 @@ public class GradientDrawable extends Drawable {
mFillPaint.setShader(new LinearGradient(x0, y0, x1, y1,
colors, st.mPositions, Shader.TileMode.CLAMP));
- if (!mGradientState.mHasSolidColor) {
- mFillPaint.setColor(mAlpha << 24);
- }
} else if (st.mGradient == RADIAL_GRADIENT) {
x0 = r.left + (r.right - r.left) * st.mCenterX;
y0 = r.top + (r.bottom - r.top) * st.mCenterY;
@@ -759,9 +757,6 @@ public class GradientDrawable extends Drawable {
mFillPaint.setShader(new RadialGradient(x0, y0,
level * st.mGradientRadius, colors, null,
Shader.TileMode.CLAMP));
- if (!mGradientState.mHasSolidColor) {
- mFillPaint.setColor(mAlpha << 24);
- }
} else if (st.mGradient == SWEEP_GRADIENT) {
x0 = r.left + (r.right - r.left) * st.mCenterX;
y0 = r.top + (r.bottom - r.top) * st.mCenterY;
@@ -792,9 +787,12 @@ public class GradientDrawable extends Drawable {
}
mFillPaint.setShader(new SweepGradient(x0, y0, tempColors, tempPositions));
- if (!mGradientState.mHasSolidColor) {
- mFillPaint.setColor(mAlpha << 24);
- }
+ }
+
+ // If we don't have a solid color, the alpha channel must be
+ // maxed out so that alpha modulation works correctly.
+ if (!st.mHasSolidColor) {
+ mFillPaint.setColor(Color.BLACK);
}
}
}
@@ -1281,6 +1279,9 @@ public class GradientDrawable extends Drawable {
// the app is stroking the shape, set the color to the default
// value of state.mSolidColor
mFillPaint.setColor(0);
+ } else {
+ // Otherwise, make sure the fill alpha is maxed out.
+ mFillPaint.setColor(Color.BLACK);
}
mPadding = state.mPadding;
if (state.mStrokeWidth >= 0) {
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 1a2f35e..ca72c25 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -61,6 +61,7 @@ public class Allocation extends BaseObj {
Bitmap mBitmap;
int mUsage;
Allocation mAdaptedAllocation;
+ int mSize;
boolean mConstrainedLOD;
boolean mConstrainedFace;
@@ -268,10 +269,22 @@ public class Allocation extends BaseObj {
mType = t;
mUsage = usage;
+ mSize = mType.getCount() * mType.getElement().getBytesSize();
if (t != null) {
updateCacheInfo(t);
}
+ try {
+ RenderScript.registerNativeAllocation.invoke(RenderScript.sRuntime, mSize);
+ } catch (Exception e) {
+ Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
+ throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
+ }
+ }
+
+ protected void finalize() throws Throwable {
+ RenderScript.registerNativeFree.invoke(RenderScript.sRuntime, mSize);
+ super.finalize();
}
private void validateIsInt32() {
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 4de4766..854f079 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -18,6 +18,7 @@ package android.renderscript;
import java.io.File;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -61,11 +62,24 @@ public class RenderScript {
static boolean sInitialized;
native static void _nInit();
+ static Object sRuntime;
+ static Method registerNativeAllocation;
+ static Method registerNativeFree;
static {
sInitialized = false;
if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
try {
+ Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
+ Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
+ sRuntime = get_runtime.invoke(null);
+ registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE);
+ registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE);
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "Error loading GC methods: " + e);
+ throw new RSRuntimeException("Error loading GC methods: " + e);
+ }
+ try {
System.loadLibrary("rs_jni");
_nInit();
sInitialized = true;