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 // 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 "jni/SurfaceTexturePlatformWrapper_jni.h" | 13 #include "jni/SurfaceTexturePlatformWrapper_jni.h" |
14 #include "ui/gl/android/scoped_java_surface.h" | 14 #include "ui/gl/android/scoped_java_surface.h" |
15 #include "ui/gl/android/surface_texture_listener.h" | 15 #include "ui/gl/android/surface_texture_listener.h" |
16 #include "ui/gl/gl_bindings.h" | 16 #include "ui/gl/gl_bindings.h" |
17 | 17 |
18 // TODO(boliu): Remove this method when when we move off ICS. See | 18 // TODO(boliu): Remove this method when when we move off ICS. See |
19 // http://crbug.com/161864. | 19 // http://crbug.com/161864. |
20 bool GlContextMethodsAvailable() { | 20 bool GlContextMethodsAvailable() { |
21 bool available = base::android::BuildInfo::GetInstance()->sdk_int() >= 16; | 21 bool available = base::android::BuildInfo::GetInstance()->sdk_int() >= 16; |
22 if (!available) | 22 if (!available) |
23 LOG(WARNING) << "Running on unsupported device: rendering may not work"; | 23 LOG(WARNING) << "Running on unsupported device: rendering may not work"; |
24 return available; | 24 return available; |
25 } | 25 } |
26 | 26 |
27 namespace gfx { | 27 namespace gfx { |
28 | 28 |
29 SurfaceTexture::SurfaceTexture(int texture_id) { | 29 scoped_refptr<SurfaceTexture> SurfaceTexture::Create(int texture_id) { |
30 JNIEnv* env = base::android::AttachCurrentThread(); | 30 JNIEnv* env = base::android::AttachCurrentThread(); |
31 j_surface_texture_.Reset( | 31 return new SurfaceTexture( |
32 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); | 32 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); |
33 } | 33 } |
34 | 34 |
| 35 scoped_refptr<SurfaceTexture> SurfaceTexture::CreateSingleBuffered( |
| 36 int texture_id) { |
| 37 DCHECK(IsSingleBufferModeSupported()); |
| 38 JNIEnv* env = base::android::AttachCurrentThread(); |
| 39 return new SurfaceTexture( |
| 40 Java_SurfaceTexturePlatformWrapper_createSingleBuffered(env, texture_id)); |
| 41 } |
| 42 |
| 43 SurfaceTexture::SurfaceTexture( |
| 44 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture) { |
| 45 j_surface_texture_.Reset(j_surface_texture); |
| 46 } |
| 47 |
35 SurfaceTexture::~SurfaceTexture() { | 48 SurfaceTexture::~SurfaceTexture() { |
36 JNIEnv* env = base::android::AttachCurrentThread(); | 49 JNIEnv* env = base::android::AttachCurrentThread(); |
37 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj()); | 50 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj()); |
38 } | 51 } |
39 | 52 |
40 void SurfaceTexture::SetFrameAvailableCallback( | 53 void SurfaceTexture::SetFrameAvailableCallback( |
41 const base::Closure& callback) { | 54 const base::Closure& callback) { |
42 JNIEnv* env = base::android::AttachCurrentThread(); | 55 JNIEnv* env = base::android::AttachCurrentThread(); |
43 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( | 56 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( |
44 env, | 57 env, |
45 j_surface_texture_.obj(), | 58 j_surface_texture_.obj(), |
46 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback))); | 59 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback))); |
47 } | 60 } |
48 | 61 |
49 void SurfaceTexture::UpdateTexImage() { | 62 void SurfaceTexture::UpdateTexImage() { |
50 JNIEnv* env = base::android::AttachCurrentThread(); | 63 JNIEnv* env = base::android::AttachCurrentThread(); |
51 Java_SurfaceTexturePlatformWrapper_updateTexImage(env, | 64 Java_SurfaceTexturePlatformWrapper_updateTexImage(env, |
52 j_surface_texture_.obj()); | 65 j_surface_texture_.obj()); |
53 } | 66 } |
54 | 67 |
| 68 void SurfaceTexture::ReleaseTexImage() { |
| 69 DCHECK(IsSingleBufferModeSupported()); |
| 70 JNIEnv* env = base::android::AttachCurrentThread(); |
| 71 Java_SurfaceTexturePlatformWrapper_releaseTexImage(env, |
| 72 j_surface_texture_.obj()); |
| 73 } |
| 74 |
55 void SurfaceTexture::GetTransformMatrix(float mtx[16]) { | 75 void SurfaceTexture::GetTransformMatrix(float mtx[16]) { |
56 JNIEnv* env = base::android::AttachCurrentThread(); | 76 JNIEnv* env = base::android::AttachCurrentThread(); |
57 | 77 |
58 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix( | 78 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix( |
59 env, env->NewFloatArray(16)); | 79 env, env->NewFloatArray(16)); |
60 Java_SurfaceTexturePlatformWrapper_getTransformMatrix( | 80 Java_SurfaceTexturePlatformWrapper_getTransformMatrix( |
61 env, j_surface_texture_.obj(), jmatrix.obj()); | 81 env, j_surface_texture_.obj(), jmatrix.obj()); |
62 | 82 |
63 jboolean is_copy; | 83 jboolean is_copy; |
64 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); | 84 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 122 |
103 ANativeWindow* SurfaceTexture::CreateSurface() { | 123 ANativeWindow* SurfaceTexture::CreateSurface() { |
104 JNIEnv* env = base::android::AttachCurrentThread(); | 124 JNIEnv* env = base::android::AttachCurrentThread(); |
105 ScopedJavaSurface surface(this); | 125 ScopedJavaSurface surface(this); |
106 ANativeWindow* native_window = ANativeWindow_fromSurface( | 126 ANativeWindow* native_window = ANativeWindow_fromSurface( |
107 env, surface.j_surface().obj()); | 127 env, surface.j_surface().obj()); |
108 return native_window; | 128 return native_window; |
109 } | 129 } |
110 | 130 |
111 // static | 131 // static |
| 132 bool SurfaceTexture::IsSingleBufferModeSupported() { |
| 133 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
| 134 } |
| 135 |
112 bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) { | 136 bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) { |
113 return RegisterNativesImpl(env); | 137 return RegisterNativesImpl(env); |
114 } | 138 } |
115 | 139 |
116 } // namespace gfx | 140 } // namespace gfx |
OLD | NEW |