OSDN Git Service

Don't set Allocation mSize when we have no Type.
authorStephen Hines <srhines@google.com>
Tue, 10 Sep 2013 00:56:07 +0000 (17:56 -0700)
committerStephen Hines <srhines@google.com>
Tue, 10 Sep 2013 00:56:07 +0000 (17:56 -0700)
Bug: 10667740

A3D creates Allocations before knowing the underlying Type (and thus size).
Moving the mSize calculation to be conditional for concrete Allocations
eliminates the bug. In the future, we could let A3D dynamically update the
Allocation size if it is necessary to improve heap behavior.

Change-Id: I520246806b6ead0387a1a41372dade1a6e7c2271

graphics/java/android/renderscript/Allocation.java

index ca72c25..dca934f 100644 (file)
@@ -269,9 +269,12 @@ public class Allocation extends BaseObj {
 
         mType = t;
         mUsage = usage;
-        mSize = mType.getCount() * mType.getElement().getBytesSize();
 
         if (t != null) {
+            // TODO: A3D doesn't have Type info during creation, so we can't
+            // calculate the size ahead of time. We can possibly add a method
+            // to update the size in the future if it seems reasonable.
+            mSize = mType.getCount() * mType.getElement().getBytesSize();
             updateCacheInfo(t);
         }
         try {