Merge tips of mozilla-central and mozilla-inbound

This commit is contained in:
Ed Morley 2011-09-25 13:58:53 +01:00
Родитель 4cbb00125a e0fc97dd2d
Коммит 27cc5cc8df
8 изменённых файлов: 95 добавлений и 277 удалений

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

@ -487,19 +487,17 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPropertyBag> contextProps;
nsCOMPtr<nsIWritablePropertyBag2> contextProps;
if (!JSVAL_IS_NULL(aContextOptions) &&
!JSVAL_IS_VOID(aContextOptions))
{
JSContext *cx = nsContentUtils::GetCurrentJSContext();
nsCOMPtr<nsIWritablePropertyBag2> newProps;
// note: if any contexts end up supporting something other
// than objects, e.g. plain strings, then we'll need to expand
// this to know how to create nsISupportsStrings etc.
if (JSVAL_IS_OBJECT(aContextOptions)) {
newProps = do_CreateInstance("@mozilla.org/hash-property-bag;1");
contextProps = do_CreateInstance("@mozilla.org/hash-property-bag;1");
JSObject *opts = JSVAL_TO_OBJECT(aContextOptions);
JSIdArray *props = JS_Enumerate(cx, opts);
@ -520,11 +518,11 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
}
if (JSVAL_IS_BOOLEAN(propval)) {
newProps->SetPropertyAsBool(pstr, propval == JSVAL_TRUE ? PR_TRUE : PR_FALSE);
contextProps->SetPropertyAsBool(pstr, propval == JSVAL_TRUE ? PR_TRUE : PR_FALSE);
} else if (JSVAL_IS_INT(propval)) {
newProps->SetPropertyAsInt32(pstr, JSVAL_TO_INT(propval));
contextProps->SetPropertyAsInt32(pstr, JSVAL_TO_INT(propval));
} else if (JSVAL_IS_DOUBLE(propval)) {
newProps->SetPropertyAsDouble(pstr, JSVAL_TO_DOUBLE(propval));
contextProps->SetPropertyAsDouble(pstr, JSVAL_TO_DOUBLE(propval));
} else if (JSVAL_IS_STRING(propval)) {
JSString *propvalString = JS_ValueToString(cx, propval);
nsDependentJSString vstr;
@ -533,12 +531,10 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
return NS_ERROR_FAILURE;
}
newProps->SetPropertyAsAString(pstr, vstr);
contextProps->SetPropertyAsAString(pstr, vstr);
}
}
}
contextProps = newProps;
}
rv = UpdateContext(contextProps);

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

