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>
This commit is contained in:
Derek Foreman 2022-10-25 14:54:58 -05:00 committed by Pekka Paalanen
parent 2ca2eac39a
commit 5079f0b2f9
9 changed files with 19 additions and 10 deletions

View File

@ -446,7 +446,7 @@ feedback_presented(void *data,
struct feedback *feedback = data;
struct window *window = feedback->window;
struct feedback *prev_feedback = window->received_feedback;
uint64_t seq = ((uint64_t)seq_hi << 32) + seq_lo;
uint64_t seq = u64_from_u32s(seq_hi, seq_lo);
const struct timespec *prevpresent;
uint32_t commit, present;
uint32_t f2c, c2p, f2p;

View File

@ -1010,7 +1010,7 @@ dmabuf_modifiers(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo)
{
struct display *d = data;
uint64_t modifier = ((uint64_t)modifier_hi << 32) | modifier_lo;
uint64_t modifier = u64_from_u32s(modifier_hi, modifier_lo);
if (format != d->format) {
return;

View File

@ -730,7 +730,7 @@ dmabuf_modifier(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo)
{
struct display *d = data;
uint64_t modifier = ((uint64_t) modifier_hi << 32 ) | modifier_lo;
uint64_t modifier = u64_from_u32s(modifier_hi, modifier_lo);
if (format == d->drm_format && modifier == DRM_FORMAT_MOD_LINEAR)
d->requested_format_found = true;

View File

@ -4704,7 +4704,7 @@ relative_pointer_handle_motion(void *data, struct zwp_relative_pointer_v1 *point
{
struct input *input = data;
struct window *window = input->pointer_focus;
uint32_t ms = (((uint64_t) utime_hi) << 32 | utime_lo) / 1000;
uint32_t ms = u64_from_u32s(utime_hi, utime_lo) / 1000;
if (window->locked_pointer_motion_handler &&
window->pointer_locked) {

View File

@ -1382,12 +1382,12 @@ drm_pending_state_apply_sync(struct drm_pending_state *pending_state)
void
drm_output_update_msc(struct drm_output *output, unsigned int seq)
{
uint64_t msc_hi = output->base.msc >> 32;
uint32_t msc_hi = output->base.msc >> 32;
if (seq < (output->base.msc & 0xffffffff))
msc_hi++;
output->base.msc = (msc_hi << 32) + seq;
output->base.msc = u64_from_u32s(msc_hi, seq);
}
static void

View File

@ -37,6 +37,7 @@
#include "linux-dmabuf.h"
#include "linux-dmabuf-unstable-v1-server-protocol.h"
#include "shared/os-compatibility.h"
#include "shared/helpers.h"
#include "libweston-internal.h"
#include "shared/weston-drm-fourcc.h"
@ -121,8 +122,7 @@ params_add(struct wl_client *client,
if (wl_resource_get_version(params_resource) < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
buffer->attributes.modifier[plane_idx] = DRM_FORMAT_MOD_INVALID;
else
buffer->attributes.modifier[plane_idx] = ((uint64_t)modifier_hi << 32) |
modifier_lo;
buffer->attributes.modifier[plane_idx] = u64_from_u32s(modifier_hi, modifier_lo);
buffer->attributes.n_planes++;
}

View File

@ -22,6 +22,8 @@
#ifndef WESTON_HELPERS_H
#define WESTON_HELPERS_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -171,6 +173,12 @@ do { \
*/
#define WESTON_EXPORT_FOR_TESTS __attribute__ ((visibility("default")))
static inline uint64_t
u64_from_u32s(uint32_t hi, uint32_t lo)
{
return ((uint64_t)hi << 32) + lo;
}
#ifdef __cplusplus
}
#endif

View File

@ -30,6 +30,7 @@
#include <assert.h>
#include <time.h>
#include <stdbool.h>
#include <shared/helpers.h>
#define NSEC_PER_SEC 1000000000
@ -216,7 +217,7 @@ static inline void
timespec_from_proto(struct timespec *a, uint32_t tv_sec_hi,
uint32_t tv_sec_lo, uint32_t tv_nsec)
{
a->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
a->tv_sec = u64_from_u32s(tv_sec_hi, tv_sec_lo);
a->tv_nsec = tv_nsec;
}

View File

@ -123,7 +123,7 @@ feedback_presented(void *data,
assert(fb->result == FB_PENDING);
fb->result = FB_PRESENTED;
fb->seq = ((uint64_t)seq_hi << 32) + seq_lo;
fb->seq = u64_from_u32s(seq_hi, seq_lo);
timespec_from_proto(&fb->time, tv_sec_hi, tv_sec_lo, tv_nsec);
fb->refresh_nsec = refresh_nsec;
fb->flags = flags;