Index: content/common/android/scoped_java_surface.cc |
diff --git a/content/common/android/scoped_java_surface.cc b/content/common/android/scoped_java_surface.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ca84f72617ff060ca2cbb8228fb7ce74aa634e2c |
--- /dev/null |
+++ b/content/common/android/scoped_java_surface.cc |
@@ -0,0 +1,54 @@ |
+// Copyright (c) 2013 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/scoped_java_surface.h" |
+ |
+#include "base/logging.h" |
+#include "content/common/android/surface_texture_bridge.h" |
+#include "jni/Surface_jni.h" |
+ |
+namespace { |
+ |
+bool g_jni_initialized = false; |
+ |
+void RegisterNativesIfNeeded(JNIEnv* env) { |
+ if (!g_jni_initialized) { |
+ JNI_Surface::RegisterNativesImpl(env); |
+ g_jni_initialized = true; |
+ } |
+} |
+ |
+} // anonymous namespace |
+ |
+namespace content { |
+ |
+ScopedJavaSurface::ScopedJavaSurface() { |
+} |
+ |
+ScopedJavaSurface::ScopedJavaSurface( |
+ const base::android::JavaRef<jobject>& surface) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ RegisterNativesIfNeeded(env); |
+ DCHECK(env->IsInstanceOf(surface.obj(), g_Surface_clazz)); |
+ j_surface_.Reset(surface); |
+} |
+ |
+ScopedJavaSurface::ScopedJavaSurface( |
+ const SurfaceTextureBridge* surface_texture) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ RegisterNativesIfNeeded(env); |
+ ScopedJavaLocalRef<jobject> tmp(JNI_Surface::Java_Surface_Constructor( |
+ env, surface_texture->j_surface_texture().obj())); |
+ DCHECK(!tmp.is_null()); |
+ j_surface_.Reset(tmp); |
+} |
+ |
+ScopedJavaSurface::~ScopedJavaSurface() { |
+ if (!j_surface_.is_null()) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ JNI_Surface::Java_Surface_release(env, j_surface_.obj()); |
+ } |
+} |
+ |
+} // namespace content |