OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/jni_display_handler.h" | 5 #include "remoting/client/jni/jni_display_handler.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 void JniDisplayHandler::SetCursorShape( | 97 void JniDisplayHandler::SetCursorShape( |
98 const protocol::CursorShapeInfo& cursor_shape) { | 98 const protocol::CursorShapeInfo& cursor_shape) { |
99 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 99 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
100 | 100 |
101 // const_cast<> is safe as long as the Java updateCursorShape() method copies | 101 // const_cast<> is safe as long as the Java updateCursorShape() method copies |
102 // the data out of the buffer without mutating it, and doesn't keep any | 102 // the data out of the buffer without mutating it, and doesn't keep any |
103 // reference to the buffer afterwards. Unfortunately, there seems to be no way | 103 // reference to the buffer afterwards. Unfortunately, there seems to be no way |
104 // to create a read-only ByteBuffer from a pointer-to-const. | 104 // to create a read-only ByteBuffer from a pointer-to-const. |
105 char* data = string_as_array(const_cast<std::string*>(&cursor_shape.data())); | 105 char* data = |
| 106 base::string_as_array(const_cast<std::string*>(&cursor_shape.data())); |
106 int cursor_total_bytes = | 107 int cursor_total_bytes = |
107 cursor_shape.width() * cursor_shape.height() * kBytesPerPixel; | 108 cursor_shape.width() * cursor_shape.height() * kBytesPerPixel; |
108 | 109 |
109 JNIEnv* env = base::android::AttachCurrentThread(); | 110 JNIEnv* env = base::android::AttachCurrentThread(); |
110 base::android::ScopedJavaLocalRef<jobject> buffer( | 111 base::android::ScopedJavaLocalRef<jobject> buffer( |
111 env, env->NewDirectByteBuffer(data, cursor_total_bytes)); | 112 env, env->NewDirectByteBuffer(data, cursor_total_bytes)); |
112 Java_Display_updateCursorShape( | 113 Java_Display_updateCursorShape( |
113 env, java_display_.obj(), cursor_shape.width(), cursor_shape.height(), | 114 env, java_display_.obj(), cursor_shape.width(), cursor_shape.height(), |
114 cursor_shape.hotspot_x(), cursor_shape.hotspot_y(), buffer.obj()); | 115 cursor_shape.hotspot_x(), cursor_shape.hotspot_y(), buffer.obj()); |
115 } | 116 } |
116 | 117 |
117 } // namespace remoting | 118 } // namespace remoting |
OLD | NEW |