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

Commit 1549257d authored by Jason Sams's avatar Jason Sams Committed by Android (Google) Code Review
Browse files

Merge "Support defered generation of mipmaps. With this change we support...

Merge "Support defered generation of mipmaps.  With this change we support mipmap generation when the texture is uploaded to GL without requiring RS to retain the full chain."
parents 053100e6 c2908e60
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -45,7 +45,12 @@ public class Allocation extends BaseObj {

    public void uploadToTexture(int baseMipLevel) {
        mRS.validate();
        mRS.nAllocationUploadToTexture(mID, baseMipLevel);
        mRS.nAllocationUploadToTexture(mID, false, baseMipLevel);
    }

    public void uploadToTexture(boolean genMips, int baseMipLevel) {
        mRS.validate();
        mRS.nAllocationUploadToTexture(mID, genMips, baseMipLevel);
    }

    public void uploadToBufferObject() {
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public class RenderScript {
    native int  nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
    native int  nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream);

    native void nAllocationUploadToTexture(int alloc, int baseMioLevel);
    native void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel);
    native void nAllocationUploadToBufferObject(int alloc);

    native void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes);
+4 −4
Original line number Diff line number Diff line
@@ -444,11 +444,11 @@ nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e)
}

static void
nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip)
nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jboolean genMip, jint mip)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip);
    rsAllocationUploadToTexture(con, (RsAllocation)a, mip);
    LOG_API("nAllocationUploadToTexture, con(%p), a(%p), genMip(%i), mip(%i)", con, (RsAllocation)a, genMip, mip);
    rsAllocationUploadToTexture(con, (RsAllocation)a, genMip, mip);
}

static void
@@ -1369,7 +1369,7 @@ static JNINativeMethod methods[] = {
{"nAllocationCreateFromBitmap",    "(IZLandroid/graphics/Bitmap;)I",       (void*)nAllocationCreateFromBitmap },
{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I",      (void*)nAllocationCreateFromBitmapBoxed },
{"nAllocationCreateFromAssetStream","(IZI)I",                              (void*)nAllocationCreateFromAssetStream },
{"nAllocationUploadToTexture",     "(II)V",                                (void*)nAllocationUploadToTexture },
{"nAllocationUploadToTexture",     "(IZI)V",                               (void*)nAllocationUploadToTexture },
{"nAllocationUploadToBufferObject","(I)V",                                 (void*)nAllocationUploadToBufferObject },
{"nAllocationSubData1D",           "(III[II)V",                            (void*)nAllocationSubData1D_i },
{"nAllocationSubData1D",           "(III[SI)V",                            (void*)nAllocationSubData1D_s },
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ AllocationCreateFromBitmapBoxed {

AllocationUploadToTexture {
	param RsAllocation alloc
	param bool genMipMaps
	param uint32_t baseMipLevel
	}

+9 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "rsContext.h"

#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES/glext.h>

using namespace android;
@@ -88,12 +89,13 @@ bool Allocation::fixAllocation()
    return false;
}

void Allocation::deferedUploadToTexture(const Context *rsc, uint32_t lodOffset)
void Allocation::deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset)
{
    rsAssert(lodOffset < mType->getLODCount());
    mIsTexture = true;
    mTextureLOD = lodOffset;
    mUploadDefered = true;
    mTextureGenMipmap = !mType->getDimLOD() && genMipmap;
}

void Allocation::uploadToTexture(const Context *rsc)
@@ -138,6 +140,10 @@ void Allocation::uploadToTexture(const Context *rsc)
                     adapt.getDimX(), adapt.getDimY(),
                     0, format, type, ptr);
    }
    if (mTextureGenMipmap) {
        glGenerateMipmap(GL_TEXTURE_2D);
    }

}

void Allocation::deferedUploadToBufferObject(const Context *rsc)
@@ -316,10 +322,10 @@ RsAllocation rsi_AllocationCreateSized(Context *rsc, RsElement e, size_t count)
    return rsi_AllocationCreateTyped(rsc, type);
}

void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, uint32_t baseMipLevel)
void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel)
{
    Allocation *alloc = static_cast<Allocation *>(va);
    alloc->deferedUploadToTexture(rsc, baseMipLevel);
    alloc->deferedUploadToTexture(rsc, genmip, baseMipLevel);
}

void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va)
Loading