@ -248,65 +248,75 @@ class GeckoSurfaceView
mSurfaceLock.lock();
if (mInDrawing) {
Log.w(LOG_FILE_NAME, "surfaceChanged while mInDrawing is true!");
}
boolean invalidSize;
if (width == 0 || height == 0) {
mSoftwareBitmap = null;
mSoftwareBuffer = null;
mSoftwareBufferCopy = null;
invalidSize = true;
} else {
invalidSize = false;
}
boolean doSyncDraw =
mDrawMode == DRAW_2D &&
!invalidSize &&
GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning);
mSyncDraw = doSyncDraw;
mFormat = format;
mWidth = width;
mHeight = height;
mSurfaceValid = true;
Log.i(LOG_FILE_NAME, "surfaceChanged: fmt: " + format + " dim: " + width + " " + height);
try {
if (mInDrawing) {
Log.w(LOG_FILE_NAME, "surfaceChanged while mInDrawing is true!");
}
boolean invalidSize;
if (width == 0 || height == 0) {
mSoftwareBitmap = null;
mSoftwareBuffer = null;
mSoftwareBufferCopy = null;
invalidSize = true;
} else {
invalidSize = false;
}
boolean doSyncDraw =
mDrawMode == DRAW_2D &&
!invalidSize &&
GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning);
mSyncDraw = doSyncDraw;
mFormat = format;
mWidth = width;
mHeight = height;
mSurfaceValid = true;
Log.i(LOG_FILE_NAME, "surfaceChanged: fmt: " + format + " dim: " + width + " " + height);
DisplayMetrics metrics = new DisplayMetrics();
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
GeckoEvent e = new GeckoEvent(GeckoEvent.SIZE_CHANGED, width, height,
metrics.widthPixels, metrics.heightPixels);
GeckoAppShell.sendEventToGecko(e);
if (!doSyncDraw) {
if (mDrawMode == DRAW_GLES_2 || mShowingSplashScreen)
return;
Canvas c = holder.lockCanvas();
c.drawARGB(255, 255, 255, 255);
holder.unlockCanvasAndPost(c);
return;
} else {
GeckoAppShell.scheduleRedraw();
}
} finally {
mSurfaceLock.unlock();
if (mDrawMode == DRAW_GLES_2) {
// Force a frame to be drawn before the surfaceChange returns,
// otherwise we get artifacts.
GeckoAppShell.scheduleRedraw();
GeckoAppShell.geckoEventSync();
}
}
if (doSyncDraw) {
Object syncDrawObject = null;
try {
syncDrawObject = mSyncDraws.take();
} catch (InterruptedException ie) {
Log.e(LOG_FILE_NAME, "Threw exception while getting sync draw bitmap/buffer: ", ie);
}
if (syncDrawObject != null) {
if (syncDrawObject instanceof Bitmap)
draw(holder, (Bitmap)syncDrawObject);
else
draw(holder, (ByteBuffer)syncDrawObject);
} else {
Log.e("GeckoSurfaceViewJava", "Synchronised draw object is null");
}
} else if (!mShowingSplashScreen) {
// Make sure a frame is drawn before we return
// otherwise we see artifacts or a black screen
GeckoAppShell.scheduleRedraw();
GeckoAppShell.geckoEventSync();
Object syncDrawObject = null;
try {
syncDrawObject = mSyncDraws.take();
} catch (InterruptedException ie) {
Log.e(LOG_FILE_NAME, "Threw exception while getting sync draw bitmap/buffer: ", ie);
}
if (syncDrawObject != null) {
if (syncDrawObject instanceof Bitmap)
draw(holder, (Bitmap)syncDrawObject);
else
draw(holder, (ByteBuffer)syncDrawObject);
} else {
Log.e("GeckoSurfaceViewJava", "Synchronised draw object is null");
}
}
@ -362,10 +372,6 @@ class GeckoSurfaceView
return mSoftwareBuffer;
}
public Surface getSurface() {
return getHolder().getSurface();
}
/*
* Called on Gecko thread
*/

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

