| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/gl/android/surface_texture.h" | 5 #include "ui/gl/android/surface_texture.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "jni/SurfaceTexturePlatformWrapper_jni.h" | 11 #include "jni/SurfaceTexturePlatformWrapper_jni.h" |
| 12 #include "ui/gl/android/scoped_java_surface.h" | 12 #include "ui/gl/android/scoped_java_surface.h" |
| 13 #include "ui/gl/android/surface_texture_listener.h" | 13 #include "ui/gl/android/surface_texture_listener.h" |
| 14 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
| 15 | 15 |
| 16 namespace gl { | 16 namespace gl { |
| 17 | 17 |
| 18 scoped_refptr<SurfaceTexture> SurfaceTexture::Create(int texture_id) { | 18 scoped_refptr<SurfaceTexture> SurfaceTexture::Create(int texture_id) { |
| 19 return new SurfaceTexture(CreateJavaSurfaceTexture(texture_id)); |
| 20 } |
| 21 |
| 22 base::android::ScopedJavaLocalRef<jobject> |
| 23 SurfaceTexture::CreateJavaSurfaceTexture(int texture_id) { |
| 19 JNIEnv* env = base::android::AttachCurrentThread(); | 24 JNIEnv* env = base::android::AttachCurrentThread(); |
| 20 return new SurfaceTexture( | 25 return Java_SurfaceTexturePlatformWrapper_create(env, texture_id); |
| 21 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); | |
| 22 } | 26 } |
| 23 | 27 |
| 24 SurfaceTexture::SurfaceTexture( | 28 SurfaceTexture::SurfaceTexture( |
| 25 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture) { | 29 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture) { |
| 26 j_surface_texture_.Reset(j_surface_texture); | 30 j_surface_texture_.Reset(j_surface_texture); |
| 27 } | 31 } |
| 28 | 32 |
| 29 SurfaceTexture::~SurfaceTexture() { | 33 SurfaceTexture::~SurfaceTexture() { |
| 34 DestroyJavaObject(); |
| 35 } |
| 36 |
| 37 void SurfaceTexture::DestroyJavaObject() { |
| 38 if (j_surface_texture_.is_null()) |
| 39 return; |
| 40 |
| 30 JNIEnv* env = base::android::AttachCurrentThread(); | 41 JNIEnv* env = base::android::AttachCurrentThread(); |
| 31 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_); | 42 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_); |
| 43 j_surface_texture_.Reset(); |
| 32 } | 44 } |
| 33 | 45 |
| 34 void SurfaceTexture::SetFrameAvailableCallback( | 46 void SurfaceTexture::SetFrameAvailableCallback( |
| 35 const base::Closure& callback) { | 47 const base::Closure& callback) { |
| 36 JNIEnv* env = base::android::AttachCurrentThread(); | 48 JNIEnv* env = base::android::AttachCurrentThread(); |
| 37 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( | 49 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( |
| 38 env, j_surface_texture_, | 50 env, j_surface_texture_, |
| 39 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback, false))); | 51 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback, false))); |
| 40 } | 52 } |
| 41 | 53 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 Java_SurfaceTexturePlatformWrapper_release(env, j_surface_texture_); | 112 Java_SurfaceTexturePlatformWrapper_release(env, j_surface_texture_); |
| 101 } | 113 } |
| 102 | 114 |
| 103 void SurfaceTexture::SetDefaultBufferSize(int width, int height) { | 115 void SurfaceTexture::SetDefaultBufferSize(int width, int height) { |
| 104 JNIEnv* env = base::android::AttachCurrentThread(); | 116 JNIEnv* env = base::android::AttachCurrentThread(); |
| 105 Java_SurfaceTexturePlatformWrapper_setDefaultBufferSize( | 117 Java_SurfaceTexturePlatformWrapper_setDefaultBufferSize( |
| 106 env, j_surface_texture_, width, height); | 118 env, j_surface_texture_, width, height); |
| 107 } | 119 } |
| 108 | 120 |
| 109 } // namespace gl | 121 } // namespace gl |
| OLD | NEW |