Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe170db1 authored by Steve Kondik's avatar Steve Kondik
Browse files

Revert "Load and upload texture data avoiding memcpy"

This reverts commit cf67fa9b.
parent b3b9ceed
Loading
Loading
Loading
Loading
+1 −43
Original line number Diff line number Diff line
@@ -253,19 +253,6 @@ public class Allocation extends BaseObj {
        return new Allocation(id, rs, t);
    }

    static public void createAndUploadFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips, String name,int basemipLevel)
        throws IllegalArgumentException {
        rs.validate();
	int id = rs.nAllocationCreateAndUploadFromBitmap(dstFmt.mID, genMips, b,basemipLevel);
	try{
	byte bytes[] = name.getBytes("UTF-8");
	rs.nAssignName(id,bytes);
	}catch(java.io.UnsupportedEncodingException e){
	throw new RuntimeException(e);
	}
        return;
    }

    static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
        throws IllegalArgumentException {

@@ -304,36 +291,7 @@ public class Allocation extends BaseObj {
        int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
        return new Allocation(id, rs, null);
    }
    static public void createAndUploadFromBitmapResource(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips ,String name ,int basemipLevel)
	throws IllegalArgumentException {
	rs.validate();
	InputStream is = null;
	try {
		final TypedValue value = new TypedValue();
		is = res.openRawResource(id, value);
		int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
		int allocationId = rs.nAllocationCreateAndUploadFromAssetStream(dstFmt.mID, genMips,
				asset,basemipLevel);
		try{
		byte bytes[] = name.getBytes("UTF-8");
		rs.nAssignName(allocationId,bytes);
		}catch(java.io.UnsupportedEncodingException e){
		throw new RuntimeException(e);
		}
		return;
	} catch (Exception e) {
		// Ignore
		} finally {
		if (is != null) {
		try {
			is.close();
			} catch (IOException e) {
			// Ignore
			}
		}
	}
	return;
	}

    static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips)
        throws IllegalArgumentException {

+0 −2
Original line number Diff line number Diff line
@@ -101,14 +101,12 @@ public class RenderScript {

    native int  nAllocationCreateTyped(int type);
    native int  nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
    native int  nAllocationCreateAndUploadFromBitmap(int dstFmt, boolean genMips, Bitmap bmp,int basemipLevel);
    native int  nAllocationCreateFromBitmap1(int index, int dstFmt, boolean genMips, Bitmap bmp);
    native int  nAllocationAddToAllocationList(int index);
    native int  nAllocationRemoveFromAllocationList(int index);
    native int  nAllocationCreateAllocationList(int count);
    native int  nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
    native int  nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream);
    native int  nAllocationCreateAndUploadFromAssetStream(int dstFmt, boolean genMips, int assetStream,int basemipLevel);

    native void nAllocationUploadToTexture(int alloc, int baseMioLevel);
    native void nAllocationUploadToBufferObject(int alloc);
+0 −53
Original line number Diff line number Diff line
@@ -471,29 +471,6 @@ static RsElement SkBitmapToPredefined(SkBitmap::Config cfg)
    return NULL;
}

static int 
nAllocationCreateAndUploadFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap, jint basemipLevel)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    SkBitmap const * nativeBitmap =
            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
    const SkBitmap& bitmap(*nativeBitmap);
    SkBitmap::Config config = bitmap.getConfig();

    RsElement e = SkBitmapToPredefined(config);
    if (e) {
        bitmap.lockPixels();
        const int w = bitmap.width();
        const int h = bitmap.height();
        const void* ptr = bitmap.getPixels();
        jint id = (jint)rsAllocationCreateAndUploadFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr,basemipLevel);
        bitmap.unlockPixels();
        return id;
    }
    return 0;
}


static int
nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
{
@@ -562,33 +539,6 @@ nAllocationCreateAllocationList(JNIEnv *_env, jobject _this, jint index)
    return 0;
}

static int
nAllocationCreateAndUploadFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset,jint basemipLevel)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));

    Asset* asset = reinterpret_cast<Asset*>(native_asset);
    SkBitmap bitmap;
    SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(),
            &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode);

    SkBitmap::Config config = bitmap.getConfig();

    RsElement e = SkBitmapToPredefined(config);

    if (e) {
        bitmap.lockPixels();
        const int w = bitmap.width();
        const int h = bitmap.height();
        const void* ptr = bitmap.getPixels();
        jint id = (jint)rsAllocationCreateAndUploadFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr,basemipLevel);
        bitmap.unlockPixels();
        return id ;
    }
    return 0;
}


