Methods Summary |
---|
private void | freeBitmap()
Assert.assertTrue(mBitmap != null);
onFreeBitmap(mBitmap);
mBitmap = null;
|
private android.graphics.Bitmap | getBitmap()
if (mBitmap == null) {
mBitmap = onGetBitmap();
int w = mBitmap.getWidth() + mBorder * 2;
int h = mBitmap.getHeight() + mBorder * 2;
if (mWidth == UNSPECIFIED) {
setSize(w, h);
}
}
return mBitmap;
|
private static android.graphics.Bitmap | getBorderLine(boolean vertical, android.graphics.Bitmap.Config config, int length)
BorderKey key = sBorderKey;
key.vertical = vertical;
key.config = config;
key.length = length;
Bitmap bitmap = sBorderLines.get(key);
if (bitmap == null) {
bitmap = vertical
? Bitmap.createBitmap(1, length, config)
: Bitmap.createBitmap(length, 1, config);
sBorderLines.put(key.clone(), bitmap);
}
return bitmap;
|
public int | getHeight()
if (mWidth == UNSPECIFIED) getBitmap();
return mHeight;
|
protected int | getTarget()
return GL11.GL_TEXTURE_2D;
|
public int | getWidth()
if (mWidth == UNSPECIFIED) getBitmap();
return mWidth;
|
protected void | invalidateContent()
if (mBitmap != null) freeBitmap();
mContentValid = false;
mWidth = UNSPECIFIED;
mHeight = UNSPECIFIED;
|
public boolean | isContentValid()Whether the content on GPU is valid.
return isLoaded() && mContentValid;
|
public boolean | isOpaque()
return mOpaque;
|
public boolean | isUploading()
return mIsUploading;
|
protected boolean | onBind(GLCanvas canvas)
updateContent(canvas);
return isContentValid();
|
protected abstract void | onFreeBitmap(android.graphics.Bitmap bitmap)
|
protected abstract android.graphics.Bitmap | onGetBitmap()
|
public void | recycle()
super.recycle();
if (mBitmap != null) freeBitmap();
|
public static void | resetUploadLimit()
sUploadedCount = 0;
|
protected void | setIsUploading(boolean uploading)
mIsUploading = uploading;
|
public void | setOpaque(boolean isOpaque)
mOpaque = isOpaque;
|
protected void | setThrottled(boolean throttled)
mThrottled = throttled;
|
public void | updateContent(GLCanvas canvas)Updates the content on GPU's memory.
if (!isLoaded()) {
if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) {
return;
}
uploadToCanvas(canvas);
} else if (!mContentValid) {
Bitmap bitmap = getBitmap();
int format = GLUtils.getInternalFormat(bitmap);
int type = GLUtils.getType(bitmap);
canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
freeBitmap();
mContentValid = true;
}
|
public static boolean | uploadLimitReached()
return sUploadedCount > UPLOAD_LIMIT;
|
private void | uploadToCanvas(GLCanvas canvas)
Bitmap bitmap = getBitmap();
if (bitmap != null) {
try {
int bWidth = bitmap.getWidth();
int bHeight = bitmap.getHeight();
int width = bWidth + mBorder * 2;
int height = bHeight + mBorder * 2;
int texWidth = getTextureWidth();
int texHeight = getTextureHeight();
Assert.assertTrue(bWidth <= texWidth && bHeight <= texHeight);
// Upload the bitmap to a new texture.
mId = canvas.getGLId().generateTexture();
canvas.setTextureParameters(this);
if (bWidth == texWidth && bHeight == texHeight) {
canvas.initializeTexture(this, bitmap);
} else {
int format = GLUtils.getInternalFormat(bitmap);
int type = GLUtils.getType(bitmap);
Config config = bitmap.getConfig();
canvas.initializeTextureSize(this, format, type);
canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
if (mBorder > 0) {
// Left border
Bitmap line = getBorderLine(true, config, texHeight);
canvas.texSubImage2D(this, 0, 0, line, format, type);
// Top border
line = getBorderLine(false, config, texWidth);
canvas.texSubImage2D(this, 0, 0, line, format, type);
}
// Right border
if (mBorder + bWidth < texWidth) {
Bitmap line = getBorderLine(true, config, texHeight);
canvas.texSubImage2D(this, mBorder + bWidth, 0, line, format, type);
}
// Bottom border
if (mBorder + bHeight < texHeight) {
Bitmap line = getBorderLine(false, config, texWidth);
canvas.texSubImage2D(this, 0, mBorder + bHeight, line, format, type);
}
}
} finally {
freeBitmap();
}
// Update texture state.
setAssociatedCanvas(canvas);
mState = STATE_LOADED;
mContentValid = true;
} else {
mState = STATE_ERROR;
throw new RuntimeException("Texture load fail, no bitmap");
}
|