2014-10-17 16:34:01 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:set ts=2 sts=2 sw=2 et cin:
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
#ifndef AndroidSurfaceTexture_h__
|
|
|
|
#define AndroidSurfaceTexture_h__
|
2014-10-17 16:34:01 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "GLDefs.h"
|
2014-10-21 06:53:01 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/Monitor.h"
|
2014-10-17 16:34:01 -07:00
|
|
|
|
2014-11-13 10:47:24 -08:00
|
|
|
#include "SurfaceTexture.h"
|
2014-10-21 06:53:00 -07:00
|
|
|
#include "AndroidNativeWindow.h"
|
|
|
|
|
|
|
|
class gfxASurface;
|
|
|
|
|
2014-10-17 16:34:01 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class Matrix4x4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2014-10-21 06:53:01 -07:00
|
|
|
class GLContext;
|
|
|
|
|
2014-10-17 16:34:01 -07:00
|
|
|
/**
|
|
|
|
* This class is a wrapper around Android's SurfaceTexture class.
|
|
|
|
* Usage is pretty much exactly like the Java class, so see
|
|
|
|
* the Android documentation for details.
|
|
|
|
*/
|
2014-10-21 06:53:00 -07:00
|
|
|
class AndroidSurfaceTexture {
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidSurfaceTexture)
|
2014-10-17 16:34:01 -07:00
|
|
|
|
|
|
|
public:
|
2014-10-21 06:53:01 -07:00
|
|
|
|
|
|
|
// The SurfaceTexture is created in an attached state. This method requires
|
|
|
|
// Android Ice Cream Sandwich.
|
2014-11-13 10:47:24 -08:00
|
|
|
static TemporaryRef<AndroidSurfaceTexture> Create(GLContext* aGLContext, GLuint aTexture);
|
2014-10-21 06:53:01 -07:00
|
|
|
|
|
|
|
// Here the SurfaceTexture will be created in a detached state. You must call
|
|
|
|
// Attach() with the GLContext you wish to composite with. It must be done
|
|
|
|
// on the thread where that GLContext is current. This method requires
|
|
|
|
// Android Jelly Bean.
|
2014-11-13 10:47:24 -08:00
|
|
|
static TemporaryRef<AndroidSurfaceTexture> Create();
|
2014-10-21 06:53:01 -07:00
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
static AndroidSurfaceTexture* Find(int id);
|
2014-10-17 16:34:01 -07:00
|
|
|
|
2014-10-21 06:53:01 -07:00
|
|
|
// If we are on Jelly Bean, the SurfaceTexture can be detached and reattached
|
|
|
|
// to allow consumption from different GLContexts. It is recommended to only
|
|
|
|
// attach while you are consuming in order to allow this.
|
|
|
|
//
|
|
|
|
// Only one GLContext may be attached at any given time. If another is already
|
|
|
|
// attached, we try to wait for it to become detached.
|
2014-11-13 10:47:24 -08:00
|
|
|
nsresult Attach(GLContext* aContext, PRIntervalTime aTiemout = PR_INTERVAL_NO_TIMEOUT);
|
2014-10-21 06:53:01 -07:00
|
|
|
|
|
|
|
// This is a noop on ICS, and will always fail
|
2014-11-13 10:47:24 -08:00
|
|
|
nsresult Detach();
|
2014-10-21 06:53:01 -07:00
|
|
|
|
|
|
|
GLContext* GetAttachedContext() { return mAttachedContext; }
|
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
AndroidNativeWindow* NativeWindow() {
|
|
|
|
return mNativeWindow;
|
|
|
|
}
|
|
|
|
|
2014-10-17 16:34:01 -07:00
|
|
|
// This attaches the updated data to the TEXTURE_EXTERNAL target
|
|
|
|
void UpdateTexImage();
|
|
|
|
|
2014-11-13 10:47:24 -08:00
|
|
|
void GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix);
|
2014-10-17 16:34:01 -07:00
|
|
|
int ID() { return mID; }
|
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
void SetDefaultSize(mozilla::gfx::IntSize size);
|
|
|
|
|
2014-10-17 16:34:01 -07:00
|
|
|
// The callback is guaranteed to be called on the main thread even
|
|
|
|
// if the upstream callback is received on a different thread
|
|
|
|
void SetFrameAvailableCallback(nsIRunnable* aRunnable);
|
|
|
|
|
|
|
|
// Only should be called by AndroidJNI when we get a
|
|
|
|
// callback from the underlying SurfaceTexture instance
|
|
|
|
void NotifyFrameAvailable();
|
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
GLuint Texture() { return mTexture; }
|
2014-11-13 10:47:24 -08:00
|
|
|
jobject JavaSurface() { return mSurface->wrappedObject(); }
|
2014-10-21 06:53:00 -07:00
|
|
|
private:
|
|
|
|
AndroidSurfaceTexture();
|
2014-10-21 06:53:00 -07:00
|
|
|
~AndroidSurfaceTexture();
|
2014-10-17 16:34:01 -07:00
|
|
|
|
2014-10-21 06:53:01 -07:00
|
|
|
bool Init(GLContext* aContext, GLuint aTexture);
|
2014-10-17 16:34:01 -07:00
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
GLuint mTexture;
|
2014-11-13 10:47:24 -08:00
|
|
|
nsAutoPtr<mozilla::widget::android::sdk::SurfaceTexture> mSurfaceTexture;
|
|
|
|
nsAutoPtr<mozilla::widget::android::sdk::Surface> mSurface;
|
2014-10-21 06:53:00 -07:00
|
|
|
|
2014-10-21 06:53:01 -07:00
|
|
|
Monitor mMonitor;
|
|
|
|
GLContext* mAttachedContext;
|
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
RefPtr<AndroidNativeWindow> mNativeWindow;
|
2014-10-17 16:34:01 -07:00
|
|
|
int mID;
|
|
|
|
nsRefPtr<nsIRunnable> mFrameAvailableCallback;
|
|
|
|
};
|
2014-10-21 06:53:01 -07:00
|
|
|
|
2014-10-21 06:53:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 16:34:01 -07:00
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|