shared_gl_fence_egl.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include "ui/gl/shared_gl_fence_egl.h"
  5. #include "base/logging.h"
  6. #include "ui/gl/gl_bindings.h"
  7. #include "ui/gl/gl_fence_egl.h"
  8. namespace gl {
  9. SharedGLFenceEGL::SharedGLFenceEGL() : egl_fence_(GLFenceEGL::Create()) {
  10. // GLFenceEGL::Create() is not supposed to fail.
  11. DCHECK(egl_fence_);
  12. }
  13. SharedGLFenceEGL::~SharedGLFenceEGL() = default;
  14. void SharedGLFenceEGL::ServerWait() {
  15. base::AutoLock lock(lock_);
  16. #if DCHECK_IS_ON()
  17. if (!gl_api_) {
  18. gl_api_ = gl::g_current_gl_context;
  19. } else if (gl_api_ != gl::g_current_gl_context) {
  20. LOG(FATAL) << "This object should be shared among consumers on the same GL "
  21. "context";
  22. }
  23. #endif
  24. // If there is a fence, we do a wait on it. Once it has been waited upon, we
  25. // clear the fence and all future call to this method will be a no-op since we
  26. // do not need to wait on that same fence any more.
  27. if (egl_fence_) {
  28. egl_fence_->ServerWait();
  29. egl_fence_.reset();
  30. }
  31. }
  32. } // namespace gl