Merge "Fix mipmap bug introduced with Allocation cleanup. Add syncAll to rsg headers."

This commit is contained in:
Jason Sams
2010-12-15 02:11:26 -08:00
committed by Android (Google) Code Review
9 changed files with 67 additions and 48 deletions

View File

@@ -452,13 +452,9 @@ public class Allocation extends BaseObj {
return new Allocation(id, rs, t, usage);
}
static public Allocation createFromBitmap(RenderScript rs, Bitmap b,
Element dstFmt, boolean genMips) {
MipmapControl mc = MipmapControl.MIPMAP_NONE;
if (genMips) {
mc = MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE;
}
return createFromBitmap(rs, b, mc, USAGE_GRAPHICS_TEXTURE);
static public Allocation createFromBitmap(RenderScript rs, Bitmap b) {
return createFromBitmap(rs, b, MipmapControl.MIPMAP_NONE,
USAGE_GRAPHICS_TEXTURE);
}
static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b,
@@ -500,14 +496,9 @@ public class Allocation extends BaseObj {
}
static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b,
Element dstFmt,
boolean genMips,
CubemapLayout layout) {
MipmapControl mc = MipmapControl.MIPMAP_NONE;
if (genMips) {
mc = MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE;
}
return createCubemapFromBitmap(rs, b, mc, layout, USAGE_GRAPHICS_TEXTURE);
return createCubemapFromBitmap(rs, b, MipmapControl.MIPMAP_NONE,
layout, USAGE_GRAPHICS_TEXTURE);
}
static public Allocation createFromBitmapResource(RenderScript rs,
@@ -523,6 +514,15 @@ public class Allocation extends BaseObj {
return alloc;
}
static public Allocation createFromBitmapResource(RenderScript rs,
Resources res,
int id) {
return createFromBitmapResource(rs, res, id,
MipmapControl.MIPMAP_NONE,
USAGE_GRAPHICS_TEXTURE);
}
/*
static public Allocation createFromBitmapResource(RenderScript rs,
Resources res,
int id,
@@ -534,7 +534,7 @@ public class Allocation extends BaseObj {
}
return createFromBitmapResource(rs, res, id, mc, USAGE_GRAPHICS_TEXTURE);
}
*/
static public Allocation createFromString(RenderScript rs,
String str,
int usage) {

View File

@@ -128,9 +128,9 @@ public class SceneGraphRS {
}
private void loadImage() {
mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot, Element.RGB_565(mRS), true);
mGridImage.uploadToTexture(0);
mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
Allocation.USAGE_GRAPHICS_TEXTURE);
mScript.set_gTGrid(mGridImage);
}

View File

@@ -124,9 +124,9 @@ public class SimpleModelRS {
}
private void loadImage() {
mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot, Element.RGB_565(mRS), true);
mGridImage.uploadToTexture(0);
mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
Allocation.USAGE_GRAPHICS_TEXTURE);
mScript.set_gTGrid(mGridImage);
}

View File

@@ -23,6 +23,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.renderscript.*;
import android.renderscript.Allocation.CubemapLayout;
import android.renderscript.Allocation.MipmapControl;
import android.renderscript.Program.TextureType;
import android.renderscript.ProgramStore.DepthFunc;
import android.renderscript.Sampler.Value;
@@ -284,17 +285,16 @@ public class RsBenchRS {
}
private Allocation loadTextureRGB(int id) {
final Allocation allocation = Allocation.createFromBitmapResource(mRS, mRes,
id, Element.RGB_565(mRS), true);
allocation.uploadToTexture(0);
return allocation;
return Allocation.createFromBitmapResource(mRS, mRes, id,
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
Allocation.USAGE_GRAPHICS_TEXTURE);
}
private Allocation loadTextureARGB(int id) {
Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB);
final Allocation allocation = Allocation.createFromBitmap(mRS, b, Element.RGBA_8888(mRS), true);
allocation.uploadToTexture(0);
return allocation;
return Allocation.createFromBitmap(mRS, b,
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
Allocation.USAGE_GRAPHICS_TEXTURE);
}
private void loadImages() {
@@ -303,9 +303,8 @@ public class RsBenchRS {
mTexTransparent = loadTextureARGB(R.drawable.leaf);
mTexChecker = loadTextureRGB(R.drawable.checker);
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
mTexCube = Allocation.createCubemapFromBitmap(mRS, b, Element.RGB_565(mRS), false,
mTexCube = Allocation.createCubemapFromBitmap(mRS, b,
Allocation.CubemapLayout.VERTICAL_FACE_LIST);
mTexCube.uploadToTexture(0);
mScript.set_gTexTorus(mTexTorus);
mScript.set_gTexOpaque(mTexOpaque);

View File

@@ -274,17 +274,16 @@ public class RsRenderStatesRS {
}
private Allocation loadTextureRGB(int id) {
final Allocation allocation = Allocation.createFromBitmapResource(mRS, mRes,
id, Element.RGB_565(mRS), true);
allocation.uploadToTexture(0);
return allocation;
return Allocation.createFromBitmapResource(mRS, mRes, id,
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
Allocation.USAGE_GRAPHICS_TEXTURE);
}
private Allocation loadTextureARGB(int id) {
Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB);
final Allocation allocation = Allocation.createFromBitmap(mRS, b, Element.RGBA_8888(mRS), true);
allocation.uploadToTexture(0);
return allocation;
return Allocation.createFromBitmap(mRS, b,
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
Allocation.USAGE_GRAPHICS_TEXTURE);
}
private void loadImages() {
@@ -293,9 +292,8 @@ public class RsRenderStatesRS {
mTexTransparent = loadTextureARGB(R.drawable.leaf);
mTexChecker = loadTextureRGB(R.drawable.checker);
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
mTexCube = Allocation.createCubemapFromBitmap(mRS, b, Element.RGB_565(mRS), false,
mTexCube = Allocation.createCubemapFromBitmap(mRS, b,
Allocation.CubemapLayout.VERTICAL_FACE_LIST);
mTexCube.uploadToTexture(0);
mScript.set_gTexTorus(mTexTorus);
mScript.set_gTexOpaque(mTexOpaque);

View File

@@ -191,13 +191,6 @@ void Allocation::uploadToTexture(const Context *rsc) {
uploadCubeTexture(isFirstUpload);
}
if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) {
#ifndef ANDROID_RS_BUILD_FOR_HOST
glGenerateMipmap(target);
#endif //ANDROID_RS_BUILD_FOR_HOST
}
if (!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)) {
freeScriptMemory();
}
@@ -227,6 +220,12 @@ void Allocation::upload2DTexture(bool isFirstUpload, const void *ptr) {
format, type, p);
}
}
if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) {
#ifndef ANDROID_RS_BUILD_FOR_HOST
glGenerateMipmap(target);
#endif //ANDROID_RS_BUILD_FOR_HOST
}
}
void Allocation::uploadCubeTexture(bool isFirstUpload) {
@@ -266,6 +265,12 @@ void Allocation::uploadCubeTexture(bool isFirstUpload) {
}
}
}
if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) {
#ifndef ANDROID_RS_BUILD_FOR_HOST
glGenerateMipmap(target);
#endif //ANDROID_RS_BUILD_FOR_HOST
}
}
void Allocation::deferedUploadToBufferObject(const Context *rsc) {

View File

@@ -463,7 +463,7 @@ bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *r
// This will dirty the texture and the shader so next time
// we draw it will upload the data
mTextTexture->deferedUploadToTexture(mRSC);
mTextTexture->syncAll(mRSC, RS_ALLOCATION_USAGE_SCRIPT);
mFontShaderF->bindTexture(mRSC, 0, mTextTexture.get());
// Some debug code
@@ -529,7 +529,7 @@ void FontState::initTextTexture() {
Allocation *cacheAlloc = new Allocation(mRSC, texType, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE);
mTextTexture.set(cacheAlloc);
mTextTexture->deferedUploadToTexture(mRSC);
mTextTexture->syncAll(mRSC, RS_ALLOCATION_USAGE_SCRIPT);
// Split up our cache texture into lines of certain widths
int32_t nextLine = 0;

View File

@@ -275,6 +275,18 @@ static void SC_color(float r, float g, float b, float a) {
pf->setConstantColor(rsc, r, g, b, a);
}
static void SC_allocationSyncAll(RsAllocation va) {
CHECK_OBJ(va);
GET_TLS();
static_cast<Allocation *>(va)->syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT);
}
static void SC_allocationSyncAll2(RsAllocation va, RsAllocationUsageType source) {
CHECK_OBJ(va);
GET_TLS();
static_cast<Allocation *>(va)->syncAll(rsc, source);
}
static void SC_uploadToTexture2(RsAllocation va, uint32_t baseMipLevel) {
CHECK_OBJ(va);
GET_TLS();
@@ -425,6 +437,8 @@ static ScriptCState::SymbolTable_t gSyms[] = {
{ "_Z11rsgGetWidthv", (void *)&SC_getWidth, false },
{ "_Z12rsgGetHeightv", (void *)&SC_getHeight, false },
{ "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_allocationSyncAll, false },
{ "_Z18rsgUploadToTexture13rs_allocationj", (void *)&SC_uploadToTexture2, false },
{ "_Z18rsgUploadToTexture13rs_allocation", (void *)&SC_uploadToTexture, false },
{ "_Z23rsgUploadToBufferObject13rs_allocation", (void *)&SC_uploadToBufferObject, false },

View File

@@ -34,6 +34,9 @@ extern uint __attribute__((overloadable))
extern uint __attribute__((overloadable))
rsgGetHeight(void);
extern void __attribute__((overloadable))
rsgAllocationSyncAll(rs_allocation);
extern void __attribute__((overloadable))
rsgUploadToTexture(rs_allocation);
extern void __attribute__((overloadable))