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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); | 21 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); |
22 } | 22 } |
23 | 23 |
24 SurfaceTexture::SurfaceTexture( | 24 SurfaceTexture::SurfaceTexture( |
25 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture) { | 25 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture) { |
26 j_surface_texture_.Reset(j_surface_texture); | 26 j_surface_texture_.Reset(j_surface_texture); |
27 } | 27 } |
28 | 28 |
29 SurfaceTexture::~SurfaceTexture() { | 29 SurfaceTexture::~SurfaceTexture() { |
30 JNIEnv* env = base::android::AttachCurrentThread(); | 30 JNIEnv* env = base::android::AttachCurrentThread(); |
31 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj()); | 31 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_); |
32 } | 32 } |
33 | 33 |
34 void SurfaceTexture::SetFrameAvailableCallback( | 34 void SurfaceTexture::SetFrameAvailableCallback( |
35 const base::Closure& callback) { | 35 const base::Closure& callback) { |
36 JNIEnv* env = base::android::AttachCurrentThread(); | 36 JNIEnv* env = base::android::AttachCurrentThread(); |
37 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( | 37 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( |
38 env, j_surface_texture_.obj(), | 38 env, j_surface_texture_, |
39 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback, false))); | 39 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback, false))); |
40 } | 40 } |
41 | 41 |
42 void SurfaceTexture::SetFrameAvailableCallbackOnAnyThread( | 42 void SurfaceTexture::SetFrameAvailableCallbackOnAnyThread( |
43 const base::Closure& callback) { | 43 const base::Closure& callback) { |
44 JNIEnv* env = base::android::AttachCurrentThread(); | 44 JNIEnv* env = base::android::AttachCurrentThread(); |
45 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( | 45 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( |
46 env, j_surface_texture_.obj(), | 46 env, j_surface_texture_, |
47 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback, true))); | 47 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback, true))); |
48 } | 48 } |
49 | 49 |
50 void SurfaceTexture::UpdateTexImage() { | 50 void SurfaceTexture::UpdateTexImage() { |
51 JNIEnv* env = base::android::AttachCurrentThread(); | 51 JNIEnv* env = base::android::AttachCurrentThread(); |
52 Java_SurfaceTexturePlatformWrapper_updateTexImage(env, | 52 Java_SurfaceTexturePlatformWrapper_updateTexImage(env, j_surface_texture_); |
53 j_surface_texture_.obj()); | |
54 } | 53 } |
55 | 54 |
56 void SurfaceTexture::GetTransformMatrix(float mtx[16]) { | 55 void SurfaceTexture::GetTransformMatrix(float mtx[16]) { |
57 JNIEnv* env = base::android::AttachCurrentThread(); | 56 JNIEnv* env = base::android::AttachCurrentThread(); |
58 | 57 |
59 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix( | 58 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix( |
60 env, env->NewFloatArray(16)); | 59 env, env->NewFloatArray(16)); |
61 Java_SurfaceTexturePlatformWrapper_getTransformMatrix( | 60 Java_SurfaceTexturePlatformWrapper_getTransformMatrix(env, j_surface_texture_, |
62 env, j_surface_texture_.obj(), jmatrix.obj()); | 61 jmatrix); |
63 | 62 |
64 jboolean is_copy; | 63 jboolean is_copy; |
65 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); | 64 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); |
66 for (int i = 0; i < 16; ++i) { | 65 for (int i = 0; i < 16; ++i) { |
67 mtx[i] = static_cast<float>(elements[i]); | 66 mtx[i] = static_cast<float>(elements[i]); |
68 } | 67 } |
69 env->ReleaseFloatArrayElements(jmatrix.obj(), elements, JNI_ABORT); | 68 env->ReleaseFloatArrayElements(jmatrix.obj(), elements, JNI_ABORT); |
70 } | 69 } |
71 | 70 |
72 void SurfaceTexture::AttachToGLContext() { | 71 void SurfaceTexture::AttachToGLContext() { |
73 int texture_id; | 72 int texture_id; |
74 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); | 73 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
75 DCHECK(texture_id); | 74 DCHECK(texture_id); |
76 JNIEnv* env = base::android::AttachCurrentThread(); | 75 JNIEnv* env = base::android::AttachCurrentThread(); |
77 Java_SurfaceTexturePlatformWrapper_attachToGLContext( | 76 Java_SurfaceTexturePlatformWrapper_attachToGLContext(env, j_surface_texture_, |
78 env, j_surface_texture_.obj(), texture_id); | 77 texture_id); |
79 } | 78 } |
80 | 79 |
81 void SurfaceTexture::DetachFromGLContext() { | 80 void SurfaceTexture::DetachFromGLContext() { |
82 JNIEnv* env = base::android::AttachCurrentThread(); | 81 JNIEnv* env = base::android::AttachCurrentThread(); |
83 Java_SurfaceTexturePlatformWrapper_detachFromGLContext( | 82 Java_SurfaceTexturePlatformWrapper_detachFromGLContext(env, |
84 env, j_surface_texture_.obj()); | 83 j_surface_texture_); |
85 } | 84 } |
86 | 85 |
87 ANativeWindow* SurfaceTexture::CreateSurface() { | 86 ANativeWindow* SurfaceTexture::CreateSurface() { |
88 JNIEnv* env = base::android::AttachCurrentThread(); | 87 JNIEnv* env = base::android::AttachCurrentThread(); |
89 ScopedJavaSurface surface(this); | 88 ScopedJavaSurface surface(this); |
90 // Note: This ensures that any local references used by | 89 // Note: This ensures that any local references used by |
91 // ANativeWindow_fromSurface are released immediately. This is needed as a | 90 // ANativeWindow_fromSurface are released immediately. This is needed as a |
92 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 91 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
93 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 92 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
94 ANativeWindow* native_window = ANativeWindow_fromSurface( | 93 ANativeWindow* native_window = ANativeWindow_fromSurface( |
95 env, surface.j_surface().obj()); | 94 env, surface.j_surface().obj()); |
96 return native_window; | 95 return native_window; |
97 } | 96 } |
98 | 97 |
99 void SurfaceTexture::ReleaseSurfaceTexture() { | 98 void SurfaceTexture::ReleaseSurfaceTexture() { |
100 JNIEnv* env = base::android::AttachCurrentThread(); | 99 JNIEnv* env = base::android::AttachCurrentThread(); |
101 Java_SurfaceTexturePlatformWrapper_release(env, j_surface_texture_.obj()); | 100 Java_SurfaceTexturePlatformWrapper_release(env, j_surface_texture_); |
102 } | 101 } |
103 | 102 |
104 } // namespace gl | 103 } // namespace gl |
OLD | NEW |