mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 737949 - Don't initialize EGL from Fennec java code, and remove GLThread altogether. r=pcwalton,jrmuizel
This commit is contained in:
parent
e270db628e
commit
500b32e0e5
@ -126,7 +126,6 @@ FENNEC_JAVA_FILES = \
|
||||
gfx/FloatSize.java \
|
||||
gfx/GeckoLayerClient.java \
|
||||
gfx/GLController.java \
|
||||
gfx/GLThread.java \
|
||||
gfx/ImmutableViewportMetrics.java \
|
||||
gfx/InputConnectionHandler.java \
|
||||
gfx/IntSize.java \
|
||||
|
@ -45,6 +45,7 @@ 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
|
||||
@ -62,7 +63,6 @@ public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.
|
||||
private static final String LOGTAG = "GeckoFlexibleGLSurfaceView";
|
||||
|
||||
private GLSurfaceView.Renderer mRenderer;
|
||||
private GLThread mGLThread; // Protected by this class's monitor.
|
||||
private GLController mController;
|
||||
private Listener mListener;
|
||||
|
||||
@ -97,64 +97,12 @@ public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.
|
||||
}
|
||||
|
||||
public synchronized void requestRender() {
|
||||
if (mGLThread != null) {
|
||||
mGLThread.renderFrame();
|
||||
}
|
||||
if (mListener != null) {
|
||||
mListener.renderRequested();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Java GL thread. After this is called, the FlexibleGLSurfaceView may be used just
|
||||
* like a GLSurfaceView. It is illegal to access the controller after this has been called.
|
||||
*/
|
||||
public synchronized void createGLThread() {
|
||||
if (mGLThread != null) {
|
||||
throw new FlexibleGLSurfaceViewException("createGLThread() called with a GL thread " +
|
||||
"already in place!");
|
||||
}
|
||||
|
||||
mGLThread = new GLThread(mController);
|
||||
mGLThread.start();
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the Java GL thread. Returns a Thread that completes when the Java GL thread is
|
||||
* fully shut down.
|
||||
*/
|
||||
public synchronized Thread destroyGLThread() {
|
||||
// Wait for the GL thread to be started.
|
||||
while (mGLThread == null) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Thread glThread = mGLThread;
|
||||
mGLThread.shutdown();
|
||||
mGLThread = null;
|
||||
return glThread;
|
||||
}
|
||||
|
||||
public synchronized void recreateSurface() {
|
||||
if (mGLThread == null) {
|
||||
throw new FlexibleGLSurfaceViewException("recreateSurface() called with no GL " +
|
||||
"thread active!");
|
||||
}
|
||||
|
||||
mGLThread.recreateSurface();
|
||||
}
|
||||
|
||||
public synchronized GLController getGLController() {
|
||||
if (mGLThread != null) {
|
||||
throw new FlexibleGLSurfaceViewException("getGLController() called with a GL thread " +
|
||||
"active; shut down the GL thread first!");
|
||||
}
|
||||
|
||||
return mController;
|
||||
}
|
||||
|
||||
@ -162,10 +110,7 @@ public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.
|
||||
public synchronized void surfaceChanged(SurfaceHolder holder, int format, int width,
|
||||
int height) {
|
||||
mController.sizeChanged(width, height);
|
||||
if (mGLThread != null) {
|
||||
mGLThread.surfaceChanged(width, height);
|
||||
}
|
||||
|
||||
|
||||
if (mListener != null) {
|
||||
mListener.surfaceChanged(width, height);
|
||||
}
|
||||
@ -173,19 +118,10 @@ public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.
|
||||
|
||||
/** Implementation of SurfaceHolder.Callback */
|
||||
public synchronized void surfaceCreated(SurfaceHolder holder) {
|
||||
mController.surfaceCreated();
|
||||
if (mGLThread != null) {
|
||||
mGLThread.surfaceCreated();
|
||||
}
|
||||
}
|
||||
|
||||
/** Implementation of SurfaceHolder.Callback */
|
||||
public synchronized void surfaceDestroyed(SurfaceHolder holder) {
|
||||
mController.surfaceDestroyed();
|
||||
if (mGLThread != null) {
|
||||
mGLThread.surfaceDestroyed();
|
||||
}
|
||||
|
||||
if (mListener != null) {
|
||||
mListener.compositionPauseRequested();
|
||||
}
|
||||
@ -195,9 +131,6 @@ public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.
|
||||
public static GLController registerCxxCompositor() {
|
||||
try {
|
||||
FlexibleGLSurfaceView flexView = (FlexibleGLSurfaceView)GeckoApp.mAppContext.getLayerController().getView();
|
||||
try {
|
||||
flexView.destroyGLThread().join();
|
||||
} catch (InterruptedException e) {}
|
||||
return flexView.getGLController();
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "### Exception! " + e);
|
||||
|
@ -55,7 +55,6 @@ public class GLController {
|
||||
|
||||
private FlexibleGLSurfaceView mView;
|
||||
private int mGLVersion;
|
||||
private boolean mSurfaceValid;
|
||||
private int mWidth, mHeight;
|
||||
|
||||
private EGL10 mEGL;
|
||||
@ -80,50 +79,12 @@ public class GLController {
|
||||
public GLController(FlexibleGLSurfaceView view) {
|
||||
mView = view;
|
||||
mGLVersion = 2;
|
||||
mSurfaceValid = false;
|
||||
}
|
||||
|
||||
public void setGLVersion(int version) {
|
||||
mGLVersion = version;
|
||||
}
|
||||
|
||||
/** You must call this on the same thread you intend to use OpenGL on. */
|
||||
public void initGLContext() {
|
||||
initEGLContext();
|
||||
createEGLSurface();
|
||||
}
|
||||
|
||||
public void disposeGLContext() {
|
||||
if (mEGL == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mEGL.eglMakeCurrent(mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
|
||||
EGL10.EGL_NO_CONTEXT)) {
|
||||
throw new GLControllerException("EGL context could not be released! " +
|
||||
getEGLError());
|
||||
}
|
||||
|
||||
if (mEGLSurface != null) {
|
||||
if (!mEGL.eglDestroySurface(mEGLDisplay, mEGLSurface)) {
|
||||
throw new GLControllerException("EGL surface could not be destroyed! " +
|
||||
getEGLError());
|
||||
}
|
||||
|
||||
mEGLSurface = null;
|
||||
}
|
||||
|
||||
if (mEGLContext != null) {
|
||||
if (!mEGL.eglDestroyContext(mEGLDisplay, mEGLContext)) {
|
||||
throw new GLControllerException("EGL context could not be destroyed! " +
|
||||
getEGLError());
|
||||
}
|
||||
|
||||
mGL = null;
|
||||
mEGLContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
public GL getGL() { return mEGLContext.getGL(); }
|
||||
public EGLDisplay getEGLDisplay() { return mEGLDisplay; }
|
||||
public EGLConfig getEGLConfig() { return mEGLConfig; }
|
||||
@ -152,16 +113,6 @@ public class GLController {
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized void waitForValidSurface() {
|
||||
while (!mSurfaceValid) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized int getWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
@ -170,19 +121,12 @@ public class GLController {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
synchronized void surfaceCreated() {
|
||||
mSurfaceValid = true;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
synchronized void surfaceDestroyed() {
|
||||
mSurfaceValid = false;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
synchronized void sizeChanged(int newWidth, int newHeight) {
|
||||
mWidth = newWidth;
|
||||
mHeight = newHeight;
|
||||
if (mGL != null) {
|
||||
mView.getRenderer().onSurfaceChanged((GL10)mGL, mWidth, mHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void initEGL() {
|
||||
@ -193,17 +137,7 @@ public class GLController {
|
||||
throw new GLControllerException("eglGetDisplay() failed");
|
||||
}
|
||||
|
||||
int[] version = new int[2];
|
||||
if (!mEGL.eglInitialize(mEGLDisplay, version)) {
|
||||
throw new GLControllerException("eglInitialize() failed " +
|
||||
getEGLError());
|
||||
}
|
||||
|
||||
mEGLConfig = chooseConfig();
|
||||
}
|
||||
|
||||
private void initEGLContext() {
|
||||
initEGL();
|
||||
|
||||
int[] attribList = { EGL_CONTEXT_CLIENT_VERSION, mGLVersion, EGL10.EGL_NONE };
|
||||
mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig, EGL10.EGL_NO_CONTEXT,
|
||||
@ -212,6 +146,13 @@ public class GLController {
|
||||
throw new GLControllerException("createContext() failed " +
|
||||
getEGLError());
|
||||
}
|
||||
|
||||
mGL = mEGLContext.getGL();
|
||||
|
||||
if (mView.getRenderer() != null) {
|
||||
mView.getRenderer().onSurfaceCreated((GL10)mGL, mEGLConfig);
|
||||
mView.getRenderer().onSurfaceChanged((GL10)mGL, mView.getWidth(), mView.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
private EGLConfig chooseConfig() {
|
||||
@ -242,27 +183,6 @@ public class GLController {
|
||||
throw new GLControllerException("No suitable EGL configuration found");
|
||||
}
|
||||
|
||||
private void createEGLSurface() {
|
||||
SurfaceHolder surfaceHolder = mView.getHolder();
|
||||
mEGLSurface = mEGL.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, surfaceHolder, null);
|
||||
if (mEGLSurface == null || mEGLSurface == EGL10.EGL_NO_SURFACE) {
|
||||
throw new GLControllerException("EGL window surface could not be created! " +
|
||||
getEGLError());
|
||||
}
|
||||
|
||||
if (!mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) {
|
||||
throw new GLControllerException("EGL surface could not be made into the current " +
|
||||
"surface! " + getEGLError());
|
||||
}
|
||||
|
||||
mGL = mEGLContext.getGL();
|
||||
|
||||
if (mView.getRenderer() != null) {
|
||||
mView.getRenderer().onSurfaceCreated((GL10)mGL, mEGLConfig);
|
||||
mView.getRenderer().onSurfaceChanged((GL10)mGL, mView.getWidth(), mView.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an EGLSurface without assuming ownership of this surface.
|
||||
* This class does not keep a reference to the provided EGL surface; the
|
||||
|
@ -1,178 +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 android.opengl.GLSurfaceView;
|
||||
import android.view.SurfaceHolder;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
// A GL thread managed by Java. It is not necessary to use this class to use the
|
||||
// FlexibleGLSurfaceView, but it can be helpful, especially if the GL rendering is to be done
|
||||
// entirely in Java.
|
||||
class GLThread extends Thread {
|
||||
private LinkedBlockingQueue<Runnable> mQueue;
|
||||
private GLController mController;
|
||||
private boolean mRenderQueued;
|
||||
|
||||
public GLThread(GLController controller) {
|
||||
mQueue = new LinkedBlockingQueue<Runnable>();
|
||||
mController = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
Runnable runnable;
|
||||
try {
|
||||
runnable = mQueue.take();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
runnable.run();
|
||||
if (runnable instanceof ShutdownMessage) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void recreateSurface() {
|
||||
mQueue.add(new RecreateSurfaceMessage());
|
||||
}
|
||||
|
||||
public void renderFrame() {
|
||||
// Make sure there's only one render event in the queue at a time.
|
||||
synchronized (this) {
|
||||
if (!mRenderQueued) {
|
||||
mQueue.add(new RenderFrameMessage());
|
||||
mRenderQueued = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
mQueue.add(new ShutdownMessage());
|
||||
}
|
||||
|
||||
public void surfaceChanged(int width, int height) {
|
||||
mQueue.add(new SizeChangedMessage(width, height));
|
||||
}
|
||||
|
||||
public void surfaceCreated() {
|
||||
mQueue.add(new SurfaceCreatedMessage());
|
||||
}
|
||||
|
||||
public void surfaceDestroyed() {
|
||||
mQueue.add(new SurfaceDestroyedMessage());
|
||||
}
|
||||
|
||||
private void doRecreateSurface() {
|
||||
mController.disposeGLContext();
|
||||
mController.initGLContext();
|
||||
}
|
||||
|
||||
private GLSurfaceView.Renderer getRenderer() {
|
||||
return mController.getView().getRenderer();
|
||||
}
|
||||
|
||||
private class RecreateSurfaceMessage implements Runnable {
|
||||
public void run() {
|
||||
doRecreateSurface();
|
||||
}
|
||||
}
|
||||
|
||||
private class RenderFrameMessage implements Runnable {
|
||||
public void run() {
|
||||
synchronized (GLThread.this) {
|
||||
mRenderQueued = false;
|
||||
}
|
||||
|
||||
// Bail out if the surface was lost.
|
||||
if (mController.getEGLSurface() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GLSurfaceView.Renderer renderer = getRenderer();
|
||||
if (renderer != null) {
|
||||
renderer.onDrawFrame((GL10)mController.getGL());
|
||||
}
|
||||
|
||||
mController.swapBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
private class ShutdownMessage implements Runnable {
|
||||
public void run() {
|
||||
mController.disposeGLContext();
|
||||
mController = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class SizeChangedMessage implements Runnable {
|
||||
private int mWidth, mHeight;
|
||||
|
||||
public SizeChangedMessage(int width, int height) {
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
GLSurfaceView.Renderer renderer = getRenderer();
|
||||
if (renderer != null) {
|
||||
renderer.onSurfaceChanged((GL10)mController.getGL(), mWidth, mHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SurfaceCreatedMessage implements Runnable {
|
||||
public void run() {
|
||||
if (!mController.hasSurface()) {
|
||||
mController.initGLContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SurfaceDestroyedMessage implements Runnable {
|
||||
public void run() {
|
||||
mController.disposeGLContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +103,6 @@ public class LayerView extends FlexibleGLSurfaceView {
|
||||
|
||||
setFocusable(true);
|
||||
setFocusableInTouchMode(true);
|
||||
|
||||
createGLThread();
|
||||
}
|
||||
|
||||
private void addToEventQueue(MotionEvent event) {
|
||||
|
@ -1110,7 +1110,6 @@ AndroidBridge::RegisterCompositor()
|
||||
EGLSurface
|
||||
AndroidBridge::ProvideEGLSurface()
|
||||
{
|
||||
sController.WaitForValidSurface();
|
||||
return sController.ProvideEGLSurface();
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,6 @@ void AndroidEGLObject::Init(JNIEnv* aJEnv) {
|
||||
}
|
||||
|
||||
jmethodID AndroidGLController::jSetGLVersionMethod = 0;
|
||||
jmethodID AndroidGLController::jWaitForValidSurfaceMethod = 0;
|
||||
jmethodID AndroidGLController::jProvideEGLSurfaceMethod = 0;
|
||||
|
||||
void
|
||||
@ -62,7 +61,6 @@ AndroidGLController::Init(JNIEnv *aJEnv)
|
||||
jSetGLVersionMethod = aJEnv->GetMethodID(jClass, "setGLVersion", "(I)V");
|
||||
jProvideEGLSurfaceMethod = aJEnv->GetMethodID(jClass, "provideEGLSurface",
|
||||
"()Ljavax/microedition/khronos/egl/EGLSurface;");
|
||||
jWaitForValidSurfaceMethod = aJEnv->GetMethodID(jClass, "waitForValidSurface", "()V");
|
||||
}
|
||||
|
||||
void
|
||||
@ -87,10 +85,3 @@ AndroidGLController::ProvideEGLSurface()
|
||||
jobject jObj = mJEnv->CallObjectMethod(mJObj, jProvideEGLSurfaceMethod);
|
||||
return reinterpret_cast<EGLSurface>(mJEnv->GetIntField(jObj, jEGLSurfacePointerField));
|
||||
}
|
||||
|
||||
void
|
||||
AndroidGLController::WaitForValidSurface()
|
||||
{
|
||||
ASSERT_THREAD();
|
||||
mJEnv->CallVoidMethod(mJObj, jWaitForValidSurfaceMethod);
|
||||
}
|
||||
|
@ -58,11 +58,9 @@ public:
|
||||
void Acquire(JNIEnv *aJEnv, jobject aJObj);
|
||||
void SetGLVersion(int aVersion);
|
||||
EGLSurface ProvideEGLSurface();
|
||||
void WaitForValidSurface();
|
||||
|
||||
private:
|
||||
static jmethodID jSetGLVersionMethod;
|
||||
static jmethodID jWaitForValidSurfaceMethod;
|
||||
static jmethodID jProvideEGLSurfaceMethod;
|
||||
|
||||
// the JNIEnv for the compositor thread
|
||||
|
Loading…
Reference in New Issue
Block a user