jni_gl_display_handler.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_
  5. #define REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_
  6. #include <EGL/egl.h>
  7. #include <jni.h>
  8. #include "base/android/scoped_java_ref.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "remoting/base/queued_task_poster.h"
  12. #include "remoting/client/display/gl_renderer.h"
  13. #include "remoting/client/display/gl_renderer_delegate.h"
  14. #include "remoting/protocol/cursor_shape_stub.h"
  15. namespace remoting {
  16. namespace protocol {
  17. class VideoRenderer;
  18. } // namespace protocol
  19. class ChromotingClientRuntime;
  20. // Handles OpenGL display operations. Draws desktop and cursor on the OpenGL
  21. // surface. The handler should be used and destroyed on the UI thread. It also
  22. // has a core that works on the display thread.
  23. class JniGlDisplayHandler {
  24. public:
  25. JniGlDisplayHandler(const base::android::JavaRef<jobject>& java_client);
  26. JniGlDisplayHandler(const JniGlDisplayHandler&) = delete;
  27. JniGlDisplayHandler& operator=(const JniGlDisplayHandler&) = delete;
  28. ~JniGlDisplayHandler();
  29. std::unique_ptr<protocol::CursorShapeStub> CreateCursorShapeStub();
  30. std::unique_ptr<protocol::VideoRenderer> CreateVideoRenderer();
  31. void OnSurfaceCreated(
  32. JNIEnv* env,
  33. const base::android::JavaParamRef<jobject>& caller,
  34. const base::android::JavaParamRef<jobject>& surface);
  35. void OnSurfaceChanged(JNIEnv* env,
  36. const base::android::JavaParamRef<jobject>& caller,
  37. int width,
  38. int height);
  39. void OnSurfaceDestroyed(
  40. JNIEnv* env,
  41. const base::android::JavaParamRef<jobject>& caller);
  42. void OnPixelTransformationChanged(
  43. JNIEnv* env,
  44. const base::android::JavaParamRef<jobject>& caller,
  45. const base::android::JavaParamRef<jfloatArray>& matrix
  46. );
  47. void OnCursorPixelPositionChanged(
  48. JNIEnv* env,
  49. const base::android::JavaParamRef<jobject>& caller,
  50. float x,
  51. float y);
  52. void OnCursorVisibilityChanged(
  53. JNIEnv* env,
  54. const base::android::JavaParamRef<jobject>& caller,
  55. bool visible);
  56. void OnCursorInputFeedback(
  57. JNIEnv* env,
  58. const base::android::JavaParamRef<jobject>& caller,
  59. float x,
  60. float y,
  61. float diameter);
  62. private:
  63. class Core;
  64. // Callbacks from the core.
  65. void OnRenderDone();
  66. void OnCanvasSizeChanged(int width, int height);
  67. raw_ptr<ChromotingClientRuntime> runtime_;
  68. QueuedTaskPoster ui_task_poster_;
  69. std::unique_ptr<Core> core_;
  70. base::android::ScopedJavaGlobalRef<jobject> java_display_;
  71. // Used on UI thread.
  72. base::WeakPtrFactory<JniGlDisplayHandler> weak_factory_{this};
  73. };
  74. } // namespace remoting
  75. #endif // REMOTING_CLIENT_JNI_JNI_GL_DISPLAY_HANDLER_H_