[PATCH weston 1/5] compositor: When clipping pointer motions, don't loose precision

Kristian Høgsberg krh at bitplanet.net
Wed May 9 16:12:20 PDT 2012


On Wed, May 9, 2012 at 7:00 PM, Daniel Stone <daniel at fooishbar.org> wrote:
> Hi,
>
> On 9 May 2012 22:31, Jonas Ådahl <jadahl at gmail.com> wrote:
>> @@ -1563,18 +1563,20 @@ clip_pointer_motion(struct weston_compositor *ec,
>>                    wl_fixed_t *fx, wl_fixed_t *fy)
>>  {
>>        struct weston_output *output;
>> -       int32_t x, y;
>> +       wl_fixed_t x, y;
>>        int x_valid = 0, y_valid = 0;
>>        int min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN;
>>
>> -       x = wl_fixed_to_int(*fx);
>> -       y = wl_fixed_to_int(*fy);
>> +       x = *fx;
>> +       y = *fy;
>
> You could easily ditch the intermediate variable here.
>
>> @@ -1590,20 +1592,20 @@ clip_pointer_motion(struct weston_compositor *ec,
>>        }
>>
>>        if (!x_valid) {
>> -               if (x < min_x)
>> -                       x = min_x;
>> -               else if (x >= max_x)
>> -                       x = max_x;
>> +               if (x < wl_fixed_from_int(min_x))
>> +                       x = wl_fixed_from_int(min_x);
>> +               else if (x >= wl_fixed_from_int(max_x))
>> +                       x = wl_fixed_from_int(max_x);
>
> This should never be possible, as the range of a wl_fixed_t is a fair
> bit less than that of an int, so this check can be dropped.  (And, now
> it's come up, I think we might need some better range checking when we
> create wl_fixed_ts earlier in the input chain ...)

We just need min/max_x/y to be wl_fixed_t and then we need

#define WL_FIXED_MAX INT32_MAX
#define WL_FIXED_MIN INT32_MIN

Kristian

> Other than that:
> Reviewed-by: Daniel Stone <daniel at fooishbar.org>
>
> Cheers,
> Daniel
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list