summaryrefslogtreecommitdiffstats
path: root/gfx/gl
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-12-27 13:11:19 +0000
committerMoonchild <moonchild@palemoon.org>2020-12-27 13:11:19 +0000
commite011a048e431bd850bfd42b5fb8c6eec0b6b878e (patch)
tree5dce377b66881be11b3c4fffaac9cedd930c835f /gfx/gl
parent8d4456c797eea9236f4d84cdb23d85ce670152dc (diff)
downloadUXP-e011a048e431bd850bfd42b5fb8c6eec0b6b878e.tar
UXP-e011a048e431bd850bfd42b5fb8c6eec0b6b878e.tar.gz
UXP-e011a048e431bd850bfd42b5fb8c6eec0b6b878e.tar.lz
UXP-e011a048e431bd850bfd42b5fb8c6eec0b6b878e.tar.xz
UXP-e011a048e431bd850bfd42b5fb8c6eec0b6b878e.zip
Issue #1053 - Part 3b: Remove AndroidSurfaceTexture and Android media decoder
interface.
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/AndroidSurfaceTexture.cpp260
-rw-r--r--gfx/gl/AndroidSurfaceTexture.h107
-rw-r--r--gfx/gl/moz.build2
3 files changed, 0 insertions, 369 deletions
diff --git a/gfx/gl/AndroidSurfaceTexture.cpp b/gfx/gl/AndroidSurfaceTexture.cpp
deleted file mode 100644
index 3c8c81974..000000000
--- a/gfx/gl/AndroidSurfaceTexture.cpp
+++ /dev/null
@@ -1,260 +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/. */
-
-#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 "GeneratedJNINatives.h"
-#include "GLContext.h"
-
-using namespace mozilla;
-
-namespace mozilla {
-namespace gl {
-
-class AndroidSurfaceTexture::Listener
- : public java::SurfaceTextureListener::Natives<Listener>
-{
- using Base = java::SurfaceTextureListener::Natives<Listener>;
-
- const nsCOMPtr<nsIRunnable> 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>
-AndroidSurfaceTexture::Create()
-{
- return Create(nullptr, 0);
-}
-
-already_AddRefed<AndroidSurfaceTexture>
-AndroidSurfaceTexture::Create(GLContext* aContext, GLuint aTexture)
-{
- RefPtr<AndroidSurfaceTexture> 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::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));
- mSurfaceTexture->GetTransformMatrix(jarray);
-
- jfloat* array = env->GetFloatArrayElements(jarray.Get(), nullptr);
-
- aMatrix._11 = array[0];
- aMatrix._12 = array[1];
- aMatrix._13 = array[2];
- aMatrix._14 = array[3];
-
- aMatrix._21 = array[4];
- aMatrix._22 = array[5];
- aMatrix._23 = array[6];
- aMatrix._24 = array[7];
-
- aMatrix._31 = array[8];
- aMatrix._32 = array[9];
- aMatrix._33 = array[10];
- aMatrix._34 = array[11];
-
- aMatrix._41 = array[12];
- aMatrix._42 = array[13];
- aMatrix._43 = array[14];
- aMatrix._44 = array[15];
-
- 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<Listener>(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
deleted file mode 100644
index 056fab326..000000000
--- a/gfx/gl/AndroidSurfaceTexture.h
+++ /dev/null
@@ -1,107 +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 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 "GeneratedJNIWrappers.h"
-#include "SurfaceTexture.h"
-
-namespace mozilla {
-namespace gl {
-
-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<AndroidSurfaceTexture> 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<AndroidSurfaceTexture> 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;
-};
-
-}
-}
-
-
-#endif
-#endif
diff --git a/gfx/gl/moz.build b/gfx/gl/moz.build
index d5287ca59..c490400cb 100644
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -21,7 +21,6 @@ if CONFIG['MOZ_GL_PROVIDER']:
gl_provider = CONFIG['MOZ_GL_PROVIDER']
EXPORTS += [
- 'AndroidSurfaceTexture.h',
'DecomposeIntoNoRepeatTriangles.h',
'EGLUtils.h',
'ForceDiscreteGPUHelperCGL.h',
@@ -116,7 +115,6 @@ elif gl_provider == 'GLX':
]
SOURCES += [
- 'AndroidSurfaceTexture.cpp',
'DecomposeIntoNoRepeatTriangles.cpp',
'EGLUtils.cpp',
'GfxTexturesReporter.cpp',