Eliminate coupling between the software layer client and the rest of Fennec

This commit is contained in:
Patrick Walton 2012-02-02 23:30:41 -08:00
Родитель 93b70fee0c
Коммит 08a46d3640
10 изменённых файлов: 92 добавлений и 49 удалений

Просмотреть файл

@ -41,6 +41,7 @@
package org.mozilla.gecko;
import org.mozilla.gecko.gfx.FloatSize;
import org.mozilla.gecko.gfx.GeckoLayerClient;
import org.mozilla.gecko.gfx.GeckoSoftwareLayerClient;
import org.mozilla.gecko.gfx.IntSize;
import org.mozilla.gecko.gfx.LayerController;
@ -139,7 +140,7 @@ abstract public class GeckoApp
private Address mLastGeoAddress;
private static LayerController mLayerController;
private static PlaceholderLayerClient mPlaceholderLayerClient;
private static GeckoSoftwareLayerClient mSoftwareLayerClient;
private static GeckoLayerClient mLayerClient;
private AboutHomeContent mAboutHomeContent;
private static AbsoluteLayout mPluginContainer;
@ -565,7 +566,7 @@ abstract public class GeckoApp
}
public void run() {
synchronized (mSoftwareLayerClient) {
synchronized (mLayerClient) {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab == null)
return;
@ -574,10 +575,10 @@ abstract public class GeckoApp
if (lastHistoryEntry == null)
return;
if (getLayerController().getLayerClient() != mSoftwareLayerClient)
if (getLayerController().getLayerClient() != mLayerClient)
return;
ViewportMetrics viewportMetrics = mSoftwareLayerClient.getGeckoViewportMetrics();
ViewportMetrics viewportMetrics = mLayerClient.getGeckoViewportMetrics();
if (viewportMetrics != null)
mLastViewport = viewportMetrics.toJSON();
@ -589,8 +590,7 @@ abstract public class GeckoApp
void getAndProcessThumbnailForTab(final Tab tab, boolean forceBigSceenshot) {
boolean isSelectedTab = Tabs.getInstance().isSelectedTab(tab);
final Bitmap bitmap = isSelectedTab ?
mSoftwareLayerClient.getBitmap() : null;
final Bitmap bitmap = isSelectedTab ? mLayerClient.getBitmap() : null;
if (bitmap != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@ -598,8 +598,8 @@ abstract public class GeckoApp
processThumbnail(tab, bitmap, bos.toByteArray());
} else {
mLastScreen = null;
int sw = forceBigSceenshot ? mSoftwareLayerClient.getWidth() : tab.getMinScreenshotWidth();
int sh = forceBigSceenshot ? mSoftwareLayerClient.getHeight(): tab.getMinScreenshotHeight();
int sw = forceBigSceenshot ? mLayerClient.getWidth() : tab.getMinScreenshotWidth();
int sh = forceBigSceenshot ? mLayerClient.getHeight(): tab.getMinScreenshotHeight();
int dw = forceBigSceenshot ? sw : tab.getThumbnailWidth();
int dh = forceBigSceenshot ? sh : tab.getThumbnailHeight();
try {
@ -1592,7 +1592,7 @@ abstract public class GeckoApp
* Create a layer client so that Gecko will have a buffer to draw into, but don't hook
* it up to the layer controller yet.
*/
mSoftwareLayerClient = new GeckoSoftwareLayerClient(this);
mLayerClient = new GeckoSoftwareLayerClient(this);
/*
* Hook a placeholder layer client up to the layer controller so that the user can pan
@ -2447,7 +2447,7 @@ abstract public class GeckoApp
GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Add", args.toString()));
}
public GeckoSoftwareLayerClient getSoftwareLayerClient() { return mSoftwareLayerClient; }
public GeckoLayerClient getLayerClient() { return mLayerClient; }
public LayerController getLayerController() { return mLayerController; }
// accelerometer
@ -2526,7 +2526,7 @@ abstract public class GeckoApp
mPlaceholderLayerClient.destroy();
LayerController layerController = getLayerController();
layerController.setLayerClient(mSoftwareLayerClient);
layerController.setLayerClient(mLayerClient);
}
}

Просмотреть файл

@ -39,7 +39,7 @@
package org.mozilla.gecko;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.gfx.GeckoSoftwareLayerClient;
import org.mozilla.gecko.gfx.GeckoLayerClient;
import org.mozilla.gecko.gfx.LayerController;
import org.mozilla.gecko.gfx.AbstractLayerView;
@ -124,7 +124,7 @@ public class GeckoAppShell
// helper methods
// public static native void setSurfaceView(GeckoSurfaceView sv);
public static native void setSoftwareLayerClient(GeckoSoftwareLayerClient client);
public static native void setLayerClient(GeckoLayerClient client, int type);
public static native void putenv(String map);
public static native void onResume();
public static native void onLowMemory();
@ -467,9 +467,10 @@ public class GeckoAppShell
Log.i(LOGTAG, "post native init");
// Tell Gecko where the target byte buffer is for rendering
GeckoAppShell.setSoftwareLayerClient(GeckoApp.mAppContext.getSoftwareLayerClient());
GeckoAppShell.setLayerClient(GeckoApp.mAppContext.getLayerClient(),
GeckoApp.mAppContext.getLayerClient().getType());
Log.i(LOGTAG, "setSoftwareLayerClient called");
Log.i(LOGTAG, "setLayerClient called");
// First argument is the .apk path
String combinedArgs = apkPath + " -greomni " + apkPath;

Просмотреть файл

@ -46,6 +46,7 @@ import org.mozilla.gecko.GeckoEventListener;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.Rect;
@ -58,6 +59,10 @@ import java.util.regex.Pattern;
public abstract class GeckoLayerClient extends LayerClient implements GeckoEventListener {
private static final String LOGTAG = "GeckoLayerClient";
public static final int LAYER_CLIENT_TYPE_NONE = 0;
public static final int LAYER_CLIENT_TYPE_SOFTWARE = 1;
public static final int LAYER_CLIENT_TYPE_GL = 2;
protected IntSize mScreenSize;
protected IntSize mBufferSize;
@ -91,6 +96,8 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
protected abstract void updateLayerAfterDraw(Rect updatedRect);
protected abstract IntSize getBufferSize();
protected abstract IntSize getTileSize();
public abstract Bitmap getBitmap();
public abstract int getType();
public GeckoLayerClient(Context context) {
mScreenSize = new IntSize(0, 0);
@ -307,6 +314,21 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
render();
}
public int getWidth() {
return mBufferSize.width;
}
public int getHeight() {
return mBufferSize.height;
}
public ViewportMetrics getGeckoViewportMetrics() {
// Return a copy, as we modify this inside the Gecko thread
if (mGeckoViewport != null)
return new ViewportMetrics(mGeckoViewport);
return null;
}
private void sendResizeEventIfNecessary() {
sendResizeEventIfNecessary(false);
}

Просмотреть файл

@ -95,14 +95,6 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
};
}
public int getWidth() {
return mBufferSize.width;
}
public int getHeight() {
return mBufferSize.height;
}
protected void finalize() throws Throwable {
try {
if (mBuffer != null)
@ -229,14 +221,7 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
((MultiTileLayer)mTileLayer).setRenderOffset(mRenderOffset);
}
public ViewportMetrics getGeckoViewportMetrics() {
// Return a copy, as we modify this inside the Gecko thread
if (mGeckoViewport != null)
return new ViewportMetrics(mGeckoViewport);
return null;
}
public void copyPixelsFromMultiTileLayer(Bitmap target) {
private void copyPixelsFromMultiTileLayer(Bitmap target) {
Canvas c = new Canvas(target);
ByteBuffer tileBuffer = mBuffer.slice();
int bpp = CairoUtils.bitsPerPixelForCairoFormat(mFormat) / 8;
@ -259,6 +244,7 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
}
}
@Override
public Bitmap getBitmap() {
if (mTileLayer == null)
return null;
@ -307,6 +293,11 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
/* no-op */
}
@Override
public int getType() {
return LAYER_CLIENT_TYPE_SOFTWARE;
}
@Override
protected IntSize getBufferSize() {
// Round up depending on layer implementation to remove texture wastage

Просмотреть файл

@ -284,7 +284,7 @@ SHELL_WRAPPER1(nativeRun, jstring)
SHELL_WRAPPER1(notifyGeckoOfEvent, jobject)
SHELL_WRAPPER0(processNextNativeEvent)
SHELL_WRAPPER1(setSurfaceView, jobject)
SHELL_WRAPPER1(setSoftwareLayerClient, jobject)
SHELL_WRAPPER2(setLayerClient, jobject, jint)
SHELL_WRAPPER0(onResume)
SHELL_WRAPPER0(onLowMemory)
SHELL_WRAPPER3(callObserver, jstring, jstring, jstring)
@ -698,7 +698,7 @@ loadGeckoLibs(const char *apkName)
GETFUNC(notifyGeckoOfEvent);
GETFUNC(processNextNativeEvent);
GETFUNC(setSurfaceView);
GETFUNC(setSoftwareLayerClient);
GETFUNC(setLayerClient);
GETFUNC(onResume);
GETFUNC(onLowMemory);
GETFUNC(callObserver);

Просмотреть файл

@ -956,9 +956,29 @@ AndroidBridge::SetSurfaceView(jobject obj)
}
void
AndroidBridge::SetSoftwareLayerClient(jobject obj)
AndroidBridge::SetLayerClient(jobject obj, jint type)
{
mSoftwareLayerClient.Init(obj);
switch (type) {
case LAYER_CLIENT_TYPE_SOFTWARE: {
AndroidGeckoSoftwareLayerClient *client = new AndroidGeckoSoftwareLayerClient();
client->Init(obj);
mLayerClient = client;
break;
}
case LAYER_CLIENT_TYPE_GL: {
// TODO: Implement.
#if 0
AndroidGeckoGLLayerClient *client = new AndroidGeckoGLLayerClient();
client->Init(obj);
mLayerClient = client;
#endif
break;
}
default:
NS_ASSERTION(0, "Unknown layer client type!");
}
mLayerClientType = type;
}
void

Просмотреть файл

@ -110,6 +110,12 @@ public:
NOTIFY_IME_FOCUSCHANGE = 3
};
enum {
LAYER_CLIENT_TYPE_NONE = 0,
LAYER_CLIENT_TYPE_SOFTWARE = 1, // AndroidGeckoSoftwareLayerClient
LAYER_CLIENT_TYPE_GL = 2 // AndroidGeckoGLLayerClient
};
static AndroidBridge *ConstructBridge(JNIEnv *jEnv,
jclass jGeckoAppShellClass);
@ -168,8 +174,9 @@ public:
void ScheduleRestart();
void SetSoftwareLayerClient(jobject jobj);
AndroidGeckoSoftwareLayerClient &GetSoftwareLayerClient() { return mSoftwareLayerClient; }
void SetLayerClient(jobject jobj, jint type);
int GetLayerClientType() const { return mLayerClientType; }
AndroidGeckoLayerClient &GetLayerClient() { return *mLayerClient; }
void SetSurfaceView(jobject jobj);
AndroidGeckoSurfaceView& SurfaceView() { return mSurfaceView; }
@ -396,12 +403,14 @@ protected:
// the GeckoSurfaceView
AndroidGeckoSurfaceView mSurfaceView;
AndroidGeckoSoftwareLayerClient mSoftwareLayerClient;
AndroidGeckoLayerClient *mLayerClient;
int mLayerClientType;
// the GeckoAppShell java class
jclass mGeckoAppShellClass;
AndroidBridge() { }
AndroidBridge() : mLayerClient(NULL), mLayerClientType(0) { }
bool Init(JNIEnv *jEnv, jclass jGeckoApp);
bool mOpenedGraphicsLibraries;

Просмотреть файл

@ -79,7 +79,7 @@ extern "C" {
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_nativeInit(JNIEnv *, jclass);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent(JNIEnv *, jclass, jobject event);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_processNextNativeEvent(JNIEnv *, jclass);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setSoftwareLayerClient(JNIEnv *jenv, jclass, jobject sv);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setLayerClient(JNIEnv *jenv, jclass, jobject sv, jint type);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setSurfaceView(JNIEnv *jenv, jclass, jobject sv);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onResume(JNIEnv *, jclass);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onLowMemory(JNIEnv *, jclass);
@ -144,9 +144,9 @@ Java_org_mozilla_gecko_GeckoAppShell_setSurfaceView(JNIEnv *jenv, jclass, jobjec
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_setSoftwareLayerClient(JNIEnv *jenv, jclass, jobject obj)
Java_org_mozilla_gecko_GeckoAppShell_setLayerClient(JNIEnv *jenv, jclass, jobject obj, jint type)
{
AndroidBridge::Bridge()->SetSoftwareLayerClient(jenv->NewGlobalRef(obj));
AndroidBridge::Bridge()->SetLayerClient(jenv->NewGlobalRef(obj), type);
}
NS_EXPORT void JNICALL

Просмотреть файл

@ -193,7 +193,6 @@ protected:
static jmethodID jGetRenderOffsetMethod;
};
class AndroidGeckoSurfaceView : public WrappedJavaObject
{
public:

Просмотреть файл

@ -1263,8 +1263,7 @@ nsWindow::OnDraw(AndroidGeckoEvent *ae)
// END HACK: gl layers
#endif
AndroidGeckoSoftwareLayerClient &client =
AndroidBridge::Bridge()->GetSoftwareLayerClient();
AndroidGeckoLayerClient &client = AndroidBridge::Bridge()->GetLayerClient();
if (!client.BeginDrawing(gAndroidBounds.width, gAndroidBounds.height,
gAndroidTileSize.width, gAndroidTileSize.height,
metadata, HasDirectTexture())) {
@ -1273,6 +1272,8 @@ nsWindow::OnDraw(AndroidGeckoEvent *ae)
nsIntRect dirtyRect = ae->Rect().Intersect(nsIntRect(0, 0, gAndroidBounds.width, gAndroidBounds.height));
int layerClientType = AndroidBridge::Bridge()->GetLayerClientType();
unsigned char *bits = NULL;
if (HasDirectTexture()) {
if (sDirectTexture->Width() != gAndroidBounds.width ||
@ -1281,8 +1282,8 @@ nsWindow::OnDraw(AndroidGeckoEvent *ae)
}
sDirectTexture->Lock(AndroidGraphicBuffer::UsageSoftwareWrite, dirtyRect, &bits);
} else {
bits = client.LockBufferBits();
} else if (layerClientType == AndroidBridge::LAYER_CLIENT_TYPE_SOFTWARE) {
bits = ((AndroidGeckoSoftwareLayerClient &)client).LockBufferBits();
}
if (!bits) {
@ -1295,8 +1296,8 @@ nsWindow::OnDraw(AndroidGeckoEvent *ae)
if (HasDirectTexture()) {
sDirectTexture->Unlock();
} else {
client.UnlockBuffer();
} else if (layerClientType == AndroidBridge::LAYER_CLIENT_TYPE_SOFTWARE) {
((AndroidGeckoSoftwareLayerClient &)client).UnlockBuffer();
}
client.EndDrawing(dirtyRect);