static int
nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset)
{
@@ -1473,15 +1423,12 @@ static JNINativeMethod methods[] = {

{"nAllocationCreateTyped",         "(I)I",                                 (void*)nAllocationCreateTyped },
{"nAllocationCreateFromBitmap",    "(IZLandroid/graphics/Bitmap;)I",       (void*)nAllocationCreateFromBitmap },
{"nAllocationCreateAndUploadFromBitmap",    "(IZLandroid/graphics/Bitmap;I)I",	   (void*)nAllocationCreateAndUploadFromBitmap },
{"nAllocationCreateFromBitmap1",   "(IIZLandroid/graphics/Bitmap;)I",      (void*)nAllocationCreateFromBitmap1 },
{"nAllocationAddToAllocationList", "(I)I",                                 (void*)nAllocationAddToAllocationList},
{"nAllocationRemoveFromAllocationList", "(I)I",                            (void*)nAllocationRemoveFromAllocationList},
{"nAllocationCreateAllocationList", "(I)I",                                (void*)nAllocationCreateAllocationList},
{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I",      (void*)nAllocationCreateFromBitmapBoxed },
{"nAllocationCreateFromAssetStream","(IZI)I",                              (void*)nAllocationCreateFromAssetStream },
{"nAllocationCreateAndUploadFromAssetStream","(IZII)I",							   (void*)nAllocationCreateAndUploadFromAssetStream },

{"nAllocationUploadToTexture",     "(II)V",                                (void*)nAllocationUploadToTexture },
{"nAllocationUploadToBufferObject","(I)V",                                 (void*)nAllocationUploadToBufferObject },
{"nAllocationSubData1D",           "(III[II)V",                            (void*)nAllocationSubData1D_i },
+0 −10
Original line number Diff line number Diff line
@@ -99,16 +99,6 @@ AllocationCreateSized {
	ret RsAllocation
	}

AllocationCreateAndUploadFromBitmap {
	param uint32_t width
	param uint32_t height
	param RsElement dstFmt
	param RsElement srcFmt
	param bool genMips
	param const void * data
	param uint32_t basemipLevel
	ret RsAllocation
	}
AllocationCreateFromBitmap {
	param uint32_t width
	param uint32_t height

libs/rs/rsAllocation.cpp

100755 → 100644
+0 −48
Original line number Diff line number Diff line
@@ -434,54 +434,6 @@ static ElementConverter_t pickConverter(const Element *dst, const Element *src)
    return 0;
}

RsAllocation rsi_AllocationCreateAndUploadFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElement _dst, RsElement _src,  bool genMips, const void *data, uint32_t basemipLevel)
{
    const Element *src = static_cast<const Element *>(_src);
    const Element *dst = static_cast<const Element *>(_dst);
    rsAssert(!(w & (w-1)));
    rsAssert(!(h & (h-1)));

    //LOGE("rsi_AllocationCreateFromBitmap %i %i %i %i %i", w, h, dstFmt, srcFmt, genMips);
    rsi_TypeBegin(rsc, _dst);
    rsi_TypeAdd(rsc, RS_DIMENSION_X, w);
    rsi_TypeAdd(rsc, RS_DIMENSION_Y, h);
    if (genMips) {
        rsi_TypeAdd(rsc, RS_DIMENSION_LOD, 1);
    }
    RsType type = rsi_TypeCreate(rsc);
    RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, type);
    Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
    if (texAlloc == NULL) {
        LOGE("Memory allocation failure");
        return NULL;
    }

	void** temp_buffer = texAlloc->getPtrAddr();
	if(*temp_buffer != NULL){
		free(*temp_buffer);
		*temp_buffer = NULL;
		}
	*temp_buffer = const_cast<void*>(data);

    //ElementConverter_t cvt = pickConverter(dst, src);
    //cvt(texAlloc->getPtr(), data, w * h);

    if (genMips) {
        Adapter2D adapt(rsc, texAlloc);
        Adapter2D adapt2(rsc, texAlloc);
        for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
            adapt.setLOD(lod);
            adapt2.setLOD(lod + 1);
            mip(adapt2, adapt);
        }
    }

	texAlloc->uploadToTexture(rsc,basemipLevel);
	*temp_buffer = NULL;


    return texAlloc;
}

RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElement _dst, RsElement _src,  bool genMips, const void *data)
{
Loading