Bug 1294479 - Remove ANativeWindow methods from AndroidBridge; r=snorp
authorJim Chen <nchen@mozilla.com>
Fri, 19 Aug 2016 17:17:24 -0400
changeset 310424 97c5c05e25d1335812f7bdb5f63416328cf3d1a4
parent 310423 ec9f15ec23450e24bd79cf7487156e52824f7f5e
child 310425 fd8d766932630c6e2c34a6e02eb8c428bb898b46
push id20358
push userryanvm@gmail.com
push dateMon, 22 Aug 2016 13:41:41 +0000
treeherderfx-team@194fe275b4e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1294479
milestone51.0a1
Bug 1294479 - Remove ANativeWindow methods from AndroidBridge; r=snorp The ANativeWindow methods in AndroidBridge are just wrappers around ANativeWindow calls in the NDK. We should just use those calls instead of going through the wrappers.
gfx/gl/GLContextProviderEGL.cpp
gfx/layers/composite/LayerManagerComposite.cpp
widget/android/AndroidBridge.cpp
widget/android/AndroidBridge.h
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -18,17 +18,18 @@
 #if defined(XP_UNIX)
     #ifdef MOZ_WIDGET_GONK
         #include "libdisplay/GonkDisplay.h"
         #include "nsWindow.h"
         #include "nsScreenManagerGonk.h"
     #endif
 
     #ifdef MOZ_WIDGET_ANDROID
-        #include "AndroidBridge.h"
+        #include <android/native_window.h>
+        #include <android/native_window_jni.h>
     #endif
 
     #ifdef ANDROID
         #include <android/log.h>
         #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
 
         #ifdef MOZ_WIDGET_GONK
             #include "cutils/properties.h"
@@ -178,20 +179,22 @@ CreateSurfaceForWindow(nsIWidget* widget
 
     MOZ_ASSERT(widget);
 #ifdef MOZ_WIDGET_ANDROID
     void* javaSurface = GET_JAVA_SURFACE(widget);
     if (!javaSurface) {
         MOZ_CRASH("GFX: Failed to get Java surface.\n");
     }
     JNIEnv* const env = jni::GetEnvForThread();
-    void* nativeWindow = AndroidBridge::Bridge()->AcquireNativeWindow(env, reinterpret_cast<jobject>(javaSurface));
-    newSurface = sEGLLibrary.fCreateWindowSurface(sEGLLibrary.fGetDisplay(EGL_DEFAULT_DISPLAY), config,
-                                                  nativeWindow, 0);
-    AndroidBridge::Bridge()->ReleaseNativeWindow(nativeWindow);
+    ANativeWindow* const nativeWindow = ANativeWindow_fromSurface(
+            env, reinterpret_cast<jobject>(javaSurface));
+    newSurface = sEGLLibrary.fCreateWindowSurface(
+            sEGLLibrary.fGetDisplay(EGL_DEFAULT_DISPLAY),
+            config, nativeWindow, 0);
+    ANativeWindow_release(nativeWindow);
 #else
     newSurface = sEGLLibrary.fCreateWindowSurface(EGL_DISPLAY(), config,
                                                   GET_NATIVE_WINDOW(widget), 0);
 #endif
     return newSurface;
 }
 
 GLContextEGL::GLContextEGL(CreateContextFlags flags, const SurfaceCaps& caps,
--- a/gfx/layers/composite/LayerManagerComposite.cpp
+++ b/gfx/layers/composite/LayerManagerComposite.cpp
@@ -51,17 +51,17 @@
 #include "nsDebug.h"                    // for NS_WARNING, NS_RUNTIMEABORT, etc
 #include "nsISupportsImpl.h"            // for Layer::AddRef, etc
 #include "nsIWidget.h"                  // for nsIWidget
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsRect.h"                     // for mozilla::gfx::IntRect
 #include "nsRegion.h"                   // for nsIntRegion, etc
 #ifdef MOZ_WIDGET_ANDROID
 #include <android/log.h>
-#include "AndroidBridge.h"
+#include <android/native_window.h>
 #endif
 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
 #include "opengl/CompositorOGL.h"
 #include "GLContextEGL.h"
 #include "GLContextProvider.h"
 #include "ScopedGLHelpers.h"
 #endif
 #ifdef MOZ_WIDGET_GONK
@@ -1110,17 +1110,18 @@ LayerManagerComposite::RenderToPresentat
   CompositorOGL* compositor = mCompositor->AsCompositorOGL();
   GLContext* gl = compositor->gl();
   GLContextEGL* egl = GLContextEGL::Cast(gl);
 
   if (!egl) {
     return;
   }
 
-  const IntSize windowSize = AndroidBridge::Bridge()->GetNativeWindowSize(window);
+  const IntSize windowSize(ANativeWindow_getWidth(window),
+                           ANativeWindow_getHeight(window));
 
 #elif defined(MOZ_WIDGET_GONK)
   CompositorOGL* compositor = mCompositor->AsCompositorOGL();
   nsScreenGonk* screen = static_cast<nsWindow*>(mCompositor->GetWidget()->RealWidget())->GetScreen();
   if (!screen->IsPrimaryScreen()) {
     // Only primary screen support mirroring
     return;
   }
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -2,18 +2,16 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <android/log.h>
 #include <dlfcn.h>
 #include <math.h>
 #include <GLES2/gl2.h>
-#include <android/native_window.h>
-#include <android/native_window_jni.h>
 
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 
 #include "mozilla/Hal.h"
 #include "nsXULAppAPI.h"
 #include <prthread.h>
 #include "nsXPCOMStrings.h"
@@ -1029,38 +1027,16 @@ AndroidBridge::GetCurrentNetworkInformat
 
     aNetworkInfo->type() = info[0];
     aNetworkInfo->isWifi() = info[1] == 1.0f;
     aNetworkInfo->dhcpGateway() = info[2];
 
     env->ReleaseDoubleArrayElements(arr.Get(), info, 0);
 }
 
-void*
-AndroidBridge::AcquireNativeWindow(JNIEnv* aEnv, jobject aSurface)
-{
-    return ANativeWindow_fromSurface(aEnv, aSurface);
-}
-
-void
-AndroidBridge::ReleaseNativeWindow(void *window)
-{
-    return ANativeWindow_release((ANativeWindow*)window);
-}
-
-IntSize
-AndroidBridge::GetNativeWindowSize(void* window)
-{
-    if (!window) {
-      return IntSize(0, 0);
-    }
-
-    return IntSize(ANativeWindow_getWidth((ANativeWindow*)window), ANativeWindow_getHeight((ANativeWindow*)window));
-}
-
 jobject
 AndroidBridge::GetGlobalContextRef() {
     if (sGlobalContext) {
         return sGlobalContext;
     }
 
     JNIEnv* const env = GetEnvForThread();
     AutoLocalJNIFrame jniFrame(env, 4);
--- a/widget/android/AndroidBridge.h
+++ b/widget/android/AndroidBridge.h
@@ -188,20 +188,16 @@ public:
 
     bool GetStaticIntField(const char *className, const char *fieldName, int32_t* aInt, JNIEnv* env = nullptr);
 
     // Returns a global reference to the Context for Fennec's Activity. The
     // caller is responsible for ensuring this doesn't leak by calling
     // DeleteGlobalRef() when the context is no longer needed.
     jobject GetGlobalContextRef(void);
 
-    void *AcquireNativeWindow(JNIEnv* aEnv, jobject aSurface);
-    void ReleaseNativeWindow(void *window);
-    mozilla::gfx::IntSize GetNativeWindowSize(void* window);
-
     void HandleGeckoMessage(JSContext* cx, JS::HandleObject message);
 
     bool InitCamera(const nsCString& contentType, uint32_t camera, uint32_t *width, uint32_t *height, uint32_t *fps);
 
     void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
 
     nsresult GetSegmentInfoForText(const nsAString& aText,
                                    nsIMobileMessageCallback* aRequest);