Skip to content

Commit 059fede

Browse files
committed
[Renderscript] Incremental Support for Intrinsics.
- If Intrinsic API is higher than Device API, run on compat context. - By default, run on Native RS if available. - If forced using compat mode, or Device API<=19, Just fall back to regular compat mode. Change-Id: Icb0a87ea4bcf0524c1ed2841702f1cc4f04ea24d
1 parent 216d08f commit 059fede

17 files changed

+1364
-202
lines changed

v8/renderscript/java/src/android/support/v8/renderscript/Allocation.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.io.InputStream;
21+
import java.util.concurrent.locks.ReentrantReadWriteLock;
2122
import android.content.res.Resources;
2223
import android.content.res.AssetManager;
2324
import android.graphics.Bitmap;
@@ -138,7 +139,12 @@ private Element.DataType validateObjectIsPrimitiveArray(Object d, boolean checkT
138139
return null;
139140
}
140141

141-
142+
/*
143+
* Hold reference to the shared allocation in compat context
144+
* for Incremental Support Lib.
145+
*/
146+
long mIncCompatAllocation;
147+
boolean mIncAllocDestroyed;
142148
/**
143149
* The usage of the Allocation. These signal to RenderScript where to place
144150
* the Allocation in memory.
@@ -218,6 +224,16 @@ public enum MipmapControl {
218224
}
219225
}
220226

227+
/**
228+
* Getter & Setter for the dummy allocation for Inc Support Lib.
229+
*
230+
*/
231+
public long getIncAllocID() {
232+
return mIncCompatAllocation;
233+
}
234+
public void setIncAllocID(long id) {
235+
mIncCompatAllocation = id;
236+
}
221237

222238
private long getIDSafe() {
223239
if (mAdaptedAllocation != null) {
@@ -311,6 +327,8 @@ private void setBitmap(Bitmap b) {
311327

312328
mType = t;
313329
mUsage = usage;
330+
mIncCompatAllocation = 0;
331+
mIncAllocDestroyed = false;
314332

315333
if (t != null) {
316334
// TODO: A3D doesn't have Type info during creation, so we can't
@@ -2211,15 +2229,38 @@ static public Allocation createFromString(RenderScript rs,
22112229
}
22122230

22132231
/**
2232+
* Frees any native resources associated with this object. The
2233+
* primary use is to force immediate cleanup of resources when it is
2234+
* believed the GC will not respond quickly enough.
22142235
* For USAGE_IO_OUTPUT, destroy() implies setSurface(null).
2215-
*
22162236
*/
22172237
@Override
22182238
public void destroy() {
2219-
if((mUsage & USAGE_IO_OUTPUT) != 0) {
2239+
if (mIncCompatAllocation != 0) {
2240+
boolean shouldDestroy = false;
2241+
synchronized(this) {
2242+
if (!mIncAllocDestroyed) {
2243+
shouldDestroy = true;
2244+
mIncAllocDestroyed = true;
2245+
}
2246+
}
2247+
2248+
if (shouldDestroy) {
2249+
// must include nObjDestroy in the critical section
2250+
ReentrantReadWriteLock.ReadLock rlock = mRS.mRWLock.readLock();
2251+
rlock.lock();
2252+
if(mRS.isAlive()) {
2253+
mRS.nIncObjDestroy(mIncCompatAllocation);
2254+
}
2255+
rlock.unlock();
2256+
mIncCompatAllocation = 0;
2257+
}
2258+
}
2259+
if ((mUsage & (USAGE_IO_INPUT | USAGE_IO_OUTPUT)) != 0) {
22202260
setSurface(null);
22212261
}
22222262
super.destroy();
22232263
}
2264+
22242265
}
22252266

v8/renderscript/java/src/android/support/v8/renderscript/Element.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ public static Element MATRIX_2X2(RenderScript rs) {
754754
super(id, rs);
755755
}
756756

757+
/*
758+
* Get an identical dummy Element for Compat Context
759+
*
760+
*/
761+
public long getDummyElement(RenderScript mRS) {
762+
return mRS.nIncElementCreate(mType.mID, mKind.mID, mNormalized, mVectorSize);
763+
}
757764
/**
758765
* Create a custom Element of the specified DataType. The DataKind will be
759766
* set to USER and the vector size to 1 indicating non-vector.

0 commit comments

Comments
 (0)