Index: content/common/android/surface.cc |
diff --git a/content/common/android/surface.cc b/content/common/android/surface.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..12adcda912299313e6cb90c9acedd671672b297b |
--- /dev/null |
+++ b/content/common/android/surface.cc |
@@ -0,0 +1,51 @@ |
+// Copyright (c) 2012 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.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 { |
+ |
+// static |
+void Surface::Release(jobject surface) { |
+ if (surface == NULL) |
+ return; |
+ |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ RegisterNativesIfNeeded(env); |
+ JNI_Surface::Java_Surface_release(env, surface); |
+} |
+ |
+Surface::Surface(const base::android::JavaRef<jobject>& surface_texture) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ RegisterNativesIfNeeded(env); |
+ |
+ ScopedJavaLocalRef<jobject> tmp( |
+ JNI_Surface::Java_Surface_Constructor(env, surface_texture.obj())); |
+ DCHECK(!tmp.is_null()); |
+ j_surface_.Reset(tmp); |
+} |
+ |
+Surface::~Surface() { |
+} |
+ |
+void Surface::Release() { |
+ Release(j_surface_.obj()); |
+} |
+ |
+} // namespace content |