Commit 65afcfa0 authored by Vikas Soni's avatar Vikas Soni Committed by Commit Bot

Implement a shareable egl fence.

This class is an optimized way to share an egl fence
among multiple consumers. Once the shared egl fence
has been waited upon by any of the consumer, all the
future waits to the same fence becomes no-op since we
don't need to wait again on the same fence any more.
This saves un-neccesary gl calls issued to do wait by
each consumer.

Change-Id: I5bf0c0f9a36d2d1a2709100343a141ec8b841dae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989025
Commit-Queue: vikas soni <vikassoni@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731779}
parent ff208ba9
......@@ -213,6 +213,8 @@ jumbo_component("gl") {
"gl_image_egl.h",
"gl_surface_egl.cc",
"gl_surface_egl.h",
"shared_gl_fence_egl.cc",
"shared_gl_fence_egl.h",
]
if (is_linux || use_ozone) {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gl/shared_gl_fence_egl.h"
#include "base/logging.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_fence_egl.h"
namespace gl {
SharedGLFenceEGL::SharedGLFenceEGL() : egl_fence_(GLFenceEGL::Create()) {
// GLFenceEGL::Create() is not supposed to fail.
DCHECK(egl_fence_);
}
SharedGLFenceEGL::~SharedGLFenceEGL() = default;
void SharedGLFenceEGL::ServerWait() {
base::AutoLock lock(lock_);
#if DCHECK_IS_ON()
if (!gl_api_) {
gl_api_ = gl::g_current_gl_context;
} else if (gl_api_ != gl::g_current_gl_context) {
LOG(FATAL) << "This object should be shared among consumers on the same GL "
"context";
}
#endif
// If there is a fence, we do a wait on it. Once it has been waited upon, we
// clear the fence and all future call to this method will be a no-op since we
// do not need to wait on that same fence any more.
if (egl_fence_) {
egl_fence_->ServerWait();
egl_fence_.reset();
}
}
} // namespace gl
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GL_SHARED_GL_FENCE_EGL_H_
#define UI_GL_SHARED_GL_FENCE_EGL_H_
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "ui/gl/gl_export.h"
namespace gl {
class GLFenceEGL;
class GLApi;
// This class is an optimized way to share an egl fence among multiple
// consumers. Once the shared |egl_fence_| has been waited upon by any of the
// consumer, all the future waits to the same fence becomes no-op since we don't
// need to wait again on the same fence any more. This saves un-neccesary gl
// calls issued to do wait by each consumer.
// This object should only be shared among consumers of the same GL context
// which is true for Webview case.
// TODO(vikassoni): Add logic to handle consumers from different GL context.
class GL_EXPORT SharedGLFenceEGL
: public base::RefCountedThreadSafe<SharedGLFenceEGL> {
public:
SharedGLFenceEGL();
// Issues a ServerWait on the |egl_fence_|.
void ServerWait();
protected:
virtual ~SharedGLFenceEGL();
private:
friend class base::RefCountedThreadSafe<SharedGLFenceEGL>;
std::unique_ptr<GLFenceEGL> egl_fence_ GUARDED_BY(lock_);
// A lock that guard against multiple threads trying to access |egl_fence_|.
base::Lock lock_;
// GLApi on which all the consumers for this object should be on.
gl::GLApi* gl_api_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(SharedGLFenceEGL);
};
} // namespace gl
#endif // UI_GL_SHARED_GL_FENCE_EGL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment