Bug 1014614 - Rename nsSurfaceTexture to AndroidSurfaceTexture r=jgilbert

--HG--
extra : rebase_source : 4f148d8a0c2f9ec2d939f9d9939dab897b435bef
This commit is contained in:
James Willcox 2014-10-21 08:53:00 -05:00
parent 49e9ece837
commit 4ccc75ddae
15 changed files with 128 additions and 90 deletions

View File

@ -952,7 +952,7 @@ void nsNPAPIPluginInstance::ReleaseContentTexture(nsNPAPIPluginInstance::Texture
mContentTexture->Release(aTextureInfo);
}
nsSurfaceTexture* nsNPAPIPluginInstance::CreateSurfaceTexture()
AndroidSurfaceTexture* nsNPAPIPluginInstance::CreateSurfaceTexture()
{
if (!EnsureGLContext())
return nullptr;
@ -961,7 +961,7 @@ nsSurfaceTexture* nsNPAPIPluginInstance::CreateSurfaceTexture()
if (!texture)
return nullptr;
nsSurfaceTexture* surface = nsSurfaceTexture::Create(texture);
AndroidSurfaceTexture* surface = AndroidSurfaceTexture::Create(texture);
if (!surface)
return nullptr;
@ -985,7 +985,7 @@ void* nsNPAPIPluginInstance::AcquireContentWindow()
return nullptr;
}
return mContentSurface->GetNativeWindow();
return mContentSurface->NativeWindow()->Handle();
}
EGLImage
@ -997,7 +997,7 @@ nsNPAPIPluginInstance::AsEGLImage()
return mContentTexture->CreateEGLImage();
}
nsSurfaceTexture*
AndroidSurfaceTexture*
nsNPAPIPluginInstance::AsSurfaceTexture()
{
if (!mContentSurface)
@ -1008,13 +1008,13 @@ nsNPAPIPluginInstance::AsSurfaceTexture()
void* nsNPAPIPluginInstance::AcquireVideoWindow()
{
nsSurfaceTexture* surface = CreateSurfaceTexture();
AndroidSurfaceTexture* surface = CreateSurfaceTexture();
if (!surface)
return nullptr;
VideoInfo* info = new VideoInfo(surface);
void* window = info->mSurfaceTexture->GetNativeWindow();
void* window = info->mSurfaceTexture->NativeWindow()->Handle();
mVideos.insert(std::pair<void*, VideoInfo*>(window, info));
return window;

View File

@ -21,7 +21,7 @@
#include "nsAutoPtr.h"
#include "nsIRunnable.h"
#include "GLContextTypes.h"
#include "nsSurfaceTexture.h"
#include "AndroidSurfaceTexture.h"
#include "AndroidBridge.h"
#include <map>
class PluginEventRunnable;
@ -192,12 +192,12 @@ public:
void* AcquireContentWindow();
EGLImage AsEGLImage();
nsSurfaceTexture* AsSurfaceTexture();
mozilla::gl::AndroidSurfaceTexture* AsSurfaceTexture();
// For ANPVideo
class VideoInfo {
public:
VideoInfo(nsSurfaceTexture* aSurfaceTexture) :
VideoInfo(mozilla::gl::AndroidSurfaceTexture* aSurfaceTexture) :
mSurfaceTexture(aSurfaceTexture)
{
}
@ -207,7 +207,7 @@ public:
mSurfaceTexture = nullptr;
}
nsRefPtr<nsSurfaceTexture> mSurfaceTexture;
nsRefPtr<mozilla::gl::AndroidSurfaceTexture> mSurfaceTexture;
gfxRect mDimensions;
};
@ -329,7 +329,7 @@ protected:
bool mInverted;
nsRefPtr<SharedPluginTexture> mContentTexture;
nsRefPtr<nsSurfaceTexture> mContentSurface;
nsRefPtr<mozilla::gl::AndroidSurfaceTexture> mContentSurface;
#endif
enum {
@ -378,7 +378,7 @@ private:
#ifdef MOZ_WIDGET_ANDROID
void EnsureSharedTexture();
nsSurfaceTexture* CreateSurfaceTexture();
mozilla::gl::AndroidSurfaceTexture* CreateSurfaceTexture();
std::map<void*, VideoInfo*> mVideos;
bool mOnScreen;

View File

@ -185,7 +185,7 @@ AttachToContainerAsSurfaceTexture(ImageContainer* container,
MOZ_ASSERT(out_image);
MOZ_ASSERT(!*out_image);
nsSurfaceTexture* surfTex = instance->AsSurfaceTexture();
mozilla::gl::AndroidSurfaceTexture* surfTex = instance->AsSurfaceTexture();
if (!surfTex) {
return;
}

View File

@ -9,15 +9,21 @@
#include <set>
#include <map>
#include <android/log.h>
#include "nsSurfaceTexture.h"
#include "AndroidSurfaceTexture.h"
#include "gfxImageSurface.h"
#include "AndroidBridge.h"
#include "nsThreadUtils.h"
#include "mozilla/gfx/Matrix.h"
#include "GeneratedJNIWrappers.h"
using namespace mozilla;
using namespace mozilla::widget::android;
namespace mozilla {
namespace gl {
// UGH
static std::map<int, nsSurfaceTexture*> sInstances;
static std::map<int, AndroidSurfaceTexture*> sInstances;
static int sNextID = 0;
static class JNIFunctions {
@ -41,6 +47,9 @@ public:
jSurfaceTexture_updateTexImage = env->GetMethodID(jSurfaceTextureClass, "updateTexImage", "()V");
jSurfaceTexture_getTransformMatrix = env->GetMethodID(jSurfaceTextureClass, "getTransformMatrix", "([F)V");
jSurfaceClass = (jclass)env->NewGlobalRef(env->FindClass("android/view/Surface"));
jSurface_Ctor = env->GetMethodID(jSurfaceClass, "<init>", "(Landroid/graphics/SurfaceTexture;)V");
mInitialized = true;
return true;
}
@ -57,6 +66,16 @@ public:
return env->NewGlobalRef(env->NewObject(jSurfaceTextureClass, jSurfaceTexture_Ctor, (int) aTexture));
}
jobject CreateSurface(jobject aSurfaceTexture)
{
if (!EnsureInitialized())
return nullptr;
JNIEnv* env = GetJNIForThread();
AutoLocalJNIFrame jniFrame(env);
return env->NewGlobalRef(env->NewObject(jSurfaceClass, jSurface_Ctor, aSurfaceTexture));
}
void ReleaseSurfaceTexture(jobject aSurfaceTexture)
{
JNIEnv* env = GetJNIForThread();
@ -116,19 +135,21 @@ private:
jmethodID jSurfaceTexture_updateTexImage;
jmethodID jSurfaceTexture_getTransformMatrix;
jclass jSurfaceClass;
jmethodID jSurface_Ctor;
} sJNIFunctions;
nsSurfaceTexture*
nsSurfaceTexture::Create(GLuint aTexture)
AndroidSurfaceTexture*
AndroidSurfaceTexture::Create(GLuint aTexture)
{
// Right now we only support creating this on the main thread because
// of the JNIEnv assumptions in JNIHelper and elsewhere
if (!NS_IsMainThread())
if (AndroidBridge::Bridge()->GetAPIVersion() < 14 /* Ice Cream Sandwich */) {
return nullptr;
}
nsSurfaceTexture* st = new nsSurfaceTexture();
AndroidSurfaceTexture* st = new AndroidSurfaceTexture();
if (!st->Init(aTexture)) {
printf_stderr("Failed to initialize nsSurfaceTexture");
printf_stderr("Failed to initialize AndroidSurfaceTexture");
delete st;
st = nullptr;
}
@ -136,10 +157,10 @@ nsSurfaceTexture::Create(GLuint aTexture)
return st;
}
nsSurfaceTexture*
nsSurfaceTexture::Find(int id)
AndroidSurfaceTexture*
AndroidSurfaceTexture::Find(int id)
{
std::map<int, nsSurfaceTexture*>::iterator it;
std::map<int, AndroidSurfaceTexture*>::iterator it;
it = sInstances.find(id);
if (it == sInstances.end())
@ -149,13 +170,13 @@ nsSurfaceTexture::Find(int id)
}
bool
nsSurfaceTexture::Check()
AndroidSurfaceTexture::Check()
{
return sJNIFunctions.EnsureInitialized();
}
bool
nsSurfaceTexture::Init(GLuint aTexture)
AndroidSurfaceTexture::Init(GLuint aTexture)
{
if (!sJNIFunctions.EnsureInitialized())
return false;
@ -163,80 +184,80 @@ nsSurfaceTexture::Init(GLuint aTexture)
JNIEnv* env = GetJNIForThread();
mSurfaceTexture = sJNIFunctions.CreateSurfaceTexture(aTexture);
if (!mSurfaceTexture)
if (!mSurfaceTexture) {
return false;
}
mNativeWindow = AndroidBridge::Bridge()->AcquireNativeWindowFromSurfaceTexture(env, mSurfaceTexture);
mSurface = sJNIFunctions.CreateSurface(mSurfaceTexture);
if (!mSurface) {
return false;
}
mID = ++sNextID;
sInstances.insert(std::pair<int, nsSurfaceTexture*>(mID, this));
sInstances.insert(std::pair<int, AndroidSurfaceTexture*>(mID, this));
mTexture = aTexture;
return true;
}
nsSurfaceTexture::nsSurfaceTexture()
: mSurfaceTexture(nullptr), mNativeWindow(nullptr)
AndroidSurfaceTexture::AndroidSurfaceTexture()
: mTexture(0), mSurfaceTexture(nullptr), mSurface(nullptr)
{
}
nsSurfaceTexture::~nsSurfaceTexture()
AndroidSurfaceTexture::~AndroidSurfaceTexture()
{
sInstances.erase(mID);
mFrameAvailableCallback = nullptr;
if (mNativeWindow) {
AndroidBridge::Bridge()->ReleaseNativeWindowForSurfaceTexture(mSurfaceTexture);
mNativeWindow = nullptr;
}
JNIEnv* env = GetJNIForThread();
if (mSurfaceTexture) {
mozilla::widget::android::GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
env->DeleteGlobalRef(mSurfaceTexture);
mSurfaceTexture = nullptr;
}
}
void*
nsSurfaceTexture::GetNativeWindow()
{
return mNativeWindow;
if (mSurface) {
env->DeleteGlobalRef(mSurface);
mSurface = nullptr;
}
}
void
nsSurfaceTexture::UpdateTexImage()
AndroidSurfaceTexture::UpdateTexImage()
{
sJNIFunctions.UpdateTexImage(mSurfaceTexture);
}
bool
nsSurfaceTexture::GetTransformMatrix(gfx::Matrix4x4& aMatrix)
AndroidSurfaceTexture::GetTransformMatrix(gfx::Matrix4x4& aMatrix)
{
return sJNIFunctions.GetTransformMatrix(mSurfaceTexture, aMatrix);
}
void
nsSurfaceTexture::SetFrameAvailableCallback(nsIRunnable* aRunnable)
AndroidSurfaceTexture::SetFrameAvailableCallback(nsIRunnable* aRunnable)
{
if (aRunnable)
mozilla::widget::android::GeckoAppShell::RegisterSurfaceTextureFrameListener(mSurfaceTexture, mID);
GeckoAppShell::RegisterSurfaceTextureFrameListener(mSurfaceTexture, mID);
else
mozilla::widget::android::GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
mFrameAvailableCallback = aRunnable;
}
void
nsSurfaceTexture::NotifyFrameAvailable()
AndroidSurfaceTexture::NotifyFrameAvailable()
{
if (mFrameAvailableCallback) {
// Proxy to main thread if we aren't on it
if (!NS_IsMainThread()) {
// Proxy to main thread
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &nsSurfaceTexture::NotifyFrameAvailable);
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &AndroidSurfaceTexture::NotifyFrameAvailable);
NS_DispatchToCurrentThread(event);
} else {
mFrameAvailableCallback->Run();
@ -244,4 +265,7 @@ nsSurfaceTexture::NotifyFrameAvailable()
}
}
} // gl
} // mozilla
#endif // MOZ_WIDGET_ANDROID

View File

@ -4,8 +4,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/. */
#ifndef nsSurfaceTexture_h__
#define nsSurfaceTexture_h__
#ifndef AndroidSurfaceTexture_h__
#define AndroidSurfaceTexture_h__
#ifdef MOZ_WIDGET_ANDROID
#include <jni.h>
@ -13,31 +13,36 @@
#include "gfxPlatform.h"
#include "GLDefs.h"
#include "AndroidNativeWindow.h"
class gfxASurface;
namespace mozilla {
namespace gfx {
class Matrix4x4;
}
}
namespace mozilla {
namespace gl {
/**
* 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 nsSurfaceTexture MOZ_FINAL {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsSurfaceTexture)
class AndroidSurfaceTexture {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidSurfaceTexture)
public:
static nsSurfaceTexture* Create(GLuint aTexture);
static nsSurfaceTexture* Find(int id);
static AndroidSurfaceTexture* Create(GLuint aTexture);
static AndroidSurfaceTexture* Find(int id);
// Returns with reasonable certainty whether or not we'll
// be able to create and use a SurfaceTexture
static bool Check();
// This is an ANativeWindow. Use AndroidBridge::LockWindow and
// friends for manipulating it.
void* GetNativeWindow();
~AndroidSurfaceTexture();
// This attaches the updated data to the TEXTURE_EXTERNAL target
void UpdateTexImage();
@ -52,19 +57,24 @@ public:
// Only should be called by AndroidJNI when we get a
// callback from the underlying SurfaceTexture instance
void NotifyFrameAvailable();
private:
nsSurfaceTexture();
// Private destructor, to discourage deletion outside of Release():
~nsSurfaceTexture();
GLuint Texture() { return mTexture; }
private:
AndroidSurfaceTexture();
bool Init(GLuint aTexture);
GLuint mTexture;
jobject mSurfaceTexture;
void* mNativeWindow;
jobject mSurface;
int mID;
nsRefPtr<nsIRunnable> mFrameAvailableCallback;
};
}
}
#endif
#endif

View File

@ -25,7 +25,6 @@
/* from widget */
#if defined(MOZ_WIDGET_ANDROID)
#include "AndroidBridge.h"
#include "nsSurfaceTexture.h"
#endif
#include <android/log.h>

View File

@ -26,6 +26,7 @@ if CONFIG['MOZ_GL_PROVIDER']:
gl_provider = CONFIG['MOZ_GL_PROVIDER']
EXPORTS += [
'AndroidSurfaceTexture.h',
'DecomposeIntoNoRepeatTriangles.h',
'EGLUtils.h',
'ForceDiscreteGPUHelperCGL.h',
@ -114,6 +115,7 @@ else:
]
UNIFIED_SOURCES += [
'AndroidSurfaceTexture.cpp',
'DecomposeIntoNoRepeatTriangles.cpp',
'EGLUtils.cpp',
'GfxTexturesReporter.cpp',

View File

@ -12,9 +12,10 @@
#include "nsCOMPtr.h" // for already_AddRefed
#include "mozilla/gfx/Point.h" // for IntSize
class nsSurfaceTexture;
namespace mozilla {
namespace gl {
class AndroidSurfaceTexture;
}
namespace layers {
class EGLImageImage : public Image {
@ -46,7 +47,7 @@ private:
class SurfaceTextureImage : public Image {
public:
struct Data {
nsSurfaceTexture* mSurfTex;
mozilla::gl::AndroidSurfaceTexture* mSurfTex;
gfx::IntSize mSize;
bool mInverted;
};

View File

@ -78,7 +78,7 @@ EGLImageTextureClient::Unlock()
#ifdef MOZ_WIDGET_ANDROID
SurfaceTextureClient::SurfaceTextureClient(TextureFlags aFlags,
nsSurfaceTexture* aSurfTex,
AndroidSurfaceTexture* aSurfTex,
gfx::IntSize aSize,
bool aInverted)
: TextureClient(aFlags)

View File

@ -13,9 +13,10 @@
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
#include "mozilla/layers/TextureClient.h" // for TextureClient, etc
#include "nsSurfaceTexture.h"
#include "AndroidSurfaceTexture.h"
namespace mozilla {
namespace layers {
class CompositableForwarder;
@ -74,7 +75,7 @@ class SurfaceTextureClient : public TextureClient
{
public:
SurfaceTextureClient(TextureFlags aFlags,
nsSurfaceTexture* aSurfTex,
gl::AndroidSurfaceTexture* aSurfTex,
gfx::IntSize aSize,
bool aInverted);
@ -113,7 +114,7 @@ public:
}
protected:
const nsRefPtr<nsSurfaceTexture> mSurfTex;
const RefPtr<gl::AndroidSurfaceTexture> mSurfTex;
const gfx::IntSize mSize;
bool mIsLocked;
};

View File

@ -23,7 +23,7 @@
#include "mozilla/layers/GrallocTextureHost.h"
#include "nsPoint.h" // for nsIntPoint
#include "nsRegion.h" // for nsIntRegion
#include "nsSurfaceTexture.h"
#include "AndroidSurfaceTexture.h"
#include "GfxTexturesReporter.h" // for GfxTexturesReporter
#include "GLBlitTextureImageHelper.h"
#ifdef XP_MACOSX
@ -68,7 +68,7 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
case SurfaceDescriptor::TSurfaceTextureDescriptor: {
const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor();
result = new SurfaceTextureHost(aFlags,
(nsSurfaceTexture*)desc.surfTex(),
(AndroidSurfaceTexture*)desc.surfTex(),
desc.size());
break;
}
@ -578,7 +578,7 @@ GLTextureSource::gl() const
#ifdef MOZ_WIDGET_ANDROID
SurfaceTextureSource::SurfaceTextureSource(CompositorOGL* aCompositor,
nsSurfaceTexture* aSurfTex,
AndroidSurfaceTexture* aSurfTex,
gfx::SurfaceFormat aFormat,
GLenum aTarget,
GLenum aWrapMode,
@ -643,7 +643,7 @@ SurfaceTextureSource::GetTextureTransform()
////////////////////////////////////////////////////////////////////////
SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags,
nsSurfaceTexture* aSurfTex,
AndroidSurfaceTexture* aSurfTex,
gfx::IntSize aSize)
: TextureHost(aFlags)
, mSurfTex(aSurfTex)

View File

@ -39,7 +39,6 @@
class gfxReusableSurfaceWrapper;
class nsIntRegion;
class nsSurfaceTexture;
struct nsIntPoint;
struct nsIntRect;
struct nsIntSize;
@ -49,6 +48,10 @@ namespace gfx {
class DataSourceSurface;
}
namespace gl {
class AndroidSurfaceTexture;
}
namespace layers {
class Compositor;
@ -413,7 +416,7 @@ class SurfaceTextureSource : public TextureSource
{
public:
SurfaceTextureSource(CompositorOGL* aCompositor,
nsSurfaceTexture* aSurfTex,
mozilla::gl::AndroidSurfaceTexture* aSurfTex,
gfx::SurfaceFormat aFormat,
GLenum aTarget,
GLenum aWrapMode,
@ -444,7 +447,7 @@ public:
protected:
RefPtr<CompositorOGL> mCompositor;
nsSurfaceTexture* const mSurfTex;
mozilla::gl::AndroidSurfaceTexture* const mSurfTex;
const gfx::SurfaceFormat mFormat;
const GLenum mTextureTarget;
const GLenum mWrapMode;
@ -455,7 +458,7 @@ class SurfaceTextureHost : public TextureHost
{
public:
SurfaceTextureHost(TextureFlags aFlags,
nsSurfaceTexture* aSurfTex,
mozilla::gl::AndroidSurfaceTexture* aSurfTex,
gfx::IntSize aSize);
virtual ~SurfaceTextureHost();
@ -488,7 +491,7 @@ public:
virtual const char* Name() { return "SurfaceTextureHost"; }
protected:
nsSurfaceTexture* const mSurfTex;
mozilla::gl::AndroidSurfaceTexture* const mSurfTex;
const gfx::IntSize mSize;
RefPtr<CompositorOGL> mCompositor;
RefPtr<SurfaceTextureSource> mTextureSource;

View File

@ -12,7 +12,7 @@ namespace gl {
// A texture pool for for the on-screen GLContext. The main purpose of this class
// is to provide the ability to easily allocate an on-screen texture from the
// content thread. The unfortunate nature of the SurfaceTexture API (see nsSurfaceTexture)
// content thread. The unfortunate nature of the SurfaceTexture API (see AndroidSurfaceTexture)
// necessitates this.
class TexturePoolOGL
{

View File

@ -49,7 +49,6 @@ EXPORTS += [
'gfxUserFontSet.h',
'gfxUtils.h',
'GraphicsFilter.h',
'nsSurfaceTexture.h',
'RoundedRect.h',
]
@ -242,7 +241,6 @@ UNIFIED_SOURCES += [
'gfxTextRun.cpp',
'gfxUserFontSet.cpp',
'gfxUtils.cpp',
'nsSurfaceTexture.cpp',
'nsUnicodeRange.cpp',
]

View File

@ -40,7 +40,7 @@
#include "mozilla/layers/APZCTreeManager.h"
#include "nsIMobileMessageDatabaseService.h"
#include "nsPluginInstanceOwner.h"
#include "nsSurfaceTexture.h"
#include "AndroidSurfaceTexture.h"
#include "GeckoProfiler.h"
#include "nsMemoryPressure.h"
@ -862,9 +862,9 @@ Java_org_mozilla_gecko_GeckoAppShell_getNextMessageFromQueue(JNIEnv* jenv, jclas
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_onSurfaceTextureFrameAvailable(JNIEnv* jenv, jclass, jobject surfaceTexture, jint id)
{
nsSurfaceTexture* st = nsSurfaceTexture::Find(id);
mozilla::gl::AndroidSurfaceTexture* st = mozilla::gl::AndroidSurfaceTexture::Find(id);
if (!st) {
__android_log_print(ANDROID_LOG_ERROR, "GeckoJNI", "Failed to find nsSurfaceTexture with id %d", id);
__android_log_print(ANDROID_LOG_ERROR, "GeckoJNI", "Failed to find AndroidSurfaceTexture with id %d", id);
return;
}