mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 04:09:50 +00:00
Backed out changeset d6516a10c808 (bug 1322650)
This commit is contained in:
parent
2340610625
commit
f3bfd1e1da
@ -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<NPP, nsNPAPIPluginInstance*> 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<void*, VideoInfo*>::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<PluginTextureListener>
|
||||
already_AddRefed<AndroidSurfaceTexture> nsNPAPIPluginInstance::CreateSurfaceTexture()
|
||||
{
|
||||
using Base = java::SurfaceTextureListener::Natives<PluginTextureListener>;
|
||||
if (!EnsureGLContext())
|
||||
return nullptr;
|
||||
|
||||
const nsCOMPtr<nsIRunnable> 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<AndroidSurfaceTexture> surface = AndroidSurfaceTexture::Create(TexturePoolOGL::GetGLContext(),
|
||||
texture);
|
||||
if (!surface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRunnable> frameCallback = NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable);
|
||||
|
||||
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;
|
||||
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<AndroidSurfaceTexture> 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<void*, VideoInfo*>(window, info));
|
||||
|
||||
return window;
|
||||
|
@ -21,7 +21,7 @@
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
#include "nsIRunnable.h"
|
||||
#include "GLContextTypes.h"
|
||||
#include "AndroidNativeWindow.h"
|
||||
#include "AndroidSurfaceTexture.h"
|
||||
#include "AndroidBridge.h"
|
||||
#include <map>
|
||||
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<mozilla::gl::AndroidSurfaceTexture> mSurfaceTexture;
|
||||
gfxRect mDimensions;
|
||||
};
|
||||
|
||||
@ -361,8 +359,7 @@ protected:
|
||||
bool mFullScreen;
|
||||
mozilla::gl::OriginPos mOriginPos;
|
||||
|
||||
mozilla::java::GeckoSurface::GlobalRef mContentSurface;
|
||||
mozilla::gl::AndroidNativeWindow mContentWindow;
|
||||
RefPtr<mozilla::gl::AndroidSurfaceTexture> mContentSurface;
|
||||
#endif
|
||||
|
||||
enum {
|
||||
@ -412,7 +409,8 @@ private:
|
||||
mozilla::TimeStamp mStopTime;
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
mozilla::java::GeckoSurface::LocalRef CreateSurface();
|
||||
already_AddRefed<mozilla::gl::AndroidSurfaceTexture> CreateSurfaceTexture();
|
||||
|
||||
std::map<void*, VideoInfo*> mVideos;
|
||||
bool mOnScreen;
|
||||
|
||||
|
@ -165,23 +165,22 @@ nsPluginInstanceOwner::NotifyPaintWaiter(nsDisplayListBuilder* aBuilder)
|
||||
|
||||
#if MOZ_WIDGET_ANDROID
|
||||
static void
|
||||
AttachToContainerAsSurface(ImageContainer* container,
|
||||
nsNPAPIPluginInstance* instance,
|
||||
const LayoutDeviceRect& rect,
|
||||
RefPtr<Image>* out_image)
|
||||
AttachToContainerAsSurfaceTexture(ImageContainer* container,
|
||||
nsNPAPIPluginInstance* instance,
|
||||
const LayoutDeviceRect& rect,
|
||||
RefPtr<Image>* 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<Image> 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<Image> 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<Image> 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);
|
||||
}
|
||||
|
@ -19,9 +19,6 @@ namespace gl {
|
||||
|
||||
class AndroidNativeWindow {
|
||||
public:
|
||||
AndroidNativeWindow() : mNativeWindow(nullptr) {
|
||||
}
|
||||
|
||||
AndroidNativeWindow(java::sdk::Surface::Param aSurface) {
|
||||
mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(),
|
||||
aSurface.Get());
|
||||
|
@ -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")
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ namespace jni {
|
||||
*
|
||||
* void AttachTo(const MyJavaClass::LocalRef& instance)
|
||||
* {
|
||||
* MyJavaClass::Natives<MyClass>::AttachNative(
|
||||
* MyJavaClass::Natives<MyClass>::AttachInstance(
|
||||
* 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>::AttachNative(instance, this);
|
||||
* MyJavaClass::Natives<MyClass>::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<MyClass>::AttachNative(
|
||||
* MyJavaClass::Natives<MyClass>::AttachInstance(
|
||||
* instance, mozilla::MakeUnique<MyClass>());
|
||||
*
|
||||
* // "instance" owns the newly created C++ object, so the C++
|
||||
|
Loading…
x
Reference in New Issue
Block a user