Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: content/common/android/surface_texture_bridge.cc

Issue 10968009: Android: generates JNI bindings for constructors in system classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/android/surface_texture_bridge.h ('k') | content/content.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/common/android/surface_texture_listener.h" 9 #include "content/common/android/surface_texture_listener.h"
10 #include "jni/SurfaceTexture_jni.h"
10 11
11 using base::android::AttachCurrentThread; 12 using base::android::AttachCurrentThread;
12 using base::android::CheckException; 13 using base::android::CheckException;
13 using base::android::GetClass; 14 using base::android::GetClass;
14 using base::android::GetMethodID; 15 using base::android::GetMethodID;
15 using base::android::ScopedJavaLocalRef; 16 using base::android::ScopedJavaLocalRef;
16 17
18 namespace {
19 bool g_jni_initialized = false;
20
21 void RegisterNativesIfNeeded(JNIEnv* env) {
22 if (!g_jni_initialized) {
23 JNI_SurfaceTexture::RegisterNativesImpl(env);
24 g_jni_initialized = true;
25 }
26 }
27 } // namespace
28
17 namespace content { 29 namespace content {
18 30
19 SurfaceTextureBridge::SurfaceTextureBridge(int texture_id) 31 SurfaceTextureBridge::SurfaceTextureBridge(int texture_id)
20 : texture_id_(texture_id) { 32 : texture_id_(texture_id) {
21 JNIEnv* env = AttachCurrentThread(); 33 JNIEnv* env = AttachCurrentThread();
22 CHECK(env); 34 CHECK(env);
35 RegisterNativesIfNeeded(env);
23 36
24 j_class_.Reset(GetClass(env, "android/graphics/SurfaceTexture")); 37 ScopedJavaLocalRef<jobject> tmp(
25 jmethodID constructor = GetMethodID(env, j_class_, "<init>", "(I)V"); 38 JNI_SurfaceTexture::Java_SurfaceTexture_Constructor(env,
jam 2012/09/20 16:04:15 nit: the indentation of the parameters here (and t
bulach 2012/09/20 16:31:18 thanks jam! I'm not sure I fully understood, but..
jam 2012/09/20 16:53:20 doh. i just saw that. that's against the google st
26 ScopedJavaLocalRef<jobject> tmp(env, 39 texture_id));
27 env->NewObject(j_class_.obj(), constructor, texture_id));
28 DCHECK(!tmp.is_null()); 40 DCHECK(!tmp.is_null());
29 j_surface_texture_.Reset(tmp); 41 j_surface_texture_.Reset(tmp);
30 } 42 }
31 43
32 SurfaceTextureBridge::~SurfaceTextureBridge() { 44 SurfaceTextureBridge::~SurfaceTextureBridge() {
33 JNIEnv* env = AttachCurrentThread(); 45 JNIEnv* env = AttachCurrentThread();
34 CHECK(env); 46 CHECK(env);
35 47
36 // Release the listener. 48 // Release the listener.
37 const char* method_signature = 49 JNI_SurfaceTexture::Java_SurfaceTexture_setOnFrameAvailableListener(env,
38 "(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V"; 50 j_surface_texture_.obj(), NULL);
39 jmethodID method = GetMethodID(env, j_class_, "setOnFrameAvailableListener",
40 method_signature);
41 env->CallVoidMethod(j_surface_texture_.obj(), method, NULL);
42 CheckException(env);
43 51
44 // Release graphics memory. 52 // Release graphics memory.
45 jmethodID release = GetMethodID(env, j_class_, "release", "()V"); 53 JNI_SurfaceTexture::Java_SurfaceTexture_release(env,
46 env->CallVoidMethod(j_surface_texture_.obj(), release); 54 j_surface_texture_.obj());
47 CheckException(env);
48 } 55 }
49 56
50 void SurfaceTextureBridge::SetFrameAvailableCallback( 57 void SurfaceTextureBridge::SetFrameAvailableCallback(
51 const base::Closure& callback) { 58 const base::Closure& callback) {
52 JNIEnv* env = AttachCurrentThread(); 59 JNIEnv* env = AttachCurrentThread();
53 CHECK(env); 60 CHECK(env);
54 61
55 // Since the listener is owned by the Java SurfaceTexture object, setting 62 // Since the listener is owned by the Java SurfaceTexture object, setting
56 // a new listener here will release an existing one at the same time. 63 // a new listener here will release an existing one at the same time.
57 ScopedJavaLocalRef<jobject> j_listener(env, 64 ScopedJavaLocalRef<jobject> j_listener(env,
58 SurfaceTextureListener::CreateSurfaceTextureListener(env, callback)); 65 SurfaceTextureListener::CreateSurfaceTextureListener(env, callback));
59 DCHECK(!j_listener.is_null()); 66 DCHECK(!j_listener.is_null());
60 67
61 // Set it as the onFrameAvailableListener for our SurfaceTexture instance. 68 // Set it as the onFrameAvailableListener for our SurfaceTexture instance.
62 const char* method_signature = 69 JNI_SurfaceTexture::Java_SurfaceTexture_setOnFrameAvailableListener(env,
63 "(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V"; 70 j_surface_texture_.obj(), j_listener.obj());
64 jmethodID method = GetMethodID(env, j_class_, "setOnFrameAvailableListener",
65 method_signature);
66 env->CallVoidMethod(j_surface_texture_.obj(), method, j_listener.obj());
67 CheckException(env);
68 } 71 }
69 72
70 void SurfaceTextureBridge::UpdateTexImage() { 73 void SurfaceTextureBridge::UpdateTexImage() {
71 JNIEnv* env = AttachCurrentThread(); 74 JNIEnv* env = AttachCurrentThread();
72 CHECK(env); 75 CHECK(env);
73 76
74 jmethodID method = GetMethodID(env, j_class_, "updateTexImage", "()V"); 77 JNI_SurfaceTexture::Java_SurfaceTexture_updateTexImage(env,
75 env->CallVoidMethod(j_surface_texture_.obj(), method); 78 j_surface_texture_.obj());
76 CheckException(env);
77 } 79 }
78 80
79 void SurfaceTextureBridge::GetTransformMatrix(float mtx[16]) { 81 void SurfaceTextureBridge::GetTransformMatrix(float mtx[16]) {
80 JNIEnv* env = AttachCurrentThread(); 82 JNIEnv* env = AttachCurrentThread();
81 CHECK(env); 83 CHECK(env);
82 84
83 ScopedJavaLocalRef<jfloatArray> jmatrix(env, env->NewFloatArray(16)); 85 ScopedJavaLocalRef<jfloatArray> jmatrix(env, env->NewFloatArray(16));
84 jmethodID method = GetMethodID(env, j_class_, "getTransformMatrix", "([F)V"); 86 JNI_SurfaceTexture::Java_SurfaceTexture_getTransformMatrix(env,
85 env->CallVoidMethod(j_surface_texture_.obj(), method, jmatrix.obj()); 87 j_surface_texture_.obj(), jmatrix.obj());
86 CheckException(env);
87 88
88 jboolean is_copy; 89 jboolean is_copy;
89 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); 90 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy);
90 for (int i = 0; i < 16; ++i) { 91 for (int i = 0; i < 16; ++i) {
91 mtx[i] = static_cast<float>(elements[i]); 92 mtx[i] = static_cast<float>(elements[i]);
92 } 93 }
93 env->ReleaseFloatArrayElements(jmatrix.obj(), elements, JNI_ABORT); 94 env->ReleaseFloatArrayElements(jmatrix.obj(), elements, JNI_ABORT);
94 } 95 }
95 96
96 void SurfaceTextureBridge::SetDefaultBufferSize(int width, int height) { 97 void SurfaceTextureBridge::SetDefaultBufferSize(int width, int height) {
97 JNIEnv* env = AttachCurrentThread(); 98 JNIEnv* env = AttachCurrentThread();
98 CHECK(env); 99 CHECK(env);
99 100
100 jmethodID method = GetMethodID(env, j_class_, 101 JNI_SurfaceTexture::Java_SurfaceTexture_setDefaultBufferSize(env,
101 "setDefaultBufferSize", "(II)V"); 102 j_surface_texture_.obj(), static_cast<jint>(width),
102 env->CallVoidMethod(j_surface_texture_.obj(), method, 103 static_cast<jint>(height));
103 static_cast<jint>(width), static_cast<jint>(height));
104 CheckException(env);
105 } 104 }
106 105
107 } // namespace content 106 } // namespace content
OLDNEW
« no previous file with comments | « content/common/android/surface_texture_bridge.h ('k') | content/content.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698