mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 08:38:20 +00:00
[client] egl: fix context binding enabling a lock free implementation
This commit is contained in:
parent
ae2ffd0a28
commit
075c82b32c
@ -109,8 +109,6 @@ typedef struct LG_Renderer
|
||||
LG_RendererOnFrameEvent on_frame_event;
|
||||
LG_RendererOnAlert on_alert;
|
||||
LG_RendererRender render_startup;
|
||||
LG_RendererRender render_begin;
|
||||
LG_RendererRender render_end;
|
||||
LG_RendererRender render;
|
||||
LG_RendererUpdateFPS update_fps;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "desktop.h"
|
||||
#include "egl.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/option.h"
|
||||
#include "common/locking.h"
|
||||
@ -211,7 +210,6 @@ bool egl_desktop_update(EGL_Desktop * desktop, const bool sourceChanged, const L
|
||||
desktop->width = format.width;
|
||||
desktop->height = format.height;
|
||||
|
||||
egl_lock(desktop->egl);
|
||||
if (!egl_texture_setup(
|
||||
desktop->texture,
|
||||
pixFmt,
|
||||
@ -221,27 +219,20 @@ bool egl_desktop_update(EGL_Desktop * desktop, const bool sourceChanged, const L
|
||||
true // streaming texture
|
||||
))
|
||||
{
|
||||
egl_unlock(desktop->egl);
|
||||
DEBUG_ERROR("Failed to setup the desktop texture");
|
||||
return false;
|
||||
}
|
||||
egl_unlock(desktop->egl);
|
||||
}
|
||||
|
||||
if (!egl_texture_update_from_frame(desktop->texture, frame))
|
||||
return false;
|
||||
|
||||
egl_lock(desktop->egl);
|
||||
enum EGL_TexStatus status;
|
||||
if ((status = egl_texture_process(desktop->texture)) != EGL_TEX_STATUS_OK)
|
||||
{
|
||||
if (status != EGL_TEX_STATUS_NOTREADY)
|
||||
{
|
||||
DEBUG_ERROR("Failed to process the desktop texture");
|
||||
egl_unlock(desktop->egl);
|
||||
}
|
||||
}
|
||||
egl_unlock(desktop->egl);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ struct Inst
|
||||
EGLDisplay display;
|
||||
EGLConfig configs;
|
||||
EGLSurface surface;
|
||||
LG_Lock lock;
|
||||
EGLContext context, frameContext;
|
||||
|
||||
EGL_Desktop * desktop; // the desktop
|
||||
@ -171,7 +170,6 @@ bool egl_create(void ** opaque, const LG_RendererParams params)
|
||||
this->scaleY = 1.0f;
|
||||
this->screenScaleX = 1.0f;
|
||||
this->screenScaleY = 1.0f;
|
||||
LG_LOCK_INIT(this->lock);
|
||||
|
||||
this->font = LG_Fonts[0];
|
||||
if (!this->font->create(&this->fontObj, NULL, 16))
|
||||
@ -315,6 +313,27 @@ bool egl_on_frame_event(void * opaque, const LG_RendererFormat format, const Fra
|
||||
|
||||
this->useNearest = this->width < format.width || this->height < format.height;
|
||||
|
||||
/* this event runs in a second thread so we need to init it here */
|
||||
if (!this->frameContext)
|
||||
{
|
||||
static EGLint attrs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
if (!(this->frameContext = eglCreateContext(this->display, this->configs, this->context, attrs)))
|
||||
{
|
||||
DEBUG_ERROR("Failed to create the frame context");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!eglMakeCurrent(this->display, EGL_NO_SURFACE, EGL_NO_SURFACE, this->frameContext))
|
||||
{
|
||||
DEBUG_ERROR("Failed to make the frame context current");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!egl_desktop_update(this->desktop, sourceChanged, format, frame))
|
||||
{
|
||||
DEBUG_INFO("Failed to to update the desktop");
|
||||
@ -506,47 +525,6 @@ bool egl_render_startup(void * opaque, SDL_Window * window)
|
||||
return true;
|
||||
}
|
||||
|
||||
void egl_lock(void * opaque)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
|
||||
if (!this->frameContext)
|
||||
{
|
||||
static EGLint attrs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
if (!(this->frameContext = eglCreateContext(this->display, this->configs, this->context, attrs)))
|
||||
DEBUG_ERROR("Failed to create the frame context");
|
||||
}
|
||||
|
||||
LG_LOCK(this->lock);
|
||||
eglMakeCurrent(this->display, this->surface, this->surface, this->frameContext);
|
||||
}
|
||||
|
||||
void egl_unlock(void * opaque)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
eglMakeCurrent(this->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
LG_UNLOCK(this->lock);
|
||||
}
|
||||
|
||||
bool egl_render_begin(void * opaque, SDL_Window * window)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
LG_LOCK(this->lock);
|
||||
return eglMakeCurrent(this->display, this->surface, this->surface, this->context);
|
||||
}
|
||||
|
||||
bool egl_render_end(void * opaque, SDL_Window * window)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
bool ret = eglMakeCurrent(this->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
LG_UNLOCK(this->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool egl_render(void * opaque, SDL_Window * window)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
@ -623,8 +601,6 @@ struct LG_Renderer LGR_EGL =
|
||||
.on_frame_event = egl_on_frame_event,
|
||||
.on_alert = egl_on_alert,
|
||||
.render_startup = egl_render_startup,
|
||||
.render_begin = egl_render_begin,
|
||||
.render_end = egl_render_end,
|
||||
.render = egl_render,
|
||||
.update_fps = egl_update_fps
|
||||
};
|
||||
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017-2020 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "interface/renderer.h"
|
||||
|
||||
/* helpers to lock and make current the secondary context for the desktop */
|
||||
void egl_lock(void * opaque);
|
||||
void egl_unlock(void * opaque);
|
@ -104,7 +104,11 @@ void egl_texture_free(EGL_Texture ** texture)
|
||||
if (t->hasPBO)
|
||||
{
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, t->pbo);
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
if ((*texture)->tex[i].map)
|
||||
{
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
(*texture)->tex[i].map = NULL;
|
||||
}
|
||||
glDeleteBuffers(1, &t->pbo);
|
||||
if (t->sync)
|
||||
glDeleteSync(t->sync);
|
||||
@ -149,8 +153,12 @@ static void egl_texture_unmap(EGL_Texture * texture)
|
||||
{
|
||||
for(int i = 0; i < TEXTURE_COUNT; ++i)
|
||||
{
|
||||
if (!texture->tex[i].map)
|
||||
continue;
|
||||
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[i].pbo);
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
texture->tex[i].map = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,11 +281,7 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_
|
||||
for(int i = 0; i < TEXTURE_COUNT; ++i)
|
||||
{
|
||||
if (texture->tex[i].hasPBO)
|
||||
{
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[i].pbo);
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
glDeleteBuffers(1, &texture->tex[i].pbo);
|
||||
}
|
||||
|
||||
glGenBuffers(1, &texture->tex[i].pbo);
|
||||
texture->tex[i].hasPBO = true;
|
||||
@ -400,6 +404,9 @@ enum EGL_TexStatus egl_texture_process(EGL_Texture * texture)
|
||||
texture->tex[s.u].sync =
|
||||
glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
|
||||
/* we must flush to ensure the sync is in the command buffer */
|
||||
glFlush();
|
||||
|
||||
atomic_store_explicit(&texture->state.u, nextu, memory_order_release);
|
||||
|
||||
/* remap the for the next update */
|
||||
@ -421,7 +428,7 @@ enum EGL_TexStatus egl_texture_bind(EGL_Texture * texture)
|
||||
|
||||
if (texture->tex[s.s].sync != 0)
|
||||
{
|
||||
switch(glClientWaitSync(texture->tex[s.s].sync, 0, 20000000))
|
||||
switch(glClientWaitSync(texture->tex[s.s].sync, 0, 20000000)) // 20ms
|
||||
{
|
||||
case GL_ALREADY_SIGNALED:
|
||||
case GL_CONDITION_SATISFIED:
|
||||
@ -436,6 +443,7 @@ enum EGL_TexStatus egl_texture_bind(EGL_Texture * texture)
|
||||
break;
|
||||
|
||||
case GL_WAIT_FAILED:
|
||||
case GL_INVALID_VALUE:
|
||||
glDeleteSync(texture->tex[s.s].sync);
|
||||
texture->tex[s.s].sync = 0;
|
||||
EGL_ERROR("glClientWaitSync failed");
|
||||
|
@ -50,4 +50,4 @@ bool egl_texture_update (EGL_Texture * texture, const uint8_t * bu
|
||||
bool egl_texture_update_from_frame(EGL_Texture * texture, const FrameBuffer * frame);
|
||||
enum EGL_TexStatus egl_texture_process(EGL_Texture * texture);
|
||||
enum EGL_TexStatus egl_texture_bind (EGL_Texture * texture);
|
||||
int egl_texture_count (EGL_Texture * texture);
|
||||
int egl_texture_count (EGL_Texture * texture);
|
||||
|
@ -175,10 +175,6 @@ static int renderThread(void * unused)
|
||||
}
|
||||
}
|
||||
|
||||
if (state.lgr->render_begin && !state.lgr->render_begin(state.lgrData,
|
||||
state.window))
|
||||
break;
|
||||
|
||||
if (state.lgrResize)
|
||||
{
|
||||
if (state.lgr)
|
||||
@ -208,10 +204,6 @@ static int renderThread(void * unused)
|
||||
}
|
||||
}
|
||||
|
||||
if (state.lgr->render_end && !state.lgr->render_end(state.lgrData,
|
||||
state.window))
|
||||
break;
|
||||
|
||||
if (!state.resizeDone && state.resizeTimeout < microtime())
|
||||
{
|
||||
SDL_SetWindowSize(
|
||||
|
Loading…
Reference in New Issue
Block a user