summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorsievers@chromium.org <sievers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 22:41:40 +0000
committersievers@chromium.org <sievers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 22:41:40 +0000
commitd50dc7ca5f309488e6b7e9125a3b24a16627d0b0 (patch)
treea350778502fb6b8701169f97c8ed24f6ce5c6e20 /content
parent0e6b1da33bb3793821f64b159b668520593880a8 (diff)
downloadchromium_src-d50dc7ca5f309488e6b7e9125a3b24a16627d0b0.zip
chromium_src-d50dc7ca5f309488e6b7e9125a3b24a16627d0b0.tar.gz
chromium_src-d50dc7ca5f309488e6b7e9125a3b24a16627d0b0.tar.bz2
Expose extra SurfaceTextureBridge methods.
Add JNI calls to attach and detach from GL contexts. Also add a function to create a Surface/ANativeWindow for the SurfaceTexture. Review URL: https://codereview.chromium.org/11315024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165780 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/common/android/surface_texture_bridge.cc28
-rw-r--r--content/common/android/surface_texture_bridge.h15
-rw-r--r--content/common/android/surface_texture_listener.cc9
-rw-r--r--content/content.gyp10
4 files changed, 58 insertions, 4 deletions
diff --git a/content/common/android/surface_texture_bridge.cc b/content/common/android/surface_texture_bridge.cc
index 8f640f8..bdf54ee 100644
--- a/content/common/android/surface_texture_bridge.cc
+++ b/content/common/android/surface_texture_bridge.cc
@@ -4,10 +4,13 @@
#include "content/common/android/surface_texture_bridge.h"
+#include <android/native_window_jni.h>
+
#include "base/android/jni_android.h"
#include "base/logging.h"
#include "content/common/android/surface_texture_listener.h"
#include "jni/SurfaceTexture_jni.h"
+#include "jni/Surface_jni.h"
using base::android::AttachCurrentThread;
using base::android::CheckException;
@@ -20,6 +23,7 @@ bool g_jni_initialized = false;
void RegisterNativesIfNeeded(JNIEnv* env) {
if (!g_jni_initialized) {
JNI_SurfaceTexture::RegisterNativesImpl(env);
+ JNI_Surface::RegisterNativesImpl(env);
g_jni_initialized = true;
}
}
@@ -103,4 +107,28 @@ void SurfaceTextureBridge::SetDefaultBufferSize(int width, int height) {
static_cast<jint>(height));
}
+void SurfaceTextureBridge::AttachToGLContext(int texture_id) {
+ JNIEnv* env = AttachCurrentThread();
+ // Note: This method is only available on JB and greater.
+ JNI_SurfaceTexture::Java_SurfaceTexture_attachToGLContext(
+ env, j_surface_texture_.obj(), texture_id);
+}
+
+void SurfaceTextureBridge::DetachFromGLContext() {
+ JNIEnv* env = AttachCurrentThread();
+ // Note: This method is only available on JB and greater.
+ JNI_SurfaceTexture::Java_SurfaceTexture_detachFromGLContext(
+ env, j_surface_texture_.obj());
+}
+
+ANativeWindow* SurfaceTextureBridge::CreateSurface() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> jsurface(
+ JNI_Surface::Java_Surface_Constructor(
+ env, j_surface_texture_.obj()));
+ DCHECK(!jsurface.is_null());
+ ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface.obj());
+ return native_window;
+}
+
} // namespace content
diff --git a/content/common/android/surface_texture_bridge.h b/content/common/android/surface_texture_bridge.h
index 97e8ef6..0779196 100644
--- a/content/common/android/surface_texture_bridge.h
+++ b/content/common/android/surface_texture_bridge.h
@@ -11,6 +11,8 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
+struct ANativeWindow;
+
namespace content {
// This class serves as a bridge for native code to call java functions inside
@@ -37,6 +39,19 @@ class SurfaceTextureBridge
// Set the default size of the image buffers.
void SetDefaultBufferSize(int width, int height);
+ // Attach the SurfaceTexture to the given texture in the GL context that is
+ // current on the calling thread.
+ void AttachToGLContext(int texture_id);
+
+ // Detaches the SurfaceTexture from the context that owns its current GL
+ // texture. Must be called with that context current on the calling thread.
+ void DetachFromGLContext();
+
+ // Creates a native render surface for this surface texture.
+ // The caller must release the underlying reference when done with the handle
+ // by calling ANativeWindow_release().
+ ANativeWindow* CreateSurface();
+
int texture_id() const {
return texture_id_;
}
diff --git a/content/common/android/surface_texture_listener.cc b/content/common/android/surface_texture_listener.cc
index 6ff63b4..4440c5c 100644
--- a/content/common/android/surface_texture_listener.cc
+++ b/content/common/android/surface_texture_listener.cc
@@ -38,10 +38,11 @@ void SurfaceTextureListener::Destroy(JNIEnv* env, jobject obj) {
}
void SurfaceTextureListener::FrameAvailable(JNIEnv* env, jobject obj) {
- // These notifications should be coming in on a thread private to Java.
- // Should this ever change, we can try to avoid reposting to the same thread.
- DCHECK(!browser_loop_->BelongsToCurrentThread());
- browser_loop_->PostTask(FROM_HERE, callback_);
+ if (!browser_loop_->BelongsToCurrentThread()) {
+ browser_loop_->PostTask(FROM_HERE, callback_);
+ } else {
+ callback_.Run();
+ }
}
// static
diff --git a/content/content.gyp b/content/content.gyp
index e7da4dc..e057fd6 100644
--- a/content/content.gyp
+++ b/content/content.gyp
@@ -303,6 +303,16 @@
'includes': [ '../build/jar_file_jni_generator.gypi' ],
},
{
+ 'target_name': 'surface_jni_headers',
+ 'type': 'none',
+ 'variables': {
+ 'jni_gen_dir': 'content',
+ 'input_java_class': 'android/view/Surface.class',
+ 'input_jar_file': '<(android_sdk)/android.jar',
+ },
+ 'includes': [ '../build/jar_file_jni_generator.gypi' ],
+ },
+ {
'target_name': 'content_jni_headers',
'type': 'none',
'dependencies': [