[cairo] Re: about glitz yv12 support

David Reveman davidr at novell.com
Wed Jun 21 11:05:46 PDT 2006


On Wed, 2006-06-21 at 16:42 +0800, ma liang wrote: 
> Hello, David:
> 
> 2006/6/20, David Reveman <davidr at novell.com>:
> > On Tue, 2006-06-20 at 11:17 +0800, ma liang wrote:
> 
> > > 3.If it is a YV12 surface, how can I set my "base[0]: y,  base[1]: u,
> > > base[2]: v "data to the surface to display it?
> >
> > You want to upload data to the yv12 surface and display it by using
> > glitz_composite with yv12 surface as source and some drawable as
> > destination.
> >
> > To upload data into yv12 surface use glitz_set_pixels with a
> > glitz_pixel_format_t structure set up correctly to match your data.
> > scanline_order must be GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP for
> > efficient loading. If your data is not in bottom-up scanline order, flip
> > it when doing glitz_composite instead.
> >
> > -David
> >
> >
> Thank you for your reply. But I am not very clear about how to use
> glitz_composite
> (sorry for I am a newbie with glitz).
> Is there any example about this, or, if I have the following code,
> what is the next step I need to do?
> ================================================================
> dtempl.samples = 1;
> dtempl.doublebuffer = 1;
> mask = GLITZ_FORMAT_SAMPLES_MASK;
> dformat = glitz_glx_find_window_format (display, screen, mask, &dtempl, 0);
> drawable = glitz_glx_create_drawable_for_window (display, screen, dformat, win,
> 						 WIDTH_QY, HIGHT_QY);
> 
> templ.color.fourcc = GLITZ_FOURCC_YV12;
> mask = GLITZ_FORMAT_FOURCC_MASK;
> format = glitz_find_format (drawable, mask, &templ, 0);
> 
> surface = glitz_surface_create (drawable, format, WIDTH_QY, HIGHT_QY, 0, NULL);
> size = (8*((width + 7) / 8) * height) + (2*( 8*((width + 15) /
> 16)*((height+1)/2) ));
> 
> pf.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;

make that:
pf.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP;

otherwise it will be really slow.

> pf.xoffset = 0;
> pf.skip_lines = 0;
> pf.fourcc = GLITZ_FOURCC_YV12;
> pf.masks.bpp = 12;
> pf.masks.alpha_mask = 0x0;
> pf.masks.red_mask =   0x0;
> pf.masks.green_mask = 0x0;
> pf.masks.blue_mask =  0x0;
> pf.bytes_per_line = (((width * pf.masks.bpp) / 8) + 3) & -4;
> 
> /* data is a pointer to a frame base data, this frame size is WIDTH_QY
> * HIGHT_QY */
> buffer = glitz_pixel_buffer_create(drawable, (void *)data, size,
> GLITZ_BUFFER_HINT_STREAM_DRAW);

Using glitz_pixel_buffer_create and GLITZ_BUFFER_HINT_STREAM_DRAW with
YV12 data can eventually give you better performance but with existing
GL drivers, glitz_buffer_create_for_data is more efficient.

So change the above line to:
buffer = glitz_buffer_create_for_data ((void *) data);

> glitz_set_pixels ((glitz_surface_t *) surface, 0, 0, width, height,
> &pf, buffer);

You could create a cairo surface from this glitz surface and use it as a
pattern when drawing using cairo. If you want to use glitz directly do
something like this:

transform.matrix[0][0] = 1 << 16;
transform.matrix[0][1] = 0;
transform.matrix[0][2] = 0;
transform.matrix[1][0] = 0;
transform.matrix[1][1] = -1 << 16;
transform.matrix[1][2] = height << 16;
transform.matrix[2][0] = 0;
transform.matrix[2][1] = 0;
transform.matrix[2][2] = 1 << 16;

/* to adjust for GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP */
glitz_surface_set_transform (surface, &transform);

glitz_composite (GLITZ_OPERATOR_SRC,
                 surface,
                 NULL,
                 dst,
                 0, 0,
                 0, 0,
                 x_dst, y_dst,
                 width, height);

dst, should be a RGB surface attached to drawable.

-David



More information about the cairo mailing list