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/build_info.h" |
9 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "jni/SurfaceTexturePlatformWrapper_jni.h" | 12 #include "jni/SurfaceTexturePlatformWrapper_jni.h" |
12 #include "ui/gl/android/scoped_java_surface.h" | 13 #include "ui/gl/android/scoped_java_surface.h" |
13 #include "ui/gl/android/surface_texture_listener.h" | 14 #include "ui/gl/android/surface_texture_listener.h" |
14 #include "ui/gl/gl_bindings.h" | 15 #include "ui/gl/gl_bindings.h" |
15 | 16 |
16 namespace gfx { | 17 namespace gfx { |
17 | 18 |
18 scoped_refptr<SurfaceTexture> SurfaceTexture::Create(int texture_id) { | 19 scoped_refptr<SurfaceTexture> SurfaceTexture::Create(int texture_id) { |
19 JNIEnv* env = base::android::AttachCurrentThread(); | 20 JNIEnv* env = base::android::AttachCurrentThread(); |
20 return new SurfaceTexture( | 21 return new SurfaceTexture( |
21 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); | 22 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); |
22 } | 23 } |
23 | 24 |
| 25 scoped_refptr<SurfaceTexture> SurfaceTexture::CreateSingleBuffered( |
| 26 int texture_id) { |
| 27 DCHECK(IsSingleBufferModeSupported()); |
| 28 JNIEnv* env = base::android::AttachCurrentThread(); |
| 29 return new SurfaceTexture( |
| 30 Java_SurfaceTexturePlatformWrapper_createSingleBuffered(env, texture_id)); |
| 31 } |
| 32 |
24 SurfaceTexture::SurfaceTexture( | 33 SurfaceTexture::SurfaceTexture( |
25 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture) { | 34 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture) { |
26 j_surface_texture_.Reset(j_surface_texture); | 35 j_surface_texture_.Reset(j_surface_texture); |
27 } | 36 } |
28 | 37 |
29 SurfaceTexture::~SurfaceTexture() { | 38 SurfaceTexture::~SurfaceTexture() { |
30 JNIEnv* env = base::android::AttachCurrentThread(); | 39 JNIEnv* env = base::android::AttachCurrentThread(); |
31 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj()); | 40 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj()); |
32 } | 41 } |
33 | 42 |
34 void SurfaceTexture::SetFrameAvailableCallback( | 43 void SurfaceTexture::SetFrameAvailableCallback( |
35 const base::Closure& callback) { | 44 const base::Closure& callback) { |
36 JNIEnv* env = base::android::AttachCurrentThread(); | 45 JNIEnv* env = base::android::AttachCurrentThread(); |
37 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( | 46 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( |
38 env, | 47 env, |
39 j_surface_texture_.obj(), | 48 j_surface_texture_.obj(), |
40 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback))); | 49 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback))); |
41 } | 50 } |
42 | 51 |
43 void SurfaceTexture::UpdateTexImage() { | 52 void SurfaceTexture::UpdateTexImage() { |
44 JNIEnv* env = base::android::AttachCurrentThread(); | 53 JNIEnv* env = base::android::AttachCurrentThread(); |
45 Java_SurfaceTexturePlatformWrapper_updateTexImage(env, | 54 Java_SurfaceTexturePlatformWrapper_updateTexImage(env, |
46 j_surface_texture_.obj()); | 55 j_surface_texture_.obj()); |
47 } | 56 } |
48 | 57 |
| 58 void SurfaceTexture::ReleaseTexImage() { |
| 59 DCHECK(IsSingleBufferModeSupported()); |
| 60 JNIEnv* env = base::android::AttachCurrentThread(); |
| 61 Java_SurfaceTexturePlatformWrapper_releaseTexImage(env, |
| 62 j_surface_texture_.obj()); |
| 63 } |
| 64 |
49 void SurfaceTexture::GetTransformMatrix(float mtx[16]) { | 65 void SurfaceTexture::GetTransformMatrix(float mtx[16]) { |
50 JNIEnv* env = base::android::AttachCurrentThread(); | 66 JNIEnv* env = base::android::AttachCurrentThread(); |
51 | 67 |
52 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix( | 68 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix( |
53 env, env->NewFloatArray(16)); | 69 env, env->NewFloatArray(16)); |
54 Java_SurfaceTexturePlatformWrapper_getTransformMatrix( | 70 Java_SurfaceTexturePlatformWrapper_getTransformMatrix( |
55 env, j_surface_texture_.obj(), jmatrix.obj()); | 71 env, j_surface_texture_.obj(), jmatrix.obj()); |
56 | 72 |
57 jboolean is_copy; | 73 jboolean is_copy; |
58 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); | 74 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); |
(...skipping 23 matching lines...) Expand all Loading... |
82 ScopedJavaSurface surface(this); | 98 ScopedJavaSurface surface(this); |
83 // Note: This ensures that any local references used by | 99 // Note: This ensures that any local references used by |
84 // ANativeWindow_fromSurface are released immediately. This is needed as a | 100 // ANativeWindow_fromSurface are released immediately. This is needed as a |
85 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 101 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
86 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 102 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
87 ANativeWindow* native_window = ANativeWindow_fromSurface( | 103 ANativeWindow* native_window = ANativeWindow_fromSurface( |
88 env, surface.j_surface().obj()); | 104 env, surface.j_surface().obj()); |
89 return native_window; | 105 return native_window; |
90 } | 106 } |
91 | 107 |
| 108 // static |
| 109 bool SurfaceTexture::IsSingleBufferModeSupported() { |
| 110 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
| 111 } |
| 112 |
92 bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) { | 113 bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) { |
93 return RegisterNativesImpl(env); | 114 return RegisterNativesImpl(env); |
94 } | 115 } |
95 | 116 |
96 } // namespace gfx | 117 } // namespace gfx |
OLD | NEW |