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

Unified Diff: remoting/client/jni/chromoting_jni_runtime.cc

Issue 23532072: Draw the mouse cursor in Chromoting Android client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: remoting/client/jni/chromoting_jni_runtime.cc
diff --git a/remoting/client/jni/chromoting_jni_runtime.cc b/remoting/client/jni/chromoting_jni_runtime.cc
index 059a4b2b150cb9a63c3d2afea2fccad8f94f30eb..108bb71339d937272e1885c7dd39b03e04d73a1a 100644
--- a/remoting/client/jni/chromoting_jni_runtime.cc
+++ b/remoting/client/jni/chromoting_jni_runtime.cc
@@ -6,15 +6,23 @@
#include "base/android/base_jni_registrar.h"
#include "base/android/jni_android.h"
+#include "base/android/scoped_java_ref.h"
#include "base/memory/singleton.h"
+#include "base/stl_util.h"
#include "base/synchronization/waitable_event.h"
#include "media/base/yuv_convert.h"
#include "net/android/net_jni_registrar.h"
#include "remoting/base/url_request_context.h"
+namespace {
+
// Class and package name of the Java class supporting the methods we call.
const char* const kJavaClass = "org/chromium/chromoting/jni/JniInterface";
+const int kBytesPerPixel = 4;
+
+} // namespace
+
namespace remoting {
// static
@@ -181,6 +189,34 @@ void ChromotingJniRuntime::UpdateImageBuffer(int width,
buffer);
}
+void ChromotingJniRuntime::UpdateCursorShape(
+ const protocol::CursorShapeInfo& cursor_shape) {
+ DCHECK(display_task_runner_->BelongsToCurrentThread());
+
+ // const_cast<> is safe as long as the Java updateCursorShape() method copies
+ // the data out of the buffer without mutating it, and doesn't keep any
+ // reference to the buffer afterwards. Unfortunately, there seems to be no way
+ // to create a read-only ByteBuffer from a pointer-to-const.
+ char* data = string_as_array(const_cast<std::string*>(&cursor_shape.data()));
+ int cursor_total_bytes =
+ cursor_shape.width() * cursor_shape.height() * kBytesPerPixel;
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ base::android::ScopedJavaLocalRef<jobject> buffer(env,
+ env->NewDirectByteBuffer(data, cursor_total_bytes));
+ env->CallStaticVoidMethod(
+ class_,
+ env->GetStaticMethodID(
+ class_,
+ "updateCursorShape",
+ "(IIIILjava/nio/ByteBuffer;)V"),
+ cursor_shape.width(),
+ cursor_shape.height(),
+ cursor_shape.hotspot_x(),
+ cursor_shape.hotspot_y(),
+ buffer.obj());
+}
+
void ChromotingJniRuntime::RedrawCanvas() {
DCHECK(display_task_runner_->BelongsToCurrentThread());

Powered by Google App Engine
This is Rietveld 408576698