зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1395497 - Create SurfaceTexture in detached state, attach on first use r=jgilbert
MozReview-Commit-ID: HfkEUH9aiBo
This commit is contained in:
Родитель
0946e8c036
Коммит
cbcb5ef5e9
|
@ -486,6 +486,14 @@ SurfaceTextureHost::Lock()
|
|||
mSize);
|
||||
}
|
||||
|
||||
if (!mSurfTex->IsAttachedToGLContext((int64_t)gl)) {
|
||||
GLuint texName;
|
||||
gl->fGenTextures(1, &texName);
|
||||
if (NS_FAILED(mSurfTex->AttachToGLContext((int64_t)gl, texName))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,6 @@
|
|||
#include "nsDeque.h" // for nsDeque
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
#include "GeneratedJNINatives.h"
|
||||
#endif
|
||||
|
||||
static const unsigned int TEXTURE_POOL_SIZE = 10;
|
||||
static const unsigned int TEXTURE_REFILL_THRESHOLD = TEXTURE_POOL_SIZE / 2;
|
||||
|
||||
|
@ -40,19 +36,6 @@ static PoolState sPoolState = PoolState::NOT_INITIALIZE;
|
|||
|
||||
static bool sHasPendingFillTask = false;
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
|
||||
class GeckoSurfaceTextureSupport final
|
||||
: public java::GeckoSurfaceTexture::Natives<GeckoSurfaceTextureSupport>
|
||||
{
|
||||
public:
|
||||
static int32_t NativeAcquireTexture() {
|
||||
return TexturePoolOGL::AcquireTexture();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MOZ_WIDGET_ANDROID
|
||||
|
||||
void TexturePoolOGL::MaybeFillTextures()
|
||||
{
|
||||
if (sTextures->GetSize() < TEXTURE_REFILL_THRESHOLD &&
|
||||
|
@ -170,11 +153,6 @@ void TexturePoolOGL::Init()
|
|||
sMonitor = new Monitor("TexturePoolOGL.sMonitor");
|
||||
sTextures = new nsDeque();
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
if (jni::IsAvailable()) {
|
||||
GeckoSurfaceTextureSupport::Init();
|
||||
}
|
||||
#endif
|
||||
sPoolState = PoolState::INITIALIZED;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,28 +21,30 @@ public final class GeckoSurfaceTexture extends SurfaceTexture {
|
|||
|
||||
private int mHandle;
|
||||
private boolean mIsSingleBuffer;
|
||||
|
||||
private long mAttachedContext;
|
||||
private int mTexName;
|
||||
|
||||
private GeckoSurfaceTexture.Callbacks mListener;
|
||||
private AtomicInteger mUseCount;
|
||||
|
||||
@WrapForJNI(dispatchTo = "current")
|
||||
private static native int nativeAcquireTexture();
|
||||
|
||||
private GeckoSurfaceTexture(int handle, int texName) {
|
||||
super(texName);
|
||||
init(handle, texName, false);
|
||||
private GeckoSurfaceTexture(int handle) {
|
||||
super(0);
|
||||
init(handle, false);
|
||||
}
|
||||
|
||||
private GeckoSurfaceTexture(int handle, int texName, boolean singleBufferMode) {
|
||||
super(texName, singleBufferMode);
|
||||
init(handle, texName, singleBufferMode);
|
||||
private GeckoSurfaceTexture(int handle, boolean singleBufferMode) {
|
||||
super(0, singleBufferMode);
|
||||
init(handle, singleBufferMode);
|
||||
}
|
||||
|
||||
private void init(int handle, int texName, boolean singleBufferMode) {
|
||||
private void init(int handle, boolean singleBufferMode) {
|
||||
mHandle = handle;
|
||||
mIsSingleBuffer = singleBufferMode;
|
||||
mTexName = texName;
|
||||
mUseCount = new AtomicInteger(1);
|
||||
|
||||
// Start off detached
|
||||
detachFromGLContext();
|
||||
}
|
||||
|
||||
@WrapForJNI
|
||||
|
@ -55,6 +57,31 @@ public final class GeckoSurfaceTexture extends SurfaceTexture {
|
|||
return mTexName;
|
||||
}
|
||||
|
||||
@WrapForJNI(exceptionMode = "nsresult")
|
||||
public void attachToGLContext(long context, int texName) {
|
||||
if (context == mAttachedContext && texName == mTexName) {
|
||||
return;
|
||||
}
|
||||
|
||||
attachToGLContext(texName);
|
||||
|
||||
mAttachedContext = context;
|
||||
mTexName = texName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WrapForJNI(exceptionMode = "nsresult")
|
||||
public void detachFromGLContext() {
|
||||
super.detachFromGLContext();
|
||||
|
||||
mAttachedContext = mTexName = 0;
|
||||
}
|
||||
|
||||
@WrapForJNI
|
||||
public boolean isAttachedToGLContext(long context) {
|
||||
return mAttachedContext == context;
|
||||
}
|
||||
|
||||
@WrapForJNI
|
||||
public boolean isSingleBuffer() {
|
||||
return mIsSingleBuffer;
|
||||
|
@ -130,13 +157,12 @@ public final class GeckoSurfaceTexture extends SurfaceTexture {
|
|||
}
|
||||
|
||||
int handle = sNextHandle++;
|
||||
int texName = nativeAcquireTexture();
|
||||
|
||||
final GeckoSurfaceTexture gst;
|
||||
if (isSingleBufferSupported()) {
|
||||
gst = new GeckoSurfaceTexture(handle, texName, singleBufferMode);
|
||||
gst = new GeckoSurfaceTexture(handle, singleBufferMode);
|
||||
} else {
|
||||
gst = new GeckoSurfaceTexture(handle, texName);
|
||||
gst = new GeckoSurfaceTexture(handle);
|
||||
}
|
||||
|
||||
synchronized (sSurfaceTextures) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче