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

Unified Diff: remoting/client/jni/jni_display_handler.cc

Issue 2187723002: [Remoting Android] Refactor CursorShapeStubProxy from JniDisplayHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/client/jni/jni_display_handler.h ('k') | remoting/remoting_srcs.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/client/jni/jni_display_handler.cc
diff --git a/remoting/client/jni/jni_display_handler.cc b/remoting/client/jni/jni_display_handler.cc
index e139e7bc3ab7578af1345d9402a27e9e3a595c42..cd51e52a2d415883374cfc676f06e23e893d4c13 100644
--- a/remoting/client/jni/jni_display_handler.cc
+++ b/remoting/client/jni/jni_display_handler.cc
@@ -10,6 +10,7 @@
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "jni/Display_jni.h"
+#include "remoting/client/cursor_shape_stub_proxy.h"
#include "remoting/client/jni/chromoting_jni_runtime.h"
#include "remoting/client/jni/jni_client.h"
#include "remoting/client/jni/jni_video_renderer.h"
@@ -24,33 +25,6 @@ const int kBytesPerPixel = 4;
namespace remoting {
-// CursorShapeStub with a lifetime separated from JniDisplayHandler.
-class DisplayCursorShapeStub : public protocol::CursorShapeStub {
- public:
- DisplayCursorShapeStub(
- base::WeakPtr<JniDisplayHandler> display,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
- void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override;
- private:
- base::WeakPtr<JniDisplayHandler> display_handler_;
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
-};
-
-DisplayCursorShapeStub::DisplayCursorShapeStub(
- base::WeakPtr<JniDisplayHandler> display,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner) :
- display_handler_(display),
- task_runner_(task_runner) {
-}
-
-void DisplayCursorShapeStub::SetCursorShape(
- const protocol::CursorShapeInfo& cursor_shape) {
- task_runner_->PostTask(FROM_HERE,
- base::Bind(&JniDisplayHandler::UpdateCursorShape,
- display_handler_,
- cursor_shape));
-}
-
// JniDisplayHandler definitions.
JniDisplayHandler::JniDisplayHandler(ChromotingJniRuntime* runtime)
: runtime_(runtime),
@@ -73,30 +47,10 @@ void JniDisplayHandler::InitializeClient(
java_display_.obj(), java_client.obj());
}
-void JniDisplayHandler::UpdateCursorShape(
- const protocol::CursorShapeInfo& cursor_shape) {
- DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
-
- // const_cast<> is safe as long as the Java updateCursorShape() method copies
- // the data out of the buffer without mutating it, and doesn't keep any
- // reference to the buffer afterwards. Unfortunately, there seems to be no way
- // to create a read-only ByteBuffer from a pointer-to-const.
- char* data = string_as_array(const_cast<std::string*>(&cursor_shape.data()));
- int cursor_total_bytes =
- cursor_shape.width() * cursor_shape.height() * kBytesPerPixel;
-
- JNIEnv* env = base::android::AttachCurrentThread();
- base::android::ScopedJavaLocalRef<jobject> buffer(
- env, env->NewDirectByteBuffer(data, cursor_total_bytes));
- Java_Display_updateCursorShape(
- env, java_display_.obj(), cursor_shape.width(), cursor_shape.height(),
- cursor_shape.hotspot_x(), cursor_shape.hotspot_y(), buffer.obj());
-}
-
std::unique_ptr<protocol::CursorShapeStub>
JniDisplayHandler::CreateCursorShapeStub() {
- return base::WrapUnique(
- new DisplayCursorShapeStub(weak_ptr_, runtime_->display_task_runner()));
+ return base::WrapUnique(new CursorShapeStubProxy(
+ weak_ptr_, runtime_->display_task_runner()));
}
std::unique_ptr<protocol::VideoRenderer>
@@ -140,4 +94,24 @@ void JniDisplayHandler::ScheduleRedraw(
FROM_HERE, base::Bind(&JniDisplayHandler::RedrawCanvas, weak_ptr_));
}
+void JniDisplayHandler::SetCursorShape(
+ const protocol::CursorShapeInfo& cursor_shape) {
+ DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
+
+ // const_cast<> is safe as long as the Java updateCursorShape() method copies
+ // the data out of the buffer without mutating it, and doesn't keep any
+ // reference to the buffer afterwards. Unfortunately, there seems to be no way
+ // to create a read-only ByteBuffer from a pointer-to-const.
+ char* data = string_as_array(const_cast<std::string*>(&cursor_shape.data()));
+ int cursor_total_bytes =
+ cursor_shape.width() * cursor_shape.height() * kBytesPerPixel;
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ base::android::ScopedJavaLocalRef<jobject> buffer(
+ env, env->NewDirectByteBuffer(data, cursor_total_bytes));
+ Java_Display_updateCursorShape(
+ env, java_display_.obj(), cursor_shape.width(), cursor_shape.height(),
+ cursor_shape.hotspot_x(), cursor_shape.hotspot_y(), buffer.obj());
+}
+
} // namespace remoting
« no previous file with comments | « remoting/client/jni/jni_display_handler.h ('k') | remoting/remoting_srcs.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698