[RFC weston 13/16] compositor: Add a function to test if images transformed by a matrix should be bilinearly filtered

Pekka Paalanen ppaalanen at gmail.com
Wed Oct 1 00:41:10 PDT 2014


On Tue, 30 Sep 2014 14:35:24 -0500
Derek Foreman <derekf at osg.samsung.com> wrote:

> Thanks for taking a look!
> 
> On 26/09/14 05:48 PM, Bill Spitzak wrote:
> > 90 degree rotation about x or y will require filtering.
> 
> Yup, you're right.
> 
> > You test y scale twice, must be a typo. I think you intended to test z,
> > but in fact z scale is not relevant so you should not test it at all.
> 
> Argh - thanks.  Why isn't Z scale relevant?  I'm worried about making
> assumptions about the transformations these matrices represent and
> having those assumptions violated in the future...  For Z not to matter
> are we assuming projection will always be orthographic?

Weston never uses the final Z coordinate for anything, so in that sense
it is always orthographic. Essentially, we could just do with 3x3
matrices perfectly fine. 3x3 supports 2D-projective which is enough to
implement fake-3D effects like
http://people.collabora.com/~pq/rotate3d-fun.webm
(The gl-renderer does not route the W element at all, I had to patch
that. Pixman-renderer OTOH just worked.)

Weston also hardcodes the input Z coordinate always to 0, no matter
which way you are going between buffer and output spaces.

I suppose the 4x4 matrix was originally chosen to fit the OpenGL API.
And maybe with some speculation about a desktop cube implementation or
something, but I don't really see the cube or such coming, not as a
generic thing anyway as only the gl-renderer could support it with
true 3D space.

> > Translation by non-integer will also require filtering.
> 
> Good point.
> 
> > I recommend instead of checking the rotation to instead look for zeros
> > in the correct locations in the matrix. Matrix must be of the form:
> > 
> >  |sx 0  0 tx|
> >  |0  sy 0 ty|
> >  |?  ?  ?  ?|
> >  |0  0  0  1|
> > 
> > or
> > 
> >  |0  sx 0 tx|
> >  |sy 0  0 ty|
> >  |?  ?  ?  ?|
> >  |0  0  0  1|
> > 
> > sx and sy must be ±1, and tx and ty must be integers. The ? can be any
> > value.
> 
> That could save us the very expensive matrix decomposition.  I'll try
> this out.  Thanks.
> 
> I think this may be better than decomposition for deciding to use video
> planes in compositor-drm as well.
> 
> (In fact, you've got me wondering if we ever need to split a matrix into
> basic transformations at all...)

I'd be wondering about that, too. My intuition would say there is no
need to really decompose. Just checking the elements should suffice,
and when the matrix is supportable for whatever, then you pick the
right elements (which is a bit like decomposition, but no need to be
generic at all).

And you take take advantage of the fact that incoming Z=0 and outgoing
Z is ignored, I believe. That is, for the final, total transformation
matrix between buffer and output spaces.

> > Also pixman is already doing equivalent tests and short-circuiting to
> > nearest filter, so you might not need to check this anyway.
> 
> This is also used for the gl renderer, so I don't think I can count on
> that short circuit there...  Though bilinear vs nearest doesn't have
> anywhere near the same performance impact there.

Yeah, we need to pick nearest vs. linear in the gl-renderer ourselves.
Even if the choice did not affect the outcome, choosing nearest when we
can might save memory bandwidth. I hope.

And then we have the accuracy problems of GL, so picking nearest
guarantees a crisp image reproduction, otherwise one might get a little
blur. In theory we should get rid of the blur by careful coordinate
manipulation even with linear, but I'm not sure that manipulation is
portable between GL implementations.


Thanks,
pq

> Are you suggesting pixman always be set to use bilinear, and it'll just
> pick nearest automatically when the image transform doesn't require it?
> 
> > On 09/26/2014 02:10 PM, Derek Foreman wrote:
> > 
> >> +WL_EXPORT int
> >> +weston_matrix_needs_filtering(struct weston_matrix *matrix)
> >> +{
> >> +    if (!rot_is_90(weston_matrix_get_rotation_x(matrix))
> >> +     || !rot_is_90(weston_matrix_get_rotation_y(matrix))
> >> +     || !rot_is_90(weston_matrix_get_rotation_z(matrix))
> >> +     || (fabs(weston_matrix_get_scale_x(matrix) - 1.0) > 0.0001)
> >> +     || (fabs(weston_matrix_get_scale_y(matrix) - 1.0) > 0.0001)
> >> +     || (fabs(weston_matrix_get_scale_y(matrix) - 1.0) > 0.0001))
> >> +        return 1;
> >> +
> >> +    return 0;
> >> +}


More information about the wayland-devel mailing list