Bug 1255628 - Remove AndroidNativeWindow, as we can use the NDK functions directly now r=rbarker
authorJames Willcox <snorp@snorp.net>
Wed, 22 Jun 2016 11:19:05 -0500
changeset 308262 4a3775a4a1ab7ec6adef8ca6518bad4ab3f4e4bc
parent 308261 7a7aa2512bf7e53483214433de619dfbee43417d
child 308263 f3f1efff2522b0dca6e5933e65fa935446dc0ea6
push id31092
push usercbook@mozilla.com
push dateFri, 05 Aug 2016 10:16:59 +0000
treeherderautoland@b97dd7dd3cb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1255628
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1255628 - Remove AndroidNativeWindow, as we can use the NDK functions directly now r=rbarker
dom/plugins/base/nsNPAPIPluginInstance.cpp
gfx/gl/AndroidNativeWindow.cpp
gfx/gl/AndroidNativeWindow.h
gfx/gl/AndroidSurfaceTexture.cpp
gfx/gl/AndroidSurfaceTexture.h
gfx/gl/moz.build
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -908,17 +908,17 @@ void* nsNPAPIPluginInstance::AcquireCont
 {
   if (!mContentSurface) {
     mContentSurface = CreateSurfaceTexture();
 
     if (!mContentSurface)
       return nullptr;
   }
 
-  return mContentSurface->NativeWindow()->Handle();
+  return mContentSurface->NativeWindow();
 }
 
 AndroidSurfaceTexture*
 nsNPAPIPluginInstance::AsSurfaceTexture()
 {
   if (!mContentSurface)
     return nullptr;
 
@@ -929,17 +929,17 @@ void* nsNPAPIPluginInstance::AcquireVide
 {
   RefPtr<AndroidSurfaceTexture> surface = CreateSurfaceTexture();
   if (!surface) {
     return nullptr;
   }
 
   VideoInfo* info = new VideoInfo(surface);
 
-  void* window = info->mSurfaceTexture->NativeWindow()->Handle();
+  void* window = info->mSurfaceTexture->NativeWindow();
   mVideos.insert(std::pair<void*, VideoInfo*>(window, info));
 
   return window;
 }
 
 void nsNPAPIPluginInstance::ReleaseVideoWindow(void* window)
 {
   std::map<void*, VideoInfo*>::iterator it = mVideos.find(window);
deleted file mode 100644
--- a/gfx/gl/AndroidNativeWindow.cpp
+++ /dev/null
@@ -1,281 +0,0 @@
-#ifdef MOZ_WIDGET_ANDROID
-
-#include "AndroidNativeWindow.h"
-#include "prlink.h"
-
-// #define ANDROID_NATIVE_WINDOW_DEBUG
-
-#if defined(ANDROID_NATIVE_WINDOW_DEBUG) || defined(DEBUG)
-#define ALOG(args...)  __android_log_print(ANDROID_LOG_INFO, "AndroidNativeWindow" , ## args)
-#else
-#define ALOG(args...) ((void)0)
-#endif
-
-using namespace mozilla::gfx;
-using namespace mozilla::gl;
-using namespace mozilla;
-
-class NativeWindowLibrary
-{
-public:
-
-  NativeWindowLibrary()
-    : fANativeWindow_fromSurface(nullptr)
-    , fANativeWindow_release(nullptr)
-    , fANativeWindow_setBuffersGeometry(nullptr)
-    , fANativeWindow_lock(nullptr)
-    , fANativeWindow_unlockAndPost(nullptr)
-    , fANativeWindow_getFormat(nullptr)
-    , fANativeWindow_getWidth(nullptr)
-    , fANativeWindow_getHeight(nullptr)
-  {
-    PRLibrary* lib = PR_LoadLibrary("libandroid.so");
-
-    fANativeWindow_fromSurface = (pfnANativeWindow_fromSurface)PR_FindSymbol(lib, "ANativeWindow_fromSurface");
-    fANativeWindow_release = (pfnANativeWindow_release)PR_FindSymbol(lib, "ANativeWindow_release");
-    fANativeWindow_setBuffersGeometry = (pfnANativeWindow_setBuffersGeometry)PR_FindSymbol(lib, "ANativeWindow_setBuffersGeometry");
-    fANativeWindow_lock = (pfnANativeWindow_lock)PR_FindSymbol(lib, "ANativeWindow_lock");
-    fANativeWindow_unlockAndPost = (pfnANativeWindow_unlockAndPost)PR_FindSymbol(lib, "ANativeWindow_unlockAndPost");
-    fANativeWindow_getFormat = (pfnANativeWindow_getFormat)PR_FindSymbol(lib, "ANativeWindow_getFormat");
-    fANativeWindow_getWidth = (pfnANativeWindow_getWidth)PR_FindSymbol(lib, "ANativeWindow_getWidth");
-    fANativeWindow_getHeight = (pfnANativeWindow_getHeight)PR_FindSymbol(lib, "ANativeWindow_getHeight");
-  }
-
-  void* ANativeWindow_fromSurface(JNIEnv* aEnv, jobject aSurface) {
-    ALOG("%s: env=%p, surface=%p\n", __PRETTY_FUNCTION__, aEnv, aSurface);
-    if (!Initialized()) {
-      return nullptr;
-    }
-
-    return fANativeWindow_fromSurface(aEnv, aSurface);
-  }
-
-  void ANativeWindow_release(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return;
-    }
-
-    fANativeWindow_release(aWindow);
-  }
-
-  bool ANativeWindow_setBuffersGeometry(void* aWindow, int32_t aWidth, int32_t aHeight, int32_t aFormat) {
-    ALOG("%s: window=%p, width=%d, height=%d, format=%d\n", __PRETTY_FUNCTION__, aWindow, aWidth, aHeight, aFormat);
-    if (!Initialized()) {
-      return false;
-    }
-
-    return fANativeWindow_setBuffersGeometry(aWindow, aWidth, aHeight, (int32_t)aFormat) == 0;
-  }
-
-  bool ANativeWindow_lock(void* aWindow, void* out_buffer, void*in_out_dirtyBounds) {
-    ALOG("%s: window=%p, out_buffer=%p, in_out_dirtyBounds=%p\n", __PRETTY_FUNCTION__,
-         aWindow, out_buffer, in_out_dirtyBounds);
-    if (!Initialized()) {
-      return false;
-    }
-
-    return fANativeWindow_lock(aWindow, out_buffer, in_out_dirtyBounds) == 0;
-  }
-
-  bool ANativeWindow_unlockAndPost(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return false;
-    }
-
-    return fANativeWindow_unlockAndPost(aWindow) == 0;
-  }
-
-  AndroidWindowFormat ANativeWindow_getFormat(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return AndroidWindowFormat::Unknown;
-    }
-
-    return (AndroidWindowFormat)fANativeWindow_getFormat(aWindow);
-  }
-
-  int32_t ANativeWindow_getWidth(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return -1;
-    }
-
-    return fANativeWindow_getWidth(aWindow);
-  }
-
-  int32_t ANativeWindow_getHeight(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return -1;
-    }
-
-    return fANativeWindow_getHeight(aWindow);
-  }
-
-  bool Initialized() {
-    return fANativeWindow_fromSurface && fANativeWindow_release && fANativeWindow_setBuffersGeometry
-      && fANativeWindow_lock && fANativeWindow_unlockAndPost && fANativeWindow_getFormat && fANativeWindow_getWidth
-      && fANativeWindow_getHeight;
-  }
-
-private:
-
-  typedef void* (*pfnANativeWindow_fromSurface)(JNIEnv* env, jobject surface);
-  pfnANativeWindow_fromSurface fANativeWindow_fromSurface;
-
-  typedef void (*pfnANativeWindow_release)(void* window);
-  pfnANativeWindow_release fANativeWindow_release;
-
-  typedef int32_t (*pfnANativeWindow_setBuffersGeometry)(void* window, int32_t width, int32_t height, int32_t format);
-  pfnANativeWindow_setBuffersGeometry fANativeWindow_setBuffersGeometry;
-
-  typedef int32_t (*pfnANativeWindow_lock)(void* window, void* out_buffer, void* in_out_dirtyBounds);
-  pfnANativeWindow_lock fANativeWindow_lock;
-
-  typedef int32_t (*pfnANativeWindow_unlockAndPost)(void* window);
-  pfnANativeWindow_unlockAndPost fANativeWindow_unlockAndPost;
-
-  typedef AndroidWindowFormat (*pfnANativeWindow_getFormat)(void* window);
-  pfnANativeWindow_getFormat fANativeWindow_getFormat;
-
-  typedef int32_t (*pfnANativeWindow_getWidth)(void* window);
-  pfnANativeWindow_getWidth fANativeWindow_getWidth;
-
-  typedef int32_t (*pfnANativeWindow_getHeight)(void* window);
-  pfnANativeWindow_getHeight fANativeWindow_getHeight;
-};
-
-static NativeWindowLibrary* sLibrary = nullptr;
-
-static bool
-EnsureInit()
-{
-  static bool initialized = false;
-  if (!initialized) {
-    if (!sLibrary) {
-      sLibrary = new NativeWindowLibrary();
-    }
-    initialized = sLibrary->Initialized();
-  }
-
-  return initialized;
-}
-
-
-namespace mozilla {
-
-/* static */ AndroidNativeWindow*
-AndroidNativeWindow::CreateFromSurface(JNIEnv* aEnv, jobject aSurface)
-{
-  if (!EnsureInit()) {
-    ALOG("Not initialized");
-    return nullptr;
-  }
-
-  void* window = sLibrary->ANativeWindow_fromSurface(aEnv, aSurface);
-  if (!window) {
-    ALOG("Failed to create window from surface");
-    return nullptr;
-  }
-
-  return new AndroidNativeWindow(window);
-}
-
-AndroidNativeWindow::~AndroidNativeWindow()
-{
-  if (EnsureInit() && mWindow) {
-    sLibrary->ANativeWindow_release(mWindow);
-    mWindow = nullptr;
-  }
-}
-
-IntSize
-AndroidNativeWindow::Size()
-{
-  MOZ_ASSERT(mWindow);
-  if (!EnsureInit()) {
-    return IntSize(0, 0);
-  }
-
-  return IntSize(sLibrary->ANativeWindow_getWidth(mWindow), sLibrary->ANativeWindow_getHeight(mWindow));
-}
-
-AndroidWindowFormat
-AndroidNativeWindow::Format()
-{
-  MOZ_ASSERT(mWindow);
-  if (!EnsureInit()) {
-    return AndroidWindowFormat::Unknown;
-  }
-
-  return sLibrary->ANativeWindow_getFormat(mWindow);
-}
-
-bool
-AndroidNativeWindow::SetBuffersGeometry(int32_t aWidth, int32_t aHeight, AndroidWindowFormat aFormat)
-{
-  MOZ_ASSERT(mWindow);
-  if (!EnsureInit())
-    return false;
-
-  return sLibrary->ANativeWindow_setBuffersGeometry(mWindow, aWidth, aHeight, (int32_t)aFormat);
-}
-
-bool
-AndroidNativeWindow::Lock(void** out_bits,int32_t* out_width, int32_t* out_height,
-                          int32_t* out_stride, AndroidWindowFormat* out_format)
-{
-  /* 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;
-
-
-  ANativeWindow_Buffer buffer;
-
-  if (!sLibrary->ANativeWindow_lock(mWindow, &buffer, nullptr)) {
-    ALOG("Failed to lock");
-    return false;
-  }
-
-  *out_bits = buffer.bits;
-  *out_width = buffer.width;
-  *out_height = buffer.height;
-  *out_stride = buffer.stride;
-  *out_format = (AndroidWindowFormat)buffer.format;
-  return true;
-}
-
-bool
-AndroidNativeWindow::UnlockAndPost()
-{
-  if (!EnsureInit()) {
-    ALOG("Not initialized");
-    return false;
-  }
-
-  return sLibrary->ANativeWindow_unlockAndPost(mWindow);
-}
-
-}
-
-#endif // MOZ_WIDGET_ANDROID
deleted file mode 100644
--- a/gfx/gl/AndroidNativeWindow.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-// vim:set ts=2 sts=2 sw=2 et cin:
-/* 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/. */
-
-#ifndef AndroidNativeWindow_h__
-#define AndroidNativeWindow_h__
-#ifdef MOZ_WIDGET_ANDROID
-
-#include <jni.h>
-#include "GLDefs.h"
-
-#include "nsISupports.h"
-#include "mozilla/gfx/2D.h"
-
-
-namespace mozilla {
-namespace gl {
-
-enum class AndroidWindowFormat {
-  Unknown = -1,
-  RGBA_8888 = 1,
-  RGBX_8888 = 1 << 1,
-  RGB_565 = 1 << 2
-};
-
-/**
- * This class is a wrapper around Android's SurfaceTexture class.
- * Usage is pretty much exactly like the Java class, so see
- * the Android documentation for details.
- */
-class AndroidNativeWindow {
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidNativeWindow)
-
-public:
-
-  static AndroidNativeWindow* CreateFromSurface(JNIEnv* aEnv, jobject aSurface);
-
-  gfx::IntSize Size();
-  AndroidWindowFormat Format();
-
-  bool SetBuffersGeometry(int32_t aWidth, int32_t aHeight, AndroidWindowFormat aFormat);
-
-  bool Lock(void** out_bits, int32_t* out_width, int32_t* out_height, int32_t* out_stride, AndroidWindowFormat* out_format);
-  bool UnlockAndPost();
-
-  void* Handle() { return mWindow; }
-
-protected:
-  AndroidNativeWindow(void* aWindow)
-    : mWindow(aWindow)
-  {
-
-  }
-
-  virtual ~AndroidNativeWindow();
-
-  void* mWindow;
-};
-
-}
-}
-
-
-#endif
-#endif
--- a/gfx/gl/AndroidSurfaceTexture.cpp
+++ b/gfx/gl/AndroidSurfaceTexture.cpp
@@ -2,16 +2,17 @@
 // vim:set ts=2 sts=2 sw=2 et cin:
 /* 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/. */
 
 #ifdef MOZ_WIDGET_ANDROID
 
 #include <map>
+#include <android/native_window_jni.h>
 #include <android/log.h>
 #include "AndroidSurfaceTexture.h"
 #include "gfxImageSurface.h"
 #include "gfxPrefs.h"
 #include "AndroidBridge.h"
 #include "nsThreadUtils.h"
 #include "mozilla/gfx/Matrix.h"
 #include "GeneratedJNIWrappers.h"
@@ -194,18 +195,18 @@ AndroidSurfaceTexture::Init(GLContext* a
 
   mAttachedContext = aContext;
 
   if (NS_WARN_IF(NS_FAILED(
       Surface::New(mSurfaceTexture, ReturnTo(&mSurface))))) {
     return false;
   }
 
-  mNativeWindow = AndroidNativeWindow::CreateFromSurface(jni::GetEnvForThread(),
-                                                         mSurface.Get());
+  mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(),
+                                            mSurface.Get());
   MOZ_ASSERT(mNativeWindow, "Failed to create native window from surface");
 
   mID = sInstances.Add(this);
 
   return true;
 }
 
 AndroidSurfaceTexture::AndroidSurfaceTexture()
