Bug 789271 - Remove placeholder code from PluginLayer r=blassey

--HG--
extra : rebase_source : ea4287baa67b24a5382ceb323317b795e6ebc44e
This commit is contained in:
James Willcox 2012-12-10 10:00:17 -05:00
parent 97f68e365f
commit 64ad895cda
3 changed files with 15 additions and 172 deletions

View File

@ -428,10 +428,6 @@ pref("plugin.disable", false);
pref("dom.ipc.plugins.enabled", false);
pref("plugins.click_to_play", true);
// Disabled because of thread safety problem
// in getting the bits from the surface.
// Bug 756253
pref("plugins.use_placeholder", 0);
// product URLs
// The breakpad report server to link to in about:crashes

View File

@ -145,7 +145,6 @@ public class GeckoLayerClient
sendResizeEventIfNecessary(true);
DisplayPortCalculator.initPrefs();
PluginLayer.initPrefs();
}
public void destroy() {

View File

@ -24,24 +24,18 @@ import java.nio.FloatBuffer;
public class PluginLayer extends TileLayer {
private static final String LOGTAG = "PluginLayer";
private static final String PREF_PLUGIN_USE_PLACEHOLDER = "plugins.use_placeholder";
private static boolean sUsePlaceholder = true;
private View mView;
private SurfaceView mSurfaceView;
private PluginLayoutParams mLayoutParams;
private AbsoluteLayout mContainer;
private boolean mViewVisible;
private boolean mShowPlaceholder;
private boolean mDestroyed;
private boolean mViewVisible;
private RectF mLastViewport;
private float mLastZoomFactor;
private ShowViewRunnable mShowViewRunnable;
private static final float TEXTURE_MAP[] = {
0.0f, 1.0f, // top left
0.0f, 0.0f, // bottom left
@ -54,7 +48,6 @@ public class PluginLayer extends TileLayer {
mView = view;
mContainer = GeckoApp.mAppContext.getPluginContainer();
mShowViewRunnable = new ShowViewRunnable(this);
mView.setWillNotDraw(false);
if (mView instanceof SurfaceView) {
@ -66,17 +59,8 @@ public class PluginLayer extends TileLayer {
mLayoutParams = new PluginLayoutParams(rect, maxDimension);
}
static void initPrefs() {
PrefsHelper.getPref(PREF_PLUGIN_USE_PLACEHOLDER, new PrefsHelper.PrefHandlerBase() {
@Override public void prefValue(String pref, int value) {
sUsePlaceholder = (value == 1);
Log.i(LOGTAG, "Using plugin placeholder: " + sUsePlaceholder);
}
});
}
public void setVisible(boolean newVisible) {
if (newVisible && !mShowPlaceholder) {
public void setVisible(boolean visible) {
if (visible) {
showView();
} else {
hideView();
@ -88,54 +72,30 @@ public class PluginLayer extends TileLayer {
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
mView.setVisibility(View.GONE);
mViewVisible = false;
}
});
mViewVisible = false;
}
}
private void suspendView() {
// Right now we can only show a placeholder ("suspend") a
// SurfaceView plugin (Flash)
if (mSurfaceView != null) {
hideView();
GeckoApp.mAppContext.mMainHandler.removeCallbacks(mShowViewRunnable);
GeckoApp.mAppContext.mMainHandler.postDelayed(mShowViewRunnable, 250);
}
}
public void updateView() {
showView(true);
}
public void showView() {
showView(false);
}
public void showView(boolean forceUpdate) {
if (!mViewVisible || forceUpdate) {
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
if (mContainer.indexOfChild(mView) < 0) {
mContainer.addView(mView, mLayoutParams);
} else {
mContainer.updateViewLayout(mView, mLayoutParams);
mView.setVisibility(View.VISIBLE);
}
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
if (mContainer.indexOfChild(mView) < 0) {
mContainer.addView(mView, mLayoutParams);
} else {
mContainer.updateViewLayout(mView, mLayoutParams);
mView.setVisibility(View.VISIBLE);
}
});
mViewVisible = true;
mShowPlaceholder = false;
}
mViewVisible = true;
}
});
}
public void destroy() {
mDestroyed = true;
mContainer.removeView(mView);
GeckoApp.mAppContext.mMainHandler.removeCallbacks(mShowViewRunnable);
}
public void reset(Rect rect) {
@ -150,115 +110,16 @@ public class PluginLayer extends TileLayer {
if (!RectUtils.fuzzyEquals(context.viewport, mLastViewport) ||
!FloatUtils.fuzzyEquals(context.zoomFactor, mLastZoomFactor)) {
// Viewport has changed from the last update
// Attempt to figure out if this is a full page plugin or near to it. If so, we don't show the placeholder because
// it just performs badly (flickering).
boolean fullPagePlugin = (mLayoutParams.width >= (context.viewport.width() * 0.90f) ||
mLayoutParams.height >= (context.viewport.height() * 0.90f));
if (!fullPagePlugin && mLastViewport != null && mSurfaceView != null && !mShowPlaceholder && sUsePlaceholder) {
// We have a SurfaceView that we can snapshot for a placeholder, and we are
// not currently showing a placeholder.
Surface surface = mSurfaceView.getHolder().getSurface();
SurfaceBits bits = GeckoAppShell.getSurfaceBits(surface);
if (bits != null) {
int cairoFormat = -1;
switch (bits.format) {
case PixelFormat.RGBA_8888:
cairoFormat = CairoImage.FORMAT_ARGB32;
break;
case PixelFormat.RGB_565:
cairoFormat = CairoImage.FORMAT_RGB16_565;
break;
default:
Log.w(LOGTAG, "Unable to handle format " + bits.format);
break;
}
if (cairoFormat >= 0) {
BufferedCairoImage image = (BufferedCairoImage)mImage;
image.setBuffer(bits.buffer, bits.width, bits.height, cairoFormat);
mPosition = new Rect(mLayoutParams.x, mLayoutParams.y, mLayoutParams.x + bits.width, mLayoutParams.y + bits.height);
mPosition.offset(Math.round(mLastViewport.left), Math.round(mLastViewport.top));
mResolution = mLastZoomFactor;
// We've uploaded the snapshot to the texture now (or will in super.performUpdates)
// so we can draw the placeholder
mShowPlaceholder = true;
super.performUpdates(context);
}
}
}
mLastZoomFactor = context.zoomFactor;
mLastViewport = context.viewport;
mLayoutParams.reposition(context.viewport, context.zoomFactor);
if (mShowPlaceholder) {
suspendView();
} else {
// We aren't showing the placeholder so we need to update the view position immediately
updateView();
}
showView();
}
}
@Override
public void draw(RenderContext context) {
if (!mShowPlaceholder || mDestroyed || !initialized())
return;
RectF bounds;
Rect position = getPosition();
RectF viewport = context.viewport;
bounds = getBounds(context);
float height = mLayoutParams.height;
float left = bounds.left - viewport.left;
float top = viewport.height() - (bounds.top + height - viewport.top);
float[] coords = {
//x, y, z, texture_x, texture_y
left/viewport.width(), top/viewport.height(), 0,
0.0f, mLayoutParams.height / bounds.height(),
left/viewport.width(), (top+height)/viewport.height(), 0,
0.0f, 0.0f,
(left+mLayoutParams.width)/viewport.width(), top/viewport.height(), 0,
mLayoutParams.width / bounds.width(), mLayoutParams.height / bounds.height(),
(left+mLayoutParams.width)/viewport.width(), (top+height)/viewport.height(), 0,
mLayoutParams.width / bounds.width(), 0.0f
};
FloatBuffer coordBuffer = context.coordBuffer;
int positionHandle = context.positionHandle;
int textureHandle = context.textureHandle;
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTextureID());
// Make sure we are at position zero in the buffer
coordBuffer.position(0);
coordBuffer.put(coords);
// Unbind any the current array buffer so we can use client side buffers
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
// Vertex coordinates are x,y,z starting at position 0 into the buffer.
coordBuffer.position(0);
GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20, coordBuffer);
// Texture coordinates are texture_x, texture_y starting at position 3 into the buffer.
coordBuffer.position(3);
GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20, coordBuffer);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
class PluginLayoutParams extends AbsoluteLayout.LayoutParams
@ -308,17 +169,4 @@ public class PluginLayer extends TileLayer {
}
}
}
class ShowViewRunnable implements Runnable {
private PluginLayer mLayer;
public ShowViewRunnable(PluginLayer layer) {
mLayer = layer;
}
public void run() {
mLayer.showView();
}
}
}