Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Unified Diff: content/common/android/surface_texture_bridge.cc

Issue 10695020: upstream SurfaceTextureListener and SurfaceTextureBridge class for android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing comments and add StreamTextureManagerAndroid class Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/android/surface_texture_bridge.cc
diff --git a/content/common/android/surface_texture_bridge.cc b/content/common/android/surface_texture_bridge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..99030b0343ed8b9a4cdd6ea37af070fd0d21cc7e
--- /dev/null
+++ b/content/common/android/surface_texture_bridge.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/android/surface_texture_bridge.h"
+
+#include "base/android/jni_android.h"
+#include "base/logging.h"
+#include "content/common/android/surface_texture_listener.h"
+
+using base::android::AttachCurrentThread;
+using base::android::CheckException;
+using base::android::GetClass;
+using base::android::GetMethodID;
+using base::android::ScopedJavaLocalRef;
+
+namespace content {
+
+SurfaceTextureBridge::SurfaceTextureBridge(int texture_id)
+ : texture_id_(texture_id) {
+ JNIEnv* env = AttachCurrentThread();
+ CHECK(env);
+
+ j_class_.Reset(GetClass(env, "android/graphics/SurfaceTexture"));
+ jmethodID constructor = GetMethodID(env, j_class_, "<init>", "(I)V");
+ ScopedJavaLocalRef<jobject> tmp(env,
+ env->NewObject(j_class_.obj(), constructor, texture_id));
+ DCHECK(!tmp.is_null());
+ j_surface_texture_.Reset(tmp);
+}
+
+SurfaceTextureBridge::~SurfaceTextureBridge() {
+ JNIEnv* env = AttachCurrentThread();
+ CHECK(env);
+
+ // Release the listener.
+ const char* method_signature =
+ "(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V";
+ jmethodID method = GetMethodID(env, j_class_, "setOnFrameAvailableListener",
+ method_signature);
+ env->CallVoidMethod(j_surface_texture_.obj(), method, NULL);
+ CheckException(env);
+
+ // Release graphics memory.
+ jmethodID release = GetMethodID(env, j_class_, "release", "()V");
+ env->CallVoidMethod(j_surface_texture_.obj(), release);
+ CheckException(env);
+}
+
+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(env,
+ SurfaceTextureListener::CreateSurfaceTextureListener(env, callback));
+ DCHECK(!j_listener.is_null());
+
+ // Set it as the onFrameAvailableListener for our SurfaceTexture instance.
+ const char* method_signature =
+ "(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V";
+ jmethodID method = GetMethodID(env, j_class_, "setOnFrameAvailableListener",
+ method_signature);
+ env->CallVoidMethod(j_surface_texture_.obj(), method, j_listener.obj());
+ CheckException(env);
+}
+
+void SurfaceTextureBridge::UpdateTexImage() {
+ JNIEnv* env = AttachCurrentThread();
+ CHECK(env);
+
+ jmethodID method = GetMethodID(env, j_class_, "updateTexImage", "()V");
+ env->CallVoidMethod(j_surface_texture_.obj(), method);
+ CheckException(env);
+}
+
+void SurfaceTextureBridge::GetTransformMatrix(float mtx[16]) {
+ JNIEnv* env = AttachCurrentThread();
+ CHECK(env);
+
+ ScopedJavaLocalRef<jfloatArray> jmatrix(env, env->NewFloatArray(16));
+ jmethodID method = GetMethodID(env, j_class_, "getTransformMatrix", "([F)V");
+ env->CallVoidMethod(j_surface_texture_.obj(), method, jmatrix.obj());
+ CheckException(env);
+
+ jboolean is_copy;
+ jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy);
+ for (int i = 0; i < 16; ++i) {
+ mtx[i] = static_cast<float>(elements[i]);
+ }
+ env->ReleaseFloatArrayElements(jmatrix.obj(), elements, JNI_ABORT);
+}
+
+void SurfaceTextureBridge::SetDefaultBufferSize(int width, int height) {
+ JNIEnv* env = AttachCurrentThread();
+ CHECK(env);
+
+ jmethodID method = GetMethodID(env, j_class_,
+ "setDefaultBufferSize", "(II)V");
+ env->CallVoidMethod(j_surface_texture_.obj(), method,
+ static_cast<jint>(width), static_cast<jint>(height));
+ CheckException(env);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698