egl_thread_context.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_EGL_THREAD_CONTEXT_H_
  5. #define REMOTING_CLIENT_JNI_EGL_THREAD_CONTEXT_H_
  6. #include <EGL/egl.h>
  7. #include "base/threading/thread_checker.h"
  8. namespace remoting {
  9. // Establishes an EGL-OpenGL|ES 2 (if 3 is not supported) or 3 (backward
  10. // compatible with 2) context on current thread. Must be constructed, used, and
  11. // deleted on single thread (i.e. the display thread). Each thread can have no
  12. // more than one EglThreadContext.
  13. class EglThreadContext {
  14. public:
  15. enum class GlVersion {
  16. UNKNOWN = 0,
  17. ES_2 = 2,
  18. ES_3 = 3
  19. };
  20. EglThreadContext();
  21. EglThreadContext(const EglThreadContext&) = delete;
  22. EglThreadContext& operator=(const EglThreadContext&) = delete;
  23. ~EglThreadContext();
  24. // Creates a surface on the given window and binds the context to the surface.
  25. // Unbinds |window| last bound if |window| is NULL.
  26. // EGLNativeWindowType is platform specific. E.g. ANativeWindow* on Android.
  27. void BindToWindow(EGLNativeWindowType window);
  28. // Returns true if the context is bound to a window (i.e. current surface is
  29. // not NULL).
  30. bool IsWindowBound() const;
  31. // Posts EGL surface buffer to the window being bound.
  32. // Returns true if the buffer is successfully swapped.
  33. bool SwapBuffers();
  34. // Returns the current OpenGL ES client version of the EGL context.
  35. GlVersion client_version() const {
  36. return client_version_;
  37. }
  38. private:
  39. // Creates an EGLContext with given |renderable_type| and |client_version|.
  40. // |renderable_type| and |client_version| must match with each other.
  41. // E.g. renderable_type = EGL_OPENGL_ES3_BIT,
  42. // client_version = CLIENT_VERSION_ES_3.
  43. bool CreateContextWithClientVersion(int renderable_type,
  44. GlVersion client_version);
  45. EGLDisplay display_ = EGL_NO_DISPLAY;
  46. EGLConfig config_ = nullptr;
  47. EGLSurface surface_ = EGL_NO_SURFACE;
  48. EGLContext context_ = EGL_NO_CONTEXT;
  49. GlVersion client_version_ = GlVersion::UNKNOWN;
  50. base::ThreadChecker thread_checker_;
  51. };
  52. } // namespace remoting
  53. #endif // REMOTING_CLIENT_JNI_EGL_THREAD_CONTEXT_H_