Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/client/jni/jni_display_handler.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/bind.h" | |
| 9 #include "base/location.h" | |
| 10 #include "base/stl_util.h" | |
| 11 #include "jni/Display_jni.h" | |
| 12 #include "remoting/client/jni/chromoting_jni_runtime.h" | |
| 13 #include "remoting/client/jni/jni_client.h" | |
| 14 | |
| 15 using base::android::JavaParamRef; | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const int kBytesPerPixel = 4; | |
|
Lambros
2016/05/28 00:43:05
Either add blank line here, or remove blank line a
Yuwei
2016/06/01 21:30:11
Done.
| |
| 20 } | |
| 21 | |
| 22 namespace remoting { | |
| 23 | |
| 24 JniDisplayHandler::JniDisplayHandler( | |
| 25 scoped_refptr<base::SingleThreadTaskRunner> display_runner, | |
| 26 base::android::ScopedJavaGlobalRef<jobject> java_display) : | |
| 27 display_runner_(display_runner), | |
| 28 java_display_(java_display), | |
| 29 weak_factory_(this) { | |
| 30 } | |
| 31 | |
| 32 JniDisplayHandler::~JniDisplayHandler() { | |
| 33 DCHECK(display_runner_->BelongsToCurrentThread()); | |
| 34 } | |
| 35 | |
| 36 base::android::ScopedJavaLocalRef<jobject> JniDisplayHandler::NewBitmap( | |
|
Lambros
2016/05/28 00:43:05
Add "// static" comment, and make this a static me
Yuwei
2016/06/01 21:30:11
Done.
| |
| 37 int width, | |
| 38 int height) { | |
|
Lambros
2016/05/28 00:43:05
Can fit on previous line. Run git cl format
Yuwei
2016/06/01 21:30:10
It doesn't seem like cl format makes any change...
| |
| 39 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 40 return Java_Display_newBitmap(env, width, height); | |
| 41 } | |
| 42 | |
| 43 void JniDisplayHandler::UpdateFrameBitmap( | |
| 44 base::android::ScopedJavaGlobalRef<jobject> bitmap) { | |
| 45 DCHECK(display_runner_->BelongsToCurrentThread()); | |
| 46 | |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 48 Java_Display_setVideoFrame(env, java_display_.obj(), bitmap.obj()); | |
| 49 } | |
| 50 | |
| 51 void JniDisplayHandler::UpdateCursorShape( | |
| 52 const protocol::CursorShapeInfo& cursor_shape) { | |
| 53 DCHECK(display_runner_->BelongsToCurrentThread()); | |
| 54 | |
| 55 // const_cast<> is safe as long as the Java updateCursorShape() method copies | |
| 56 // the data out of the buffer without mutating it, and doesn't keep any | |
| 57 // reference to the buffer afterwards. Unfortunately, there seems to be no way | |
| 58 // to create a read-only ByteBuffer from a pointer-to-const. | |
| 59 char* data = string_as_array(const_cast<std::string*>(&cursor_shape.data())); | |
| 60 int cursor_total_bytes = | |
| 61 cursor_shape.width() * cursor_shape.height() * kBytesPerPixel; | |
| 62 | |
| 63 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 64 base::android::ScopedJavaLocalRef<jobject> buffer( | |
| 65 env, env->NewDirectByteBuffer(data, cursor_total_bytes)); | |
| 66 Java_Display_updateCursorShape(env, java_display_.obj(), cursor_shape.width(), | |
| 67 cursor_shape.height(), cursor_shape.hotspot_x(), | |
| 68 cursor_shape.hotspot_y(), buffer.obj()); | |
| 69 } | |
| 70 | |
| 71 void JniDisplayHandler::RedrawCanvas() { | |
| 72 DCHECK(display_runner_->BelongsToCurrentThread()); | |
| 73 | |
| 74 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 75 Java_Display_redrawGraphicsInternal(env, java_display_.obj()); | |
| 76 } | |
| 77 | |
| 78 base::WeakPtr<JniDisplayHandler> JniDisplayHandler::GetWeakPtr() { | |
| 79 return weak_factory_.GetWeakPtr(); | |
| 80 } | |
| 81 | |
| 82 // static | |
| 83 bool JniDisplayHandler::RegisterJni(JNIEnv* env) { | |
| 84 return RegisterNativesImpl(env); | |
| 85 } | |
| 86 | |
| 87 void JniDisplayHandler::Destroy( | |
| 88 JNIEnv* env, | |
| 89 const base::android::JavaParamRef<jobject>& caller) { | |
| 90 if (display_runner_->BelongsToCurrentThread()) { | |
| 91 delete this; | |
| 92 } else { | |
| 93 display_runner_->DeleteSoon(FROM_HERE, this); | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 void JniDisplayHandler::ScheduleRedraw( | |
| 98 JNIEnv* env, | |
| 99 const base::android::JavaParamRef<jobject>& caller) { | |
| 100 display_runner_->PostTask( | |
| 101 FROM_HERE, base::Bind(&JniDisplayHandler::RedrawCanvas, GetWeakPtr())); | |
| 102 } | |
| 103 | |
| 104 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& caller) { | |
| 105 return reinterpret_cast<intptr_t>( | |
| 106 new JniDisplayHandler( | |
| 107 ChromotingJniRuntime::GetInstance()->display_task_runner(), | |
| 108 base::android::ScopedJavaGlobalRef<jobject>(env, caller))); | |
| 109 } | |
| 110 | |
| 111 } // namespace remoting | |
| OLD | NEW |