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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 | 46 |
47 void DisplayCursorShapeStub::SetCursorShape( | 47 void DisplayCursorShapeStub::SetCursorShape( |
48 const protocol::CursorShapeInfo& cursor_shape) { | 48 const protocol::CursorShapeInfo& cursor_shape) { |
49 task_runner_->PostTask(FROM_HERE, | 49 task_runner_->PostTask(FROM_HERE, |
50 base::Bind(&JniDisplayHandler::UpdateCursorShape, | 50 base::Bind(&JniDisplayHandler::UpdateCursorShape, |
51 display_handler_, | 51 display_handler_, |
52 cursor_shape)); | 52 cursor_shape)); |
53 } | 53 } |
54 | 54 |
55 // JniDisplayHandler definitions. | 55 // JniDisplayHandler definitions. |
56 JniDisplayHandler::JniDisplayHandler( | 56 JniDisplayHandler::JniDisplayHandler(ChromotingJniRuntime* runtime) |
57 ChromotingJniRuntime* runtime, | |
58 base::android::ScopedJavaGlobalRef<jobject> java_display) | |
59 : runtime_(runtime), | 57 : runtime_(runtime), |
60 java_display_(java_display), | 58 weak_factory_(this) { |
61 weak_factory_(this) {} | 59 JNIEnv* env = base::android::AttachCurrentThread(); |
60 java_display_.Reset(Java_Display_createJavaDisplayObject( | |
61 env, reinterpret_cast<intptr_t>(this))); | |
62 } | |
62 | 63 |
63 JniDisplayHandler::~JniDisplayHandler() { | 64 JniDisplayHandler::~JniDisplayHandler() { |
64 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 65 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
66 Java_Display_invalidate(base::android::AttachCurrentThread(), | |
67 java_display_.obj()); | |
68 } | |
69 | |
70 base::android::ScopedJavaLocalRef<jobject> JniDisplayHandler::GetJavaDisplay() { | |
71 return base::android::ScopedJavaLocalRef<jobject>(java_display_); | |
Lambros
2016/06/27 23:51:44
I'm not sure if this is correct? ScopedJavaLocalRe
Sergey Ulanov
2016/06/27 23:59:18
It's a java object, so it cannot be owned. This li
Yuwei
2016/06/28 00:03:26
It will eventually call SetNewLocalRef(env, other.
| |
65 } | 72 } |
66 | 73 |
67 void JniDisplayHandler::UpdateCursorShape( | 74 void JniDisplayHandler::UpdateCursorShape( |
68 const protocol::CursorShapeInfo& cursor_shape) { | 75 const protocol::CursorShapeInfo& cursor_shape) { |
69 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 76 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
70 | 77 |
71 // const_cast<> is safe as long as the Java updateCursorShape() method copies | 78 // const_cast<> is safe as long as the Java updateCursorShape() method copies |
72 // the data out of the buffer without mutating it, and doesn't keep any | 79 // the data out of the buffer without mutating it, and doesn't keep any |
73 // reference to the buffer afterwards. Unfortunately, there seems to be no way | 80 // reference to the buffer afterwards. Unfortunately, there seems to be no way |
74 // to create a read-only ByteBuffer from a pointer-to-const. | 81 // to create a read-only ByteBuffer from a pointer-to-const. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 124 |
118 JNIEnv* env = base::android::AttachCurrentThread(); | 125 JNIEnv* env = base::android::AttachCurrentThread(); |
119 Java_Display_redrawGraphicsInternal(env, java_display_.obj()); | 126 Java_Display_redrawGraphicsInternal(env, java_display_.obj()); |
120 } | 127 } |
121 | 128 |
122 // static | 129 // static |
123 bool JniDisplayHandler::RegisterJni(JNIEnv* env) { | 130 bool JniDisplayHandler::RegisterJni(JNIEnv* env) { |
124 return RegisterNativesImpl(env); | 131 return RegisterNativesImpl(env); |
125 } | 132 } |
126 | 133 |
127 void JniDisplayHandler::Destroy( | |
128 JNIEnv* env, | |
129 const base::android::JavaParamRef<jobject>& caller) { | |
130 if (runtime_->display_task_runner()->BelongsToCurrentThread()) { | |
131 delete this; | |
132 } else { | |
133 runtime_->display_task_runner()->DeleteSoon(FROM_HERE, this); | |
134 } | |
135 } | |
136 | |
137 void JniDisplayHandler::ScheduleRedraw( | 134 void JniDisplayHandler::ScheduleRedraw( |
138 JNIEnv* env, | 135 JNIEnv* env, |
139 const base::android::JavaParamRef<jobject>& caller) { | 136 const base::android::JavaParamRef<jobject>& caller) { |
140 runtime_->display_task_runner()->PostTask( | 137 runtime_->display_task_runner()->PostTask( |
141 FROM_HERE, base::Bind(&JniDisplayHandler::RedrawCanvas, | 138 FROM_HERE, base::Bind(&JniDisplayHandler::RedrawCanvas, |
142 weak_factory_.GetWeakPtr())); | 139 weak_factory_.GetWeakPtr())); |
143 } | 140 } |
144 | 141 |
145 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& caller) { | |
146 return reinterpret_cast<intptr_t>(new JniDisplayHandler( | |
147 ChromotingJniRuntime::GetInstance(), | |
148 base::android::ScopedJavaGlobalRef<jobject>(env, caller))); | |
149 } | |
150 | |
151 } // namespace remoting | 142 } // namespace remoting |
OLD | NEW |