@ -106,9 +106,8 @@ AndroidBridge::Init(JNIEnv *jEnv,
mJNIEnv = nsnull;
mThread = nsnull;
mOpenedGraphicsLibraries = false;
mOpenedBitmapLibrary = false;
mHasNativeBitmapAccess = false;
mHasNativeWindowAccess = false;
mGeckoAppShellClass = (jclass) jEnv->NewGlobalRef(jGeckoAppShellClass);
@ -978,46 +977,33 @@ AndroidBridge::ExecuteNextRunnable()
}
__android_log_print(ANDROID_LOG_INFO, "GeckoBridge", "leaving %s", __PRETTY_FUNCTION__);
}
void
AndroidBridge::OpenGraphicsLibraries()
{
if (!mOpenedGraphicsLibraries) {
// Try to dlopen libjnigraphics.so for direct bitmap access on
// Android 2.2+ (API level 8)
mOpenedGraphicsLibraries = true;
void *handle = dlopen("/system/lib/libjnigraphics.so", RTLD_LAZY | RTLD_LOCAL);
if (handle) {
AndroidBitmap_getInfo = (int (*)(JNIEnv *, jobject, void *))dlsym(handle, "AndroidBitmap_getInfo");
AndroidBitmap_lockPixels = (int (*)(JNIEnv *, jobject, void **))dlsym(handle, "AndroidBitmap_lockPixels");
AndroidBitmap_unlockPixels = (int (*)(JNIEnv *, jobject))dlsym(handle, "AndroidBitmap_unlockPixels");
ALOG_BRIDGE("Successfully opened libjnigraphics.so");
}
// Try to dlopen libandroid.so for and native window access on
// Android 2.3+ (API level 9)
handle = dlopen("/system/lib/libandroid.so", RTLD_LAZY | RTLD_LOCAL);
if (handle) {
ANativeWindow_fromSurface = (void* (*)(JNIEnv*, jobject))dlsym(handle, "ANativeWindow_fromSurface");
ANativeWindow_release = (void (*)(void*))dlsym(handle, "ANativeWindow_release");
ANativeWindow_setBuffersGeometry = (int (*)(void*, int, int, int)) dlsym(handle, "ANativeWindow_setBuffersGeometry");
ANativeWindow_lock = (int (*)(void*, void*, void*)) dlsym(handle, "ANativeWindow_lock");
ANativeWindow_unlockAndPost = (int (*)(void*))dlsym(handle, "ANativeWindow_unlockAndPost");
ALOG_BRIDGE("Successfully opened libandroid.so");
}
mHasNativeBitmapAccess = AndroidBitmap_getInfo && AndroidBitmap_lockPixels && AndroidBitmap_unlockPixels;
mHasNativeWindowAccess = ANativeWindow_fromSurface && ANativeWindow_release && ANativeWindow_lock && ANativeWindow_unlockAndPost;
}
}
bool
AndroidBridge::HasNativeBitmapAccess()
{
OpenGraphicsLibraries();
if (!mOpenedBitmapLibrary) {
// Try to dlopen libjnigraphics.so for direct bitmap access on
// Android 2.2+ (API level 8)
mOpenedBitmapLibrary = true;
void *handle = dlopen("/system/lib/libjnigraphics.so", RTLD_LAZY | RTLD_LOCAL);
if (handle == nsnull)
return false;
AndroidBitmap_getInfo = (int (*)(JNIEnv *, jobject, void *))dlsym(handle, "AndroidBitmap_getInfo");
if (AndroidBitmap_getInfo == nsnull)
return false;
AndroidBitmap_lockPixels = (int (*)(JNIEnv *, jobject, void **))dlsym(handle, "AndroidBitmap_lockPixels");
if (AndroidBitmap_lockPixels == nsnull)
return false;
AndroidBitmap_unlockPixels = (int (*)(JNIEnv *, jobject))dlsym(handle, "AndroidBitmap_unlockPixels");
if (AndroidBitmap_unlockPixels == nsnull)
return false;
ALOG_BRIDGE("Successfully opened libjnigraphics.so");
mHasNativeBitmapAccess = true;
}
return mHasNativeBitmapAccess;
}
@ -1071,92 +1057,3 @@ AndroidBridge::UnlockBitmap(jobject bitmap)
if ((err = AndroidBitmap_unlockPixels(JNI(), bitmap)) != 0)
ALOG_BRIDGE("AndroidBitmap_unlockPixels failed! (error %d)", err);
}
bool
AndroidBridge::HasNativeWindowAccess()
{
OpenGraphicsLibraries();
return mHasNativeWindowAccess;
}
void*
AndroidBridge::AcquireNativeWindow(jobject surface)
{
if (!HasNativeWindowAccess())
return nsnull;
return ANativeWindow_fromSurface(JNI(), surface);
}
void
AndroidBridge::ReleaseNativeWindow(void *window)
{
if (!window)
return;
ANativeWindow_release(window);
}
bool
AndroidBridge::SetNativeWindowFormat(void *window, int format)
{
return ANativeWindow_setBuffersGeometry(window, 0, 0, format) == 0;
}
bool
AndroidBridge::LockWindow(void *window, unsigned char **bits, int *width, int *height, int *format, int *stride)
{
/* Copied from native_window.h in Android NDK (platform-9) */
typedef struct ANativeWindow_Buffer {
// The number of pixels that are show horizontally.
int32_t width;
// The number of pixels that are shown vertically.
int32_t height;
// The number of *pixels* that a line in the buffer takes in
// memory. This may be >= width.
int32_t stride;
// The format of the buffer. One of WINDOW_FORMAT_*
int32_t format;
// The actual bits.
void* bits;
// Do not touch.
uint32_t reserved[6];
} ANativeWindow_Buffer;
int err;
ANativeWindow_Buffer buffer;
*bits = NULL;
*width = *height = *format = 0;
if ((err = ANativeWindow_lock(window, (void*)&buffer, NULL)) != 0) {
ALOG_BRIDGE("ANativeWindow_lock failed! (error %d)", err);
return false;
}
*bits = (unsigned char*)buffer.bits;
*width = buffer.width;
*height = buffer.height;
*format = buffer.format;
*stride = buffer.stride;
return true;
}
bool
AndroidBridge::UnlockWindow(void* window)
{
int err;
if ((err = ANativeWindow_unlockAndPost(window)) != 0) {
ALOG_BRIDGE("ANativeWindow_unlockAndPost failed! (error %d)", err);
return false;
}
return true;
}

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

