Patch Detail
Show a patch.
GET /api/1.1/patches/9570/?format=api
{ "id": 9570, "url": "https://patchwork.libcamera.org/api/1.1/patches/9570/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9570/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200911085514.30021-4-show.liu@linaro.org>", "date": "2020-09-11T08:55:13", "name": "[libcamera-devel,v6,3/4] qcam: add viewfinderGL class to accelerate the format convert", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "64dbb07a99816e5e447cab27549b668beb2a9c3f", "submitter": { "id": 24, "url": "https://patchwork.libcamera.org/api/1.1/people/24/?format=api", "name": "Show Liu", "email": "show.liu@linaro.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/9570/mbox/", "series": [ { "id": 1284, "url": "https://patchwork.libcamera.org/api/1.1/series/1284/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1284", "date": "2020-09-11T08:55:10", "name": "qcam: accelerate format conversion by OpenGL shader", "version": 6, "mbox": "https://patchwork.libcamera.org/series/1284/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9570/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9570/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 11E0FBDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 11 Sep 2020 08:55:49 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D24D862D53;\n\tFri, 11 Sep 2020 10:55:48 +0200 (CEST)", "from mail-pf1-x429.google.com (mail-pf1-x429.google.com\n\t[IPv6:2607:f8b0:4864:20::429])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 132BF62D5B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 11 Sep 2020 10:55:47 +0200 (CEST)", "by mail-pf1-x429.google.com with SMTP id v196so6934137pfc.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 11 Sep 2020 01:55:47 -0700 (PDT)", "from localhost.localdomain (211-20-20-223.HINET-IP.hinet.net.\n\t[211.20.20.223]) by smtp.gmail.com with ESMTPSA id\n\tw192sm1616543pfd.156.2020.09.11.01.55.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 11 Sep 2020 01:55:44 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"o2mf0K7u\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=5O4q8wP4WZ8rtOxrQxfssO+wmURgF1l82eXdHikeIOY=;\n\tb=o2mf0K7uJqSC8NuKBdfG0qA/Ah3/HKAF13Y8AwA3uPDxvhHmYvUsdaJpPIw27KeZKK\n\ty0W0A+UfFDY5ebb4Lcq8I/VO7QuhBX3+DOMm5efp4Izd/Gd/UnxlDqchVLKML8b7Pntk\n\t7+pSXYX89zmYm0fM+TtyjaO0NtIbnzKDl4Cr4zCrWYBC8YAEe5bltt2adExONKduhgsL\n\tJhZfwUA/sX3ehcFIJ2snmmBujXgvP7nVIS//0BVYAMfLQI4eixqRtKfP6u6Efsc+2Ptq\n\tbUM+ArR9J1uDWVnhVceL8kJPEHpxgEgUBz8MR1BOgPJmisXa2unpNApMSP2DL2obB9r0\n\tm37Q==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=5O4q8wP4WZ8rtOxrQxfssO+wmURgF1l82eXdHikeIOY=;\n\tb=UG1gQ1qO/VikxjfeRfuVVtBD1Mp5LCKVhSffbT8i8AVpKY3M14xMsUIKLaeo5OwIyS\n\troycoYlsjVPbiUKr/iJ2ckuYf3fZgCX2CkUIpdhVp0bOlcSN9zKknBE2L8UVQbDWQgXT\n\t8RKXxqCaePFMlk53AbBeqjsqlTmmMQy7p5sV2Rb4DW8SaOkjEuIo3xjJlv2y+CtsRRgq\n\t5Jm6WxnaBaDoPuv8mlJJUQGMi60EDtVBqA6qKURH04tQ+Ki+61XbU+gVMpSBK5MDoO4t\n\tgPSZ9cyMrHMJmsq5EN92RyT+MGHQuT/Xr+NaKKyoo//cYKIZdW0RJEP055LW78lhNR3+\n\tBJew==", "X-Gm-Message-State": "AOAM532xWOUW5NPTqjiCGbo57NeVfK4zJsZhCcC9LZFKbMxOFNdOlZF+\n\tYJBe1hTz1AuVqFcJ4yg+HYSHHv87sOm4AA==", "X-Google-Smtp-Source": "ABdhPJxTfnisZeBE0NAx+kSM3VwjeB6/mkXzKQIfl37jqZNwaM7X6v/21+iYSjZUsmBqH3aok6gPMQ==", "X-Received": "by 2002:a17:902:a5cb:: with SMTP id\n\tt11mr1076741plq.102.1599814545006; \n\tFri, 11 Sep 2020 01:55:45 -0700 (PDT)", "From": "Show Liu <show.liu@linaro.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 11 Sep 2020 16:55:13 +0800", "Message-Id": "<20200911085514.30021-4-show.liu@linaro.org>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20200911085514.30021-1-show.liu@linaro.org>", "References": "<20200911085514.30021-1-show.liu@linaro.org>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v6 3/4] qcam: add viewfinderGL class to\n\taccelerate the format convert", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "the viewfinderGL accelerates the format conversion by\nusing OpenGL ES shader\n\nSigned-off-by: Show Liu <show.liu@linaro.org>\n---\n meson.build | 1 +\n src/qcam/meson.build | 17 +-\n src/qcam/viewfinder_gl.cpp | 456 +++++++++++++++++++++++++++++++++++++\n src/qcam/viewfinder_gl.h | 96 ++++++++\n 4 files changed, 568 insertions(+), 2 deletions(-)\n create mode 100644 src/qcam/viewfinder_gl.cpp\n create mode 100644 src/qcam/viewfinder_gl.h", "diff": "diff --git a/meson.build b/meson.build\nindex 1ea35e9..c58d458 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -26,6 +26,7 @@ libcamera_version = libcamera_git_version.split('+')[0]\n \n # Configure the build environment.\n cc = meson.get_compiler('c')\n+cxx = meson.get_compiler('cpp')\n config_h = configuration_data()\n \n if cc.has_header_symbol('execinfo.h', 'backtrace')\ndiff --git a/src/qcam/meson.build b/src/qcam/meson.build\nindex a4bad0a..9bb48c0 100644\n--- a/src/qcam/meson.build\n+++ b/src/qcam/meson.build\n@@ -16,14 +16,14 @@ qcam_moc_headers = files([\n \n qcam_resources = files([\n 'assets/feathericons/feathericons.qrc',\n- 'assets/shader/shaders.qrc'\n ])\n \n qt5 = import('qt5')\n qt5_dep = dependency('qt5',\n method : 'pkg-config',\n modules : ['Core', 'Gui', 'Widgets'],\n- required : get_option('qcam'))\n+ required : get_option('qcam'),\n+ version : '>=5.4')\n \n if qt5_dep.found()\n qcam_deps = [\n@@ -42,6 +42,19 @@ if qt5_dep.found()\n ])\n endif\n \n+ if cxx.has_header_symbol('QOpenGLWidget', 'QOpenGLWidget',\n+ dependencies : qt5_dep, args : '-fPIC')\n+ qcam_sources += files([\n+ 'viewfinder_gl.cpp',\n+ ])\n+ qcam_moc_headers += files([\n+ 'viewfinder_gl.h',\n+ ])\n+ qcam_resources += files([\n+ 'assets/shader/shaders.qrc'\n+ ])\n+ endif\n+\n # gcc 9 introduced a deprecated-copy warning that is triggered by Qt until\n # Qt 5.13. clang 10 introduced the same warning, but detects more issues\n # that are not fixed in Qt yet. Disable the warning manually in both cases.\ndiff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp\nnew file mode 100644\nindex 0000000..84f4866\n--- /dev/null\n+++ b/src/qcam/viewfinder_gl.cpp\n@@ -0,0 +1,456 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Linaro\n+ *\n+ * viewfinderGL.cpp - OpenGL Viewfinder for rendering by OpenGL shader\n+ */\n+\n+#include \"viewfinder_gl.h\"\n+\n+#include <QImage>\n+\n+#include <libcamera/formats.h>\n+\n+static const QList<libcamera::PixelFormat> supportedFormats{\n+\tlibcamera::formats::NV12,\n+\tlibcamera::formats::NV21,\n+\tlibcamera::formats::NV16,\n+\tlibcamera::formats::NV61,\n+\tlibcamera::formats::NV24,\n+\tlibcamera::formats::NV42,\n+\tlibcamera::formats::YUV420,\n+\tlibcamera::formats::YVU420\n+};\n+\n+ViewFinderGL::ViewFinderGL(QWidget *parent)\n+\t: QOpenGLWidget(parent), buffer_(nullptr), yuvData_(nullptr),\n+\t fragmentShader_(nullptr), vertexShader_(nullptr),\n+\t vertexBuffer_(QOpenGLBuffer::VertexBuffer),\n+\t textureU_(QOpenGLTexture::Target2D),\n+\t textureV_(QOpenGLTexture::Target2D),\n+\t textureY_(QOpenGLTexture::Target2D)\n+{\n+}\n+\n+ViewFinderGL::~ViewFinderGL()\n+{\n+\tremoveShader();\n+\n+\tif (vertexBuffer_.isCreated())\n+\t\tvertexBuffer_.destroy();\n+}\n+\n+const QList<libcamera::PixelFormat> &ViewFinderGL::nativeFormats() const\n+{\n+\treturn supportedFormats;\n+}\n+\n+int ViewFinderGL::setFormat(const libcamera::PixelFormat &format,\n+\t\t\t const QSize &size)\n+{\n+\tint ret = 0;\n+\n+\t/* If the fragment is ceeated remove it and create a new one */\n+\tif (fragmentShader_) {\n+\t\tif (shaderProgram_.isLinked()) {\n+\t\t\tshaderProgram_.release();\n+\t\t\tshaderProgram_.removeShader(fragmentShader_);\n+\t\t\tdelete fragmentShader_;\n+\t\t}\n+\t}\n+\n+\tif (selectFormat(format)) {\n+\t\tformat_ = format;\n+\t\tsize_ = size;\n+\t} else {\n+\t\tret = -1;\n+\t}\n+\tupdateGeometry();\n+\treturn ret;\n+}\n+\n+void ViewFinderGL::stop()\n+{\n+\tif (buffer_) {\n+\t\trenderComplete(buffer_);\n+\t\tbuffer_ = nullptr;\n+\t}\n+}\n+\n+QImage ViewFinderGL::getCurrentImage()\n+{\n+\tQMutexLocker locker(&mutex_);\n+\n+\treturn grabFramebuffer();\n+}\n+\n+void ViewFinderGL::render(libcamera::FrameBuffer *buffer, MappedBuffer *map)\n+{\n+\tif (buffer->planes().size() != 1) {\n+\t\tqWarning() << \"Multi-planar buffers are not supported\";\n+\t\treturn;\n+\t}\n+\n+\tif (buffer_)\n+\t\trenderComplete(buffer_);\n+\n+\tyuvData_ = static_cast<unsigned char *>(map->memory);\n+\tupdate();\n+\tbuffer_ = buffer;\n+}\n+\n+bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format)\n+{\n+\tbool ret = true;\n+\tswitch (format) {\n+\tcase libcamera::formats::NV12:\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 2;\n+\t\tvertexShaderSrc_ = \":NV_vertex_shader.glsl\";\n+\t\tfragmentShaderSrc_ = \":NV_2_planes_UV_f.glsl\";\n+\t\tbreak;\n+\tcase libcamera::formats::NV21:\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 2;\n+\t\tvertexShaderSrc_ = \":NV_vertex_shader.glsl\";\n+\t\tfragmentShaderSrc_ = \":NV_2_planes_VU_f.glsl\";\n+\t\tbreak;\n+\tcase libcamera::formats::NV16:\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 1;\n+\t\tvertexShaderSrc_ = \":NV_vertex_shader.glsl\";\n+\t\tfragmentShaderSrc_ = \":NV_2_planes_UV_f.glsl\";\n+\t\tbreak;\n+\tcase libcamera::formats::NV61:\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 1;\n+\t\tvertexShaderSrc_ = \":NV_vertex_shader.glsl\";\n+\t\tfragmentShaderSrc_ = \":NV_2_planes_VU_f.glsl\";\n+\t\tbreak;\n+\tcase libcamera::formats::NV24:\n+\t\thorzSubSample_ = 1;\n+\t\tvertSubSample_ = 1;\n+\t\tvertexShaderSrc_ = \":NV_vertex_shader.glsl\";\n+\t\tfragmentShaderSrc_ = \":NV_2_planes_UV_f.glsl\";\n+\t\tbreak;\n+\tcase libcamera::formats::NV42:\n+\t\thorzSubSample_ = 1;\n+\t\tvertSubSample_ = 1;\n+\t\tvertexShaderSrc_ = \":NV_vertex_shader.glsl\";\n+\t\tfragmentShaderSrc_ = \":NV_2_planes_VU_f.glsl\";\n+\t\tbreak;\n+\tcase libcamera::formats::YUV420:\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 2;\n+\t\tvertexShaderSrc_ = \":NV_vertex_shader.glsl\";\n+\t\tfragmentShaderSrc_ = \":NV_3_planes_f.glsl\";\n+\t\tbreak;\n+\tcase libcamera::formats::YVU420:\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 2;\n+\t\tvertexShaderSrc_ = \":NV_vertex_shader.glsl\";\n+\t\tfragmentShaderSrc_ = \":NV_3_planes_f.glsl\";\n+\t\tbreak;\n+\tdefault:\n+\t\tret = false;\n+\t\tqWarning() << \"[ViewFinderGL]:\"\n+\t\t\t << \"format not supported.\";\n+\t\tbreak;\n+\t};\n+\n+\treturn ret;\n+}\n+\n+bool ViewFinderGL::createVertexShader()\n+{\n+\t/* Create Vertex Shader */\n+\tvertexShader_ = new QOpenGLShader(QOpenGLShader::Vertex, this);\n+\n+\t/* Compile the vertex shader */\n+\tif (!vertexShader_->compileSourceFile(vertexShaderSrc_)) {\n+\t\tqWarning() << \"[ViewFinderGL]:\" << vertexShader_->log();\n+\t\treturn false;\n+\t}\n+\n+\tshaderProgram_.addShader(vertexShader_);\n+\treturn true;\n+}\n+\n+bool ViewFinderGL::createFragmentShader()\n+{\n+\tint attributeVertex;\n+\tint attributeTexture;\n+\n+\t/* Create Fragment Shader */\n+\tfragmentShader_ = new QOpenGLShader(QOpenGLShader::Fragment, this);\n+\n+\t/* Compile the fragment shader */\n+\tif (!fragmentShader_->compileSourceFile(fragmentShaderSrc_)) {\n+\t\tqWarning() << \"[ViewFinderGL]:\" << fragmentShader_->log();\n+\t\treturn false;\n+\t}\n+\n+\tshaderProgram_.addShader(fragmentShader_);\n+\n+\t/* Link shader pipeline */\n+\tif (!shaderProgram_.link()) {\n+\t\tqWarning() << \"[ViewFinderGL]:\" << shaderProgram_.log();\n+\t\tclose();\n+\t}\n+\n+\t/* Bind shader pipeline for use */\n+\tif (!shaderProgram_.bind()) {\n+\t\tqWarning() << \"[ViewFinderGL]:\" << shaderProgram_.log();\n+\t\tclose();\n+\t}\n+\n+\tattributeVertex = shaderProgram_.attributeLocation(\"vertexIn\");\n+\tattributeTexture = shaderProgram_.attributeLocation(\"textureIn\");\n+\n+\tshaderProgram_.enableAttributeArray(attributeVertex);\n+\tshaderProgram_.setAttributeBuffer(attributeVertex,\n+\t\t\t\t\t GL_FLOAT,\n+\t\t\t\t\t 0,\n+\t\t\t\t\t 2,\n+\t\t\t\t\t 2 * sizeof(GLfloat));\n+\n+\tshaderProgram_.enableAttributeArray(attributeTexture);\n+\tshaderProgram_.setAttributeBuffer(attributeTexture,\n+\t\t\t\t\t GL_FLOAT,\n+\t\t\t\t\t 8 * sizeof(GLfloat),\n+\t\t\t\t\t 2,\n+\t\t\t\t\t 2 * sizeof(GLfloat));\n+\n+\ttextureUniformY_ = shaderProgram_.uniformLocation(\"tex_y\");\n+\ttextureUniformU_ = shaderProgram_.uniformLocation(\"tex_u\");\n+\ttextureUniformV_ = shaderProgram_.uniformLocation(\"tex_v\");\n+\n+\tif (!textureY_.isCreated())\n+\t\ttextureY_.create();\n+\n+\tif (!textureU_.isCreated())\n+\t\ttextureU_.create();\n+\n+\tif (!textureV_.isCreated())\n+\t\ttextureV_.create();\n+\n+\tid_y_ = textureY_.textureId();\n+\tid_u_ = textureU_.textureId();\n+\tid_v_ = textureV_.textureId();\n+\treturn true;\n+}\n+\n+void ViewFinderGL::configureTexture(unsigned int id)\n+{\n+\tglBindTexture(GL_TEXTURE_2D, id);\n+\tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\n+\tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\n+\tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);\n+\tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);\n+}\n+\n+void ViewFinderGL::removeShader()\n+{\n+\tif (shaderProgram_.isLinked()) {\n+\t\tshaderProgram_.release();\n+\t\tshaderProgram_.removeAllShaders();\n+\t}\n+\n+\tif (fragmentShader_)\n+\t\tdelete fragmentShader_;\n+\n+\tif (vertexShader_)\n+\t\tdelete vertexShader_;\n+}\n+\n+void ViewFinderGL::initializeGL()\n+{\n+\tinitializeOpenGLFunctions();\n+\tglEnable(GL_TEXTURE_2D);\n+\tglDisable(GL_DEPTH_TEST);\n+\n+\tstatic const GLfloat coordinates[2][4][2]{\n+\t\t{\n+\t\t\t/* Vertex coordinates */\n+\t\t\t{ -1.0f, -1.0f },\n+\t\t\t{ -1.0f, +1.0f },\n+\t\t\t{ +1.0f, +1.0f },\n+\t\t\t{ +1.0f, -1.0f },\n+\t\t},\n+\t\t{\n+\t\t\t/* Texture coordinates */\n+\t\t\t{ 1.0f, 0.0f },\n+\t\t\t{ 1.0f, 1.0f },\n+\t\t\t{ 0.0f, 1.0f },\n+\t\t\t{ 0.0f, 0.0f },\n+\t\t},\n+\t};\n+\n+\tvertexBuffer_.create();\n+\tvertexBuffer_.bind();\n+\tvertexBuffer_.allocate(coordinates, sizeof(coordinates));\n+\n+\t/* Create Vertex Shader */\n+\tif (!createVertexShader())\n+\t\tqWarning() << \"[ViewFinderGL]: create vertex shader failed.\";\n+\n+\tglClearColor(1.0f, 1.0f, 1.0f, 0.0f);\n+}\n+\n+void ViewFinderGL::doRender()\n+{\n+\tswitch (format_) {\n+\tcase libcamera::formats::NV12:\n+\tcase libcamera::formats::NV21:\n+\tcase libcamera::formats::NV16:\n+\tcase libcamera::formats::NV61:\n+\tcase libcamera::formats::NV24:\n+\tcase libcamera::formats::NV42:\n+\t\t/* activate texture Y */\n+\t\tglActiveTexture(GL_TEXTURE0);\n+\t\tconfigureTexture(id_y_);\n+\t\tglTexImage2D(GL_TEXTURE_2D,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t size_.width(),\n+\t\t\t size_.height(),\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t GL_UNSIGNED_BYTE,\n+\t\t\t yuvData_);\n+\t\tshaderProgram_.setUniformValue(textureUniformY_, 0);\n+\n+\t\t/* activate texture UV/VU */\n+\t\tglActiveTexture(GL_TEXTURE1);\n+\t\tconfigureTexture(id_u_);\n+\t\tglTexImage2D(GL_TEXTURE_2D,\n+\t\t\t 0,\n+\t\t\t GL_RG,\n+\t\t\t size_.width() / horzSubSample_,\n+\t\t\t size_.height() / vertSubSample_,\n+\t\t\t 0,\n+\t\t\t GL_RG,\n+\t\t\t GL_UNSIGNED_BYTE,\n+\t\t\t (char *)yuvData_ + size_.width() * size_.height());\n+\t\tshaderProgram_.setUniformValue(textureUniformU_, 1);\n+\t\tbreak;\n+\n+\tcase libcamera::formats::YUV420:\n+\t\t/* activate texture Y */\n+\t\tglActiveTexture(GL_TEXTURE0);\n+\t\tconfigureTexture(id_y_);\n+\t\tglTexImage2D(GL_TEXTURE_2D,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t size_.width(),\n+\t\t\t size_.height(),\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t GL_UNSIGNED_BYTE,\n+\t\t\t yuvData_);\n+\t\tshaderProgram_.setUniformValue(textureUniformY_, 0);\n+\n+\t\t/* activate texture U */\n+\t\tglActiveTexture(GL_TEXTURE1);\n+\t\tconfigureTexture(id_u_);\n+\t\tglTexImage2D(GL_TEXTURE_2D,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t size_.width() / horzSubSample_,\n+\t\t\t size_.height() / vertSubSample_,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t GL_UNSIGNED_BYTE,\n+\t\t\t (char *)yuvData_ + size_.width() * size_.height());\n+\t\tshaderProgram_.setUniformValue(textureUniformU_, 1);\n+\n+\t\t/* activate texture V */\n+\t\tglActiveTexture(GL_TEXTURE2);\n+\t\tconfigureTexture(id_v_);\n+\t\tglTexImage2D(GL_TEXTURE_2D,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t size_.width() / horzSubSample_,\n+\t\t\t size_.height() / vertSubSample_,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t GL_UNSIGNED_BYTE,\n+\t\t\t (char *)yuvData_ + size_.width() * size_.height() * 5 / 4);\n+\t\tshaderProgram_.setUniformValue(textureUniformV_, 2);\n+\t\tbreak;\n+\n+\tcase libcamera::formats::YVU420:\n+\t\t/* activate texture Y */\n+\t\tglActiveTexture(GL_TEXTURE0);\n+\t\tconfigureTexture(id_y_);\n+\t\tglTexImage2D(GL_TEXTURE_2D,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t size_.width(),\n+\t\t\t size_.height(),\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t GL_UNSIGNED_BYTE,\n+\t\t\t yuvData_);\n+\t\tshaderProgram_.setUniformValue(textureUniformY_, 0);\n+\n+\t\t/* activate texture V */\n+\t\tglActiveTexture(GL_TEXTURE2);\n+\t\tconfigureTexture(id_v_);\n+\t\tglTexImage2D(GL_TEXTURE_2D,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t size_.width() / horzSubSample_,\n+\t\t\t size_.height() / vertSubSample_,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t GL_UNSIGNED_BYTE,\n+\t\t\t (char *)yuvData_ + size_.width() * size_.height());\n+\t\tshaderProgram_.setUniformValue(textureUniformV_, 1);\n+\n+\t\t/* activate texture U */\n+\t\tglActiveTexture(GL_TEXTURE1);\n+\t\tconfigureTexture(id_u_);\n+\t\tglTexImage2D(GL_TEXTURE_2D,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t size_.width() / horzSubSample_,\n+\t\t\t size_.height() / vertSubSample_,\n+\t\t\t 0,\n+\t\t\t GL_RED,\n+\t\t\t GL_UNSIGNED_BYTE,\n+\t\t\t (char *)yuvData_ + size_.width() * size_.height() * 5 / 4);\n+\t\tshaderProgram_.setUniformValue(textureUniformU_, 2);\n+\t\tbreak;\n+\n+\tdefault:\n+\t\tbreak;\n+\t};\n+}\n+\n+void ViewFinderGL::paintGL()\n+{\n+\tif (!fragmentShader_)\n+\t\tif (!createFragmentShader()) {\n+\t\t\tqWarning() << \"[ViewFinderGL]:\"\n+\t\t\t\t << \"create fragment shader failed.\";\n+\t\t}\n+\n+\tif (yuvData_) {\n+\t\tglClearColor(0.0, 0.0, 0.0, 1.0);\n+\t\tglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\n+\n+\t\tdoRender();\n+\t\tglDrawArrays(GL_TRIANGLE_FAN, 0, 4);\n+\t}\n+}\n+\n+void ViewFinderGL::resizeGL(int w, int h)\n+{\n+\tglViewport(0, 0, w, h);\n+}\n+\n+QSize ViewFinderGL::sizeHint() const\n+{\n+\treturn size_.isValid() ? size_ : QSize(640, 480);\n+}\ndiff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h\nnew file mode 100644\nindex 0000000..69502b7\n--- /dev/null\n+++ b/src/qcam/viewfinder_gl.h\n@@ -0,0 +1,96 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Linaro\n+ *\n+ * viewfinder_GL.h - OpenGL Viewfinder for rendering by OpenGL shader\n+ *\n+ */\n+#ifndef __VIEWFINDER_GL_H__\n+#define __VIEWFINDER_GL_H__\n+\n+#include <QImage>\n+#include <QMutex>\n+#include <QOpenGLBuffer>\n+#include <QOpenGLFunctions>\n+#include <QOpenGLShader>\n+#include <QOpenGLShaderProgram>\n+#include <QOpenGLTexture>\n+#include <QOpenGLWidget>\n+#include <QSize>\n+\n+#include <libcamera/buffer.h>\n+#include <libcamera/formats.h>\n+\n+#include \"viewfinder.h\"\n+\n+class ViewFinderGL : public QOpenGLWidget,\n+\t\t public ViewFinder,\n+\t\t protected QOpenGLFunctions\n+{\n+\tQ_OBJECT\n+\n+public:\n+\tViewFinderGL(QWidget *parent = nullptr);\n+\t~ViewFinderGL();\n+\n+\tconst QList<libcamera::PixelFormat> &nativeFormats() const override;\n+\n+\tint setFormat(const libcamera::PixelFormat &format, const QSize &size) override;\n+\tvoid render(libcamera::FrameBuffer *buffer, MappedBuffer *map) override;\n+\tvoid stop() override;\n+\n+\tQImage getCurrentImage() override;\n+\n+Q_SIGNALS:\n+\tvoid renderComplete(libcamera::FrameBuffer *buffer);\n+\n+protected:\n+\tvoid initializeGL() override;\n+\tvoid paintGL() override;\n+\tvoid resizeGL(int w, int h) override;\n+\tQSize sizeHint() const override;\n+\n+private:\n+\tbool selectFormat(const libcamera::PixelFormat &format);\n+\n+\tvoid configureTexture(unsigned int id);\n+\tbool createFragmentShader();\n+\tbool createVertexShader();\n+\tvoid removeShader();\n+\tvoid doRender();\n+\n+\t/* Captured image size, format and buffer */\n+\tlibcamera::FrameBuffer *buffer_;\n+\tlibcamera::PixelFormat format_;\n+\tQSize size_;\n+\tunsigned char *yuvData_;\n+\n+\t/* OpenGL components for rendering */\n+\tQOpenGLShader *fragmentShader_;\n+\tQOpenGLShader *vertexShader_;\n+\tQOpenGLShaderProgram shaderProgram_;\n+\n+\t/* Vertex buffer */\n+\tQOpenGLBuffer vertexBuffer_;\n+\n+\t/* Fragment and Vertex shader file name */\n+\tQString fragmentShaderSrc_;\n+\tQString vertexShaderSrc_;\n+\n+\t/* YUV texture planars and parameters */\n+\tGLuint id_u_;\n+\tGLuint id_v_;\n+\tGLuint id_y_;\n+\tGLuint textureUniformU_;\n+\tGLuint textureUniformV_;\n+\tGLuint textureUniformY_;\n+\tQOpenGLTexture textureU_;\n+\tQOpenGLTexture textureV_;\n+\tQOpenGLTexture textureY_;\n+\tunsigned int horzSubSample_;\n+\tunsigned int vertSubSample_;\n+\n+\tQMutex mutex_; /* Prevent concurrent access to image_ */\n+};\n+\n+#endif /* __VIEWFINDER_GL_H__ */\n", "prefixes": [ "libcamera-devel", "v6", "3/4" ] }