| 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 "remoting/client/jni/chromoting_jni.h" | 5 #include "remoting/client/jni/chromoting_jni.h" |
| 6 | 6 |
| 7 #include "base/android/base_jni_registrar.h" | 7 #include "base/android/base_jni_registrar.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "media/base/yuv_convert.h" |
| 10 #include "net/android/net_jni_registrar.h" | 11 #include "net/android/net_jni_registrar.h" |
| 11 #include "remoting/base/url_request_context.h" | 12 #include "remoting/base/url_request_context.h" |
| 12 #include "remoting/client/jni/chromoting_jni_instance.h" | |
| 13 | 13 |
| 14 namespace { | |
| 15 // Class and package name of the Java class supporting the methods we call. | 14 // Class and package name of the Java class supporting the methods we call. |
| 16 const char* const JAVA_CLASS = "org/chromium/chromoting/jni/JNIInterface"; | 15 const char* const JAVA_CLASS = "org/chromium/chromoting/jni/JniInterface"; |
| 17 } // namespace | |
| 18 | 16 |
| 19 namespace remoting { | 17 namespace remoting { |
| 20 | 18 |
| 21 // static | 19 // static |
| 22 ChromotingJni* ChromotingJni::GetInstance() { | 20 ChromotingJni* ChromotingJni::GetInstance() { |
| 23 return Singleton<ChromotingJni>::get(); | 21 return Singleton<ChromotingJni>::get(); |
| 24 } | 22 } |
| 25 | 23 |
| 26 ChromotingJni::ChromotingJni() { | 24 ChromotingJni::ChromotingJni() { |
| 27 // Obtain a reference to the Java environment. (Future calls to this function | 25 // Obtain a reference to the Java environment. (Future calls to this function |
| (...skipping 19 matching lines...) Expand all Loading... |
| 47 base::MessageLoop::QuitClosure()); | 45 base::MessageLoop::QuitClosure()); |
| 48 network_task_runner_ = AutoThread::CreateWithType("native_net", | 46 network_task_runner_ = AutoThread::CreateWithType("native_net", |
| 49 ui_task_runner_, | 47 ui_task_runner_, |
| 50 base::MessageLoop::TYPE_IO); | 48 base::MessageLoop::TYPE_IO); |
| 51 display_task_runner_ = AutoThread::Create("native_disp", | 49 display_task_runner_ = AutoThread::Create("native_disp", |
| 52 ui_task_runner_); | 50 ui_task_runner_); |
| 53 | 51 |
| 54 url_requester_ = new URLRequestContextGetter(ui_task_runner_, | 52 url_requester_ = new URLRequestContextGetter(ui_task_runner_, |
| 55 network_task_runner_); | 53 network_task_runner_); |
| 56 | 54 |
| 55 // Allows later decoding of video frames. |
| 56 media::InitializeCPUSpecificYUVConversions(); |
| 57 |
| 57 class_ = static_cast<jclass>(env->NewGlobalRef(env->FindClass(JAVA_CLASS))); | 58 class_ = static_cast<jclass>(env->NewGlobalRef(env->FindClass(JAVA_CLASS))); |
| 58 } | 59 } |
| 59 | 60 |
| 60 ChromotingJni::~ChromotingJni() { | 61 ChromotingJni::~ChromotingJni() { |
| 61 // The singleton should only ever be destroyed on the main thread. | 62 // The singleton should only ever be destroyed on the main thread. |
| 62 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 63 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 63 | 64 |
| 64 // The session must be shut down first, since it depends on our other | 65 // The session must be shut down first, since it depends on our other |
| 65 // components' still being alive. | 66 // components' still being alive. |
| 66 DisconnectFromHost(); | 67 DisconnectFromHost(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 void ChromotingJni::DisplayAuthenticationPrompt() { | 109 void ChromotingJni::DisplayAuthenticationPrompt() { |
| 109 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 110 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 110 | 111 |
| 111 JNIEnv* env = base::android::AttachCurrentThread(); | 112 JNIEnv* env = base::android::AttachCurrentThread(); |
| 112 env->CallStaticVoidMethod( | 113 env->CallStaticVoidMethod( |
| 113 class_, | 114 class_, |
| 114 env->GetStaticMethodID(class_, "displayAuthenticationPrompt", "()V")); | 115 env->GetStaticMethodID(class_, "displayAuthenticationPrompt", "()V")); |
| 115 } | 116 } |
| 116 | 117 |
| 118 void ChromotingJni::UpdateImageBuffer(int width, int height, jobject buffer) { |
| 119 DCHECK(display_task_runner_->BelongsToCurrentThread()); |
| 120 |
| 121 JNIEnv* env = base::android::AttachCurrentThread(); |
| 122 env->SetStaticIntField( |
| 123 class_, |
| 124 env->GetStaticFieldID(class_, "sWidth", "I"), |
| 125 width); |
| 126 env->SetStaticIntField( |
| 127 class_, |
| 128 env->GetStaticFieldID(class_, "sHeight", "I"), |
| 129 height); |
| 130 env->SetStaticObjectField( |
| 131 class_, |
| 132 env->GetStaticFieldID(class_, "sBuffer", "Ljava/nio/ByteBuffer;"), |
| 133 buffer); |
| 134 } |
| 135 |
| 136 void ChromotingJni::RedrawCanvas() { |
| 137 DCHECK(display_task_runner_->BelongsToCurrentThread()); |
| 138 |
| 139 JNIEnv* env = base::android::AttachCurrentThread(); |
| 140 env->CallStaticVoidMethod( |
| 141 class_, |
| 142 env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); |
| 143 } |
| 144 |
| 117 } // namespace remoting | 145 } // namespace remoting |
| OLD | NEW |