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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "jni/Display_jni.h" | 12 #include "jni/Display_jni.h" |
| 13 #include "remoting/client/callback_cursor_shape_stub.h" |
13 #include "remoting/client/jni/chromoting_jni_runtime.h" | 14 #include "remoting/client/jni/chromoting_jni_runtime.h" |
14 #include "remoting/client/jni/jni_client.h" | 15 #include "remoting/client/jni/jni_client.h" |
15 #include "remoting/client/jni/jni_video_renderer.h" | 16 #include "remoting/client/jni/jni_video_renderer.h" |
16 | 17 |
17 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const int kBytesPerPixel = 4; | 22 const int kBytesPerPixel = 4; |
22 | 23 |
23 } | 24 } |
24 | 25 |
25 namespace remoting { | 26 namespace remoting { |
26 | 27 |
27 // CursorShapeStub with a lifetime separated from JniDisplayHandler. | |
28 class DisplayCursorShapeStub : public protocol::CursorShapeStub { | |
29 public: | |
30 DisplayCursorShapeStub( | |
31 base::WeakPtr<JniDisplayHandler> display, | |
32 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
33 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; | |
34 private: | |
35 base::WeakPtr<JniDisplayHandler> display_handler_; | |
36 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
37 }; | |
38 | |
39 DisplayCursorShapeStub::DisplayCursorShapeStub( | |
40 base::WeakPtr<JniDisplayHandler> display, | |
41 scoped_refptr<base::SingleThreadTaskRunner> task_runner) : | |
42 display_handler_(display), | |
43 task_runner_(task_runner) { | |
44 } | |
45 | |
46 void DisplayCursorShapeStub::SetCursorShape( | |
47 const protocol::CursorShapeInfo& cursor_shape) { | |
48 task_runner_->PostTask(FROM_HERE, | |
49 base::Bind(&JniDisplayHandler::UpdateCursorShape, | |
50 display_handler_, | |
51 cursor_shape)); | |
52 } | |
53 | |
54 // JniDisplayHandler definitions. | 28 // JniDisplayHandler definitions. |
55 JniDisplayHandler::JniDisplayHandler(ChromotingJniRuntime* runtime) | 29 JniDisplayHandler::JniDisplayHandler(ChromotingJniRuntime* runtime) |
56 : runtime_(runtime), | 30 : runtime_(runtime), |
57 weak_factory_(this) { | 31 weak_factory_(this) { |
58 weak_ptr_ = weak_factory_.GetWeakPtr(); | 32 weak_ptr_ = weak_factory_.GetWeakPtr(); |
59 JNIEnv* env = base::android::AttachCurrentThread(); | 33 JNIEnv* env = base::android::AttachCurrentThread(); |
60 java_display_.Reset(Java_Display_createJavaDisplayObject( | 34 java_display_.Reset(Java_Display_createJavaDisplayObject( |
61 env, reinterpret_cast<intptr_t>(this))); | 35 env, reinterpret_cast<intptr_t>(this))); |
62 } | 36 } |
63 | 37 |
(...skipping 24 matching lines...) Expand all Loading... |
88 JNIEnv* env = base::android::AttachCurrentThread(); | 62 JNIEnv* env = base::android::AttachCurrentThread(); |
89 base::android::ScopedJavaLocalRef<jobject> buffer( | 63 base::android::ScopedJavaLocalRef<jobject> buffer( |
90 env, env->NewDirectByteBuffer(data, cursor_total_bytes)); | 64 env, env->NewDirectByteBuffer(data, cursor_total_bytes)); |
91 Java_Display_updateCursorShape( | 65 Java_Display_updateCursorShape( |
92 env, java_display_.obj(), cursor_shape.width(), cursor_shape.height(), | 66 env, java_display_.obj(), cursor_shape.width(), cursor_shape.height(), |
93 cursor_shape.hotspot_x(), cursor_shape.hotspot_y(), buffer.obj()); | 67 cursor_shape.hotspot_x(), cursor_shape.hotspot_y(), buffer.obj()); |
94 } | 68 } |
95 | 69 |
96 std::unique_ptr<protocol::CursorShapeStub> | 70 std::unique_ptr<protocol::CursorShapeStub> |
97 JniDisplayHandler::CreateCursorShapeStub() { | 71 JniDisplayHandler::CreateCursorShapeStub() { |
98 return base::WrapUnique( | 72 return base::WrapUnique(new CallbackCursorShapeStub( |
99 new DisplayCursorShapeStub(weak_ptr_, runtime_->display_task_runner())); | 73 base::Bind(&JniDisplayHandler::UpdateCursorShape, weak_ptr_), |
| 74 runtime_->display_task_runner())); |
100 } | 75 } |
101 | 76 |
102 std::unique_ptr<protocol::VideoRenderer> | 77 std::unique_ptr<protocol::VideoRenderer> |
103 JniDisplayHandler::CreateVideoRenderer() { | 78 JniDisplayHandler::CreateVideoRenderer() { |
104 return base::WrapUnique( | 79 return base::WrapUnique( |
105 new JniVideoRenderer(runtime_, weak_ptr_)); | 80 new JniVideoRenderer(runtime_, weak_ptr_)); |
106 } | 81 } |
107 | 82 |
108 // static | 83 // static |
109 base::android::ScopedJavaLocalRef<jobject> JniDisplayHandler::NewBitmap( | 84 base::android::ScopedJavaLocalRef<jobject> JniDisplayHandler::NewBitmap( |
(...skipping 24 matching lines...) Expand all Loading... |
134 } | 109 } |
135 | 110 |
136 void JniDisplayHandler::ScheduleRedraw( | 111 void JniDisplayHandler::ScheduleRedraw( |
137 JNIEnv* env, | 112 JNIEnv* env, |
138 const base::android::JavaParamRef<jobject>& caller) { | 113 const base::android::JavaParamRef<jobject>& caller) { |
139 runtime_->display_task_runner()->PostTask( | 114 runtime_->display_task_runner()->PostTask( |
140 FROM_HERE, base::Bind(&JniDisplayHandler::RedrawCanvas, weak_ptr_)); | 115 FROM_HERE, base::Bind(&JniDisplayHandler::RedrawCanvas, weak_ptr_)); |
141 } | 116 } |
142 | 117 |
143 } // namespace remoting | 118 } // namespace remoting |
OLD | NEW |