Flutter Linux Embedder
fl_gl_fence.cc File Reference
#include "fl_gl_fence.h"
#include <epoxy/egl.h>
#include <epoxy/gl.h>

Go to the source code of this file.

Classes

struct  _FlGLFence
 

Functions

static void fl_gl_fence_dispose (GObject *object)
 
static void fl_gl_fence_class_init (FlGLFenceClass *klass)
 
static void fl_gl_fence_init (FlGLFence *self)
 
FlGLFence * fl_gl_fence_new (FlOpenGLManager *opengl_manager)
 
static void client_wait (FlGLFence *self)
 
void fl_gl_fence_wait (FlGLFence *self)
 

Variables

static constexpr EGLTimeKHR kFenceTimeoutNanoseconds = 1000000000
 

Function Documentation

◆ client_wait()

static void client_wait ( FlGLFence *  self)
static

Definition at line 73 of file fl_gl_fence.cc.

73  {
74  // The commands were flushed when the fence was created, so they don't need to
75  // be flushed again here. Flushing wouldn't work anyway, as that only applies
76  // to a fence created in the context current on this thread.
77  EGLint result = eglClientWaitSyncKHR(self->display, self->sync, 0,
79  if (result == EGL_TIMEOUT_EXPIRED_KHR) {
80  g_warning("Timed out waiting for OpenGL rendering to complete");
81  }
82 }
static constexpr EGLTimeKHR kFenceTimeoutNanoseconds
Definition: fl_gl_fence.cc:13

References kFenceTimeoutNanoseconds.

Referenced by fl_gl_fence_wait().

◆ fl_gl_fence_class_init()

static void fl_gl_fence_class_init ( FlGLFenceClass *  klass)
static

Definition at line 41 of file fl_gl_fence.cc.

41  {
42  G_OBJECT_CLASS(klass)->dispose = fl_gl_fence_dispose;
43 }
static void fl_gl_fence_dispose(GObject *object)
Definition: fl_gl_fence.cc:30

References fl_gl_fence_dispose().

◆ fl_gl_fence_dispose()

static void fl_gl_fence_dispose ( GObject *  object)
static

Definition at line 30 of file fl_gl_fence.cc.

30  {
31  FlGLFence* self = FL_GL_FENCE(object);
32 
33  if (self->sync != EGL_NO_SYNC_KHR) {
34  eglDestroySyncKHR(self->display, self->sync);
35  self->sync = EGL_NO_SYNC_KHR;
36  }
37 
38  G_OBJECT_CLASS(fl_gl_fence_parent_class)->dispose(object);
39 }

Referenced by fl_gl_fence_class_init().

◆ fl_gl_fence_init()

static void fl_gl_fence_init ( FlGLFence *  self)
static

Definition at line 45 of file fl_gl_fence.cc.

45  {
46  self->display = EGL_NO_DISPLAY;
47  self->sync = EGL_NO_SYNC_KHR;
48 }

◆ fl_gl_fence_new()

FlGLFence* fl_gl_fence_new ( FlOpenGLManager *  opengl_manager)

FlGLFence:

#FlGLFence marks a point in the OpenGL command stream that can be waited on, which is how rendering done in one context is made visible to another. Flushing a context only guarantees its commands have been submitted, not that they have completed, so a texture rendered in one context can't be used in another until a fence taken after the rendering has been reached. fl_gl_fence_new: @opengl_manager: an #FlOpenGLManager.

Creates a fence that is reached when the commands submitted to the current OpenGL context so far have completed. Requires the context that did the rendering to be current.

Only use this if fl_opengl_manager_can_fence() returns TRUE; drivers without fences have to fall back to waiting for the rendering to complete, e.g. with glFinish().

If the fence can't be created a warning is generated and an #FlGLFence that is not waited for is returned.

Returns: a new #FlGLFence.

Definition at line 50 of file fl_gl_fence.cc.

50  {
51  g_return_val_if_fail(FL_IS_OPENGL_MANAGER(opengl_manager), nullptr);
52 
53  FlGLFence* self = FL_GL_FENCE(g_object_new(fl_gl_fence_get_type(), nullptr));
54 
55  EGLDisplay display = fl_opengl_manager_get_display(opengl_manager);
56  EGLSyncKHR sync = eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, nullptr);
57  // Creating a fence only adds it to the command stream; the commands have to
58  // be flushed for it to be reached, otherwise waiting on it can never return.
59  glFlush();
60  if (sync == EGL_NO_SYNC_KHR) {
61  g_warning("Failed to create fence");
62  return self;
63  }
64 
65  self->display = display;
66  self->sync = sync;
67  self->can_wait_sync = fl_opengl_manager_can_wait_sync(opengl_manager);
68 
69  return self;
70 }
gboolean fl_opengl_manager_can_wait_sync(FlOpenGLManager *self)
EGLDisplay fl_opengl_manager_get_display(FlOpenGLManager *self)

References fl_opengl_manager_can_wait_sync(), and fl_opengl_manager_get_display().

Referenced by TEST_F().

◆ fl_gl_fence_wait()

void fl_gl_fence_wait ( FlGLFence *  fence)

fl_gl_fence_wait: @fence: an #FlGLFence.

Makes the current OpenGL context wait for @fence before executing any commands submitted after this point. Requires the context that is going to use the rendered texture to be current.

This doesn't block the calling thread, the waiting is done by OpenGL. Falls back to blocking the calling thread if the driver can't wait this way.

Definition at line 84 of file fl_gl_fence.cc.

84  {
85  g_return_if_fail(FL_IS_GL_FENCE(self));
86 
87  // Nothing to wait for if the fence couldn't be created.
88  if (self->sync == EGL_NO_SYNC_KHR) {
89  return;
90  }
91 
92  if (!self->can_wait_sync) {
93  client_wait(self);
94  return;
95  }
96 
97  eglWaitSyncKHR(self->display, self->sync, 0);
98 }
static void client_wait(FlGLFence *self)
Definition: fl_gl_fence.cc:73

References client_wait().

Referenced by fl_subsurface_egl_present(), and TEST_F().

Variable Documentation

◆ kFenceTimeoutNanoseconds

constexpr EGLTimeKHR kFenceTimeoutNanoseconds = 1000000000
staticconstexpr

Definition at line 13 of file fl_gl_fence.cc.

Referenced by client_wait().