-
-}
-
-int
-__driParseEvents(__DRIscreenPrivate *psp, __DRIdrawablePrivate *pdp)
-{
- __DRIDrawableConfigEvent *dc;
- __DRIBufferAttachEvent *ba;
- unsigned int tail, mask, *p, end, total, size, changed;
- unsigned char *data;
- size_t rect_size;
- __DRIcontextPrivate *pcp = pdp->driContextPriv;
-
- if (pcp == NULL)
- return 0;
-
- /* Check for wraparound. */
- if (psp->dri2.buffer->prealloc - pdp->dri2.tail > psp->dri2.buffer->size) {
- /* If prealloc overlaps into what we just parsed, the
- * server overwrote it and we have to reset our tail
- * pointer. */
- DRM_UNLOCK(psp->fd, psp->lock, pcp->hHWContext);
- (*dri_interface->reemitDrawableInfo)(pdp->pdraw);
- DRM_LIGHT_LOCK(psp->fd, psp->lock, pcp->hHWContext);
- }
-
- total = psp->dri2.buffer->head - pdp->dri2.tail;
- mask = psp->dri2.buffer->size - 1;
- tail = pdp->dri2.tail;
- end = psp->dri2.buffer->head;
- data = psp->dri2.buffer->data;
- changed = 0;
-
- while (tail != end) {
- p = (unsigned int *) (data + (tail & mask));
- size = DRI2_EVENT_SIZE(*p);
- if (size > total || (tail & mask) + size > psp->dri2.buffer->size) {
- /* illegal data, bail out. */
- fprintf(stderr, "illegal event size\n");
- break;
- }
-
- switch (DRI2_EVENT_TYPE(*p)) {
- case DRI2_EVENT_DRAWABLE_CONFIG:
- dc = (__DRIDrawableConfigEvent *) p;
-
- if (dc->drawable != pdp->hHWDrawable)
- break;
-
- if (pdp->w != dc->width || pdp->h != dc->height)
- changed = 1;
-
- pdp->x = dc->x;
- pdp->y = dc->y;
- pdp->w = dc->width;
- pdp->h = dc->height;
-
- pdp->backX = 0;
- pdp->backY = 0;
- pdp->numBackClipRects = 1;
- pdp->pBackClipRects[0].x1 = 0;
- pdp->pBackClipRects[0].y1 = 0;
- pdp->pBackClipRects[0].x2 = pdp->w;
- pdp->pBackClipRects[0].y2 = pdp->h;
-
- pdp->numClipRects = dc->num_rects;
- _mesa_free(pdp->pClipRects);
- rect_size = dc->num_rects * sizeof dc->rects[0];
- pdp->pClipRects = _mesa_malloc(rect_size);
- memcpy(pdp->pClipRects, dc->rects, rect_size);
-
- if (changed)
- (*psp->DriverAPI.UpdateBuffer)(pdp, p);
- break;
-
- case DRI2_EVENT_BUFFER_ATTACH:
- ba = (__DRIBufferAttachEvent *) p;
-
- if (ba->drawable != pdp->hHWDrawable)
- break;
-
- (*psp->DriverAPI.UpdateBuffer)(pdp, p);
- break;
-
- default:
- break;
- }
-
- tail += size;
- }
-
- pdp->dri2.tail = tail;
-
- /* FIXME: Return whether we changed anything. This check always
- * returns true if we received events, but we could refine the
- * check to only return TRUE if the drawable actually changed. */
-
- return total > 0;