Commit Graph

20 Commits

Author SHA1 Message Date
Ray Smith 7b1520c4d9 helpers: don't override C++11's built-in static_assert
The #ifndef doesn't work with the built-in static_assert from C++11, so
it ends up getting redefined. It seems that there are other versions of
static_assert internally in some C++ standard library implementations
that have additional arguments, and these also get overwritten by the
two-argument version here.

Detect if we're using a suitably-recent version of C++ and avoid the
redefintion in that case.

Signed-off-by: Ray Smith <rsmith@brightsign.biz>
2024-07-24 08:48:25 +00:00
Loïc Molinari d1ee47361c helpers: Add FALLTHROUGH macro
Use gcc and clang's 'fallthrough' attribute instead of a comment to
fall through switch statements. This allows to request fall through
inside a block and prevents issues with preprocessed files.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-07-04 14:15:04 +00:00
Loïc Molinari 4566eae245 gl-renderer: Improve wireframe rendering
Render wireframe within paint nodes instead of drawing lines in a
second pass. The wireframe is blended over the node in a single draw
call. This slightly simplifies the logic by removing the computation
of a second set of indices and enables wireframe anti-aliasing using
Celes and Abraham's "Fast and versatile texture-based wireframe
rendering" paper from 2011.

Celes and Abraham use a one-dimensional set of texture coords for each
triangle edge, 1.0 for the 2 vertices defining the edge and 0.0 for
the other vertex, which basically define barycentric coords. Texture
mapping and the mip chain is then exploited to give a constant-width
edge. The main drawback of the technique is that contour edges of
node's damage mesh are drawn half as thick as interior lines since
each triangle draws half of each line's thickness.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-06-27 20:40:37 +00:00
Loïc Molinari 0729ffbdb8 build: Add generic compiler builtins support
Wrap compiler builtins into shared functions with proper generic
implementations. __builtin_clz() isn't wrapped for now because its use
by screenshooter is pretty specific. It will be properly wrapped in
the next commit which needs a round up to the next power of 2
function.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-06-27 20:40:37 +00:00
Loïc Molinari f7a14ba0e7 gl-renderer: Batch paint node's draw calls
A paint node with 'n' rects damaged by 'm' quads emits 'n*m' OpenGL
draw calls. This commit batches the 'n*m' clipped polygons into an
indexed triangle strip damage mesh using degenerate triangles. A
single draw call per paint node is emitted to reduce API overhead.

Fan debug mode is disabled for now and will be added back using
batching in the next commits.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-06-04 17:24:12 +00:00
Philipp Zabel b3d94c9843 helpers: Add an integer division helper that rounds up
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-09-15 09:44:44 +03:00
Marius Vlad 59ac0a38da libweston/vertex-clipping: Use shared helper
And introduced a new helper, CLIP, with it.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2023-01-24 16:59:37 +02:00
Daniel Stone ef87ad2237 build: Add unreachable()
unreachable() is used to hint to the compiler that a certain branch
cannot ever be reached. The implementation is taken from Mesa.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2023-01-10 10:59:04 +02:00
Derek Foreman 5079f0b2f9 helpers: Add a u64 from 2 u32 helper
We do this enough that having a single implementation for it is probably
a win.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-10-27 08:13:30 +00:00
Pekka Paalanen 32a790f774 shared: add WESTON_EXPORT_FOR_TESTS
This is a new function exporting macro that intends to make writing unit
tests in the Weston test suite easier.

A test needs to access a private function to be able to verify its
behavior. Previously we have used things like putting such functions in
a separate .c file and then building that file into the corresponding
test. That is a bit awkward and can lead to proliferation of arbitrary
.c files for no good reason. It may also require pre-processor magic,
and sometimes copying chunks of code causing a risk of deviating the
code being tested from the code actually used.

This patch proposes another approach: a private export from a DSO.
Except, private exports do not really exist, and this is just a normal
export with a specific C macro, and omitting the function from public
headers.

Once exported, a test program can link the DSO during build, be that a
shared library or even a plugin, use the private header declaring the
function, and simply call the function in the test.

The declaration of WESTON_EXPORT_FOR_TESTS is in shared/helpers.h so
that it is available to all components equally while still not being in
a public header. Other places that were considered:

- include/libweston/libweston.h is a public header, but external users
  should not know about the macro.

- libweston/libweston-private.h is too private and not available to all
  components, particularly color-lcms plugin.

- libweston/backend.h is not appropriate for color-lcms plugin either.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-03-01 13:32:15 +00:00
Leandro Ribeiro 58393ca733 shared/helpers: fix ARRAY_COPY macro
In commit "backend-drm: simplify compile time array copy", the macro
ARRAY_COPY was introduced.

The macro STRING was accidentally introduced in the same commit, and as
it is completely unnecessary, remove it.

Also, memcpy was copying from src to dst, and it should do the opposite.
So fix it.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-28 11:35:28 -03:00
Leandro Ribeiro 3193ab5807 backend-drm: simplify compile time array copy
In drm_fb_get_from_dmabuf() we have some compile time array copies, and
multiple static_assert() calls are needed (for safety). This makes the
code unpleasant to read.

Add ARRAY_COPY macro, to simplify the code.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:00:38 -03:00
Pekka Paalanen eb5a95bfc9 libweston: move TYPEVERIFY macro into shared
This will be useful in the test harness macros.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-02-17 12:52:33 +00:00
Marius Vlad 48392643ec clients: Fix/resolved doxygen warnings
Missing/wrong parameters and '[out]' issues.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2019-06-25 14:05:54 +00:00
Daniel Stone 11f91bbd36 helpers: Move static_assert definition to shared
Collect the fallback definitions of static_assert() from desktop-shell
and the test shell, and move them to helpers.h. This allows code
throughout the tree to use static_assert() for build-time assertions,
where it is supported by the compiler.

As GCC goes out of its way to only add static_assert() when C11 has been
explicitly requested - which we don't do - make sure to use the more
widely available _Static_assert() if that is provided.

This will be used in future patches to ensure two array lengths don't go
out of sync.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2018-07-09 15:39:20 +01:00
Abdur Rehman 5735eedb43 shared/helpers.h: fix a typo in a comment
Signed-off-by: Abdur Rehman <arehmanq199@gmail.com>
Reviewed-by: Yong Bakos <ybakos@humanoriented.com>
2017-01-03 11:59:08 +00:00
Quentin Glidic 8f9d90a84b
desktop-shell: Port to libweston-desktop
All the shell protocol details, Xwayland glue and popups (and their
grab) are now handled in libweston-desktop.
Fullscreen methods (for wl_shell) are removed for now.

Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Acked-by: Giulio Camuffo <giulio.camuffo@kdab.com>

Differential Revision: https://phabricator.freedesktop.org/D1209
2016-08-14 09:29:08 +02:00
Jon Cruz 867d50eea7 Unified multiple definitions of container_of() macro.
Removed duplicate definitions of the container_of() macro and
refactored sources to use the single implementation.

Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-15 17:11:58 -07:00
Jon Cruz d618f688d5 Moved the MIN() macro to the helper include.
Removed multiple definitions of the MIN() macro from existing
locations and unified with a single definition. Updated sources
to use the shared version.

Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-15 17:11:52 -07:00
Jon Cruz 35b2eaa989 Moved helper macro to a discrete include file.
To help reduce code duplication and also 'kitchen-sink' includes
the ARRAY_LENGTH macro was moved to a stand-alone file and
referenced from the sources consuming it. Other macros will be
added in subsequent passes.

Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-15 17:11:45 -07:00