From nobody Wed Nov 5 15:53:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497429907857961.5913368574801; Wed, 14 Jun 2017 01:45:07 -0700 (PDT) Received: from localhost ([::1]:47234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL3vG-0003LV-Md for importer@patchew.org; Wed, 14 Jun 2017 04:45:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL3sA-0000cB-Ul for qemu-devel@nongnu.org; Wed, 14 Jun 2017 04:41:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL3s7-0007bC-JC for qemu-devel@nongnu.org; Wed, 14 Jun 2017 04:41:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36308) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dL3s7-0007av-Ad for qemu-devel@nongnu.org; Wed, 14 Jun 2017 04:41:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5068C81F01; Wed, 14 Jun 2017 08:41:50 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-125.ams2.redhat.com [10.36.116.125]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CACA777F1; Wed, 14 Jun 2017 08:41:47 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E2E6816E2F; Wed, 14 Jun 2017 10:41:49 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5068C81F01 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5068C81F01 From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 14 Jun 2017 10:41:46 +0200 Message-Id: <20170614084149.31314-2-kraxel@redhat.com> In-Reply-To: <20170614084149.31314-1-kraxel@redhat.com> References: <20170614084149.31314-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 14 Jun 2017 08:41:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/4] egl-helpers: add helpers to handle opengl framebuffers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a collection of egl_fb_*() helper functions to manage and use opengl framebuffers, which is a common pattern in UI code with opengl support. Signed-off-by: Gerd Hoffmann --- include/ui/egl-helpers.h | 15 ++++++++++ ui/egl-helpers.c | 76 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 91 insertions(+) diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h index c785d60e91..be8908737c 100644 --- a/include/ui/egl-helpers.h +++ b/include/ui/egl-helpers.h @@ -8,6 +8,21 @@ extern EGLDisplay *qemu_egl_display; extern EGLConfig qemu_egl_config; =20 +typedef struct egl_fb { + int width; + int height; + GLuint texture; + GLuint framebuffer; + bool delete_texture; +} egl_fb; + +void egl_fb_destroy(egl_fb *fb); +void egl_fb_setup_default(egl_fb *fb, int width, int height); +void egl_fb_create_for_tex(egl_fb *fb, int width, int height, GLuint textu= re); +void egl_fb_create_new_tex(egl_fb *fb, int width, int height); +void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip); +void egl_fb_read(void *dst, egl_fb *src); + #ifdef CONFIG_OPENGL_DMABUF =20 extern int qemu_egl_rn_fd; diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index 4a4d3370ee..bb19a5eeca 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -24,6 +24,82 @@ EGLDisplay *qemu_egl_display; EGLConfig qemu_egl_config; =20 +/* ------------------------------------------------------------------ */ + +void egl_fb_destroy(egl_fb *fb) +{ + if (!fb->framebuffer) { + return; + } + + if (fb->delete_texture) { + glDeleteTextures(1, &fb->texture); + fb->delete_texture =3D false; + } + glDeleteFramebuffers(1, &fb->framebuffer); + + fb->width =3D 0; + fb->height =3D 0; + fb->texture =3D 0; + fb->framebuffer =3D 0; +} + +void egl_fb_setup_default(egl_fb *fb, int width, int height) +{ + fb->width =3D width; + fb->height =3D height; + fb->framebuffer =3D 0; /* default framebuffer */ +} + +void egl_fb_create_for_tex(egl_fb *fb, int width, int height, GLuint textu= re) +{ + fb->width =3D width; + fb->height =3D height; + fb->texture =3D texture; + if (!fb->framebuffer) { + glGenFramebuffers(1, &fb->framebuffer); + } + + glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb->framebuffer); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, fb->texture, 0); +} + +void egl_fb_create_new_tex(egl_fb *fb, int width, int height) +{ + GLuint texture; + + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, + 0, GL_BGRA, GL_UNSIGNED_BYTE, 0); + + egl_fb_create_for_tex(fb, width, height, texture); + fb->delete_texture =3D true; +} + +void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip) +{ + GLuint y1, y2; + + glBindFramebuffer(GL_READ_FRAMEBUFFER, src->framebuffer); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst->framebuffer); + glViewport(0, 0, dst->width, dst->height); + y1 =3D flip ? src->height : 0; + y2 =3D flip ? 0 : src->height; + glBlitFramebuffer(0, y1, src->width, y2, + 0, 0, dst->width, dst->height, + GL_COLOR_BUFFER_BIT, GL_LINEAR); +} + +void egl_fb_read(void *dst, egl_fb *src) +{ + glBindFramebuffer(GL_READ_FRAMEBUFFER, src->framebuffer); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadPixels(0, 0, src->width, src->height, + GL_BGRA, GL_UNSIGNED_BYTE, dst); +} + /* ---------------------------------------------------------------------- = */ =20 #ifdef CONFIG_OPENGL_DMABUF --=20 2.9.3