Fix scissor rect and use the Java compositor's cached viewport metrics when drawing decorations

This commit is contained in:
Patrick Walton 2012-02-13 20:20:38 -08:00
parent 430c9e63f5
commit dd0a3bbc18
7 changed files with 30 additions and 66 deletions

View File

@ -1345,16 +1345,6 @@ protected:
bool mDirty;
};
#ifdef MOZ_WIDGET_ANDROID
class TransformLayerUserData : public LayerUserData {
public:
gfx3DMatrix matrix;
TransformLayerUserData(gfx3DMatrix& aMatrix) : matrix(aMatrix) {}
virtual ~TransformLayerUserData() {}
};
#endif
}
}

View File

@ -186,14 +186,6 @@ CompositorParent::Composite()
//layer->AsShadowLayer()->SetShadowTransform(worldTransform);
#endif
#ifdef MOZ_WIDGET_ANDROID
// Hang the transform of the root layer off the layer manager.
gfx3DMatrix transform = layer->GetTransform();
transform *= v;
TransformLayerUserData* transformUserData = new TransformLayerUserData(transform);
mLayerManager->SetUserData(nsGkAtoms::transform, transformUserData);
#endif
mLayerManager->EndEmptyTransaction();
#ifdef COMPOSITOR_PERFORMANCE_WARNING

View File

