Commit Graph

14 Commits

Author SHA1 Message Date
Laurent Pinchart
9e10811bb5 qcam: viewfinder_gl: Add support for RGB formats
Add support for 24-bit and 32-bit RGB formats. The fragment samples the
texture and reorders the components, using a pattern set through the
RGB_PATTERN macro. The pattern stores the shader vec4 element indices
(named {r, g, b, a} by convention, for elements 0 to 3) to be extracted
from the texture samples, when interpreted by OpenGL as RGBA.

Note that, as textures are created with GL_UNSIGNED_BYTE, the RGBA
order corresponds to bytes in memory, while the libcamera formats are
named based on the components order in a 32-bit word stored in memory in
little endian format.

An alternative to manual reordering in the shader would be to set the
texture swizzling mask. This is however not available in OpenGL ES
before version 3.0, which we don't mandate at the moment.

Only the BGR888 and RGB888 formats have been tested, with the vimc
pipeline handler.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07 19:27:33 +02:00
Laurent Pinchart
3badc5c4be qcam: viewfinder_gl: Store textures in an array
In preparation for RGB formats support, store the three Y, U and V
textures in an array. This makes the code more generic, and will avoid
referring to an RGB texture as textureY_.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07 19:27:29 +02:00
Laurent Pinchart
819f6172ea qcam: viewfinder_gl: Rename yuvData_ to data_
In preparation for RGB formats support, rename the pointer to image data
from yuvData_ to data_.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07 19:27:24 +02:00
Laurent Pinchart
dfadca6356 qcam: viewfinder_gl: Rename YUV.vert to identity.vert
In preparation for RGB formats support, rename the identity vertex
shader from YUV.vert to identity.vert.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07 19:25:24 +02:00
Laurent Pinchart
99f72137e5 qcam: viewfinder_gl: Remove unneeded casts
There's no need to cast the yuvData_ unsigned char pointer to a char
pointer before performing pointer arithmetics. Drop the unneeded casts.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07 19:25:24 +02:00
Laurent Pinchart
3b9a582f95 qcam: viewfinder_gl: Keep fragment shader when format doesn't change
When ViewFinderGL::setFormat() is called, the fragment shader is deleted
and recreated for the new format. This results in unnecessary shader
recompilation if only the size is changed and the pixel format remains
the same. Keep the existing shader in that case.

The null test for fragmentShader_ can be removed, as if the shader
program is linked, the fragment shader is guaranteed to exist.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07 19:25:24 +02:00
Laurent Pinchart
4b9a774a4c qcam: viewfinder_gl: Fix fragment shader rebuild when setting format
When setting a new format, the existing fragment shader is deleted and a
new shader should be created. However, the shader pointer isn't set to
nullptr after deleting it, resulting in the deleter shader being reused.
Fix it by managing shader pointers with std::unique_ptr<> to prevent
similar bugs from happening in the future.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07 19:25:24 +02:00
Laurent Pinchart
dcc47ff715 qcam: viewfinder_gl: Add shader to render packed YUV formats
The shader supports all 4 packed 8-bit YUV variants.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04 22:51:45 +03:00
Laurent Pinchart
ae9e7fbf3a qcam: viewfinder_gl: Merge the semi-planar UV and VU shaders
Use macros to select the U and V pattern, to avoid code duplication
between the two semi-planar shaders.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04 22:51:45 +03:00
Laurent Pinchart
0bc03960da qcam: viewfinder_gl: Support #define in shaders
Prepare the infrastructure to support defining preprocessor macros in
shaders:

- Rename the fragmentShaderSrc_ member to fragmentShaderFile_ to reflect
  better that it contains a file name, not shader source code
- Add a new fragmentShaderDefines_ member to store preprocessor macros
- Prepend the macros to the shader source before compiling it

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04 22:51:45 +03:00
Laurent Pinchart
440028d6c9 qcam: viewfinder_gl: Rename shader files
Rename shader files to prepare for packed YUYV support:

- The NV prefix isn't a good match for packed (or for 3-planar) formats,
  replace it with a YUV prefix
- Use .frag and .vert extensions to differentiate between fragment and
  vertex shaders

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04 22:51:45 +03:00
Laurent Pinchart
079afd17e7 qcam: viewfinder_gl: Hardcode the vertex shader file name
The GL renderer uses the same vertex shader for all formats. Hardcode
the file name instead of storing it in a member variable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04 22:51:45 +03:00
Laurent Pinchart
52f2581709 qcam: viewfinder_gl: Don't store texture IDs in class members
The texture IDs can easily and cheaply be retrieved from the textures,
there's no need to store them in class members.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04 22:51:45 +03:00
Show Liu
9db6ce0ba4 qcam: Add ViewFinderGL class to accelerate the format conversion
The viewfinderGL accelerates the format conversion by using OpenGL ES
shader.

The minimum Qt version is bumped to v5.4, as QOpenGLWidget wasn't
available before that.

Signed-off-by: Show Liu <show.liu@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-09-15 05:10:35 +03:00