| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/android/surface_texture_bridge.h" | 5 #include "content/common/android/surface_texture_bridge.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 | 8 |
| 9 // TODO(boliu): Remove this include when we move off ICS. | 9 // TODO(boliu): Remove this include when we move off ICS. |
| 10 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
| 11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "content/common/android/surface.h" |
| 13 #include "content/common/android/surface_texture_listener.h" | 14 #include "content/common/android/surface_texture_listener.h" |
| 14 #include "jni/SurfaceTexture_jni.h" | 15 #include "jni/SurfaceTexture_jni.h" |
| 15 #include "jni/Surface_jni.h" | |
| 16 | 16 |
| 17 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
| 18 using base::android::CheckException; | 18 using base::android::CheckException; |
| 19 using base::android::GetClass; | 19 using base::android::GetClass; |
| 20 using base::android::ScopedJavaLocalRef; | 20 using base::android::ScopedJavaLocalRef; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 bool g_jni_initialized = false; | 23 bool g_jni_initialized = false; |
| 24 | 24 |
| 25 void RegisterNativesIfNeeded(JNIEnv* env) { | 25 void RegisterNativesIfNeeded(JNIEnv* env) { |
| 26 if (!g_jni_initialized) { | 26 if (!g_jni_initialized) { |
| 27 JNI_SurfaceTexture::RegisterNativesImpl(env); | 27 JNI_SurfaceTexture::RegisterNativesImpl(env); |
| 28 JNI_Surface::RegisterNativesImpl(env); | |
| 29 g_jni_initialized = true; | 28 g_jni_initialized = true; |
| 30 } | 29 } |
| 31 } | 30 } |
| 32 | 31 |
| 33 // TODO(boliu): Remove this method when when we move off ICS. See | 32 // TODO(boliu): Remove this method when when we move off ICS. See |
| 34 // http://crbug.com/161864. | 33 // http://crbug.com/161864. |
| 35 bool GlContextMethodsAvailable() { | 34 bool GlContextMethodsAvailable() { |
| 36 bool available = base::android::BuildInfo::GetInstance()->sdk_int() >= 16; | 35 bool available = base::android::BuildInfo::GetInstance()->sdk_int() >= 16; |
| 37 if (!available) | 36 if (!available) |
| 38 LOG(WARNING) << "Running on unsupported device: rendering may not work"; | 37 LOG(WARNING) << "Running on unsupported device: rendering may not work"; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (GlContextMethodsAvailable()) { | 131 if (GlContextMethodsAvailable()) { |
| 133 JNIEnv* env = AttachCurrentThread(); | 132 JNIEnv* env = AttachCurrentThread(); |
| 134 // Note: This method is only available on JB and greater. | 133 // Note: This method is only available on JB and greater. |
| 135 JNI_SurfaceTexture::Java_SurfaceTexture_detachFromGLContext( | 134 JNI_SurfaceTexture::Java_SurfaceTexture_detachFromGLContext( |
| 136 env, j_surface_texture_.obj()); | 135 env, j_surface_texture_.obj()); |
| 137 } | 136 } |
| 138 } | 137 } |
| 139 | 138 |
| 140 ANativeWindow* SurfaceTextureBridge::CreateSurface() { | 139 ANativeWindow* SurfaceTextureBridge::CreateSurface() { |
| 141 JNIEnv* env = AttachCurrentThread(); | 140 JNIEnv* env = AttachCurrentThread(); |
| 142 ScopedJavaLocalRef<jobject> jsurface( | 141 Surface surface(j_surface_texture_); |
| 143 JNI_Surface::Java_Surface_Constructor( | 142 ANativeWindow* native_window = |
| 144 env, j_surface_texture_.obj())); | 143 ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
| 145 DCHECK(!jsurface.is_null()); | 144 surface.Release(); |
| 146 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface.obj()); | |
| 147 JNI_Surface::Java_Surface_release(env, jsurface.obj()); | |
| 148 return native_window; | 145 return native_window; |
| 149 } | 146 } |
| 150 | 147 |
| 151 } // namespace content | 148 } // namespace content |
| OLD | NEW |