@ -267,22 +267,6 @@ public:
void ExecuteNextRunnable();
/* Copied from Android's native_window.h in newer (platform 9) NDK */
enum {
WINDOW_FORMAT_RGBA_8888 = 1,
WINDOW_FORMAT_RGBX_8888 = 2,
WINDOW_FORMAT_RGB_565 = 4,
};
bool HasNativeWindowAccess();
void *AcquireNativeWindow(jobject surface);
void ReleaseNativeWindow(void *window);
bool SetNativeWindowFormat(void *window, int format);
bool LockWindow(void *window, unsigned char **bits, int *width, int *height, int *format, int *stride);
bool UnlockWindow(void *window);
protected:
static AndroidBridge *sBridge;
@ -304,11 +288,8 @@ protected:
void EnsureJNIThread();
bool mOpenedGraphicsLibraries;
void OpenGraphicsLibraries();
bool mOpenedBitmapLibrary;
bool mHasNativeBitmapAccess;
bool mHasNativeWindowAccess;
nsCOMArray<nsIRunnable> mRunnableQueue;
@ -365,13 +346,6 @@ protected:
int (* AndroidBitmap_getInfo)(JNIEnv *env, jobject bitmap, void *info);
int (* AndroidBitmap_lockPixels)(JNIEnv *env, jobject bitmap, void **buffer);
int (* AndroidBitmap_unlockPixels)(JNIEnv *env, jobject bitmap);
void* (*ANativeWindow_fromSurface)(JNIEnv *env, jobject surface);
void (*ANativeWindow_release)(void *window);
int (*ANativeWindow_setBuffersGeometry)(void *window, int width, int height, int format);
int (* ANativeWindow_lock)(void *window, void *outBuffer, void *inOutDirtyBounds);
int (* ANativeWindow_unlockAndPost)(void *window);
};
}

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

@ -109,7 +109,6 @@ jmethodID AndroidGeckoSurfaceView::jDraw2DBitmapMethod = 0;
jmethodID AndroidGeckoSurfaceView::jDraw2DBufferMethod = 0;
jmethodID AndroidGeckoSurfaceView::jGetSoftwareDrawBitmapMethod = 0;
jmethodID AndroidGeckoSurfaceView::jGetSoftwareDrawBufferMethod = 0;
jmethodID AndroidGeckoSurfaceView::jGetSurfaceMethod = 0;
jmethodID AndroidGeckoSurfaceView::jGetHolderMethod = 0;
#define JNI() (AndroidBridge::JNI())
@ -184,7 +183,6 @@ AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(JNIEnv *jEnv)
jEndDrawingMethod = getMethod("endDrawing", "()V");
jDraw2DBitmapMethod = getMethod("draw2D", "(Landroid/graphics/Bitmap;II)V");
jDraw2DBufferMethod = getMethod("draw2D", "(Ljava/nio/ByteBuffer;I)V");
jGetSurfaceMethod = getMethod("getSurface", "()Landroid/view/Surface;");
jGetHolderMethod = getMethod("getHolder", "()Landroid/view/SurfaceHolder;");
}
@ -518,12 +516,6 @@ AndroidGeckoSurfaceView::GetSoftwareDrawBuffer()
return JNI()->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBufferMethod);
}
jobject
AndroidGeckoSurfaceView::GetSurface()
{
return JNI()->CallObjectMethod(wrapped_obj, jGetSurfaceMethod);
}
jobject
AndroidGeckoSurfaceView::GetSurfaceHolder()
{

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

@ -175,8 +175,6 @@ public:
void Draw2D(jobject bitmap, int width, int height);
void Draw2D(jobject buffer, int stride);
jobject GetSurface();
// must have a JNI local frame when calling this,
// and you'd better know what you're doing
jobject GetSurfaceHolder();
@ -189,7 +187,6 @@ protected:
static jmethodID jDraw2DBufferMethod;
static jmethodID jGetSoftwareDrawBitmapMethod;
static jmethodID jGetSoftwareDrawBufferMethod;
static jmethodID jGetSurfaceMethod;
static jmethodID jGetHolderMethod;
};

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

