Bug 730898. Merge LayerView and GLSurfaceView. r=pcwalton

Once, GLThread is gone we don't have any need to support both styles of GL
rendering. Merging LayerView and FlexibleGLSurfaceView makes it clearer what's
going on, and I expect we'll also be able to take out some dead code from the
resulting LayerView.

This patch is mostly uninteresting. The interesting bits are that
implementations of requestRender and the constructors are merged. Everything
else is mostly copying over methods and renaming FlexibleGLSurfaceView's
mController to mGLController.
This commit is contained in:
Jeff Muizelaar 2012-03-30 14:21:59 -04:00
parent 7eb668b2ff
commit fd6b0690da
10 changed files with 105 additions and 201 deletions

View File

@ -123,7 +123,6 @@ FENNEC_JAVA_FILES = \
gfx/CheckerboardImage.java \
gfx/DisplayPortCalculator.java \
gfx/DisplayPortMetrics.java \
gfx/FlexibleGLSurfaceView.java \
gfx/FloatSize.java \
gfx/GeckoLayerClient.java \
gfx/GLController.java \

View File

@ -1,158 +0,0 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Android code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011-2012
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Patrick Walton <pcwalton@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.gecko.gfx;
import org.mozilla.gecko.GeckoApp;
import android.content.Context;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import javax.microedition.khronos.opengles.GL10;
/*
* This class extends SurfaceView and allows dynamically switching between two modes
* of operation. In one mode, it is used like a GLSurfaceView, and has it's own GL
* thread. In the other mode, it allows external code to perform GL composition, by
* exposing the GL controller.
*
* In our case, we start off in the first mode because we are rendering the placeholder
* image. This mode is initiated by a call to createGLThread(). Once Gecko comes up,
* it invokes registerCxxCompositor() via a JNI call, which shuts down the GL thread and
* returns the GL controller. The JNI code then takes the EGL surface from the GL
* controller and allows the off-main thread compositor to deal with it directly.
*/
public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private static final String LOGTAG = "GeckoFlexibleGLSurfaceView";
private GLSurfaceView.Renderer mRenderer;
private GLController mController;
private Listener mListener;
public FlexibleGLSurfaceView(Context context) {
super(context);
init();
}
public FlexibleGLSurfaceView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
init();
}
public void init() {
SurfaceHolder holder = getHolder();
holder.addCallback(this);
holder.setFormat(PixelFormat.RGB_565);
mController = new GLController(this);
}
public void setRenderer(GLSurfaceView.Renderer renderer) {
mRenderer = renderer;
}
public GLSurfaceView.Renderer getRenderer() {
return mRenderer;
}
public void setListener(Listener listener) {
mListener = listener;
}
public synchronized void requestRender() {
if (mListener != null) {
mListener.renderRequested();
}
}
public synchronized GLController getGLController() {
return mController;
}
/** Implementation of SurfaceHolder.Callback */
public synchronized void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
mController.sizeChanged(width, height);
if (mListener != null) {
mListener.surfaceChanged(width, height);
}
}
/** Implementation of SurfaceHolder.Callback */
public synchronized void surfaceCreated(SurfaceHolder holder) {
mController.surfaceCreated();
}
/** Implementation of SurfaceHolder.Callback */
public synchronized void surfaceDestroyed(SurfaceHolder holder) {
mController.surfaceDestroyed();
if (mListener != null) {
mListener.compositionPauseRequested();
}
}
/** This function is invoked by Gecko (compositor thread) via JNI; be careful when modifying signature. */
public static GLController registerCxxCompositor() {
try {
FlexibleGLSurfaceView flexView = (FlexibleGLSurfaceView)GeckoApp.mAppContext.getLayerController().getView();
return flexView.getGLController();
} catch (Exception e) {
Log.e(LOGTAG, "### Exception! " + e);
return null;
}
}
public interface Listener {
void renderRequested();
void compositionPauseRequested();
void compositionResumeRequested();
void surfaceChanged(int width, int height);
}
public static class FlexibleGLSurfaceViewException extends RuntimeException {
public static final long serialVersionUID = 1L;
FlexibleGLSurfaceViewException(String e) {
super(e);
}
}
}

