diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2018-08-23 13:11:41 +0300 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2018-08-23 13:21:28 +0300 |
commit | 40d96062a37ca924a66a926a234b35644928d4a7 (patch) | |
tree | c0f5c95473af017a66b9ef7ad66a6c4f7a964aa9 /kms++util/src | |
parent | 4dae98543f848095542a51b8c23322edf07c192e (diff) |
Revert "testpat: remove threaded drawing"
This reverts commit 33246d9b5fb0347aabd62caac1da03440f9e1634.
Add threaded drawing back, but have it behind a CMAKE variable so that
it can easily be turned off.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Diffstat (limited to 'kms++util/src')
-rw-r--r-- | kms++util/src/testpat.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/kms++util/src/testpat.cpp b/kms++util/src/testpat.cpp index fee8d8c..8795cc6 100644 --- a/kms++util/src/testpat.cpp +++ b/kms++util/src/testpat.cpp @@ -4,6 +4,10 @@ #include <cstring> #include <cassert> +#ifdef HAS_PTHREAD +#include <thread> +#endif + #include <kms++/kms++.h> #include <kms++util/kms++util.h> @@ -152,7 +156,36 @@ static void draw_test_pattern_part(IFramebuffer& fb, unsigned start_y, unsigned static void draw_test_pattern_impl(IFramebuffer& fb, YUVType yuvt) { +#ifdef HAS_PTHREAD + if (fb.height() < 20) { + draw_test_pattern_part(fb, 0, fb.height(), yuvt); + return; + } + + // Create the mmaps before starting the threads + for (unsigned i = 0; i < fb.num_planes(); ++i) + fb.map(0); + + unsigned num_threads = thread::hardware_concurrency(); + vector<thread> workers; + + unsigned part = (fb.height() / num_threads) & ~1; + + for (unsigned n = 0; n < num_threads; ++n) { + unsigned start = n * part; + unsigned end = start + part; + + if (n == num_threads - 1) + end = fb.height(); + + workers.push_back(thread([&fb, start, end, yuvt]() { draw_test_pattern_part(fb, start, end, yuvt); })); + } + + for (thread& t : workers) + t.join(); +#else draw_test_pattern_part(fb, 0, fb.height(), yuvt); +#endif } void draw_test_pattern(IFramebuffer &fb, YUVType yuvt) |