Bug 1166309 - Move gfx mozglue dependency to after Gecko starts; r=snorp

This commit is contained in:
Jim Chen 2015-06-10 00:25:01 -04:00
parent fff18a12b9
commit e44c4f499f
2 changed files with 30 additions and 18 deletions

View File

@ -15,6 +15,7 @@ import java.nio.ByteBuffer;
/** A buffered image that simply saves a buffer of pixel data. */
public class BufferedImage {
private ByteBuffer mBuffer;
private Bitmap mBitmap;
private IntSize mSize;
private int mFormat;
@ -29,14 +30,13 @@ public class BufferedImage {
public BufferedImage(Bitmap bitmap) {
mFormat = bitmapConfigToFormat(bitmap.getConfig());
mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
int bpp = bitsPerPixelForFormat(mFormat);
mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * bpp);
bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
mBitmap = bitmap;
}
private synchronized void freeBuffer() {
mBuffer = DirectBufferAllocator.free(mBuffer);
if (mBuffer != null) {
mBuffer = DirectBufferAllocator.free(mBuffer);
}
}
public void destroy() {
@ -47,7 +47,16 @@ public class BufferedImage {
}
}
public ByteBuffer getBuffer() { return mBuffer; }
public ByteBuffer getBuffer() {
if (mBuffer == null) {
int bpp = bitsPerPixelForFormat(mFormat);
mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * bpp);
mBitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
mBitmap = null;
}
return mBuffer;
}
public IntSize getSize() { return mSize; }
public int getFormat() { return mFormat; }

View File

@ -161,12 +161,6 @@ public class LayerRenderer implements Tabs.OnTabsChangedListener {
mFrameTimings = new int[60];
mCurrentFrame = mFrameTimingsSum = mDroppedFrames = 0;
// Initialize the FloatBuffer that will be used to store all vertices and texture
// coordinates in draw() commands.
mCoordByteBuffer = DirectBufferAllocator.allocate(COORD_BUFFER_SIZE * 4);
mCoordByteBuffer.order(ByteOrder.nativeOrder());
mCoordBuffer = mCoordByteBuffer.asFloatBuffer();
Tabs.registerOnTabsChangedListener(this);
mZoomedViewListeners = new ArrayList<LayerView.ZoomedViewListener>();
}
@ -190,9 +184,11 @@ public class LayerRenderer implements Tabs.OnTabsChangedListener {
}
public void destroy() {
DirectBufferAllocator.free(mCoordByteBuffer);
mCoordByteBuffer = null;
mCoordBuffer = null;
if (mCoordByteBuffer != null) {
DirectBufferAllocator.free(mCoordByteBuffer);
mCoordByteBuffer = null;
mCoordBuffer = null;
}
mHorizScrollLayer.destroy();
mVertScrollLayer.destroy();
Tabs.unregisterOnTabsChangedListener(this);
@ -348,10 +344,17 @@ public class LayerRenderer implements Tabs.OnTabsChangedListener {
private RenderContext createContext(RectF viewport, RectF pageRect, float zoomFactor, PointF offset) {
if (mCoordBuffer == null) {
throw new IllegalStateException();
// Initialize the FloatBuffer that will be used to store all vertices and texture
// coordinates in draw() commands.
mCoordByteBuffer = DirectBufferAllocator.allocate(COORD_BUFFER_SIZE * 4);
mCoordByteBuffer.order(ByteOrder.nativeOrder());
mCoordBuffer = mCoordByteBuffer.asFloatBuffer();
if (mCoordBuffer == null) {
throw new IllegalStateException();
}
}
return new RenderContext(viewport, pageRect, zoomFactor, offset, mPositionHandle, mTextureHandle,
mCoordBuffer);
return new RenderContext(viewport, pageRect, zoomFactor, offset,
mPositionHandle, mTextureHandle, mCoordBuffer);
}
private void updateDroppedFrames(long frameStartTime) {