Bug 1322650 - Adjust Android Flash support to API changes r=jchen

MozReview-Commit-ID: CmMINaGcTER
This commit is contained in:
James Willcox 2017-03-09 17:51:17 -06:00
Родитель cf48e4bebd
Коммит 2d93d7d835
7 изменённых файлов: 90 добавлений и 56 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -7,5 +7,10 @@ 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();
}

Просмотреть файл

@ -44,7 +44,7 @@ namespace jni {
*
* void AttachTo(const MyJavaClass::LocalRef& instance)
* {
* MyJavaClass::Natives<MyClass>::AttachInstance(
* MyJavaClass::Natives<MyClass>::AttachNative(
* instance, static_cast<SupportsWeakPtr<MyClass>*>(this));
*
* // "instance" does NOT own "this", so the C++ object
@ -70,7 +70,7 @@ namespace jni {
*
* void AttachTo(const MyJavaClass::LocalRef& instance)
* {
* MyJavaClass::Natives<MyClass>::AttachInstance(instance, this);
* MyJavaClass::Natives<MyClass>::AttachNative(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<MyClass>::AttachInstance(
* MyJavaClass::Natives<MyClass>::AttachNative(
* instance, mozilla::MakeUnique<MyClass>());
*
* // "instance" owns the newly created C++ object, so the C++