diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 83f32a0f6e40..588d07a58db5 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -1640,7 +1640,8 @@ MediaDecoder::IsWebMEnabled() bool MediaDecoder::IsAndroidMediaPluginEnabled() { - return jni::GetAPIVersion() < 16 + return AndroidBridge::Bridge() + && AndroidBridge::Bridge()->GetAPIVersion() < 16 && Preferences::GetBool("media.plugins.enabled"); } #endif diff --git a/dom/media/MediaPrefs.h b/dom/media/MediaPrefs.h index 196746710904..d86082e331be 100644 --- a/dom/media/MediaPrefs.h +++ b/dom/media/MediaPrefs.h @@ -7,7 +7,7 @@ #define MEDIA_PREFS_H #ifdef MOZ_WIDGET_ANDROID -#include "GeneratedJNIWrappers.h" +#include "AndroidBridge.h" #endif #include "mozilla/Atomics.h" @@ -199,7 +199,8 @@ private: static int32_t MediaDecoderLimitDefault() { #ifdef MOZ_WIDGET_ANDROID - if (jni::GetAPIVersion() < 18) { + if (AndroidBridge::Bridge() && + AndroidBridge::Bridge()->GetAPIVersion() < 18) { // Older Android versions have broken support for multiple simultaneous // decoders, see bug 1278574. return 1; diff --git a/dom/media/platforms/android/AndroidDecoderModule.cpp b/dom/media/platforms/android/AndroidDecoderModule.cpp index 3ea51005704b..673a94b16c7b 100644 --- a/dom/media/platforms/android/AndroidDecoderModule.cpp +++ b/dom/media/platforms/android/AndroidDecoderModule.cpp @@ -2,7 +2,8 @@ * 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 "GeneratedJNIWrappers.h" +#include "AndroidDecoderModule.h" +#include "AndroidBridge.h" #include "MediaInfo.h" #include "MediaPrefs.h" #include "OpusDecoder.h" @@ -127,7 +128,8 @@ AndroidDecoderModule::SupportsMimeType( const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const { - if (jni::GetAPIVersion() < 16) { + if (!AndroidBridge::Bridge() || + AndroidBridge::Bridge()->GetAPIVersion() < 16) { return false; } diff --git a/dom/media/platforms/android/RemoteDataDecoder.cpp b/dom/media/platforms/android/RemoteDataDecoder.cpp index dd075e7459c3..0149e2262f98 100644 --- a/dom/media/platforms/android/RemoteDataDecoder.cpp +++ b/dom/media/platforms/android/RemoteDataDecoder.cpp @@ -4,6 +4,7 @@ #include "AndroidBridge.h" #include "AndroidDecoderModule.h" +#include "AndroidSurfaceTexture.h" #include "JavaCallbacksSupport.h" #include "SimpleMap.h" #include "GLImages.h" @@ -133,7 +134,7 @@ public: if (size > 0) { RefPtr img = new SurfaceTextureImage( - mDecoder->mSurfaceHandle, inputInfo.mImageSize, false /* NOT continuous */, + mDecoder->mSurfaceTexture.get(), inputInfo.mImageSize, gl::OriginPos::BottomLeft); RefPtr v = VideoData::CreateFromImage( @@ -176,12 +177,18 @@ public: RefPtr Init() override { - jni::Object::LocalRef surf = SurfaceAllocator::AcquireSurface(mConfig.mImage.width, mConfig.mImage.height, false); - if (!surf) { - return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__); + mSurfaceTexture = AndroidSurfaceTexture::Create(); + if (!mSurfaceTexture) { + NS_WARNING("Failed to create SurfaceTexture for video decode\n"); + return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR, + __func__); } - mSurfaceHandle = GeckoSurface::LocalRef(GeckoSurface::Ref::From(surf))->GetHandle(); + if (!jni::IsFennec()) { + NS_WARNING("Remote decoding not supported in non-Fennec environment\n"); + return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR, + __func__); + } // Register native methods. JavaCallbacksSupport::Init(); @@ -190,10 +197,9 @@ public: JavaCallbacksSupport::AttachNative( mJavaCallbacks, mozilla::MakeUnique(this)); - auto surfRef = Surface::LocalRef(Surface::Ref::From(surf)); mJavaDecoder = CodecProxy::Create(false, // false indicates to create a decoder and true denotes encoder mFormat, - surfRef, + mSurfaceTexture->JavaSurface(), mJavaCallbacks, mDrmStubId); if (mJavaDecoder == nullptr) { @@ -233,7 +239,7 @@ public: private: layers::ImageContainer* mImageContainer; const VideoInfo mConfig; - AndroidSurfaceTextureHandle mSurfaceHandle; + RefPtr mSurfaceTexture; SimpleMap mInputInfos; bool mIsCodecSupportAdaptivePlayback = false; }; @@ -405,6 +411,7 @@ RemoteDataDecoder::CreateVideoDecoder(const CreateDecoderParams& aParams, const nsString& aDrmStubId, CDMProxy* aProxy) { + const VideoInfo& config = aParams.VideoConfig(); MediaFormat::LocalRef format; NS_ENSURE_SUCCESS( diff --git a/dom/plugins/base/nsNPAPIPluginInstance.cpp b/dom/plugins/base/nsNPAPIPluginInstance.cpp index 00223651cb9d..07abc9ed6beb 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.cpp +++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp @@ -58,8 +58,6 @@ using namespace mozilla::dom; #include "TexturePoolOGL.h" #include "SurfaceTypes.h" #include "EGLUtils.h" -#include "GeneratedJNIWrappers.h" -#include "GeneratedJNINatives.h" using namespace mozilla; using namespace mozilla::gl; @@ -108,7 +106,7 @@ static bool EnsureGLContext() static std::map sPluginNPPMap; -#endif // MOZ_WIDGET_ANDROID +#endif using namespace mozilla; using namespace mozilla::plugins::parent; @@ -204,12 +202,14 @@ nsNPAPIPluginInstance::Destroy() mAudioChannelAgent = nullptr; #if MOZ_WIDGET_ANDROID - if (mContentSurface) { - java::SurfaceAllocator::DisposeSurface(mContentSurface); - } + if (mContentSurface) + mContentSurface->SetFrameAvailableCallback(nullptr); + + mContentSurface = nullptr; std::map::iterator it; for (it = mVideos.begin(); it != mVideos.end(); it++) { + it->second->mSurfaceTexture->SetFrameAvailableCallback(nullptr); delete it->second; } mVideos.clear(); @@ -858,50 +858,24 @@ GLContext* nsNPAPIPluginInstance::GLContext() return sPluginContext; } -class PluginTextureListener - : public java::SurfaceTextureListener::Natives +already_AddRefed nsNPAPIPluginInstance::CreateSurfaceTexture() { - using Base = java::SurfaceTextureListener::Natives; + if (!EnsureGLContext()) + return nullptr; - const nsCOMPtr mCallback; -public: - using Base::AttachNative; - using Base::DisposeNative; + GLuint texture = TexturePoolOGL::AcquireTexture(); + if (!texture) + return nullptr; - PluginTextureListener(nsIRunnable* aCallback) : mCallback(aCallback) {} - - void OnFrameAvailable() - { - if (NS_IsMainThread()) { - mCallback->Run(); - return; - } - NS_DispatchToMainThread(mCallback); - } -}; - -java::GeckoSurface::LocalRef nsNPAPIPluginInstance::CreateSurface() -{ - java::GeckoSurface::LocalRef surf = java::SurfaceAllocator::AcquireSurface(0, 0, false); - if (!surf) { + RefPtr surface = AndroidSurfaceTexture::Create(TexturePoolOGL::GetGLContext(), + texture); + if (!surface) { return nullptr; } nsCOMPtr frameCallback = NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable); - - java::SurfaceTextureListener::LocalRef listener = java::SurfaceTextureListener::New(); - - PluginTextureListener::AttachNative(listener, MakeUnique(frameCallback.get())); - - java::GeckoSurfaceTexture::LocalRef gst = java::GeckoSurfaceTexture::Lookup(surf->GetHandle()); - if (!gst) { - return nullptr; - } - - const auto& st = java::sdk::SurfaceTexture::Ref::From(gst); - st->SetOnFrameAvailableListener(listener); - - return surf; + surface->SetFrameAvailableCallback(frameCallback); + return surface.forget(); } void nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable() @@ -912,29 +886,35 @@ void nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable() void* nsNPAPIPluginInstance::AcquireContentWindow() { - if (!mContentWindow.NativeWindow()) { - mContentSurface = CreateSurface(); + if (!mContentSurface) { + mContentSurface = CreateSurfaceTexture(); + if (!mContentSurface) return nullptr; - - mContentWindow = AndroidNativeWindow(mContentSurface); } - return mContentWindow.NativeWindow(); + return mContentSurface->NativeWindow(); } -java::GeckoSurface::Param -nsNPAPIPluginInstance::AsSurface() +AndroidSurfaceTexture* +nsNPAPIPluginInstance::AsSurfaceTexture() { + if (!mContentSurface) + return nullptr; + return mContentSurface; } void* nsNPAPIPluginInstance::AcquireVideoWindow() { - java::GeckoSurface::LocalRef surface = CreateSurface(); + RefPtr surface = CreateSurfaceTexture(); + if (!surface) { + return nullptr; + } + VideoInfo* info = new VideoInfo(surface); - void* window = info->mNativeWindow.NativeWindow(); + void* window = info->mSurfaceTexture->NativeWindow(); mVideos.insert(std::pair(window, info)); return window; diff --git a/dom/plugins/base/nsNPAPIPluginInstance.h b/dom/plugins/base/nsNPAPIPluginInstance.h index 9a5df2e9322c..777469f895ee 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.h +++ b/dom/plugins/base/nsNPAPIPluginInstance.h @@ -21,7 +21,7 @@ #ifdef MOZ_WIDGET_ANDROID #include "nsIRunnable.h" #include "GLContextTypes.h" -#include "AndroidNativeWindow.h" +#include "AndroidSurfaceTexture.h" #include "AndroidBridge.h" #include class PluginEventRunnable; @@ -215,24 +215,22 @@ public: // For ANPNativeWindow void* AcquireContentWindow(); - mozilla::java::GeckoSurface::Param AsSurface(); + mozilla::gl::AndroidSurfaceTexture* AsSurfaceTexture(); // For ANPVideo class VideoInfo { public: - VideoInfo(mozilla::java::GeckoSurface::Param aSurface) - : mSurface(aSurface) - , mNativeWindow(aSurface) + VideoInfo(mozilla::gl::AndroidSurfaceTexture* aSurfaceTexture) : + mSurfaceTexture(aSurfaceTexture) { } ~VideoInfo() { - mozilla::java::SurfaceAllocator::DisposeSurface(mSurface); + mSurfaceTexture = nullptr; } - mozilla::java::GeckoSurface::GlobalRef mSurface; - mozilla::gl::AndroidNativeWindow mNativeWindow; + RefPtr mSurfaceTexture; gfxRect mDimensions; }; @@ -361,8 +359,7 @@ protected: bool mFullScreen; mozilla::gl::OriginPos mOriginPos; - mozilla::java::GeckoSurface::GlobalRef mContentSurface; - mozilla::gl::AndroidNativeWindow mContentWindow; + RefPtr mContentSurface; #endif enum { @@ -412,7 +409,8 @@ private: mozilla::TimeStamp mStopTime; #ifdef MOZ_WIDGET_ANDROID - mozilla::java::GeckoSurface::LocalRef CreateSurface(); + already_AddRefed CreateSurfaceTexture(); + std::map mVideos; bool mOnScreen; diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index 267d7fe93005..ac10539aecc1 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -165,23 +165,22 @@ nsPluginInstanceOwner::NotifyPaintWaiter(nsDisplayListBuilder* aBuilder) #if MOZ_WIDGET_ANDROID static void -AttachToContainerAsSurface(ImageContainer* container, - nsNPAPIPluginInstance* instance, - const LayoutDeviceRect& rect, - RefPtr* out_image) +AttachToContainerAsSurfaceTexture(ImageContainer* container, + nsNPAPIPluginInstance* instance, + const LayoutDeviceRect& rect, + RefPtr* out_image) { MOZ_ASSERT(out_image); MOZ_ASSERT(!*out_image); - java::GeckoSurface::LocalRef surface = instance->AsSurface(); - if (!surface) { + mozilla::gl::AndroidSurfaceTexture* surfTex = instance->AsSurfaceTexture(); + if (!surfTex) { return; } RefPtr img = new SurfaceTextureImage( - surface->GetHandle(), + surfTex, gfx::IntSize::Truncate(rect.width, rect.height), - true, // continuously update without a transaction instance->OriginPos()); *out_image = img; } @@ -224,7 +223,7 @@ nsPluginInstanceOwner::GetImageContainer() if (r.width && r.height) { // Try to get it as an EGLImage first. RefPtr img; - AttachToContainerAsSurface(container, mInstance, r, &img); + AttachToContainerAsSurfaceTexture(container, mInstance, r, &img); if (img) { container->SetCurrentImageInTransaction(img); @@ -1586,9 +1585,8 @@ nsPluginInstanceOwner::GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInf if (aVideoInfo->mDimensions.width && aVideoInfo->mDimensions.height) { RefPtr img = new SurfaceTextureImage( - aVideoInfo->mSurface->GetHandle(), + aVideoInfo->mSurfaceTexture, gfx::IntSize::Truncate(aVideoInfo->mDimensions.width, aVideoInfo->mDimensions.height), - true, /* continuous */ gl::OriginPos::BottomLeft); container->SetCurrentImageInTransaction(img); } diff --git a/gfx/gl/AndroidNativeWindow.h b/gfx/gl/AndroidNativeWindow.h deleted file mode 100644 index b55c8a0c9bcc..000000000000 --- a/gfx/gl/AndroidNativeWindow.h +++ /dev/null @@ -1,55 +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 -#include -#include -#include "GeneratedJNIWrappers.h" -#include "SurfaceTexture.h" - -namespace mozilla { -namespace gl { - -class AndroidNativeWindow { -public: - AndroidNativeWindow() : mNativeWindow(nullptr) { - } - - AndroidNativeWindow(java::sdk::Surface::Param aSurface) { - mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(), - aSurface.Get()); - } - - AndroidNativeWindow(java::GeckoSurface::Param aSurface) { - auto surf = java::sdk::Surface::LocalRef(java::sdk::Surface::Ref::From(aSurface)); - mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(), - surf.Get()); - } - - ~AndroidNativeWindow() { - if (mNativeWindow) { - ANativeWindow_release(mNativeWindow); - mNativeWindow = nullptr; - } - } - - ANativeWindow* NativeWindow() const { - return mNativeWindow; - } - -private: - ANativeWindow* mNativeWindow; -}; - -} // gl -} // mozilla - -#endif // MOZ_WIDGET_ANDROID -#endif // AndroidNativeWindow_h__ diff --git a/gfx/gl/AndroidSurfaceTexture.cpp b/gfx/gl/AndroidSurfaceTexture.cpp index 107da39455d0..3c8c81974a5c 100644 --- a/gfx/gl/AndroidSurfaceTexture.cpp +++ b/gfx/gl/AndroidSurfaceTexture.cpp @@ -1,20 +1,204 @@ +/* -*- 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/. */ + #ifdef MOZ_WIDGET_ANDROID +#include +#include +#include #include "AndroidSurfaceTexture.h" +#include "gfxImageSurface.h" +#include "gfxPrefs.h" +#include "AndroidBridge.h" +#include "nsThreadUtils.h" +#include "mozilla/gfx/Matrix.h" +#include "GeneratedJNINatives.h" +#include "GLContext.h" using namespace mozilla; namespace mozilla { namespace gl { +class AndroidSurfaceTexture::Listener + : public java::SurfaceTextureListener::Natives +{ + using Base = java::SurfaceTextureListener::Natives; + + const nsCOMPtr mCallback; + +public: + using Base::AttachNative; + using Base::DisposeNative; + + Listener(nsIRunnable* aCallback) : mCallback(aCallback) {} + + void OnFrameAvailable() + { + if (NS_IsMainThread()) { + mCallback->Run(); + return; + } + NS_DispatchToMainThread(mCallback); + } +}; + +already_AddRefed +AndroidSurfaceTexture::Create() +{ + return Create(nullptr, 0); +} + +already_AddRefed +AndroidSurfaceTexture::Create(GLContext* aContext, GLuint aTexture) +{ + RefPtr st = new AndroidSurfaceTexture(); + if (!st->Init(aContext, aTexture)) { + printf_stderr("Failed to initialize AndroidSurfaceTexture"); + st = nullptr; + } + + return st.forget(); +} + +nsresult +AndroidSurfaceTexture::Attach(GLContext* aContext, PRIntervalTime aTimeout) +{ + MonitorAutoLock lock(mMonitor); + + if (mAttachedContext == aContext) { + NS_WARNING("Tried to attach same GLContext to AndroidSurfaceTexture"); + return NS_OK; + } + + if (!CanDetach()) { + return NS_ERROR_NOT_AVAILABLE; + } + + while (mAttachedContext) { + // Wait until it's detached (or we time out) + if (NS_FAILED(lock.Wait(aTimeout))) { + return NS_ERROR_NOT_AVAILABLE; + } + } + + MOZ_ASSERT(aContext->IsOwningThreadCurrent(), "Trying to attach GLContext from different thread"); + + aContext->fGenTextures(1, &mTexture); + + if (NS_FAILED(mSurfaceTexture->AttachToGLContext(mTexture))) { + return NS_ERROR_NOT_AVAILABLE; + } + mAttachedContext = aContext; + mAttachedContext->MakeCurrent(); + + return NS_OK; +} + +nsresult +AndroidSurfaceTexture::Detach() +{ + MonitorAutoLock lock(mMonitor); + + if (!CanDetach() || + !mAttachedContext || + !mAttachedContext->IsOwningThreadCurrent()) + { + return NS_ERROR_FAILURE; + } + + mAttachedContext->MakeCurrent(); + + mSurfaceTexture->DetachFromGLContext(); + + mTexture = 0; + mAttachedContext = nullptr; + lock.NotifyAll(); + return NS_OK; +} + +bool +AndroidSurfaceTexture::CanDetach() const +{ + // The API for attach/detach only exists on 16+, and PowerVR has some sort of + // fencing issue. Additionally, attach/detach seems to be busted on at least + // some Mali adapters (400MP2 for sure, bug 1131793) + return AndroidBridge::Bridge()->GetAPIVersion() >= 16 && + (!mAttachedContext || mAttachedContext->Vendor() != GLVendor::Imagination) && + (!mAttachedContext || mAttachedContext->Vendor() != GLVendor::ARM /* Mali */) && + gfxPrefs::SurfaceTextureDetachEnabled(); +} + +bool +AndroidSurfaceTexture::Init(GLContext* aContext, GLuint aTexture) +{ + + if (!aTexture && !CanDetach()) { + // We have no texture and cannot initialize detached, bail out + return false; + } + + if (NS_WARN_IF(NS_FAILED( + java::sdk::SurfaceTexture::New(aTexture, ReturnTo(&mSurfaceTexture))))) { + return false; + } + + if (!aTexture) { + mSurfaceTexture->DetachFromGLContext(); + } + + mAttachedContext = aContext; + + if (NS_WARN_IF(NS_FAILED( + java::sdk::Surface::New(mSurfaceTexture, ReturnTo(&mSurface))))) { + return false; + } + + mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(), + mSurface.Get()); + MOZ_ASSERT(mNativeWindow, "Failed to create native window from surface"); + + return true; +} + +AndroidSurfaceTexture::AndroidSurfaceTexture() + : mTexture(0) + , mSurfaceTexture() + , mSurface() + , mAttachedContext(nullptr) + , mMonitor("AndroidSurfaceTexture") +{ +} + +AndroidSurfaceTexture::~AndroidSurfaceTexture() +{ + if (mSurfaceTexture) { + SetFrameAvailableCallback(nullptr); + mSurfaceTexture = nullptr; + } + + if (mNativeWindow) { + ANativeWindow_release(mNativeWindow); + mNativeWindow = nullptr; + } +} + void -AndroidSurfaceTexture::GetTransformMatrix(java::sdk::SurfaceTexture::LocalRef aSurfaceTexture, - gfx::Matrix4x4& aMatrix) +AndroidSurfaceTexture::UpdateTexImage() +{ + mSurfaceTexture->UpdateTexImage(); +} + +void +AndroidSurfaceTexture::GetTransformMatrix(gfx::Matrix4x4& aMatrix) const { JNIEnv* const env = jni::GetEnvForThread(); auto jarray = jni::FloatArray::LocalRef::Adopt(env, env->NewFloatArray(16)); - aSurfaceTexture->GetTransformMatrix(jarray); + mSurfaceTexture->GetTransformMatrix(jarray); jfloat* array = env->GetFloatArrayElements(jarray.Get(), nullptr); @@ -41,6 +225,36 @@ AndroidSurfaceTexture::GetTransformMatrix(java::sdk::SurfaceTexture::LocalRef aS env->ReleaseFloatArrayElements(jarray.Get(), array, 0); } +void +AndroidSurfaceTexture::SetFrameAvailableCallback(nsIRunnable* aRunnable) +{ + java::SurfaceTextureListener::LocalRef newListener; + + if (aRunnable) { + newListener = java::SurfaceTextureListener::New(); + Listener::AttachNative(newListener, MakeUnique(aRunnable)); + } + + if (aRunnable || mListener) { + MOZ_ALWAYS_TRUE(NS_SUCCEEDED( + mSurfaceTexture->SetOnFrameAvailableListener(newListener))); + } + + if (mListener) { + Listener::DisposeNative(java::SurfaceTextureListener::LocalRef( + newListener.Env(), mListener)); + } + + mListener = newListener; +} + +void +AndroidSurfaceTexture::SetDefaultSize(mozilla::gfx::IntSize size) +{ + mSurfaceTexture->SetDefaultBufferSize(size.width, size.height); +} + } // gl } // mozilla + #endif // MOZ_WIDGET_ANDROID diff --git a/gfx/gl/AndroidSurfaceTexture.h b/gfx/gl/AndroidSurfaceTexture.h index 51b556516729..056fab326351 100644 --- a/gfx/gl/AndroidSurfaceTexture.h +++ b/gfx/gl/AndroidSurfaceTexture.h @@ -8,23 +8,100 @@ #define AndroidSurfaceTexture_h__ #ifdef MOZ_WIDGET_ANDROID -#include "mozilla/gfx/Matrix.h" -#include "SurfaceTexture.h" +#include +#include +#include "nsIRunnable.h" +#include "gfxPlatform.h" +#include "GLDefs.h" +#include "mozilla/gfx/2D.h" +#include "mozilla/gfx/MatrixFwd.h" +#include "mozilla/Monitor.h" -typedef uint32_t AndroidSurfaceTextureHandle; +#include "GeneratedJNIWrappers.h" +#include "SurfaceTexture.h" namespace mozilla { namespace gl { -class AndroidSurfaceTexture { -public: - static void GetTransformMatrix(java::sdk::SurfaceTexture::LocalRef aSurfaceTexture, - mozilla::gfx::Matrix4x4& aMatrix); +class GLContext; +/** + * 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 AndroidSurfaceTexture { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidSurfaceTexture) + +public: + + // The SurfaceTexture is created in an attached state. This method requires + // Android Ice Cream Sandwich. + static already_AddRefed Create(GLContext* aGLContext, GLuint aTexture); + + // Here the SurfaceTexture will be created in a detached state. You must call + // Attach() with the GLContext you wish to composite with. It must be done + // on the thread where that GLContext is current. This method requires + // Android Jelly Bean. + static already_AddRefed Create(); + + // If we are on Jelly Bean, the SurfaceTexture can be detached and reattached + // to allow consumption from different GLContexts. It is recommended to only + // attach while you are consuming in order to allow this. + // + // Only one GLContext may be attached at any given time. If another is already + // attached, we try to wait for it to become detached. + nsresult Attach(GLContext* aContext, PRIntervalTime aTiemout = PR_INTERVAL_NO_TIMEOUT); + + 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; } + + ANativeWindow* NativeWindow() const { + return mNativeWindow; + } + + // This attaches the updated data to the TEXTURE_EXTERNAL target + void UpdateTexImage(); + + void GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix) const; + + void SetDefaultSize(mozilla::gfx::IntSize size); + + // The callback is guaranteed to be called on the main thread even + // if the upstream callback is received on a different thread + void SetFrameAvailableCallback(nsIRunnable* aRunnable); + + GLuint Texture() const { return mTexture; } + const java::sdk::Surface::Ref& JavaSurface() const { return mSurface; } + +private: + class Listener; + + AndroidSurfaceTexture(); + ~AndroidSurfaceTexture(); + + bool Init(GLContext* aContext, GLuint aTexture); + + GLuint mTexture; + java::sdk::SurfaceTexture::GlobalRef mSurfaceTexture; + java::sdk::Surface::GlobalRef mSurface; + java::SurfaceTextureListener::GlobalRef mListener; + + GLContext* mAttachedContext; + + ANativeWindow* mNativeWindow; + + Monitor mMonitor; }; -} // gl -} // mozilla +} +} -#endif // MOZ_WIDGET_ANDROID -#endif // AndroidSurfaceTexture_h__ + +#endif +#endif diff --git a/gfx/gl/GLBlitHelper.cpp b/gfx/gl/GLBlitHelper.cpp index 79f16a75e666..242df6b3fbc3 100644 --- a/gfx/gl/GLBlitHelper.cpp +++ b/gfx/gl/GLBlitHelper.cpp @@ -684,8 +684,30 @@ GLBlitHelper::BindAndUploadEGLImage(EGLImage image, GLuint target) bool GLBlitHelper::BlitSurfaceTextureImage(layers::SurfaceTextureImage* stImage) { - // FIXME - return false; + AndroidSurfaceTexture* surfaceTexture = stImage->GetSurfaceTexture(); + + ScopedBindTextureUnit boundTU(mGL, LOCAL_GL_TEXTURE0); + + if (NS_FAILED(surfaceTexture->Attach(mGL, PR_MillisecondsToInterval(ATTACH_WAIT_MS)))) + return false; + + // UpdateTexImage() changes the EXTERNAL binding, so save it here + // so we can restore it after. + int oldBinding = 0; + mGL->fGetIntegerv(LOCAL_GL_TEXTURE_BINDING_EXTERNAL, &oldBinding); + + surfaceTexture->UpdateTexImage(); + + gfx::Matrix4x4 transform; + surfaceTexture->GetTransformMatrix(transform); + + mGL->fUniformMatrix4fv(mTextureTransformLoc, 1, false, &transform._11); + mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4); + + surfaceTexture->Detach(); + + mGL->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL, oldBinding); + return true; } bool diff --git a/gfx/gl/GLContextEGL.h b/gfx/gl/GLContextEGL.h index 89356f22c723..d090c15bfc85 100644 --- a/gfx/gl/GLContextEGL.h +++ b/gfx/gl/GLContextEGL.h @@ -69,9 +69,6 @@ public: virtual bool ReleaseTexImage() override; void SetEGLSurfaceOverride(EGLSurface surf); - EGLSurface GetEGLSurfaceOverride() { - return mSurfaceOverride; - } virtual bool MakeCurrentImpl(bool aForce) override; diff --git a/gfx/gl/GLScreenBuffer.cpp b/gfx/gl/GLScreenBuffer.cpp index 2eea58389555..7c0007b4243a 100755 --- a/gfx/gl/GLScreenBuffer.cpp +++ b/gfx/gl/GLScreenBuffer.cpp @@ -90,12 +90,6 @@ GLScreenBuffer::CreateFactory(GLContext* gl, factory = SurfaceFactory_GLXDrawable::Create(gl, caps, ipcChannel, flags); #elif defined(MOZ_WIDGET_UIKIT) factory = MakeUnique(mGLContext, caps, ipcChannel, mFlags); -#elif defined(MOZ_WIDGET_ANDROID) - if (XRE_IsParentProcess()) { - factory = SurfaceFactory_EGLImage::Create(gl, caps, ipcChannel, flags); - } else { - factory = SurfaceFactory_SurfaceTexture::Create(gl, caps, ipcChannel, flags); - } #else if (gl->GetContextType() == GLContextType::EGL) { if (XRE_IsParentProcess()) { diff --git a/gfx/gl/SharedSurface.h b/gfx/gl/SharedSurface.h index 158586a3c98e..0cd21d1b7b0d 100644 --- a/gfx/gl/SharedSurface.h +++ b/gfx/gl/SharedSurface.h @@ -96,10 +96,6 @@ public: // Unlocking is harmless if we're already unlocked. void UnlockProd(); - // This surface has been moved to the front buffer and will not be locked again - // until it is recycled. Do any finalization steps here. - virtual void Commit(){} - protected: virtual void LockProdImpl() = 0; virtual void UnlockProdImpl() = 0; diff --git a/gfx/gl/SharedSurfaceEGL.cpp b/gfx/gl/SharedSurfaceEGL.cpp index 5ca24af67f60..9baa82027c61 100644 --- a/gfx/gl/SharedSurfaceEGL.cpp +++ b/gfx/gl/SharedSurfaceEGL.cpp @@ -7,7 +7,6 @@ #include "GLBlitHelper.h" #include "GLContextEGL.h" -#include "GLContextProvider.h" #include "GLLibraryEGL.h" #include "GLReadTexImageHelper.h" #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc @@ -101,6 +100,12 @@ SharedSurface_EGLImage::~SharedSurface_EGLImage() mProdTex = 0; } +layers::TextureFlags +SharedSurface_EGLImage::GetTextureFlags() const +{ + return layers::TextureFlags::DEALLOCATE_CLIENT; +} + void SharedSurface_EGLImage::ProducerReleaseImpl() { @@ -180,136 +185,6 @@ SurfaceFactory_EGLImage::Create(GLContext* prodGL, const SurfaceCaps& caps, return Move(ret); } -//////////////////////////////////////////////////////////////////////// - -#ifdef MOZ_WIDGET_ANDROID - -/*static*/ UniquePtr -SharedSurface_SurfaceTexture::Create(GLContext* prodGL, - const GLFormats& formats, - const gfx::IntSize& size, - bool hasAlpha, - java::GeckoSurface::Param surface) -{ - MOZ_ASSERT(surface); - - UniquePtr ret; - - AndroidNativeWindow window(surface); - EGLSurface eglSurface = GLContextProviderEGL::CreateEGLSurface(window.NativeWindow()); - if (!eglSurface) { - return Move(ret); - } - - ret.reset(new SharedSurface_SurfaceTexture(prodGL, size, hasAlpha, - formats, surface, eglSurface)); - return Move(ret); -} - -SharedSurface_SurfaceTexture::SharedSurface_SurfaceTexture(GLContext* gl, - const gfx::IntSize& size, - bool hasAlpha, - const GLFormats& formats, - java::GeckoSurface::Param surface, - EGLSurface eglSurface) - : SharedSurface(SharedSurfaceType::AndroidSurfaceTexture, - AttachmentType::Screen, - gl, - size, - hasAlpha, - true) - , mSurface(surface) - , mEglSurface(eglSurface) -{ -} - -SharedSurface_SurfaceTexture::~SharedSurface_SurfaceTexture() -{ - GLContextProviderEGL::DestroyEGLSurface(mEglSurface); - java::SurfaceAllocator::DisposeSurface(mSurface); -} - -void -SharedSurface_SurfaceTexture::LockProdImpl() -{ - MOZ_RELEASE_ASSERT(mSurface->GetAvailable()); - - GLContextEGL *gl = GLContextEGL::Cast(mGL); - mOrigEglSurface = gl->GetEGLSurfaceOverride(); - gl->SetEGLSurfaceOverride(mEglSurface); -} - -void -SharedSurface_SurfaceTexture::UnlockProdImpl() -{ - MOZ_RELEASE_ASSERT(mSurface->GetAvailable()); - - GLContextEGL *gl = GLContextEGL::Cast(mGL); - MOZ_ASSERT(gl->GetEGLSurfaceOverride() == mEglSurface); - - gl->SetEGLSurfaceOverride(mOrigEglSurface); - mOrigEglSurface = nullptr; -} - -void -SharedSurface_SurfaceTexture::Commit() -{ - MOZ_RELEASE_ASSERT(mSurface->GetAvailable()); - - LockProdImpl(); - mGL->SwapBuffers(); - UnlockProdImpl(); - mSurface->SetAvailable(false); -} - -void -SharedSurface_SurfaceTexture::WaitForBufferOwnership() -{ - MOZ_RELEASE_ASSERT(!mSurface->GetAvailable()); - mSurface->SetAvailable(true); -} - -bool -SharedSurface_SurfaceTexture::ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) -{ - *out_descriptor = layers::SurfaceTextureDescriptor(mSurface->GetHandle(), mSize, false /* NOT continuous */); - return true; -} - -//////////////////////////////////////////////////////////////////////// - -/*static*/ UniquePtr -SurfaceFactory_SurfaceTexture::Create(GLContext* prodGL, const SurfaceCaps& caps, - const RefPtr& allocator, - const layers::TextureFlags& flags) -{ - UniquePtr ret( - new SurfaceFactory_SurfaceTexture(prodGL, caps, allocator, flags)); - return Move(ret); -} - -UniquePtr -SurfaceFactory_SurfaceTexture::CreateShared(const gfx::IntSize& size) -{ - bool hasAlpha = mReadCaps.alpha; - - jni::Object::LocalRef surface = java::SurfaceAllocator::AcquireSurface(size.width, size.height, true); - if (!surface) { - // Try multi-buffer mode - surface = java::SurfaceAllocator::AcquireSurface(size.width, size.height, false); - if (!surface) { - // Give up - NS_WARNING("Failed to allocate SurfaceTexture!"); - return nullptr; - } - } - - return SharedSurface_SurfaceTexture::Create(mGL, mFormats, size, hasAlpha, - java::GeckoSurface::Ref::From(surface)); -} - -#endif // MOZ_WIDGET_ANDROID - } // namespace gl } /* namespace mozilla */ diff --git a/gfx/gl/SharedSurfaceEGL.h b/gfx/gl/SharedSurfaceEGL.h index 718753db2a2c..e1f3403a6376 100644 --- a/gfx/gl/SharedSurfaceEGL.h +++ b/gfx/gl/SharedSurfaceEGL.h @@ -10,11 +10,6 @@ #include "mozilla/Mutex.h" #include "SharedSurface.h" -#ifdef MOZ_WIDGET_ANDROID -#include "GeneratedJNIWrappers.h" -#include "AndroidNativeWindow.h" -#endif - namespace mozilla { namespace gl { @@ -63,9 +58,7 @@ protected: public: virtual ~SharedSurface_EGLImage(); - virtual layers::TextureFlags GetTextureFlags() const override { - return layers::TextureFlags::DEALLOCATE_CLIENT; - } + virtual layers::TextureFlags GetTextureFlags() const override; virtual void LockProdImpl() override {} virtual void UnlockProdImpl() override {} @@ -117,90 +110,6 @@ public: } }; -#ifdef MOZ_WIDGET_ANDROID - -class SharedSurface_SurfaceTexture - : public SharedSurface -{ -public: - static UniquePtr Create(GLContext* prodGL, - const GLFormats& formats, - const gfx::IntSize& size, - bool hasAlpha, - java::GeckoSurface::Param surface); - - static SharedSurface_SurfaceTexture* Cast(SharedSurface* surf) { - MOZ_ASSERT(surf->mType == SharedSurfaceType::AndroidSurfaceTexture); - - return (SharedSurface_SurfaceTexture*)surf; - } - - java::GeckoSurface::Param JavaSurface() { return mSurface; } - -protected: - java::GeckoSurface::GlobalRef mSurface; - EGLSurface mEglSurface; - EGLSurface mOrigEglSurface; - - SharedSurface_SurfaceTexture(GLContext* gl, - const gfx::IntSize& size, - bool hasAlpha, - const GLFormats& formats, - java::GeckoSurface::Param surface, - EGLSurface eglSurface); - -public: - virtual ~SharedSurface_SurfaceTexture(); - - virtual layers::TextureFlags GetTextureFlags() const override { - return layers::TextureFlags::DEALLOCATE_CLIENT; - } - - virtual void LockProdImpl() override; - virtual void UnlockProdImpl() override; - - virtual void ProducerAcquireImpl() override {} - virtual void ProducerReleaseImpl() override {} - - virtual void ProducerReadAcquireImpl() override {} - virtual void ProducerReadReleaseImpl() override {} - - // Implementation-specific functions below: - // Returns texture and target - virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override; - - virtual bool ReadbackBySharedHandle(gfx::DataSourceSurface* out_surface) override { return false; } - - virtual void Commit() override; - - virtual void WaitForBufferOwnership() override; -}; - - - -class SurfaceFactory_SurfaceTexture - : public SurfaceFactory -{ -public: - // Fallible: - static UniquePtr Create(GLContext* prodGL, - const SurfaceCaps& caps, - const RefPtr& allocator, - const layers::TextureFlags& flags); - -protected: - SurfaceFactory_SurfaceTexture(GLContext* prodGL, const SurfaceCaps& caps, - const RefPtr& allocator, - const layers::TextureFlags& flags) - : SurfaceFactory(SharedSurfaceType::AndroidSurfaceTexture, prodGL, caps, allocator, flags) - { } - -public: - virtual UniquePtr CreateShared(const gfx::IntSize& size) override; -}; - -#endif // MOZ_WIDGET_ANDROID - } // namespace gl } /* namespace mozilla */ diff --git a/gfx/gl/SurfaceTypes.h b/gfx/gl/SurfaceTypes.h index fd2f1a65a163..d69385cd6246 100644 --- a/gfx/gl/SurfaceTypes.h +++ b/gfx/gl/SurfaceTypes.h @@ -77,7 +77,6 @@ enum class SharedSurfaceType : uint8_t { IOSurface, GLXDrawable, SharedGLTexture, - AndroidSurfaceTexture, Max }; diff --git a/gfx/gl/moz.build b/gfx/gl/moz.build index 08d8673b0465..a96fb3e48334 100644 --- a/gfx/gl/moz.build +++ b/gfx/gl/moz.build @@ -24,7 +24,6 @@ if CONFIG['MOZ_GL_PROVIDER']: gl_provider = CONFIG['MOZ_GL_PROVIDER'] EXPORTS += [ - 'AndroidNativeWindow.h', 'AndroidSurfaceTexture.h', 'DecomposeIntoNoRepeatTriangles.h', 'EGLUtils.h', diff --git a/gfx/layers/GLImages.cpp b/gfx/layers/GLImages.cpp index 85760305caa1..e45c3e7d6441 100644 --- a/gfx/layers/GLImages.cpp +++ b/gfx/layers/GLImages.cpp @@ -98,17 +98,14 @@ GLImage::GetAsSourceSurface() } #ifdef MOZ_WIDGET_ANDROID -SurfaceTextureImage::SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle, +SurfaceTextureImage::SurfaceTextureImage(gl::AndroidSurfaceTexture* aSurfTex, const gfx::IntSize& aSize, - bool aContinuous, gl::OriginPos aOriginPos) : GLImage(ImageFormat::SURFACE_TEXTURE), - mHandle(aHandle), + mSurfaceTexture(aSurfTex), mSize(aSize), - mContinuous(aContinuous), mOriginPos(aOriginPos) { - MOZ_ASSERT(mHandle); } #endif diff --git a/gfx/layers/GLImages.h b/gfx/layers/GLImages.h index 3044d132466e..3e419d4b6013 100644 --- a/gfx/layers/GLImages.h +++ b/gfx/layers/GLImages.h @@ -64,17 +64,13 @@ private: class SurfaceTextureImage : public GLImage { public: - SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle, + SurfaceTextureImage(gl::AndroidSurfaceTexture* aSurfTex, const gfx::IntSize& aSize, - bool aContinuous, gl::OriginPos aOriginPos); gfx::IntSize GetSize() override { return mSize; } - AndroidSurfaceTextureHandle GetHandle() const { - return mHandle; - } - bool GetContinuous() const { - return mContinuous; + gl::AndroidSurfaceTexture* GetSurfaceTexture() const { + return mSurfaceTexture; } gl::OriginPos GetOriginPos() const { return mOriginPos; @@ -85,9 +81,8 @@ public: } private: - AndroidSurfaceTextureHandle mHandle; + RefPtr mSurfaceTexture; gfx::IntSize mSize; - bool mContinuous; gl::OriginPos mOriginPos; }; diff --git a/gfx/layers/client/CanvasClient.cpp b/gfx/layers/client/CanvasClient.cpp index ce5b8a2372a0..03d406b5b924 100644 --- a/gfx/layers/client/CanvasClient.cpp +++ b/gfx/layers/client/CanvasClient.cpp @@ -461,8 +461,6 @@ CanvasClientSharedSurface::UpdateRenderer(gfx::IntSize aSize, Renderer& aRendere mReadbackClient = nullptr; } - surf->Commit(); - if (asyncRenderer) { // If surface type is Basic, above codes will readback // the GLContext to mReadbackClient in order to send frame to diff --git a/gfx/layers/client/ImageClient.cpp b/gfx/layers/client/ImageClient.cpp index 2d550222d749..382dbe21d60b 100644 --- a/gfx/layers/client/ImageClient.cpp +++ b/gfx/layers/client/ImageClient.cpp @@ -132,7 +132,7 @@ ImageClient::CreateTextureClientForImage(Image* aImage, KnowsCompositor* aForwar } else if (aImage->GetFormat() == ImageFormat::SURFACE_TEXTURE) { SurfaceTextureImage* typedImage = aImage->AsSurfaceTextureImage(); texture = AndroidSurfaceTextureData::CreateTextureClient( - typedImage->GetHandle(), size, typedImage->GetContinuous(), typedImage->GetOriginPos(), + typedImage->GetSurfaceTexture(), size, typedImage->GetOriginPos(), aForwarder->GetTextureForwarder(), TextureFlags::DEFAULT); #endif } else { diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h index 7817f5b0430a..85a140898352 100644 --- a/gfx/layers/composite/TextureHost.h +++ b/gfx/layers/composite/TextureHost.h @@ -601,7 +601,7 @@ protected: /** * Called when mCompositableCount becomes 0. */ - virtual void NotifyNotUsed(); + void NotifyNotUsed(); // for Compositor. void CallNotifyNotUsed(); diff --git a/gfx/layers/ipc/LayersSurfaces.ipdlh b/gfx/layers/ipc/LayersSurfaces.ipdlh index 9f1d6fd04337..c6e24e43a8ad 100644 --- a/gfx/layers/ipc/LayersSurfaces.ipdlh +++ b/gfx/layers/ipc/LayersSurfaces.ipdlh @@ -60,9 +60,8 @@ struct SurfaceDescriptorMacIOSurface { }; struct SurfaceTextureDescriptor { - uint64_t handle; + uintptr_t surfTex; IntSize size; - bool continuous; }; struct EGLImageDescriptor { diff --git a/gfx/layers/opengl/TextureClientOGL.cpp b/gfx/layers/opengl/TextureClientOGL.cpp index 80643d6ed0cb..78d4e6d9c9a1 100644 --- a/gfx/layers/opengl/TextureClientOGL.cpp +++ b/gfx/layers/opengl/TextureClientOGL.cpp @@ -79,31 +79,34 @@ EGLImageTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) #ifdef MOZ_WIDGET_ANDROID already_AddRefed -AndroidSurfaceTextureData::CreateTextureClient(AndroidSurfaceTextureHandle aHandle, +AndroidSurfaceTextureData::CreateTextureClient(AndroidSurfaceTexture* aSurfTex, gfx::IntSize aSize, - bool aContinuous, gl::OriginPos aOriginPos, LayersIPCChannel* aAllocator, TextureFlags aFlags) { + MOZ_ASSERT(XRE_IsParentProcess(), + "Can't pass an android surfaces between processes."); + + if (!aSurfTex || !XRE_IsParentProcess()) { + return nullptr; + } + if (aOriginPos == gl::OriginPos::BottomLeft) { aFlags |= TextureFlags::ORIGIN_BOTTOM_LEFT; } return TextureClient::CreateWithData( - new AndroidSurfaceTextureData(aHandle, aSize, aContinuous), + new AndroidSurfaceTextureData(aSurfTex, aSize), aFlags, aAllocator ); } -AndroidSurfaceTextureData::AndroidSurfaceTextureData(AndroidSurfaceTextureHandle aHandle, - gfx::IntSize aSize, bool aContinuous) - : mHandle(aHandle) +AndroidSurfaceTextureData::AndroidSurfaceTextureData(AndroidSurfaceTexture* aSurfTex, + gfx::IntSize aSize) + : mSurfTex(aSurfTex) , mSize(aSize) - , mContinuous(aContinuous) -{ - MOZ_ASSERT(mHandle); -} +{} AndroidSurfaceTextureData::~AndroidSurfaceTextureData() {} @@ -122,7 +125,8 @@ AndroidSurfaceTextureData::FillInfo(TextureData::Info& aInfo) const bool AndroidSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) { - aOutDescriptor = SurfaceTextureDescriptor(mHandle, mSize, mContinuous); + aOutDescriptor = SurfaceTextureDescriptor((uintptr_t)mSurfTex.get(), + mSize); return true; } diff --git a/gfx/layers/opengl/TextureClientOGL.h b/gfx/layers/opengl/TextureClientOGL.h index aae9d04316e7..6555f138adda 100644 --- a/gfx/layers/opengl/TextureClientOGL.h +++ b/gfx/layers/opengl/TextureClientOGL.h @@ -54,9 +54,8 @@ class AndroidSurfaceTextureData : public TextureData { public: static already_AddRefed - CreateTextureClient(AndroidSurfaceTextureHandle aHandle, + CreateTextureClient(gl::AndroidSurfaceTexture* aSurfTex, gfx::IntSize aSize, - bool aContinuous, gl::OriginPos aOriginPos, LayersIPCChannel* aAllocator, TextureFlags aFlags); @@ -76,11 +75,10 @@ public: virtual void Deallocate(LayersIPCChannel*) override {} protected: - AndroidSurfaceTextureData(AndroidSurfaceTextureHandle aHandle, gfx::IntSize aSize, bool aContinuous); + AndroidSurfaceTextureData(gl::AndroidSurfaceTexture* aSurfTex, gfx::IntSize aSize); - const AndroidSurfaceTextureHandle mHandle; + const RefPtr mSurfTex; const gfx::IntSize mSize; - const bool mContinuous; }; #endif // MOZ_WIDGET_ANDROID diff --git a/gfx/layers/opengl/TextureHostOGL.cpp b/gfx/layers/opengl/TextureHostOGL.cpp index 87ef1e858308..10ee44c7a3e6 100644 --- a/gfx/layers/opengl/TextureHostOGL.cpp +++ b/gfx/layers/opengl/TextureHostOGL.cpp @@ -56,14 +56,9 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc, #ifdef MOZ_WIDGET_ANDROID case SurfaceDescriptor::TSurfaceTextureDescriptor: { const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor(); - java::GeckoSurfaceTexture::LocalRef surfaceTexture = java::GeckoSurfaceTexture::Lookup(desc.handle()); - - MOZ_RELEASE_ASSERT(surfaceTexture); - result = new SurfaceTextureHost(aFlags, - surfaceTexture, - desc.size(), - desc.continuous()); + (AndroidSurfaceTexture*)desc.surfTex(), + desc.size()); break; } #endif @@ -340,7 +335,7 @@ GLTextureSource::IsValid() const #ifdef MOZ_WIDGET_ANDROID SurfaceTextureSource::SurfaceTextureSource(TextureSourceProvider* aProvider, - mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex, + AndroidSurfaceTexture* aSurfTex, gfx::SurfaceFormat aFormat, GLenum aTarget, GLenum aWrapMode, @@ -366,7 +361,12 @@ SurfaceTextureSource::BindTexture(GLenum aTextureUnit, } gl->fActiveTexture(aTextureUnit); - gl->fBindTexture(mTextureTarget, mSurfTex->GetTexName()); + + // SurfaceTexture spams us if there are any existing GL errors, so + // we'll clear them here in order to avoid that. + gl->FlushErrors(); + + mSurfTex->UpdateTexImage(); ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget); } @@ -395,9 +395,7 @@ SurfaceTextureSource::GetTextureTransform() MOZ_ASSERT(mSurfTex); gfx::Matrix4x4 ret; - - const auto& surf = java::sdk::SurfaceTexture::LocalRef(java::sdk::SurfaceTexture::Ref::From(mSurfTex)); - AndroidSurfaceTexture::GetTransformMatrix(surf, ret); + mSurfTex->GetTransformMatrix(ret); return ret; } @@ -411,39 +409,18 @@ SurfaceTextureSource::DeallocateDeviceData() //////////////////////////////////////////////////////////////////////// SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags, - mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex, - gfx::IntSize aSize, - bool aContinuousUpdate) + AndroidSurfaceTexture* aSurfTex, + gfx::IntSize aSize) : TextureHost(aFlags) , mSurfTex(aSurfTex) , mSize(aSize) - , mContinuousUpdate(aContinuousUpdate) { - // Continuous update makes no sense with single buffer mode - MOZ_ASSERT(!mSurfTex->IsSingleBuffer() || !mContinuousUpdate); } SurfaceTextureHost::~SurfaceTextureHost() { } -void -SurfaceTextureHost::PrepareTextureSource(CompositableTextureSourceRef& aTexture) -{ - GLContext* gl = this->gl(); - if (!gl || !gl->MakeCurrent()) { - return; - } - - if (!mContinuousUpdate) { - // UpdateTexImage() advances the internal buffer queue, so we only want to call this - // once per transactionwhen we are not in continuous mode (as we are here). Otherwise, - // the SurfaceTexture content will be de-synced from the rest of the page in subsequent - // compositor passes. - mSurfTex->UpdateTexImage(); - } -} - gl::GLContext* SurfaceTextureHost::gl() const { @@ -459,13 +436,9 @@ SurfaceTextureHost::Lock() return false; } - if (mContinuousUpdate) { - mSurfTex->UpdateTexImage(); - } - if (!mTextureSource) { gfx::SurfaceFormat format = gfx::SurfaceFormat::R8G8B8A8; - GLenum target = LOCAL_GL_TEXTURE_EXTERNAL; // This is required by SurfaceTexture + GLenum target = LOCAL_GL_TEXTURE_EXTERNAL; GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE; mTextureSource = new SurfaceTextureSource(mProvider, mSurfTex, @@ -475,7 +448,14 @@ SurfaceTextureHost::Lock() mSize); } - return true; + return NS_SUCCEEDED(mSurfTex->Attach(gl)); +} + +void +SurfaceTextureHost::Unlock() +{ + MOZ_ASSERT(mSurfTex); + mSurfTex->Detach(); } void @@ -494,16 +474,6 @@ SurfaceTextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider) } } -void -SurfaceTextureHost::NotifyNotUsed() -{ - if (mSurfTex->IsSingleBuffer()) { - mSurfTex->ReleaseTexImage(); - } - - TextureHost::NotifyNotUsed(); -} - gfx::SurfaceFormat SurfaceTextureHost::GetFormat() const { diff --git a/gfx/layers/opengl/TextureHostOGL.h b/gfx/layers/opengl/TextureHostOGL.h index eb0ea58d34eb..6ea6b851e1d4 100644 --- a/gfx/layers/opengl/TextureHostOGL.h +++ b/gfx/layers/opengl/TextureHostOGL.h @@ -31,16 +31,15 @@ #include "nsRegionFwd.h" // for nsIntRegion #include "OGLShaderProgram.h" // for ShaderProgramType, etc -#ifdef MOZ_WIDGET_ANDROID -#include "GeneratedJNIWrappers.h" -#include "AndroidSurfaceTexture.h" -#endif - namespace mozilla { namespace gfx { class DataSourceSurface; } // namespace gfx +namespace gl { +class AndroidSurfaceTexture; +} // namespace gl + namespace layers { class Compositor; @@ -342,7 +341,7 @@ class SurfaceTextureSource : public TextureSource { public: SurfaceTextureSource(TextureSourceProvider* aProvider, - java::GeckoSurfaceTexture::Ref& aSurfTex, + mozilla::gl::AndroidSurfaceTexture* aSurfTex, gfx::SurfaceFormat aFormat, GLenum aTarget, GLenum aWrapMode, @@ -377,7 +376,7 @@ public: protected: RefPtr mGL; - mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex; + RefPtr mSurfTex; const gfx::SurfaceFormat mFormat; const GLenum mTextureTarget; const GLenum mWrapMode; @@ -388,23 +387,20 @@ class SurfaceTextureHost : public TextureHost { public: SurfaceTextureHost(TextureFlags aFlags, - mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex, - gfx::IntSize aSize, - bool aContinuousUpdate); + mozilla::gl::AndroidSurfaceTexture* aSurfTex, + gfx::IntSize aSize); virtual ~SurfaceTextureHost(); - virtual void PrepareTextureSource(CompositableTextureSourceRef& aTexture) override; - virtual void DeallocateDeviceData() override; virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override; virtual bool Lock() override; - virtual gfx::SurfaceFormat GetFormat() const override; + virtual void Unlock() override; - virtual void NotifyNotUsed() override; + virtual gfx::SurfaceFormat GetFormat() const override; virtual bool BindTextureSource(CompositableTextureSourceRef& aTexture) override { @@ -424,9 +420,8 @@ public: virtual const char* Name() override { return "SurfaceTextureHost"; } protected: - mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex; + RefPtr mSurfTex; const gfx::IntSize mSize; - bool mContinuousUpdate; RefPtr mCompositor; RefPtr mTextureSource; }; diff --git a/gfx/layers/opengl/TexturePoolOGL.cpp b/gfx/layers/opengl/TexturePoolOGL.cpp index 5b4701c2704f..8bd2aee9137e 100644 --- a/gfx/layers/opengl/TexturePoolOGL.cpp +++ b/gfx/layers/opengl/TexturePoolOGL.cpp @@ -10,10 +10,6 @@ #include "nsDebug.h" // for NS_ASSERTION, NS_ERROR, etc #include "nsDeque.h" // for nsDeque -#ifdef MOZ_WIDGET_ANDROID -#include "GeneratedJNINatives.h" -#endif - #define TEXTURE_POOL_SIZE 10 namespace mozilla { @@ -24,19 +20,6 @@ static GLContext* sActiveContext = nullptr; static Monitor* sMonitor = nullptr; static nsDeque* sTextures = nullptr; -#ifdef MOZ_WIDGET_ANDROID - -class GeckoSurfaceTextureSupport final - : public java::GeckoSurfaceTexture::Natives -{ -public: - static int32_t NativeAcquireTexture() { - return TexturePoolOGL::AcquireTexture(); - } -}; - -#endif // MOZ_WIDGET_ANDROID - GLuint TexturePoolOGL::AcquireTexture() { NS_ASSERTION(sMonitor, "not initialized"); @@ -128,12 +111,6 @@ void TexturePoolOGL::Init() { sMonitor = new Monitor("TexturePoolOGL.sMonitor"); sTextures = new nsDeque(); - -#ifdef MOZ_WIDGET_ANDROID - if (jni::IsAvailable()) { - GeckoSurfaceTextureSupport::Init(); - } -#endif } void TexturePoolOGL::Shutdown() diff --git a/mobile/android/base/AndroidManifest.xml.in b/mobile/android/base/AndroidManifest.xml.in index d0c20ad74904..d436cce508ec 100644 --- a/mobile/android/base/AndroidManifest.xml.in +++ b/mobile/android/base/AndroidManifest.xml.in @@ -473,12 +473,5 @@ android:isolatedProcess="false"> - - - diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in index b3642b49ab81..c2d491b88645 100644 --- a/mobile/android/base/Makefile.in +++ b/mobile/android/base/Makefile.in @@ -547,7 +547,6 @@ libs:: classes.dex GECKOVIEW_AIDLS = \ org/mozilla/gecko/IGeckoEditableChild.aidl \ org/mozilla/gecko/IGeckoEditableParent.aidl \ - org/mozilla/gecko/gfx/ISurfaceAllocator.aidl \ org/mozilla/gecko/media/ICodec.aidl \ org/mozilla/gecko/media/ICodecCallbacks.aidl \ org/mozilla/gecko/media/IMediaDrmBridge.aidl \ diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build index b2acb121f720..2d29c7ac8ab6 100644 --- a/mobile/android/base/moz.build +++ b/mobile/android/base/moz.build @@ -379,8 +379,6 @@ gvjar.sources += [geckoview_source_dir + 'java/org/mozilla/gecko/' + x 'gfx/FloatSize.java', 'gfx/FullScreenState.java', 'gfx/GeckoLayerClient.java', - 'gfx/GeckoSurface.java', - 'gfx/GeckoSurfaceTexture.java', 'gfx/ImmutableViewportMetrics.java', 'gfx/IntSize.java', 'gfx/LayerView.java', @@ -393,8 +391,6 @@ gvjar.sources += [geckoview_source_dir + 'java/org/mozilla/gecko/' + x 'gfx/RectUtils.java', 'gfx/RenderTask.java', 'gfx/StackScroller.java', - 'gfx/SurfaceAllocator.java', - 'gfx/SurfaceAllocatorService.java', 'gfx/SurfaceTextureListener.java', 'gfx/ViewTransform.java', 'gfx/VsyncSource.java', @@ -1266,7 +1262,6 @@ DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME'] FINAL_TARGET_PP_FILES += ['package-name.txt.in'] gvjar.sources += ['generated/org/mozilla/gecko/' + x for x in [ - 'gfx/ISurfaceAllocator.java', 'IGeckoEditableChild.java', 'IGeckoEditableParent.java', 'media/ICodec.java', diff --git a/mobile/android/geckoview/src/main/AndroidManifest.xml b/mobile/android/geckoview/src/main/AndroidManifest.xml index 62137f765614..adf67239f8b3 100644 --- a/mobile/android/geckoview/src/main/AndroidManifest.xml +++ b/mobile/android/geckoview/src/main/AndroidManifest.xml @@ -38,14 +38,6 @@ - - - - - - diff --git a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/GeckoSurface.aidl b/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/GeckoSurface.aidl deleted file mode 100644 index 3fe35450fc0c..000000000000 --- a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/GeckoSurface.aidl +++ /dev/null @@ -1,7 +0,0 @@ -/* 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/. */ - -package org.mozilla.gecko.gfx; - -parcelable GeckoSurface; \ No newline at end of file diff --git a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/ISurfaceAllocator.aidl b/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/ISurfaceAllocator.aidl deleted file mode 100644 index 1021df4a7c5c..000000000000 --- a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/ISurfaceAllocator.aidl +++ /dev/null @@ -1,12 +0,0 @@ -/* 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/. */ - -package org.mozilla.gecko.gfx; - -import org.mozilla.gecko.gfx.GeckoSurface; - -interface ISurfaceAllocator { - GeckoSurface acquireSurface(in int width, in int height, in boolean singleBufferMode); - void releaseSurface(in int handle); -} diff --git a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl b/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl index 3a5835d5de3a..1bb74cf83f24 100644 --- a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl +++ b/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl @@ -13,7 +13,7 @@ import org.mozilla.gecko.media.Sample; interface ICodec { void setCallbacks(in ICodecCallbacks callbacks); - boolean configure(in FormatParam format, in Surface surface, int flags, in String drmStubId); + boolean configure(in FormatParam format, inout Surface surface, int flags, in String drmStubId); boolean isAdaptivePlaybackSupported(); void start(); void stop(); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurface.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurface.java deleted file mode 100644 index 7388a4712f0e..000000000000 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurface.java +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- - * 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/. */ - -package org.mozilla.gecko.gfx; - -import android.graphics.SurfaceTexture; - -import android.os.Parcel; -import android.os.Parcelable; -import android.view.Surface; -import android.util.Log; - -import java.util.HashMap; - -import org.mozilla.gecko.annotation.WrapForJNI; -import org.mozilla.gecko.AppConstants.Versions; - -public final class GeckoSurface extends Surface { - private static final String LOGTAG = "GeckoSurface"; - - private static HashMap sSurfaceTextures = new HashMap(); - - private int mHandle; - private boolean mIsSingleBuffer; - private volatile boolean mIsAvailable; - - private SurfaceTexture mDummySurfaceTexture; - - @WrapForJNI(exceptionMode = "nsresult") - public GeckoSurface(GeckoSurfaceTexture gst) { - super(gst); - mHandle = gst.getHandle(); - mIsSingleBuffer = gst.isSingleBuffer(); - mIsAvailable = true; - } - - public GeckoSurface(SurfaceTexture st) { - super(st); - mDummySurfaceTexture = st; - } - - public GeckoSurface() { - // A no-arg constructor exists, but is hidden in the SDK. We need to create a dummy - // SurfaceTexture here in order to create the instance. This is used to transfer the - // GeckoSurface across binder. - super(new SurfaceTexture(0)); - } - - @Override - public void readFromParcel(Parcel p) { - super.readFromParcel(p); - mHandle = p.readInt(); - mIsSingleBuffer = p.readByte() == 1 ? true : false; - mIsAvailable = (p.readByte() == 1 ? true : false); - - if (mDummySurfaceTexture != null) { - mDummySurfaceTexture.release(); - mDummySurfaceTexture = null; - } - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public GeckoSurface createFromParcel(Parcel p) { - GeckoSurface surf = new GeckoSurface(); - surf.readFromParcel(p); - return surf; - } - - public GeckoSurface[] newArray(int size) { - return new GeckoSurface[size]; - } - }; - - @Override - public void writeToParcel(Parcel out, int flags) { - super.writeToParcel(out, flags); - out.writeInt(mHandle); - out.writeByte((byte) (mIsSingleBuffer ? 1 : 0)); - out.writeByte((byte) (mIsAvailable ? 1 : 0)); - } - - @WrapForJNI - public int getHandle() { - return mHandle; - } - - @WrapForJNI - public boolean getAvailable() { - return mIsAvailable; - } - - @WrapForJNI - public void setAvailable(boolean available) { - mIsAvailable = available; - } -} \ No newline at end of file diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java deleted file mode 100644 index 3d53ee90186a..000000000000 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- - * 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/. */ - -package org.mozilla.gecko.gfx; - -import android.graphics.SurfaceTexture; -import android.util.Log; - -import java.util.HashMap; - -import org.mozilla.gecko.annotation.WrapForJNI; -import org.mozilla.gecko.AppConstants.Versions; - -public final class GeckoSurfaceTexture extends SurfaceTexture { - private static final String LOGTAG = "GeckoSurfaceTexture"; - private static volatile int sNextHandle = 1; - private static HashMap sSurfaceTextures = new HashMap(); - - private int mHandle; - private boolean mIsSingleBuffer; - private int mTexName; - private GeckoSurfaceTexture.Callbacks mListener; - - @WrapForJNI(dispatchTo = "current") - private static native int nativeAcquireTexture(); - - private GeckoSurfaceTexture(int handle, int texName) { - super(texName); - mHandle = handle; - mIsSingleBuffer = false; - mTexName = texName; - } - - private GeckoSurfaceTexture(int handle, int texName, boolean singleBufferMode) { - super(texName, singleBufferMode); - mHandle = handle; - mIsSingleBuffer = singleBufferMode; - mTexName = texName; - } - - @WrapForJNI - public int getHandle() { - return mHandle; - } - - @WrapForJNI - public int getTexName() { - return mTexName; - } - - @WrapForJNI - public boolean isSingleBuffer() { - return mIsSingleBuffer; - } - - @Override - @WrapForJNI - public synchronized void updateTexImage() { - super.updateTexImage(); - if (mListener != null) { - mListener.onUpdateTexImage(); - } - } - - @Override - @WrapForJNI - public synchronized void releaseTexImage() { - if (!mIsSingleBuffer) { - return; - } - - super.releaseTexImage(); - if (mListener != null) { - mListener.onReleaseTexImage(); - } - } - - public synchronized void setListener(GeckoSurfaceTexture.Callbacks listener) { - mListener = listener; - } - - @WrapForJNI - public static boolean isSingleBufferSupported() { - return Versions.feature19Plus; - } - - public static GeckoSurfaceTexture acquire(boolean singleBufferMode) { - if (singleBufferMode && !isSingleBufferSupported()) { - throw new IllegalArgumentException("single buffer mode not supported on API version < 19"); - } - - int handle = sNextHandle++; - int texName = nativeAcquireTexture(); - - final GeckoSurfaceTexture gst; - if (isSingleBufferSupported()) { - gst = new GeckoSurfaceTexture(handle, texName, singleBufferMode); - } else { - gst = new GeckoSurfaceTexture(handle, texName); - } - - synchronized (sSurfaceTextures) { - if (sSurfaceTextures.containsKey(handle)) { - gst.release(); - throw new IllegalArgumentException("Already have a GeckoSurfaceTexture with that handle"); - } - - sSurfaceTextures.put(handle, gst); - } - - - return gst; - } - - public static void dispose(int handle) { - final GeckoSurfaceTexture gst; - synchronized (sSurfaceTextures) { - gst = sSurfaceTextures.remove(handle); - } - - if (gst != null) { - gst.setListener(null); - gst.release(); - } - } - - @WrapForJNI - public static GeckoSurfaceTexture lookup(int handle) { - synchronized (sSurfaceTextures) { - return sSurfaceTextures.get(handle); - } - } - - public interface Callbacks { - void onUpdateTexImage(); - void onReleaseTexImage(); - } -} \ No newline at end of file diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocator.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocator.java deleted file mode 100644 index a6e3571c79ee..000000000000 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocator.java +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- - * 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/. */ - -package org.mozilla.gecko.gfx; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; - -import android.graphics.SurfaceTexture; -import android.os.IBinder; -import android.os.Process; -import android.os.RemoteException; -import android.util.Log; -import android.view.Surface; - -import org.mozilla.gecko.annotation.WrapForJNI; -import org.mozilla.gecko.GeckoAppShell; - -public final class SurfaceAllocator { - private static final String LOGTAG = "SurfaceAllocator"; - - private static SurfaceAllocatorConnection sConnection; - - private static synchronized void ensureConnection() throws Exception { - if (sConnection != null) { - return; - } - - sConnection = new SurfaceAllocatorConnection(); - Intent intent = new Intent(); - intent.setClassName(GeckoAppShell.getApplicationContext(), - "org.mozilla.gecko.gfx.SurfaceAllocatorService"); - - // FIXME: may not want to auto create - if (!GeckoAppShell.getApplicationContext().bindService(intent, sConnection, Context.BIND_AUTO_CREATE)) { - throw new Exception("Failed to connect to surface allocator service!"); - } - } - - @WrapForJNI - public static GeckoSurface acquireSurface(int width, int height, boolean singleBufferMode) { - try { - ensureConnection(); - - if (singleBufferMode && !GeckoSurfaceTexture.isSingleBufferSupported()) { - return null; - } - - return sConnection.getAllocator().acquireSurface(width, height, singleBufferMode); - } catch (Exception e) { - Log.w(LOGTAG, "Failed to acquire GeckoSurface", e); - return null; - } - } - - @WrapForJNI - public static void disposeSurface(GeckoSurface surface) { - try { - ensureConnection(); - } catch (Exception e) { - Log.w(LOGTAG, "Failed to dispose surface, no connection"); - return; - } - - // Release the SurfaceTexture on the other side - try { - sConnection.getAllocator().releaseSurface(surface.getHandle()); - } catch (RemoteException e) { - Log.w(LOGTAG, "Failed to release surface texture", e); - } - - // And now our Surface - try { - surface.release(); - } catch (Exception e) { - Log.w(LOGTAG, "Failed to release surface", e); - } - } - - private static final class SurfaceAllocatorConnection implements ServiceConnection { - private ISurfaceAllocator mAllocator; - - public synchronized ISurfaceAllocator getAllocator() { - while (mAllocator == null) { - try { - this.wait(); - } catch (InterruptedException e) { } - } - - return mAllocator; - } - - @Override - public synchronized void onServiceConnected(ComponentName name, IBinder service) { - mAllocator = ISurfaceAllocator.Stub.asInterface(service); - this.notifyAll(); - } - - @Override - public synchronized void onServiceDisconnected(ComponentName name) { - mAllocator = null; - } - } -} diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocatorService.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocatorService.java deleted file mode 100644 index 02d1a9a82d83..000000000000 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocatorService.java +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * 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/. */ - -package org.mozilla.gecko.gfx; - -import android.app.Service; -import android.content.Intent; -import android.os.Binder; -import android.os.IBinder; -import android.os.RemoteException; -import android.util.Log; - -public class SurfaceAllocatorService extends Service { - - static private String LOGTAG = "SurfaceAllocatorService"; - - public int onStartCommand(final Intent intent, final int flags, final int startId) { - return Service.START_STICKY; - } - - private Binder mBinder = new ISurfaceAllocator.Stub() { - public GeckoSurface acquireSurface(int width, int height, boolean singleBufferMode) { - GeckoSurfaceTexture gst = GeckoSurfaceTexture.acquire(singleBufferMode); - if (width > 0 && height > 0) { - gst.setDefaultBufferSize(width, height); - } - - return new GeckoSurface(gst); - } - - public void releaseSurface(int handle) { - GeckoSurfaceTexture.dispose(handle); - } - }; - - public IBinder onBind(final Intent intent) { - return mBinder; - } - - public boolean onUnbind(Intent intent) { - return false; - } -} diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java index eab29e89cf78..560674e4fbdd 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java @@ -17,12 +17,10 @@ final class SurfaceTextureListener private SurfaceTextureListener() { } - @WrapForJNI(dispatchTo = "gecko") @Override // JNIObject - protected native void disposeNative(); - @Override - protected void finalize() { - disposeNative(); + protected void disposeNative() { + // SurfaceTextureListener is disposed inside AndroidSurfaceTexture. + throw new IllegalStateException("unreachable code"); } @WrapForJNI(stubName = "OnFrameAvailable") diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/JNIObject.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/JNIObject.java index aaae03a2b5e4..a3a127a1a0b0 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/JNIObject.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/JNIObject.java @@ -7,10 +7,5 @@ public abstract class JNIObject private long mHandle; // Dispose of any reference to a native object. - // - // If the native instance is destroyed from the native side, this should never be - // called, so you should throw an UnsupportedOperationException. If instead you - // want to destroy the native side from the Java end, make override this with - // a native call, and the right thing will be done in the native code. protected abstract void disposeNative(); } diff --git a/widget/android/AndroidBridge.cpp b/widget/android/AndroidBridge.cpp index 1fd218efbf3d..ea9422f82da4 100644 --- a/widget/android/AndroidBridge.cpp +++ b/widget/android/AndroidBridge.cpp @@ -173,7 +173,9 @@ AndroidBridge::AndroidBridge() AutoJNIClass string(jEnv, "java/lang/String"); jStringClass = string.getGlobalRef(); - mAPIVersion = jni::GetAPIVersion(); + if (!GetStaticIntField("android/os/Build$VERSION", "SDK_INT", &mAPIVersion, jEnv)) { + ALOG_BRIDGE("Failed to find API version"); + } AutoJNIClass channels(jEnv, "java/nio/channels/Channels"); jChannels = channels.getGlobalRef(); diff --git a/widget/android/GeneratedJNINatives.h b/widget/android/GeneratedJNINatives.h index 1539e52e8b6c..c6abedcacf69 100644 --- a/widget/android/GeneratedJNINatives.h +++ b/widget/android/GeneratedJNINatives.h @@ -336,36 +336,17 @@ template class SurfaceTextureListener::Natives : public mozilla::jni::NativeImpl { public: - static const JNINativeMethod methods[2]; + static const JNINativeMethod methods[1]; }; template const JNINativeMethod SurfaceTextureListener::Natives::methods[] = { - mozilla::jni::MakeNativeMethod( - mozilla::jni::NativeStub - ::template Wrap<&Impl::DisposeNative>), - mozilla::jni::MakeNativeMethod( mozilla::jni::NativeStub ::template Wrap<&Impl::OnFrameAvailable>) }; -template -class GeckoSurfaceTexture::Natives : public mozilla::jni::NativeImpl -{ -public: - static const JNINativeMethod methods[1]; -}; - -template -const JNINativeMethod GeckoSurfaceTexture::Natives::methods[] = { - - mozilla::jni::MakeNativeMethod( - mozilla::jni::NativeStub - ::template Wrap<&Impl::NativeAcquireTexture>) -}; - template class LayerView::Compositor::Natives : public mozilla::jni::NativeImpl { diff --git a/widget/android/GeneratedJNIWrappers.cpp b/widget/android/GeneratedJNIWrappers.cpp index a8367aeb20ba..255e28d92747 100644 --- a/widget/android/GeneratedJNIWrappers.cpp +++ b/widget/android/GeneratedJNIWrappers.cpp @@ -1063,9 +1063,6 @@ auto SurfaceTextureListener::New() -> SurfaceTextureListener::LocalRef return mozilla::jni::Constructor::Call(SurfaceTextureListener::Context(), nullptr); } -constexpr char SurfaceTextureListener::DisposeNative_t::name[]; -constexpr char SurfaceTextureListener::DisposeNative_t::signature[]; - constexpr char SurfaceTextureListener::OnFrameAvailable_t::name[]; constexpr char SurfaceTextureListener::OnFrameAvailable_t::signature[]; @@ -1120,106 +1117,6 @@ auto GeckoLayerClient::UpdateRootFrameMetrics(float a0, float a1, float a2, floa return mozilla::jni::Method::Call(GeckoLayerClient::mCtx, nullptr, a0, a1, a2, a3, a4, a5, a6); } -const char GeckoSurface::name[] = - "org/mozilla/gecko/gfx/GeckoSurface"; - -constexpr char GeckoSurface::New_t::name[]; -constexpr char GeckoSurface::New_t::signature[]; - -auto GeckoSurface::New(mozilla::jni::Object::Param a0, GeckoSurface::LocalRef* a1) -> nsresult -{ - MOZ_ASSERT(a1); - nsresult rv = NS_OK; - *a1 = mozilla::jni::Constructor::Call(GeckoSurface::Context(), &rv, a0); - return rv; -} - -constexpr char GeckoSurface::GetAvailable_t::name[]; -constexpr char GeckoSurface::GetAvailable_t::signature[]; - -auto GeckoSurface::GetAvailable() const -> bool -{ - return mozilla::jni::Method::Call(GeckoSurface::mCtx, nullptr); -} - -constexpr char GeckoSurface::GetHandle_t::name[]; -constexpr char GeckoSurface::GetHandle_t::signature[]; - -auto GeckoSurface::GetHandle() const -> int32_t -{ - return mozilla::jni::Method::Call(GeckoSurface::mCtx, nullptr); -} - -constexpr char GeckoSurface::SetAvailable_t::name[]; -constexpr char GeckoSurface::SetAvailable_t::signature[]; - -auto GeckoSurface::SetAvailable(bool a0) const -> void -{ - return mozilla::jni::Method::Call(GeckoSurface::mCtx, nullptr, a0); -} - -const char GeckoSurfaceTexture::name[] = - "org/mozilla/gecko/gfx/GeckoSurfaceTexture"; - -constexpr char GeckoSurfaceTexture::GetHandle_t::name[]; -constexpr char GeckoSurfaceTexture::GetHandle_t::signature[]; - -auto GeckoSurfaceTexture::GetHandle() const -> int32_t -{ - return mozilla::jni::Method::Call(GeckoSurfaceTexture::mCtx, nullptr); -} - -constexpr char GeckoSurfaceTexture::GetTexName_t::name[]; -constexpr char GeckoSurfaceTexture::GetTexName_t::signature[]; - -auto GeckoSurfaceTexture::GetTexName() const -> int32_t -{ - return mozilla::jni::Method::Call(GeckoSurfaceTexture::mCtx, nullptr); -} - -constexpr char GeckoSurfaceTexture::IsSingleBuffer_t::name[]; -constexpr char GeckoSurfaceTexture::IsSingleBuffer_t::signature[]; - -auto GeckoSurfaceTexture::IsSingleBuffer() const -> bool -{ - return mozilla::jni::Method::Call(GeckoSurfaceTexture::mCtx, nullptr); -} - -constexpr char GeckoSurfaceTexture::IsSingleBufferSupported_t::name[]; -constexpr char GeckoSurfaceTexture::IsSingleBufferSupported_t::signature[]; - -auto GeckoSurfaceTexture::IsSingleBufferSupported() -> bool -{ - return mozilla::jni::Method::Call(GeckoSurfaceTexture::Context(), nullptr); -} - -constexpr char GeckoSurfaceTexture::Lookup_t::name[]; -constexpr char GeckoSurfaceTexture::Lookup_t::signature[]; - -auto GeckoSurfaceTexture::Lookup(int32_t a0) -> GeckoSurfaceTexture::LocalRef -{ - return mozilla::jni::Method::Call(GeckoSurfaceTexture::Context(), nullptr, a0); -} - -constexpr char GeckoSurfaceTexture::NativeAcquireTexture_t::name[]; -constexpr char GeckoSurfaceTexture::NativeAcquireTexture_t::signature[]; - -constexpr char GeckoSurfaceTexture::ReleaseTexImage_t::name[]; -constexpr char GeckoSurfaceTexture::ReleaseTexImage_t::signature[]; - -auto GeckoSurfaceTexture::ReleaseTexImage() const -> void -{ - return mozilla::jni::Method::Call(GeckoSurfaceTexture::mCtx, nullptr); -} - -constexpr char GeckoSurfaceTexture::UpdateTexImage_t::name[]; -constexpr char GeckoSurfaceTexture::UpdateTexImage_t::signature[]; - -auto GeckoSurfaceTexture::UpdateTexImage() const -> void -{ - return mozilla::jni::Method::Call(GeckoSurfaceTexture::mCtx, nullptr); -} - const char ImmutableViewportMetrics::name[] = "org/mozilla/gecko/gfx/ImmutableViewportMetrics"; @@ -1648,25 +1545,6 @@ auto StackScroller::SViscousFluidScale(float a0) -> nsresult return rv; } -const char SurfaceAllocator::name[] = - "org/mozilla/gecko/gfx/SurfaceAllocator"; - -constexpr char SurfaceAllocator::AcquireSurface_t::name[]; -constexpr char SurfaceAllocator::AcquireSurface_t::signature[]; - -auto SurfaceAllocator::AcquireSurface(int32_t a0, int32_t a1, bool a2) -> mozilla::jni::Object::LocalRef -{ - return mozilla::jni::Method::Call(SurfaceAllocator::Context(), nullptr, a0, a1, a2); -} - -constexpr char SurfaceAllocator::DisposeSurface_t::name[]; -constexpr char SurfaceAllocator::DisposeSurface_t::signature[]; - -auto SurfaceAllocator::DisposeSurface(mozilla::jni::Object::Param a0) -> void -{ - return mozilla::jni::Method::Call(SurfaceAllocator::Context(), nullptr, a0); -} - const char ViewTransform::name[] = "org/mozilla/gecko/gfx/ViewTransform"; diff --git a/widget/android/GeneratedJNIWrappers.h b/widget/android/GeneratedJNIWrappers.h index 40f0533a161f..308ad170c1c7 100644 --- a/widget/android/GeneratedJNIWrappers.h +++ b/widget/android/GeneratedJNIWrappers.h @@ -3308,23 +3308,6 @@ public: static auto New() -> SurfaceTextureListener::LocalRef; - struct DisposeNative_t { - typedef SurfaceTextureListener Owner; - typedef void ReturnType; - typedef void SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "disposeNative"; - static constexpr char signature[] = - "()V"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::GECKO; - }; - struct OnFrameAvailable_t { typedef SurfaceTextureListener Owner; typedef void ReturnType; @@ -3490,260 +3473,6 @@ public: }; -class GeckoSurface : public mozilla::jni::ObjectBase -{ -public: - static const char name[]; - - explicit GeckoSurface(const Context& ctx) : ObjectBase(ctx) {} - - struct New_t { - typedef GeckoSurface Owner; - typedef GeckoSurface::LocalRef ReturnType; - typedef GeckoSurface::Param SetterType; - typedef mozilla::jni::Args< - mozilla::jni::Object::Param> Args; - static constexpr char name[] = ""; - static constexpr char signature[] = - "(Lorg/mozilla/gecko/gfx/GeckoSurfaceTexture;)V"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::NSRESULT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - static auto New(mozilla::jni::Object::Param, GeckoSurface::LocalRef*) -> nsresult; - - struct GetAvailable_t { - typedef GeckoSurface Owner; - typedef bool ReturnType; - typedef bool SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "getAvailable"; - static constexpr char signature[] = - "()Z"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto GetAvailable() const -> bool; - - struct GetHandle_t { - typedef GeckoSurface Owner; - typedef int32_t ReturnType; - typedef int32_t SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "getHandle"; - static constexpr char signature[] = - "()I"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto GetHandle() const -> int32_t; - - struct SetAvailable_t { - typedef GeckoSurface Owner; - typedef void ReturnType; - typedef void SetterType; - typedef mozilla::jni::Args< - bool> Args; - static constexpr char name[] = "setAvailable"; - static constexpr char signature[] = - "(Z)V"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto SetAvailable(bool) const -> void; - - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - -}; - -class GeckoSurfaceTexture : public mozilla::jni::ObjectBase -{ -public: - static const char name[]; - - explicit GeckoSurfaceTexture(const Context& ctx) : ObjectBase(ctx) {} - - struct GetHandle_t { - typedef GeckoSurfaceTexture Owner; - typedef int32_t ReturnType; - typedef int32_t SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "getHandle"; - static constexpr char signature[] = - "()I"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto GetHandle() const -> int32_t; - - struct GetTexName_t { - typedef GeckoSurfaceTexture Owner; - typedef int32_t ReturnType; - typedef int32_t SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "getTexName"; - static constexpr char signature[] = - "()I"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto GetTexName() const -> int32_t; - - struct IsSingleBuffer_t { - typedef GeckoSurfaceTexture Owner; - typedef bool ReturnType; - typedef bool SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "isSingleBuffer"; - static constexpr char signature[] = - "()Z"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto IsSingleBuffer() const -> bool; - - struct IsSingleBufferSupported_t { - typedef GeckoSurfaceTexture Owner; - typedef bool ReturnType; - typedef bool SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "isSingleBufferSupported"; - static constexpr char signature[] = - "()Z"; - static const bool isStatic = true; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - static auto IsSingleBufferSupported() -> bool; - - struct Lookup_t { - typedef GeckoSurfaceTexture Owner; - typedef GeckoSurfaceTexture::LocalRef ReturnType; - typedef GeckoSurfaceTexture::Param SetterType; - typedef mozilla::jni::Args< - int32_t> Args; - static constexpr char name[] = "lookup"; - static constexpr char signature[] = - "(I)Lorg/mozilla/gecko/gfx/GeckoSurfaceTexture;"; - static const bool isStatic = true; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - static auto Lookup(int32_t) -> GeckoSurfaceTexture::LocalRef; - - struct NativeAcquireTexture_t { - typedef GeckoSurfaceTexture Owner; - typedef int32_t ReturnType; - typedef int32_t SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "nativeAcquireTexture"; - static constexpr char signature[] = - "()I"; - static const bool isStatic = true; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - struct ReleaseTexImage_t { - typedef GeckoSurfaceTexture Owner; - typedef void ReturnType; - typedef void SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "releaseTexImage"; - static constexpr char signature[] = - "()V"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto ReleaseTexImage() const -> void; - - struct UpdateTexImage_t { - typedef GeckoSurfaceTexture Owner; - typedef void ReturnType; - typedef void SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "updateTexImage"; - static constexpr char signature[] = - "()V"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto UpdateTexImage() const -> void; - - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - - template class Natives; -}; - class ImmutableViewportMetrics : public mozilla::jni::ObjectBase { public: @@ -4883,60 +4612,6 @@ public: }; -class SurfaceAllocator : public mozilla::jni::ObjectBase -{ -public: - static const char name[]; - - explicit SurfaceAllocator(const Context& ctx) : ObjectBase(ctx) {} - - struct AcquireSurface_t { - typedef SurfaceAllocator Owner; - typedef mozilla::jni::Object::LocalRef ReturnType; - typedef mozilla::jni::Object::Param SetterType; - typedef mozilla::jni::Args< - int32_t, - int32_t, - bool> Args; - static constexpr char name[] = "acquireSurface"; - static constexpr char signature[] = - "(IIZ)Lorg/mozilla/gecko/gfx/GeckoSurface;"; - static const bool isStatic = true; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - static auto AcquireSurface(int32_t, int32_t, bool) -> mozilla::jni::Object::LocalRef; - - struct DisposeSurface_t { - typedef SurfaceAllocator Owner; - typedef void ReturnType; - typedef void SetterType; - typedef mozilla::jni::Args< - mozilla::jni::Object::Param> Args; - static constexpr char name[] = "disposeSurface"; - static constexpr char signature[] = - "(Lorg/mozilla/gecko/gfx/GeckoSurface;)V"; - static const bool isStatic = true; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - static auto DisposeSurface(mozilla::jni::Object::Param) -> void; - - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::ANY; - -}; - class ViewTransform : public mozilla::jni::ObjectBase { public: diff --git a/widget/android/bindings/AndroidBuild-classes.txt b/widget/android/bindings/AndroidBuild-classes.txt deleted file mode 100644 index e4acfaf812b3..000000000000 --- a/widget/android/bindings/AndroidBuild-classes.txt +++ /dev/null @@ -1,2 +0,0 @@ -[android.os.Build$VERSION] - = noLiteral:true \ No newline at end of file diff --git a/widget/android/bindings/moz.build b/widget/android/bindings/moz.build index 411bdac5b986..455531dfb565 100644 --- a/widget/android/bindings/moz.build +++ b/widget/android/bindings/moz.build @@ -10,7 +10,6 @@ with Files("**"): # List of stems to generate .cpp and .h files for. To add a stem, add it to # this list and ensure that $(stem)-classes.txt exists in this directory. generated = [ - 'AndroidBuild', 'AndroidRect', 'KeyEvent', 'MediaCodec', diff --git a/widget/android/jni/Natives.h b/widget/android/jni/Natives.h index 91e399aa786d..c818c739e196 100644 --- a/widget/android/jni/Natives.h +++ b/widget/android/jni/Natives.h @@ -44,7 +44,7 @@ namespace jni { * * void AttachTo(const MyJavaClass::LocalRef& instance) * { - * MyJavaClass::Natives::AttachNative( + * MyJavaClass::Natives::AttachInstance( * instance, static_cast*>(this)); * * // "instance" does NOT own "this", so the C++ object @@ -70,7 +70,7 @@ namespace jni { * * void AttachTo(const MyJavaClass::LocalRef& instance) * { - * MyJavaClass::Natives::AttachNative(instance, this); + * MyJavaClass::Natives::AttachInstance(instance, this); * * // "instance" owns "this" through the RefPtr, so the C++ object * // may be destroyed as soon as instance.disposeNative() is called. @@ -91,7 +91,7 @@ namespace jni { * * static void AttachTo(const MyJavaClass::LocalRef& instance) * { - * MyJavaClass::Natives::AttachNative( + * MyJavaClass::Natives::AttachInstance( * instance, mozilla::MakeUnique()); * * // "instance" owns the newly created C++ object, so the C++ diff --git a/widget/android/jni/Utils.cpp b/widget/android/jni/Utils.cpp index 1223dcd78513..c065800ed6df 100644 --- a/widget/android/jni/Utils.cpp +++ b/widget/android/jni/Utils.cpp @@ -7,7 +7,6 @@ #include "mozilla/Assertions.h" #include "GeneratedJNIWrappers.h" -#include "AndroidBuild.h" #include "nsAppShell.h" #ifdef MOZ_CRASHREPORTER @@ -313,13 +312,5 @@ bool IsFennec() return sIsFennec; } -int GetAPIVersion() { - static int32_t apiVersion = 0; - if (!apiVersion && IsAvailable()) { - apiVersion = java::sdk::VERSION::SDK_INT(); - } - return apiVersion; -} - } // jni } // mozilla diff --git a/widget/android/jni/Utils.h b/widget/android/jni/Utils.h index 94acb935b775..0d5b07ebb8cd 100644 --- a/widget/android/jni/Utils.h +++ b/widget/android/jni/Utils.h @@ -146,8 +146,6 @@ void DispatchToGeckoPriorityQueue(UniquePtr&& aCall); */ bool IsFennec(); -int GetAPIVersion(); - } // jni } // mozilla