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 #ifndef REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_ | 5 #ifndef REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_ |
6 #define REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_ | 6 #define REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_ |
7 | 7 |
| 8 #include <EGL/egl.h> |
8 #include <jni.h> | 9 #include <jni.h> |
9 | 10 |
10 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "remoting/client/gl_renderer.h" |
| 15 #include "remoting/client/gl_renderer_delegate.h" |
13 #include "remoting/client/jni/display_updater_factory.h" | 16 #include "remoting/client/jni/display_updater_factory.h" |
| 17 #include "remoting/protocol/cursor_shape_stub.h" |
14 | 18 |
15 namespace remoting { | 19 namespace remoting { |
16 | 20 |
17 class ChromotingJniRuntime; | 21 class ChromotingJniRuntime; |
| 22 class DualBufferFrameConsumer; |
| 23 class EglThreadContext; |
18 | 24 |
19 // Handles OpenGL display operations. Draws desktop and cursor on the OpenGL | 25 // Handles OpenGL display operations. Draws desktop and cursor on the OpenGL |
20 // surface. | 26 // surface. |
21 // JNI functions should all be called on the UI thread. The display handler | 27 // JNI functions should all be called on the UI thread. The display handler |
22 // itself should be deleted on the display thread. | 28 // itself should be deleted on the display thread. |
23 // Please see GlDisplay.java for documentations. | 29 // Please see GlDisplay.java for documentations. |
24 class JniGlDisplayHandler : public DisplayUpdaterFactory { | 30 class JniGlDisplayHandler : public DisplayUpdaterFactory, |
| 31 public protocol::CursorShapeStub, |
| 32 public GlRendererDelegate { |
25 public: | 33 public: |
26 JniGlDisplayHandler(ChromotingJniRuntime* runtime); | 34 JniGlDisplayHandler(ChromotingJniRuntime* runtime); |
27 ~JniGlDisplayHandler() override; | 35 ~JniGlDisplayHandler() override; |
28 | 36 |
29 // Sets the DesktopViewFactory for the Java client. | 37 // Sets the DesktopViewFactory for the Java client. |
30 void InitializeClient( | 38 void InitializeClient( |
31 const base::android::JavaRef<jobject>& java_client); | 39 const base::android::JavaRef<jobject>& java_client); |
| 40 |
| 41 // CursorShapeStub override. |
| 42 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; |
| 43 |
32 // DisplayUpdaterFactory overrides. | 44 // DisplayUpdaterFactory overrides. |
33 std::unique_ptr<protocol::CursorShapeStub> CreateCursorShapeStub() override; | 45 std::unique_ptr<protocol::CursorShapeStub> CreateCursorShapeStub() override; |
34 std::unique_ptr<protocol::VideoRenderer> CreateVideoRenderer() override; | 46 std::unique_ptr<protocol::VideoRenderer> CreateVideoRenderer() override; |
35 | 47 |
| 48 // GlrendererDelegate overrides. |
| 49 bool CanRenderFrame() override; |
| 50 void OnFrameRendered() override; |
| 51 void OnSizeChanged(int width, int height) override; |
| 52 |
36 static bool RegisterJni(JNIEnv* env); | 53 static bool RegisterJni(JNIEnv* env); |
37 | 54 |
38 void OnSurfaceCreated( | 55 void OnSurfaceCreated( |
39 JNIEnv* env, | 56 JNIEnv* env, |
40 const base::android::JavaParamRef<jobject>& caller, | 57 const base::android::JavaParamRef<jobject>& caller, |
41 const base::android::JavaParamRef<jobject>& surface); | 58 const base::android::JavaParamRef<jobject>& surface); |
42 | 59 |
43 void OnSurfaceChanged(JNIEnv* env, | 60 void OnSurfaceChanged(JNIEnv* env, |
44 const base::android::JavaParamRef<jobject>& caller, | 61 const base::android::JavaParamRef<jobject>& caller, |
45 int width, | 62 int width, |
46 int height); | 63 int height); |
47 | 64 |
48 void OnSurfaceDestroyed( | 65 void OnSurfaceDestroyed( |
49 JNIEnv* env, | 66 JNIEnv* env, |
50 const base::android::JavaParamRef<jobject>& caller); | 67 const base::android::JavaParamRef<jobject>& caller); |
51 | 68 |
52 void OnPixelTransformationChanged( | 69 void OnPixelTransformationChanged( |
53 JNIEnv* env, | 70 JNIEnv* env, |
54 const base::android::JavaParamRef<jobject>& caller, | 71 const base::android::JavaParamRef<jobject>& caller, |
55 const base::android::JavaParamRef<jfloatArray>& matrix | 72 const base::android::JavaParamRef<jfloatArray>& matrix |
56 ); | 73 ); |
57 | 74 |
58 void OnCursorPixelPositionChanged( | 75 void OnCursorPixelPositionChanged( |
59 JNIEnv* env, | 76 JNIEnv* env, |
60 const base::android::JavaParamRef<jobject>& caller, | 77 const base::android::JavaParamRef<jobject>& caller, |
61 int x, | 78 int x, |
62 int y); | 79 int y, |
| 80 bool followed_by_viewport_move); |
63 | 81 |
64 void OnCursorVisibilityChanged( | 82 void OnCursorVisibilityChanged( |
65 JNIEnv* env, | 83 JNIEnv* env, |
66 const base::android::JavaParamRef<jobject>& caller, | 84 const base::android::JavaParamRef<jobject>& caller, |
67 bool visible); | 85 bool visible); |
68 | 86 |
69 void OnCursorInputFeedback( | 87 void OnCursorInputFeedback( |
70 JNIEnv* env, | 88 JNIEnv* env, |
71 const base::android::JavaParamRef<jobject>& caller, | 89 const base::android::JavaParamRef<jobject>& caller, |
72 int x, | 90 int x, |
73 int y, | 91 int y, |
74 float diameter); | 92 float diameter); |
75 | 93 |
76 void SetRenderEventEnabled(JNIEnv* env, | 94 void SetRenderEventEnabled(JNIEnv* env, |
77 const base::android::JavaParamRef<jobject>& caller, | 95 const base::android::JavaParamRef<jobject>& caller, |
78 jboolean enabled); | 96 jboolean enabled); |
79 | 97 |
80 private: | 98 private: |
81 static void NotifyRenderEventOnUiThread( | 99 void SetRenderEventEnabledOnDisplayThread(bool enabled); |
82 base::android::ScopedJavaGlobalRef<jobject> java_client); | 100 |
| 101 static void NotifyRenderDoneOnUiThread( |
| 102 base::android::ScopedJavaGlobalRef<jobject> java_display); |
| 103 |
| 104 void SurfaceCreatedOnDisplayThread( |
| 105 base::android::ScopedJavaGlobalRef<jobject> surface); |
| 106 |
| 107 void SurfaceDestroyedOnDisplayThread(); |
| 108 |
| 109 void ChangePixelTransformationOnDisplayThread( |
| 110 base::android::ScopedJavaGlobalRef<jfloatArray> jmatrix); |
| 111 |
| 112 void ChangeCursorPositionOnDisplayThread(int x, |
| 113 int y, |
| 114 bool followed_by_viewport_move); |
83 | 115 |
84 static void ChangeCanvasSizeOnUiThread( | 116 static void ChangeCanvasSizeOnUiThread( |
85 base::android::ScopedJavaGlobalRef<jobject> java_client, | 117 base::android::ScopedJavaGlobalRef<jobject> java_display, |
86 int width, | 118 int width, |
87 int height); | 119 int height); |
88 | 120 |
89 ChromotingJniRuntime* runtime_; | 121 ChromotingJniRuntime* runtime_; |
90 | 122 |
91 base::android::ScopedJavaGlobalRef<jobject> java_display_; | 123 base::android::ScopedJavaGlobalRef<jobject> java_display_; |
92 | 124 |
| 125 std::unique_ptr<EglThreadContext> egl_context_; |
| 126 |
| 127 base::WeakPtr<DualBufferFrameConsumer> frame_consumer_; |
| 128 |
| 129 bool render_event_enabled_ = false; |
| 130 bool rendering_blocked_ = false; |
| 131 |
| 132 // |renderer_| must be deleted earlier than |egl_context_|. |
| 133 GlRenderer renderer_; |
| 134 |
| 135 // Used on display thread. |
| 136 base::WeakPtr<JniGlDisplayHandler> weak_ptr_; |
| 137 base::WeakPtrFactory<JniGlDisplayHandler> weak_factory_; |
93 DISALLOW_COPY_AND_ASSIGN(JniGlDisplayHandler); | 138 DISALLOW_COPY_AND_ASSIGN(JniGlDisplayHandler); |
94 }; | 139 }; |
95 | 140 |
96 } // namespace remoting | 141 } // namespace remoting |
97 | 142 |
98 #endif // REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_ | 143 #endif // REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_ |
OLD | NEW |