@ -225,24 +225,17 @@ public class GeckoGLLayerClient extends GeckoLayerClient
}
/** For Gecko to use. */
public LayerRenderer.Frame createFrame(float offsetX, float offsetY, float zoomFactor) {
public LayerRenderer.Frame createFrame() {
// Create the shaders and textures if necessary.
if (!mLayerRendererInitialized) {
mLayerRenderer.createProgram();
mLayerRendererInitialized = true;
}
// FIXME: This geometry is surely wrong.
ViewportMetrics metrics = getLayerController().getViewportMetrics();
FloatSize pageSize = metrics.getPageSize(), screenSize = metrics.getSize();
RectF viewport = new RectF(offsetX, offsetY, offsetX + screenSize.width,
offsetY + screenSize.height);
// Build the contexts and create the frame.
Layer.RenderContext pageContext = mLayerRenderer.createContext(viewport, pageSize,
zoomFactor);
Layer.RenderContext pageContext = mLayerRenderer.createPageContext();
Layer.RenderContext screenContext = mLayerRenderer.createScreenContext();
return mLayerRenderer.createFrame(false, pageContext, screenContext);
return mLayerRenderer.createFrame(pageContext, screenContext);
}
/** For Gecko to use. */

View File

@ -277,7 +277,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
*/
public void onDrawFrame(GL10 gl) {
RenderContext pageContext = createPageContext(), screenContext = createScreenContext();
Frame frame = createFrame(true, pageContext, screenContext);
Frame frame = createFrame(pageContext, screenContext);
synchronized (mView.getController()) {
frame.beginDrawing();
frame.drawBackground();
@ -316,7 +316,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
return createContext(viewport, pageSize, 1.0f);
}
private RenderContext createPageContext() {
public RenderContext createPageContext() {
LayerController layerController = mView.getController();
Rect viewport = new Rect();
@ -327,7 +327,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
return createContext(new RectF(viewport), pageSize, zoomFactor);
}
public RenderContext createContext(RectF viewport, FloatSize pageSize, float zoomFactor) {
private RenderContext createContext(RectF viewport, FloatSize pageSize, float zoomFactor) {
return new RenderContext(viewport, pageSize, zoomFactor, mPositionHandle, mTextureHandle,
mCoordBuffer);
}
@ -448,9 +448,8 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
return shader;
}
public Frame createFrame(boolean scissor, RenderContext pageContext,
RenderContext screenContext) {
return new Frame(scissor, pageContext, screenContext);
public Frame createFrame(RenderContext pageContext, RenderContext screenContext) {
return new Frame(pageContext, screenContext);
}
class FadeRunnable implements Runnable {
@ -490,8 +489,6 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
}
public class Frame {
// Whether to use a scissor rect to clip the page.
private final boolean mScissor;
// The timestamp recording the start of this frame.
private long mFrameStartTime;
// A rendering context for page-positioned layers, and one for screen-positioned layers.
@ -499,12 +496,18 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
// Whether a layer was updated.
private boolean mUpdated;
public Frame(boolean scissor, RenderContext pageContext, RenderContext screenContext) {
mScissor = scissor;
public Frame(RenderContext pageContext, RenderContext screenContext) {
mPageContext = pageContext;
mScreenContext = screenContext;
}
private void setScissorRect() {
Rect scissorRect = transformToScissorRect(getPageRect());
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
GLES20.glScissor(scissorRect.left, scissorRect.top,
scissorRect.width(), scissorRect.height());
}
public void beginDrawing() {
mFrameStartTime = SystemClock.uptimeMillis();
@ -574,23 +577,22 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
if (!untransformedPageRect.contains(mView.getController().getViewport()))
mShadowLayer.draw(mPageContext);
/* Define the scissor rect, if necessary. */
if (mScissor) {
Rect scissorRect = transformToScissorRect(pageRect);
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
GLES20.glScissor(scissorRect.left, scissorRect.top,
scissorRect.width(), scissorRect.height());
}
/* Draw the checkerboard. */
setScissorRect();
mCheckerboardLayer.draw(mScreenContext);
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
// Draws the layer the client added to us.
void drawRootLayer() {
Layer rootLayer = mView.getController().getRoot();
if (rootLayer != null)
rootLayer.draw(mPageContext);
if (rootLayer == null) {
return;
}
setScissorRect();
rootLayer.draw(mPageContext);
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
public void drawForeground() {

View File

@ -387,8 +387,7 @@ AndroidGeckoGLLayerClient::InitGeckoGLLayerClientClass(JNIEnv *jEnv)
jGetViewTransformMethod = getMethod("getViewTransform",
"()Lorg/mozilla/gecko/gfx/ViewTransform;");
jCreateFrameMethod = getMethod("createFrame",
"(FFF)Lorg/mozilla/gecko/gfx/LayerRenderer$Frame;");
jCreateFrameMethod = getMethod("createFrame", "()Lorg/mozilla/gecko/gfx/LayerRenderer$Frame;");
jActivateProgramMethod = getMethod("activateProgram", "()V");
jDeactivateProgramMethod = getMethod("deactivateProgram", "()V");
#endif
@ -931,8 +930,7 @@ AndroidGeckoGLLayerClient::GetViewTransform(AndroidViewTransform& aViewTransform
}
void
AndroidGeckoGLLayerClient::CreateFrame(AndroidLayerRendererFrame& aFrame,
float aXOffset, float aYOffset, float aZoomFactor)
AndroidGeckoGLLayerClient::CreateFrame(AndroidLayerRendererFrame& aFrame)
{
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at CreateFrame()!");
@ -940,8 +938,7 @@ AndroidGeckoGLLayerClient::CreateFrame(AndroidLayerRendererFrame& aFrame,
return;
}
jobject frameJObj = env->CallObjectMethod(wrapped_obj, jCreateFrameMethod, aXOffset, aYOffset,
aZoomFactor);
jobject frameJObj = env->CallObjectMethod(wrapped_obj, jCreateFrameMethod);
NS_ABORT_IF_FALSE(frameJObj, "No frame object!");
aFrame.Init(frameJObj);
}

View File

@ -270,8 +270,7 @@ public:
: mViewTransformGetter(*this) { Init(jobj); }
void GetViewTransform(AndroidViewTransform& aViewTransform);
void CreateFrame(AndroidLayerRendererFrame& aFrame, float aXOffset, float aYOffset,
float aZoomFactor);
void CreateFrame(AndroidLayerRendererFrame& aFrame);
void ActivateProgram();
void DeactivateProgram();

View File

@ -2396,18 +2396,9 @@ void
nsWindow::DrawWindowUnderlay(LayerManager* aManager, nsIntRect aRect) {
AndroidBridge::AutoLocalJNIFrame jniFrame(GetJNIForThread());
mozilla::layers::LayerUserData* userData = aManager->GetUserData(nsGkAtoms::transform);
mozilla::layers::TransformLayerUserData* transformUserData =
static_cast<mozilla::layers::TransformLayerUserData*>(userData);
NS_ABORT_IF_FALSE(userData, "No transform user data!");
// Transform the unit square to figure out the offset and scale we need.
gfxRect rect(0, 0, 1, 1);
transformUserData->matrix.TransformBounds(rect);
AndroidGeckoLayerClient& client = AndroidBridge::Bridge()->GetLayerClient();
AndroidGeckoGLLayerClient& glClient = static_cast<AndroidGeckoGLLayerClient&>(client);
glClient.CreateFrame(mLayerRendererFrame, rect.x, rect.y, rect.width);
glClient.CreateFrame(mLayerRendererFrame);
glClient.ActivateProgram();
mLayerRendererFrame.BeginDrawing();