@ -129,7 +129,6 @@ static nsRefPtr<gl::GLContext> sGLContext;
static bool sFailedToCreateGLContext = false;
static bool sValidSurface;
static bool sSurfaceExists = false;
static void *sNativeWindow = nsnull;
// Multitouch swipe thresholds in inches
static const double SWIPE_MAX_PINCH_DELTA_INCHES = 0.4;
@ -847,27 +846,12 @@ nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
case AndroidGeckoEvent::SURFACE_CREATED:
sSurfaceExists = true;
if (AndroidBridge::Bridge()->HasNativeWindowAccess()) {
AndroidGeckoSurfaceView& sview(AndroidBridge::Bridge()->SurfaceView());
jobject surface = sview.GetSurface();
if (surface) {
sNativeWindow = AndroidBridge::Bridge()->AcquireNativeWindow(surface);
if (sNativeWindow) {
AndroidBridge::Bridge()->SetNativeWindowFormat(sNativeWindow, AndroidBridge::WINDOW_FORMAT_RGB_565);
}
}
}
break;
case AndroidGeckoEvent::SURFACE_DESTROYED:
if (sGLContext && sValidSurface) {
sGLContext->ReleaseSurface();
}
if (sNativeWindow) {
AndroidBridge::Bridge()->ReleaseNativeWindow(sNativeWindow);
sNativeWindow = nsnull;
}
sSurfaceExists = false;
sValidSurface = false;
break;
@ -1018,35 +1002,7 @@ nsWindow::OnDraw(AndroidGeckoEvent *ae)
AndroidBridge::Bridge()->HideProgressDialogOnce();
if (GetLayerManager(nsnull)->GetBackendType() == LayerManager::LAYERS_BASIC) {
if (sNativeWindow) {
unsigned char *bits;
int width, height, format, stride;
if (!AndroidBridge::Bridge()->LockWindow(sNativeWindow, &bits, &width, &height, &format, &stride)) {
ALOG("failed to lock buffer - skipping draw");
return;
}
if (!bits || format != AndroidBridge::WINDOW_FORMAT_RGB_565 ||
width != mBounds.width || height != mBounds.height) {
ALOG("surface is not expected dimensions or format - skipping draw");
AndroidBridge::Bridge()->UnlockWindow(sNativeWindow);
return;
}
nsRefPtr<gfxImageSurface> targetSurface =
new gfxImageSurface(bits,
gfxIntSize(mBounds.width, mBounds.height),
stride * 2,
gfxASurface::ImageFormatRGB16_565);
if (targetSurface->CairoStatus()) {
ALOG("### Failed to create a valid surface from the bitmap");
} else {
DrawTo(targetSurface);
}
AndroidBridge::Bridge()->UnlockWindow(sNativeWindow);
} else if (AndroidBridge::Bridge()->HasNativeBitmapAccess()) {
if (AndroidBridge::Bridge()->HasNativeBitmapAccess()) {
jobject bitmap = sview.GetSoftwareDrawBitmap();
if (!bitmap) {
ALOG("no bitmap to draw into - skipping draw");

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

@ -721,10 +721,6 @@
and close the popup -->
<method name="searchFailed">
<body><![CDATA[
// if it's the last session to return, time to clean up...
if (this.mSessionReturns == 0)
this.postSearchCleanup();
// if all searches are done and they all failed...
if (this.mSessionReturns == 0 && this.getResultCount() == 0) {
if (this.minResultsForPopup == 0) {
@ -734,6 +730,10 @@
this.closeResultPopup();
}
}
// if it's the last session to return, time to clean up...
if (this.mSessionReturns == 0)
this.postSearchCleanup();
]]></body>
</method>