shared_gl_fence_egl.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2020 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 UI_GL_SHARED_GL_FENCE_EGL_H_
  5. #define UI_GL_SHARED_GL_FENCE_EGL_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "base/synchronization/lock.h"
  9. #include "base/thread_annotations.h"
  10. #include "ui/gl/gl_export.h"
  11. namespace gl {
  12. class GLFenceEGL;
  13. class GLApi;
  14. // This class is an optimized way to share an egl fence among multiple
  15. // consumers. Once the shared |egl_fence_| has been waited upon by any of the
  16. // consumer, all the future waits to the same fence becomes no-op since we don't
  17. // need to wait again on the same fence any more. This saves un-neccesary gl
  18. // calls issued to do wait by each consumer.
  19. // This object should only be shared among consumers of the same GL context
  20. // which is true for Webview case.
  21. // TODO(vikassoni): Add logic to handle consumers from different GL context.
  22. class GL_EXPORT SharedGLFenceEGL
  23. : public base::RefCountedThreadSafe<SharedGLFenceEGL> {
  24. public:
  25. SharedGLFenceEGL();
  26. SharedGLFenceEGL(const SharedGLFenceEGL&) = delete;
  27. SharedGLFenceEGL& operator=(const SharedGLFenceEGL&) = delete;
  28. // Issues a ServerWait on the |egl_fence_|.
  29. void ServerWait();
  30. protected:
  31. virtual ~SharedGLFenceEGL();
  32. private:
  33. friend class base::RefCountedThreadSafe<SharedGLFenceEGL>;
  34. std::unique_ptr<GLFenceEGL> egl_fence_ GUARDED_BY(lock_);
  35. // A lock that guard against multiple threads trying to access |egl_fence_|.
  36. base::Lock lock_;
  37. // GLApi on which all the consumers for this object should be on.
  38. raw_ptr<gl::GLApi> gl_api_ = nullptr;
  39. };
  40. } // namespace gl
  41. #endif // UI_GL_SHARED_GL_FENCE_EGL_H_