summaryrefslogtreecommitdiff
path: root/chromium/ui/gl/android
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/gl/android')
-rw-r--r--chromium/ui/gl/android/gl_jni_registrar.cc3
-rw-r--r--chromium/ui/gl/android/surface_texture_bridge.cc99
-rw-r--r--chromium/ui/gl/android/surface_texture_bridge.h2
-rw-r--r--chromium/ui/gl/android/surface_texture_listener.cc13
-rw-r--r--chromium/ui/gl/android/surface_texture_listener.h13
5 files changed, 38 insertions, 92 deletions
diff --git a/chromium/ui/gl/android/gl_jni_registrar.cc b/chromium/ui/gl/android/gl_jni_registrar.cc
index 997268cc540..cba90cef77d 100644
--- a/chromium/ui/gl/android/gl_jni_registrar.cc
+++ b/chromium/ui/gl/android/gl_jni_registrar.cc
@@ -6,6 +6,7 @@
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
+#include "ui/gl/android/surface_texture_bridge.h"
#include "ui/gl/android/surface_texture_listener.h"
namespace ui {
@@ -13,6 +14,8 @@ namespace gl {
namespace android {
static base::android::RegistrationMethod kGLRegisteredMethods[] = {
+ { "SurfaceTextureBridge",
+ gfx::SurfaceTextureBridge::RegisterSurfaceTextureBridge },
{ "SurfaceTextureListener",
gfx::SurfaceTextureListener::RegisterSurfaceTextureListener },
};
diff --git a/chromium/ui/gl/android/surface_texture_bridge.cc b/chromium/ui/gl/android/surface_texture_bridge.cc
index c4206a983e6..9f2a3372e84 100644
--- a/chromium/ui/gl/android/surface_texture_bridge.cc
+++ b/chromium/ui/gl/android/surface_texture_bridge.cc
@@ -10,26 +10,11 @@
#include "base/android/build_info.h"
#include "base/android/jni_android.h"
#include "base/logging.h"
-#include "jni/SurfaceTexture_jni.h"
+#include "jni/SurfaceTextureBridge_jni.h"
#include "ui/gl/android/scoped_java_surface.h"
#include "ui/gl/android/surface_texture_listener.h"
#include "ui/gl/gl_bindings.h"
-using base::android::AttachCurrentThread;
-using base::android::CheckException;
-using base::android::GetClass;
-using base::android::ScopedJavaLocalRef;
-
-namespace {
-bool g_jni_initialized = false;
-
-void RegisterNativesIfNeeded(JNIEnv* env) {
- if (!g_jni_initialized) {
- JNI_SurfaceTexture::RegisterNativesImpl(env);
- g_jni_initialized = true;
- }
-}
-
// TODO(boliu): Remove this method when when we move off ICS. See
// http://crbug.com/161864.
bool GlContextMethodsAvailable() {
@@ -39,66 +24,38 @@ bool GlContextMethodsAvailable() {
return available;
}
-} // namespace
-
namespace gfx {
SurfaceTextureBridge::SurfaceTextureBridge(int texture_id) {
- JNIEnv* env = AttachCurrentThread();
- CHECK(env);
- RegisterNativesIfNeeded(env);
-
- ScopedJavaLocalRef<jobject> tmp(
- JNI_SurfaceTexture::Java_SurfaceTexture_Constructor(
- env, texture_id));
- DCHECK(!tmp.is_null());
- j_surface_texture_.Reset(tmp);
+ JNIEnv* env = base::android::AttachCurrentThread();
+ j_surface_texture_.Reset(Java_SurfaceTextureBridge_create(env, texture_id));
}
SurfaceTextureBridge::~SurfaceTextureBridge() {
- JNIEnv* env = AttachCurrentThread();
- CHECK(env);
-
- // Release the listener.
- JNI_SurfaceTexture::Java_SurfaceTexture_setOnFrameAvailableListener(
- env, j_surface_texture_.obj(), NULL);
-
- // Release graphics memory.
- JNI_SurfaceTexture::Java_SurfaceTexture_release(
- env, j_surface_texture_.obj());
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SurfaceTextureBridge_destroy(env, j_surface_texture_.obj());
}
void SurfaceTextureBridge::SetFrameAvailableCallback(
const base::Closure& callback) {
- JNIEnv* env = AttachCurrentThread();
- CHECK(env);
-
- // Since the listener is owned by the Java SurfaceTexture object, setting
- // a new listener here will release an existing one at the same time.
- ScopedJavaLocalRef<jobject> j_listener(
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SurfaceTextureBridge_setFrameAvailableCallback(
env,
- SurfaceTextureListener::CreateSurfaceTextureListener(env, callback));
- DCHECK(!j_listener.is_null());
-
- // Set it as the onFrameAvailableListener for our SurfaceTexture instance.
- JNI_SurfaceTexture::Java_SurfaceTexture_setOnFrameAvailableListener(
- env, j_surface_texture_.obj(), j_listener.obj());
+ j_surface_texture_.obj(),
+ reinterpret_cast<int>(new SurfaceTextureListener(callback)));
}
void SurfaceTextureBridge::UpdateTexImage() {
- JNIEnv* env = AttachCurrentThread();
- CHECK(env);
-
- JNI_SurfaceTexture::Java_SurfaceTexture_updateTexImage(
- env, j_surface_texture_.obj());
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SurfaceTextureBridge_updateTexImage(env, j_surface_texture_.obj());
}
void SurfaceTextureBridge::GetTransformMatrix(float mtx[16]) {
- JNIEnv* env = AttachCurrentThread();
- CHECK(env);
+ JNIEnv* env = base::android::AttachCurrentThread();
- ScopedJavaLocalRef<jfloatArray> jmatrix(env, env->NewFloatArray(16));
- JNI_SurfaceTexture::Java_SurfaceTexture_getTransformMatrix(
+ base::android::ScopedJavaLocalRef<jfloatArray> jmatrix(
+ env, env->NewFloatArray(16));
+ Java_SurfaceTextureBridge_getTransformMatrix(
env, j_surface_texture_.obj(), jmatrix.obj());
jboolean is_copy;
@@ -110,11 +67,10 @@ void SurfaceTextureBridge::GetTransformMatrix(float mtx[16]) {
}
void SurfaceTextureBridge::SetDefaultBufferSize(int width, int height) {
- JNIEnv* env = AttachCurrentThread();
- CHECK(env);
+ JNIEnv* env = base::android::AttachCurrentThread();
if (width > 0 && height > 0) {
- JNI_SurfaceTexture::Java_SurfaceTexture_setDefaultBufferSize(
+ Java_SurfaceTextureBridge_setDefaultBufferSize(
env, j_surface_texture_.obj(), static_cast<jint>(width),
static_cast<jint>(height));
} else {
@@ -128,28 +84,31 @@ void SurfaceTextureBridge::AttachToGLContext() {
int texture_id;
glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
DCHECK(texture_id);
- JNIEnv* env = AttachCurrentThread();
- // Note: This method is only available on JB and greater.
- JNI_SurfaceTexture::Java_SurfaceTexture_attachToGLContext(
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SurfaceTextureBridge_attachToGLContext(
env, j_surface_texture_.obj(), texture_id);
}
}
void SurfaceTextureBridge::DetachFromGLContext() {
if (GlContextMethodsAvailable()) {
- JNIEnv* env = AttachCurrentThread();
- // Note: This method is only available on JB and greater.
- JNI_SurfaceTexture::Java_SurfaceTexture_detachFromGLContext(
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SurfaceTextureBridge_detachFromGLContext(
env, j_surface_texture_.obj());
}
}
ANativeWindow* SurfaceTextureBridge::CreateSurface() {
- JNIEnv* env = AttachCurrentThread();
+ JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaSurface surface(this);
- ANativeWindow* native_window =
- ANativeWindow_fromSurface(env, surface.j_surface().obj());
+ ANativeWindow* native_window = ANativeWindow_fromSurface(
+ env, surface.j_surface().obj());
return native_window;
}
+// static
+bool SurfaceTextureBridge::RegisterSurfaceTextureBridge(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
} // namespace gfx
diff --git a/chromium/ui/gl/android/surface_texture_bridge.h b/chromium/ui/gl/android/surface_texture_bridge.h
index fc7fb5416ac..474f0c22d39 100644
--- a/chromium/ui/gl/android/surface_texture_bridge.h
+++ b/chromium/ui/gl/android/surface_texture_bridge.h
@@ -57,6 +57,8 @@ class GL_EXPORT SurfaceTextureBridge
return j_surface_texture_;
}
+ static bool RegisterSurfaceTextureBridge(JNIEnv* env);
+
private:
friend class base::RefCountedThreadSafe<SurfaceTextureBridge>;
~SurfaceTextureBridge();
diff --git a/chromium/ui/gl/android/surface_texture_listener.cc b/chromium/ui/gl/android/surface_texture_listener.cc
index 0547720202c..39d8468dd4a 100644
--- a/chromium/ui/gl/android/surface_texture_listener.cc
+++ b/chromium/ui/gl/android/surface_texture_listener.cc
@@ -12,19 +12,6 @@
namespace gfx {
-// static
-jobject SurfaceTextureListener::CreateSurfaceTextureListener(
- JNIEnv* env,
- const base::Closure& callback) {
- // The java listener object owns and releases the native instance.
- // This is necessary to avoid races with incoming notifications.
- ScopedJavaLocalRef<jobject> listener(Java_SurfaceTextureListener_create(env,
- reinterpret_cast<int>(new SurfaceTextureListener(callback))));
-
- DCHECK(!listener.is_null());
- return listener.Release();
-}
-
SurfaceTextureListener::SurfaceTextureListener(const base::Closure& callback)
: callback_(callback),
browser_loop_(base::MessageLoopProxy::current()) {
diff --git a/chromium/ui/gl/android/surface_texture_listener.h b/chromium/ui/gl/android/surface_texture_listener.h
index faab6be1eb1..60103aad97d 100644
--- a/chromium/ui/gl/android/surface_texture_listener.h
+++ b/chromium/ui/gl/android/surface_texture_listener.h
@@ -18,7 +18,7 @@ namespace gfx {
// Listener class for all the callbacks from android SurfaceTexture.
class GL_EXPORT SurfaceTextureListener {
-public:
+ public:
// Destroy this listener.
void Destroy(JNIEnv* env, jobject obj);
@@ -27,19 +27,14 @@ public:
static bool RegisterSurfaceTextureListener(JNIEnv* env);
-private:
+ private:
+ // Native code should not hold any reference to this object, and instead pass
+ // it up to Java for being referenced by a SurfaceTexture instance.
SurfaceTextureListener(const base::Closure& callback);
~SurfaceTextureListener();
friend class SurfaceTextureBridge;
- // Static factory method for the creation of a SurfaceTextureListener.
- // The native code should not hold any reference to the returned object,
- // but only use it to pass it up to Java for being referenced by a
- // SurfaceTexture instance.
- static jobject CreateSurfaceTextureListener(JNIEnv* env,
- const base::Closure& callback);
-
base::Closure callback_;
scoped_refptr<base::MessageLoopProxy> browser_loop_;