@@ -222,16 +223,21 @@ AndroidSurfaceTexture::~AndroidSurfaceTe
   sInstances.Remove(mID);
 
   mFrameAvailableCallback = nullptr;
 
   if (mSurfaceTexture) {
     GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
     mSurfaceTexture = nullptr;
   }
+
+  if (mNativeWindow) {
+    ANativeWindow_release(mNativeWindow);
+    mNativeWindow = nullptr;
+  }
 }
 
 void
 AndroidSurfaceTexture::UpdateTexImage()
 {
   mSurfaceTexture->UpdateTexImage();
 }
 
--- a/gfx/gl/AndroidSurfaceTexture.h
+++ b/gfx/gl/AndroidSurfaceTexture.h
@@ -4,25 +4,25 @@
  * 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/. */
 
 #ifndef AndroidSurfaceTexture_h__
 #define AndroidSurfaceTexture_h__
 #ifdef MOZ_WIDGET_ANDROID
 
 #include <jni.h>
+#include <android/native_window.h>
 #include "nsIRunnable.h"
 #include "gfxPlatform.h"
 #include "GLDefs.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/MatrixFwd.h"
 #include "mozilla/Monitor.h"
 
 #include "SurfaceTexture.h"
-#include "AndroidNativeWindow.h"
 
 namespace mozilla {
 namespace gl {
 
 class GLContext;
 
 /**
  * This class is a wrapper around Android's SurfaceTexture class.
@@ -57,17 +57,17 @@ public:
   nsresult Detach();
 
   // Ability to detach is based on API version (16+), and we also block PowerVR
   // since it has some type of fencing problem. Bug 1100126.
   bool CanDetach() const;
 
   GLContext* AttachedContext() const { return mAttachedContext; }
 
-  AndroidNativeWindow* NativeWindow() const {
+  ANativeWindow* NativeWindow() const {
     return mNativeWindow;
   }
 
   // This attaches the updated data to the TEXTURE_EXTERNAL target
   void UpdateTexImage();
 
   void GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix) const;
   int ID() const { return mID; }
@@ -92,17 +92,17 @@ private:
   bool Init(GLContext* aContext, GLuint aTexture);
 
   GLuint mTexture;
   java::sdk::SurfaceTexture::GlobalRef mSurfaceTexture;
   java::sdk::Surface::GlobalRef mSurface;
 
   GLContext* mAttachedContext;
 
-  RefPtr<AndroidNativeWindow> mNativeWindow;
+  ANativeWindow* mNativeWindow;
   int mID;
   nsCOMPtr<nsIRunnable> mFrameAvailableCallback;
 
   mutable Monitor mMonitor;
 };
 
 }
 }
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -21,17 +21,16 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'an
     gl_provider = 'EGL'
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     gl_provider = 'EGL'
 
 if CONFIG['MOZ_GL_PROVIDER']:
     gl_provider = CONFIG['MOZ_GL_PROVIDER']
 
 EXPORTS += [
-    'AndroidNativeWindow.h',
     'AndroidSurfaceTexture.h',
     'DecomposeIntoNoRepeatTriangles.h',
     'EGLUtils.h',
     'ForceDiscreteGPUHelperCGL.h',
     'GfxTexturesReporter.h',
     'GLBlitHelper.h',
     'GLConsts.h',
     'GLContext.h',
@@ -124,17 +123,16 @@ elif gl_provider == 'GLX':
         'GLContextProviderGLX.cpp',
         'SharedSurfaceGLX.cpp'
     ]
     EXPORTS += [
         'SharedSurfaceGLX.h'
     ]
 
 UNIFIED_SOURCES += [
-    'AndroidNativeWindow.cpp',
     'AndroidSurfaceTexture.cpp',
     'DecomposeIntoNoRepeatTriangles.cpp',
     'EGLUtils.cpp',
     'GfxTexturesReporter.cpp',
     'GLBlitHelper.cpp',
     'GLContext.cpp',
     'GLContextFeatures.cpp',
     'GLContextProviderEGL.cpp',