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

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

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 2 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
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_callback.h" 5 #include "content/common/android/surface_callback.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/bind.h" 10 #include "base/bind.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "ui/gl/android_native_window.h" 17 #include "ui/gl/android_native_window.h"
18 #include "jni/SurfaceCallback_jni.h" 18 #include "jni/SurfaceCallback_jni.h"
19 19
20 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
21 using base::android::CheckException; 21 using base::android::CheckException;
22 using base::android::GetMethodID; 22 using base::android::GetClass;
23 using base::android::MethodID;
23 using base::WaitableEvent; 24 using base::WaitableEvent;
24 using content::SurfaceTexturePeer; 25 using content::SurfaceTexturePeer;
25 26
26 namespace content { 27 namespace content {
27 28
28 namespace { 29 namespace {
29 30
30 struct GlobalState { 31 struct GlobalState {
31 base::Lock registration_lock; 32 base::Lock registration_lock;
32 // We hold a reference to a message loop proxy which handles message loop 33 // We hold a reference to a message loop proxy which handles message loop
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 primaryID, secondaryID, NULL); 70 primaryID, secondaryID, NULL);
70 } 71 }
71 72
72 void ReleaseSurface(jobject surface) { 73 void ReleaseSurface(jobject surface) {
73 if (surface == NULL) 74 if (surface == NULL)
74 return; 75 return;
75 76
76 JNIEnv* env = AttachCurrentThread(); 77 JNIEnv* env = AttachCurrentThread();
77 CHECK(env); 78 CHECK(env);
78 79
79 jclass cls = env->FindClass("android/view/Surface"); 80 ScopedJavaLocalRef<jclass> cls(GetClass(env, "android/view/Surface"));
80 DCHECK(cls);
81 81
82 jmethodID method = env->GetMethodID(cls, "release", "()V"); 82 jmethodID method = MethodID::Get<MethodID::TYPE_INSTANCE>(
83 DCHECK(method); 83 env, cls.obj(), "release", "()V");
84 84
85 env->CallVoidMethod(surface, method); 85 env->CallVoidMethod(surface, method);
86 DCHECK(env);
87
88 env->DeleteLocalRef(cls);
89 } 86 }
90 87
91 void SetSurfaceAsync(JNIEnv* env, 88 void SetSurfaceAsync(JNIEnv* env,
92 jobject jsurface, 89 jobject jsurface,
93 SurfaceTexturePeer::SurfaceTextureTarget type, 90 SurfaceTexturePeer::SurfaceTextureTarget type,
94 int primary_id, 91 int primary_id,
95 int secondary_id, 92 int secondary_id,
96 WaitableEvent* completion) { 93 WaitableEvent* completion) {
97 base::AutoLock lock(g_state.Pointer()->registration_lock); 94 base::AutoLock lock(g_state.Pointer()->registration_lock);
98 95
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 base::AutoLock lock(global_state->registration_lock); 146 base::AutoLock lock(global_state->registration_lock);
150 global_state->native_window_loop = loop; 147 global_state->native_window_loop = loop;
151 global_state->native_window_callback = callback; 148 global_state->native_window_callback = callback;
152 } 149 }
153 150
154 bool RegisterSurfaceCallback(JNIEnv* env) { 151 bool RegisterSurfaceCallback(JNIEnv* env) {
155 return RegisterNativesImpl(env); 152 return RegisterNativesImpl(env);
156 } 153 }
157 154
158 } // namespace content 155 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/java/java_method.cc ('k') | content/common/android/surface_texture_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698