Backed out changeset d6516a10c808 (bug 1322650)

This commit is contained in:
Sebastian Hengst 2017-05-05 18:53:40 +02:00
parent 2340610625
commit f3bfd1e1da
7 changed files with 56 additions and 90 deletions

View file

@ -58,8 +58,6 @@ using namespace mozilla::dom;
#include "TexturePoolOGL.h" #include "TexturePoolOGL.h"
#include "SurfaceTypes.h" #include "SurfaceTypes.h"
#include "EGLUtils.h" #include "EGLUtils.h"
#include "GeneratedJNIWrappers.h"
#include "GeneratedJNINatives.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::gl; using namespace mozilla::gl;
@ -108,7 +106,7 @@ static bool EnsureGLContext()
static std::map<NPP, nsNPAPIPluginInstance*> sPluginNPPMap; static std::map<NPP, nsNPAPIPluginInstance*> sPluginNPPMap;
#endif // MOZ_WIDGET_ANDROID #endif
using namespace mozilla; using namespace mozilla;
using namespace mozilla::plugins::parent; using namespace mozilla::plugins::parent;
@ -204,12 +202,14 @@ nsNPAPIPluginInstance::Destroy()
mAudioChannelAgent = nullptr; mAudioChannelAgent = nullptr;
#if MOZ_WIDGET_ANDROID #if MOZ_WIDGET_ANDROID
if (mContentSurface) { if (mContentSurface)
java::SurfaceAllocator::DisposeSurface(mContentSurface); mContentSurface->SetFrameAvailableCallback(nullptr);
}
mContentSurface = nullptr;
std::map<void*, VideoInfo*>::iterator it; std::map<void*, VideoInfo*>::iterator it;
for (it = mVideos.begin(); it != mVideos.end(); it++) { for (it = mVideos.begin(); it != mVideos.end(); it++) {
it->second->mSurfaceTexture->SetFrameAvailableCallback(nullptr);
delete it->second; delete it->second;
} }
mVideos.clear(); mVideos.clear();
@ -858,50 +858,24 @@ GLContext* nsNPAPIPluginInstance::GLContext()
return sPluginContext; return sPluginContext;
} }
class PluginTextureListener already_AddRefed<AndroidSurfaceTexture> nsNPAPIPluginInstance::CreateSurfaceTexture()
: public java::SurfaceTextureListener::Natives<PluginTextureListener>
{ {
using Base = java::SurfaceTextureListener::Natives<PluginTextureListener>; if (!EnsureGLContext())
return nullptr;
const nsCOMPtr<nsIRunnable> mCallback; GLuint texture = TexturePoolOGL::AcquireTexture();
public: if (!texture)
using Base::AttachNative; return nullptr;
using Base::DisposeNative;
PluginTextureListener(nsIRunnable* aCallback) : mCallback(aCallback) {} RefPtr<AndroidSurfaceTexture> surface = AndroidSurfaceTexture::Create(TexturePoolOGL::GetGLContext(),
texture);
void OnFrameAvailable() if (!surface) {
{
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) {
return nullptr; return nullptr;
} }
nsCOMPtr<nsIRunnable> frameCallback = NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable); nsCOMPtr<nsIRunnable> frameCallback = NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable);
surface->SetFrameAvailableCallback(frameCallback);
java::SurfaceTextureListener::LocalRef listener = java::SurfaceTextureListener::New(); return surface.forget();
PluginTextureListener::AttachNative(listener, MakeUnique<PluginTextureListener>(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;
} }
void nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable() void nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable()
@ -912,29 +886,35 @@ void nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable()
void* nsNPAPIPluginInstance::AcquireContentWindow() void* nsNPAPIPluginInstance::AcquireContentWindow()
{ {
if (!mContentWindow.NativeWindow()) { if (!mContentSurface) {
mContentSurface = CreateSurface(); mContentSurface = CreateSurfaceTexture();
if (!mContentSurface) if (!mContentSurface)
return nullptr; return nullptr;
mContentWindow = AndroidNativeWindow(mContentSurface);
} }
return mContentWindow.NativeWindow(); return mContentSurface->NativeWindow();
} }
java::GeckoSurface::Param AndroidSurfaceTexture*
nsNPAPIPluginInstance::AsSurface() nsNPAPIPluginInstance::AsSurfaceTexture()
{ {
if (!mContentSurface)
return nullptr;
return mContentSurface; return mContentSurface;
} }
void* nsNPAPIPluginInstance::AcquireVideoWindow() void* nsNPAPIPluginInstance::AcquireVideoWindow()
{ {
java::GeckoSurface::LocalRef surface = CreateSurface(); RefPtr<AndroidSurfaceTexture> surface = CreateSurfaceTexture();
if (!surface) {
return nullptr;
}
VideoInfo* info = new VideoInfo(surface); VideoInfo* info = new VideoInfo(surface);
void* window = info->mNativeWindow.NativeWindow(); void* window = info->mSurfaceTexture->NativeWindow();
mVideos.insert(std::pair<void*, VideoInfo*>(window, info)); mVideos.insert(std::pair<void*, VideoInfo*>(window, info));
return window; return window;

View file

@ -21,7 +21,7 @@
#ifdef MOZ_WIDGET_ANDROID #ifdef MOZ_WIDGET_ANDROID
#include "nsIRunnable.h" #include "nsIRunnable.h"
#include "GLContextTypes.h" #include "GLContextTypes.h"
#include "AndroidNativeWindow.h" #include "AndroidSurfaceTexture.h"
#include "AndroidBridge.h" #include "AndroidBridge.h"
#include <map> #include <map>
class PluginEventRunnable; class PluginEventRunnable;
@ -215,24 +215,22 @@ public:
// For ANPNativeWindow // For ANPNativeWindow
void* AcquireContentWindow(); void* AcquireContentWindow();
mozilla::java::GeckoSurface::Param AsSurface(); mozilla::gl::AndroidSurfaceTexture* AsSurfaceTexture();
// For ANPVideo // For ANPVideo
class VideoInfo { class VideoInfo {
public: public:
VideoInfo(mozilla::java::GeckoSurface::Param aSurface) VideoInfo(mozilla::gl::AndroidSurfaceTexture* aSurfaceTexture) :
: mSurface(aSurface) mSurfaceTexture(aSurfaceTexture)
, mNativeWindow(aSurface)
{ {
} }
~VideoInfo() ~VideoInfo()
{ {
mozilla::java::SurfaceAllocator::DisposeSurface(mSurface); mSurfaceTexture = nullptr;
} }
mozilla::java::GeckoSurface::GlobalRef mSurface; RefPtr<mozilla::gl::AndroidSurfaceTexture> mSurfaceTexture;
mozilla::gl::AndroidNativeWindow mNativeWindow;
gfxRect mDimensions; gfxRect mDimensions;
}; };
@ -361,8 +359,7 @@ protected:
bool mFullScreen; bool mFullScreen;
mozilla::gl::OriginPos mOriginPos; mozilla::gl::OriginPos mOriginPos;
mozilla::java::GeckoSurface::GlobalRef mContentSurface; RefPtr<mozilla::gl::AndroidSurfaceTexture> mContentSurface;
mozilla::gl::AndroidNativeWindow mContentWindow;
#endif #endif
enum { enum {
@ -412,7 +409,8 @@ private:
mozilla::TimeStamp mStopTime; mozilla::TimeStamp mStopTime;
#ifdef MOZ_WIDGET_ANDROID #ifdef MOZ_WIDGET_ANDROID
mozilla::java::GeckoSurface::LocalRef CreateSurface(); already_AddRefed<mozilla::gl::AndroidSurfaceTexture> CreateSurfaceTexture();
std::map<void*, VideoInfo*> mVideos; std::map<void*, VideoInfo*> mVideos;
bool mOnScreen; bool mOnScreen;

View file

@ -165,23 +165,22 @@ nsPluginInstanceOwner::NotifyPaintWaiter(nsDisplayListBuilder* aBuilder)
#if MOZ_WIDGET_ANDROID #if MOZ_WIDGET_ANDROID
static void static void
AttachToContainerAsSurface(ImageContainer* container, AttachToContainerAsSurfaceTexture(ImageContainer* container,
nsNPAPIPluginInstance* instance, nsNPAPIPluginInstance* instance,
const LayoutDeviceRect& rect, const LayoutDeviceRect& rect,
RefPtr<Image>* out_image) RefPtr<Image>* out_image)
{ {
MOZ_ASSERT(out_image); MOZ_ASSERT(out_image);
MOZ_ASSERT(!*out_image); MOZ_ASSERT(!*out_image);
java::GeckoSurface::LocalRef surface = instance->AsSurface(); mozilla::gl::AndroidSurfaceTexture* surfTex = instance->AsSurfaceTexture();
if (!surface) { if (!surfTex) {
return; return;
} }
RefPtr<Image> img = new SurfaceTextureImage( RefPtr<Image> img = new SurfaceTextureImage(
surface->GetHandle(), surfTex,
gfx::IntSize::Truncate(rect.width, rect.height), gfx::IntSize::Truncate(rect.width, rect.height),
true, // continuously update without a transaction
instance->OriginPos()); instance->OriginPos());
*out_image = img; *out_image = img;
} }
@ -224,7 +223,7 @@ nsPluginInstanceOwner::GetImageContainer()
if (r.width && r.height) { if (r.width && r.height) {
// Try to get it as an EGLImage first. // Try to get it as an EGLImage first.
RefPtr<Image> img; RefPtr<Image> img;
AttachToContainerAsSurface(container, mInstance, r, &img); AttachToContainerAsSurfaceTexture(container, mInstance, r, &img);
if (img) { if (img) {
container->SetCurrentImageInTransaction(img); container->SetCurrentImageInTransaction(img);
@ -1586,9 +1585,8 @@ nsPluginInstanceOwner::GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInf
if (aVideoInfo->mDimensions.width && aVideoInfo->mDimensions.height) { if (aVideoInfo->mDimensions.width && aVideoInfo->mDimensions.height) {
RefPtr<Image> img = new SurfaceTextureImage( RefPtr<Image> img = new SurfaceTextureImage(
aVideoInfo->mSurface->GetHandle(), aVideoInfo->mSurfaceTexture,
gfx::IntSize::Truncate(aVideoInfo->mDimensions.width, aVideoInfo->mDimensions.height), gfx::IntSize::Truncate(aVideoInfo->mDimensions.width, aVideoInfo->mDimensions.height),
true, /* continuous */
gl::OriginPos::BottomLeft); gl::OriginPos::BottomLeft);
container->SetCurrentImageInTransaction(img); container->SetCurrentImageInTransaction(img);
} }

View file

@ -19,9 +19,6 @@ namespace gl {
class AndroidNativeWindow { class AndroidNativeWindow {
public: public:
AndroidNativeWindow() : mNativeWindow(nullptr) {
}
AndroidNativeWindow(java::sdk::Surface::Param aSurface) { AndroidNativeWindow(java::sdk::Surface::Param aSurface) {
mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(), mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(),
aSurface.Get()); aSurface.Get());

View file

@ -17,12 +17,10 @@ final class SurfaceTextureListener
private SurfaceTextureListener() { private SurfaceTextureListener() {
} }
@WrapForJNI(dispatchTo = "gecko") @Override // JNIObject
protected native void disposeNative();
@Override @Override
protected void finalize() { protected void disposeNative() {
disposeNative(); // SurfaceTextureListener is disposed inside AndroidSurfaceTexture.
throw new IllegalStateException("unreachable code");
} }
@WrapForJNI(stubName = "OnFrameAvailable") @WrapForJNI(stubName = "OnFrameAvailable")

View file

@ -7,10 +7,5 @@ public abstract class JNIObject
private long mHandle; private long mHandle;
// Dispose of any reference to a native object. // 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(); protected abstract void disposeNative();
} }

View file

@ -44,7 +44,7 @@ namespace jni {
* *
* void AttachTo(const MyJavaClass::LocalRef& instance) * void AttachTo(const MyJavaClass::LocalRef& instance)
* { * {
* MyJavaClass::Natives<MyClass>::AttachNative( * MyJavaClass::Natives<MyClass>::AttachInstance(
* instance, static_cast<SupportsWeakPtr<MyClass>*>(this)); * instance, static_cast<SupportsWeakPtr<MyClass>*>(this));
* *
* // "instance" does NOT own "this", so the C++ object * // "instance" does NOT own "this", so the C++ object
@ -70,7 +70,7 @@ namespace jni {
* *
* void AttachTo(const MyJavaClass::LocalRef& instance) * void AttachTo(const MyJavaClass::LocalRef& instance)
* { * {
* MyJavaClass::Natives<MyClass>::AttachNative(instance, this); * MyJavaClass::Natives<MyClass>::AttachInstance(instance, this);
* *
* // "instance" owns "this" through the RefPtr, so the C++ object * // "instance" owns "this" through the RefPtr, so the C++ object
* // may be destroyed as soon as instance.disposeNative() is called. * // may be destroyed as soon as instance.disposeNative() is called.
@ -91,7 +91,7 @@ namespace jni {
* *
* static void AttachTo(const MyJavaClass::LocalRef& instance) * static void AttachTo(const MyJavaClass::LocalRef& instance)
* { * {
* MyJavaClass::Natives<MyClass>::AttachNative( * MyJavaClass::Natives<MyClass>::AttachInstance(
* instance, mozilla::MakeUnique<MyClass>()); * instance, mozilla::MakeUnique<MyClass>());
* *
* // "instance" owns the newly created C++ object, so the C++ * // "instance" owns the newly created C++ object, so the C++