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

Side by Side 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: address comment 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 unified diff | Download patch
« no previous file with comments | « remoting/client/jni/chromoting_jni_runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/stl_util.h"
10 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
11 #include "media/base/yuv_convert.h" 13 #include "media/base/yuv_convert.h"
12 #include "net/android/net_jni_registrar.h" 14 #include "net/android/net_jni_registrar.h"
13 #include "remoting/base/url_request_context.h" 15 #include "remoting/base/url_request_context.h"
14 16
17 namespace {
18
15 // Class and package name of the Java class supporting the methods we call. 19 // Class and package name of the Java class supporting the methods we call.
16 const char* const kJavaClass = "org/chromium/chromoting/jni/JniInterface"; 20 const char* const kJavaClass = "org/chromium/chromoting/jni/JniInterface";
17 21
22 const int kBytesPerPixel = 4;
23
24 } // namespace
25
18 namespace remoting { 26 namespace remoting {
19 27
20 // static 28 // static
21 ChromotingJniRuntime* ChromotingJniRuntime::GetInstance() { 29 ChromotingJniRuntime* ChromotingJniRuntime::GetInstance() {
22 return Singleton<ChromotingJniRuntime>::get(); 30 return Singleton<ChromotingJniRuntime>::get();
23 } 31 }
24 32
25 ChromotingJniRuntime::ChromotingJniRuntime() { 33 ChromotingJniRuntime::ChromotingJniRuntime() {
26 // Obtain a reference to the Java environment. (Future calls to this function 34 // Obtain a reference to the Java environment. (Future calls to this function
27 // made from the same thread return the same stored reference instead of 35 // made from the same thread return the same stored reference instead of
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 env->SetStaticIntField( 182 env->SetStaticIntField(
175 class_, 183 class_,
176 env->GetStaticFieldID(class_, "sHeight", "I"), 184 env->GetStaticFieldID(class_, "sHeight", "I"),
177 height); 185 height);
178 env->SetStaticObjectField( 186 env->SetStaticObjectField(
179 class_, 187 class_,
180 env->GetStaticFieldID(class_, "sBuffer", "Ljava/nio/ByteBuffer;"), 188 env->GetStaticFieldID(class_, "sBuffer", "Ljava/nio/ByteBuffer;"),
181 buffer); 189 buffer);
182 } 190 }
183 191
192 void ChromotingJniRuntime::UpdateCursorShape(
193 const protocol::CursorShapeInfo& cursor_shape) {
194 DCHECK(display_task_runner_->BelongsToCurrentThread());
195
196 // 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
198 // reference to the buffer afterwards. Unfortunately, there seems to be no way
199 // to create a read-only ByteBuffer from a pointer-to-const.
200 char* data = string_as_array(const_cast<std::string*>(&cursor_shape.data()));
201 int cursor_total_bytes =
202 cursor_shape.width() * cursor_shape.height() * kBytesPerPixel;
203
204 JNIEnv* env = base::android::AttachCurrentThread();
205 base::android::ScopedJavaLocalRef<jobject> buffer(env,
206 env->NewDirectByteBuffer(data, cursor_total_bytes));
207 env->CallStaticVoidMethod(
208 class_,
209 env->GetStaticMethodID(
210 class_,
211 "updateCursorShape",
212 "(IIIILjava/nio/ByteBuffer;)V"),
213 cursor_shape.width(),
214 cursor_shape.height(),
215 cursor_shape.hotspot_x(),
216 cursor_shape.hotspot_y(),
217 buffer.obj());
218 }
219
184 void ChromotingJniRuntime::RedrawCanvas() { 220 void ChromotingJniRuntime::RedrawCanvas() {
185 DCHECK(display_task_runner_->BelongsToCurrentThread()); 221 DCHECK(display_task_runner_->BelongsToCurrentThread());
186 222
187 JNIEnv* env = base::android::AttachCurrentThread(); 223 JNIEnv* env = base::android::AttachCurrentThread();
188 env->CallStaticVoidMethod( 224 env->CallStaticVoidMethod(
189 class_, 225 class_,
190 env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); 226 env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V"));
191 } 227 }
192 228
193 void ChromotingJniRuntime::DetachFromVmAndSignal(base::WaitableEvent* waiter) { 229 void ChromotingJniRuntime::DetachFromVmAndSignal(base::WaitableEvent* waiter) {
194 base::android::DetachFromVM(); 230 base::android::DetachFromVM();
195 waiter->Signal(); 231 waiter->Signal();
196 } 232 }
197 233
198 } // namespace remoting 234 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/jni/chromoting_jni_runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698