View File

@ -53,7 +53,7 @@ public class GLController {
private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
private static final String LOGTAG = "GeckoGLController";
private FlexibleGLSurfaceView mView;
private LayerView mView;
private int mGLVersion;
private boolean mSurfaceValid;
private int mWidth, mHeight;
@ -77,7 +77,7 @@ public class GLController {
EGL10.EGL_NONE
};
public GLController(FlexibleGLSurfaceView view) {
public GLController(LayerView view) {
mView = view;
mGLVersion = 2;
mSurfaceValid = false;
@ -92,7 +92,7 @@ public class GLController {
public EGLConfig getEGLConfig() { return mEGLConfig; }
public EGLContext getEGLContext() { return mEGLContext; }
public EGLSurface getEGLSurface() { return mEGLSurface; }
public FlexibleGLSurfaceView getView() { return mView; }
public LayerView getView() { return mView; }
public boolean hasSurface() {
return mEGLSurface != null;

View File

@ -58,7 +58,7 @@ import android.util.Log;
import android.view.View;
public class GeckoLayerClient implements GeckoEventResponder,
FlexibleGLSurfaceView.Listener {
LayerView.Listener {
private static final String LOGTAG = "GeckoLayerClient";
private static final String PREF_DISPLAYPORT_STRATEGY = "gfx.displayport.strategy";
@ -407,19 +407,19 @@ public class GeckoLayerClient implements GeckoEventResponder,
mLayerRenderer.deactivateDefaultProgram();
}
/** Implementation of FlexibleGLSurfaceView.Listener */
/** Implementation of LayerView.Listener */
public void renderRequested() {
GeckoAppShell.scheduleComposite();
}
/** Implementation of FlexibleGLSurfaceView.Listener */
/** Implementation of LayerView.Listener */
public void compositionPauseRequested() {
// We need to coordinate with Gecko when pausing composition, to ensure
// that Gecko never executes a draw event while the compositor is paused.
GeckoAppShell.sendEventToGecko(GeckoEvent.createCompositorPauseEvent());
}
/** Implementation of FlexibleGLSurfaceView.Listener */
/** Implementation of LayerView.Listener */
public void compositionResumeRequested() {
// Asking Gecko to resume the compositor takes too long (see
// https://bugzilla.mozilla.org/show_bug.cgi?id=735230#c23), so we
@ -429,7 +429,7 @@ public class GeckoLayerClient implements GeckoEventResponder,
GeckoAppShell.sendEventToGecko(GeckoEvent.createCompositorResumeEvent());
}
/** Implementation of FlexibleGLSurfaceView.Listener */
/** Implementation of LayerView.Listener */
public void surfaceChanged(int width, int height) {
mLayerController.setViewportSize(new FloatSize(width, height));

View File

@ -58,6 +58,16 @@ import android.util.Log;
import java.nio.IntBuffer;
import java.util.LinkedList;
import org.mozilla.gecko.GeckoApp;
import android.content.Context;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import javax.microedition.khronos.opengles.GL10;
/**
* A view rendered by the layer compositor.
*
@ -66,9 +76,10 @@ import java.util.LinkedList;
*
* Note that LayerView is accessed by Robocop via reflection.
*/
public class LayerView extends FlexibleGLSurfaceView {
public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
private Context mContext;
private LayerController mController;
private GLController mGLController;
private InputConnectionHandler mInputConnectionHandler;
private LayerRenderer mRenderer;
private GestureDetector mGestureDetector;
@ -81,6 +92,8 @@ public class LayerView extends FlexibleGLSurfaceView {
/* Must be a PAINT_xxx constant */
private int mPaintState = PAINT_NONE;
private Listener mListener;
/* Flags used to determine when to show the painted surface. The integer
* order must correspond to the order in which these states occur. */
public static final int PAINT_NONE = 0;
@ -91,10 +104,14 @@ public class LayerView extends FlexibleGLSurfaceView {
public LayerView(Context context, LayerController controller) {
super(context);
SurfaceHolder holder = getHolder();
holder.addCallback(this);
holder.setFormat(PixelFormat.RGB_565);
mGLController = new GLController(this);
mContext = context;
mController = controller;
mRenderer = new LayerRenderer(this);
setRenderer(mRenderer);
mGestureDetector = new GestureDetector(context, controller.getGestureListener());
mScaleGestureDetector =
new SimpleScaleGestureDetector(controller.getScaleGestureListener());
@ -196,15 +213,9 @@ public class LayerView extends FlexibleGLSurfaceView {
return false;
}
@Override
public void requestRender() {
super.requestRender();
synchronized(this) {
if (!mRenderTimeReset) {
mRenderTimeReset = true;
mRenderTime = System.nanoTime();
}
public synchronized void requestRender() {
if (mListener != null) {
mListener.renderRequested();
}
}
@ -238,13 +249,12 @@ public class LayerView extends FlexibleGLSurfaceView {
public void setLayerRenderer(LayerRenderer renderer) {
mRenderer = renderer;
setRenderer(mRenderer);
}
public LayerRenderer getLayerRenderer() {
return mRenderer;
}
/* paintState must be a PAINT_xxx constant. The state will only be changed
* if paintState represents a state that occurs after the current state. */
public void setPaintState(int paintState) {
@ -257,5 +267,61 @@ public class LayerView extends FlexibleGLSurfaceView {
public int getPaintState() {
return mPaintState;
}
}
public GLSurfaceView.Renderer getRenderer() {
return mRenderer;
}
public void setListener(Listener listener) {
mListener = listener;
}
public synchronized GLController getGLController() {
return mGLController;
}
/** Implementation of SurfaceHolder.Callback */
public synchronized void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
mGLController.sizeChanged(width, height);
if (mListener != null) {
mListener.surfaceChanged(width, height);
}
}
/** Implementation of SurfaceHolder.Callback */
public synchronized void surfaceCreated(SurfaceHolder holder) {
mGLController.surfaceCreated();
}
/** Implementation of SurfaceHolder.Callback */
public synchronized void surfaceDestroyed(SurfaceHolder holder) {
mGLController.surfaceDestroyed();
if (mListener != null) {
mListener.compositionPauseRequested();
}
}
/** This function is invoked by Gecko (compositor thread) via JNI; be careful when modifying signature. */
public static GLController registerCxxCompositor() {
try {
LayerView layerView = GeckoApp.mAppContext.getLayerController().getView();
return layerView.getGLController();
} catch (Exception e) {
Log.e(LOGTAG, "### Exception! " + e);
return null;
}
}
public interface Listener {
void renderRequested();
void compositionPauseRequested();
void compositionResumeRequested();
void surfaceChanged(int width, int height);
}
}

View File

@ -201,7 +201,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
jStringClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("java/lang/String"));
#ifdef MOZ_JAVA_COMPOSITOR
jFlexSurfaceView = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("org/mozilla/gecko/gfx/FlexibleGLSurfaceView"));
jLayerView = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("org/mozilla/gecko/gfx/LayerView"));
AndroidGLController::Init(jEnv);
AndroidEGLObject::Init(jEnv);
@ -1119,9 +1119,9 @@ AndroidBridge::RegisterCompositor()
AutoLocalJNIFrame jniFrame(env, 3);
jmethodID registerCompositor = env->GetStaticMethodID(jFlexSurfaceView, "registerCxxCompositor", "()Lorg/mozilla/gecko/gfx/GLController;");
jmethodID registerCompositor = env->GetStaticMethodID(jLayerView, "registerCxxCompositor", "()Lorg/mozilla/gecko/gfx/GLController;");
jobject glController = env->CallStaticObjectMethod(jFlexSurfaceView, registerCompositor);
jobject glController = env->CallStaticObjectMethod(jLayerView, registerCompositor);
sController.Acquire(env, glController);
sController.SetGLVersion(2);

View File

@ -49,7 +49,7 @@
#include "nsIObserver.h"
#include "nsThreadUtils.h"
#include "AndroidFlexViewWrapper.h"
#include "AndroidLayerViewWrapper.h"
#include "AndroidJavaWrappers.h"
#include "nsIMutableArray.h"
@ -554,7 +554,7 @@ protected:
jclass jEGLContextClass;
jclass jEGL10Class;
jclass jFlexSurfaceView;
jclass jLayerView;
jmethodID jRegisterCompositorMethod;
// some convinient types to have around

View File

@ -35,11 +35,11 @@
*
* ***** END LICENSE BLOCK ***** */
#include "AndroidFlexViewWrapper.h"
#include "AndroidLayerViewWrapper.h"
#include "nsDebug.h"
#define ASSERT_THREAD() \
NS_ASSERTION((void*)pthread_self() == mThread, "Something is calling AndroidGLController from the wrong thread!")
NS_ASSERTION(pthread_self() == mThread, "Something is calling AndroidGLController from the wrong thread!")
static jfieldID jEGLSurfacePointerField = 0;
@ -55,7 +55,7 @@ jmethodID AndroidGLController::jWaitForValidSurfaceMethod = 0;
jmethodID AndroidGLController::jProvideEGLSurfaceMethod = 0;
void
AndroidGLController::Init(JNIEnv *aJEnv)
AndroidGLController::Init(JNIEnv* aJEnv)
{
jclass jClass = reinterpret_cast<jclass>(aJEnv->NewGlobalRef(aJEnv->FindClass("org/mozilla/gecko/gfx/GLController")));
@ -69,7 +69,7 @@ void
AndroidGLController::Acquire(JNIEnv* aJEnv, jobject aJObj)
{
mJEnv = aJEnv;
mThread = (void*)pthread_self();
mThread = pthread_self();
mJObj = aJEnv->NewGlobalRef(aJObj);
}

View File

@ -35,27 +35,24 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef AndroidFlexViewWrapper_h__
#define AndroidFlexViewWrapper_h__
#ifndef AndroidLayerViewWrapper_h__
#define AndroidLayerViewWrapper_h__
#include <jni.h>
#include <cassert>
#include <cstdlib>
#include <pthread.h>
#include <android/log.h>
class AndroidEGLObject {
public:
static void Init(JNIEnv* aJEnv);
};
typedef void *EGLSurface;
typedef void* EGLSurface;
class AndroidGLController {
public:
static void Init(JNIEnv* aJEnv);
void Acquire(JNIEnv *aJEnv, jobject aJObj);
void Acquire(JNIEnv* aJEnv, jobject aJObj);
void SetGLVersion(int aVersion);
EGLSurface ProvideEGLSurface();
void WaitForValidSurface();
@ -66,8 +63,8 @@ private:
static jmethodID jProvideEGLSurfaceMethod;
// the JNIEnv for the compositor thread
JNIEnv *mJEnv;
void *mThread;
JNIEnv* mJEnv;
pthread_t mThread;
jobject mJObj;
};

View File

@ -62,7 +62,7 @@ CPPSRCS = \
AndroidJavaWrappers.cpp \
AndroidBridge.cpp \
AndroidDirectTexture.cpp \
AndroidFlexViewWrapper.cpp \
AndroidLayerViewWrapper.cpp \
AndroidGraphicBuffer.cpp \
AndroidJNI.cpp \
AndroidMediaLayer.cpp \
@ -92,7 +92,7 @@ XPIDLSRCS = \
SHARED_LIBRARY_LIBS = ../xpwidgets/libxpwidgets_s.a
EXPORTS = AndroidBridge.h AndroidJavaWrappers.h AndroidFlexViewWrapper.h
EXPORTS = AndroidBridge.h AndroidJavaWrappers.h AndroidLayerViewWrapper.h
include $(topsrcdir)/config/rules.mk