Skip to content

Commit fb9aa9f

Browse files
author
Jason Sams
committed
Convert from SurfaceTexture to Surface
Change-Id: I2ad4307294d4144999ca0c12ac19849b188243fb
1 parent 972ed58 commit fb9aa9f

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

graphics/java/android/renderscript/Allocation.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.content.res.AssetManager;
2323
import android.graphics.Bitmap;
2424
import android.graphics.BitmapFactory;
25+
import android.view.Surface;
2526
import android.graphics.SurfaceTexture;
2627
import android.util.Log;
2728
import android.util.TypedValue;
@@ -1185,17 +1186,38 @@ public SurfaceTexture getSurfaceTexture() {
11851186
}
11861187

11871188
/**
1189+
*
11881190
* @hide
1191+
*
11891192
*/
1190-
public void setSurfaceTexture(SurfaceTexture sur) {
1193+
public Surface getSurface() {
1194+
return new Surface(getSurfaceTexture());
1195+
}
1196+
1197+
/**
1198+
* @hide
1199+
*/
1200+
public void setSurface(Surface sur) {
1201+
mRS.validate();
11911202
if ((mUsage & USAGE_IO_OUTPUT) == 0) {
11921203
throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT.");
11931204
}
11941205

1195-
mRS.validate();
1196-
mRS.nAllocationSetSurfaceTexture(getID(), sur);
1206+
mRS.nAllocationSetSurface(getID(), sur);
11971207
}
11981208

1209+
/**
1210+
* @hide
1211+
*/
1212+
public void setSurfaceTexture(SurfaceTexture st) {
1213+
mRS.validate();
1214+
if ((mUsage & USAGE_IO_OUTPUT) == 0) {
1215+
throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT.");
1216+
}
1217+
1218+
Surface s = new Surface(st);
1219+
mRS.nAllocationSetSurface(getID(), s);
1220+
}
11991221

12001222
/**
12011223
* Creates a non-mipmapped renderscript allocation to use as a

graphics/java/android/renderscript/RenderScript.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ synchronized void nAllocationGetSurfaceTextureID2(int alloc, SurfaceTexture st)
299299
validate();
300300
rsnAllocationGetSurfaceTextureID2(mContext, alloc, st);
301301
}
302-
native void rsnAllocationSetSurfaceTexture(int con, int alloc, SurfaceTexture sur);
303-
synchronized void nAllocationSetSurfaceTexture(int alloc, SurfaceTexture sur) {
302+
native void rsnAllocationSetSurface(int con, int alloc, Surface sur);
303+
synchronized void nAllocationSetSurface(int alloc, Surface sur) {
304304
validate();
305-
rsnAllocationSetSurfaceTexture(mContext, alloc, sur);
305+
rsnAllocationSetSurface(mContext, alloc, sur);
306306
}
307307
native void rsnAllocationIoSend(int con, int alloc);
308308
synchronized void nAllocationIoSend(int alloc) {

graphics/jni/android_renderscript_RenderScript.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include <rs.h>
4343
#include <rsEnv.h>
44+
#include <gui/Surface.h>
4445
#include <gui/SurfaceTexture.h>
4546
#include <gui/SurfaceTextureClient.h>
4647
#include <android_runtime/android_graphics_SurfaceTexture.h>
@@ -486,19 +487,17 @@ nAllocationGetSurfaceTextureID2(JNIEnv *_env, jobject _this, RsContext con, jint
486487
}
487488

488489
static void
489-
nAllocationSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con,
490-
RsAllocation alloc, jobject sur)
490+
nAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
491491
{
492492
LOG_API("nAllocationSetSurfaceTexture, con(%p), alloc(%p), surface(%p)",
493493
con, alloc, (Surface *)sur);
494494

495-
sp<ANativeWindow> window;
495+
sp<Surface> s;
496496
if (sur != 0) {
497-
sp<SurfaceTexture> st = SurfaceTexture_getSurfaceTexture(_env, sur);
498-
window = new SurfaceTextureClient(st);
497+
s = Surface_getSurface(_env, sur);
499498
}
500499

501-
rsAllocationSetSurface(con, alloc, window.get());
500+
rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
502501
}
503502

504503
static void
@@ -1362,7 +1361,7 @@ static JNINativeMethod methods[] = {
13621361
{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
13631362
{"rsnAllocationGetSurfaceTextureID", "(II)I", (void*)nAllocationGetSurfaceTextureID },
13641363
{"rsnAllocationGetSurfaceTextureID2","(IILandroid/graphics/SurfaceTexture;)V",(void*)nAllocationGetSurfaceTextureID2 },
1365-
{"rsnAllocationSetSurfaceTexture", "(IILandroid/graphics/SurfaceTexture;)V",(void*)nAllocationSetSurfaceTexture },
1364+
{"rsnAllocationSetSurface", "(IILandroid/view/Surface;)V", (void*)nAllocationSetSurface },
13661365
{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
13671366
{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
13681367
{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },

0 commit comments

Comments
 (0)