Chromium Code Reviews| 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_runtime.h" | 5 #include "remoting/client/jni/chromoting_jni_runtime.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/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "media/base/yuv_convert.h" | 13 #include "media/base/yuv_convert.h" |
| 14 #include "net/android/net_jni_registrar.h" | 14 #include "net/android/net_jni_registrar.h" |
| 15 #include "remoting/base/url_request_context.h" | 15 #include "remoting/base/url_request_context.h" |
| 16 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Class and package name of the Java class supporting the methods we call. | 20 // Class and package name of the Java class supporting the methods we call. |
| 20 const char* const kJavaClass = "org/chromium/chromoting/jni/JniInterface"; | 21 const char* const kJavaClass = "org/chromium/chromoting/jni/JniInterface"; |
| 21 | 22 |
| 22 const int kBytesPerPixel = 4; | 23 const int kBytesPerPixel = 4; |
| 23 | 24 |
| 24 } // namespace | 25 } // namespace |
| 25 | 26 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 "commitPairingCredentials", | 163 "commitPairingCredentials", |
| 163 "(Ljava/lang/String;[B[B)V"), | 164 "(Ljava/lang/String;[B[B)V"), |
| 164 host_jstr, | 165 host_jstr, |
| 165 id_arr, | 166 id_arr, |
| 166 secret_arr); | 167 secret_arr); |
| 167 | 168 |
| 168 // Because we passed them as arguments, their corresponding Java objects were | 169 // Because we passed them as arguments, their corresponding Java objects were |
| 169 // GCd as soon as the managed method returned, so we mustn't release it here. | 170 // GCd as soon as the managed method returned, so we mustn't release it here. |
| 170 } | 171 } |
| 171 | 172 |
| 172 void ChromotingJniRuntime::UpdateImageBuffer(int width, | 173 base::android::ScopedJavaLocalRef<jobject> ChromotingJniRuntime::NewBitmap( |
| 173 int height, | 174 webrtc::DesktopSize size) { |
| 174 jobject buffer) { | 175 JNIEnv* env = base::android::AttachCurrentThread(); |
| 176 | |
| 177 jobject bitmap = env->CallStaticObjectMethod( | |
|
Yaron
2013/10/09 06:42:30
Any reason not to start switching this over to the
Lambros
2013/10/10 01:35:58
Can it be realistically done as part of this CL? I
Yaron
2013/10/10 11:13:37
Ok fair enough
| |
| 178 class_, | |
| 179 env->GetStaticMethodID( | |
| 180 class_, | |
| 181 "newBitmap", | |
| 182 "(II)Landroid/graphics/Bitmap;"), | |
| 183 size.width(), | |
| 184 size.height()); | |
| 185 return base::android::ScopedJavaLocalRef<jobject>(env, bitmap); | |
| 186 } | |
| 187 | |
| 188 void ChromotingJniRuntime::UpdateFrameBitmap(jobject bitmap) { | |
| 175 DCHECK(display_task_runner_->BelongsToCurrentThread()); | 189 DCHECK(display_task_runner_->BelongsToCurrentThread()); |
| 176 | 190 |
| 177 JNIEnv* env = base::android::AttachCurrentThread(); | 191 JNIEnv* env = base::android::AttachCurrentThread(); |
| 178 env->SetStaticIntField( | 192 |
| 193 env->CallStaticVoidMethod( | |
| 179 class_, | 194 class_, |
| 180 env->GetStaticFieldID(class_, "sWidth", "I"), | 195 env->GetStaticMethodID( |
| 181 width); | 196 class_, |
| 182 env->SetStaticIntField( | 197 "setVideoFrame", |
| 183 class_, | 198 "(Landroid/graphics/Bitmap;)V"), |
| 184 env->GetStaticFieldID(class_, "sHeight", "I"), | 199 bitmap); |
| 185 height); | |
| 186 env->SetStaticObjectField( | |
| 187 class_, | |
| 188 env->GetStaticFieldID(class_, "sBuffer", "Ljava/nio/ByteBuffer;"), | |
| 189 buffer); | |
| 190 } | 200 } |
| 191 | 201 |
| 192 void ChromotingJniRuntime::UpdateCursorShape( | 202 void ChromotingJniRuntime::UpdateCursorShape( |
| 193 const protocol::CursorShapeInfo& cursor_shape) { | 203 const protocol::CursorShapeInfo& cursor_shape) { |
| 194 DCHECK(display_task_runner_->BelongsToCurrentThread()); | 204 DCHECK(display_task_runner_->BelongsToCurrentThread()); |
| 195 | 205 |
| 196 // const_cast<> is safe as long as the Java updateCursorShape() method copies | 206 // const_cast<> is safe as long as the Java updateCursorShape() method copies |
| 197 // the data out of the buffer without mutating it, and doesn't keep any | 207 // the data out of the buffer without mutating it, and doesn't keep any |
| 198 // reference to the buffer afterwards. Unfortunately, there seems to be no way | 208 // reference to the buffer afterwards. Unfortunately, there seems to be no way |
| 199 // to create a read-only ByteBuffer from a pointer-to-const. | 209 // to create a read-only ByteBuffer from a pointer-to-const. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 225 class_, | 235 class_, |
| 226 env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); | 236 env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); |
| 227 } | 237 } |
| 228 | 238 |
| 229 void ChromotingJniRuntime::DetachFromVmAndSignal(base::WaitableEvent* waiter) { | 239 void ChromotingJniRuntime::DetachFromVmAndSignal(base::WaitableEvent* waiter) { |
| 230 base::android::DetachFromVM(); | 240 base::android::DetachFromVM(); |
| 231 waiter->Signal(); | 241 waiter->Signal(); |
| 232 } | 242 } |
| 233 | 243 |
| 234 } // namespace remoting | 244 } // namespace remoting |
| OLD | NEW |