| 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 19 matching lines...) Expand all Loading... |
| 30 : runtime_(runtime), | 30 : runtime_(runtime), |
| 31 weak_factory_(this) { | 31 weak_factory_(this) { |
| 32 weak_ptr_ = weak_factory_.GetWeakPtr(); | 32 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); | 33 JNIEnv* env = base::android::AttachCurrentThread(); |
| 34 java_display_.Reset(Java_Display_createJavaDisplayObject( | 34 java_display_.Reset(Java_Display_createJavaDisplayObject( |
| 35 env, reinterpret_cast<intptr_t>(this))); | 35 env, reinterpret_cast<intptr_t>(this))); |
| 36 } | 36 } |
| 37 | 37 |
| 38 JniDisplayHandler::~JniDisplayHandler() { | 38 JniDisplayHandler::~JniDisplayHandler() { |
| 39 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 39 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 40 Java_Display_invalidate(base::android::AttachCurrentThread(), | 40 Java_Display_invalidate(base::android::AttachCurrentThread(), java_display_); |
| 41 java_display_.obj()); | |
| 42 } | 41 } |
| 43 | 42 |
| 44 void JniDisplayHandler::InitializeClient( | 43 void JniDisplayHandler::InitializeClient( |
| 45 const base::android::JavaRef<jobject>& java_client) { | 44 const base::android::JavaRef<jobject>& java_client) { |
| 46 return Java_Display_initializeClient(base::android::AttachCurrentThread(), | 45 return Java_Display_initializeClient(base::android::AttachCurrentThread(), |
| 47 java_display_.obj(), java_client.obj()); | 46 java_display_, java_client); |
| 48 } | 47 } |
| 49 | 48 |
| 50 std::unique_ptr<protocol::CursorShapeStub> | 49 std::unique_ptr<protocol::CursorShapeStub> |
| 51 JniDisplayHandler::CreateCursorShapeStub() { | 50 JniDisplayHandler::CreateCursorShapeStub() { |
| 52 return base::WrapUnique(new CursorShapeStubProxy( | 51 return base::WrapUnique(new CursorShapeStubProxy( |
| 53 weak_ptr_, runtime_->display_task_runner())); | 52 weak_ptr_, runtime_->display_task_runner())); |
| 54 } | 53 } |
| 55 | 54 |
| 56 std::unique_ptr<protocol::VideoRenderer> | 55 std::unique_ptr<protocol::VideoRenderer> |
| 57 JniDisplayHandler::CreateVideoRenderer() { | 56 JniDisplayHandler::CreateVideoRenderer() { |
| 58 return base::WrapUnique( | 57 return base::WrapUnique( |
| 59 new JniVideoRenderer(runtime_, weak_ptr_)); | 58 new JniVideoRenderer(runtime_, weak_ptr_)); |
| 60 } | 59 } |
| 61 | 60 |
| 62 // static | 61 // static |
| 63 base::android::ScopedJavaLocalRef<jobject> JniDisplayHandler::NewBitmap( | 62 base::android::ScopedJavaLocalRef<jobject> JniDisplayHandler::NewBitmap( |
| 64 int width, | 63 int width, |
| 65 int height) { | 64 int height) { |
| 66 JNIEnv* env = base::android::AttachCurrentThread(); | 65 JNIEnv* env = base::android::AttachCurrentThread(); |
| 67 return Java_Display_newBitmap(env, width, height); | 66 return Java_Display_newBitmap(env, width, height); |
| 68 } | 67 } |
| 69 | 68 |
| 70 void JniDisplayHandler::UpdateFrameBitmap( | 69 void JniDisplayHandler::UpdateFrameBitmap( |
| 71 base::android::ScopedJavaGlobalRef<jobject> bitmap) { | 70 base::android::ScopedJavaGlobalRef<jobject> bitmap) { |
| 72 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 71 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 73 | 72 |
| 74 JNIEnv* env = base::android::AttachCurrentThread(); | 73 JNIEnv* env = base::android::AttachCurrentThread(); |
| 75 Java_Display_setVideoFrame(env, java_display_.obj(), bitmap.obj()); | 74 Java_Display_setVideoFrame(env, java_display_, bitmap); |
| 76 } | 75 } |
| 77 | 76 |
| 78 void JniDisplayHandler::RedrawCanvas() { | 77 void JniDisplayHandler::RedrawCanvas() { |
| 79 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 78 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 80 | 79 |
| 81 JNIEnv* env = base::android::AttachCurrentThread(); | 80 JNIEnv* env = base::android::AttachCurrentThread(); |
| 82 Java_Display_redrawGraphicsInternal(env, java_display_.obj()); | 81 Java_Display_redrawGraphicsInternal(env, java_display_); |
| 83 } | 82 } |
| 84 | 83 |
| 85 // static | 84 // static |
| 86 bool JniDisplayHandler::RegisterJni(JNIEnv* env) { | 85 bool JniDisplayHandler::RegisterJni(JNIEnv* env) { |
| 87 return RegisterNativesImpl(env); | 86 return RegisterNativesImpl(env); |
| 88 } | 87 } |
| 89 | 88 |
| 90 void JniDisplayHandler::ScheduleRedraw( | 89 void JniDisplayHandler::ScheduleRedraw( |
| 91 JNIEnv* env, | 90 JNIEnv* env, |
| 92 const base::android::JavaParamRef<jobject>& caller) { | 91 const base::android::JavaParamRef<jobject>& caller) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 104 // to create a read-only ByteBuffer from a pointer-to-const. | 103 // to create a read-only ByteBuffer from a pointer-to-const. |
| 105 char* data = | 104 char* data = |
| 106 base::string_as_array(const_cast<std::string*>(&cursor_shape.data())); | 105 base::string_as_array(const_cast<std::string*>(&cursor_shape.data())); |
| 107 int cursor_total_bytes = | 106 int cursor_total_bytes = |
| 108 cursor_shape.width() * cursor_shape.height() * kBytesPerPixel; | 107 cursor_shape.width() * cursor_shape.height() * kBytesPerPixel; |
| 109 | 108 |
| 110 JNIEnv* env = base::android::AttachCurrentThread(); | 109 JNIEnv* env = base::android::AttachCurrentThread(); |
| 111 base::android::ScopedJavaLocalRef<jobject> buffer( | 110 base::android::ScopedJavaLocalRef<jobject> buffer( |
| 112 env, env->NewDirectByteBuffer(data, cursor_total_bytes)); | 111 env, env->NewDirectByteBuffer(data, cursor_total_bytes)); |
| 113 Java_Display_updateCursorShape( | 112 Java_Display_updateCursorShape( |
| 114 env, java_display_.obj(), cursor_shape.width(), cursor_shape.height(), | 113 env, java_display_, cursor_shape.width(), cursor_shape.height(), |
| 115 cursor_shape.hotspot_x(), cursor_shape.hotspot_y(), buffer.obj()); | 114 cursor_shape.hotspot_x(), cursor_shape.hotspot_y(), buffer); |
| 116 } | 115 } |
| 117 | 116 |
| 118 } // namespace remoting | 117 } // namespace remoting |
| OLD | NEW |