Bug 1367287 - Reference count GeckoSurfaceTexture r=jchen

MozReview-Commit-ID: 1JJVzCmANyH
This commit is contained in:
James Willcox 2017-06-01 12:12:55 -05:00
Родитель fcdd58e1ca
Коммит bd21ee4811
5 изменённых файлов: 94 добавлений и 14 удалений

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

@ -421,10 +421,16 @@ SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags,
{
// Continuous update makes no sense with single buffer mode
MOZ_ASSERT(!mSurfTex->IsSingleBuffer() || !mContinuousUpdate);
mSurfTex->IncrementUse();
}
SurfaceTextureHost::~SurfaceTextureHost()
{
if (mSurfTex) {
mSurfTex->DecrementUse();
mSurfTex = nullptr;
}
}
void
@ -516,7 +522,11 @@ SurfaceTextureHost::DeallocateDeviceData()
if (mTextureSource) {
mTextureSource->DeallocateDeviceData();
}
mSurfTex = nullptr;
if (mSurfTex) {
mSurfTex->DecrementUse();
mSurfTex = nullptr;
}
}
#endif // MOZ_WIDGET_ANDROID

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

@ -22,6 +22,7 @@ public final class GeckoSurfaceTexture extends SurfaceTexture {
private boolean mIsSingleBuffer;
private int mTexName;
private GeckoSurfaceTexture.Callbacks mListener;
private volatile int mUseCount = 1;
@WrapForJNI(dispatchTo = "current")
private static native int nativeAcquireTexture();
@ -86,6 +87,30 @@ public final class GeckoSurfaceTexture extends SurfaceTexture {
return Versions.feature19Plus;
}
@WrapForJNI
public void incrementUse() {
mUseCount++;
}
@WrapForJNI
public void decrementUse() {
mUseCount--;
if (mUseCount == 0) {
synchronized (sSurfaceTextures) {
sSurfaceTextures.remove(mHandle);
}
setListener(null);
if (Versions.feature16Plus) {
detachFromGLContext();
}
release();
}
}
public static GeckoSurfaceTexture acquire(boolean singleBufferMode) {
if (singleBufferMode && !isSingleBufferSupported()) {
throw new IllegalArgumentException("single buffer mode not supported on API version < 19");
@ -114,18 +139,6 @@ public final class GeckoSurfaceTexture extends SurfaceTexture {
return gst;
}
public static void dispose(int handle) {
final GeckoSurfaceTexture gst;
synchronized (sSurfaceTextures) {
gst = sSurfaceTextures.remove(handle);
}
if (gst != null) {
gst.setListener(null);
gst.release();
}
}
@WrapForJNI
public static GeckoSurfaceTexture lookup(int handle) {
synchronized (sSurfaceTextures) {

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

@ -31,7 +31,10 @@ public class SurfaceAllocatorService extends Service {
}
public void releaseSurface(int handle) {
GeckoSurfaceTexture.dispose(handle);
final GeckoSurfaceTexture gst = GeckoSurfaceTexture.lookup(handle);
if (gst != null) {
gst.decrementUse();
}
}
};

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

@ -1102,6 +1102,14 @@ auto GeckoSurface::SetAvailable(bool a0) const -> void
const char GeckoSurfaceTexture::name[] =
"org/mozilla/gecko/gfx/GeckoSurfaceTexture";
constexpr char GeckoSurfaceTexture::DecrementUse_t::name[];
constexpr char GeckoSurfaceTexture::DecrementUse_t::signature[];
auto GeckoSurfaceTexture::DecrementUse() const -> void
{
return mozilla::jni::Method<DecrementUse_t>::Call(GeckoSurfaceTexture::mCtx, nullptr);
}
constexpr char GeckoSurfaceTexture::GetHandle_t::name[];
constexpr char GeckoSurfaceTexture::GetHandle_t::signature[];
@ -1118,6 +1126,14 @@ auto GeckoSurfaceTexture::GetTexName() const -> int32_t
return mozilla::jni::Method<GetTexName_t>::Call(GeckoSurfaceTexture::mCtx, nullptr);
}
constexpr char GeckoSurfaceTexture::IncrementUse_t::name[];
constexpr char GeckoSurfaceTexture::IncrementUse_t::signature[];
auto GeckoSurfaceTexture::IncrementUse() const -> void
{
return mozilla::jni::Method<IncrementUse_t>::Call(GeckoSurfaceTexture::mCtx, nullptr);
}
constexpr char GeckoSurfaceTexture::IsSingleBuffer_t::name[];
constexpr char GeckoSurfaceTexture::IsSingleBuffer_t::signature[];

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

@ -3428,6 +3428,25 @@ public:
explicit GeckoSurfaceTexture(const Context& ctx) : ObjectBase<GeckoSurfaceTexture>(ctx) {}
struct DecrementUse_t {
typedef GeckoSurfaceTexture Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "decrementUse";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::ANY;
static const mozilla::jni::DispatchTarget dispatchTarget =
mozilla::jni::DispatchTarget::CURRENT;
};
auto DecrementUse() const -> void;
struct GetHandle_t {
typedef GeckoSurfaceTexture Owner;
typedef int32_t ReturnType;
@ -3466,6 +3485,25 @@ public:
auto GetTexName() const -> int32_t;
struct IncrementUse_t {
typedef GeckoSurfaceTexture Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "incrementUse";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::ANY;
static const mozilla::jni::DispatchTarget dispatchTarget =
mozilla::jni::DispatchTarget::CURRENT;
};
auto IncrementUse() const -> void;
struct IsSingleBuffer_t {
typedef GeckoSurfaceTexture Owner;
typedef bool ReturnType;