OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/android/scoped_java_surface.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/common/android/surface_texture_bridge.h" |
| 9 #include "jni/Surface_jni.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 bool g_jni_initialized = false; |
| 14 |
| 15 void RegisterNativesIfNeeded(JNIEnv* env) { |
| 16 if (!g_jni_initialized) { |
| 17 JNI_Surface::RegisterNativesImpl(env); |
| 18 g_jni_initialized = true; |
| 19 } |
| 20 } |
| 21 |
| 22 } // anonymous namespace |
| 23 |
| 24 namespace content { |
| 25 |
| 26 ScopedJavaSurface::ScopedJavaSurface() { |
| 27 } |
| 28 |
| 29 ScopedJavaSurface::ScopedJavaSurface( |
| 30 const base::android::JavaRef<jobject>& surface) { |
| 31 JNIEnv* env = base::android::AttachCurrentThread(); |
| 32 RegisterNativesIfNeeded(env); |
| 33 DCHECK(env->IsInstanceOf(surface.obj(), g_Surface_clazz)); |
| 34 j_surface_.Reset(surface); |
| 35 } |
| 36 |
| 37 ScopedJavaSurface::ScopedJavaSurface( |
| 38 const SurfaceTextureBridge* surface_texture) { |
| 39 JNIEnv* env = base::android::AttachCurrentThread(); |
| 40 RegisterNativesIfNeeded(env); |
| 41 ScopedJavaLocalRef<jobject> tmp(JNI_Surface::Java_Surface_Constructor( |
| 42 env, surface_texture->j_surface_texture().obj())); |
| 43 DCHECK(!tmp.is_null()); |
| 44 j_surface_.Reset(tmp); |
| 45 } |
| 46 |
| 47 ScopedJavaSurface::~ScopedJavaSurface() { |
| 48 if (!j_surface_.is_null()) { |
| 49 JNIEnv* env = base::android::AttachCurrentThread(); |
| 50 JNI_Surface::Java_Surface_release(env, j_surface_.obj()); |
| 51 } |
| 52 } |
| 53 |
| 54 } // namespace content |
OLD | NEW |